Jump to content
  • Advertisement
Sign in to follow this  

Custom Model Format help

This topic is 4160 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

I wrote a quick MaxScript exporter in 3ds max 7. Heres the code:
tmesh = snapshotAsMesh selection[1]
out_name = "c:/123.txt"
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.X to:out_file
format "% " vert.Z to:out_file
format "%\n" vert.Y to:out_file
format "\n" to:out_file
for f = 1 to num_faces do
face = getFace tmesh f
format "% " face.X to:out_file
format "% " face.Z to:out_file
format "%\n" face.Y to:out_file
close out_file
edit out_name
It just exports the selected object(in my testing i just exported a cube) It produces this output:
-3.23639 0.0 -29.2095
3.23639 0.0 -29.2095
-3.23639 0.0 29.2095
3.23639 0.0 29.2095
-3.23639 11.3347 -29.2095
3.23639 11.3347 -29.2095
-3.23639 11.3347 29.2095
3.23639 11.3347 29.2095

1.0 4.0 3.0
4.0 1.0 2.0
5.0 8.0 6.0
8.0 5.0 7.0
1.0 6.0 2.0
6.0 1.0 5.0
2.0 8.0 4.0
8.0 2.0 6.0
4.0 7.0 3.0
7.0 4.0 8.0
3.0 5.0 1.0
5.0 3.0 7.0
Any Ideas on how i could load this into my game as a model?(c++ win32)

Share this post

Link to post
Share on other sites

ifstream file(filepath, ios_base::binary);
if (!file.is_open())
cout << "mesh file: "<<filepath<<" not opened"<<endl; return false;

file.read( (char*)&geometry_coordinates_count, sizeof(unsigned int) );

geometry_coordinates = new float[geometry_coordinates_count];
file.read( (char*)geometry_coordinates, sizeof(float)*geometry_coordinates_count );
glBindBufferARB(GL_ARRAY_BUFFER_ARB, geometry_coordinates_VBO);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, geometry_coordinates_count*sizeof(float), geometry_coordinates, GL_STATIC_DRAW_ARB);

and so on...

I suppose you will have to rewrite your exporter to take account of smoothing groups and multiple UV sets;)

Share this post

Link to post
Share on other sites
Thanks but when i try to compile that i get a whole bunch of "x undeclared errors". What im specifically interested is drawing the faces. Ive got as far as drawing the vertices but i have no idea how to render the faces

Share this post

Link to post
Share on other sites
Each triple (a,b,c) of face indices is a triangle. The value of each (a,b,c) is an index into the vertex list; at least that's how it appears based on your code.

Share this post

Link to post
Share on other sites
Ive been looking at using glDrawElements to draw the faces with glVertexPointer but i cant seem to get it working. Please could someone help. I really want make my own format(so i can implement collision detection...etc) for learning.


Share this post

Link to post
Share on other sites
In your drawing loop just go:

// Put your vertices here, 3 to each triangle
// make sure you draw them in the right order for the normals
// to come out properly

.... blah blah


Be very sure to have vertices in groups of three.
For a single square face as an example with corner vertices
1 2
3 4
you would draw two triangles with vertices 1,3,2 and 2,3,4 to make up that face

Share this post

Link to post
Share on other sites
Here you go:


for (int j=0; j < obj.indexcount; j++)





With a little tweaking to your exporter you can easily load these into a vertex array as well.



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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!