From: Angelo Scandaliato Date: Thu, 6 Oct 2016 22:18:33 +0000 (-0700) Subject: moved ExportSkins function into ExportMeshes function X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ae36ca0e44674eb6e40e8a3a123f1cb5c064612e;p=platform%2Fupstream%2Fassimp.git moved ExportSkins function into ExportMeshes function --- diff --git a/code/glTFAsset.h b/code/glTFAsset.h index 4b5fb67..4d95938 100644 --- a/code/glTFAsset.h +++ b/code/glTFAsset.h @@ -807,7 +807,7 @@ namespace glTF Ref camera; Ref light; - std::vector< Ref > skeletons; //!< The ID of skeleton nodes. + std::vector< Ref > skeletons; //!< The ID of skeleton nodes. Each of which is the root of a node hierarchy. Ref skin; //!< The ID of the skin referenced by this node. std::string jointName; //!< Name used when this node is a joint in a skin. diff --git a/code/glTFAssetWriter.inl b/code/glTFAssetWriter.inl index 1b11987..5443455 100644 --- a/code/glTFAssetWriter.inl +++ b/code/glTFAssetWriter.inl @@ -386,6 +386,12 @@ namespace glTF { AddRefsVector(obj, "meshes", n.meshes, w.mAl); + AddRefsVector(obj, "skeletons", n.skeletons, w.mAl); + + if (n.skin) { + obj.AddMember("skin", Value(n.skin->id, w.mAl).Move(), w.mAl); + } + if (!n.jointName.empty()) { obj.AddMember("jointName", n.jointName, w.mAl); } diff --git a/code/glTFExporter.cpp b/code/glTFExporter.cpp index 8892db0..8947b5f 100644 --- a/code/glTFExporter.cpp +++ b/code/glTFExporter.cpp @@ -144,8 +144,6 @@ glTFExporter::glTFExporter(const char* filename, IOSystem* pIOSystem, const aiSc ExportAnimations(); - ExportSkins(); - glTF::AssetWriter writer(*mAsset); if (isBinary) { @@ -367,6 +365,51 @@ void glTFExporter::ExportMaterials() } } +void ExportSkins(Asset& mAsset, const aiMesh* aim, Ref& meshRef, Ref& bufferRef) +{ + if(!aim->HasBones()) { return; } // skip to next mesh if no bones exist. + + std::string skinName = aim->mName.C_Str(); + skinName = mAsset.FindUniqueID(skinName, "skin"); + Ref skinRef = mAsset.skins.Create(skinName); + skinRef->name = skinName; + + mat4* inverseBindMatricesData = new mat4[aim->mNumBones]; + + for (unsigned int idx_bone = 0; idx_bone < aim->mNumBones; ++idx_bone) { + const aiBone* aib = aim->mBones[idx_bone]; + + // aib->mName =====> skinRef->jointNames + // Find the node with id = mName. + Ref nodeRef = mAsset.nodes.Get(aib->mName.C_Str()); + nodeRef->jointName = "joint_" + std::to_string(idx_bone); + skinRef->jointNames.push_back("joint_" + std::to_string(idx_bone)); + // std::cout << "Node->id " << nodeRef->id << "\n"; + + // Identity Matrix =====> skinRef->bindShapeMatrix + // Temporary. Hard-coded identity matrix here + skinRef->bindShapeMatrix.isPresent = true; + IdentityMatrix4(skinRef->bindShapeMatrix.value); + + // aib->mOffsetMatrix =====> skinRef->inverseBindMatrices + CopyValue(aib->mOffsetMatrix, inverseBindMatricesData[idx_bone]); + + // aib->mNumWeights; + // aib->mWeights; + } // End: for-loop mNumMeshes + + // Create the Accessor for skinRef->inverseBindMatrices + Ref invBindMatrixAccessor = ExportData(mAsset, skinName, bufferRef, aim->mNumBones, inverseBindMatricesData, AttribType::MAT4, AttribType::MAT4, ComponentType_FLOAT); + if (invBindMatrixAccessor) skinRef->inverseBindMatrices = invBindMatrixAccessor; + + // Create the skinned mesh instance node. + Ref node = mAsset.nodes.Create(mAsset.FindUniqueID(skinName, "node")); + node->meshes.push_back(meshRef); + node->name = node->id; + node->skeletons.push_back(mAsset.nodes.Get(aim->mBones[0]->mName.C_Str())); + node->skin = skinRef; +} + void glTFExporter::ExportMeshes() { // Not for @@ -488,6 +531,9 @@ void glTFExporter::ExportMeshes() p.mode = PrimitiveMode_TRIANGLES; } + /*************** Skins ****************/ + ExportSkins(*mAsset, aim, m, b); + /****************** Compression ******************/ ///TODO: animation: weights, joints. if(comp_allow) @@ -640,7 +686,6 @@ inline void ExtractAnimationData(Asset& mAsset, std::string& animId, RefmNumPositionKeys > 0) { - std::cout<< "Parameters.TIME\n"; typedef float TimeType; std::vector timeData; timeData.resize(nodeChannel->mNumPositionKeys); @@ -689,13 +734,9 @@ inline void ExtractAnimationData(Asset& mAsset, std::string& animId, Ref bufferRef = mAsset->buffers.Get(unsigned (0)); - std::cout<<"GetBodyBuffer " << bufferRef << "\n"; std::cout<<"mNumAnimations " << mScene->mNumAnimations << "\n"; for (unsigned int i = 0; i < mScene->mNumAnimations; ++i) { @@ -715,7 +756,6 @@ void glTFExporter::ExportAnimations() std::string name = nameAnim + "_" + std::to_string(channelIndex); name = mAsset->FindUniqueID(name, "animation"); Ref animRef = mAsset->animations.Create(name); - std::cout<<"channelName " << name << "\n"; /******************* Parameters ********************/ ExtractAnimationData(*mAsset, name, animRef, bufferRef, nodeChannel); @@ -740,8 +780,6 @@ void glTFExporter::ExportAnimations() if (channelSize < 1) { continue; } - std::cout<<"channelType " << channelType << "\n"; - Animation::AnimChannel tmpAnimChannel; Animation::AnimSampler tmpAnimSampler; @@ -750,9 +788,7 @@ void glTFExporter::ExportAnimations() tmpAnimSampler.output = channelType; tmpAnimSampler.id = name + "_" + channelType; - std::cout<<"nodeChannel->mNodeName.C_Str() " << nodeChannel->mNodeName.C_Str() << "\n"; tmpAnimChannel.target.id = mAsset->nodes.Get(nodeChannel->mNodeName.C_Str()); - std::cout<<"tmpAnimChannel.target.id " << tmpAnimChannel.target.id << "\n"; tmpAnimSampler.input = "TIME"; tmpAnimSampler.interpolation = "LINEAR"; @@ -763,62 +799,64 @@ void glTFExporter::ExportAnimations() } - std::cout<<"mNumMeshChannels " << anim->mNumMeshChannels << "\n"; - for (unsigned int channelIndex = 0; channelIndex < anim->mNumMeshChannels; ++channelIndex) { - const aiMeshAnim* meshChannel = anim->mMeshChannels[channelIndex]; - } + // std::cout<<"mNumMeshChannels " << anim->mNumMeshChannels << "\n"; + // for (unsigned int channelIndex = 0; channelIndex < anim->mNumMeshChannels; ++channelIndex) { + // const aiMeshAnim* meshChannel = anim->mMeshChannels[channelIndex]; + // } } // End: for-loop mNumAnimations } +// void glTFExporter::ExportSkins() +// { +// Ref bufferRef = mAsset->buffers.Get(unsigned (0)); +// for (unsigned int idx_mesh = 0; idx_mesh < mScene->mNumMeshes; ++idx_mesh) { +// const aiMesh* aim = mScene->mMeshes[idx_mesh]; -void glTFExporter::ExportSkins() -{ - Ref bufferRef = mAsset->buffers.Get(unsigned (0)); - - for (unsigned int idx_mesh = 0; idx_mesh < mScene->mNumMeshes; ++idx_mesh) { - const aiMesh* aim = mScene->mMeshes[idx_mesh]; - - if(!aim->HasBones()) { continue; } // skip to next mesh if no bones exist. - - std::string skinName = aim->mName.C_Str(); - skinName = mAsset->FindUniqueID(skinName, "skin"); - Ref skinRef = mAsset->skins.Create(skinName); - skinRef->name = skinName; - - mat4* inverseBindMatricesData = new mat4[aim->mNumBones]; +// if(!aim->HasBones()) { continue; } // skip to next mesh if no bones exist. - for (unsigned int idx_bone = 0; idx_bone < aim->mNumBones; ++idx_bone) { - const aiBone* aib = aim->mBones[idx_bone]; +// std::string skinName = aim->mName.C_Str(); +// skinName = mAsset->FindUniqueID(skinName, "skin"); +// Ref skinRef = mAsset->skins.Create(skinName); +// skinRef->name = skinName; - // aib->mName =====> skinRef->jointNames - // Find the node with id = mName. - Ref nodeRef = mAsset->nodes.Get(aib->mName.C_Str()); - nodeRef->jointName = "joint_" + std::to_string(idx_bone); - skinRef->jointNames.push_back("joint_" + std::to_string(idx_bone)); - std::cout << "Node->id " << nodeRef->id << "\n"; +// mat4* inverseBindMatricesData = new mat4[aim->mNumBones]; - // Identity Matrix =====> skinRef->bindShapeMatrix - // Temporary. Hard-coded identity matrix here - skinRef->bindShapeMatrix.isPresent = true; - IdentityMatrix4(skinRef->bindShapeMatrix.value); +// for (unsigned int idx_bone = 0; idx_bone < aim->mNumBones; ++idx_bone) { +// const aiBone* aib = aim->mBones[idx_bone]; +// // aib->mName =====> skinRef->jointNames +// // Find the node with id = mName. +// Ref nodeRef = mAsset->nodes.Get(aib->mName.C_Str()); +// nodeRef->jointName = "joint_" + std::to_string(idx_bone); +// skinRef->jointNames.push_back("joint_" + std::to_string(idx_bone)); +// // std::cout << "Node->id " << nodeRef->id << "\n"; - // aib->mOffsetMatrix =====> skinRef->inverseBindMatrices - CopyValue(aib->mOffsetMatrix, inverseBindMatricesData[idx_bone]); +// // Identity Matrix =====> skinRef->bindShapeMatrix +// // Temporary. Hard-coded identity matrix here +// skinRef->bindShapeMatrix.isPresent = true; +// IdentityMatrix4(skinRef->bindShapeMatrix.value); - // aib->mNumWeights; - // aib->mWeights; +// // aib->mOffsetMatrix =====> skinRef->inverseBindMatrices +// CopyValue(aib->mOffsetMatrix, inverseBindMatricesData[idx_bone]); - } // End: for-loop mNumMeshes +// // aib->mNumWeights; +// // aib->mWeights; +// } // End: for-loop mNumMeshes - Ref invBindMatrixAccessor = ExportData(*mAsset, skinName, bufferRef, aim->mNumBones, inverseBindMatricesData, AttribType::MAT4, AttribType::MAT4, ComponentType_FLOAT); - if (invBindMatrixAccessor) skinRef->inverseBindMatrices = invBindMatrixAccessor; - - } // End: for-loop mNumMeshes -} +// // Create the Accessor for skinRef->inverseBindMatrices +// Ref invBindMatrixAccessor = ExportData(*mAsset, skinName, bufferRef, aim->mNumBones, inverseBindMatricesData, AttribType::MAT4, AttribType::MAT4, ComponentType_FLOAT); +// if (invBindMatrixAccessor) skinRef->inverseBindMatrices = invBindMatrixAccessor; +// // Create the skinned mesh instance node. +// Ref node = mAsset->nodes.Create(mAsset->FindUniqueID(skinName, "node")); +// node->meshes.push_back(mAsset->meshes.Get(aim->mName.C_Str())); +// node->name = node->id; +// node->skeletons.push_back(mAsset->nodes.Get(aim->mBones[0]->mName.C_Str())); +// node->skin = skinRef; +// } // End: for-loop mNumMeshes +// } diff --git a/code/glTFExporter.h b/code/glTFExporter.h index a661183..838711e 100644 --- a/code/glTFExporter.h +++ b/code/glTFExporter.h @@ -55,12 +55,17 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. struct aiScene; struct aiNode; struct aiMaterial; +// struct aiMesh; namespace glTF { class Asset; struct TexProperty; + + // class Ref; + + // struct Mesh; } namespace Assimp @@ -102,7 +107,7 @@ namespace Assimp unsigned int ExportNode(const aiNode* node); void ExportScene(); void ExportAnimations(); - void ExportSkins(); + // void ExportSkins(const aiMesh* aim, glTF::Ref& m); }; }