Add skeleton generation to aiScene

kimkulling/create_skeleton_data_issue_4015
Kim Kulling 2022-04-28 21:43:02 +02:00
parent 0afb594f40
commit 64a6968254
4 changed files with 41 additions and 3 deletions

View File

@ -1030,6 +1030,34 @@ aiMesh *FBXConverter::SetupEmptyMesh(const Geometry &mesh, aiNode *parent) {
return out_mesh;
}
static aiSkeleton *createAiSkeleton(SkeletonBoneContainer &sbc) {
if (sbc.MeshArray.empty() || sbc.SkeletonBoneToMeshLookup.empty()) {
return nullptr;
}
aiSkeleton *skeleton = new aiSkeleton;
for (auto *mesh : sbc.MeshArray) {
auto it = sbc.SkeletonBoneToMeshLookup.find(mesh);
if (it == sbc.SkeletonBoneToMeshLookup.end()) {
continue;
}
SkeletonBoneArray *ba = it->second;
if (ba == nullptr) {
continue;
}
skeleton->mNumBones = static_cast<unsigned int>(ba->size());
skeleton->mBones = new aiSkeletonBone*[skeleton->mNumBones];
size_t index = 0;
for (auto bone : (* ba)) {
skeleton->mBones[index] = bone;
++index;
}
}
return skeleton;
}
unsigned int FBXConverter::ConvertMeshSingleMaterial(const MeshGeometry &mesh, const Model &model,
const aiMatrix4x4 &absolute_transform, aiNode *parent,
aiNode *) {
@ -1155,6 +1183,10 @@ unsigned int FBXConverter::ConvertMeshSingleMaterial(const MeshGeometry &mesh, c
} else if (doc.Settings().readWeights && mesh.DeformerSkin() != nullptr && doc.Settings().useSkeleton) {
SkeletonBoneContainer sbc;
ConvertWeightsToSkeleton(out_mesh, mesh, absolute_transform, parent, NO_MATERIAL_SEPARATION, nullptr, sbc);
aiSkeleton *skeleton = createAiSkeleton(sbc);
if (skeleton != nullptr) {
mSkeletons.emplace_back(skeleton);
}
}
std::vector<aiAnimMesh *> animMeshes;
@ -3657,6 +3689,12 @@ void FBXConverter::TransferDataToScene() {
std::swap_ranges(textures.begin(), textures.end(), mSceneOut->mTextures);
}
if (!mSkeletons.empty()) {
mSceneOut->mSkeletons = new aiSkeleton *[mSkeletons.size()];
mSceneOut->mNumSkeletons = static_cast<unsigned int>(mSkeletons.size());
std::swap_ranges(mSkeletons.begin(), mSkeletons.end(), mSceneOut->mSkeletons);
}
}
void FBXConverter::ConvertOrphanedEmbeddedTextures() {

View File

@ -467,6 +467,7 @@ private:
double anim_fps;
std::vector<aiSkeleton *> mSkeletons;
aiScene* const mSceneOut;
const FBX::Document& doc;
bool mRemoveEmptyBones;

View File

@ -1018,7 +1018,7 @@ struct aiSkeleton {
/**
*
*/
C_STRUCT aiSkeletonBone *mBones;
C_STRUCT aiSkeletonBone **mBones;
#ifdef __cplusplus
/**

View File

@ -79,8 +79,7 @@ extern "C" {
* the imported scene does consist of only a single root node without children.
*/
// -------------------------------------------------------------------------------
struct ASSIMP_API aiNode
{
struct ASSIMP_API aiNode {
/** The name of the node.
*
* The name might be empty (length of zero) but all nodes which