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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>
<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