c++ - How does a 3ds Max store normals in a Mesh class? -


i'm writing 3ds max exporter , need mesh normals computed application. have mesh instance , can vertex positions, uvs, colors, etc. normals seem not easy... btw: know how compute face/vertex normals, need exact data 3ds max, smoothing groups , material index taken account.

for case i've created simple box , looked resulting mesh instance after calling buildnormals() method. here i've found after debugging , digging documentation, mentioned data inside of mesh class:

i have simple vertex/face numbers:

int numverts = 8; int numfaces = 12; 

and verices/faces data:

point3* verts;    // contains 8 vectors positions (x,y,z) face*   faces;    // contains 12 faces, each 3 indexes *verts - [0-7] 

so far good... have computed normals data:

int normalcount = 24;  // 6 sides * 4 vertices each, no reuse of normal data point3* gfxnormals;    // contains 24 normal vectors 

at point have data need can't assign 1 normal 1 rendered vertex. there 1 more interesting table:

tab<ulong> norind;    // contains 8 indexes - {0,3,6,9,12,15,18,21} 

it seems somehow connected previous fields (i have 8 verts, each has 3 normals) have no idea how use in more complex situations.

what need get:

i need index of normal particular vertex in particular face, or in other words - if wanted render 0'th face in opengl use:

glvertex3f( verts[ faces[0].v[0] ].x, verts[ faces[0].v[0] ].y, verts[ faces[0].v[0] ].z ); glvertex3f( verts[ faces[0].v[1] ].x, verts[ faces[0].v[1] ].y, verts[ faces[0].v[1] ].z );     glvertex3f( verts[ faces[0].v[2] ].x, verts[ faces[0].v[2] ].y, verts[ faces[0].v[2] ].z ); 

but pass glnormal3f()?

the way them this:

for(int f = 0; f < mesh->numfaces; ++f) {         point3 normal;         face* face = &mesh->faces[f];          for(int v = 0; v < 3; ++v)         {                 dword vi = face->v[v];                 point3 normal;                 if(mesh->getrvertptr(vi))                         normal = getvertexnormal(mesh, f, mesh->getrvertptr(vi));                 else                         normal = point3(0, 0, 1);                        fprintf(file, "\t\t\t<normal x=\"%f\" y=\"%f\" z=\"%f\" />\n", normal.x, normal.y, normal.z);         } } 

Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -