[Tutorial] Import MESH into 3DS MAX

TaylorMouseTaylorMouse Posts: 70
edited November 2014 in General Modding
3DS Max Importscript for OgreXML ( beta )

I'm a 3D Studio Max user and did not find anything on importing a Ogre MESH model !
So when I read that it could be converted to XML ( readable but hugh ) I decided to do a little scripting.

And the result is as follows ( after a few hours of trial and error )

Screen01.png


OgreCommandLineTools -> http://www.ogre3d.org/download/tools
Autodesk 3D Studio Max -> http://usa.autodesk.com/adsk/servlet/pc ... eID=123112
My Import Script -> http://users.telenet.be/u122561/downloa ... OgreXml.ms

So how it works:

1. Open the Pack.zip
2. choose a MESH file and extract it
3. convert the MESH file with the OgreXmlConverter.exe to an XML file ( just drag the MESH file on the exe )
example:
Alchemist.MESH -> Achemist.MESH.xml
4. Open Max
5. Select Run Max Script and select my script
6. It asks for a xml file -> select the Alchemist.MESH.xml
7. Wait a few seconds
8. Apply the texture on the Alchemist ( it is the body.png )

NOTE: It may be required to download dds support for MAX from the NVIDIA website to support dds files in MAX ( but I think it is supported in the later versions )


TODO:
1. The xml file format support different sets of formats when it comes to uv mappings and normals, for example the weapons have another file format then the characters. This needs to be added !
2. The bones are not imported ( yet )
3. No animation is done ( yet ) -> for that I need to figure out how to decrypt the ANIMATION files.

But for now, on a one nights works, it is starting to look good.

Imput is ALWAYS welcome.

Hope you can enjoy for

T.
9757-albums2216-picture19549.png
9757-albums2216-picture19984.png
«134567

