Paste Code
Paste Blends
Paste Images
Index: release/scripts/startup/bl_ui/properties_data_bone.py
===================================================================
--- release/scripts/startup/bl_ui/properties_data_bone.py (revision 39268)
+++ release/scripts/startup/bl_ui/properties_data_bone.py (working copy)
@@ -356,6 +356,25 @@
col.label(text="Offset:")
col.prop(bone, "use_cyclic_offset")

+class BONE_PT_physics(BoneButtonsPanel, bpy.types.Panel):
+ bl_label = "Physics"
+
+ @classmethod
+ def poll(cls, context):
+ rd = context.scene.render
+ ob = context.object
+
+ return ob and ob.mode == 'POSE' and context.bone and rd.engine == 'BLENDER_GAME'
+
+ def draw_header(self, context):
+ bone = context.bone
+
+ self.layout.prop(bone, "use_physics", text="")
+
+ def draw(self, context):
+ layout = self.layout
+
+ bone = context.bone

class BONE_PT_custom_props(BoneButtonsPanel, PropertyPanel, bpy.types.Panel):
COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
Index: source/blender/makesdna/DNA_armature_types.h
===================================================================
--- source/blender/makesdna/DNA_armature_types.h (revision 39268)
+++ source/blender/makesdna/DNA_armature_types.h (working copy)
@@ -199,7 +199,8 @@
BONE_EDITMODE_LOCKED = (1<<19), /* bone transforms are locked in EditMode */
BONE_TRANSFORM_CHILD = (1<<20), /* Indicates that a parent is also being transformed */
BONE_UNSELECTABLE = (1<<21), /* bone cannot be selected */
- BONE_NO_LOCAL_LOCATION = (1<<22) /* bone location is in armature space */
+ BONE_NO_LOCAL_LOCATION = (1<<22), /* bone location is in armature space */
+ BONE_USE_PHYSICS = (1<<23) /* BGE bone physics */
} eBone_Flag;

#define MAXBONENAME 32
Index: source/blender/makesrna/intern/rna_armature.c
===================================================================
--- source/blender/makesrna/intern/rna_armature.c (revision 39268)
+++ source/blender/makesrna/intern/rna_armature.c (working copy)
@@ -553,6 +553,11 @@
RNA_def_property_range(prop, 0.0f, 1000.0f);
RNA_def_property_ui_text(prop, "B-Bone Display Z Width", "B-Bone Z size");
RNA_def_property_update(prop, 0, "rna_Armature_update_data");
+
+ /* BGE bone physics settings */
+ prop= RNA_def_property(srna, "use_physics", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "flag", BONE_USE_PHYSICS);
+ RNA_def_property_ui_text(prop, "Use Physics", "Enable physics for this bone");
}

// err... bones should not be directly edited (only editbones should be...)
Index: source/gameengine/Converter/BL_BlenderDataConversion.cpp
===================================================================
--- source/gameengine/Converter/BL_BlenderDataConversion.cpp (revision 39268)
+++ source/gameengine/Converter/BL_BlenderDataConversion.cpp (working copy)
@@ -69,6 +69,7 @@
#include "KX_Light.h"
#include "KX_Camera.h"
#include "KX_EmptyObject.h"
+#include "KX_BoneObject.h"
#include "KX_FontObject.h"
#include "MT_Point3.h"
#include "MT_Transform.h"
@@ -1638,10 +1639,125 @@
}
}

+static void setup_bone_physics(KX_BoneObject* bone, BL_ArmatureObject *armobj, KX_Scene* kxscene, KX_BlenderSceneConverter *converter)
+{
+ Bone *bbone = bone->GetBone();
+ PHY_ShapeProps shapeprops = {0};
+ PHY_MaterialProps smmaterial = {0};
+ KX_ObjectProperties objprop = {0};

+ objprop.m_in_active_layer = (armobj->GetBlenderObject()->lay & kxscene->GetBlenderScene()->lay) != 0;

+ objprop.m_boundclass = KX_BOUNDCAPSULE;
+ objprop.m_boundobject.c.m_radius = 0.5f;
+ objprop.m_boundobject.c.m_height = (bbone->length - objprop.m_boundobject.c.m_radius) * 0.5f;

+ Object* parent = armobj->GetBlenderObject();
+ while (parent && parent->parent)
+ parent = parent->parent;
+ objprop.m_dynamic_parent = converter->FindGameObject(parent);
+ KX_ConvertBulletObject(bone, NULL, NULL, kxscene, &shapeprops, &smmaterial, &objprop);
+}

