Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The rendering result is NOT correct when multiple meshes is included within the same GLTF file! #26

Open
HanetakaChou opened this issue Dec 28, 2024 · 1 comment

Comments

@HanetakaChou
Copy link
Contributor

I try to use this GLTF file, and I get the following result.
1

When I debug the code, I realize that the same index buffer may be shared by different skinned meshes.
Scene::CreateMeshBuffers

 // ...

 for (const auto& skinnedInstance : m_SceneGraph->GetSkinnedMeshInstances())
    {
        const auto& skinnedMesh = skinnedInstance->GetMesh();

        if (!skinnedMesh->buffers)
        {
            skinnedMesh->buffers = std::make_shared<BufferGroup>();

            uint32_t totalVertices = skinnedMesh->totalVertices;

            skinnedMesh->buffers->indexBuffer = skinnedInstance->GetPrototypeMesh()->buffers->indexBuffer;
            skinnedMesh->buffers->indexBufferDescriptor = skinnedInstance->GetPrototypeMesh()->buffers->indexBufferDescriptor;

 // ...

This means that the index offset should NOT be omitted when we create the skinned mesh.
SkinnedMeshInstance::SkinnedMeshInstance

// ...

SkinnedMeshInstance::SkinnedMeshInstance(std::shared_ptr<SceneTypeFactory> sceneTypeFactory, std::shared_ptr<MeshInfo> prototypeMesh)
    : MeshInstance(nullptr)
    , m_SceneTypeFactory(sceneTypeFactory)
{
    m_PrototypeMesh = std::move(prototypeMesh);
    
    auto skinnedMesh = m_SceneTypeFactory->CreateMesh();
    skinnedMesh->skinPrototype = m_PrototypeMesh;
    skinnedMesh->name = m_PrototypeMesh->name;
    skinnedMesh->objectSpaceBounds = m_PrototypeMesh->objectSpaceBounds;
    // ** This line is what I add!
    skinnedMesh->indexOffset = m_PrototypeMesh->indexOffset;
    // **
    skinnedMesh->totalVertices = m_PrototypeMesh->totalVertices;
    skinnedMesh->totalIndices = m_PrototypeMesh->totalIndices;
    skinnedMesh->geometries.reserve(m_PrototypeMesh->geometries.size());

// ...    
@HanetakaChou
Copy link
Contributor Author

@apanteleev One Pull Request has been created!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant