Sign in to follow this  
toasterthegamer

MaxScript Exporter

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:

[code]

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
)
[/code]


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):
[code]

<Mesh VertexCount="24" FaceCount="12">
<Vertex>
<X>-0.5</X>
<Y>-0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Z>
<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>
[/code]


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
[quote name='csisy' timestamp='1325269899' post='4898205']
I know this is an old topic, but I have the same problem, and I don't want to create a new thread. [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]
Any idea for the solution?
[/quote]
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:
[CODE]
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
[/CODE]
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

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

f.ids[j] = id
[/CODE]

Share this post


Link to post
Share on other sites
Hi,

Pierre Terdiman gave a src code about mesh consolidation here :

[url="http://codercorner.com/CodeArticles.htm"]http://codercorner.com/CodeArticles.htm[/url]
http://www.codercorner.com/Consolidation.zip

It may be useful in your case.

Cheers!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this