+static void kxbones_from_blbones(BL_ArmatureObject *gameobj, KX_Scene *kxscene, Bone *bone, KX_BlenderSceneConverter *converter)
+{
+ KX_BoneObject *bobj = NULL;
+
+ if (bone->flag & BONE_USE_PHYSICS)
+ {
+ MT_Matrix4x4 mtbone_matrix, mtarm_matrix;
+ float bone_matrix[4][4] = {0};
+ bArmature* armobj = (bArmature*)gameobj->GetArmatureObject()->data;
+
+ bobj = new KX_BoneObject(bone, kxscene, KX_Scene::m_callbacks);
+ bobj->SetLayer(gameobj->GetBlenderObject()->lay);
+
+ // Setup position and orientation
+ gameobj->GetBoneMatrix(bone, mtbone_matrix);
+ //if (bone->parent)
+ //{
+ //gameobj->GetBoneMatrix(bone->parent, mtbonepar_matrix);
+ //mtbone_matrix = mtbone_matrix * mtbonepar_matrix;
+ //}
+ //mtbone_matrix = mtbone_matrix * gameobj->GetSGNode()->GetWorldTransform();
+ mtarm_matrix.setValue((float*)gameobj->GetArmatureObject()->obmat);
+ mtbone_matrix = mtbone_matrix * mtarm_matrix;
+
+ mtbone_matrix.getValue((float*)bone_matrix);
+ MT_Transform bone_trans((float*)bone_matrix);
+
+ bobj->GetSGNode()->SetLocalPosition(bone_trans.getOrigin() - MT_Vector3(0.0, gameobj->GetBoneLength(bone)*0.5, 0.0));
+ //bobj->GetSGNode()->SetModified();
+ bobj->GetSGNode()->SetLocalOrientation(bone_trans.getBasis());
+ //bobj->NodeSetLocalPosition(MT_Point3(bone_matrix[0][3], bone_matrix[1][3], bone_matrix[2][3]));
+ //bobj->NodeSetLocalOrientation(MT_Matrix3x3(bone_matrix[0][0], bone_matrix[0][1], bone_matrix[0][2],
+ // bone_matrix[1][0], bone_matrix[1][1], bone_matrix[1][2],
+ // bone_matrix[2][0], bone_matrix[2][1], bone_matrix[2][2]));
+ bobj->NodeUpdateGS(0);
+
+ kxscene->GetLogicManager()->RegisterGameObjectName(bobj->GetName(), bobj);
+
+ // Handle parenting
+ SG_Callbacks callback(NULL, NULL, NULL, KX_Scene::KX_ScenegraphUpdateFunc, KX_Scene::KX_ScenegraphRescheduleFunc);
+ SG_Node* parentinversenode = new SG_Node(NULL, kxscene, callback);
+
+ KX_NormalParentRelation* parent_rel = KX_NormalParentRelation::New();
+ parentinversenode->SetParentRelation(parent_rel);
+
+ //mtbone_matrix.invert();
+ //mtbone_matrix.getValue((float*)bone_matrix);
+ //MT_Transform parinvtrans((float*)bone_matrix);
+ MT_Transform parinvtrans((float*)gameobj->GetBlenderObject()->parentinv);
+ parentinversenode->SetLocalPosition(parinvtrans.getOrigin());
+
+ MT_Matrix3x3 ori(parinvtrans.getBasis());
+ MT_Vector3 x(ori.getColumn(0));
+ MT_Vector3 y(ori.getColumn(1));
+ MT_Vector3 z(ori.getColumn(2));
+ MT_Vector3 localscale(x.length(), y.length(), z.length());
+ if (!MT_fuzzyZero(localscale[0]))
+ x /= localscale[0];
+ if (!MT_fuzzyZero(localscale[1]))
+ y /= localscale[1];
+ if (!MT_fuzzyZero(localscale[2]))
+ z /= localscale[2];
+ ori.setColumn(0, x);
+ ori.setColumn(1, y);
+ ori.setColumn(2, z);
+ parentinversenode->SetLocalOrientation(ori);
+ parentinversenode->SetLocalScale(localscale);
+
+ parentinversenode->AddChild(bobj->GetSGNode());
+
+ bobj->GetSGNode()->SetParentRelation(KX_BoneParentRelation::New(bone));
+ gameobj->GetSGNode()->AddChild(bobj->GetSGNode());
+
+ // Setup physics
+ setup_bone_physics(bobj, gameobj, kxscene, converter);
+
+ if ((gameobj->GetBlenderObject()->lay & kxscene->GetBlenderScene()->lay) != 0)
+ kxscene->GetObjectList()->Add(bobj->AddRef());
+ else
+ kxscene->GetInactiveList()->Add(bobj->AddRef());
+ }
+
+ for (Bone* child=(Bone*)bone->childbase.first; child; child=(Bone*)child->next)
+ kxbones_from_blbones(gameobj, kxscene, child, converter);
+
+ if (bobj)
+ bobj->Release();
+}
+
+static void BL_ConvertBones(BL_ArmatureObject *gameobj, KX_Scene *kxscene, KX_BlenderSceneConverter *converter)
+{
+
+ bArmature* armobj = (bArmature*)gameobj->GetArmatureObject()->data;
+ for (Bone* bone=(Bone*)armobj->bonebase.first; bone; bone=(Bone*)bone->next)
+ {
+ kxbones_from_blbones(gameobj, kxscene, bone, converter);
+ }
+}
+
static KX_LightObject *gamelight_from_blamp(Object *ob, Lamp *la, unsigned int layerflag, KX_Scene *kxscene, RAS_IRenderTools *rendertools, KX_BlenderSceneConverter *converter) {
RAS_LightObject lightobj;
KX_LightObject *gamelight;
@@ -2546,12 +2662,16 @@
gameobj->GetDeformer()->UpdateBuckets();
}

