synched with trunk at revision 30243
[blender-staging.git] / source / blender / makesrna / intern / rna_object.c
index 5b97545c3307ce34de1445b69f251f9907788d77..92b045d3052588ca3dea51bf49cd33e3d2ad40fc 100644 (file)
@@ -134,12 +134,45 @@ void rna_Object_internal_update(Main *bmain, Scene *scene, PointerRNA *ptr)
        DAG_id_flush_update(ptr->id.data, OB_RECALC_OB);
 }
 
-void rna_Object_matrix_update(Main *bmain, Scene *scene, PointerRNA *ptr)
+void rna_Object_matrix_world_update(Main *bmain, Scene *scene, PointerRNA *ptr)
 {
        object_apply_mat4(ptr->id.data, ((Object *)ptr->id.data)->obmat);
        rna_Object_internal_update(bmain, scene, ptr);
 }
 
+void rna_Object_matrix_local_get(PointerRNA *ptr, float values[16])
+{
+       Object *ob= ptr->id.data;
+
+       if(ob->parent) {
+               float invmat[4][4]; /* for inverse of parent's matrix */
+               invert_m4_m4(invmat, ob->parent->obmat);
+               mul_m4_m4m4((float(*)[4])values, ob->obmat, invmat);
+       }
+       else {
+               copy_m4_m4((float(*)[4])values, ob->obmat);
+       }
+}
+
+void rna_Object_matrix_local_set(PointerRNA *ptr, const float values[16])
+{
+       Object *ob= ptr->id.data;
+
+       /* localspace matrix is truly relative to the parent, but parameters
+        * stored in object are relative to parentinv matrix.  Undo the parent
+        * inverse part before updating obmat and calling apply_obmat() */
+       if(ob->parent) {
+               float invmat[4][4];
+               invert_m4_m4(invmat, ob->parentinv);
+               mul_m4_m4m4(ob->obmat, (float(*)[4])values, invmat);
+       }
+       else {
+               copy_m4_m4(ob->obmat, (float(*)[4])values);
+       }
+
+       object_apply_mat4(ob, ob->obmat);
+}
+
 void rna_Object_internal_update_data(Main *bmain, Scene *scene, PointerRNA *ptr)
 {
        DAG_id_flush_update(ptr->id.data, OB_RECALC_DATA);
@@ -210,7 +243,7 @@ static void rna_Object_layer_update(Main *bmain, Scene *scene, PointerRNA *ptr)
 
 static void rna_Base_layer_update(Main *bmain, Scene *scene, PointerRNA *ptr)
 {
-       Base *base= (Base*)ptr->id.data;
+       Base *base= (Base*)ptr->data;
        Object *ob= (Object*)base->object;
 
        rna_Object_layer_update__internal(scene, base, ob);
@@ -737,6 +770,8 @@ static int rna_GameObjectSettings_physics_type_get(PointerRNA *ptr)
        if (!(ob->gameflag & OB_COLLISION)) {
                if (ob->gameflag & OB_OCCLUDER) {
                        ob->body_type = OB_BODY_TYPE_OCCLUDER;
+               } else if (ob->gameflag & OB_NAVMESH){
+                       ob->body_type = OB_BODY_TYPE_NAVMESH;
                } else {
                        ob->body_type = OB_BODY_TYPE_NO_COLLISION;
                }
@@ -766,31 +801,35 @@ static void rna_GameObjectSettings_physics_type_set(PointerRNA *ptr, int 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);
+               ob->gameflag &= ~(OB_OCCLUDER|OB_NAVMESH|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);
+               ob->gameflag &= ~(OB_SENSOR|OB_COLLISION|OB_DYNAMIC|OB_NAVMESH);
+               break;
+       case OB_BODY_TYPE_NAVMESH:
+               ob->gameflag |= OB_NAVMESH;
+               ob->gameflag &= ~(OB_SENSOR|OB_COLLISION|OB_DYNAMIC|OB_OCCLUDER);
                break;
        case OB_BODY_TYPE_NO_COLLISION:
-               ob->gameflag &= ~(OB_SENSOR|OB_COLLISION|OB_OCCLUDER|OB_DYNAMIC);
+               ob->gameflag &= ~(OB_SENSOR|OB_COLLISION|OB_OCCLUDER|OB_DYNAMIC|OB_NAVMESH);
                break;
        case OB_BODY_TYPE_STATIC:
                ob->gameflag |= OB_COLLISION;
-               ob->gameflag &= ~(OB_DYNAMIC|OB_RIGID_BODY|OB_SOFT_BODY|OB_OCCLUDER|OB_SENSOR);
+               ob->gameflag &= ~(OB_DYNAMIC|OB_RIGID_BODY|OB_SOFT_BODY|OB_OCCLUDER|OB_SENSOR|OB_NAVMESH);
                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);
+               ob->gameflag &= ~(OB_RIGID_BODY|OB_SOFT_BODY|OB_OCCLUDER|OB_SENSOR|OB_NAVMESH);
                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);
+               ob->gameflag &= ~(OB_SOFT_BODY|OB_OCCLUDER|OB_SENSOR|OB_NAVMESH);
                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);
