Important Max script for Unreal v1.0 model imports.

A refuge for those migrating from the fallen DXEditing.com and a place for general discussion relating to Deus Ex editing (coding, mapping, etc).
Post Reply
User avatar
Dead-eye
X-51
Posts: 944
Joined: Tue Apr 25, 2006 3:45 am
Location: Santa Cruz, California

Important Max script for Unreal v1.0 model imports.

Post by Dead-eye »

So as of the new forums coming to OTP I thought I would give you guys a vary useful max script that was used for importing models into Deus Ex from 3ds Max. Sadly I couldn't find it. But thanks to Crossfire over at 3d Buzz I may have found you a script that will be just as good. Although I have yet to test it.

Essentially what this script dose is it takes each object in a scene and saves it out. It also uses the objects center as the center of the scene it save out for each object, which might be a problem, but the important thing is that is saves each object as a separate file.

How this is helpful is when someone is exporting an object with animations, usually they need use the snapshot tool in Max to make one object for every frame of animation your mesh has. Then take each object and save them by themselves in separate files for every frame of animation you have. Considering that some animations can be as much as 1000 frames saving each one out by hand is time consuming and repetitive task.

What you can do instead is when you make your snapshot for every frame of animation you can use this script to save out each object as a separate file for import into Deus Ex. This is a lot less time consuming then doing it by hand.

Code: Select all

