Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2009-08-04 13:20:48 +0400
committerCampbell Barton <ideasman42@gmail.com>2009-08-04 13:20:48 +0400
commit610d9348f588734023c5ba34b2621b2d4fcddca8 (patch)
tree3a494c2837b3c4936576ac1e2f88be24c2c047ff
parent9bb8540ba9e716363ed654aeb989cf83ea704d4a (diff)
- allow changing game engine physics types in RNA
- allow appending with a NULL scene (only used to add object bases into the current scene)
-rw-r--r--source/blender/blenloader/intern/readfile.c5
-rw-r--r--source/blender/makesrna/intern/rna_object.c95
2 files changed, 92 insertions, 8 deletions
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 28694233331..f52afd9391d 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -10543,7 +10543,7 @@ static void append_named_part(FileData *fd, Main *mainvar, Scene *scene, char *n
}
}
- if(idcode==ID_OB) { /* loose object: give a base */
+ if(idcode==ID_OB && scene) { /* loose object: give a base */
base= MEM_callocN( sizeof(Base), "app_nam_part");
BLI_addtail(&scene->base, base);
@@ -10683,7 +10683,8 @@ void BLO_script_library_append(BlendHandle **bh, char *dir, char *name,
if(fd) fd->reports= NULL;
/* do we need to do this? */
- DAG_scene_sort(scene);
+ if(scene)
+ DAG_scene_sort(scene);
*bh= (BlendHandle*)fd;
}
diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c
index 53a73e0b03e..7e26cb00394 100644
--- a/source/blender/makesrna/intern/rna_object.c
+++ b/source/blender/makesrna/intern/rna_object.c
@@ -57,6 +57,7 @@ static EnumPropertyItem parent_type_items[] = {
#include "DNA_key_types.h"
#include "BKE_armature.h"
+#include "BKE_bullet.h"
#include "BKE_context.h"
#include "BKE_curve.h"
#include "BKE_depsgraph.h"
@@ -479,6 +480,86 @@ static void rna_MaterialSlot_name_get(PointerRNA *ptr, char *str)
strcpy(str, "");
}
+/* why does this have to be so complicated?, can't all this crap be
+ * moved to in BGE conversion function? - Campbell *
+ *
+ * logic from check_body_type()
+ * */
+static int rna_GameObjectSettings_physics_type_get(PointerRNA *ptr)
+{
+ Object *ob= (Object*)ptr->id.data;
+
+ /* determine the body_type setting based on flags */
+ if (!(ob->gameflag & OB_COLLISION)) {
+ if (ob->gameflag & OB_OCCLUDER) {
+ ob->body_type = OB_BODY_TYPE_OCCLUDER;
+ } else {
+ ob->body_type = OB_BODY_TYPE_NO_COLLISION;
+ }
+ } else if (ob->gameflag & OB_SENSOR) {
+ ob->body_type = OB_BODY_TYPE_SENSOR;
+ } else if (!(ob->gameflag & OB_DYNAMIC)) {
+ ob->body_type = OB_BODY_TYPE_STATIC;
+ } else if (!(ob->gameflag & (OB_RIGID_BODY|OB_SOFT_BODY))) {
+ ob->body_type = OB_BODY_TYPE_DYNAMIC;
+ } else if (ob->gameflag & OB_RIGID_BODY) {
+ ob->body_type = OB_BODY_TYPE_RIGID;
+ } else {
+ ob->body_type = OB_BODY_TYPE_SOFT;
+ /* create the structure here because we display soft body buttons in the main panel */
+ if (!ob->bsoft)
+ ob->bsoft = bsbNew();
+ }
+
+ return ob->body_type;
+}
+
+static void rna_GameObjectSettings_physics_type_set(PointerRNA *ptr, int value)
+{
+ Object *ob= (Object*)ptr->id.data;
+ ob->body_type= value;
+
+ switch (ob->body_type) {
+ case OB_BODY_TYPE_SENSOR:
+ ob->gameflag |= OB_SENSOR|OB_COLLISION|OB_GHOST;
+ ob->gameflag &= ~(OB_OCCLUDER|OB_DYNAMIC|OB_RIGID_BODY|OB_SOFT_BODY|OB_ACTOR|OB_ANISOTROPIC_FRICTION|OB_DO_FH|OB_ROT_FH|OB_COLLISION_RESPONSE);
+ break;
+ case OB_BODY_TYPE_OCCLUDER:
+ ob->gameflag |= OB_OCCLUDER;
+ ob->gameflag &= ~(OB_SENSOR|OB_COLLISION|OB_DYNAMIC);
+ break;
+ case OB_BODY_TYPE_NO_COLLISION:
+ ob->gameflag &= ~(OB_SENSOR|OB_COLLISION|OB_OCCLUDER|OB_DYNAMIC);
+ break;
+ case OB_BODY_TYPE_STATIC:
+ ob->gameflag |= OB_COLLISION;
+ ob->gameflag &= ~(OB_DYNAMIC|OB_RIGID_BODY|OB_SOFT_BODY|OB_OCCLUDER|OB_SENSOR);
+ break;
+ case OB_BODY_TYPE_DYNAMIC:
+ ob->gameflag |= OB_COLLISION|OB_DYNAMIC|OB_ACTOR;
+ ob->gameflag &= ~(OB_RIGID_BODY|OB_SOFT_BODY|OB_OCCLUDER|OB_SENSOR);
+ break;
+ case OB_BODY_TYPE_RIGID:
+ ob->gameflag |= OB_COLLISION|OB_DYNAMIC|OB_RIGID_BODY|OB_ACTOR;
+ ob->gameflag &= ~(OB_SOFT_BODY|OB_OCCLUDER|OB_SENSOR);
+ break;
+ default:
+ case OB_BODY_TYPE_SOFT:
+ ob->gameflag |= OB_COLLISION|OB_DYNAMIC|OB_SOFT_BODY|OB_ACTOR;
+ ob->gameflag &= ~(OB_RIGID_BODY|OB_OCCLUDER|OB_SENSOR);
+
+ /* assume triangle mesh, if no bounds chosen for soft body */
+ if ((ob->gameflag & OB_BOUNDS) && (ob->boundtype<OB_BOUND_POLYH))
+ {
+ ob->boundtype=OB_BOUND_POLYH;
+ }
+ /* create a BulletSoftBody structure if not already existing */
+ if (!ob->bsoft)
+ ob->bsoft = bsbNew();
+ break;
+ }
+}
+
static PointerRNA rna_Object_active_particle_system_get(PointerRNA *ptr)
{
Object *ob= (Object*)ptr->id.data;
@@ -667,11 +748,13 @@ static void rna_def_object_game_settings(BlenderRNA *brna)
PropertyRNA *prop;
static EnumPropertyItem body_type_items[] = {
- {OB_BODY_TYPE_NO_COLLISION, "NO_COLLISION", 0, "No Collision", ""},
- {OB_BODY_TYPE_STATIC, "STATIC", 0, "Static", ""},
- {OB_BODY_TYPE_DYNAMIC, "DYNAMIC", 0, "Dynamic", ""},
- {OB_BODY_TYPE_RIGID, "RIGID_BODY", 0, "Rigid Body", ""},
- {OB_BODY_TYPE_SOFT, "SOFT_BODY", 0, "Soft Body", ""},
+ {OB_BODY_TYPE_NO_COLLISION, "NO_COLLISION", 0, "No Collision", "Disable colision for this object"},
+ {OB_BODY_TYPE_STATIC, "STATIC", 0, "Static", "Stationary object"},
+ {OB_BODY_TYPE_DYNAMIC, "DYNAMIC", 0, "Dynamic", "Linear physics"},
+ {OB_BODY_TYPE_RIGID, "RIGID_BODY", 0, "Rigid Body", "Linear and angular physics"},
+ {OB_BODY_TYPE_SOFT, "SOFT_BODY", 0, "Soft Body", "Soft body"},
+ {OB_BODY_TYPE_OCCLUDER, "OCCLUDE", 0, "Occlude", "Occluder for optimizing scene rendering"},
+ {OB_BODY_TYPE_SENSOR, "SENSOR", 0, "Sensor", "Collision Sensor, detects static and dynamic objects but not the other collision sensor objects"},
{0, NULL, 0, NULL, NULL}};
static EnumPropertyItem collision_bounds_items[] = {
@@ -726,7 +809,7 @@ static void rna_def_object_game_settings(BlenderRNA *brna)
prop= RNA_def_property(srna, "physics_type", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "body_type");
RNA_def_property_enum_items(prop, body_type_items);
- RNA_def_property_clear_flag(prop, PROP_EDITABLE); // this controls various gameflags
+ RNA_def_property_enum_funcs(prop, "rna_GameObjectSettings_physics_type_get", "rna_GameObjectSettings_physics_type_set", NULL);
RNA_def_property_ui_text(prop, "Physics Type", "Selects the type of physical representation.");
prop= RNA_def_property(srna, "actor", PROP_BOOLEAN, PROP_NONE);