From 1d735698ba008d8581a77cd83a9da81d134a097f Mon Sep 17 00:00:00 2001 From: vfxgordon Date: Mon, 7 Oct 2019 16:46:38 -0700 Subject: [PATCH] Morph target names output to mesh.extras.targetNames (#231) --- src/gltf/properties/MeshData.cpp | 9 +++++++++ src/gltf/properties/PrimitiveData.cpp | 1 + src/gltf/properties/PrimitiveData.hpp | 1 + 3 files changed, 11 insertions(+) diff --git a/src/gltf/properties/MeshData.cpp b/src/gltf/properties/MeshData.cpp index 0ec3cdd5..36c06dcb 100644 --- a/src/gltf/properties/MeshData.cpp +++ b/src/gltf/properties/MeshData.cpp @@ -14,12 +14,21 @@ MeshData::MeshData(const std::string& name, const std::vector& weights) json MeshData::serialize() const { json jsonPrimitivesArray = json::array(); + json jsonTargetNamesArray = json::array(); for (const auto& primitive : primitives) { jsonPrimitivesArray.push_back(*primitive); + if (!primitive->targetNames.empty()) { + for (auto targetName : primitive->targetNames) { + jsonTargetNamesArray.push_back(targetName); + } + } } json result = {{"name", name}, {"primitives", jsonPrimitivesArray}}; if (!weights.empty()) { result["weights"] = weights; } + if (!jsonTargetNamesArray.empty()) { + result["extras"]["targetNames"] = jsonTargetNamesArray; + } return result; } diff --git a/src/gltf/properties/PrimitiveData.cpp b/src/gltf/properties/PrimitiveData.cpp index 9ee0bccb..14d3a295 100644 --- a/src/gltf/properties/PrimitiveData.cpp +++ b/src/gltf/properties/PrimitiveData.cpp @@ -45,6 +45,7 @@ void PrimitiveData::AddTarget( positions->ix, normals != nullptr ? normals->ix : -1, tangents != nullptr ? tangents->ix : -1)); + targetNames.push_back(positions->name); } void to_json(json& j, const PrimitiveData& d) { diff --git a/src/gltf/properties/PrimitiveData.hpp b/src/gltf/properties/PrimitiveData.hpp index 6e87e533..1ff401b2 100644 --- a/src/gltf/properties/PrimitiveData.hpp +++ b/src/gltf/properties/PrimitiveData.hpp @@ -68,6 +68,7 @@ struct PrimitiveData { const MeshMode mode; std::vector> targetAccessors{}; + std::vector targetNames{}; std::map attributes; std::map dracoAttributes;