diff options
author | RevoluPowered <gordon@gordonite.tech> | 2019-11-05 17:54:34 +0000 |
---|---|---|
committer | RevoluPowered <gordon@gordonite.tech> | 2019-11-05 17:54:57 +0000 |
commit | 0bd877780fb7b344b5ed1d2fa7765078616f069b (patch) | |
tree | 46d359e6a6f1117015403ace17257915d088003f /thirdparty/assimp/code/FBX/FBXConverter.h | |
parent | 245c99175c242bdc60a212cc84986b1a9ad5aa08 (diff) |
FBX Importer Generation 3
Basic skin support
Various fixes
- Fixes bind mount id and mesh index
- Fixed duplicate nodes being created
- Prevented leak when instances being freed during re-import.
- Improved camera and light transform import
- skeleton handling and technical debt removal
- ASSIMP: bone nodes were unlinked from bones by this code
- bone_add working can distinguish between armatutes
- Updated transform to be the correct offset
- Added safety for state.root node errors
- Fixed memory leak with leaf bones
- Implemented children re-parenting for mesh template
- import_animation fixes to basic skeleton data
- Adds some more debug messages
- Fixed Godot import segfault
- Fix build failing on mono
- Clear resources we use which are no longer required after import
- Fixed bone duplication issue
- Working skeleton_bone_map which can lookup armatures properly now.
- Fixed stack being used up when mesh swapped & Fixed bone ID
Additional notes:
We use a mesh template which is a fake node to instance the initial
mesh nodes . This is to ensure the entire tree can be built.
We replace mesh node templates with the real mesh after the
skeleton is available, since this makes it ensure that the fully
built skeleton exists with all bones, all nodes, etc.
The bone stack is a stack which pops when it finds bones,
this overcomes duplicate bones with the same names.
FBX has lots of these because animation armature has bone names like bone001
and another armature will also have bone001
Fixed errors in node path assignment
Simple explanation:
- Every mesh uses a node from the stack
- Node stack was empties before completed
- Every time node not found, stack must be rebuilt to maintain correct armature order :)
Additional fixes:
- Fixes destructor in assimp
- Implements aiNode* mArmature in bone data
- Implements aiNode* mParent in bone data
- Fixes parent ID on bones.
Implemented skeleton assignment in generate_mesh_indicies
This is the only place we can safely do a lookup for the skeleton for the mesh.h
I used a pointer reference so we can pass this back out, since the skeleton assignment happens inside the function.
Added mesh re-parenting to the armature node this is a permanent feature and must be enforced, just like GLTF2 specification.
Fixed import_animation spawning tracks per skin
Diffstat (limited to 'thirdparty/assimp/code/FBX/FBXConverter.h')
-rw-r--r-- | thirdparty/assimp/code/FBX/FBXConverter.h | 80 |
1 files changed, 46 insertions, 34 deletions
diff --git a/thirdparty/assimp/code/FBX/FBXConverter.h b/thirdparty/assimp/code/FBX/FBXConverter.h index ab610058a4..619da92c17 100644 --- a/thirdparty/assimp/code/FBX/FBXConverter.h +++ b/thirdparty/assimp/code/FBX/FBXConverter.h @@ -76,16 +76,6 @@ namespace Assimp { namespace FBX { class Document; - -enum class FbxUnit { - cm = 0, - m, - km, - NumUnits, - - Undefined -}; - /** * Convert a FBX #Document to #aiScene * @param out Empty scene to be populated @@ -133,7 +123,7 @@ private: // ------------------------------------------------------------------------------------------------ // collect and assign child nodes - void ConvertNodes(uint64_t id, aiNode& parent, const aiMatrix4x4& parent_transform = aiMatrix4x4()); + void ConvertNodes(uint64_t id, aiNode *parent, aiNode *root_node); // ------------------------------------------------------------------------------------------------ void ConvertLights(const Model& model, const std::string &orig_name ); @@ -189,32 +179,35 @@ private: void SetupNodeMetadata(const Model& model, aiNode& nd); // ------------------------------------------------------------------------------------------------ - void ConvertModel(const Model& model, aiNode& nd, const aiMatrix4x4& node_global_transform); + void ConvertModel(const Model &model, aiNode *parent, aiNode *root_node, + const aiMatrix4x4 &absolute_transform); // ------------------------------------------------------------------------------------------------ // MeshGeometry -> aiMesh, return mesh index + 1 or 0 if the conversion failed - std::vector<unsigned int> ConvertMesh(const MeshGeometry& mesh, const Model& model, - const aiMatrix4x4& node_global_transform, aiNode& nd); + std::vector<unsigned int> + ConvertMesh(const MeshGeometry &mesh, const Model &model, aiNode *parent, aiNode *root_node, + const aiMatrix4x4 &absolute_transform); // ------------------------------------------------------------------------------------------------ std::vector<unsigned int> ConvertLine(const LineGeometry& line, const Model& model, - const aiMatrix4x4& node_global_transform, aiNode& nd); + aiNode *parent, aiNode *root_node); // ------------------------------------------------------------------------------------------------ - aiMesh* SetupEmptyMesh(const Geometry& mesh, aiNode& nd); + aiMesh* SetupEmptyMesh(const Geometry& mesh, aiNode *parent); // ------------------------------------------------------------------------------------------------ - unsigned int ConvertMeshSingleMaterial(const MeshGeometry& mesh, const Model& model, - const aiMatrix4x4& node_global_transform, aiNode& nd); + unsigned int ConvertMeshSingleMaterial(const MeshGeometry &mesh, const Model &model, + const aiMatrix4x4 &absolute_transform, aiNode *parent, + aiNode *root_node); // ------------------------------------------------------------------------------------------------ - std::vector<unsigned int> ConvertMeshMultiMaterial(const MeshGeometry& mesh, const Model& model, - const aiMatrix4x4& node_global_transform, aiNode& nd); + std::vector<unsigned int> + ConvertMeshMultiMaterial(const MeshGeometry &mesh, const Model &model, aiNode *parent, aiNode *root_node, + const aiMatrix4x4 &absolute_transform); // ------------------------------------------------------------------------------------------------ - unsigned int ConvertMeshMultiMaterial(const MeshGeometry& mesh, const Model& model, - MatIndexArray::value_type index, - const aiMatrix4x4& node_global_transform, aiNode& nd); + unsigned int ConvertMeshMultiMaterial(const MeshGeometry &mesh, const Model &model, MatIndexArray::value_type index, + aiNode *parent, aiNode *root_node, const aiMatrix4x4 &absolute_transform); // ------------------------------------------------------------------------------------------------ static const unsigned int NO_MATERIAL_SEPARATION = /* std::numeric_limits<unsigned int>::max() */ @@ -227,17 +220,17 @@ private: * - outputVertStartIndices is only used when a material index is specified, it gives for * each output vertex the DOM index it maps to. */ - void ConvertWeights(aiMesh* out, const Model& model, const MeshGeometry& geo, - const aiMatrix4x4& node_global_transform = aiMatrix4x4(), - unsigned int materialIndex = NO_MATERIAL_SEPARATION, - std::vector<unsigned int>* outputVertStartIndices = NULL); - + void ConvertWeights(aiMesh *out, const Model &model, const MeshGeometry &geo, const aiMatrix4x4 &absolute_transform, + aiNode *parent = NULL, aiNode *root_node = NULL, + unsigned int materialIndex = NO_MATERIAL_SEPARATION, + std::vector<unsigned int> *outputVertStartIndices = NULL); + // lookup + static const aiNode* GetNodeByName( const aiString& name, aiNode *current_node ); // ------------------------------------------------------------------------------------------------ - void ConvertCluster(std::vector<aiBone*>& bones, const Model& /*model*/, const Cluster& cl, - std::vector<size_t>& out_indices, - std::vector<size_t>& index_out_indices, - std::vector<size_t>& count_out_indices, - const aiMatrix4x4& node_global_transform); + void ConvertCluster(std::vector<aiBone *> &local_mesh_bones, const Cluster *cl, + std::vector<size_t> &out_indices, std::vector<size_t> &index_out_indices, + std::vector<size_t> &count_out_indices, const aiMatrix4x4 &absolute_transform, + aiNode *parent, aiNode *root_node); // ------------------------------------------------------------------------------------------------ void ConvertMaterialForMesh(aiMesh* out, const Model& model, const MeshGeometry& geo, @@ -462,11 +455,30 @@ private: using NodeNameCache = std::unordered_map<std::string, unsigned int>; NodeNameCache mNodeNames; + // Deformer name is not the same as a bone name - it does contain the bone name though :) + // Deformer names in FBX are always unique in an FBX file. + std::map<const std::string, aiBone *> bone_map; + double anim_fps; aiScene* const out; const FBX::Document& doc; - FbxUnit mCurrentUnit; + + static void BuildBoneList(aiNode *current_node, const aiNode *root_node, const aiScene *scene, + std::vector<aiBone*>& bones); + + void BuildBoneStack(aiNode *current_node, const aiNode *root_node, const aiScene *scene, + const std::vector<aiBone *> &bones, + std::map<aiBone *, aiNode *> &bone_stack, + std::vector<aiNode*> &node_stack ); + + static void BuildNodeList(aiNode *current_node, std::vector<aiNode *> &nodes); + + static aiNode *GetNodeFromStack(const aiString &node_name, std::vector<aiNode *> &nodes); + + static aiNode *GetArmatureRoot(aiNode *bone_node, std::vector<aiBone*> &bone_list); + + static bool IsBoneNode(const aiString &bone_name, std::vector<aiBone *> &bones); }; } |