Browse Source

Export Nodes before meshes to avoid issue if node id's are changed

Angelo Scandaliato 9 năm trước cách đây
mục cha
commit
42a8d58f45
1 tập tin đã thay đổi với 9 bổ sung66 xóa
  1. 9 66
      code/glTFExporter.cpp

+ 9 - 66
code/glTFExporter.cpp

@@ -130,18 +130,16 @@ glTFExporter::glTFExporter(const char* filename, IOSystem* pIOSystem, const aiSc
 
     //for (unsigned int i = 0; i < pScene->mNumLights; ++i) {}
 
-
     ExportMaterials();
 
-    ExportMeshes();
-
-    //for (unsigned int i = 0; i < pScene->mNumTextures; ++i) {}
-
-
     if (mScene->mRootNode) {
         ExportNode(mScene->mRootNode);
     }
 
+    ExportMeshes();
+
+    //for (unsigned int i = 0; i < pScene->mNumTextures; ++i) {}
+
     ExportScene();
 
     ExportAnimations();
@@ -581,14 +579,12 @@ void glTFExporter::ExportMeshes()
 			m->Extension.push_back(ext);
 #endif
 		}// if(comp_allow)
-	}// for (unsigned int i = 0; i < mScene->mNumMeshes; ++i) {
+	}// for (unsigned int i = 0; i < mScene->mNumMeshes; ++i)
 }
 
 unsigned int glTFExporter::ExportNode(const aiNode* n)
 {
-    std::cout<< "n->mName.C_Str() " << n->mName.C_Str() << "\n";
     Ref<Node> node = mAsset->nodes.Create(mAsset->FindUniqueID(n->mName.C_Str(), "node"));
-    std::cout<< "node->id " << node->id << "\n";
 
     if (!n->mTransformation.IsIdentity()) {
         node->matrix.isPresent = true;
@@ -704,6 +700,10 @@ inline Ref<Accessor> ExportAnimationData(Asset& a, std::string& animId, Ref<Buff
 
 inline void ExtractAnimationData(Asset& mAsset, std::string& animId, Ref<Animation>& animRef, Ref<Buffer>& buffer, const aiNodeAnim* nodeChannel)
 {
+    // Loop over the data and check to see if it exactly matches an existing buffer.
+    //    If yes, then reference the existing corresponding accessor.
+    //    Otherwise, add to the buffer and create a new accessor.
+
     //-------------------------------------------------------
     // Extract TIME parameter data.
     // Check if the timeStamps are the same for mPositionKeys, mRotationKeys, and mScalingKeys.
@@ -762,33 +762,8 @@ inline void ExtractAnimationData(Asset& mAsset, std::string& animId, Ref<Animati
 
 void glTFExporter::ExportAnimations()
 {
-    // //--------------------------
-    // // Setup to output buffer data
-    // // Not for
-    // //     using IndicesType = decltype(aiFace::mNumIndices);
-    // // But yes for
-    // //     using IndicesType = unsigned short;
-    // // because "ComponentType_UNSIGNED_SHORT" used for indices. And it's a maximal type according to glTF specification.
-    // typedef unsigned short IndicesType;
-
-    // // Variables needed for compression. BEGIN.
-    // // Indices, not pointers - because pointer to buffer is changing while writing to it.
-    // size_t idx_srcdata_begin;// Index of buffer before writing mesh data. Also, index of begin of coordinates array in buffer.
-    // size_t idx_srcdata_normal = SIZE_MAX;// Index of begin of normals array in buffer. SIZE_MAX - mean that mesh has no normals.
-    // std::vector<size_t> idx_srcdata_tc;// Array of indices. Every index point to begin of texture coordinates array in buffer.
-    // size_t idx_srcdata_ind;// Index of begin of coordinates indices array in buffer.
-    // bool comp_allow;// Point that data of current mesh can be compressed.
-    // // Variables needed for compression. END.
-
-    // std::string fname = std::string(mFilename);
-    // std::string bufferIdPrefix = fname.substr(0, fname.find("."));
-    // std::string bufferId = mAsset->FindUniqueID("", bufferIdPrefix.c_str());
-
-    // Ref<Buffer> b = mAsset->GetBodyBuffer();
     Ref<Buffer> bufferRef = mAsset->buffers.Get(unsigned (0));
     std::cout<<"GetBodyBuffer " << bufferRef << "\n";
-    // // Setup to output buffer data
-    // //--------------------------
 
     std::cout<<"mNumAnimations " << mScene->mNumAnimations << "\n";
     for (unsigned int i = 0; i < mScene->mNumAnimations; ++i) {
@@ -811,40 +786,8 @@ void glTFExporter::ExportAnimations()
             std::cout<<"channelName " << name << "\n";
 
             /******************* Parameters ********************/
-            // If compression is used then you need parameters of uncompressed region: begin and size. At this step "begin" is stored.
-            // if(comp_allow) idx_srcdata_begin = bufferRef->byteLength;
-
-            // Loop over the data and check to see if it exactly matches an existing buffer.
-            //    If yes, then reference the existing corresponding accessor.
-            //    Otherwise, add to the buffer and create a new accessor.
             ExtractAnimationData(*mAsset, name, animRef, bufferRef, nodeChannel);
 
-            // for (unsigned int j = 0; j < 3; ++j) {
-            //     std::string channelType;
-            //     switch (j) {
-            //         case 0:
-            //             channelType = "rotation";
-            //             break;
-            //         case 1:
-            //             channelType = "scale";
-            //             break;
-            //         case 2:
-            //             channelType = "translation";
-            //             break;
-            //     }
-
-            //     animRef->Channels[j].sampler = name + "_" + channelType;
-            //     animRef->Channels[j].target.path = channelType;
-            //     animRef->Samplers[j].output = channelType;
-            //     animRef->Samplers[j].id = name + "_" + channelType;
-
-            //     animRef->Channels[j].target.id = mAsset->nodes.Get(nodeChannel->mNodeName.C_Str());
-
-            //     animRef->Samplers[j].input = "TIME";
-            //     animRef->Samplers[j].interpolation = "LINEAR";
-            // }
-
-
             for (unsigned int j = 0; j < 3; ++j) {
                 std::string channelType;
                 int channelSize;