材质和纹理的信息都位于node 中
材质的信息通过类Mtl获得
纹理的信息位于node中的mesh 中的UVVert
以下是获得材质的代码:
以下是获取UV的代码,需要注意的是,需要对是否有多重贴图处理:
材质的信息通过类Mtl获得
纹理的信息位于node中的mesh 中的UVVert
以下是获得材质的代码:
//////////////////////////////////////////////////////////////////////////
//material
Mtl* nodematerial=node->GetMtl();
if(nodematerial)
{
fprintf(m_fileStream, "%s mtl -- name:<%s>\n", GetIndent(indent),nodematerial->GetName());
}
else
{
DWORD vcolor=node->GetWireColor();
fprintf(m_fileStream,"%s color -- rgb:<%d,%d,%d>\n", GetIndent(indent),GetRValue(vcolor), GetGValue(vcolor), GetBValue(vcolor));
}
//////////////////////////////////////////////////////////////////////////
//material
Mtl* nodematerial=node->GetMtl();
if(nodematerial)
{
fprintf(m_fileStream, "%s mtl -- name:<%s>\n", GetIndent(indent),nodematerial->GetName());
}
else
{
DWORD vcolor=node->GetWireColor();
fprintf(m_fileStream,"%s color -- rgb:<%d,%d,%d>\n", GetIndent(indent),GetRValue(vcolor), GetGValue(vcolor), GetBValue(vcolor));
}
//////////////////////////////////////////////////////////////////////////
以下是获取UV的代码,需要注意的是,需要对是否有多重贴图处理:
void OnlyGeometry::ExportUVInfo(Mesh* mesh,int indent)
{
int numTVerts = mesh->getNumTVerts();
if(numTVerts>0)
{
fprintf(m_fileStream, "%s texture channel 1 -- numverts:<%d>\n", GetIndent(indent),numTVerts);
for (int i = 0; i < numTVerts; i++)
{
UVVert tvert = mesh->tVerts[i];
fprintf(m_fileStream, "%s UVW tvert %d:<%f,%f,%f>\n", GetIndent(indent),i, tvert.x, tvert.y, tvert.z);
}
// print tvert indices used by tvfaces
for (int i = 0; i < mesh->getNumFaces(); i++)
{
TVFace tface = mesh->tvFace[i];
fprintf(m_fileStream, "%s TVFace %d -- tvertind:<%d,%d,%d>\n",
GetIndent(indent),i, tface.t[0], tface.t[1], tface.t[2]);
}
}
//多重贴图
for (int chanloop = 2; chanloop < MAX_MESHMAPS - 1; chanloop++)
{
if (mesh->mapSupport(chanloop))
{
numTVerts = mesh->getNumMapVerts(chanloop);
fprintf(m_fileStream, "%s texture channel %d -- numverts:<%d>\n", GetIndent(indent),chanloop, numTVerts);
for (int i = 0; i < numTVerts; i++)
{
UVVert tvert = mesh->mapVerts(chanloop)[i];
fprintf(m_fileStream, "%s UVW tvert %d:<%f,%f,%f>\n", GetIndent(indent),i, tvert.x, tvert.y, tvert.z);
}
// now, print tvert indices used by tvfaces
for (int i = 0; i < mesh->getNumFaces(); i++)
{
TVFace tface = mesh->mapFaces(chanloop)[i];
fprintf(m_fileStream, "%s TVFace %d -- tvertind:<%d,%d,%d>\n", GetIndent(indent),
i, tface.t[0], tface.t[1], tface.t[2]);
}
}
}
}
{
int numTVerts = mesh->getNumTVerts();
if(numTVerts>0)
{
fprintf(m_fileStream, "%s texture channel 1 -- numverts:<%d>\n", GetIndent(indent),numTVerts);
for (int i = 0; i < numTVerts; i++)
{
UVVert tvert = mesh->tVerts[i];
fprintf(m_fileStream, "%s UVW tvert %d:<%f,%f,%f>\n", GetIndent(indent),i, tvert.x, tvert.y, tvert.z);
}
// print tvert indices used by tvfaces
for (int i = 0; i < mesh->getNumFaces(); i++)
{
TVFace tface = mesh->tvFace[i];
fprintf(m_fileStream, "%s TVFace %d -- tvertind:<%d,%d,%d>\n",
GetIndent(indent),i, tface.t[0], tface.t[1], tface.t[2]);
}
}
//多重贴图
for (int chanloop = 2; chanloop < MAX_MESHMAPS - 1; chanloop++)
{
if (mesh->mapSupport(chanloop))
{
numTVerts = mesh->getNumMapVerts(chanloop);
fprintf(m_fileStream, "%s texture channel %d -- numverts:<%d>\n", GetIndent(indent),chanloop, numTVerts);
for (int i = 0; i < numTVerts; i++)
{
UVVert tvert = mesh->mapVerts(chanloop)[i];
fprintf(m_fileStream, "%s UVW tvert %d:<%f,%f,%f>\n", GetIndent(indent),i, tvert.x, tvert.y, tvert.z);
}
// now, print tvert indices used by tvfaces
for (int i = 0; i < mesh->getNumFaces(); i++)
{
TVFace tface = mesh->mapFaces(chanloop)[i];
fprintf(m_fileStream, "%s TVFace %d -- tvertind:<%d,%d,%d>\n", GetIndent(indent),
i, tface.t[0], tface.t[1], tface.t[2]);
}
}
}
}