Skip to content

Instantly share code, notes, and snippets.

@WamWooWam
Created January 25, 2019 23:25
Show Gist options
  • Save WamWooWam/0ece7e3e2d6e69c8d17dc3308883fd0d to your computer and use it in GitHub Desktop.
Save WamWooWam/0ece7e3e2d6e69c8d17dc3308883fd0d to your computer and use it in GitHub Desktop.
Object Set importer for Dash Engine
#
# Object Set importer for Dash Engine
#
# This script loads *.set.xml files from Hedgehog Engine games (Unleashed, Generations) into
# the currently loaded level, keeping position and rotation
#
# Authored by WamWooWam, licenced under the MIT Licence
#
import xml.etree.ElementTree as ET
import unreal
zero = unreal.Vector(0, 0, 0)
forward = unreal.Vector(1, 0, 0)
up = unreal.Vector(0, 0, 1)
right = unreal.MathLibrary.cross_vector_vector(up, forward)
def find_asset(kind):
dir_name = kind
if dir_name == "SuperRing":
dir_name = "Ring"
print("Searching for " + kind)
assets = unreal.EditorAssetLibrary.list_assets(
"/Game/DashEngine/Objects/" + dir_name + "/", True)
if len(assets) == 0:
assets = unreal.EditorAssetLibrary.list_assets(
"/Game/DashEngine/Objects/" + dir_name + "s" + "/", True)
for asset in assets:
if asset.endswith("." + kind + "Actor"):
return unreal.EditorAssetLibrary.load_asset(asset)
def get_position(obj):
xml = obj.find("Position")
return unreal.Vector(float(xml.find("x").text), float(xml.find("z").text), float(xml.find("y").text)) * 100
def get_rotation(obj):
xml = obj.find("Rotation")
quat = unreal.Quat(float(xml.find("x").text), float(xml.find("y").text), float(
xml.find("z").text), float(xml.find("w").text)).rotator()
return unreal.Rotator(-quat.roll, quat.yaw, -quat.pitch)
def direction_to_vector(direction):
if direction == 0:
return forward
if direction == 1:
return right
if direction == 2:
return up
return zero
file = "C:\\Users\\wamwo\\Desktop\\mykonos\\Normal.set.xml"
root = ET.parse(file).getroot()
for obj in root:
kind = obj.tag
found = find_asset(kind)
if found != None:
multiSet = obj.find("MultiSetParam")
if multiSet != None:
interval = float(multiSet.find("Interval").text)
count = int(multiSet.find("Count").text)
direction = int(multiSet.find("Direction").text)
base_position = get_position(obj)
base_rotation = get_rotation(obj)
base_rotation_quat = unreal.Quat()
base_rotation_quat.set_from_euler(unreal.Vector(base_rotation.roll, base_rotation.pitch, base_rotation.yaw))
base_translate = (base_rotation_quat.rotate_vector(direction_to_vector(direction)) * interval)
set_elements = multiSet.findall("Element")
i = 0
while i < count:
position = None
rotation = None
try:
element = set_elements[i]
position = get_position(element)
rotation = get_rotation(element)
except:
position = base_position + (base_translate * (len(set_elements) - i))
rotation = base_rotation
pass
unreal.EditorLevelLibrary.spawn_actor_from_object(found, position, rotation)
i += 1
else:
position = get_position(obj)
rotation = get_rotation(obj)
unreal.EditorLevelLibrary.spawn_actor_from_object(
found, position, rotation)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment