From 6f2e9700015e79e64cb3bc602385f6bfb428b2f9 Mon Sep 17 00:00:00 2001 From: turanszkij Date: Mon, 27 Jun 2016 11:39:37 +0200 Subject: [PATCH] fixed bone parenting --- WickedEngine/wiLoader.cpp | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/WickedEngine/wiLoader.cpp b/WickedEngine/wiLoader.cpp index 25bad5125..519cc4ff5 100644 --- a/WickedEngine/wiLoader.cpp +++ b/WickedEngine/wiLoader.cpp @@ -2314,24 +2314,6 @@ void Model::FinishLoading() } } } - // Match parentBone (not armaturedeform!) - if (!x->boneParent.empty() && x->mesh != nullptr) - { - Armature* armature = x->mesh->armature; - if (armature != nullptr) - { - for (Bone* b : armature->boneCollection) - { - if (!b->name.compare(x->boneParent)) - { - XMFLOAT4X4 saved_parent_rest_inv = x->parent_inv_rest; - x->attachTo(b); - x->parent_inv_rest = saved_parent_rest_inv; - break; - } - } - } - } } for (Light* x : lights) { @@ -2353,16 +2335,32 @@ void Model::FinishLoading() { if (x != y && !x->parentName.empty() && !x->parentName.compare(y->name)) { + Transform* parent = y; + if (!x->boneParent.empty()) + { + Armature* armature = dynamic_cast(y); + if (armature != nullptr) + { + for (Bone* bone : armature->boneCollection) + { + if (!bone->name.compare(x->boneParent)) + { + parent = bone; + break; + } + } + } + } // Match parent XMFLOAT4X4 saved_parent_rest_inv = x->parent_inv_rest; - x->attachTo(y); + x->attachTo(parent); x->parent_inv_rest = saved_parent_rest_inv; break; } } } - // If it has still not parent, then attach to this model! + // If it has still no parent, then attach to this model! if (x->parent == nullptr) { x->attachTo(this);