+               ob->gameflag &= ~(OB_RIGID_BODY|OB_OCCLUDER|OB_SENSOR|OB_NAVMESH);
 
                /* assume triangle mesh, if no bounds chosen for soft body */
                if ((ob->gameflag & OB_BOUNDS) && (ob->boundtype<OB_BOUND_POLYH))
@@ -1093,6 +1132,7 @@ static void rna_def_object_game_settings(BlenderRNA *brna)
                {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"},
+               {OB_BODY_TYPE_NAVMESH, "NAVMESH", 0, "NavMesh", "Navigation mesh"},
                {0, NULL, 0, NULL, NULL}};
 
        srna= RNA_def_struct(brna, "GameObjectSettings", NULL);
@@ -1262,9 +1302,18 @@ static void rna_def_object_game_settings(BlenderRNA *brna)
        RNA_def_property_pointer_sdna(prop, NULL, "bsoft");
        RNA_def_property_ui_text(prop, "Soft Body Settings", "Settings for Bullet soft body simulation");
 
+       prop= RNA_def_property(srna, "create_obstacle", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "gameflag", OB_HASOBSTACLE);
+       RNA_def_property_ui_text(prop, "Create obstacle", "Create representation for obstacle simulation");
+
+       prop= RNA_def_property(srna, "obstacle_radius", PROP_FLOAT, PROP_NONE|PROP_UNIT_LENGTH);
+       RNA_def_property_float_sdna(prop, NULL, "obstacleRad");
+       RNA_def_property_range(prop, 0.0, 1000.0);
+       RNA_def_property_ui_text(prop, "Obstacle Radius", "Radius of object representation in obstacle simulation");
+
        /* state */
 
-       prop= RNA_def_property(srna, "state", PROP_BOOLEAN, PROP_LAYER_MEMBER);
+       prop= RNA_def_property(srna, "visible_state", PROP_BOOLEAN, PROP_LAYER_MEMBER);
        RNA_def_property_boolean_sdna(prop, NULL, "state", 1);
        RNA_def_property_array(prop, OB_MAX_STATES);
        RNA_def_property_ui_text(prop, "State", "State determining which controllers are displayed");
@@ -1443,7 +1492,7 @@ static void rna_def_object(BlenderRNA *brna)
                {OB_BOUND_SPHERE, "SPHERE", 0, "Sphere", ""},
                {OB_BOUND_CYLINDER, "CYLINDER", 0, "Cylinder", ""},
                {OB_BOUND_CONE, "CONE", 0, "Cone", ""},
-               {OB_BOUND_POLYH, "POLYHEDER", 0, "Polyheder", ""},
+               {OB_BOUND_POLYH, "POLYHEDRON", 0, "Polyhedron", ""},
                {0, NULL, 0, NULL, NULL}};
 
        static EnumPropertyItem dupli_items[] = {
@@ -1700,11 +1749,17 @@ static void rna_def_object(BlenderRNA *brna)
        RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_internal_update");
 
        /* matrix */
-       prop= RNA_def_property(srna, "matrix", PROP_FLOAT, PROP_MATRIX);
+       prop= RNA_def_property(srna, "matrix_world", PROP_FLOAT, PROP_MATRIX);
        RNA_def_property_float_sdna(prop, NULL, "obmat");
        RNA_def_property_multi_array(prop, 2, matrix_dimsize);
-       RNA_def_property_ui_text(prop, "Matrix", "Transformation matrix");
-       RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_matrix_update");
+       RNA_def_property_ui_text(prop, "Matrix World", "Worldspace transformation matrix");
+       RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_matrix_world_update");
+
+       prop= RNA_def_property(srna, "matrix_local", PROP_FLOAT, PROP_MATRIX);
+       RNA_def_property_multi_array(prop, 2, matrix_dimsize);
+       RNA_def_property_ui_text(prop, "Local Matrix", "Parent relative transformation matrix");
+       RNA_def_property_float_funcs(prop, "rna_Object_matrix_local_get", "rna_Object_matrix_local_set", NULL);
+       RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, NULL);
 
        /* collections */
        prop= RNA_def_property(srna, "constraints", PROP_COLLECTION, PROP_NONE);