From 42a8d58f45af0227c1c509dd08576745f757fbf3 Mon Sep 17 00:00:00 2001 From: Angelo Scandaliato Date: Thu, 6 Oct 2016 11:29:09 -0700 Subject: [PATCH] Export Nodes before meshes to avoid issue if node id's are changed --- code/glTFExporter.cpp | 75 ++++++------------------------------------- 1 file changed, 9 insertions(+), 66 deletions(-) diff --git a/code/glTFExporter.cpp b/code/glTFExporter.cpp index 7a0a9a8a3..d3179e56a 100644 --- a/code/glTFExporter.cpp +++ b/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 = 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 ExportAnimationData(Asset& a, std::string& animId, Ref& animRef, Ref& 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 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 b = mAsset->GetBodyBuffer(); Ref 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;