added skins and jointNames

pull/1024/head
Angelo Scandaliato 2016-10-05 17:30:02 -07:00
parent cfa0ea3189
commit 79852de5ae
4 changed files with 66 additions and 20 deletions

View File

@ -128,6 +128,7 @@ namespace glTF
struct BufferView; // here due to cross-reference
struct Texture;
struct Light;
struct Skin;
// Vec/matrix types, as raw float arrays
@ -806,6 +807,10 @@ namespace glTF
Ref<Camera> camera;
Ref<Light> light;
std::vector< Ref<Node> > skeletons; //!< The ID of skeleton nodes.
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.
Node() {}
void Read(Value& obj, Asset& r);
};
@ -845,6 +850,11 @@ namespace glTF
struct Skin : public Object
{
Nullable<mat4> bindShapeMatrix; //!< Floating-point 4x4 transformation matrix stored in column-major order.
Ref<Accessor> inverseBindMatrices; //!< The ID of the accessor containing the floating-point 4x4 inverse-bind matrices.
std::vector<std::string/*Ref<Node>*/> jointNames; //!< Joint names of the joints (nodes with a jointName property) in this skin.
std::string name; //!< The user-defined name of this object.
Skin() {}
void Read(Value& obj, Asset& r);
};
@ -1099,7 +1109,7 @@ namespace glTF
LazyDict<Sampler> samplers;
LazyDict<Scene> scenes;
//LazyDict<Shader> shaders;
//LazyDict<Skin> skins;
LazyDict<Skin> skins;
//LazyDict<Technique> techniques;
LazyDict<Texture> textures;
@ -1124,7 +1134,7 @@ namespace glTF
, samplers (*this, "samplers")
, scenes (*this, "scenes")
//, shaders (*this, "shaders")
//, skins (*this, "skins")
, skins (*this, "skins")
//, techniques (*this, "techniques")
, textures (*this, "textures")
, lights (*this, "lights", "KHR_materials_common")

View File

@ -377,6 +377,10 @@ namespace glTF {
AddRefsVector(obj, "children", n.children, w.mAl);
AddRefsVector(obj, "meshes", n.meshes, w.mAl);
if (!n.jointName.empty()) {
obj.AddMember("jointName", n.jointName, w.mAl);
}
}
inline void Write(Value& obj, Program& b, AssetWriter& w)
@ -412,7 +416,15 @@ namespace glTF {
inline void Write(Value& obj, Skin& b, AssetWriter& w)
{
/****************** jointNames *******************/
Value vJointNames;
vJointNames.SetArray();
vJointNames.Reserve(unsigned(b.jointNames.size()), w.mAl);
for (size_t i = 0; i < unsigned(b.jointNames.size()); ++i) {
vJointNames.PushBack(StringRef(b.jointNames[i]), w.mAl);
}
obj.AddMember("jointNames", vJointNames, w.mAl);
}
inline void Write(Value& obj, Technique& b, AssetWriter& w)

View File

@ -126,8 +126,6 @@ glTFExporter::glTFExporter(const char* filename, IOSystem* pIOSystem, const aiSc
ExportMetadata();
//for (unsigned int i = 0; i < pScene->mNumAnimations; ++i) {}
//for (unsigned int i = 0; i < pScene->mNumCameras; ++i) {}
//for (unsigned int i = 0; i < pScene->mNumLights; ++i) {}
@ -148,6 +146,8 @@ glTFExporter::glTFExporter(const char* filename, IOSystem* pIOSystem, const aiSc
ExportAnimations();
ExportSkins();
glTF::AssetWriter writer(*mAsset);
if (isBinary) {
@ -701,8 +701,7 @@ inline void ExtractAnimationData(Asset& mAsset, std::string& animId, Ref<Animati
std::vector<TimeType> timeData;
timeData.resize(nodeChannel->mNumPositionKeys);
for (size_t i = 0; i < nodeChannel->mNumPositionKeys; ++i) {
// timeData[i] = uint16_t(nodeChannel->mPositionKeys[i].mTime);
timeData[i] = nodeChannel->mPositionKeys[i].mTime;
timeData[i] = nodeChannel->mPositionKeys[i].mTime; // Check if we have to cast type here. e.g. uint16_t()
}
Ref<Accessor> timeAccessor = ExportAnimationData(mAsset, animId, buffer, nodeChannel->mNumPositionKeys, &timeData[0], AttribType::SCALAR, AttribType::SCALAR, ComponentType_FLOAT);
@ -773,7 +772,6 @@ void glTFExporter::ExportAnimations()
// // Setup to output buffer data
// //--------------------------
// aiString aiName;
std::cout<<"mNumAnimations " << mScene->mNumAnimations << "\n";
for (unsigned int i = 0; i < mScene->mNumAnimations; ++i) {
const aiAnimation* anim = mScene->mAnimations[i];
@ -793,25 +791,15 @@ void glTFExporter::ExportAnimations()
name = mAsset->FindUniqueID(name, "animation");
Ref<Animation> animRef = mAsset->animations.Create(name);
// 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.
/******************* 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);
// FAKE DATA FOR NOW!!!!!
// These are accessors to bufferviews to buffer data.
// Ref<Accessor> acc = mAsset->accessors.Get(unsigned (0));
// animRef->Parameters.TIME = acc;
// animRef->Parameters.rotation = acc;
// animRef->Parameters.scale = acc;
// animRef->Parameters.translation = acc;
for (unsigned int j = 0; j < 3; ++j) {
std::string channelType;
switch (j) {
@ -848,6 +836,41 @@ void glTFExporter::ExportAnimations()
void glTFExporter::ExportSkins()
{
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.
std::string skinName = aim->mName.C_Str();
skinName = mAsset->FindUniqueID(skinName, "skin");
Ref<Skin> skinRef = mAsset->skins.Create(skinName);
skinRef->name = skinName;
for (unsigned int idx_bone = 0; idx_bone < aim->mNumBones; ++idx_bone) {
const aiBone* aib = aim->mBones[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";
// skinRef->bindShapeMatrix;
// skinRef->inverseBindMatrices;
// aib->mNumWeights;
// aib->mOffsetMatrix;
// aib->mWeights;
} // End: for-loop mNumMeshes
} // End: for-loop mNumMeshes
}
#endif // ASSIMP_BUILD_NO_GLTF_EXPORTER

View File

@ -102,6 +102,7 @@ namespace Assimp
unsigned int ExportNode(const aiNode* node);
void ExportScene();
void ExportAnimations();
void ExportSkins();
};
}