- // Set up armature constraints
+ // Set up armature constraints and bone physics
for (i=0;i<sumolist->GetCount();++i)
{
KX_GameObject* gameobj = (KX_GameObject*) sumolist->GetValue(i);
if (gameobj->GetGameObjectType() == SCA_IObject::OBJ_ARMATURE)
- ((BL_ArmatureObject*)gameobj)->LoadConstraints(converter);
+ {
+ BL_ArmatureObject* arm_obj = (BL_ArmatureObject*)gameobj;
+ arm_obj->LoadConstraints(converter);
+ BL_ConvertBones(arm_obj, kxscene, converter);
+ }
}

bool processCompoundChildren = false;
Index: source/gameengine/Ketsji/CMakeLists.txt
===================================================================
--- source/gameengine/Ketsji/CMakeLists.txt (revision 39268)
+++ source/gameengine/Ketsji/CMakeLists.txt (working copy)
@@ -91,6 +91,7 @@
BL_Texture.cpp
KX_ArmatureSensor.cpp
KX_BlenderMaterial.cpp
+ KX_BoneObject.cpp
KX_BulletPhysicsController.cpp
KX_Camera.cpp
KX_CameraActuator.cpp
@@ -162,6 +163,7 @@
BL_Texture.h
KX_ArmatureSensor.h
KX_BlenderMaterial.h
+ KX_BoneObject.h
KX_BulletPhysicsController.h
KX_Camera.h
KX_CameraActuator.h
Index: source/gameengine/Ketsji/KX_BoneObject.cpp
===================================================================
--- source/gameengine/Ketsji/KX_BoneObject.cpp (revision 0)
+++ source/gameengine/Ketsji/KX_BoneObject.cpp (revision 0)
@@ -0,0 +1,48 @@
+/**
+ * $Id: KX_EmptyObject.cpp 35171 2011-02-25 13:35:59Z jesterking $
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Mitchell Stokes.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file gameengine/Ketsji/KX_BoneObject.cpp
+ * \ingroup ketsji
+ */
+
+#include "KX_BoneObject.h"
+
+#include "DNA_armature_types.h";
+
+KX_BoneObject::KX_BoneObject(Bone *bone, void* sgReplicationInfo,SG_Callbacks callbacks) :
+ KX_GameObject(sgReplicationInfo,callbacks),
+ m_bone(bone)
+{
+ SetName(bone->name);
+}
+
+KX_BoneObject::~KX_BoneObject()
+{
+
+}
+
+Bone *KX_BoneObject::GetBone()
+{
+ return m_bone;
+}
\ No newline at end of file

