我是用DirectXToolKit做一些基本的渲染,我希望能夠獲得每個模型的頂點座標爲了計算模型之間的衝突。如何從DirectXTK(ToolKit)獲取所有頂點座標DirectX :: Model類用於碰撞檢測
目前,我有一些測試代碼加載模式,但ID3D11Buffer
負載內部使用CreateFromSDKMESH
void Model3D::LoadSDKMESH(ID3D11Device* p_device, ID3D11DeviceContext* device_context, const wchar_t* file_mesh)
{
mAlpha = 1.0f;
mTint = DirectX::Colors::White.v;
mStates.reset(new DirectX::CommonStates(p_device));
auto fx = new DirectX::EffectFactory(p_device);
fx->SetDirectory(L"media");
mFxFactory.reset(fx);
mBatch.reset(new DirectX::PrimitiveBatch<DirectX::VertexPositionColor>(device_context));
mBatchEffect.reset(new DirectX::BasicEffect(p_device));
mBatchEffect->SetVertexColorEnabled(true);
{
void const* shaderByteCode;
size_t byteCodeLength;
mBatchEffect->GetVertexShaderBytecode(&shaderByteCode, &byteCodeLength);
HR(p_device->CreateInputLayout(DirectX::VertexPositionColor::InputElements,
DirectX::VertexPositionColor::InputElementCount,
shaderByteCode, byteCodeLength,
mBatchInputLayout.ReleaseAndGetAddressOf()));
}
mModel = DirectX::Model::CreateFromSDKMESH(p_device, file_mesh, *mFxFactory);
}
我知道有一種方式來獲得從ID3D11Buffer
頂點,回答在這裏: How to read vertices from vertex buffer in Direct3d11
但他們建議不要從GPU內存加載。所以我認爲最好是提前加載頂點到一個單獨的容器中。