Model Export Question

Started by
8 comments, last by Pangplast2 16 years, 8 months ago
In 3ds max(any version with MaxScript)how could i properly write an exporter in MaxScript that will export only the vertices and faces properly so it can be easily read and rendered? Thanks
Advertisement
This article provides some good insight.

Basically, open an existing script and see how it's put together. Then write your script similar to the example one.
Thanks that was helpful but it doesnt really talk about rendering your own format. Just in case im using c++, opengl and win32
Quote:Original post by hahaha
Thanks that was helpful but it doesnt really talk about rendering your own format. Just in case im using c++, opengl and win32

Rendering your own format is an entirely different matter. Basically you just load your file into whatever data structures you are using to render in OpenGL (vertex arrays or VBOs, etc.). Specifics depend on how you are rendering, and how your file format is laid out.
I think NeHe has a few articles on model loading, probably worth looking at.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

If i have these structs:
struct Vertex{   float x,y,z};struct Face{   float x,y,z;}


and this is the vertex and face data loaded into a pointer of the structures

Vertices:-3.23639 0.0 -29.20953.23639 0.0 -29.2095-3.23639 0.0 29.20953.23639 0.0 29.2095-3.23639 11.3347 -29.20953.23639 11.3347 -29.2095-3.23639 11.3347 29.20953.23639 11.3347 29.2095Faces:1.0 4.0 3.04.0 1.0 2.05.0 8.0 6.08.0 5.0 7.01.0 6.0 2.06.0 1.0 5.02.0 8.0 4.08.0 2.0 6.04.0 7.0 3.07.0 4.0 8.03.0 5.0 1.05.0 3.0 7.0


How would i go about rendering it?
I am not sure you understand rendering triangles. The vertices are fine, but each Face needs to be a collection of 3 vertices, not 3 floats. After all, a Face is a triangle, and it therefore needs a vertex for each corner. In actual fact, most systems just store 3 indices (offsets) into the array of vertices for each face.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

As swift coder said, you should change your data structures

Vertices:Vertices 1: -3.23639 0.0 -29.2095Vertices 2: 3.23639 0.0 -29.2095Vertices 3: -3.23639 0.0 29.2095Vertices 4: 3.23639 0.0 29.2095Vertices 5: -3.23639 11.3347 -29.2095Vertices 6: 3.23639 11.3347 -29.2095Vertices 7: -3.23639 11.3347 29.2095Vertices 8: 3.23639 11.3347 29.2095Faces:Face1: 1 4 3Face2: 4 1 2Face3: 5 8 6Face4: 8 5 7Face5: 1 6 2Face6: 6 1 5Face7: 2 8 4Face8: 8 2 6Face9: 4 7 3Face10: 7 4 8Face11: 3 5 1Face12: 5 3 7


Now you can iterate over your faces using the face pointer, using face n(a,b,c) to render a triangle.

// you can do this alot faster using vertex and index arrays, but for immediate rendering this will work.for (int i=1; i<=numFaces; ++i){  vertex1 = Vertices[Faces.a];  vertex2 = Vertices[Faces.b];  vertex3 = Vertices[Faces.c];  DrawTriangle(vertex1, vertex2, vertex3);}


This data is based on a 1 index, You should start working from a 0 index.

0123456789 instead of 123456789(10)

[Edited by - lubby on July 28, 2007 6:01:41 AM]
Thanks a lot! Its been puzzling me for days:)
Ive come across another problem. Ive written this code for exporting the texture verts:

for i = 1 to NumTVerts do(    tv = GetTVert Mesh i    format "%\n%\n%\n" tv.x tv.y tv.z to:out --file )


when i execute the script with a texture mapped cube i get 3 values(tv.x tv.y tv.z...(either 0.0 or 0.1)) for each face. I can render the faces fine but when it comes to using those texture coords im lost!
Please can someone tell me how to use the texture coords.

Thanks
For every face-value (3 for every triangle) you must att two more floats, the (u,v) texture coordinate.

Do not try to use the so called "sticky uv's" method where you put the uv's whith the vertice, this will make it a lot harder to make nice models since two or more triangles MUST share uv coords.

You're still on easystreet now, just wait until you get to bones, vertexgroups, frames and transforms :)

This topic is closed to new replies.

Advertisement