Home Technical Talk

Max to UE4 Maxscript Help

Hi guys. My apologies if this is the wrong subforum, it's the only one I could find that seemed the most relevant.

If anyone's familiar with Tom Shannon's TS Tools for importing Max objects/scenes into UE4, I'm basically trying to modify that to make it a little more "one click solutiony." With the TS Tools you have to select all of the master objects (either singular objects or one of an object which is instantiated) in your scene manually which can be tedious. As well, when importing into UE by going to Edit -> Paste, the meshes your UE scene are populated with default to the DefaultCube mesh from the engine files and not the corresponding mesh from your Max scene which means you have to manually replace each mesh with the correct imported meshes. While this doesn't seem like much of a problem with smaller groups of objects or scenes, I've had to deal with scenes which have hundreds of unique objects and this becomes rather tedious.

I've only just begun delving into Maxscript in the last week or so and have made some good progress, but I've hit a snag and I'm really stuck as to what to do. I think I know the logic, but I'm just not sure of the proper order/syntax.

My script at the moment is capable of looping through the scene and picking only one of each kind of object (e.g. if you have a cube which is instantiated 5 times, it only picks one) and exports those accordingly as the "master" file. I also have dissected the TS_Tools script and implemented a similar system which can copy all the transforms of every object in the scene and generate a clipboard text for populating the UE scene based on the objects and their respective transforms in the Max scene. My problem has been trying to change the mesh which UE populates itself with (at the moment just the default cube) with the actual corresponding master mesh from Max. While this works fine for singular objects, it does not work for instantiated ones and only populates the first instantiated mesh and not the others.

The part in question in my script is the following:

StaticMesh=StaticMesh'/Engine/EditorMeshes/EditorCube.EditorCube'

EditorCube is just a placeholder and I would like to have that for every object in the scene, if it's an instance it would reference the "master" exported file and use that because that is the name of the file which will be exported into UE4. (e.g. Cube00, Cube01, Cube02 would all reference Cube00 as that's the master file).

My apologies if I'm not explaining this properly, I'm a little burnt out at this point from trying to solve this. If you want me to clarify anything I've said I'll do my best.
Here's the truncated script below so it's not super long:

try(destroyDialog UE4Tools)catch()
rollout UE4Tools "UE4 Tools" width:280 height:224
(
GroupBox 'grp3' "Export to Unreal" pos:[8,8] width:264 height:208 align:#left
button 'btn_exportdirectory' "Set Content Folder" pos:[16,32] width:120 height:32 align:#left
button 'btn_exportAll' "Export All" pos:[17,152] width:120 height:32 enabled:false align:#left
edittext 'edittext_exportDirectory' "" pos:[17,72] width:249 height:24 readOnly:true align:#left 
button 'btn_exportSelected' "Export Selected" pos:[145,152] width:120 height:32 enabled:false align:#left
checkbox 'chk_layerFolders' "Generate Layer Folders" pos:[73,128] width:144 height:16 enabled:false align:#left
progressBar 'pb1' "Progress" pos:[16,192] width:248 height:16 align:#left
global exportDirectory = undefined
global exportObjs = #()
global exportText_header = 
"Begin Map
Begin Level
"
global exportText_body = 
" Begin Actor Class=StaticMeshActor Name=% Archetype=StaticMeshActor'/Script/Engine.Default__StaticMeshActor'
Begin Object Class=StaticMeshComponent Name=\"StaticMeshComponent0\" Archetype=StaticMeshComponent'Default__StaticMeshActor:StaticMeshComponent0'
End Object
Begin Object Name=\"StaticMeshComponent0\"
StaticMesh=StaticMesh'/Engine/EditorMeshes/EditorCube.EditorCube'
RelativeLocation=(X=%,Y=%,Z=%)
RelativeRotation=(Pitch=%,Yaw=%,Roll=%)
RelativeScale3D=(X=%,Y=%,Z=%)
End Object
StaticMeshComponent=StaticMeshComponent0
RootComponent=StaticMeshComponent0
ActorLabel=\"%\"
End Actor
"
global exportText_footer =
" End Level
Begin Surface
End Surface
End Map
"
global exportText = undefined
--Set Export Directory
fn fn_exportDirectory =
(
try
(
messageBox "Either select your Content folder in your Unreal Project or select a directory anywhere else and import separately."
exportDirectory = getSavePath caption:"Select your Meshes folder in your Unreal Project" initialDir:#images
edittext_exportDirectory.text = exportDirectory
print exportDirectory
btn_exportAll.enabled = on
btn_exportSelected.enabled = on
)
catch()
)
--Get Instances All
fn fn_getInstancesAll =
(
exportObjs = #()
local myinstances = #()
select geometry
if selection.count != 0 do
(
local firstInstances = #()
-- Go through and find all master objects from instances
for o in selection do 
(
InstanceMgr.GetInstances o &firstOnly
if firstOnly.count > 1 do append firstInstances firstOnly[firstOnly.count]
)
-- Go through and find all singular non-instance objects
for o in selection do 
(
if InstanceMgr.CanMakeObjectsUnique o == false then
(append firstInstances o)
)
if firstInstances.count != 0 do select firstInstances
)
for i in selection do
(
insertItem i exportObjs 1
)
)
--Export All
fn fn_exportAll =
(
fn_getInstancesAll()
makeDir (exportDirectory + @\export)
exportText = exportText_header
local exportStream = stringstream ""
for o = 1 to exportObjs.count do
(
select exportObjs[o]
local objCoord = $.pos
if check_origin == true do
(
$.pos = [0,0,0]
)
local currentObj = $.name
local exportFileName = exportDirectory + (@\) + currentObj + @.fbx
exportFile exportFileName #noPrompt selectedOnly:true
$.pos = objCoord
)
for obj in geometry do
(
local exportText_bodyTemp = exportText_body
select obj
local objCoord = $.pos
local objX_pos = $.pos.x
local objY_pos = $.pos.y 
local objZ_pos= $.pos.z
local objX_rot = 0
local objY_rot = 0
local objZ_rot = 0
local objX_scale = 1
local objY_scale = 1
local objZ_scale = 1
local currentObj = $.name
local exportFileName = exportDirectory + (@\) + currentObj + @.fbx
format exportText_bodyTemp currentObj objX_pos objY_pos objZ_pos objX_rot objY_rot objZ_rot objX_scale objY_scale objZ_scale currentObj to:exportStream
exportText_bodyTemp = exportStream
exportStream = stringstream ""
exportText += exportText_bodyTemp
)
exportText = exportText + exportText_footer
messageBox exportText
setClipBoardText exportText
print exportObjs
)
on btn_exportdirectory pressed do
fn_exportDirectory()
on btn_exportAll pressed do
fn_exportAll()
)
createDialog UE4Tools style:#(#style_sysmenu,#style_toolwindow)

Sign In or Register to comment.