[Bf-blender-cvs] [1831c93] master: Game Engine: Option to record static objects animation

James Yonan noreply at git.blender.org
Mon Dec 9 12:28:49 CET 2013


Commit: 1831c930a5a2144e7941407e2a283cd168897626
Author: James Yonan
Date:   Mon Dec 9 22:26:52 2013 +1100
http://developer.blender.org/rB1831c930a5a2144e7941407e2a283cd168897626

Game Engine: Option to record static objects animation

===================================================================

M	doc/python_api/rst/bge_types/bge.types.KX_GameObject.rst
M	release/scripts/startup/bl_ui/properties_game.py
M	source/blender/makesdna/DNA_object_types.h
M	source/blender/makesrna/intern/rna_object.c
M	source/gameengine/Converter/BL_BlenderDataConversion.cpp
M	source/gameengine/Converter/KX_BlenderSceneConverter.cpp
M	source/gameengine/Ketsji/KX_ConvertPhysicsObject.h
M	source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
M	source/gameengine/Ketsji/KX_GameObject.cpp
M	source/gameengine/Ketsji/KX_GameObject.h

===================================================================

diff --git a/doc/python_api/rst/bge_types/bge.types.KX_GameObject.rst b/doc/python_api/rst/bge_types/bge.types.KX_GameObject.rst
index 5d69963..af4852d 100644
--- a/doc/python_api/rst/bge_types/bge.types.KX_GameObject.rst
+++ b/doc/python_api/rst/bge_types/bge.types.KX_GameObject.rst
@@ -151,11 +151,17 @@ base class --- :class:`SCA_IObject`
       visibility flag.
 
       :type: boolean
-      
+
       .. note::
-      
+
          Game logic will still run for invisible objects.
 
+   .. attribute:: record_animation
+
+      Record animation for this object.
+
+      :type: boolean
+
    .. attribute:: color
 
       The object color of the object. [r, g, b, a]
diff --git a/release/scripts/startup/bl_ui/properties_game.py b/release/scripts/startup/bl_ui/properties_game.py
index 3470c95..fdbe02e 100644
--- a/release/scripts/startup/bl_ui/properties_game.py
+++ b/release/scripts/startup/bl_ui/properties_game.py
@@ -156,6 +156,7 @@ class PHYSICS_PT_game_physics(PhysicsButtonsPanel, Panel):
             col = layout.column()
             col.prop(game, "use_actor")
             col.prop(game, "use_ghost")
+            col.prop(game, "use_record_animation")
             col.prop(ob, "hide_render", text="Invisible")
 
             layout.separator()
diff --git a/source/blender/makesdna/DNA_object_types.h b/source/blender/makesdna/DNA_object_types.h
index 2ff697f..7034162 100644
--- a/source/blender/makesdna/DNA_object_types.h
+++ b/source/blender/makesdna/DNA_object_types.h
@@ -542,6 +542,8 @@ enum {
 	OB_NAVMESH               = 1 << 20,
 	OB_HASOBSTACLE           = 1 << 21,
 	OB_CHARACTER             = 1 << 22,
+
+	OB_RECORD_ANIMATION      = 1 << 23,
 };
 
 /* ob->gameflag2 */
diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c
index 184e067..9c1d0c4 100644
--- a/source/blender/makesrna/intern/rna_object.c
+++ b/source/blender/makesrna/intern/rna_object.c
@@ -1646,6 +1646,10 @@ static void rna_def_object_game_settings(BlenderRNA *brna)
 	RNA_def_property_ui_text(prop, "Physics Type", "Select the type of physical representation");
 	RNA_def_property_update(prop, NC_LOGIC, NULL);
 
+	prop = RNA_def_property(srna, "use_record_animation", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "gameflag", OB_RECORD_ANIMATION);
+	RNA_def_property_ui_text(prop, "Record Animation", "Record animation objects without physics");
+
 	prop = RNA_def_property(srna, "use_actor", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "gameflag", OB_ACTOR);
 	RNA_def_property_ui_text(prop, "Actor", "Object is detected by the Near and Radar sensor");
diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp
index 1b27fde..eeaffd9 100644
--- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp
+++ b/source/gameengine/Converter/BL_BlenderDataConversion.cpp
@@ -1513,6 +1513,7 @@ static void BL_CreatePhysicsObjectNew(KX_GameObject* gameobj,
 	objprop.m_softbody = (blenderobject->gameflag & OB_SOFT_BODY) != 0;
 	objprop.m_angular_rigidbody = (blenderobject->gameflag & OB_RIGID_BODY) != 0;
 	objprop.m_character = (blenderobject->gameflag & OB_CHARACTER) != 0;
+	objprop.m_record_animation = (blenderobject->gameflag & OB_RECORD_ANIMATION) != 0;
 	
 	///contact processing threshold is only for rigid bodies and static geometry, not 'dynamic'
 	if (objprop.m_angular_rigidbody || !objprop.m_dyna )
diff --git a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp
index e682f33..4ed8e3e 100644
--- a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp
+++ b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp
@@ -706,8 +706,7 @@ void	KX_BlenderSceneConverter::ResetPhysicsObjectsAnimationIpo(bool clearIpo)
 		for (g=0;g<numObjects;g++)
 		{
 			KX_GameObject* gameObj = (KX_GameObject*)parentList->GetValue(g);
-			if (gameObj->IsDynamic())
-			{
+			if (gameObj->IsRecordAnimation()) {
 				
 				Object* blenderObject = gameObj->GetBlenderObject();
 				if (blenderObject)
@@ -769,7 +768,7 @@ void	KX_BlenderSceneConverter::resetNoneDynamicObjectToIpo()
 			CListValue* parentList = scene->GetRootParentList();
 			for (int ix=0;ix<parentList->GetCount();ix++) {
 				KX_GameObject* gameobj = (KX_GameObject*)parentList->GetValue(ix);
-				if (!gameobj->IsDynamic()) {
+				if (!gameobj->IsRecordAnimation()) {
 					Object* blenderobject = gameobj->GetBlenderObject();
 					if (!blenderobject)
 						continue;
@@ -821,8 +820,7 @@ void	KX_BlenderSceneConverter::WritePhysicsObjectToAnimationIpo(int frameNumber)
 		{
 			KX_GameObject* gameObj = (KX_GameObject*)parentList->GetValue(g);
 			Object* blenderObject = gameObj->GetBlenderObject();
-			if (blenderObject && blenderObject->parent==NULL && gameObj->IsDynamic())
-			{
+			if (blenderObject && blenderObject->parent==NULL && gameObj->IsRecordAnimation()) {
 
 				if (blenderObject->adt==NULL)
 					BKE_id_add_animdata(&blenderObject->id);
@@ -939,9 +937,7 @@ void	KX_BlenderSceneConverter::TestHandlesPhysicsObjectToAnimationIpo()
 		for (g=0;g<numObjects;g++)
 		{
 			KX_GameObject* gameObj = (KX_GameObject*)parentList->GetValue(g);
-			if (gameObj->IsDynamic())
-			{
-				
+			if (gameObj->IsRecordAnimation()) {
 #if 0
 				Object* blenderObject = gameObj->GetBlenderObject();
 				if (blenderObject && blenderObject->ipo)
diff --git a/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h b/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h
index 903966b..1ed3a99 100644
--- a/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h
+++ b/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h
@@ -71,6 +71,7 @@ struct KX_ObjectProperties
 	bool	m_ghost;
 	class KX_GameObject*	m_dynamic_parent;
 	bool	m_isactor;
+	bool	m_record_animation;
 	bool	m_sensor;
 	bool	m_character;
 	bool	m_concave;
diff --git a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
index bde50588f..16513a9 100644
--- a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
+++ b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
@@ -435,6 +435,11 @@ void	KX_ConvertBulletObject(	class	KX_GameObject* gameobj,
 		shapeInfo->Release();
 
 	gameobj->SetPhysicsController(physicscontroller,isbulletdyna);
+
+	// record animation for dynamic objects
+	if (isbulletdyna)
+		gameobj->SetRecordAnimation(true);
+
 	// don't add automatically sensor object, they are added when a collision sensor is registered
 	if (!isbulletsensor && objprop->m_in_active_layer)
 	{
@@ -493,6 +498,11 @@ void	KX_ConvertBulletObject(	class	KX_GameObject* gameobj,
 	gameobj->getClientInfo()->m_type = 
 		(isbulletsensor) ? ((isActor) ? KX_ClientObjectInfo::OBACTORSENSOR : KX_ClientObjectInfo::OBSENSOR) :
 		(isActor) ? KX_ClientObjectInfo::ACTOR : KX_ClientObjectInfo::STATIC;
+
+	// should we record animation for this object?
+	if (objprop->m_record_animation)
+		gameobj->SetRecordAnimation(true);
+
 	// store materialname in auxinfo, needed for touchsensors
 	if (meshobj)
 	{
diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp
index 96f76ff..d3b5a98 100644
--- a/source/gameengine/Ketsji/KX_GameObject.cpp
+++ b/source/gameengine/Ketsji/KX_GameObject.cpp
@@ -112,6 +112,7 @@ KX_GameObject::KX_GameObject(
       m_pInstanceObjects(NULL),
       m_pDupliGroupObject(NULL),
       m_actionManager(NULL),
+      m_bRecordAnimation(false),
       m_isDeformable(false)
 
 #ifdef WITH_PYTHON
@@ -1791,6 +1792,7 @@ PyAttributeDef KX_GameObject::Attributes[] = {
 	KX_PYATTRIBUTE_RW_FUNCTION("linVelocityMin",		KX_GameObject, pyattr_get_lin_vel_min, pyattr_set_lin_vel_min),
 	KX_PYATTRIBUTE_RW_FUNCTION("linVelocityMax",		KX_GameObject, pyattr_get_lin_vel_max, pyattr_set_lin_vel_max),
 	KX_PYATTRIBUTE_RW_FUNCTION("visible",	KX_GameObject, pyattr_get_visible,	pyattr_set_visible),
+	KX_PYATTRIBUTE_RW_FUNCTION("record_animation",	KX_GameObject, pyattr_get_record_animation,	pyattr_set_record_animation),
 	KX_PYATTRIBUTE_BOOL_RW    ("occlusion", KX_GameObject, m_bOccluder),
 	KX_PYATTRIBUTE_RW_FUNCTION("position",	KX_GameObject, pyattr_get_worldPosition,	pyattr_set_localPosition),
 	KX_PYATTRIBUTE_RO_FUNCTION("localInertia",	KX_GameObject, pyattr_get_localInertia),
@@ -2258,6 +2260,28 @@ int KX_GameObject::pyattr_set_visible(void *self_v, const KX_PYATTRIBUTE_DEF *at
 	return PY_SET_ATTR_SUCCESS;
 }
 
+PyObject *KX_GameObject::pyattr_get_record_animation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
+{
+	KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
+	return PyBool_FromLong(self->IsRecordAnimation());
+}
+
+int KX_GameObject::pyattr_set_record_animation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
+{
+	KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
+	int param = PyObject_IsTrue(value);
+	if (param == -1) {
+		PyErr_SetString(PyExc_AttributeError, "gameOb.record_animation = bool: KX_GameObject, expected boolean");
+		return PY_SET_ATTR_FAIL;
+	}
+
+	self->SetRecordAnimation(param);
+
+	return PY_SET_ATTR_SUCCESS;
+}
+
+
+
 PyObject *KX_GameObject::pyattr_get_worldPosition(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
 {
 #ifdef USE_MATHUTILS
diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h
index 55e2b31..12aac68 100644
--- a/source/gameengine/Ketsji/KX_GameObject.h
+++ b/source/gameengine/Ketsji/KX_GameObject.h
@@ -126,6 +126,7 @@ protected:
 
 	BL_ActionManager* GetActionManager();
 	
+	bool								m_bRecordAnimation;
 public:
 	bool								m_isDeformable;
 
@@ -600,6 +601,20 @@ public:
 	}
 
 	/**
+	 * Should we record animation for this object?
+	 */
+
+	void SetRecordAnimation(bool recordAnimation)
+	{
+		m_bRecordAnimation = recordAnimation;
+	}
+
+	bool IsRecordAnimation() const
+	{
+		return m_bRecordAnimation;
+	}
+
+	/**
 	 * Check if this object has a vertex parent relationship
 	 */
 	bool IsVertexParent( )
@@ -981,6 +996,8 @@ public:
 	static int			pyattr_set_lin_vel_max(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
 	static PyObject*	pyattr_get_visible(void *self_v, const KX

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list