Download

Python Scripted Asset Instancing and Placement from Maya almost there

Hi,

I’m learning and building a workflow for my first Unreal project. I’m bringing in an environment from Maya, which I created with modular pieces that all have their pivot at the origin as you can see below in Maya.

These objects were imported into Unreal with the transforms set this way:
importTransform.JPG

Then I have instances of these objects place in Maya.

So I wrote a script to save out the transforms, so that the library objects can be instanced and placed as they were in Maya, in Unreal. The transforms are not coming in correct, and need to be adjusted in some way to work correctly in Unreal. I tried applying x rot 90, scale y -1, and also switching Y and Z transform values, but I’m just guessing and not getting the correct result. Can Anyone look at this code and see what I might need to adjust? The code below is run in Maya, and it writes out a python script which I execute in Unreal to instance and place objects.



def writeEnvPlacementScript(outputFile):
#print placement script for unreal
objLs = cmds.ls(sl=1)
f = open(outputFile, "w")
f.write('import unreal
')
f.write('def placeStaticMesh(world, curAsset, curLocation, curRotation, curScale):
')
f.write(' unreal.EditorLevelLibrary.spawn_actor_from_object(curAsset, curLocation, curRotation)
')

for obj in objLs:
curPos = cmds.xform(obj,ws=1,t=1,q=1)
curRot = cmds.xform(obj,ws=1,ro=1,q=1)
curScl = cmds.xform(obj,ws=1,s=1,q=1)

f.write('world = unreal.EditorLevelLibrary.get_editor_world()
')
f.write('curAsset=unreal.load_object(world, \'/Game/assets/env/rizuHome/'+obj.split('_')[0]+'.'+obj.split('_')[0]+'\')
')
f.write('curLocation = unreal.Vector('+str(curPos[0])+','+str(curPos[2])+','+str(curPos[1])+')
')
f.write('curRotation = unreal.Rotator('+str(curRot[0])+','+str(curRot[1])+','+str(curRot[2])+')
')
f.write('curScale = unreal.Vector('+str(curScl[0])+','+str(curScl[1])+','+str(curScl[2])+')
')
f.write('placeStaticMesh(world, curAsset, curLocation, curRotation, curScale)

')
f.close()
writeEnvPlacementScript(outputFile)


So far, it does the instancing and placing, but the transforms are way off.

Thanks,

Adnan