2016-08-19 37 views
0

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

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模式不同。 my render model

the correct .fbx model

我应该怎么办?任何想法?

+0

您是使用左手还是右手的查看坐标? (我看不到你在哪里计算'm_proj'。通常CMO被导出用于右手查看,这就是为什么API提供了一个选项来翻转剔除方向,使它看起来与LH坐标正确。 –

回答

2

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

发送给GPU的三角形有一个排列顺序,它必须通过重新排列三角形顶点来保持一致,顺时针或逆时针方向。然后,渲染状态定义了什么是正面,什么必须被扑灭,正面,背面或没有。

+0

是的,这是对的,我将第四个参数改为false,结果是正确的。 – zhangbaochong