使用 DirectXTK 加载网格

loading mesh with DirectXTK

我使用 DirectXTK 加载网格。首先,我将 .fbx 导入 vs2015 并构建,然后获取 .cmo 文件。然后我使用 DirectXTK 加载 .cmo 如下:

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

但是我无法得到正确的结果,车轮的角度和一些细节与.fbx模型不同。

我该怎么办?有什么想法吗?

你的模型没问题,但是你的剔除是倒置的,这就是渲染错误的原因。

发送到 GPU 的三角形有一个缠绕顺序,它必须是一致的,通过重新排列三角形顶点顺时针或逆时针。然后,渲染状态定义什么是正面,什么必须剔除,正面、背面或 none.