DirectXTK12 icon indicating copy to clipboard operation
DirectXTK12 copied to clipboard

Wiki Issue for Getting Started -> Animating using model bones

Open focusright opened this issue 1 year ago • 3 comments

In this wiki documentation

https://github.com/microsoft/DirectXTK12/wiki/Animating-using-model-bones#modifying-model-bones

The result does not match the screenshot provided. The problem can be addressed either in the model or the CreateLookAt() function in Game::CreateWindowSizeDependentResources(). Since I don't have the original source file of the model I fixed it in the code with

void Game::CreateWindowSizeDependentResources()
{
    // TODO: Initialize windows-size dependent objects here.

    auto size = m_deviceResources->GetOutputSize();
    m_view = Matrix::CreateLookAt(Vector3(10, 2, 0),
        Vector3(0, 2, 0), Vector3::UnitY);
    m_proj = Matrix::CreatePerspectiveFieldOfView(XM_PI / 4.f,
        float(size.right) / float(size.bottom), 0.1f, 10000.f);
}

The main fix being in changing the Vector3 parameters in the CreateLookAt() function.

focusright avatar Mar 27 '24 06:03 focusright

The repo where I am working on this is located here

https://github.com/focusright/graphics/tree/main/codebase/directx12/practice/03-directxtk12-wiki/07-animating-using-model-bones

focusright avatar Mar 27 '24 06:03 focusright

FWIW, all the tutorials source can be found https://github.com/walbourn/directxtk-tutorials

walbourn avatar Mar 27 '24 18:03 walbourn

I looked at the tutorial source and found the culprit, the line

m_model->CopyBoneTransformsTo(nbones, m_animBones.get());

needs to remain right after the lines where the bone arrays are made:

m_drawBones = ModelBone::MakeArray(nbones);
m_animBones = ModelBone::MakeArray(nbones);

m_model->CopyBoneTransformsTo(nbones, m_animBones.get());

uint32_t index = 0;
for (const auto& it : m_model->bones)
{
    if (_wcsicmp(it.name.c_str(), L"tank_geo") == 0)
    {
        // Need to recenter the model.
        m_animBones[index] = XMMatrixIdentity();
    }

    ++index;  
}

In this section of the wiki

https://github.com/microsoft/DirectXTK12/wiki/Animating-using-model-bones#modifying-model-bones

the last sentence is "(after you have loaded the model and created the bone arrays):"

which made my code like this:

m_drawBones = ModelBone::MakeArray(nbones);
m_animBones = ModelBone::MakeArray(nbones);

uint32_t index = 0;
for (const auto& it : m_model->bones)
{
    if (_wcsicmp(it.name.c_str(), L"tank_geo") == 0)
    {
        // Need to recenter the model.
        m_animBones[index] = XMMatrixIdentity();
    }

    ++index;  
}

m_model->CopyBoneTransformsTo(nbones, m_animBones.get());

Hopefully this will help someone else who tries to follow the tutorial like I did.

focusright avatar Mar 28 '24 21:03 focusright

Thanks for the feedback.

Hopefully the edits here make it more clear:

https://github.com/microsoft/DirectXTK/wiki/Animating-using-model-bones

https://github.com/microsoft/DirectXTK12/wiki/Animating-using-model-bones

walbourn avatar Aug 22 '24 19:08 walbourn