macroScript KeensBatchExporter category:"File"
(
--///////////////////////////////////////////////////
--This MaxScript started out as a simple test that
--would allow you to export objects using their pivot
--as the scene origin(so if you had 5 objects 
--scattered around the scene it would move them to 
--0,0,0 for export then move them back after export is 
--done).I got a request for batch operations in the
--script and thought that would be a nice feature so
--i did some research on that and now the script allows
--you to batch export to any format that 3ds max 
--supports and use the scene object name as the file 
--name. You can choose to export only selected 
--(or unselected) objects, or export all objects in 
--the scene. It also allows you to add prefixes to 
--the beginning and/or end of the file name on export,
--or add them to the scene object name.
--///////////////////////////////////////////////////

global prefixpopupgui
--global PrefixText = name()

fn DoExport outputpath ext useobjpivot exportsetup exportsel invertsel pfxb pfxbs pfxa pfxas = 
(
	if (outputpath != undefined) do
	(
		OldSelection = getCurrentSelection()
		if (not exportsel) then
			max select all
		else if (invertsel) then
			max select invert
		
		objList = getCurrentSelection()
		
		for p=1 to objList.count do
		(
			if (pfxb != "") then
				Prefix1 = pfxb + pfxbs
			else
				Prefix1 = ""
			if (pfxa != "") then
				Prefix2 = pfxa + pfxas
			else
				Prefix2 = ""
				
			exportName = outputPath + "\\" + Prefix1 + objList[p].name + Prefix2 + "." + ext
			select objList[p]
			if (useobjpivot) do
			(
				OldPosition = $.Position
				$.position = [0,0,0]
			)
			if (exportsetup and p == 1) then
				exportfile exportName selectedOnly:TRUE
			else
				exportfile exportName #noPrompt selectedOnly:TRUE
			
			if (useobjpivot) then
				$.Position = OldPosition
				
			if (p == objList.count) then
				select OldSelection		--reselect old selection
			
		) --end for
	) --end if
) --end fn

fn DoMaxSave outputpath useobjpivot exportsel invertsel pfxb pfxbs pfxa pfxas = 
(
	if (outputpath != undefined) do
	(
		OldSelection = getCurrentSelection()
		if (not exportsel) then
			max select all
		else if (invertsel) then
			max select invert
		
		objList = getCurrentSelection()
		
		for p=1 to objList.count do
		(
			if (pfxb != "") then
				Prefix1 = pfxb + pfxbs
			else
				Prefix1 = ""
			if (pfxa != "") then
				Prefix2 = pfxas + pfxa
			else
				Prefix2 = ""
				
			saveName = outputPath + "\\" + Prefix1 + objList[p].name + Prefix2 + ".max"
			select objList[p]
			if (useobjpivot) do
			(
				OldPosition = $.Position
				$.position = [0,0,0]
			)
				max views redraw
				saveNodes selection saveName
			
			if (useobjpivot) then
				$.Position = OldPosition
			if (p == objList.count) then
				select OldSelection		--reselect old selection
				
		) --end for
	) --end if
) --end fn

fn DoPrefixToObject pfxb pfxbs pfxa pfxas =
(

		objList = getCurrentSelection()
		
		for p=1 to objList.count do
		(
				Prefix1 = pfxb + pfxbs
				Prefix2 = pfxas + pfxa
				
			ChangeNameTo = Prefix1 + objList[p].name + Prefix2
			select objList[p]
			
				$.name = ChangeNameTo
			
		) --end for
)

--Start GUI

rollout prefixpopup "Add Prefix To Object Name" width:446 height:130
(
	GroupBox grp48 "Prefix Warning" pos:[2,6] width:252 height:120
	label lbl164 "WARNING! You are about to add one or more Prefixes to the the names of all currently selected Objects. Are you sure you want to continue?" pos:[8,24] width:240 height:45
	button clickyes "Yes" pos:[96,88] width:64 height:24
	
	edittext newpfxb "" pos:[262,45] width:125 height:20
	GroupBox grp96 "AddPrefix" pos:[259,7] width:184 height:111
	edittext newpfxbs "" pos:[388,45] width:48 height:20
	label lbl308 "Prefix before name" pos:[265,29] width:100 height:16
	label lbl309 "Separator" pos:[387,29] width:48 height:16
	edittext newpfxa "" pos:[262,90] width:125 height:20
	edittext newpfxas "" pos:[388,90] width:48 height:20
	label lbl310 "Prefix after name" pos:[265,74] width:83 height:16
	label lbl311 "Separator" pos:[387,74] width:48 height:16
	
	on clickyes pressed do
	(
		DoPrefixToObject newpfxb.text newpfxbs.text newpfxa.text newpfxas.text
		--closeRolloutFloater prefixpopupgui
	)
	
	on clickno pressed do
	(
		closeRolloutFloater prefixpopupgui
	)
)

rollout base "Batch Export" width:188 height:480
(
	
	label lbl1 "Output Directory" pos:[4,32] width:105 height:16
	edittext outputpath "" pos:[0,48] width:156 height:20
	label lbl2 "Extension (ase=good .ase=bad)" pos:[4,80] width:159 height:16
	edittext editExt "" pos:[0,96] width:36 height:20
	button kExport "EXPORT" pos:[12,128] width:60 height:26
	checkbox useobjpivot "Checkbox" pos:[8,178] width:16 height:16 checked:true
	GroupBox grp1 "Output" pos:[2,8] width:184 height:113
	GroupBox grp2 "Modify" pos:[2,158] width:184 height:129
	label lbl12 "Use Object Pivot As Origin" pos:[24,178] width:129 height:16
	button DirLookUp "..." pos:[160,48] width:16 height:20
	checkbox exportsetup "Checkbox" pos:[8,198] width:16 height:16 checked:true
	label lbl25 "Configure Export Settings" pos:[24,198] width:129 height:16
	
	edittext pfxb "" pos:[5,355] width:125 height:20
	GroupBox grp15 "AddPrefix" pos:[2,317] width:184 height:111
	edittext pfxbs "" pos:[131,355] width:48 height:20
	label lbl40 "Prefix before name" pos:[8,339] width:100 height:16
	label lbl41 "Separator" pos:[130,339] width:48 height:16
	edittext pfxa "" pos:[5,400] width:125 height:20
	edittext pfxas "" pos:[131,400] width:48 height:20
	label lbl78 "Prefix after name" pos:[8,384] width:83 height:16
	label lbl79 "Separator" pos:[130,384] width:48 height:16
	
	checkbox exportsel "Checkbox" pos:[8,218] width:16 height:16 checked:true
	label lbl128 "Export Only Selected Meshes" pos:[24,218] width:147 height:16 enabled:true
	
	checkbox invertsel "Checkbox" pos:[8,238] width:16 height:16 checked:false
	label lbl129 "Invert Selection" pos:[24,238] width:129 height:16
	
	checkbox savemax "Checkbox" pos:[40,98] width:16 height:16 enabled:true checked:false
	label lbl193 "Save As .MAX file" pos:[56,98] width:90 height:16
	button savemaxbutton "Save .MAX files" pos:[88,128] width:80 height:26 enabled:false
	
	button prefix2object "Asign prefixes to object names" pos:[16,293] width:156 height:20
	
	on kExport pressed do
	(
		if (outputpath.text == "" and editExt.text == "") then
			messagebox("Please specify an output directory and a file extension.")
		else if (outputpath.text == "") then
			messagebox("Please specify an output directory.")
		else if (editExt.text == "") then
			messagebox("Please specify a file extension.")
		else if (not doesFileExist outputpath.text) then
			messagebox("'" + outputpath.text + "'" + " does not exist, please enter a valid output directory.")
		else
			DoExport outputpath.text editExt.text useobjpivot.state exportsetup.state exportsel.state invertsel.state pfxb.text pfxbs.text pfxa.text pfxas.text
	)
	on DirLookUp pressed do
	(
		outputpath.text = getSavePath "Save to:"
	)
	on exportsel changed state do
	(
		if (exportsel.checked == true) then
		(
			invertsel.enabled = true
		)
		else
		(
			invertsel.enabled = false
			invertsel.checked = false
		)
	)
	on savemax changed state do
	(
		if (savemax.checked == true) then
		(
			editExt.enabled = false
			savemaxbutton.enabled = true
			kExport.enabled = false
		)
		else
		(
			editExt.enabled = true
			savemaxbutton.enabled = false
			kExport.enabled = true
		)
	)
	on savemaxbutton pressed do
	(
		if (outputpath.text == "") then
			messagebox("Please specify an output directory.")
		else if (not doesFileExist outputpath.text) then
			messagebox("'" + outputpath.text + "'" + " does not exist, please enter a valid output directory.")
		else
			DoMaxSave outputpath.text useobjpivot.state exportsel.state invertsel.state pfxb.text pfxbs.text pfxa.text pfxas.text
	)

	on prefix2object pressed do
	(
		prefixpopupgui = newRolloutFloater "Prefix to Object" 454 164
		addRollout prefixpopup prefixpopupgui
	)

)


rollout info "info/contact" width:188 height:430
(
	GroupBox grp48 "Contact" pos:[2,6] width:184 height:79
	label lbl160 "author:" pos:[8,21] width:160 height:16
	label lbl161 "Kurt'commander_keen'Loeffler" pos:[8,35] width:160 height:16
	label lbl162 "email:" pos:[9,49] width:160 height:16
	label lbl163 "kurtloeffler@gmail.com" pos:[9,63] width:162 height:16
	GroupBox grp53 "Info" pos:[2,97] width:184 height:306
	label lbl164 "This MaxScript started out as a simple test that would allow you to export objects using their pivot as the scene origin(so if you had 5 objects scattered around the scene it would move them to 0,0,0 for export then move them back after export is done).I got a request for batch operations in the script and thought that would be a nice feature so i did some research on that and now the script allows you to batch export to any format that 3ds max supports and use the scene object name as the file name. You can choose to export only selected (or unselected) objects, or export all objects in the scene. It also allows you to add prefixes to the beginning and/or end of the file name on export, or add them to the scene object name." pos:[8,112] width:170 height:289
)

gui = newRolloutFloater "BatchExport" 192 480
addRollout base gui
addRollout info gui

)
And readme:

Code: Select all

----------------------------------------------------------

Batch exports all selected models as .ASE individually.
Places objects at 0,0,0 automatically and puts them back to their original position. (Make sure that your pivot point is correct!)
Uses object name as .ASE filename
Can add prefixes to the filename

How to use : Put in Max\Scripts 
Once in Max, Top menu > MaxScript > Run Script > select file and run. Then Top menu > Customize > Customize User Interface -> Toolbars -> Search for Keenbatchexport and drag to a toolbar, (example deafault top toolbar) Click new button

----------------------------------------------------------

Additionals notes in the KeensBatchExporter.ms (can be opened with notepad)
Image
User avatar
Phasmatis
Off Topic Productions
Off Topic Productions
Posts: 2057
Joined: Sun Apr 25, 2004 7:55 am
Location: UK
Contact:

Re: Importance Max script for Unreal v1.0 model imports.

Post by Phasmatis »

If I read that right, unfortunately that isn't how it works. I'll use a weapon as an example.

You have the weapon, hands/arms and muzzle flash, each of these are a separate material, so one texture for the weapon, one for the hand/arms and one for the muzzle flash. Each of these can be separate objects (in max) but that will make it more complicated later on, personally I attach everything together so it's all one object. You then rig that object with bones and animate it.

Once everything is animated all you need to do is select just the mesh and use the snapshot tool, delete the original mesh and bones and you're left with a mesh for each frame. So once finished you should only be left with 60 or so meshes in the scene dependant on how many frames there are in the animation. Then you export the entire scene to a .3ds file and use 3ds2de to convert it to a readable format for Deus Ex. You don't want or need to export every frame into it's own file it wouldn't work with 3ds2de.
Keeper of the pointy stick of injustice™.
User avatar
Dead-eye
X-51
Posts: 944
Joined: Tue Apr 25, 2006 3:45 am
Location: Santa Cruz, California

