Archived

This topic is now archived and is closed to further replies.

IVI4j

MD2 problem

Recommended Posts

I just got done putting the md2 loading procedures in my code but when I loaded up the model using it , the model was really screwed up. The particular demo has the md2 model in the center of 3d space with a light source rotating around it. It looks very blocky and the triangles seem to be shading wrong. I''ve checked over the code a few times and came up with nothing. The md2 itself was exported from milkshape (in which it appeared very smooth). Also, the sphere generated by auxSolidSphere is correctly effected by the lighting. Any help would be appreciated.

Share this post


Link to post
Share on other sites
You aren''t very clear as to exactly what''s wrong, maybe you aren''t enabling smooth shading? Are you sure the normals are being generated correctly and being passed to OpenGL in the right way?

Can''t tell what''s wrong without seeing it, maybe post a screenshot and some code?

Share this post


Link to post
Share on other sites
Heres the CalculateNormals procedure...

void CalculateNormal( float *p1, float *p2, float *p3)
{
float a[3], b[3], result[3];
float length;

a[0] = p1[0] - p2[0];
a[1] = p1[1] - p2[1];
a[2] = p1[2] - p2[2];

b[0] = p1[0] - p3[0];
b[1] = p1[1] - p3[1];
b[2] = p1[2] - p3[2];

result[0] = a[1] * b[2] - b[1] * a[2];
result[1] = b[0] * a[2] - b[0] * b[2];
result[2] = a[0] * b[1] - b[0] * a[1];

length = (float)sqrt(result[0] * result[0] + result[1] * result[1] + result[2] * result[2]);

//Normalize and specify the normal
glNormal3f(result[0]/length, result[1]/length, result[2]/length);
}

And here is the DisplayMD2 procedure...

void DisplayMD2(modelData_t *model, int frameNum)
{
vector_t *pointList; //Current Frames vertices
int i; //Index counter

//Create a pointer to the frame we want to show
pointList = &model->pointList[model->numPoints * frameNum];

//Display the model as solid triangles
glBegin(GL_TRIANGLES);
for(i = 0; i < model->numTriangles; i++)
{
CalculateNormal(pointList[model->triIndex.meshIndex[0]].point,pointList[model->triIndex[i].meshIndex[2]].point,pointList[model->triIndex[i].meshIndex[1]].point);

glVertex3fv(pointList[model->triIndex[i].meshIndex[0]].point);
glVertex3fv(pointList[model->triIndex[i].meshIndex[2]].point);
glVertex3fv(pointList[model->triIndex[i].meshIndex[1]].point);
}
glEnd();
}

Smooth shading was my first suspicion, but It was already in the init procedure. I''m wondering if its a problem with milkshape exporting to md2, so I''m going to try the MS3D loading code on this page. I don''t know how to post a screenshot, but I can try to describe it better. The curved survaces look a lot like a colidascope while the light is moving over them. They randomly turn dark, then light up. The larger triangles do the same thing but slower. The cockpit on the model which is similar to a sphere is where it really messes up. No matter where the light is coming from, the triangles are checkered between the light''s color and black. I understand thats still not very clear , but do any of those symptoms ring a bell?

Share this post


Link to post
Share on other sites
To me it sounds like your triangles aren''t facing the same way. Some point into the model, while others point out. Open up Milkshape and disable smooth shading (use flat). All the triangles pointing the wrong way are dark now. Select them and face them in the other direction (there''s a button for it somewhere...).



Sander Maréchal
[Lone Wolves Production][Articles][GD Emporium][E-mail]

Share this post


Link to post
Share on other sites
I tried turning milkshape to flat shading, but all the triangles were colored still. I decided to check over the code more thourghly and found that I had put an "A" where there should be a "B" (Duh? How could I miss that?).

result[0] = a[1] * b[2] - b[1] * a[2];
>> result[1] = b[0] * a[2] - A[0] * b[2]; <<
result[2] = a[0] * b[1] - b[0] * a[1];




This fixed a lot of the problem but it still seems to be really blocky. Not at all like the smooth shaded version (or even the flat shaded version) in milkshape. Would this point to the milkshape model being exported to MD2, or is this type of smoothing made seperately via one of the curving methods in OpenGL?

Share this post


Link to post
Share on other sites
Actualy MD2s carry normals but in a very wierd way. There is a global lookup tabele of vectors that is used for all md2s and model stores just indexes in that array.

You should never let your fears become the boundaries of your dreams.

Share this post


Link to post
Share on other sites