Jump to content
  • Advertisement
Sign in to follow this  
toasterthegamer

MaxScript Exporter

This topic is 2364 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys,

I've been working on a maxscript exporter that exports to xml for use inside a dx10 environment. So far I have it exporting some data in the xml format I want, but the data isn't very usable to me in its current form.

Whats happening is that in order to get the correct number of vertices in 3ds max I had to get them by face. This led to a lot of duplicate vertices which i removed later on. However max stores indices in a few different places(if I understand this right), one for the vertices and then one for the UV's, one for the normal's, etc.

This is a problem for me cause directX doesn't work this way as vertices, normals, uv's are usually stored in the same place and then indices are stored separate. Here is my max code that gets the mesh info:



fn GetMeshData obj =
(
for f = 1 to obj.faces.count do
(
local PosIndices = getFace obj f
local FaceNormals = meshop.getFaceRNormals obj f
local UVIndices = meshop.getMapFace obj 1 f

local FaceVert0 = D3DVertex()
local FaceVert1 = D3DVertex()
local FaceVert2 = D3DVertex()

FaceVert0.pos = obj.verts[ PosIndices.x ].pos
FaceVert1.pos = obj.verts[ PosIndices.y ].pos
FaceVert2.pos = obj.verts[ PosIndices.z ].pos

FaceVert0.normal = FaceNormals[1]
FaceVert1.normal = FaceNormals[2]
FaceVert2.normal = FaceNormals[3]

FaceVert0.uv = [ (meshop.getMapVert obj 1 UVIndices.x).x, (meshop.getMapVert obj 1 UVIndices.x).y ]
FaceVert1.uv = [ (meshop.getMapVert obj 1 UVIndices.y).x, (meshop.getMapVert obj 1 UVIndices.y).y ]
FaceVert2.uv = [ (meshop.getMapVert obj 1 UVIndices.z).x, (meshop.getMapVert obj 1 UVIndices.z).y ]

append objVertices FaceVert0
append objVertices FaceVert1
append objVertices FaceVert2

local Face = D3DFace()

poly = GetTVFace obj f

Face.indices[1] = poly.x
Face.indices[2] = poly.y
Face.indices[3] = poly.z

append objFaces Face
)



D3DVertex, D3DFace are structs. objVertices and objFaces are arrays. I really dislike maxscript, but as I don't have the SDK for 3ds max this is my only option. I remove duplicate vertices when I load the file into my app.

Here is what the output looks like(simple cube):


<Mesh VertexCount="24" FaceCount="12">
<Vertex>
<X>-0.5</X>
<Y>-0.5</Y>
<Z>0</Z>
<NX>0</NX>
<NY>0</NY>
<NZ>-1</NZ>
<U>1</U>
<V>0</V>
</Vertex>
<Vertex>
<X>-0.5</X>
<Y>0.5</Y>
<Z>0</Z>
<NX>0</NX>
<NY>0</NY>
<NZ>-1</NZ>
<U>1</U>
<V>1</V>
</Vertex>
<Vertex>
<X>0.5</X>
<Y>0.5</Y>
<Z>0</Z>
<NX>0</NX>
<NY>0</NY>
<NZ>-1</NZ>
<U>0</U>
<V>1</V>
</Vertex>
<Vertex>
<X>0.5</X>
<Y>-0.5</Y>
<Z>0</Z>
<NX>0</NX>
<NY>0</NY>
<NZ>-1</NZ>
<U>0</U>
<V>0</V>
</Vertex>
<Vertex>
<X>-0.5</X>
<Y>-0.5</Y>
<Z>1</Z>
<NX>0</NX>
<NY>0</NY>
<NZ>1</NZ>
<U>0</U>
<V>0</V>
</Vertex>
<Vertex>
<X>0.5</X>
<Y>-0.5</Y>
<Z>1</Z>
<NX>0</NX>
<NY>0</NY>
<NZ>1</NZ>
<U>1</U>
<V>0</V>
</Vertex>
<Vertex>
<X>0.5</X>
<Y>0.5</Y>
<Z>1</Z>
<NX>0</NX>
<NY>0</NY>
<NZ>1</NZ>
<U>1</U>
<V>1</V>
</Vertex>
<Vertex>
<X>-0.5</X>
<Y>0.5</Y>
<Z>1</Z>
<NX>0</NX>
<NY>0</NY>
<NZ>1</NZ>
<U>0</U>
<V>1</V>
</Vertex>
<Vertex>
<X>-0.5</X>
<Y>-0.5</Y>
<Z>0</Z>
<NX>0</NX>
<NY>-1</NY>
<NZ>0</NZ>
<U>0</U>
<V>0</V>
</Vertex>
<Vertex>
<X>0.5</X>
<Y>-0.5</Y>
<Z>0</Z>
<NX>0</NX>
<NY>-1</NY>
<NZ>0</NZ>
<U>1</U>
<V>0</V>
</Vertex>
<Vertex>
<X>0.5</X>
<Y>-0.5</Y>
<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0.5</X>
<Y>-0.5</Y>
<Z>0</Z>
<NX>-1</NX>
<NY>0</NY>
<NZ>0</NZ>
<U>1</U>
<V>0</V>
</Vertex>
<Vertex>
<X>-0.5</X>
<Y>-0.5</Y>
<Z>1</Z>
<NX>-1</NX>
<NY>0</NY>
<NZ>0</NZ>
<U>1</U>
<V>1</V>
</Vertex>
<Vertex>
<X>-0.5</X>
<Y>0.5</Y>
<Z>1</Z>
<NX>-1</NX>
<NY>0</NY>
<NZ>0</NZ>
<U>0</U>
<V>1</V>
</Vertex>
<Face>
<Vertex1>9</Vertex1>
<Vertex2>11</Vertex2>
<Vertex3>10</Vertex3>
</Face>
<Face>
<Vertex1>10</Vertex1>
<Vertex2>8</Vertex2>
<Vertex3>9</Vertex3>
</Face>
<Face>
<Vertex1>8</Vertex1>
<Vertex2>9</Vertex2>
<Vertex3>11</Vertex3>
</Face>
<Face>
<Vertex1>11</Vertex1>
<Vertex2>10</Vertex2>
<Vertex3>8</Vertex3>
</Face>
<Face>
<Vertex1>4</Vertex1>
<Vertex2>5</Vertex2>
<Vertex3>7</Vertex3>
</Face>
<Face>
<Vertex1>7</Vertex1>
<Vertex2>6</Vertex2>
<Vertex3>4</Vertex3>
</Face>
<Face>
<Vertex1>0</Vertex1>
<Vertex2>1</Vertex2>
<Vertex3>3</Vertex3>
</Face>
<Face>
<Vertex1>3</Vertex1>
<Vertex2>2</Vertex2>
<Vertex3>0</Vertex3>
</Face>
<Face>
<Vertex1>4</Vertex1>
<Vertex2>5</Vertex2>
<Vertex3>7</Vertex3>
</Face>
<Face>
<Vertex1>7</Vertex1>
<Vertex2>6</Vertex2>
<Vertex3>4</Vertex3>
</Face>
<Face>
<Vertex1>0</Vertex1>
<Vertex2>1</Vertex2>
<Vertex3>3</Vertex3>
</Face>
<Face>
<Vertex1>3</Vertex1>
<Vertex2>2</Vertex2>
<Vertex3>0</Vertex3>
</Face>
</Mesh>



As you can see my indices go up to 12(0-11). I have 24 vertices though. The numbers just don't match up! Any help would be greatly appreciated!

Thanks,
-Jon

Share this post


Link to post
Share on other sites
Advertisement
I know this is an old topic, but I have the same problem, and I don't want to create a new thread. :)
Any idea for the solution?

Share this post


Link to post
Share on other sites

I know this is an old topic, but I have the same problem, and I don't want to create a new thread. smile.png
Any idea for the solution?

Umm, my first solution is:
I have a struct with pos:point3, normal:point3, tex:point2 members
Every mesh, I create an array from this struct and an other, which contains ids:array(3) (Face)
For each face, I get the vertex ids, texcoord ids and face normal. I start a new loop 1 to 3, and get the datas from the mesh:

v = ScreamVertex()

pos = (getVert tmesh ids[j])
texcoord = (getTVert tmesh tids[j])

-- make y-up
z = pos.z
pos.z = pos.y
pos.y = z

v.pos = pos
v.normal = normal
v.tex = texcoord

Then I wrote a function which returns with an id to a vertex, and -1 if the vertex isn't exist. If the vertex isn't exist, I add it to the array and get the id. If exist, the face's j-th id will be the returned id


id = GetVertexId vertices pos normal texcoord
if id == -1 then
(
append vertices v
id = vertices.count - 1
)

f.ids[j] = id

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!