Re: Importance Max script for Unreal v1.0 model imports.

Post by Dead-eye »

Phasmatis wrote:If I read that right, unfortunately that isn't how it works. I'll use a weapon as an example.

You have the weapon, hands/arms and muzzle flash, each of these are a separate material, so one texture for the weapon, one for the hand/arms and one for the muzzle flash. Each of these can be separate objects (in max) but that will make it more complicated later on, personally I attach everything together so it's all one object. You then rig that object with bones and animate it.

Once everything is animated all you need to do is select just the mesh and use the snapshot tool, delete the original mesh and bones and you're left with a mesh for each frame. So once finished you should only be left with 60 or so meshes in the scene dependant on how many frames there are in the animation. Then you export the entire scene to a .3ds file and use 3ds2de to convert it to a readable format for Deus Ex. You don't want or need to export every frame into it's own file it wouldn't work with 3ds2de.
Hmmmm... really? I seem to remember needing to do this for models back in the day... maybe 3ds2de has more functionality then older versions used for unreal?
Image
User avatar
Phasmatis
Off Topic Productions
Off Topic Productions
Posts: 2057
Joined: Sun Apr 25, 2004 7:55 am
Location: UK
Contact:

Re: Important Max script for Unreal v1.0 model imports.

Post by Phasmatis »

Nope, it's been like that since Unreal1. You can have separate *sequences* though. I'll use a weapon as an example again. You can animate a sequence say "idle1" snapshot it and export those frames as idle1.3ds, do the same for all the other sequences and then import them all with 3ds2de, that will put the sequence names in the class for easier coding but that's the only reason to do it imo.
Keeper of the pointy stick of injustice™.
User avatar
Dead-eye
X-51
Posts: 944
Joined: Tue Apr 25, 2006 3:45 am
Location: Santa Cruz, California

Re: Important Max script for Unreal v1.0 model imports.

Post by Dead-eye »

Hmmm... interesting. In the VTM's from 3d buzz they say that you need to do that with every frame of animation... they even wright some code to do it for you but I guess they got it wrong or something.

As a question if you have more then one object in a scene how would you go about exporting that? Will Unreal see that there is 2 objects with animations in the scene because the object names are different or is this something to be avoided?
Image
User avatar
Phasmatis
Off Topic Productions
Off Topic Productions
Posts: 2057
Joined: Sun Apr 25, 2004 7:55 am
Location: UK
Contact:

Re: Important Max script for Unreal v1.0 model imports.

Post by Phasmatis »

You can only export one model which is why I said earlier...
Phasmatis Teh Great wrote: ...Each of these can be separate objects (in max) but that will make it more complicated later on...
Because if you have two objects in the scene and snapshot has been used on both objects you get two lots of meshes. You then have to attach each object to corresponding object, so if it's a gun, the hand is one object called "Hand" and the gun is another object called "Gun" you then need to attach "Hand01" to "Gun01", "hand02" to "Gun02" etc you can make a script for doing that, I had one years ago before I started using bones but I find using bones much easier personally.

The peeps on 3dBuzz may be talking about an updated exporter, I think there was one that did everything from Max so it may have been more efficient, it was a long long time ago when I edited unreal but 3ds2de will curse you if you try to use two objects in the same model.
Keeper of the pointy stick of injustice™.
User avatar
Yachs
Thug
Posts: 19
Joined: Thu Nov 04, 2010 10:37 am

Re: Important Max script for Unreal v1.0 model imports.

Post by Yachs »

your script dosnt work on max 9. It is save model in 3d format?
Image
Post Reply