check if bones exist before creating skin

pull/1034/head
Angelo Scandaliato 2016-10-15 17:21:55 -07:00
parent 9c4bb1c9bc
commit fcf2d6357e
1 changed files with 39 additions and 27 deletions

View File

@ -517,17 +517,23 @@ void glTFExporter::ExportMeshes()
} }
//---------------------------------------- //----------------------------------------
// For the skin // Initialize variables for the skin
std::string skinName = mAsset->FindUniqueID("skin", "skin"); bool createSkin = false;
Ref<Skin> skinRef = mAsset->skins.Create(skinName); for (unsigned int idx_mesh = 0; idx_mesh < mScene->mNumMeshes; ++idx_mesh) {
skinRef->name = skinName; const aiMesh* aim = mScene->mMeshes[idx_mesh];
// std::vector<glTF::mat4> inverseBindMatricesData; if(aim->HasBones()) {
std::vector<aiMatrix4x4> inverseBindMatricesData; createSkin = true;
break;
}
}
// Identity Matrix =====> skinRef->bindShapeMatrix Ref<Skin> skinRef;
// Temporary. Hard-coded identity matrix here std::string skinName = mAsset->FindUniqueID("skin", "skin");
skinRef->bindShapeMatrix.isPresent = true; std::vector<aiMatrix4x4> inverseBindMatricesData;
IdentityMatrix4(skinRef->bindShapeMatrix.value); if(createSkin) {
skinRef = mAsset->skins.Create(skinName);
skinRef->name = skinName;
}
//---------------------------------------- //----------------------------------------
for (unsigned int idx_mesh = 0; idx_mesh < mScene->mNumMeshes; ++idx_mesh) { for (unsigned int idx_mesh = 0; idx_mesh < mScene->mNumMeshes; ++idx_mesh) {
@ -725,24 +731,30 @@ void glTFExporter::ExportMeshes()
//---------------------------------------- //----------------------------------------
// Finish the skin // Finish the skin
// Create the Accessor for skinRef->inverseBindMatrices // Create the Accessor for skinRef->inverseBindMatrices
mat4* invBindMatrixData = new mat4[inverseBindMatricesData.size()]; if (createSkin) {
for (int idx_joint = 0; idx_joint < inverseBindMatricesData.size(); ++idx_joint) { mat4* invBindMatrixData = new mat4[inverseBindMatricesData.size()];
CopyValue(inverseBindMatricesData[idx_joint], invBindMatrixData[idx_joint]); for (int idx_joint = 0; idx_joint < inverseBindMatricesData.size(); ++idx_joint) {
CopyValue(inverseBindMatricesData[idx_joint], invBindMatrixData[idx_joint]);
}
Ref<Accessor> invBindMatrixAccessor = ExportData(*mAsset, skinName, b, inverseBindMatricesData.size(), invBindMatrixData, AttribType::MAT4, AttribType::MAT4, ComponentType_FLOAT);
if (invBindMatrixAccessor) skinRef->inverseBindMatrices = invBindMatrixAccessor;
// Identity Matrix =====> skinRef->bindShapeMatrix
// Temporary. Hard-coded identity matrix here
skinRef->bindShapeMatrix.isPresent = true;
IdentityMatrix4(skinRef->bindShapeMatrix.value);
// Find node that contains this mesh and add "skeletons" and "skin" attributes to that node.
Ref<Node> rootNode = mAsset->nodes.Get(unsigned(0));
Ref<Node> meshNode;
std::string meshID = mAsset->meshes.Get(unsigned(0))->id;
FindMeshNode(rootNode, meshNode, meshID);
Ref<Node> rootJoint = FindSkeletonRootJoint(skinRef);
meshNode->skeletons.push_back(rootJoint);
meshNode->skin = skinRef;
} }
Ref<Accessor> invBindMatrixAccessor = ExportData(*mAsset, skinName, b, inverseBindMatricesData.size(), invBindMatrixData, AttribType::MAT4, AttribType::MAT4, ComponentType_FLOAT);
if (invBindMatrixAccessor) skinRef->inverseBindMatrices = invBindMatrixAccessor;
// Find node that contains this mesh and add "skeletons" and "skin" attributes to that node.
Ref<Node> rootNode = mAsset->nodes.Get(unsigned(0));
Ref<Node> meshNode;
std::string meshID = mAsset->meshes.Get(unsigned(0))->id;
FindMeshNode(rootNode, meshNode, meshID);
Ref<Node> rootJoint = FindSkeletonRootJoint(skinRef);
meshNode->skeletons.push_back(rootJoint);
meshNode->skin = skinRef;
//----------------------------------------
} }
/* /*