我在互联网上寻找一些 Assimp 样本,但没有成功。
我有以下结构:
struct VertexTextureNormal
{
XMFLOAT3 Position;
XMFLOAT2 TexCoord;
XMFLOAT3 Normal;
};
任何人都可以发布填充顶点和索引数组的实际代码吗?
答案 0 :(得分:2)
DWORD nIndices;
DWORD *pIndices;
if (pAIMesh->HasFaces())
{
aiFace *pAIFaces;
pAIFaces = pAIMesh->mFaces;
nIndices = pAIMesh->mNumFaces * 3;
pIndices = new DWORD[nIndices];
for (DWORD i = 0; i < pAIMesh->mNumFaces; i++)
{
if (pAIFaces[i].mNumIndices != 3)
{
aiReleaseImport(pScene);
delete[] pIndices;
return E_FAIL;
}
for (DWORD j = 0; j < 3; j++)
{
pIndices[i * 3 + j] = pAIFaces[i].mIndices[j];
}
}
}
if (pAIMesh->HasPositions())
{
DWORD nVertices;
CVertex *pVertices;
nVertices = pAIMesh->mNumVertices;
pVertices = new CVertex[nVertices];
for (DWORD i = 0; i < nVertices; i++)
{
pVertices[i].vPos = XMFLOAT3(pAIMesh->mVertices[i].x, pAIMesh->mVertices[i].y, pAIMesh->mVertices[i].z);
XMStoreFloat3(&pVertices[i].vPos, XMVector3TransformCoord(XMLoadFloat3(&pVertices[i].vPos), mLocalWorld));
}
if (pAIMesh->HasNormals())
{
for (DWORD i = 0; i < nVertices; i++)
{
XMVECTOR xvNormal = XMLoadFloat3((XMFLOAT3 *)&pAIMesh->mNormals[i]);
xvNormal = XMVector3Normalize(xvNormal);
XMStoreFloat3(&pVertices[i].vNormal, xvNormal);
}
}
if (pAIMesh->HasTextureCoords(0))
{
for (DWORD i = 0; i < nVertices; i++)
{
pVertices[i].vTexCoords = XMFLOAT2(pAIMesh->mTextureCoords[0][i].x, pAIMesh->mTextureCoords[0][i].y);
}
}
pMesh->m_pVertices = pVertices;
pMesh->m_dwNumVertices = nVertices;
}