Search code examples
directxdirectx-11directxtk

loading mesh with DirectXTK


I use DirectXTK to load mesh. First, I import .fbx into vs2015 and build, then get .cmo file. Then I use DirectXTK load .cmo as follow:

bool MeshDemo::BuildModels()
{
    m_fxFactory.reset(new EffectFactory(m_pd3dDevice));
    m_states.reset(new CommonStates(m_pd3dDevice)); 
    m_model = Model::CreateFromCMO(m_pd3dDevice, L"T54.cmo", *m_fxFactory, true, true);

    return true;
}
void MeshDemo::Render()
{
    m_pImmediateContext->ClearRenderTargetView(m_pRenderTargetView, Colors::Silver);
    m_pImmediateContext->ClearDepthStencilView(m_pDepthStencilView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);

    XMVECTOR qid = XMQuaternionIdentity();
    const XMVECTORF32 scale = { 0.01f, 0.01f, 0.01f };
    const XMVECTORF32 translate = { 0.f, 0.f, 0.f };
    XMMATRIX world = XMLoadFloat4x4(&m_world);
    XMVECTOR rotate = XMQuaternionRotationRollPitchYaw(0, XM_PI / 2.f, XM_PI / 2.f);
    rotate = XMQuaternionRotationRollPitchYaw(0, XM_PI / 2.f, XM_PI / 2.f);
    XMMATRIX local = XMMatrixMultiply(world, XMMatrixTransformation(
        g_XMZero, qid, scale, g_XMZero, rotate, translate));
    local *= XMMatrixRotationX(-XM_PIDIV2);
    m_model->Draw(m_pImmediateContext, *m_states, local, XMLoadFloat4x4(&m_view),
        XMLoadFloat4x4(&m_proj));

    m_pSwapChain->Present(0, 0);
}

But I can't get correct results,the angle of wheel and some details are different with the .fbx model. my render model

the correct .fbx model

what should I do? Any idear?


Solution

  • Your model is fine, but your culling is inverted, and this is why the render is wrong.

    Triangles sent to the GPU have a winding order, it has to be consistent, clock wise or counter clock wise by rearranging the triangle vertices. Then, a render state define what is the front side, and what has to be culled away, front, back or none.