Comments

  • I'm getting an Error when importing the .xml file

    -- Type error: Call needs function or class, got: undefined

    I tried it on 3 pc 32 and 64 bit versions.

    Max Version: 2009 SP1
  • TiptoeTiptoe Posts: 184
    You are the man! Bless you TaylorMouse!

    I've been searching for some type of 3DS Max importer for the past few days. I found the OgreXMLconverter (which works a treat by the way) but I still had no way to import the .xml files into Max.

    As far as I know, the only way to convert ogre .xml files into a format Max can read, is to use either 3D Object Converter or Ultimate Unwrap 3D (but those programs cost more than Torchlight itself :shock:).

    So this script is wonderful! Thankyou so much!

    I'm going to try it out right now :mrgreen: .
  • What max version are you using TipToe?
  • TiptoeTiptoe Posts: 184
    Monkeynutz wrote:
    I'm getting an Error when importing the .xml file

    -- Type error: Call needs function or class, got: undefined

    Uh oh! I just got the same error :(.

    I just tried using it in Max 8 (32 bit Windows XP). I really wish I could help you, but I know nothing about programming. Still, if you need the error logs or anything, just give a shout, I'll try to help you in any way I can.
  • Which xml file are you guys using ?

    did you try the alchemist ?

    btw I'm only got the Demo version ( if that has anything to do with it )

    that log, yep send it to me

    open the max script listener and run the script, post the error message from there plz

    T.
    9757-albums2216-picture19549.png
    9757-albums2216-picture19984.png
  • VravVrav Posts: 66
    Very nice, good sir! I've been using Blender's OGRE mesh import plugin, and then exporting things to obj. Good for previewing textures on characters, though I could see the reverse of that method working for importing new statics or weapons, since you're not going to mess up the rig on those.

    Maybe you can learn something from the OGRE tools that already exist for Blender.
    http://www.ogre3d.org/wiki/index.php/Tools:_Blender
  • TiptoeTiptoe Posts: 184
    Ok, I just tried it again with the Alchemist model (I tried it with the Vanquisher before) but no luck, still got the same error message :( .

    Anyway, here is the error log:
    Welcome to MAXScript.
    
    SiegeMax is launching from:
    
    C:\Program Files\Dungeon Siege II Tool Kit\SiegeMax\Plugins8\..\..\SiegeMax\Scripts/startup.ms
    
    Launching SiegeMax version 0002.0038
    Deleting macroscripts and Quad Menu items in category [Siege Max Tools]
    Macroscript category [Siege Max Tools] has been set up for housekeeping
    Removing Stale Menu: Context SiegeMax Tools 1
    Removing Stale Menu: Context SiegeMax Tools 2
    -- Error occurred in anonymous codeblock
    --  Frame:
    --   nbrFaces: undefined
    --   vertex_array: undefined
    --   face_array: undefined
    --   aSubMesh: undefined
    --   nbrVertexes: undefined
    --   file_stream: <File:C:\Documents and Settings\Gigabyte User\My Documents\Torchlight Files\Alchemist.MESH.xml>
    --   strLine: "        <submesh material="Starter_Set/boots" usesharedvertices="false" use32bitindexes="false" operationtype="triangle_list">"
    --   getAttribute: undefined
    --   normal_array: undefined
    --   meshName: undefined
    --   textCoord_array: undefined
    --   trimmed: "<submesh material="Starter_Set/boots" usesharedvertices="false" use32bitindexes="false" operationtype="triangle_list">"
    -- Error occurred during fileIn in <File:C:\Program Files\Autodesk\3dsMax8\Scripts\ImportOgreXml.ms>
    >> MAXScript FileIn Exception: -- Type error: Call needs function or class, got: undefined <<
    

    As you can see, I have SeigeMax installed (for modding Dungeon Seige) could that be the problem?

    Also, I put the ImportOgreXml.ms script into the 'Scripts' folder. Is that the right location?

    Thanks again TaylorMouse. If you can get this working it's going to make a lot of people very happy, not just in the Torchlight community, but the Ogre folks as well :mrgreen:
  • I didn't have the time to investigate it yesterday,
    the script does not have to be in the scripts folder, you can select it from where you want, I didn't test it with the Dungeon Siege tool tho

    try this:
    instead of clicking Run Script, press the button, Open Script
    then press <cntrl> + <e>, this will evaluate the script and open a dialogue box to select your xml file.

    could you test this for me ?

    thnx

    T.
    9757-albums2216-picture19549.png
    9757-albums2216-picture19984.png
  • TiptoeTiptoe Posts: 184
    Okie dokie, just did as you asked. No Error message this time (in fact I had a blue OK message in the maxscript listener window) but unfortunately no model was imported :( .

    Here is the log:
    -- Created by Taylor Mouse 
    -- (c) 2009
    -- Imports a OgreXML mesh
    
    -- Written for 3D Studio Max 7.0 and above
    
    -- EXAMPLE
    -- &lt;mesh&gt;
    -- 	&lt;submeshes&gt;
    --    &lt;submesh material="Starter_Set/boots" usesharedvertices="false" use32bitindexes="false" operationtype="triangle_list"&gt;
    --      &lt;faces count="282"&gt;
    --        &lt;face v1="0" v2="1" v3="2" /&gt;
    -- 		  ....
    --		&lt;/faces&gt;
    --		&lt;geometry vertexcount="262"&gt;
    --        &lt;vertexbuffer positions="true" normals="true"&gt;
    --          &lt;vertex&gt;
    --            &lt;position x="0.0900497" y="0.617301" z="0.0876787" /&gt;
    --            &lt;normal x="-0.87242" y="0.127848" z="0.47174" /&gt;
    --          &lt;/vertex&gt;		
    --			...
    -- 		  &lt;/vertexbuffer&gt;
    --		  &lt;vertexbuffer texture_coord_dimensions_0="2" texture_coords="1"&gt;
    --		    &lt;vertex&gt;
    --            &lt;texcoord u="0.539437" v="0.841156" /&gt;
    --		  	&lt;/vertex&gt;
    --			...
    
    -- TODO -&gt; BONE STUFF COMES HERE
    
    --		&lt;/geometry&gt;
    -- 	&lt;/submeshes&gt;
    
    -- &lt;mesh&gt;
    
    
    
    --1. Open the file dialogue to ask for the file
    
    file_Name = getOpenFileName CAPTION:"Select Ogre XML file." \
    						   TYPES:"Ogre XML(*.xml)|*.xml|All files(*.*)|*.*"
    					
    
    -- 2. Open the file for reading
    if file_Name != undefined then
    (
    	file_stream = openFile file_Name
    	if file_stream != undefined then
    	(
    		strLine = readLine file_stream		
    	
    		-- 3. Check if this file in a correct format
    		if strLine == "&lt;mesh&gt;" then
    		(
    			-- 4. Keep reading until it hits the closing mesh tag
    			while strLine != "&lt;/mesh&gt;" do
    			(
    				strLine = READLINE file_stream
    				trimmed = TRIMLEFT strLine
    			
    				if SUBSTRING trimmed 1 16 == "&lt;sharedgeometry " then
    				(
    					nbrVertexes = GetAttribute trimmed "vertexcount"
    					nbrVertexes = nbrVertexes as integer
    
    
    -- !!!!! TODO check if the uv coordinates  are at the vertex level or if they are seperate !!!!! -----------------
    
    
    					-- 10. Get the vertex data
    					vertex_array = #()
    					normal_array = #()
    					vertex_array.count = nbrVertexes
    					normal_array.count = nbrVertexes
    					
    					strLine = READLINE file_stream -- &lt;vertexBuffer&gt;
    					
    					for v = 1 to nbrVertexes do
    					(
    						strLine = READLINE file_stream -- &lt;vertex&gt;
    						strPosition = READLINE file_stream -- &lt;position&gt;
    						strNormals = READLINE file_stream -- &lt;normals&gt;
    
    						strPosition = TRIMLEFT strPosition
    						strNormals = TRIMLEFT strNormals
    
    						p1 = GetAttribute strPosition "x"
    						p2 = GetAttribute strPosition "z"
    						p3 = GetAttribute strPosition "y"						
    						
    						p1 = p1 as float
    						p2 = p2 as float
    						p3 = p3 as float
    						
    						vertex_array&#91;v&#93; = POINT3 p1 p2 p3
    						
    						p1 = GetAttribute strNormals "x"
    						p2 = GetAttribute strNormals "y"
    						p3 = GetAttribute strNormals "z"						
    						
    						p1 = p1 as float
    						p2 = p2 as float
    						p3 = p3 as float
    						
    						normal_array&#91;v&#93; = POINT3 p1 p2 p3
    
    						strLine = READLINE file_stream -- &lt;/vertex&gt;
    
    					) 
    					
    					strLine = READLINE file_stream -- &lt;/vertexBuffer&gt;
    					
    					-- 11. Read the texture coordinates
    					textCoord_array = #()
    					textCoord_array.count = nbrVertexes
    
    					
    					strLine = READLINE file_stream -- &lt;vertexbuffer texture_coord&gt;
    					for t = 1 to nbrVertexes do
    					(
    						strLine = READLINE file_stream -- &lt;vertex&gt;
    
    						strCoord = READLINE file_stream -- &lt;uv&gt;
    						strCoord = TRIMLEFT strCoord
    						
    						tu = GetAttribute strCoord "u"
    						tv = GetAttribute strCoord "v"
    						
    						tu = tu as float
    						tv = 1 - tv as float
    						
    						textCoord_array&#91;t&#93; = POINT3 tu tv 0.0
    						
    						strLine = READLINE file_stream -- &lt;/vertex&gt;
    					)
    	
    				)
    				
    			
    				-- 5. This requires a new 3D mesh object
    				if SUBSTRING trimmed 1 9 == "&lt;submesh " then
    				(
    					-- 6. Get the mesh name
    					meshName =  GetAttribute trimmed "material"
    					print meshName 
    					
    					strLine = READLINE file_stream
    					trimmed = TRIMLEFT strLine
    					
    					-- 7. Get the number of faces
    					nbrFaces = GetAttribute trimmed "count"
    					nbrFaces = nbrFaces as number
    
    					face_array = #()
    					face_array.count = nbrFaces
    
    					-- 8. Get the face data
    					for f = 1 to nbrFaces do
    					(
    						strLine = READLINE file_stream
    						trimmed = TRIMLEFT strLine
    						
    						v1 = GetAttribute trimmed "v1"
    						v2 = GetAttribute trimmed "v3"
    						v3 = GetAttribute trimmed "v2"
    
    						v1 = v1 as float + 1
    						v2 = v2 as float + 1
    						v3 = v3 as float + 1 
    
    						face_array&#91;f&#93; = POINT3 v1 v2 v3
    					)
    					strLine = READLINE file_stream
    					
    					-- 9. Get the number of vertices/normals
    					strLine = READLINE file_stream -- &lt;geometry&gt;
    					trimmed = TRIMLEFT strLine
    					
    					nbrVertexes = GetAttribute trimmed "vertexcount"
    					nbrVertexes = nbrVertexes as integer
    
    
    					if nbrVertexes != undefined then
    					(
    					
    						-- 10. Get the vertex data
    						vertex_array = #()
    						normal_array = #()
    						vertex_array.count = nbrVertexes
    						normal_array.count = nbrVertexes
    						
    						strLine = READLINE file_stream -- &lt;vertexBuffer&gt;
    						
    						for v = 1 to nbrVertexes do
    						(
    							strLine = READLINE file_stream -- &lt;vertex&gt;
    							strPosition = READLINE file_stream -- &lt;position&gt;
    							strNormals = READLINE file_stream -- &lt;normals&gt;
    	
    							strPosition = TRIMLEFT strPosition
    							strNormals = TRIMLEFT strNormals
    	
    							p1 = GetAttribute strPosition "x"
    							p2 = GetAttribute strPosition "z"
    							p3 = GetAttribute strPosition "y"						
    							
    							p1 = p1 as float
    							p2 = p2 as float
    							p3 = p3 as float
    							
    							vertex_array&#91;v&#93; = POINT3 p1 p2 p3
    							
    							p1 = GetAttribute strNormals "x"
    							p2 = GetAttribute strNormals "y"
    							p3 = GetAttribute strNormals "z"						
    							
    							p1 = p1 as float
    							p2 = p2 as float
    							p3 = p3 as float
    							
    							normal_array&#91;v&#93; = POINT3 p1 p2 p3
    	
    							strLine = READLINE file_stream -- &lt;/vertex&gt;
    	
    						)
    						strLine = READLINE file_stream -- &lt;/vertexBuffer&gt;
    						
    						-- 11. Read the texture coordinates
    						textCoord_array = #()
    						textCoord_array.count = nbrVertexes
    	
    						
    						strLine = READLINE file_stream -- &lt;vertexbuffer texture_coord&gt;
    						for t = 1 to nbrVertexes do
    						(
    							strLine = READLINE file_stream -- &lt;vertex&gt;
    	
    							strCoord = READLINE file_stream -- &lt;uv&gt;
    							strCoord = TRIMLEFT strCoord
    							
    							tu = GetAttribute strCoord "u"
    							tv = GetAttribute strCoord "v"
    							
    							tu = tu as float
    							tv = 1 - tv as float
    							
    							textCoord_array&#91;t&#93; = POINT3 tu tv 0.0
    							
    							strLine = READLINE file_stream -- &lt;/vertex&gt;
    						)
    						
    						
    						strLine = READLINE file_stream -- &lt;/vertexbuffer texture_coord&gt;
    						strLine = READLINE file_stream -- &lt;/geometry&gt;
    					)
    					
    					
    					-- 12. Build the mesh
    					aSubMesh = MESH  VERTICES:vertex_array FACES:face_array TVERTS:textCoord_array
    					aSubMesh.Name = meshName
    					UPDATE aSubMesh
    					
    					--13. Build the faces
    					BUILDTVFACES aSubMesh FALSE
    			
    					--14. Set the UVW coordinates to the faces.
    					for i = 1 to face_array.count do
    					(
    						SETTVFACE aSubMesh i face_array&#91;i&#93;
    					)
    					UPDATE aSubMesh
    					
    					
    					-- 15. TODO THE BONES !!!!!!!!!!!!
    					
    					
    					
    				)
    				
    				
    				
    			)
    		)
    		else
    		(
    			print "File is not in the correct format."
    		)
    		close file_stream
    	)
    )
    
    
    --// the following function gets the attribute from the element
    fn GetAttribute  xmlElement xmlAttribute =
    (
    	if FINDSTRING xmlElement xmlAttribute == 0 then return 
    	
    	print xmlElement 
    	
    	attributePos      = FINDSTRING xmlElement xmlAttribute
    	if attributePos == undefined then return "ERROR"
    	attributeStartPos = attributePos + xmlAttribute.count + 2
    	attributeOffset   = xmlElement.count - attributeStartPos
    	
    	if attributeOffset &lt; 0 then return 
    	
    	attributeTemp     = SUBSTRING xmlElement attributeStartPos attributeOffset
    	attributeLength   = FINDSTRING attributeTemp "\""
    	attributeLength   = attributeLength - 1
    	strAttributeValue = SUBSTRING attributeTemp 1 attributeLength
    
    	return strAttributeValue
    )
    
    
    

    Hope this helps. Let me know if there's anything else you need.
  • SiENcESiENcE Posts: 9
    The Ogre Wiki is a very good source!

    All Ogre Exporters
    http://www.ogre3d.org/wiki/index.php/OGRE_Exporters

    Content Creation Tools
    http://www.ogre3d.org/wiki/index.php/DCC_Tools

    3DS to Mesh
    -> http://www.ogre3d.org/wiki/index.php/3DS2Mesh (win download here)

    Lexiexporter (LEXIExporter is a native plugin for 3DSMax9)
    -> http://www.ogre3d.org/wiki/index.php/LEXIExporter

    and of couse oFusion Community Edition 1.8.6
    for Max 7/8/9
    http://www.ofusiontechnologies.com/downloads.html
  • Hey Tiptoe, that is my script you pasted there :)

    anyway, did you zoom in very close, cause the model is only about 1or 2 units high !

    T.
    9757-albums2216-picture19549.png
    9757-albums2216-picture19984.png
  • TiptoeTiptoe Posts: 184
    Yep, I just tested it again, no objects were imported into the scene. I even tried the 'Select by Name' feature, but the object list was empty :( .
  • I managed to Import Models into 3ds max 2009.

    First drop a model.Mesh into OgreXMLconverter (just drag into the .exe) and it converts to model.Mesh.Xml

    Then open model.Mesh.Xml with 3d Object Converter

    Once open you can view the model there and convert to another file format.
    (Note The Demo version of 3d Object Converter doesn't allow you to convert, you need the full version.)

    File formats that worked for me:
    .3ds
    .ms
    .prj

    Im not getting the UV cords tough..
  • TiptoeTiptoe Posts: 184
    I did look at 3D Object Converter http://web.axelero.hu/karpo/ but it costs $50 :shock:.

    So I think TaylorMouse's script is the best way to go, especially if he can figure out how to import both the mesh and the animation files *crosses fingers*.
  • You dont always have to pay for everything :twisted:

    Just be creative
  • moosemoose Posts: 15
    Question for the Runic guys:

    Will it be necessary to go through the process of using these user-created scripts to convert & save new meshes for use in full-content mods? Will torchEd include the plugins required for saving .MESH files straight from Max, or convering a .ase, obj, 3ds into .MESH, as well as the .ANIMATION files, etc?

    You guys mentioned the content that will be included with the editor, just wanted to see if there will be plugins/scripts included with that 3dsMax content that will allow for easy saving of files for asset creation in mods.

    not saying that the efforts of the community aren't something i want to capitalize on, just wondering if we'll get official tools for 3ds Max mesh exporting.

    thanks!
  • travisbaldreetravisbaldree Posts: 1,665 ✭✭✭✭
    We will be including our official MAX exporters -
    We're also giving you all the raw max files and animations for the player classes and their wardrobes, as well as a few monsters, a full tileset, and some weapons and props.
  • VravVrav Posts: 66
    We will be including our official MAX exporters
    Yessss.

    ... bit off topic for the thread, but been meaning to ask: will it be possible to download the editor without all the working-res artwork? I keep hearing "it's twice as big a download as the game" and honestly I don't know if I want the art again. I mean, can live with it, but yes. Guess it would be good reference.

    You guys keep mentioning that the editor is "free" - does that mean people who don't buy the game can download it? So basically, the $20 was just for the campaign you guys made. Iiinteresting.
  • I'm back home so I will be purchasing the game in a few moments, and then I'll try again, with MAX 2009

    I'll keep you informed as soon as I got it to work there.

    btw thnx travisbaldree

    T.
    9757-albums2216-picture19549.png
    9757-albums2216-picture19984.png
  • SoberseanSobersean Posts: 513
    Vrav wrote:
    We will be including our official MAX exporters
    Yessss.

    ... bit off topic for the thread, but been meaning to ask: will it be possible to download the editor without all the working-res artwork? I keep hearing "it's twice as big a download as the game" and honestly I don't know if I want the art again. I mean, can live with it, but yes. Guess it would be good reference.

    You guys keep mentioning that the editor is "free" - does that mean people who don't buy the game can download it? So basically, the $20 was just for the campaign you guys made. Iiinteresting.

    In case Travis is gone, I heard them talk about posting the various assest in thier respective "folders" for download, separately from the download of the editor. At least that was the plan they were mentioning during one of the live streams from last weekend.
    Arguing over a video game? That's just silly.
  • Ok I changed the script a bit so you can test it again, this time I tested it on MaX 2009 , hopefully this time it works :P


    get it here http://users.telenet.be/u122561/downloads/ImportOgreXml.ms

    T.
    9757-albums2216-picture19549.png
    9757-albums2216-picture19984.png
  • heronheron Posts: 637
    We will be including our official MAX exporters -
    We're also giving you all the raw max files and animations for the player classes and their wardrobes, as well as a few monsters, a full tileset, and some weapons and props.

    thank you sir.
  • MiXeRMiXeR Posts: 27
    We will be including our official MAX exporters -
    We're also giving you all the raw max files and animations for the player classes and their wardrobes, as well as a few monsters, a full tileset, and some weapons and props.

    This message must have been sent from above... it's... almost, too good to be true ^^
    I'm gonna keep on trying to make my own classes until i succeed (: But first I'm gonna create my own weapons just to get back into 3ds max again and learn how the editor works a bit.
  • Thanks for the script, Taylor. I tried the new one you uploaded and was still getting an error but I got it to work by renaming it 'ImportOgreXml2.ms'
  • TiptoeTiptoe Posts: 184
    Ok I've just tested the new script in 3DS Max 8 and 3DS Max 2010. But I still get the same error message in both :( .

    So I tried renaming it to ImportOgreXml2.ms (as SirDerpington suggested) but sadly, this didn't make any difference for me.

    One interesting thing I did note, the 3DS Max 2010 error log highlighted this line:

    Meshname = GetAttribute trimmed "material"

    maxerror.jpg

    Could this line be the culprit? When I converted the Alchemist.mesh to an .xml file I copied the .mesh file to a different folder before converting it, I didn't copy any material files or anything else (it was just the .mesh file). Did I mess up the conversion process?
  • weird, I know that not all the xml files are the same, and it blocks when the uv coordinates are together with the rest of the vertex coordinates,
    anyway, could you save the file and rename it like Derpington said ?

    I don't know how it would be possible that it would work all of a sudden after saving, but hey if that would do the trick ??

    T.
    9757-albums2216-picture19549.png
    9757-albums2216-picture19984.png
  • TiptoeTiptoe Posts: 184
    anyway, could you save the file and rename it like Derpington said ?

    I'm not sure how to re-save a maxscript file (I can use 'em, but I dunno how to write 'em :roll:). Is this done from within 3DS Max itself?
  • TiptoeTiptoe Posts: 184
    Nevermind, I figured it out :D.

    I re-saved it as ImportOgreXml3.ms, but sadly it still didn't work. It gave me the same error message.
  • hey guys and gals :)

    I guess just like you guys I am keen to get modding, so when I saw this thread I jumped right in and gave the scripts a blast.. I've also had the same error messages that others seem to have been getting, and I think I have found the problem.

    the problem lies not with the script, but with the xml files themselves. the line

    meshName = GetAttribute trimmed "material"

    is sometimes getting characters such as / and # from the xml, and I dont think it likes it :P So, I went I made a copy of the xml file I wanted to open, and changed all of the lines such as

    <submesh material="Material_#1/boots" usesharedvertices="false" use32bitindexes="false"

    to something it might be more happier to chew on, such as

    <submesh material="ohyeah" usesharedvertices="false" use32bitindexes="false"

    and this seems to have done the trick. hope this helps you guys, and looking forward to seeing the crazy creations the mod community make for this fine game
  • BflerBfler Posts: 2
    Is there a way to export a model back into the game. I edited the vanquisher model a bit and exported it with ogremax exporter back into the game folder but with that the game crashes every time I switch to the character creation screen.
«134567
Sign In or Register to comment.