Not logged in, Join Here! or Log In Below:  
 
News Articles Search    
 

 Home / 3D Theory & Graphics / IGame and Normals list Account Manager
 
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.
 
NightElf

April 29, 2005, 03:34 AM

Hello!

I've managed to export from 3ds Max, a custom model format.

However, after i have play a while with the models exported, i've noticed that the normals from model are totally wrong, when i have try some simple ligthing. Any ideas what can be the problem?

Here is how i have exported the mesh:

- exported vertexs list
- exported normals list
- exported uv list
- exported faces list (have 3 index into vertex/normal/uv list)


Thanks in advance.

p.s. i can paste some code if is necesary.

 
Erik Faye-Lund

April 29, 2005, 04:40 AM

the normals in IGame are in world space, just multiply with the inverse of the absolute matrix.

something like this.

Matrix3 m = mesh->GetIGameObjectTM().ExtractMatrix3();
m.NoTrans();
m.NoScale();
m.Invert();

mesh->GetVertex(face->vert[j], vert, true);
mesh->GetNormal(face->norm[j], norm);
norm = m * norm;

 
NightElf

April 29, 2005, 05:29 AM

Well, thanks for your advice, but still this have't fix the problem.

Here is how i extract the mesh:

  1.  
  2.  
  3. // vertex position list
  4. int numVerts = gm->GetNumberOfVerts();
  5. for(int iv = 0; iv<numVerts; iv++)
  6. {
  7. Point3 v;
  8. gm->GetVertex(iv,v);
  9. // write the position to file
  10. }
  11.  
  12.  
  13. // vertex normal list
  14. int numNorms = gm->GetNumberOfNormals();
  15. for(int in = 0; in<numNorms; in++)
  16. {
  17. Point3 n;
  18. if (gm->GetNormal(in,n))
  19. {
  20. Matrix3 m = gm->GetIGameObjectTM().ExtractMatrix3();
  21. m.NoTrans();
  22. m.NoScale();
  23. m.Invert();
  24. n = m * n;
  25. // write the normal to file
  26. }
  27.  
  28.  
  29. // uv list
  30. int numTVs = gm->GetNumberOfTexVerts();
  31. for(int itc = 0; itc<numTVs; itc++)
  32. {
  33. Point2 tv;
  34. if(gm->GetTexVertex(itc,tv))
  35. {
  36. // write the tv to file
  37. }
  38. }
  39.  
  40.  
  41. // finaly write the faces
  42. int numFaces = gm->GetNumberOfFaces();
  43. for(int iface=0; iface<numFaces; iface++)
  44. {
  45. FaceEx* f = gm->GetFace(iface);
  46. // write the index in vertex list f->vert[0],f->vert[1],f->vert[2]
  47. // write the index in normal list f->norm[0],f->norm[1],f->norm[2]
  48. // write the index in uv list f->texCoord[0],f->texCoord[1],f->texCoord[2]
  49. }
  50.  


I beleve is a problem with the normal list. Theoreticaly, this must match with the face normals index, but seems to not, or is something wrong with my method.

Thanks in advance.

 
CoderByBirth

April 29, 2005, 06:21 AM

There is a bug in IGame that requires you to call SetCreateOptimizedNormalList() before you call InitializeData() or the normals will be junk.
There is also a bug in the extraction of vertex colors making them invalid unless the vertex color modifier has been collapsed in the modifier stack. This can be worked around using GetMapVertex().

 
NightElf

April 29, 2005, 06:57 AM

I have gm->SetCreateOptimizedNormalList() before gm->InitializeData().

Problem still exist:(

 
Rui Martins

April 29, 2005, 09:46 AM

Go with the KISS rule.

Create a very simple object, and then debug your exporter with it as input.

 
This thread contains 6 messages.
 
 
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.