Browse Source

gltf2 export target names for blendshapes

Yingying Wang 5 years ago
parent
commit
4e34853ac7
2 changed files with 21 additions and 0 deletions
  1. 16 0
      code/AssetLib/glTF2/glTF2AssetWriter.inl
  2. 5 0
      code/AssetLib/glTF2/glTF2Exporter.cpp

+ 16 - 0
code/AssetLib/glTF2/glTF2AssetWriter.inl

@@ -468,6 +468,22 @@ namespace glTF2 {
         }
         }
 
 
         obj.AddMember("primitives", primitives, w.mAl);
         obj.AddMember("primitives", primitives, w.mAl);
+        // targetNames
+        if (m.targetNames.size() > 0) {
+            Value extras;
+            extras.SetObject();
+            Value targetNames;
+            targetNames.SetArray();
+            targetNames.Reserve(unsigned(m.targetNames.size()), w.mAl);
+            for (unsigned int n = 0; n < m.targetNames.size(); ++n) {
+                std::string name = m.targetNames[n];
+                Value tname;
+                tname.SetString(name.c_str(), w.mAl);
+                targetNames.PushBack(tname, w.mAl);
+            }
+            extras.AddMember("targetNames", targetNames, w.mAl);
+            obj.AddMember("extras", extras, w.mAl);
+        }
     }
     }
 
 
     inline void Write(Value& obj, Node& n, AssetWriter& w)
     inline void Write(Value& obj, Node& n, AssetWriter& w)

+ 5 - 0
code/AssetLib/glTF2/glTF2Exporter.cpp

@@ -824,9 +824,14 @@ void glTF2Exporter::ExportMeshes()
 
 
         /*************** Targets for blendshapes ****************/
         /*************** Targets for blendshapes ****************/
         if (aim->mNumAnimMeshes > 0) {
         if (aim->mNumAnimMeshes > 0) {
+            bool bExportTargetNames = this->mProperties->HasPropertyBool("GLTF2_TARGETNAMES_EXP") &&
+                              this->mProperties->GetPropertyBool("GLTF2_TARGETNAMES_EXP");
+
             p.targets.resize(aim->mNumAnimMeshes);
             p.targets.resize(aim->mNumAnimMeshes);
             for (unsigned int am = 0; am < aim->mNumAnimMeshes; ++am) {
             for (unsigned int am = 0; am < aim->mNumAnimMeshes; ++am) {
                 aiAnimMesh *pAnimMesh = aim->mAnimMeshes[am];
                 aiAnimMesh *pAnimMesh = aim->mAnimMeshes[am];
+                if (bExportTargetNames)
+                    m->targetNames.push_back(pAnimMesh->mName.data);
 
 
                 // position
                 // position
                 if (pAnimMesh->HasPositions()) {
                 if (pAnimMesh->HasPositions()) {