This topic is 3782 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm using this system to load models into an application ( this is using the cal3d format and library) and it keeps getting the wrong winding order. It will load for example 4 objects together, and one of them will get the wrong order but the others are right. I tracked down the part of the code that is probably causing it. It makes a check for something, but why does it come out with different results sometimes, why did they make it like this?, how can I just skip this check / test and make it always use the same method without messing it up? full file --http://svn.gna.org/viewcvs/cal3d/trunk/cal3d/src/cal3d/loader.cpp?rev=489&view=auto
// check if left-handed coord system is used by the object
// can be done only once since the object has one system for all faces
if (justOnce==0)
{
// get vertexes of first face
std::vector<CalCoreSubmesh::Vertex>& vectorVertex = pCoreSubmesh->getVectorVertex();
CalCoreSubmesh::Vertex& v1 = vectorVertex[tmp[0]];
CalCoreSubmesh::Vertex& v2 = vectorVertex[tmp[1]];
CalCoreSubmesh::Vertex& v3 = vectorVertex[tmp[2]];

CalVector point1 = CalVector(v1.position.x, v1.position.y, v1.position.z);
CalVector point2 = CalVector(v2.position.x, v2.position.y, v2.position.z);
CalVector point3 = CalVector(v3.position.x, v3.position.y, v3.position.z);

// gets vectors (v1-v2) and (v3-v2)
CalVector vect1 = point1 - point2;
CalVector vect2 = point3 - point2;

// calculates normal of face
CalVector cross = vect1 % vect2;
float	crossLength = cross.length();
if (crossLength == 0.0f)
{
CalError::setLastError(CalError::INVALID_FILE_FORMAT, __FILE__, __LINE__);
return 0;
}
CalVector faceNormal = cross / crossLength;

// compare the calculated normal with the normal of a vertex
CalVector maxNorm = v1.normal;

// if the two vectors point to the same direction then the poly needs flipping
// so if the dot product > 0 it needs flipping
if (faceNormal*maxNorm>0)
flipModel = true;

flipModel = !flipModel;

justOnce = 1;
}

// flip if needed
if (flipModel)
{
tmp[3] = face.vertexId[1];
face.vertexId[1]=face.vertexId[2];
face.vertexId[2]=tmp[3];
}

##### Share on other sites
Are you sure that your model have correct vertex normals? Which 3d-content creation software you are using?
This code just compares triangle normal with vertex normal.

##### Share on other sites
The program is blender, the normals arn't wrong, but they may not be what the program is expecting. I guess basically The test assumes that you don't have a combination of smooth and flat normals? Which is not a good thing to assume, since almost every kind of model could have both.

• 18
• 11
• 19
• 9
• 52
• ### Forum Statistics

• Total Topics
631397
• Total Posts
2999811
×