AdrianM
07-18-2008, 05:34 PM
Hi all!
I'm trying to load an .xsi file and render it's geometry but i get some unusual cracks. The model looks just fine in XSI. Here's the code used to render the contents:
I'm loading a .xsi file and rendering but i get some unusual cr@cks. Can someone spot where i am making a mistake?
void Recurse( CSLModel* in_child )
{
CSLModel* *l_childrenList = in_child->GetChildrenList();
if (in_child->Primitive())
{
if ( in_child->Primitive()->Type() == CSLTemplate::SI_MESH)
{
CSLGeometry* pGeometry = (CSLGeometry*)in_child->Primitive();
CSLMesh* pMesh = (CSLMesh*)in_child->Primitive();
CSLShape_35* pShape = (CSLShape_35*)pMesh->Shape();
int numVertices = pShape->GetVertexCount();
CSIBCVector3D* pVertices = pShape->GetVertexListPtr();
CSIBCVector3D* pNormals = pShape->GetNormalListPtr();
CSIBCVector2D* pTextCoords = NULL;
if (pShape->UVCoordArrays())
pTextCoords = pShape->UVCoordArrays()<li type="circle">->GetUVCoordListPtr();
std::vector<CVector3D> vertexArray,normalArray;
std::vector<CVector2D> texCoordArray;
std::vector<int> indexArray;
CSLTriangleStripList **triStripLists = pMesh->TriangleStripLists();
int triStripListCount = pMesh->GetTriangleStripListCount();
int i;
TriangleStripList triStripList;
for (i=0; i<triStripListCount; i++)
{
int triStripCount = triStripLists[i]->GetTriangleStripCount();
CSLTriangleStrip** triStrip = triStripLists[i]->TriangleStrips();
TriangleStrip triangleStrip;
int j;
for (j=0; j<triStripCount; j++)
{
TriangleStripAtom triStripAtom;
int* pVertexIndices = triStrip[j]->GetVertexIndicesPtr();
int* pNormalIndices = triStrip[j]->GetNormalIndicesPtr();
int* pUVIndices = triStrip[j]->GetUVIndicesPtr(0);
int vertexCount = triStrip[j]->GetVertexCount();
int k;
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);
glBegin(GL_TRIANGLE_STRIP);
k = 0;
for (k=0; k<vertexCount; k++)
{
glNormal3fv(*CVector3D(pNormals[pNormalIndices[k].m_fX,
pNormals[pNormalIndices[k].m_fY,pNormals[pNormalIndices[k].m_fZ));
glVertex3fv(*CVector3D(pVertices[pVertexIndices[k].m_fX,
pVertices[pVertexIndices[k].m_fY,
pVertices[pVertexIndices[k].m_fZ));
}
glEnd();
}
}
}
}
for (int i = 0; i < in_child->GetChildrenCount(); i++ )
{
Recurse( l_childrenList[i] );
}
}
I'm trying to load an .xsi file and render it's geometry but i get some unusual cracks. The model looks just fine in XSI. Here's the code used to render the contents:
I'm loading a .xsi file and rendering but i get some unusual cr@cks. Can someone spot where i am making a mistake?
void Recurse( CSLModel* in_child )
{
CSLModel* *l_childrenList = in_child->GetChildrenList();
if (in_child->Primitive())
{
if ( in_child->Primitive()->Type() == CSLTemplate::SI_MESH)
{
CSLGeometry* pGeometry = (CSLGeometry*)in_child->Primitive();
CSLMesh* pMesh = (CSLMesh*)in_child->Primitive();
CSLShape_35* pShape = (CSLShape_35*)pMesh->Shape();
int numVertices = pShape->GetVertexCount();
CSIBCVector3D* pVertices = pShape->GetVertexListPtr();
CSIBCVector3D* pNormals = pShape->GetNormalListPtr();
CSIBCVector2D* pTextCoords = NULL;
if (pShape->UVCoordArrays())
pTextCoords = pShape->UVCoordArrays()<li type="circle">->GetUVCoordListPtr();
std::vector<CVector3D> vertexArray,normalArray;
std::vector<CVector2D> texCoordArray;
std::vector<int> indexArray;
CSLTriangleStripList **triStripLists = pMesh->TriangleStripLists();
int triStripListCount = pMesh->GetTriangleStripListCount();
int i;
TriangleStripList triStripList;
for (i=0; i<triStripListCount; i++)
{
int triStripCount = triStripLists[i]->GetTriangleStripCount();
CSLTriangleStrip** triStrip = triStripLists[i]->TriangleStrips();
TriangleStrip triangleStrip;
int j;
for (j=0; j<triStripCount; j++)
{
TriangleStripAtom triStripAtom;
int* pVertexIndices = triStrip[j]->GetVertexIndicesPtr();
int* pNormalIndices = triStrip[j]->GetNormalIndicesPtr();
int* pUVIndices = triStrip[j]->GetUVIndicesPtr(0);
int vertexCount = triStrip[j]->GetVertexCount();
int k;
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);
glBegin(GL_TRIANGLE_STRIP);
k = 0;
for (k=0; k<vertexCount; k++)
{
glNormal3fv(*CVector3D(pNormals[pNormalIndices[k].m_fX,
pNormals[pNormalIndices[k].m_fY,pNormals[pNormalIndices[k].m_fZ));
glVertex3fv(*CVector3D(pVertices[pVertexIndices[k].m_fX,
pVertices[pVertexIndices[k].m_fY,
pVertices[pVertexIndices[k].m_fZ));
}
glEnd();
}
}
}
}
for (int i = 0; i < in_child->GetChildrenCount(); i++ )
{
Recurse( l_childrenList[i] );
}
}