Skip to content

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

Description

@HanetakaChou

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

// ...    

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions