[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [20315] trunk/blender/source: BGE: user control to compound shape and setParent.
Benoit Bolsee
benoit.bolsee at online.be
Thu May 21 15:32:15 CEST 2009
Revision: 20315
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20315
Author: ben2610
Date: 2009-05-21 15:32:15 +0200 (Thu, 21 May 2009)
Log Message:
-----------
BGE: user control to compound shape and setParent.
Compound shape control
======================
1) GUI control
It is now possible to control which child shape is added to
a parent compound shape in the Physics buttons. The "Compound"
shape button becomes "Add to parent" on child objects and
determines whether the child shape is to be added to the top
parent compound shape when the game is stated.
Notes: * "Compound" is only available to top parent objects
(objects without parent).
* Nesting of compound shape is not possible: a child
object with "Add to parent" button set will be added
to the top parent compound shape, regardless of its
position in the parent-child hierarchy and even if its
immediate parent doesn't have the "Add to parent" button set.
2) runtime control
It is now possible to control the compound shape at runtime:
The SetParent actuator has a new "Compound" button that indicates
whether the object shape should be added to the compound shape
of the parent object, provided the parent has a compound shape
of course. If not, the object retain it's individual state
while parented.
Similarly, the KX_GameObject.setParent() python function has
a new compound parameter.
Notes: * When an object is dynamically added to a compound
shape, it looses temporarily all its physics capability
to the benefit of the parent: it cannot register collisions
and the characteristics of its shape are lost (ghost, sensor,
dynamic, etc.).
* Nested compound shape is not supported: if the object
being parented is already a compound shape, it is not
added to the compound parent (as if the Compound option
was not set in the actuator or the setParent function).
* To ensure compatibility with old blend files, the Blender
subversion is changed to 2.48.5 and the old blend files
are automatically converted to match the old behavior:
all children of a Compound object will have the "Add to
parent" button set automatically.
Child ghost control
===================
It is now possible to control if an object should becomes ghost
or solid when parented. This is only applicable if the object
is not added to the parent compound shape (see above).
A new "Ghost" button is available on the SetParent actuator to
that effect. Similarly the KX_GameObject.setParent() python function
has a new compound parameter.
Notes: * This option is not applicable to sensor objects: they stay
ghost all the time.
* Make sure the child object does not enter in collision with
the parent shape when the Ghost option if off and the parent is
dynamic: the collision creates a reaction force but the parent
cannot escape the child, so the force builds up and produces
eratic movements.
* The collision capability of an ordinary object (dynamic or static)
is limited when it is parented: it becomes automatically static
and can only detect dynamic and sensor objects.
* A sensor object retain its full collision capability when parented:
it can detect static and dynamic object.
Python control
==============
KX_GameObject.setParent(parent,compound,ghost):
Sets this object's parent.
Control the shape status with the optional compound and ghost parameters:
compound=1: the object shape should be added to the parent compound shape (default)
compound=0: the object should keep its individual shape.
In that case you can control if it should be ghost or not:
ghost=1 if the object should be made ghost while parented (default)
ghost=0 if the object should be solid while parented
Note: if the object type is sensor, it stays ghost regardless of ghost parameter
parent: KX_GameObject reference or string (object name w/o OB prefix)
Modified Paths:
--------------
trunk/blender/source/blender/blenkernel/BKE_blender.h
trunk/blender/source/blender/blenloader/intern/readfile.c
trunk/blender/source/blender/makesdna/DNA_actuator_types.h
trunk/blender/source/blender/src/buttons_logic.c
trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp
trunk/blender/source/gameengine/Converter/KX_ConvertActuators.cpp
trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp
trunk/blender/source/gameengine/Ketsji/KX_GameObject.h
trunk/blender/source/gameengine/Ketsji/KX_ParentActuator.cpp
trunk/blender/source/gameengine/Ketsji/KX_ParentActuator.h
trunk/blender/source/gameengine/PyDoc/GameTypes.py
Modified: trunk/blender/source/blender/blenkernel/BKE_blender.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_blender.h 2009-05-21 11:10:34 UTC (rev 20314)
+++ trunk/blender/source/blender/blenkernel/BKE_blender.h 2009-05-21 13:32:15 UTC (rev 20315)
@@ -41,7 +41,7 @@
struct MemFile;
#define BLENDER_VERSION 248
-#define BLENDER_SUBVERSION 4
+#define BLENDER_SUBVERSION 5
#define BLENDER_MINVERSION 245
#define BLENDER_MINSUBVERSION 15
Modified: trunk/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readfile.c 2009-05-21 11:10:34 UTC (rev 20314)
+++ trunk/blender/source/blender/blenloader/intern/readfile.c 2009-05-21 13:32:15 UTC (rev 20315)
@@ -8106,6 +8106,22 @@
}
}
+ if (main->versionfile < 248 || (main->versionfile == 248 && main->subversionfile < 5)) {
+ Object *ob;
+ for(ob = main->object.first; ob; ob= ob->id.next) {
+ if(ob->parent) {
+ /* check if top parent has compound shape set and if yes, set this object
+ to compound shaper as well (was the behaviour before, now it's optional) */
+ Object *parent= newlibadr(fd, lib, ob->parent);
+ while (parent->parent != NULL) {
+ parent = newlibadr(fd, lib, parent->parent);
+ }
+ if (parent->gameflag & OB_CHILD)
+ ob->gameflag |= OB_CHILD;
+ }
+ }
+ }
+
if (main->versionfile < 249) {
Scene *sce;
for (sce= main->scene.first; sce; sce= sce->id.next)
Modified: trunk/blender/source/blender/makesdna/DNA_actuator_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_actuator_types.h 2009-05-21 11:10:34 UTC (rev 20314)
+++ trunk/blender/source/blender/makesdna/DNA_actuator_types.h 2009-05-21 13:32:15 UTC (rev 20315)
@@ -215,7 +215,8 @@
}bTwoDFilterActuator;
typedef struct bParentActuator {
- char pad[4];
+ char pad[2];
+ short flag;
int type;
struct Object *ob;
} bParentActuator;
@@ -483,6 +484,11 @@
/* parentactuator->type */
#define ACT_PARENT_SET 0
#define ACT_PARENT_REMOVE 1
+
+/* parentactuator->flag */
+#define ACT_PARENT_COMPOUND 1
+#define ACT_PARENT_GHOST 2
+
#endif
Modified: trunk/blender/source/blender/src/buttons_logic.c
===================================================================
--- trunk/blender/source/blender/src/buttons_logic.c 2009-05-21 11:10:34 UTC (rev 20314)
+++ trunk/blender/source/blender/src/buttons_logic.c 2009-05-21 13:32:15 UTC (rev 20315)
@@ -2747,11 +2747,22 @@
if(parAct->type==ACT_PARENT_SET) {
- ysize= 48;
+ ysize= 68;
glRects(xco, yco-ysize, xco+width, yco);
uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
-
uiDefIDPoinBut(block, test_obpoin_but, ID_OB, 1, "OB:", xco+40, yco-44, (width-80), 19, &(parAct->ob), "Set this object as parent");
+ uiBlockBeginAlign(block);
+ uiDefButBitI(block, TOGN, ACT_PARENT_COMPOUND, B_REDR,
+ "Compound",
+ xco + 40, yco - 64, (width - 80)/2, 19, &parAct->flag,
+ 0.0, 0.0, 0, 0,
+ "Add this object shape to the parent shape (only if the parent shape is already compound)");
+ uiDefButBitI(block, TOGN, ACT_PARENT_GHOST, B_REDR,
+ "Ghost",
+ xco + 40 + ((width - 80)/2), yco - 64, (width - 80)/2, 19, &parAct->flag,
+ 0.0, 0.0, 0, 0,
+ "Make this object ghost while parented (only if not compound)");
+ uiBlockEndAlign(block);
}
else if(parAct->type==ACT_PARENT_REMOVE) {
@@ -3480,9 +3491,14 @@
}
if (ob->body_type!=OB_BODY_TYPE_SOFT)
{
- uiDefButBitI(block, TOG, OB_CHILD, B_REDR, "Compound", 240,105,110,19,
- &ob->gameflag, 0, 0, 0, 0,
- "Add Children");
+ if (ob->parent)
+ uiDefButBitI(block, TOG, OB_CHILD, B_REDR, "Add to parent", 240,105,110,19,
+ &ob->gameflag, 0, 0, 0, 0,
+ "Add this shape to the parent compound shape");
+ else
+ uiDefButBitI(block, TOG, OB_CHILD, B_REDR, "Compound", 240,105,110,19,
+ &ob->gameflag, 0, 0, 0, 0,
+ "Create a compound shape with the children's shape that are tagged for addition");
}
}
uiBlockEndAlign(block);
Modified: trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp
===================================================================
--- trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp 2009-05-21 11:10:34 UTC (rev 20314)
+++ trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp 2009-05-21 13:32:15 UTC (rev 20315)
@@ -1377,10 +1377,11 @@
}
bool isCompoundChild = false;
+ bool hasCompoundChildren = !parent && (blenderobject->gameflag & OB_CHILD);
- if (parent && (parent->gameflag & OB_DYNAMIC)) {
+ if (parent/* && (parent->gameflag & OB_DYNAMIC)*/) {
- if ((parent->gameflag & OB_CHILD) != 0)
+ if ((parent->gameflag & OB_CHILD) != 0 && (blenderobject->gameflag & OB_CHILD))
{
isCompoundChild = true;
}
@@ -1406,7 +1407,7 @@
objprop.m_lockZRotaxis = (blenderobject->gameflag2 & OB_LOCK_RIGID_BODY_Z_ROT_AXIS) !=0;
objprop.m_isCompoundChild = isCompoundChild;
- objprop.m_hasCompoundChildren = (blenderobject->gameflag & OB_CHILD) != 0;
+ objprop.m_hasCompoundChildren = hasCompoundChildren;
objprop.m_margin = blenderobject->margin;
// ACTOR is now a separate feature
objprop.m_isactor = (blenderobject->gameflag & OB_ACTOR)!=0;
Modified: trunk/blender/source/gameengine/Converter/KX_ConvertActuators.cpp
===================================================================
--- trunk/blender/source/gameengine/Converter/KX_ConvertActuators.cpp 2009-05-21 11:10:34 UTC (rev 20314)
+++ trunk/blender/source/gameengine/Converter/KX_ConvertActuators.cpp 2009-05-21 13:32:15 UTC (rev 20315)
@@ -1123,6 +1123,8 @@
{
bParentActuator *parAct = (bParentActuator *) bact->data;
int mode = KX_ParentActuator::KX_PARENT_NODEF;
+ bool addToCompound = true;
+ bool ghost = true;
KX_GameObject *tmpgob = NULL;
switch(parAct->type)
@@ -1130,6 +1132,8 @@
case ACT_PARENT_SET:
mode = KX_ParentActuator::KX_PARENT_SET;
tmpgob = converter->FindGameObject(parAct->ob);
+ addToCompound = !(parAct->flag & ACT_PARENT_COMPOUND);
+ ghost = !(parAct->flag & ACT_PARENT_GHOST);
break;
case ACT_PARENT_REMOVE:
mode = KX_ParentActuator::KX_PARENT_REMOVE;
@@ -1140,6 +1144,8 @@
KX_ParentActuator *tmpparact
= new KX_ParentActuator(gameobj,
mode,
+ addToCompound,
+ ghost,
tmpgob);
baseact = tmpparact;
break;
Modified: trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp 2009-05-21 11:10:34 UTC (rev 20314)
+++ trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp 2009-05-21 13:32:15 UTC (rev 20315)
@@ -949,39 +949,27 @@
assert(colShape->isCompound());
btCompoundShape* compoundShape = (btCompoundShape*)colShape;
- // compute the local transform from parent, this may include a parent inverse node
+ // compute the local transform from parent, this may include several node in the chain
SG_Node* gameNode = gameobj->GetSGNode();
- SG_Node* parentInverseNode = gameNode->GetSGParent();
- if (parentInverseNode && parentInverseNode->GetSGClientObject() != NULL)
- // this is not a parent inverse node, cancel it
- parentInverseNode = NULL;
- // now combine the parent inverse node and the game node
- MT_Point3 childPos = gameNode->GetLocalPosition();
- MT_Matrix3x3 childRot = gameNode->GetLocalOrientation();
- MT_Vector3 childScale = gameNode->GetLocalScale();
- if (parentInverseNode)
- {
- const MT_Point3& parentInversePos = parentInverseNode->GetLocalPosition();
- const MT_Matrix3x3& parentInverseRot = parentInverseNode->GetLocalOrientation();
- const MT_Vector3& parentInverseScale = parentInverseNode->GetLocalScale();
- childRot = parentInverseRot * childRot;
- childScale = parentInverseScale * childScale;
- childPos = parentInversePos+parentInverseScale*(parentInverseRot*childPos);
- }
+ SG_Node* parentNode = objprop->m_dynamic_parent->GetSGNode();
+ // relative transform
+ MT_Vector3 parentScale = parentNode->GetWorldScaling();
+ parentScale[0] = MT_Scalar(1.0)/parentScale[0];
+ parentScale[1] = MT_Scalar(1.0)/parentScale[1];
+ parentScale[2] = MT_Scalar(1.0)/parentScale[2];
+ MT_Vector3 relativeScale = gameNode->GetWorldScaling() * parentScale;
+ MT_Matrix3x3 parentInvRot = parentNode->GetWorldOrientation().transposed();
+ MT_Vector3 relativePos = parentInvRot*((gameNode->GetWorldPosition()-parentNode->GetWorldPosition())*parentScale);
+ MT_Matrix3x3 relativeRot = parentInvRot*gameNode->GetWorldOrientation();
- shapeInfo->m_childScale.setValue(childScale.x(),childScale.y(),childScale.z());
+ shapeInfo->m_childScale.setValue(relativeScale[0],relativeScale[1],relativeScale[2]);
bm->setLocalScaling(shapeInfo->m_childScale);
-
- shapeInfo->m_childTrans.setOrigin(btVector3(childPos.x(),childPos.y(),childPos.z()));
- float rotval[12];
- childRot.getValue(rotval);
- btMatrix3x3 newRot;
- newRot.setValue(rotval[0],rotval[1],rotval[2],rotval[4],rotval[5],rotval[6],rotval[8],rotval[9],rotval[10]);
- newRot = newRot.transpose();
+ shapeInfo->m_childTrans.getOrigin().setValue(relativePos[0],relativePos[1],relativePos[2]);
+ float rot[12];
+ relativeRot.getValue(rot);
+ shapeInfo->m_childTrans.getBasis().setFromOpenGLSubMatrix(rot);
- shapeInfo->m_childTrans.setBasis(newRot);
parentShapeInfo->AddShape(shapeInfo);
-
compoundShape->addChildShape(shapeInfo->m_childTrans,bm);
//do some recalc?
//recalc inertia for rigidbody
Modified: trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp 2009-05-21 11:10:34 UTC (rev 20314)
+++ trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp 2009-05-21 13:32:15 UTC (rev 20315)
@@ -224,7 +224,7 @@
}
-void KX_GameObject::SetParent(KX_Scene *scene, KX_GameObject* obj)
+void KX_GameObject::SetParent(KX_Scene *scene, KX_GameObject* obj, bool addToCompound, bool ghost)
{
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list