Create XML exporter?

Create XML exporter?

jeffmorris
Advocate Advocate
1,978 Views
8 Replies
Message 1 of 9

Create XML exporter?

jeffmorris
Advocate
Advocate

Is it possible to create an XML exporter so that the Trainz Mesh Importer can import *.XML files and export *.IM files?

 

http://online.ts2009.com/mediaWiki/index.php/Trainz_Mesh_Importer

0 Likes
1,979 Views
8 Replies
Replies (8)
Message 2 of 9

jeffmorris
Advocate
Advocate

There is a tutorial at http://help.autodesk.com/view/3DSMAX/2016/ENU//?guid=__files_GUID_537409FE_EF5B_4E02_8261_456F74134C... showing me how to create an exporter using MAXScript.

If I want to write a string to a file, I get two results:

 

print "trainzImport" to:out_file

 

result: "trainzInput"

 

out_text = "trainzInput"

format "%\n" out_text to:out_file

 

result: trainzInput

 

How do I use:

 

print "trainzImport" to:out_file

 

and have the file show:

 

trainzInput

 

and not:

 

"trainzInput"

 

0 Likes
Message 3 of 9

jeffmorris
Advocate
Advocate

Will someone PLEASE help me write XML exporter for Trainz?

0 Likes
Message 4 of 9

paulneale
Advisor
Advisor

Have you ever seen my dotNet help page for Max?

 

http://www.penproductions.ca/tutorials/dotNet/dotNet.htm

 

and more specifically

 

http://www.penproductions.ca/tutorials/dotNet/xml/xml.htm

 

Does that get you what you are looking for?

Paul Neale

http://paulneale.com


Paul Neale




EESignature

0 Likes
Message 5 of 9

jeffmorris
Advocate
Advocate

How do I install and set up 3DS MAX 2016 SDK for Visual Studio 2013 or 2015?

 

Paul, I think that something is wrong with the forum on your PEN Productions website.

0 Likes
Message 6 of 9

paulneale
Advisor
Advisor

The forums don't work but those links should. They are just pages on my site. Follow tutorials link on the left if they don't for some reason. 

 

You don't need Visual Studio installed as it is a Max Script solution. 

Paul Neale

http://paulneale.com


Paul Neale




EESignature

0 Likes
Message 7 of 9

jeffmorris
Advocate
Advocate

I started writing the XML exporter. How do I remove the square brackets from the verticles? I want this line:

 

format "%%%\n" "<position>" (getVert tmesh v) "</position>" to:out_file

 

to output the following line:

 

<position>-7.5,-7.5,15</position>

 

and not

 

<position>[-7.5,-7.5,15]</position>

 

The Trainz Mesh Importer expects a triangle mesh with three verticles.

 

 

 

macroScript TrainzExport category: "HowTo"
(
fn GetGeometry o = (
 Superclassof o == Geometryclass and classof o != TargetObject )
obj = pickobject filter:GetGeometry
if isValidNode obj then
(
 tmesh =snapshotAsMesh obj
 out_name = GetSaveFileName()
 if out_name != undefined then
 (
  out_file = createfile out_name
  format "%\n" "<trainzImport>" to:out_file 
  format "%\n" "<version>1</version>" to:out_file
  format "%\n" "<mesh>" to:out_file
  format "%\n" "<triangles>" to:out_file
  num_verts = tmesh.numverts
  num_faces = tmesh.numfaces
  for v = 1 to num_verts do
  (	  
  format "%\n" "<triangle>" to:out_file
  format "%\n" "<vertex>" to:out_file
  format "%%%\n" "<position>" (getVert tmesh v) "</position>" to:out_file
  format "%\n" "</vertex>" to:out_file
  format "%\n" "</triangle>" to:out_file
  )
  format "%\n" "</triangles>" to:out_file
  format "%\n" "</mesh>" to:out_file
  format "%\n" "</trainzImport>" to:out_file   
  close out_file
  edit out_name
 )--end if
)--end if
)--end macroscript
<trainzImport>
   <version>1</version>
 
   <mesh>                                
     <name>m.tiny</name>
     <triangles>
       <triangle>
         <materialId>0</materialId>
         <vertex>
           <position>0,0,2</position>
           <texcoord>0,0</texcoord>
         </vertex>
         <vertex>
           <position>10,0,2</position>
           <texcoord>1,0</texcoord>
         </vertex>
         <vertex>
           <position>10,10,2</position>
           <texcoord>1,1</texcoord>
         </vertex>
       </triangle>
     </triangles>
   </mesh>
 
   <materials>
     <material>
       <name>BrickWall</name>
       <id>0</id>
       <diffuse>1,1,1</diffuse>
        <textures>
         <texture>
           <textureName>c:/textures/brick.tga</textureName>
           <typeName>diffuse</typeName>
         </texture>
       </textures>        
     </material>
   </materials>
 
 </trainzImport>
