Skip to content

Commit

Permalink
Morph target names output to mesh.extras.targetNames (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
vfxgordon authored and Pär Winzell committed Oct 7, 2019
1 parent 5c3229d commit 1d73569
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/gltf/properties/MeshData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,21 @@ MeshData::MeshData(const std::string& name, const std::vector<float>& 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;
}
1 change: 1 addition & 0 deletions src/gltf/properties/PrimitiveData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/gltf/properties/PrimitiveData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ struct PrimitiveData {
const MeshMode mode;

std::vector<std::tuple<int, int, int>> targetAccessors{};
std::vector<std::string> targetNames{};

std::map<std::string, int> attributes;
std::map<std::string, int> dracoAttributes;
Expand Down

0 comments on commit 1d73569

Please sign in to comment.