diff --git a/src/Fbx2Raw.cpp b/src/Fbx2Raw.cpp index 671db6c..685a0ce 100644 --- a/src/Fbx2Raw.cpp +++ b/src/Fbx2Raw.cpp @@ -787,6 +787,7 @@ static void ReadMesh(RawModel &raw, FbxScene *pScene, FbxNode *pNode, const std: static_cast(blendShapes.GetBlendChannel(channelIx).deformPercent), shape.normals.LayerPresent(), shape.tangents.LayerPresent(), + shape.shape->GetName() }); } } diff --git a/src/Raw2Gltf.cpp b/src/Raw2Gltf.cpp index b27ec90..cd6c2ed 100644 --- a/src/Raw2Gltf.cpp +++ b/src/Raw2Gltf.cpp @@ -940,7 +940,7 @@ ModelData *Raw2Gltf( GLT_VEC4F, tangents); } - primitive->AddTarget(pAcc.get(), nAcc.get(), tAcc.get()); + primitive->AddTarget(pAcc.get(), nAcc.get(), tAcc.get(), channel.name); } } if (options.useDraco) { diff --git a/src/RawModel.h b/src/RawModel.h index ce3ab67..118930b 100644 --- a/src/RawModel.h +++ b/src/RawModel.h @@ -320,6 +320,7 @@ struct RawBlendChannel float defaultDeform; bool hasNormals; bool hasTangents; + std::string name; }; struct RawSurface diff --git a/src/glTF/PrimitiveData.cpp b/src/glTF/PrimitiveData.cpp index 54c504a..18adbd0 100644 --- a/src/glTF/PrimitiveData.cpp +++ b/src/glTF/PrimitiveData.cpp @@ -39,13 +39,16 @@ void PrimitiveData::NoteDracoBuffer(const BufferViewData &data) dracoBufferView = data.ix; } -void PrimitiveData::AddTarget(const AccessorData *positions, const AccessorData *normals, const AccessorData *tangents) +void PrimitiveData::AddTarget(const AccessorData *positions, const AccessorData *normals, const AccessorData *tangents, + const std::string &shape_name) { targetAccessors.push_back(std::make_tuple( positions->ix, normals ? normals->ix : -1, tangents ? tangents ->ix : -1 )); + + targetNames.push_back(shape_name); } void to_json(json &j, const PrimitiveData &d) { @@ -70,6 +73,15 @@ void to_json(json &j, const PrimitiveData &d) { } j["targets"] = targets; } + if (!d.targetNames.empty()) { + json extras {}; + json names {}; + for (const auto &name : d.targetNames) { + names.push_back(name); + } + extras["target_names"] = names; + j["extras"] = extras; + } if (!d.dracoAttributes.empty()) { j["extensions"] = { { KHR_DRACO_MESH_COMPRESSION, { diff --git a/src/glTF/PrimitiveData.h b/src/glTF/PrimitiveData.h index 892c662..a90da32 100644 --- a/src/glTF/PrimitiveData.h +++ b/src/glTF/PrimitiveData.h @@ -31,7 +31,8 @@ struct PrimitiveData void AddAttrib(std::string name, const AccessorData &accessor); - void AddTarget(const AccessorData *positions, const AccessorData *normals, const AccessorData *tangents); + void AddTarget(const AccessorData *positions, const AccessorData *normals, const AccessorData *tangents, + const std::string &name); template void AddDracoAttrib(const AttributeDefinition attribute, const std::vector &attribArr) @@ -62,6 +63,7 @@ struct PrimitiveData const MeshMode mode; std::vector> targetAccessors {}; + std::vector targetNames {}; std::map attributes; std::map dracoAttributes;