Importer in the same wind order
-
hello.
I'm trying to finish a sketchup importer for opengl in c++ .
My problem is that the shaders that represent the materials of sketchup are five:
1)front color back color
2)front color back texture
3)texture front, back color
4)double color
5)double texture.in these shaders i use the gl_frontfacing (that return true if the face is front and false if the face is back )for draw the different materials.
For example ,in case 2: in the pixel shader:if(gl_frontFacing)
{
gl_color = frontColor
}
else
{
gl_color = texture color
}ecc...
I see that the gl_frontFacing return true if the vertexes are in counterclockwise order or the opposite, i'm not remember good, The problem is that in my importer i have some faces that are counterclockwise and others that are clockwise , then i get a wrong model.
I think that the problem is the indexes order of the vertexes , how i can get all the faces in an unique wind order?
thanks. -
If you get the face.vertices they won't always return in the direction expected; however,
face.outer_loop.vertices should always return them counterclockwise around the face normal; with all other face.loops [i.e. holes] return their vertices clockwise -
thanks TIG.
Now i must find a method for import all faces in correct wing order:
1)i see that there is a m_pMesh->GetPolygonPointIndex(m_nCurrPoly+1, m_nCurrPoint+1, &m_idx);
is sufficent have the correct indexes of the vertexes for import all in the correct windorder ?
2) or i must separate the importation of vertexes like the sketchup example SkpToXml of the sdk?
The sample project do that:
extract the loopshr = pFace->get_Loops(&pLoops);
long nLoops;
hr = pLoops->get_Count(&nLoops);//If this is a simple face (no loops)
if (nLoops==1){/////////////////////////////////////////////////////////////////is a simple face
//import vertex in counterclockwise orderCComPtr<ISkpLoop> pLoop;
hr = pFace->get_OuterLoop(&pLoop);
CComPtr<ISkpVertices> pVerts;
hr = pLoop->get_Vertices(&pVerts);
}
else ///////////////////////////////////////////////////////////////////is a complex face tessellate it with:pFace->CreateMeshWithUVHelper(3, pUVHelper, &pMesh);
and imports vertex in clockwise order?????
//there i must place the m_pMesh->GetPolygonPointIndex??? and import in specific order????
ecc....is sufficent????
Thanks a lot.
Advertisement