moved ExportSkins function into ExportMeshes function
parent
83c9addbc9
commit
ae36ca0e44
|
@ -807,7 +807,7 @@ namespace glTF
|
||||||
Ref<Camera> camera;
|
Ref<Camera> camera;
|
||||||
Ref<Light> light;
|
Ref<Light> light;
|
||||||
|
|
||||||
std::vector< Ref<Node> > skeletons; //!< The ID of skeleton nodes.
|
std::vector< Ref<Node> > skeletons; //!< The ID of skeleton nodes. Each of which is the root of a node hierarchy.
|
||||||
Ref<Skin> skin; //!< The ID of the skin referenced by this node.
|
Ref<Skin> skin; //!< The ID of the skin referenced by this node.
|
||||||
std::string jointName; //!< Name used when this node is a joint in a skin.
|
std::string jointName; //!< Name used when this node is a joint in a skin.
|
||||||
|
|
||||||
|
|
|
@ -386,6 +386,12 @@ namespace glTF {
|
||||||
|
|
||||||
AddRefsVector(obj, "meshes", n.meshes, w.mAl);
|
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()) {
|
if (!n.jointName.empty()) {
|
||||||
obj.AddMember("jointName", n.jointName, w.mAl);
|
obj.AddMember("jointName", n.jointName, w.mAl);
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,8 +144,6 @@ glTFExporter::glTFExporter(const char* filename, IOSystem* pIOSystem, const aiSc
|
||||||
|
|
||||||
ExportAnimations();
|
ExportAnimations();
|
||||||
|
|
||||||
ExportSkins();
|
|
||||||
|
|
||||||
glTF::AssetWriter writer(*mAsset);
|
glTF::AssetWriter writer(*mAsset);
|
||||||
|
|
||||||
if (isBinary) {
|
if (isBinary) {
|
||||||
|
@ -367,6 +365,51 @@ void glTFExporter::ExportMaterials()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ExportSkins(Asset& mAsset, const aiMesh* aim, Ref<Mesh>& meshRef, Ref<Buffer>& 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<Skin> 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<Node> 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<Accessor> 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> 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()
|
void glTFExporter::ExportMeshes()
|
||||||
{
|
{
|
||||||
// Not for
|
// Not for
|
||||||
|
@ -488,6 +531,9 @@ void glTFExporter::ExportMeshes()
|
||||||
p.mode = PrimitiveMode_TRIANGLES;
|
p.mode = PrimitiveMode_TRIANGLES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*************** Skins ****************/
|
||||||
|
ExportSkins(*mAsset, aim, m, b);
|
||||||
|
|
||||||
/****************** Compression ******************/
|
/****************** Compression ******************/
|
||||||
///TODO: animation: weights, joints.
|
///TODO: animation: weights, joints.
|
||||||
if(comp_allow)
|
if(comp_allow)
|
||||||
|
@ -640,7 +686,6 @@ inline void ExtractAnimationData(Asset& mAsset, std::string& animId, Ref<Animati
|
||||||
// Extract TIME parameter data.
|
// Extract TIME parameter data.
|
||||||
// Check if the timeStamps are the same for mPositionKeys, mRotationKeys, and mScalingKeys.
|
// Check if the timeStamps are the same for mPositionKeys, mRotationKeys, and mScalingKeys.
|
||||||
if(nodeChannel->mNumPositionKeys > 0) {
|
if(nodeChannel->mNumPositionKeys > 0) {
|
||||||
std::cout<< "Parameters.TIME\n";
|
|
||||||
typedef float TimeType;
|
typedef float TimeType;
|
||||||
std::vector<TimeType> timeData;
|
std::vector<TimeType> timeData;
|
||||||
timeData.resize(nodeChannel->mNumPositionKeys);
|
timeData.resize(nodeChannel->mNumPositionKeys);
|
||||||
|
@ -689,13 +734,9 @@ inline void ExtractAnimationData(Asset& mAsset, std::string& animId, Ref<Animati
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void glTFExporter::ExportAnimations()
|
void glTFExporter::ExportAnimations()
|
||||||
{
|
{
|
||||||
Ref<Buffer> bufferRef = mAsset->buffers.Get(unsigned (0));
|
Ref<Buffer> bufferRef = mAsset->buffers.Get(unsigned (0));
|
||||||
std::cout<<"GetBodyBuffer " << bufferRef << "\n";
|
|
||||||
|
|
||||||
std::cout<<"mNumAnimations " << mScene->mNumAnimations << "\n";
|
std::cout<<"mNumAnimations " << mScene->mNumAnimations << "\n";
|
||||||
for (unsigned int i = 0; i < mScene->mNumAnimations; ++i) {
|
for (unsigned int i = 0; i < mScene->mNumAnimations; ++i) {
|
||||||
|
@ -715,7 +756,6 @@ void glTFExporter::ExportAnimations()
|
||||||
std::string name = nameAnim + "_" + std::to_string(channelIndex);
|
std::string name = nameAnim + "_" + std::to_string(channelIndex);
|
||||||
name = mAsset->FindUniqueID(name, "animation");
|
name = mAsset->FindUniqueID(name, "animation");
|
||||||
Ref<Animation> animRef = mAsset->animations.Create(name);
|
Ref<Animation> animRef = mAsset->animations.Create(name);
|
||||||
std::cout<<"channelName " << name << "\n";
|
|
||||||
|
|
||||||
/******************* Parameters ********************/
|
/******************* Parameters ********************/
|
||||||
ExtractAnimationData(*mAsset, name, animRef, bufferRef, nodeChannel);
|
ExtractAnimationData(*mAsset, name, animRef, bufferRef, nodeChannel);
|
||||||
|
@ -740,8 +780,6 @@ void glTFExporter::ExportAnimations()
|
||||||
|
|
||||||
if (channelSize < 1) { continue; }
|
if (channelSize < 1) { continue; }
|
||||||
|
|
||||||
std::cout<<"channelType " << channelType << "\n";
|
|
||||||
|
|
||||||
Animation::AnimChannel tmpAnimChannel;
|
Animation::AnimChannel tmpAnimChannel;
|
||||||
Animation::AnimSampler tmpAnimSampler;
|
Animation::AnimSampler tmpAnimSampler;
|
||||||
|
|
||||||
|
@ -750,9 +788,7 @@ void glTFExporter::ExportAnimations()
|
||||||
tmpAnimSampler.output = channelType;
|
tmpAnimSampler.output = channelType;
|
||||||
tmpAnimSampler.id = name + "_" + 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());
|
tmpAnimChannel.target.id = mAsset->nodes.Get(nodeChannel->mNodeName.C_Str());
|
||||||
std::cout<<"tmpAnimChannel.target.id " << tmpAnimChannel.target.id << "\n";
|
|
||||||
|
|
||||||
tmpAnimSampler.input = "TIME";
|
tmpAnimSampler.input = "TIME";
|
||||||
tmpAnimSampler.interpolation = "LINEAR";
|
tmpAnimSampler.interpolation = "LINEAR";
|
||||||
|
@ -763,62 +799,64 @@ void glTFExporter::ExportAnimations()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout<<"mNumMeshChannels " << anim->mNumMeshChannels << "\n";
|
// std::cout<<"mNumMeshChannels " << anim->mNumMeshChannels << "\n";
|
||||||
for (unsigned int channelIndex = 0; channelIndex < anim->mNumMeshChannels; ++channelIndex) {
|
// for (unsigned int channelIndex = 0; channelIndex < anim->mNumMeshChannels; ++channelIndex) {
|
||||||
const aiMeshAnim* meshChannel = anim->mMeshChannels[channelIndex];
|
// const aiMeshAnim* meshChannel = anim->mMeshChannels[channelIndex];
|
||||||
}
|
// }
|
||||||
|
|
||||||
} // End: for-loop mNumAnimations
|
} // End: for-loop mNumAnimations
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// void glTFExporter::ExportSkins()
|
||||||
|
// {
|
||||||
|
// Ref<Buffer> 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()
|
// if(!aim->HasBones()) { continue; } // skip to next mesh if no bones exist.
|
||||||
{
|
|
||||||
Ref<Buffer> bufferRef = mAsset->buffers.Get(unsigned (0));
|
|
||||||
|
|
||||||
for (unsigned int idx_mesh = 0; idx_mesh < mScene->mNumMeshes; ++idx_mesh) {
|
// std::string skinName = aim->mName.C_Str();
|
||||||
const aiMesh* aim = mScene->mMeshes[idx_mesh];
|
// skinName = mAsset->FindUniqueID(skinName, "skin");
|
||||||
|
// Ref<Skin> skinRef = mAsset->skins.Create(skinName);
|
||||||
|
// skinRef->name = skinName;
|
||||||
|
|
||||||
if(!aim->HasBones()) { continue; } // skip to next mesh if no bones exist.
|
// mat4* inverseBindMatricesData = new mat4[aim->mNumBones];
|
||||||
|
|
||||||
std::string skinName = aim->mName.C_Str();
|
// for (unsigned int idx_bone = 0; idx_bone < aim->mNumBones; ++idx_bone) {
|
||||||
skinName = mAsset->FindUniqueID(skinName, "skin");
|
// const aiBone* aib = aim->mBones[idx_bone];
|
||||||
Ref<Skin> skinRef = mAsset->skins.Create(skinName);
|
|
||||||
skinRef->name = skinName;
|
|
||||||
|
|
||||||
mat4* inverseBindMatricesData = new mat4[aim->mNumBones];
|
// // aib->mName =====> skinRef->jointNames
|
||||||
|
// // Find the node with id = mName.
|
||||||
|
// Ref<Node> 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";
|
||||||
|
|
||||||
for (unsigned int idx_bone = 0; idx_bone < aim->mNumBones; ++idx_bone) {
|
// // Identity Matrix =====> skinRef->bindShapeMatrix
|
||||||
const aiBone* aib = aim->mBones[idx_bone];
|
// // Temporary. Hard-coded identity matrix here
|
||||||
|
// skinRef->bindShapeMatrix.isPresent = true;
|
||||||
|
// IdentityMatrix4(skinRef->bindShapeMatrix.value);
|
||||||
|
|
||||||
// aib->mName =====> skinRef->jointNames
|
// // aib->mOffsetMatrix =====> skinRef->inverseBindMatrices
|
||||||
// Find the node with id = mName.
|
// CopyValue(aib->mOffsetMatrix, inverseBindMatricesData[idx_bone]);
|
||||||
Ref<Node> 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
|
// // aib->mNumWeights;
|
||||||
// Temporary. Hard-coded identity matrix here
|
// // aib->mWeights;
|
||||||
skinRef->bindShapeMatrix.isPresent = true;
|
// } // End: for-loop mNumMeshes
|
||||||
IdentityMatrix4(skinRef->bindShapeMatrix.value);
|
|
||||||
|
|
||||||
|
// // Create the Accessor for skinRef->inverseBindMatrices
|
||||||
|
// Ref<Accessor> invBindMatrixAccessor = ExportData(*mAsset, skinName, bufferRef, aim->mNumBones, inverseBindMatricesData, AttribType::MAT4, AttribType::MAT4, ComponentType_FLOAT);
|
||||||
|
// if (invBindMatrixAccessor) skinRef->inverseBindMatrices = invBindMatrixAccessor;
|
||||||
|
|
||||||
// aib->mOffsetMatrix =====> skinRef->inverseBindMatrices
|
// // Create the skinned mesh instance node.
|
||||||
CopyValue(aib->mOffsetMatrix, inverseBindMatricesData[idx_bone]);
|
// Ref<Node> node = mAsset->nodes.Create(mAsset->FindUniqueID(skinName, "node"));
|
||||||
|
// node->meshes.push_back(mAsset->meshes.Get(aim->mName.C_Str()));
|
||||||
// aib->mNumWeights;
|
// node->name = node->id;
|
||||||
// aib->mWeights;
|
// node->skeletons.push_back(mAsset->nodes.Get(aim->mBones[0]->mName.C_Str()));
|
||||||
|
// node->skin = skinRef;
|
||||||
} // End: for-loop mNumMeshes
|
// } // End: for-loop mNumMeshes
|
||||||
|
// }
|
||||||
Ref<Accessor> invBindMatrixAccessor = ExportData(*mAsset, skinName, bufferRef, aim->mNumBones, inverseBindMatricesData, AttribType::MAT4, AttribType::MAT4, ComponentType_FLOAT);
|
|
||||||
if (invBindMatrixAccessor) skinRef->inverseBindMatrices = invBindMatrixAccessor;
|
|
||||||
|
|
||||||
} // End: for-loop mNumMeshes
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -55,12 +55,17 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
struct aiScene;
|
struct aiScene;
|
||||||
struct aiNode;
|
struct aiNode;
|
||||||
struct aiMaterial;
|
struct aiMaterial;
|
||||||
|
// struct aiMesh;
|
||||||
|
|
||||||
namespace glTF
|
namespace glTF
|
||||||
{
|
{
|
||||||
class Asset;
|
class Asset;
|
||||||
|
|
||||||
struct TexProperty;
|
struct TexProperty;
|
||||||
|
|
||||||
|
// class Ref;
|
||||||
|
|
||||||
|
// struct Mesh;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Assimp
|
namespace Assimp
|
||||||
|
@ -102,7 +107,7 @@ namespace Assimp
|
||||||
unsigned int ExportNode(const aiNode* node);
|
unsigned int ExportNode(const aiNode* node);
|
||||||
void ExportScene();
|
void ExportScene();
|
||||||
void ExportAnimations();
|
void ExportAnimations();
|
||||||
void ExportSkins();
|
// void ExportSkins(const aiMesh* aim, glTF::Ref<glTF::Mesh>& m);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue