使用ASSIMP在DirectX9中加载.obj模型

使用ASSIMP在DirectX9中加载.obj模型

问题描述:

这是我第一次发布。我有这个问题,这个3d模型加载库ASSIMP。我试图将其集成到一个示例Direct3d9应用程序。它不会这么好。我是一个有经验的C ++程序员,所以它不应该花太多麻烦帮助我:)。所以我在过去做了几个d3d9应用程序和渲染手动原语。但现在我试图渲染一个obj模型加载ASSIMP。当我试图渲染它,没有任何渲染。这是非常奇怪,甚至没有一个poly渲染。这是非常令人沮丧,因为我花了1周试图解决这一个问题,在谷歌搜索返回没有有用的结果。你们老实说是我最后的希望。确定这里是我的代码。漂亮请看看,帮助我明白我做错了什么。如果你知道一个directx9 ASSIMP示例的链接,也会赞赏作为google只显示OpenGL :(任何帮助将非常感谢:)

This is my first time posting. I have this issue with this 3d model loading library called ASSIMP. I am trying to integrate it in a sample Direct3d9 app. and it is not going so well. I am an experienced C++ programmer so it shouldn't take too much hassle to help me :). So i have in the past made several d3d9 apps and rendered manual primitives. but now i am trying to render an obj model loaded with ASSIMP. when i try to render it, NOTHING is rendered at all. this is very weird, not even one poly is rendered. this is VERY frustrating as i have spent 1 week trying to fix this one problem and searching on google returns no useful results. you guys are honestly my last hope lol. ok so here is my code. pretty please take a look and help me understand what i am doing wrong. also if you know of a link where a directx9 ASSIMP example may be that would also be appreciated as google only shows OpenGL :(. Any help will be much appreciated thanks :)

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);
}


我在这段代码中找不到任何错误。你确定你的指针都指向他们应该在哪里?

I might be getting old but i can't find anything wrong in this code. Are you sure your pointers are all pointing where they should?