Advertisement

CelShading#37 how do I make my own model file?

Started by December 09, 2002 05:10 AM
0 comments, last by zenwarcloud 22 years, 2 months ago
I have tried and tried to figure out the format of "Model.txt", so that I can write and play around with my own models, but with no success. =( Can someone please post a simple example of a "Model.txt" file for this program, like for a single triangle at the origin or something easy like that? This would really help me to understand exactly how the model data is specified and how it is read into the program. Thanks...
"A thousand mile journey starts with the first step."
file format is actually straightforward. ReadMesh function is the key to understanding it.

the file consists of two parts: header and vertex data.

header is an integer value specifying number of triangles in the model, saved in binary. it's sizeof(int) bytes long. let's call this number NumTris.

vertex data consists of NumTris triangles (which the author for some reason calls polygons - why overcomplicate things?) each triangle consists of three vertices. each vertex in turn consists of position and normal vectors. each of those is made up of three floating point values.

here's a piece of code that should generate a model.txt containing a triangle with vertices (1, 2, 0), (1, -2, 0), and (-1, 2, 0). normals for all vertices are (0, 0, 1).


    FILE *fp = fopen("model.txt", "wb");// write number of triangles (1)int numtris = 1;fwrite(&numtris, sizeof(int), 1, fp);// write the trianglePOLYGON tri;// initialize positionstri.Verts[0].Pos.x = 1;tri.Verts[0].Pos.y = 2;tri.Verts[0].Pos.z = 0;tri.Verts[1].Pos.x = 1;tri.Verts[1].Pos.y = -2;tri.Verts[1].Pos.z = 0;tri.Verts[2].Pos.x = -1;tri.Verts[2].Pos.y = 2;tri.Verts[2].Pos.z = 0;// initialize normalstri.Verts[0].Nor.x = 0;tri.Verts[0].Nor.y = 0;tri.Verts[0].Nor.z = 1;tri.Verts[1].Nor.x = 0;tri.Verts[1].Nor.y = 0;tri.Verts[1].Nor.z = 1;tri.Verts[2].Nor.x = 0;tri.Verts[2].Nor.y = 0;tri.Verts[2].Nor.z = 1;// write themfwrite(&tri, sizeof(tri), 1, fp);fclose(fp);    



[edited by - niyaw on December 9, 2002 6:23:30 AM]

This topic is closed to new replies.

Advertisement