Property changes on: source\gameengine\Ketsji\KX_BoneObject.cpp
___________________________________________________________________
Added: svn:eol-style
+ native

Index: source/gameengine/Ketsji/KX_BoneObject.h
===================================================================
--- source/gameengine/Ketsji/KX_BoneObject.h (revision 0)
+++ source/gameengine/Ketsji/KX_BoneObject.h (revision 0)
@@ -0,0 +1,51 @@
+/**
+ * $Id: $
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Mitchell Stokes.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file KX_BoneObject.h
+ * \ingroup ketsji
+ */
+
+#ifndef __KX_BONEOBJECT
+#define __KX_BONEOBJECT
+#include "KX_GameObject.h"
+
+class KX_BoneObject : public KX_GameObject
+{
+private:
+ struct Bone *m_bone;
+public:
+ KX_BoneObject(struct Bone *bone, void* sgReplicationInfo,SG_Callbacks callbacks);
+ virtual ~KX_BoneObject();
+
+ struct Bone *GetBone();
+
+#ifdef WITH_CXX_GUARDEDALLOC
+public:
+ void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:KX_BoneObject"); }
+ void operator delete( void *mem ) { MEM_freeN(mem); }
+#endif
+};
+
+#endif //__KX_EMPTYOBJECT
+

Property changes on: source\gameengine\Ketsji\KX_BoneObject.h
___________________________________________________________________
Added: svn:eol-style
+ native

  1. Index: release/scripts/startup/bl_ui/properties_data_bone.py
  2. ===================================================================
  3. --- release/scripts/startup/bl_ui/properties_data_bone.py       (revision 39268)
  4. +++ release/scripts/startup/bl_ui/properties_data_bone.py       (working copy)
  5. @@ -356,6 +356,25 @@
  6.          col.label(text="Offset:")
  7.          col.prop(bone, "use_cyclic_offset")
  8.  
  9. +class BONE_PT_physics(BoneButtonsPanel, bpy.types.Panel):
  10. +    bl_label = "Physics"
  11. +    
  12. +    @classmethod
  13. +    def poll(cls, context):
  14. +        rd = context.scene.render
  15. +        ob = context.object
  16. +        
  17. +        return ob and ob.mode == 'POSE' and context.bone and rd.engine == 'BLENDER_GAME'
  18. +        
  19. +    def draw_header(self, context):
  20. +        bone = context.bone
  21. +        
  22. +        self.layout.prop(bone, "use_physics", text="")
  23. +        
  24. +    def draw(self, context):
  25. +        layout = self.layout
  26. +        
  27. +        bone = context.bone
  28.  
  29.  class BONE_PT_custom_props(BoneButtonsPanel, PropertyPanel, bpy.types.Panel):
  30.      COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
  31. Index: source/blender/makesdna/DNA_armature_types.h
  32. ===================================================================
  33. --- source/blender/makesdna/DNA_armature_types.h        (revision 39268)
  34. +++ source/blender/makesdna/DNA_armature_types.h        (working copy)
  35. @@ -199,7 +199,8 @@
  36.         BONE_EDITMODE_LOCKED            = (1<<19),      /* bone transforms are locked in EditMode */
  37.         BONE_TRANSFORM_CHILD            = (1<<20),      /* Indicates that a parent is also being transformed */
  38.         BONE_UNSELECTABLE                       = (1<<21),      /* bone cannot be selected */
  39. -       BONE_NO_LOCAL_LOCATION          = (1<<22)       /* bone location is in armature space */
  40. +       BONE_NO_LOCAL_LOCATION          = (1<<22),      /* bone location is in armature space */
  41. +       BONE_USE_PHYSICS                        = (1<<23)       /* BGE bone physics */
  42.  } eBone_Flag;
  43.  
  44.  #define MAXBONENAME 32
  45. Index: source/blender/makesrna/intern/rna_armature.c
  46. ===================================================================
  47. --- source/blender/makesrna/intern/rna_armature.c       (revision 39268)
  48. +++ source/blender/makesrna/intern/rna_armature.c       (working copy)
  49. @@ -553,6 +553,11 @@
  50.         RNA_def_property_range(prop, 0.0f, 1000.0f);
  51.         RNA_def_property_ui_text(prop, "B-Bone Display Z Width", "B-Bone Z size");
  52.         RNA_def_property_update(prop, 0, "rna_Armature_update_data");
  53. +
  54. +       /* BGE bone physics settings */
  55. +       prop= RNA_def_property(srna, "use_physics", PROP_BOOLEAN, PROP_NONE);
  56. +       RNA_def_property_boolean_sdna(prop, NULL, "flag", BONE_USE_PHYSICS);
  57. +       RNA_def_property_ui_text(prop, "Use Physics", "Enable physics for this bone");
  58.  }
  59.  
  60.  // err... bones should not be directly edited (only editbones should be...)
  61. Index: source/gameengine/Converter/BL_BlenderDataConversion.cpp
  62. ===================================================================
  63. --- source/gameengine/Converter/BL_BlenderDataConversion.cpp    (revision 39268)
  64. +++ source/gameengine/Converter/BL_BlenderDataConversion.cpp    (working copy)
  65. @@ -69,6 +69,7 @@
  66.  #include "KX_Light.h"
  67.  #include "KX_Camera.h"
  68.  #include "KX_EmptyObject.h"
  69. +#include "KX_BoneObject.h"
  70.  #include "KX_FontObject.h"
  71.  #include "MT_Point3.h"
  72.  #include "MT_Transform.h"
  73. @@ -1638,10 +1639,125 @@
  74.         }
  75.  }
  76.  
  77. +static void setup_bone_physics(KX_BoneObject* bone, BL_ArmatureObject *armobj, KX_Scene* kxscene, KX_BlenderSceneConverter *converter)
  78. +{
  79. +       Bone *bbone = bone->GetBone();
  80. +       PHY_ShapeProps shapeprops = {0};
  81. +       PHY_MaterialProps smmaterial = {0};
  82. +       KX_ObjectProperties objprop = {0};
  83.  
  84. +       objprop.m_in_active_layer = (armobj->GetBlenderObject()->lay & kxscene->GetBlenderScene()->lay) != 0;
  85.  
  86. +       objprop.m_boundclass = KX_BOUNDCAPSULE;
  87. +       objprop.m_boundobject.c.m_radius = 0.5f;
  88. +       objprop.m_boundobject.c.m_height = (bbone->length - objprop.m_boundobject.c.m_radius) * 0.5f;
  89.  
  90. +       Object* parent = armobj->GetBlenderObject();
  91. +       while (parent && parent->parent)
  92. +               parent = parent->parent;
  93. +       objprop.m_dynamic_parent = converter->FindGameObject(parent);
  94. +       KX_ConvertBulletObject(bone, NULL, NULL, kxscene, &shapeprops, &smmaterial, &objprop);
  95. +}
  96.  
  97. +static void kxbones_from_blbones(BL_ArmatureObject *gameobj, KX_Scene *kxscene, Bone *bone, KX_BlenderSceneConverter *converter)
  98. +{
  99. +               KX_BoneObject *bobj = NULL;
  100. +
  101. +               if (bone->flag & BONE_USE_PHYSICS)
  102. +               {
  103. +                       MT_Matrix4x4 mtbone_matrix, mtarm_matrix;
  104. +                       float bone_matrix[4][4] = {0};
  105. +                       bArmature* armobj = (bArmature*)gameobj->GetArmatureObject()->data;
  106. +
  107. +                       bobj = new KX_BoneObject(bone, kxscene, KX_Scene::m_callbacks);
  108. +                       bobj->SetLayer(gameobj->GetBlenderObject()->lay);
  109. +
  110. +                       // Setup position and orientation
  111. +                       gameobj->GetBoneMatrix(bone, mtbone_matrix);
  112. +                       //if (bone->parent)
  113. +                       //{
  114. +                       //gameobj->GetBoneMatrix(bone->parent, mtbonepar_matrix);
  115. +                       //mtbone_matrix = mtbone_matrix * mtbonepar_matrix;
  116. +                       //}
  117. +                       //mtbone_matrix = mtbone_matrix * gameobj->GetSGNode()->GetWorldTransform();
  118. +                       mtarm_matrix.setValue((float*)gameobj->GetArmatureObject()->obmat);
  119. +                       mtbone_matrix = mtbone_matrix * mtarm_matrix;
  120. +
  121. +                       mtbone_matrix.getValue((float*)bone_matrix);
  122. +                       MT_Transform bone_trans((float*)bone_matrix);
  123. +
  124. +                       bobj->GetSGNode()->SetLocalPosition(bone_trans.getOrigin() - MT_Vector3(0.0, gameobj->GetBoneLength(bone)*0.5, 0.0));
  125. +                       //bobj->GetSGNode()->SetModified();
  126. +                       bobj->GetSGNode()->SetLocalOrientation(bone_trans.getBasis());
  127. +                       //bobj->NodeSetLocalPosition(MT_Point3(bone_matrix[0][3], bone_matrix[1][3], bone_matrix[2][3]));
  128. +                       //bobj->NodeSetLocalOrientation(MT_Matrix3x3(bone_matrix[0][0], bone_matrix[0][1], bone_matrix[0][2],
  129. +                       //                                                      bone_matrix[1][0], bone_matrix[1][1], bone_matrix[1][2],
  130. +                       //                                                      bone_matrix[2][0], bone_matrix[2][1], bone_matrix[2][2]));
  131. +                       bobj->NodeUpdateGS(0);
  132. +
  133. +                       kxscene->GetLogicManager()->RegisterGameObjectName(bobj->GetName(), bobj);
  134. +
  135. +                       // Handle parenting
  136. +                       SG_Callbacks callback(NULL, NULL, NULL, KX_Scene::KX_ScenegraphUpdateFunc, KX_Scene::KX_ScenegraphRescheduleFunc);
  137. +                       SG_Node* parentinversenode = new SG_Node(NULL, kxscene, callback);
  138. +
  139. +                       KX_NormalParentRelation* parent_rel = KX_NormalParentRelation::New();
  140. +                       parentinversenode->SetParentRelation(parent_rel);
  141. +
  142. +                       //mtbone_matrix.invert();
  143. +                       //mtbone_matrix.getValue((float*)bone_matrix);
  144. +                       //MT_Transform parinvtrans((float*)bone_matrix);
  145. +                       MT_Transform parinvtrans((float*)gameobj->GetBlenderObject()->parentinv);
  146. +                       parentinversenode->SetLocalPosition(parinvtrans.getOrigin());
  147. +
  148. +                       MT_Matrix3x3 ori(parinvtrans.getBasis());
  149. +                       MT_Vector3 x(ori.getColumn(0));
  150. +                       MT_Vector3 y(ori.getColumn(1));
  151. +                       MT_Vector3 z(ori.getColumn(2));
  152. +                       MT_Vector3 localscale(x.length(), y.length(), z.length());
  153. +                       if (!MT_fuzzyZero(localscale[0]))
  154. +                               x /= localscale[0];
  155. +                       if (!MT_fuzzyZero(localscale[1]))
  156. +                               y /= localscale[1];
  157. +                       if (!MT_fuzzyZero(localscale[2]))
  158. +                               z /= localscale[2];
  159. +                       ori.setColumn(0, x);                                                           
  160. +                       ori.setColumn(1, y);                                                           
  161. +                       ori.setColumn(2, z);                                                           
  162. +                       parentinversenode->SetLocalOrientation(ori);
  163. +                       parentinversenode->SetLocalScale(localscale);
  164. +
  165. +                       parentinversenode->AddChild(bobj->GetSGNode());
  166. +
  167. +                       bobj->GetSGNode()->SetParentRelation(KX_BoneParentRelation::New(bone));
  168. +                       gameobj->GetSGNode()->AddChild(bobj->GetSGNode());
  169. +
  170. +                       // Setup physics
  171. +                       setup_bone_physics(bobj, gameobj, kxscene, converter);
  172. +
  173. +                       if ((gameobj->GetBlenderObject()->lay & kxscene->GetBlenderScene()->lay) != 0)
  174. +                               kxscene->GetObjectList()->Add(bobj->AddRef());
  175. +                       else
  176. +                               kxscene->GetInactiveList()->Add(bobj->AddRef());
  177. +               }
  178. +
  179. +               for (Bone* child=(Bone*)bone->childbase.first; child; child=(Bone*)child->next)
  180. +                       kxbones_from_blbones(gameobj, kxscene, child, converter);
  181. +
  182. +               if (bobj)
  183. +                       bobj->Release();
  184. +}
  185. +
  186. +static void BL_ConvertBones(BL_ArmatureObject *gameobj, KX_Scene *kxscene, KX_BlenderSceneConverter *converter)
  187. +{
  188. +       
  189. +       bArmature* armobj = (bArmature*)gameobj->GetArmatureObject()->data;
  190. +       for (Bone* bone=(Bone*)armobj->bonebase.first; bone; bone=(Bone*)bone->next)
  191. +       {
  192. +               kxbones_from_blbones(gameobj, kxscene, bone, converter);
  193. +       }
  194. +}
  195. +
  196.  static KX_LightObject *gamelight_from_blamp(Object *ob, Lamp *la, unsigned int layerflag, KX_Scene *kxscene, RAS_IRenderTools *rendertools, KX_BlenderSceneConverter *converter) {
  197.         RAS_LightObject lightobj;
  198.         KX_LightObject *gamelight;
  199. @@ -2546,12 +2662,16 @@
  200.                         gameobj->GetDeformer()->UpdateBuckets();
  201.         }
  202.  
  203. -       // Set up armature constraints
  204. +       // Set up armature constraints and bone physics
  205.         for (i=0;i<sumolist->GetCount();++i)
  206.         {
  207.                 KX_GameObject* gameobj = (KX_GameObject*) sumolist->GetValue(i);
  208.                 if (gameobj->GetGameObjectType() == SCA_IObject::OBJ_ARMATURE)
  209. -                       ((BL_ArmatureObject*)gameobj)->LoadConstraints(converter);
  210. +               {
  211. +                       BL_ArmatureObject* arm_obj = (BL_ArmatureObject*)gameobj;
  212. +                       arm_obj->LoadConstraints(converter);
  213. +                       BL_ConvertBones(arm_obj, kxscene, converter);
  214. +               }
  215.         }
  216.  
  217.         bool processCompoundChildren = false;
  218. Index: source/gameengine/Ketsji/CMakeLists.txt
  219. ===================================================================
  220. --- source/gameengine/Ketsji/CMakeLists.txt     (revision 39268)
  221. +++ source/gameengine/Ketsji/CMakeLists.txt     (working copy)
  222. @@ -91,6 +91,7 @@
  223.         BL_Texture.cpp
  224.         KX_ArmatureSensor.cpp
  225.         KX_BlenderMaterial.cpp
  226. +       KX_BoneObject.cpp
  227.         KX_BulletPhysicsController.cpp
  228.         KX_Camera.cpp
  229.         KX_CameraActuator.cpp
  230. @@ -162,6 +163,7 @@
  231.         BL_Texture.h
  232.         KX_ArmatureSensor.h
  233.         KX_BlenderMaterial.h
  234. +       KX_BoneObject.h
  235.         KX_BulletPhysicsController.h
  236.         KX_Camera.h
  237.         KX_CameraActuator.h
  238. Index: source/gameengine/Ketsji/KX_BoneObject.cpp
  239. ===================================================================
  240. --- source/gameengine/Ketsji/KX_BoneObject.cpp  (revision 0)
  241. +++ source/gameengine/Ketsji/KX_BoneObject.cpp  (revision 0)
  242. @@ -0,0 +1,48 @@
  243. +/**
  244. + * $Id: KX_EmptyObject.cpp 35171 2011-02-25 13:35:59Z jesterking $
  245. + *
  246. + * ***** BEGIN GPL LICENSE BLOCK *****
  247. + *
  248. + * This program is free software; you can redistribute it and/or
  249. + * modify it under the terms of the GNU General Public License
  250. + * as published by the Free Software Foundation; either version 2
  251. + * of the License, or (at your option) any later version.
  252. + *
  253. + * This program is distributed in the hope that it will be useful,
  254. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  255. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  256. + * GNU General Public License for more details.
  257. + *
  258. + * You should have received a copy of the GNU General Public License
  259. + * along with this program; if not, write to the Free Software Foundation,
  260. + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  261. + *
  262. + * Contributor(s): Mitchell Stokes.
  263. + *
  264. + * ***** END GPL LICENSE BLOCK *****
  265. + */
  266. +
  267. +/** \file gameengine/Ketsji/KX_BoneObject.cpp
  268. + *  \ingroup ketsji
  269. + */
  270. +
  271. +#include "KX_BoneObject.h"
  272. +
  273. +#include "DNA_armature_types.h";
  274. +
  275. +KX_BoneObject::KX_BoneObject(Bone *bone, void* sgReplicationInfo,SG_Callbacks callbacks) :
  276. +       KX_GameObject(sgReplicationInfo,callbacks),
  277. +       m_bone(bone)
  278. +{
  279. +       SetName(bone->name);
  280. +}
  281. +
  282. +KX_BoneObject::~KX_BoneObject()
  283. +{
  284. +
  285. +}
  286. +
  287. +Bone *KX_BoneObject::GetBone()
  288. +{
  289. +       return m_bone;
  290. +}
  291. \ No newline at end of file
  292.  
  293. Property changes on: source\gameengine\Ketsji\KX_BoneObject.cpp
  294. ___________________________________________________________________
  295. Added: svn:eol-style
  296.    + native
  297.  
  298. Index: source/gameengine/Ketsji/KX_BoneObject.h
  299. ===================================================================
  300. --- source/gameengine/Ketsji/KX_BoneObject.h    (revision 0)
  301. +++ source/gameengine/Ketsji/KX_BoneObject.h    (revision 0)
  302. @@ -0,0 +1,51 @@
  303. +/**
  304. + * $Id: $
  305. + *
  306. + * ***** BEGIN GPL LICENSE BLOCK *****
  307. + *
  308. + * This program is free software; you can redistribute it and/or
  309. + * modify it under the terms of the GNU General Public License
  310. + * as published by the Free Software Foundation; either version 2
  311. + * of the License, or (at your option) any later version.
  312. + *
  313. + * This program is distributed in the hope that it will be useful,
  314. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  315. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  316. + * GNU General Public License for more details.
  317. + *
  318. + * You should have received a copy of the GNU General Public License
  319. + * along with this program; if not, write to the Free Software Foundation,
  320. + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  321. + *
  322. + * Contributor(s): Mitchell Stokes.
  323. + *
  324. + * ***** END GPL LICENSE BLOCK *****
  325. + */
  326. +
  327. +/** \file KX_BoneObject.h
  328. + *  \ingroup ketsji
  329. + */
  330. +
  331. +#ifndef __KX_BONEOBJECT
  332. +#define  __KX_BONEOBJECT
  333. +#include "KX_GameObject.h"
  334. +
  335. +class KX_BoneObject : public KX_GameObject
  336. +{
  337. +private:
  338. +       struct Bone *m_bone;
  339. +public:
  340. +       KX_BoneObject(struct Bone *bone, void* sgReplicationInfo,SG_Callbacks callbacks);
  341. +       virtual ~KX_BoneObject();
  342. +
  343. +       struct Bone *GetBone();
  344. +
  345. +#ifdef WITH_CXX_GUARDEDALLOC
  346. +public:
  347. +       void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:KX_BoneObject"); }
  348. +       void operator delete( void *mem ) { MEM_freeN(mem); }
  349. +#endif
  350. +};
  351. +
  352. +#endif //__KX_EMPTYOBJECT
  353. +
  354.  
  355. Property changes on: source\gameengine\Ketsji\KX_BoneObject.h
  356. ___________________________________________________________________
  357. Added: svn:eol-style
  358.    + native
  359.  
  360.  
go to heaven