0 Likes
Message 8 of 9

paulneale
Advisor
Advisor
You have definitely done this the hard way. Dotnet/ MaxScript would be a far better solution and my example shows you exactly how to do this.

What you are looking for is position.x, position.y, position .z
Paul Neale

http://paulneale.com


Paul Neale




EESignature

0 Likes
Message 9 of 9

jeffmorris
Advocate
Advocate
tmesh = snapshotAsMesh selection[1]
out_name = ((GetDir #export)+"/testmesh.dat")
out_file = createfile out_name
num_verts = tmesh.numverts
num_faces = tmesh.numfaces
format "%,%\n" num_verts num_faces to:out_file
for v = 1 to num_verts do
(
 vert = getVert tmesh v
 format "%" vert to:out_file
)
format "\n" to:out_file
for f = 1 to num_faces do
(
 face = getFace tmesh f
 format "%" face to:out_file
)
close out_file
delete tmesh
edit out_name

The code above came from 3DS Max 2016 online help at http://help.autodesk.com/view/3DSMAX/2016/ENU//?guid=__files_GUID_38562330_1435_4112_9265_DE965319A2... It creates a file below:

 

 

8,12
[-7.5,-7.5,0][7.5,-7.5,0][-7.5,7.5,0][7.5,7.5,0][-7.5,-7.5,15][7.5,-7.5,15][-7.5,7.5,15][7.5,7.5,15]
[1,3,4][4,2,1][5,6,8][8,7,5][1,2,6][6,5,1][2,4,8][8,6,2][4,3,7][7,8,4][3,1,5][5,7,3]

The first line shows the number of verticles and number of triangular faces.

 

The second line shows the coordinates of the verticles at each corner of the cube.

The third line shows the positions of the verticles for drawing each triangular face.

Position [1,3,4] have verticles at [-7.5,-7.5,0],[-7.5,7.5,0], and [7.5,7.5,0].

 

   <mesh>                                
     <name>m.tiny</name>
     <triangles>
       <triangle>
         <materialId>0</materialId>
         <vertex>
           <position>-7.5,-7.5,0</position>
           <texcoord>0,0</texcoord>
         </vertex>
         <vertex>
           <position>-7.5,7.5,0</position>
           <texcoord>1,0</texcoord>
         </vertex>
         <vertex>
           <position>7.5,7.5,0</position>
           <texcoord>1,1</texcoord>
         </vertex>
       </triangle>
     </triangles>
   </mesh>

 

How do I get each position and separate it into verticles?

 

1st face = 1,3,4

1st verticle = -7.5,-7.5,0

2nd verticle = -7.5,7.5,0

3rd verticle = 7.5,7.5,0

 

2nd face = 4,2,1

1st verticle = 7.5,7.5,0

2nd verticle = 7.5,-7.5,0

3rd verticle = -7.5,-7.5,0

 

3rd face = 5,6,8

1st verticle = -7.5,-7.5,15

2nd verticle = 7.5,-7.5,15

3rd verticle = 7.5,7.5,15

 

4th face = 8,7,5

1st verticle = 7.5,7.5,15

2nd verticle = -7.5,7.5,15

3rd verticle = -7.5,-7.5,15

 

so on?

0 Likes