DiligentGraphics / DiligentTools

Utilities built on top of core module
Apache License 2.0
115 stars 69 forks source link

GLTF Material not matched #232

Closed widefire closed 1 month ago

widefire commented 1 month ago

The GLTF material not matched with some files.while the gltf file materials not empty,but some primitive material_id == -1,these primitives used the last of materials. I found in founction void Model::LoadMaterials(const tinygltf::Model& gltf_model, const ModelCreateInfo::MaterialLoadCallbackType& MaterialLoadCallback) create default material only when the gltf file no materials:

if (Materials.empty())
{
    // Push a default material for meshes with no material assigned
    Materials.push_back(Material{});
}

in function https://github.com/DiligentGraphics/DiligentTools/blob/fe2bc14c747314a6924fc59c6782a4697b5c6473/AssetLoader/interface/GLTFBuilder.hpp#L356 NewMesh.Primitives.emplace_back( IndexStart, IndexCount, VertexCount, GltfPrimitive.GetMaterialId() >= 0 ? static_cast(GltfPrimitive.GetMaterialId()) : static_cast(m_Model.Materials.size() - 1), PosMin, PosMax // ); just use the last material while Primitive mateiral_id < 0, so these primitives display error

TheMostDiligent commented 1 month ago

Can you provide a model that reproduces this problem?

widefire commented 1 month ago

this is a gltf file display error in GLTF Viewer basic_sample_new_material.zip trees and car colored red,as below gltf_viewer but they are no materials,in three.js like this: three