void ModelInfo()
{
const char* fileName = "G:\\CryEngine\\CryEngine3.4.6\\Editor\\Objects\\box.cgf";
IStatObj* pObj = gEnv->p3DEngine->LoadStatObj(fileName);
//Debug模式下pRM可能会获取为空值
IRenderMesh* pRM = pObj->GetRenderMesh();
if (pRM)
{
IIndexedMesh* pIM = pRM->GetIndexedMesh();
CMesh* pMesh = pIM->GetMesh();
/*读出模型信息*/
std::vector<Vec3> Vertices;
std::vector<vtx_idx> Indeices;
std::vector<SMeshTexCoord> TexCoords;
std::vector<SMeshTangents> Tangents;
std::vector<SMeshNormal> Normals;
std::vector<SMeshColor> Color0s;
std::vector<SMeshColor> Color1s;
if (pMesh->GetVertexCount())
{
//顶点
Vec3* pVertices0 = pMesh->GetStreamPtr<Vec3>(CMesh::POSITIONS);
int count = pMesh->GetVertexCount();
for (int i = 0; i < count; ++i)
Vertices.push_back(pVertices0[i]);
//索引
vtx_idx* pIndices0 = pMesh->GetStreamPtr<vtx_idx>(CMesh::INDICES);
int counti = pMesh->GetIndexCount();
for (int i = 0; i < counti; ++i)
Indeices.push_back(pIndices0[i]);
//纹理坐标
SMeshTexCoord* pTexCoords0 = pMesh->GetStreamPtr<SMeshTexCoord>(CMesh::TEXCOORDS);
for (int i = 0; i < count; ++i)
TexCoords.push_back(pTexCoords0[i]);
//切线坐标
SMeshTangents* pTangents = pMesh->GetStreamPtr<SMeshTangents>(CMesh::TANGENTS);
for (int i = 0; i < count; ++i)
Tangents.push_back(pTangents[i]);
//法线坐标
SMeshNormal* pNormal = pMesh->GetStreamPtr<SMeshNormal>(CMesh::NORMALS);
for (int i = 0; i < count; ++i)
Normals.push_back(pNormal[i]);
//颜色1
SMeshColor* pColor0 = pMesh->GetStreamPtr<SMeshColor>(CMesh::COLORS_0);
if (pColor0)
{
for (int i = 0; i < count; ++i)
Color0s.push_back(pColor0[i]);
}
//颜色2
SMeshColor* pColor1 = pMesh->GetStreamPtr<SMeshColor>(CMesh::COLORS_1);
if (pColor1)
{
for (int i = 0; i < count; ++i)
Color0s.push_back(pColor1[i]);
}
}
}
}
获取的都是数据的首地址,所以只再知道数据的size就能一个个提取出来了,size一般直接从mesh对象就可以Get到
本文详细介绍了如何使用CryEngine的API读取并解析3D模型文件(box.cgf)的数据,包括顶点、索引、纹理坐标、切线、法线及颜色等信息,为游戏开发和3D图形处理提供了实用的代码示例。
2460

被折叠的 条评论
为什么被折叠?



