From 072d17d64f4dcb0fff768cf64d20e33b14c60abc Mon Sep 17 00:00:00 2001 From: Philip Rideout Date: Wed, 6 May 2020 15:25:33 -0700 Subject: [PATCH] gltfio: use the new material name feature. To see proof that this works, use gltf_viewer with -u and examine the node hierarchy. You will now see the correct material names instead of the ubershader names. --- libs/gltfio/include/gltfio/SimpleViewer.h | 3 +-- libs/gltfio/src/MaterialGenerator.cpp | 4 ++-- libs/gltfio/src/UbershaderLoader.cpp | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/libs/gltfio/include/gltfio/SimpleViewer.h b/libs/gltfio/include/gltfio/SimpleViewer.h index bf97c51a5f..352f0bae94 100644 --- a/libs/gltfio/include/gltfio/SimpleViewer.h +++ b/libs/gltfio/include/gltfio/SimpleViewer.h @@ -380,8 +380,7 @@ void SimpleViewer::updateUserInterface() { rm.setCastShadows(instance, scaster); size_t numPrims = rm.getPrimitiveCount(instance); for (size_t prim = 0; prim < numPrims; ++prim) { - const Material* mat = rm.getMaterialInstanceAt(instance, prim)->getMaterial(); - const char* mname = mat->getName(); + const char* mname = rm.getMaterialInstanceAt(instance, prim)->getName(); if (mname) { ImGui::Text("prim %zu: material %s", prim, mname); } else { diff --git a/libs/gltfio/src/MaterialGenerator.cpp b/libs/gltfio/src/MaterialGenerator.cpp index f5456ecdf3..82daf4e949 100644 --- a/libs/gltfio/src/MaterialGenerator.cpp +++ b/libs/gltfio/src/MaterialGenerator.cpp @@ -381,9 +381,9 @@ MaterialInstance* MaterialGenerator::createMaterialInstance(MaterialKey* config, Material* mat = createMaterial(mEngine, *config, *uvmap, label); mCache.emplace(std::make_pair(*config, mat)); mMaterials.push_back(mat); - return mat->createInstance(); + return mat->createInstance(label); } - return iter->second->createInstance(); + return iter->second->createInstance(label); } } // anonymous namespace diff --git a/libs/gltfio/src/UbershaderLoader.cpp b/libs/gltfio/src/UbershaderLoader.cpp index bc65a32249..fdeaf75cb6 100644 --- a/libs/gltfio/src/UbershaderLoader.cpp +++ b/libs/gltfio/src/UbershaderLoader.cpp @@ -149,7 +149,7 @@ MaterialInstance* UbershaderLoader::createMaterialInstance(MaterialKey* config, return hasTexture ? int(uvmap->at(srcIndex)) - 1 : -1; }; Material* material = getMaterial(*config); - MaterialInstance* mi = material->createInstance(); + MaterialInstance* mi = material->createInstance(label); mi->setParameter("baseColorIndex", getUvIndex(config->baseColorUV, config->hasBaseColorTexture)); mi->setParameter("normalIndex", getUvIndex(config->normalUV, config->hasNormalTexture));