When I render this model in Irrlicht, the polygons are fine, but it's always black... I checked renderring code and my texture it's not NULL. Can you point out my mistakes within my file loader code? Thx a million...
(in step 1, I'd load information into ikkModel)
Code: Select all
// 2. Convert to AnimatedMesh -------------------------
if(ikkModel.nNumMat == 0)
{
// if there are no materials, add at least one buffer
AnimatedMesh->createBuffer();
}
IKK_ASSERT(ikkModel.nNumMat == ikkModel.nNumTxtr);
for (i=0; i<ikkModel.nNumMat; ++i)
{
scene::SSkinMeshBuffer *tmpBuffer = AnimatedMesh->createBuffer();
tmpBuffer->Material.MaterialType = video::EMT_SOLID;
// how to set these color values? we don't have these information in IkkModel yet... then I set all the values to default value of 3DMax
tmpBuffer->Material.AmbientColor = video::SColorf(.2f, .2f, .2f, 1.f).toSColor();
tmpBuffer->Material.DiffuseColor = video::SColorf(.8f, .8f, .8f, 1.f).toSColor();
tmpBuffer->Material.EmissiveColor = video::SColorf(0.f, 0.f, 0.f, 1.f).toSColor();
tmpBuffer->Material.SpecularColor = video::SColorf(0.f, 0.f, 0.f, 1.f).toSColor();
tmpBuffer->Material.Shininess = 0;
core::stringc TexturePath( ikkModel.pTxtr[ikkModel.pMat[i].nTxtrID].sName );
if (TexturePath.trim()!="")
{
TexturePath=stripPathFromString(file->getFileName(),true) + stripPathFromString(TexturePath,false);
tmpBuffer->Material.setTexture(0, Driver->getTexture(TexturePath.c_str()) );
}
core::stringc AlphamapPath=""; // no alpha map yet
if (AlphamapPath.trim()!="")
{
AlphamapPath=stripPathFromString(file->getFileName(),true) + stripPathFromString(AlphamapPath,false);
tmpBuffer->Material.setTexture(2, Driver->getTexture(AlphamapPath.c_str()) );
}
}
// create vertices and indices, attach them to the joints.
video::S3DVertex v;
core::array<video::S3DVertex> *Vertices;
core::array<u16> Indices;
for (i=0; i<ikkModel.nNumMesh; ++i)
{
u32 nMatID = ikkModel.pMesh[i].nMatID;
Vertices = &AnimatedMesh->getMeshBuffers()[nMatID]->Vertices_Standard;
for (j = 0; j<ikkModel.pMesh[i].nNumVert; ++j)
{
v.TCoords.X = ikkModel.pMesh[i].pUV[j*2+0];
v.TCoords.Y = ikkModel.pMesh[i].pUV[j*2+1];
v.Normal.X = ikkModel.pMesh[i].pNor[j*3+0];
v.Normal.Y = ikkModel.pMesh[i].pNor[j*3+1];
v.Normal.Z = ikkModel.pMesh[i].pNor[j*3+2];
IkkMat& ikkMat = ikkModel.pMat[ ikkModel.pMesh[i].nMatID ];
v.Color.set(ikkMat.bColor[0], ikkMat.bColor[1], ikkMat.bColor[2], ikkMat.bColor[3]);
v.Pos.X = ikkModel.pMesh[i].pPos[j*3+0];
v.Pos.Y = ikkModel.pMesh[i].pPos[j*3+1];
v.Pos.Z = ikkModel.pMesh[i].pPos[j*3+2];
// check if we already have this vertex in our vertex array
s32 index = -1;
for (u32 iV = 0; iV < Vertices->size(); ++iV)
{
if (v == (*Vertices)[iV])
{
index = (s32)iV;
break;
}
}
if (index == -1)
{
index = Vertices->size();
Vertices->push_back(v);
}
Indices.push_back(index);
}
// Add indices into IMeshBuffer
core::array<u16>& indices = AnimatedMesh->getMeshBuffers()[nMatID]->Indices;
for(j=0; j<ikkModel.pMesh[i].nNumIdx; ++j)
indices.push_back(Indices[ ikkModel.pMesh[i].pIdx[j] ]);
}