Skip to content

Commit

Permalink
Fix: Export lightIndex if available
Browse files Browse the repository at this point in the history
  • Loading branch information
spnda committed Jun 19, 2024
1 parent ee4b705 commit fe713dc
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions src/fastgltf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3075,7 +3075,7 @@ fg::Error fg::Parser::parseMaterials(simdjson::dom::array& materials, Asset& ass
}

dom::object extensionsObject;
if (auto extensionError = materialObject["extensions"].get_object().get(extensionsObject); extensionError == SUCCESS) FASTGLTF_LIKELY {
if (auto extensionError = materialObject["extensions"].get_object().get(extensionsObject); extensionError == SUCCESS) {
parseMaterialExtensions(extensionsObject, material);
} else if (extensionError != NO_SUCH_FIELD) FASTGLTF_UNLIKELY {
return Error::InvalidJson;
Expand Down Expand Up @@ -5020,15 +5020,24 @@ void fg::Exporter::writeNodes(const Asset& asset, std::string& json) {
},
}, it->transform);

if (!it->instancingAttributes.empty()) {
if (!it->instancingAttributes.empty() || it->lightIndex.has_value()) {
if (json.back() != '{') json += ',';
json += R"("extensions":{"EXT_mesh_gpu_instancing":{"attributes":{)";
for (auto ait = it->instancingAttributes.begin(); ait != it->instancingAttributes.end(); ++ait) {
json += '"' + std::string(ait->first) + "\":" + std::to_string(ait->second);
if (uabs(std::distance(it->instancingAttributes.begin(), ait)) + 1 <it->instancingAttributes.size())
json += ',';
}
json += "}}}";
json += R"("extensions":{)";
if (!it->instancingAttributes.empty()) {
json += R"("EXT_mesh_gpu_instancing":{"attributes":{)";
for (auto ait = it->instancingAttributes.begin(); ait != it->instancingAttributes.end(); ++ait) {
json += '"' + std::string(ait->first) + "\":" + std::to_string(ait->second);
if (uabs(std::distance(it->instancingAttributes.begin(), ait)) + 1 <
it->instancingAttributes.size())
json += ',';
}
json += "}}";
}
if (it->lightIndex.has_value()) {
if (json.back() != '{') json += ',';
json += R"("KHR_lights_punctual":{"light":)" + std::to_string(it->lightIndex.value()) + "}";
}
json += "}";
}

if (extrasWriteCallback != nullptr) {
Expand Down

0 comments on commit fe713dc

Please sign in to comment.