3

这是我第一次发帖。我对这个名为 ASSIMP 的 3d 模型加载库有这个问题。我正在尝试将其集成到示例 Direct3d9 应用程序中。而且进展不顺利。我是一位经验丰富的 C++ 程序员,所以帮助我应该不会太麻烦:)。所以我过去制作了几个 d3d9 应用程序并渲染了手动原语。但现在我正在尝试渲染一个加载了 ASSIMP 的 obj 模型。当我尝试渲染它时,根本没有渲染任何内容。这很奇怪,甚至没有渲染一个多边形。这非常令人沮丧,因为我花了 1 周的时间试图解决这个问题,但在谷歌上搜索没有返回任何有用的结果。老实说,你们是我最后的希望,哈哈。好的,这是我的代码。漂亮请看一下并帮助我了解我做错了什么。

bool Mesh::LoadMesh(const std::string& Filename)
{

Assimp::Importer Importer;
const aiScene *pScene = NULL;
const aiMesh *pMesh = NULL;

pScene = Importer.ReadFile(Filename.c_str(), aiProcess_Triangulate | aiProcess_ConvertToLeftHanded | aiProcess_ValidateDataStructure | aiProcess_FindInvalidData);

if (!pScene)
{
    printf("Error parsing '%s': '%s'\n", Filename.c_str(), Importer.GetErrorString());
    return false;
}

pMesh = pScene->mMeshes[0];
if (!pMesh)
{
    printf("Error Finding Model In file.  Did you export an empty scene?");
    return false;
}

for (unsigned int i = 0; i < pMesh->mNumFaces; i++) 
{
    if (pMesh->mFaces[i].mNumIndices == 3)
    {
        m_NumIndices = m_NumIndices + 3;
    }

    else
    {
        printf("Error parsing Faces. Try to Re-Export model from 3d package!");
        return false;
    }
}

m_NumFaces = pMesh->mNumFaces;
m_NumVertecies = pMesh->mNumVertices;

ZeroMemory(&m_pVB, sizeof(m_pVB));


m_pRenderDevice->CreateVertexBuffer(sizeof(Vertex) * m_NumVertecies, 0, VertexFVF, D3DPOOL_DEFAULT, &m_pVB, NULL);


m_pVB->Lock(0, 0, (void**)&m_pVertecies, 0);

for (int i = 0; i < pMesh->mNumVertices; i++)
{
    Vertex *pvertex = new Vertex(D3DXVECTOR3(pMesh->mVertices[i].x, pMesh->mVertices[i].y, pMesh->mVertices[i].z), D3DXVECTOR2(pMesh->mTextureCoords[0][i].x, pMesh->mTextureCoords[0][i].y), D3DXVECTOR3(pMesh->mNormals[i].x, pMesh->mNormals[i].y, pMesh->mNormals[i].z));
    m_pVertecies[i] = pvertex;
}

m_pVB->Unlock();


return true;
}





void Mesh::Render()
{
m_pRenderDevice->SetStreamSource(0, m_pVB, 0, sizeof(Vertex));
m_pRenderDevice->SetFVF(VertexFVF);
m_pRenderDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, m_NumFaces);
}





void Render()
{
D3DCOLOR Color = D3DCOLOR_ARGB(255, 0, 0, 255);

//Clear the Z and Back buffers
g_pRenderDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, Color, 1.0f, 0);

g_pRenderDevice->BeginScene();


InitializeViewMatrix();


D3DXMATRIX Scale;
D3DXMatrixScaling(&Scale, CameraScaleX, CameraScaleY, CameraScaleZ);


D3DXMATRIX Rotation;

CameraRotX += 0.025;
D3DXMatrixRotationYawPitchRoll(&Rotation, CameraRotX, CameraRotY, CameraRotZ);

g_pRenderDevice->SetTransform(D3DTS_WORLD, &D3DXMATRIX(Scale * Rotation));


if (pMesh)
{
    pMesh->Render();
}


g_pRenderDevice->EndScene();

g_pRenderDevice->Present(NULL, NULL, NULL, NULL);
}
4

1 回答 1

0

我可能变老了,但我在这段代码中找不到任何错误。你确定你的指针都指向他们应该指向的地方吗?

于 2012-12-28T21:16:17.973 回答