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:
authorSergej Reich <sergej.reich@googlemail.com>2013-09-06 21:59:09 +0400
committerSergej Reich <sergej.reich@googlemail.com>2013-09-06 21:59:09 +0400
commitc6f361432987804837028ede2118d83ca6a69fdb (patch)
tree8a7ffc1991a023dcf3902eacf368457dedbd691d
parentbf2d4f55de6719e8f75386b3fe9feceb09fc3abb (diff)
rigidbody: Add effector weights for individual rigid bodies
There's a need for more fine grained control over how individual rigid bodies are affected by force fields. Having effector weights for both the world and bodies might be too much. If so, we could drop it from the world and copy the world settings to the body setting for old files.
-rw-r--r--release/scripts/startup/bl_ui/properties_physics_rigidbody.py19
-rw-r--r--source/blender/blenkernel/intern/rigidbody.c33
-rw-r--r--source/blender/blenloader/intern/readfile.c6
-rw-r--r--source/blender/blenloader/intern/writefile.c1
-rw-r--r--source/blender/makesdna/DNA_rigidbody_types.h1
-rw-r--r--source/blender/makesrna/intern/rna_rigidbody.c6
6 files changed, 58 insertions, 8 deletions
diff --git a/release/scripts/startup/bl_ui/properties_physics_rigidbody.py b/release/scripts/startup/bl_ui/properties_physics_rigidbody.py
index c885aa662da..a9cb7b2145d 100644
--- a/release/scripts/startup/bl_ui/properties_physics_rigidbody.py
+++ b/release/scripts/startup/bl_ui/properties_physics_rigidbody.py
@@ -19,6 +19,7 @@
# <pep8 compliant>
import bpy
from bpy.types import Panel
+from bl_ui.properties_physics_common import effector_weights_ui
class PHYSICS_PT_rigidbody_panel():
@@ -136,5 +137,23 @@ class PHYSICS_PT_rigid_body_dynamics(PHYSICS_PT_rigidbody_panel, Panel):
col.prop(rbo, "linear_damping", text="Translation")
col.prop(rbo, "angular_damping", text="Rotation")
+class PHYSICS_PT_rigid_body_field_weights(PHYSICS_PT_rigidbody_panel, Panel):
+ bl_label = "Rigid Body Field Weights"
+ bl_options = {'DEFAULT_CLOSED'}
+ COMPAT_ENGINES = {'BLENDER_RENDER'}
+
+ @classmethod
+ def poll(cls, context):
+ obj = context.object
+ return (obj and obj.rigid_body and
+ obj.rigid_body.type == 'ACTIVE' and
+ (not context.scene.render.use_game_engine))
+
+ def draw(self, context):
+ ob = context.object
+ rbo = ob.rigid_body
+
+ effector_weights_ui(self, context, rbo.effector_weights, 'RIGID_BODY')
+
if __name__ == "__main__": # only for live edit.
bpy.utils.register_module(__name__)
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index 1ac49b2b224..48dcedfe0d3 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -144,6 +144,10 @@ void BKE_rigidbody_free_object(Object *ob)
rbo->physics_shape = NULL;
}
+ /* free effector weights */
+ if (rbo->effector_weights)
+ MEM_freeN(rbo->effector_weights);
+
/* free data itself */
MEM_freeN(rbo);
ob->rigidbody_object = NULL;
@@ -178,11 +182,15 @@ void BKE_rigidbody_free_constraint(Object *ob)
RigidBodyOb *BKE_rigidbody_copy_object(Object *ob)
{
+ RigidBodyOb *rbo = ob->rigidbody_object;
RigidBodyOb *rboN = NULL;
- if (ob->rigidbody_object) {
+ if (rbo) {
/* just duplicate the whole struct first (to catch all the settings) */
- rboN = MEM_dupallocN(ob->rigidbody_object);
+ rboN = MEM_dupallocN(rbo);
+
+ if (rbo->effector_weights)
+ rboN->effector_weights = MEM_dupallocN(rbo->effector_weights);
/* tag object as needing to be verified */
rboN->flag |= RBO_FLAG_NEEDS_VALIDATE;
@@ -959,6 +967,8 @@ RigidBodyOb *BKE_rigidbody_create_object(Scene *scene, Object *ob, short type)
/* create new settings data, and link it up */
rbo = MEM_callocN(sizeof(RigidBodyOb), "RigidBodyOb");
+ rbo->effector_weights = BKE_add_effector_weights(NULL);
+
/* set default settings */
rbo->type = type;
@@ -1211,13 +1221,16 @@ static void rigidbody_update_sim_ob(Scene *scene, RigidBodyWorld *rbw, Object *o
/* update influence of effectors - but don't do it on an effector */
/* only dynamic bodies need effector update */
else if (rbo->type == RBO_TYPE_ACTIVE && ((ob->pd == NULL) || (ob->pd->forcefield == PFIELD_NULL))) {
- EffectorWeights *effector_weights = rbw->effector_weights;
EffectedPoint epoint;
- ListBase *effectors;
+ ListBase *effectors_local;
+ ListBase *effectors_global;
/* get effectors present in the group specified by effector_weights */
- effectors = pdInitEffectors(scene, ob, NULL, effector_weights);
- if (effectors) {
+ effectors_local = pdInitEffectors(scene, ob, NULL, rbo->effector_weights);
+ effectors_global = pdInitEffectors(scene, ob, NULL, rbw->effector_weights);
+ if (effectors_local && effectors_global) {
+ float eff_force_local[3] = {0.0f, 0.0f, 0.0f};
+ float eff_force_global[3] = {0.0f, 0.0f, 0.0f};
float eff_force[3] = {0.0f, 0.0f, 0.0f};
float eff_loc[3], eff_vel[3];
@@ -1231,7 +1244,10 @@ static void rigidbody_update_sim_ob(Scene *scene, RigidBodyWorld *rbw, Object *o
/* calculate net force of effectors, and apply to sim object
* - we use 'central force' since apply force requires a "relative position" which we don't have...
*/
- pdDoEffectors(effectors, NULL, effector_weights, &epoint, eff_force, NULL);
+ pdDoEffectors(effectors_local, NULL, rbo->effector_weights, &epoint, eff_force_local, NULL);
+ pdDoEffectors(effectors_global, NULL, rbw->effector_weights, &epoint, eff_force_global, NULL);
+ add_v3_v3v3(eff_force, eff_force_global, eff_force_local);
+ mul_v3_fl(eff_force, 0.5f);
/* activate object in case it is deactivated */
if (!is_zero_v3(eff_force))
RB_body_activate(rbo->physics_object);
@@ -1239,7 +1255,8 @@ static void rigidbody_update_sim_ob(Scene *scene, RigidBodyWorld *rbw, Object *o
}
/* cleanup */
- pdEndEffectors(&effectors);
+ pdEndEffectors(&effectors_global);
+ pdEndEffectors(&effectors_local);
}
/* NOTE: passive objects don't need to be updated since they don't move */
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 0cd473fd74d..62f2e1b52cc 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -4926,6 +4926,12 @@ static void direct_link_object(FileData *fd, Object *ob)
if (ob->rigidbody_object) {
RigidBodyOb *rbo = ob->rigidbody_object;
+ rbo->effector_weights = newdataadr(fd, rbo->effector_weights);
+ if (rbo->effector_weights)
+ rbo->effector_weights->group = newlibadr(fd, ob->id.lib, rbo->effector_weights->group);
+ else
+ rbo->effector_weights = BKE_add_effector_weights(NULL);
+
/* must nullify the references to physics sim objects, since they no-longer exist
* (and will need to be recalculated)
*/
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 90405583544..dfd20d1d345 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -1525,6 +1525,7 @@ static void write_objects(WriteData *wd, ListBase *idbase)
if (ob->rigidbody_object) {
// TODO: if any extra data is added to handle duplis, will need separate function then
writestruct(wd, DATA, "RigidBodyOb", 1, ob->rigidbody_object);
+ writestruct(wd, DATA, "EffectorWeights", 1, ob->rigidbody_object->effector_weights);
}
if (ob->rigidbody_constraint) {
writestruct(wd, DATA, "RigidBodyCon", 1, ob->rigidbody_constraint);
diff --git a/source/blender/makesdna/DNA_rigidbody_types.h b/source/blender/makesdna/DNA_rigidbody_types.h
index 44416626ffd..f32908e5e15 100644
--- a/source/blender/makesdna/DNA_rigidbody_types.h
+++ b/source/blender/makesdna/DNA_rigidbody_types.h
@@ -123,6 +123,7 @@ typedef struct RigidBodyOb {
float orn[4]; /* rigid body orientation */
float pos[3]; /* rigid body position */
float pad1;
+ struct EffectorWeights *effector_weights;
} RigidBodyOb;
diff --git a/source/blender/makesrna/intern/rna_rigidbody.c b/source/blender/makesrna/intern/rna_rigidbody.c
index a07253876b0..edd9722503f 100644
--- a/source/blender/makesrna/intern/rna_rigidbody.c
+++ b/source/blender/makesrna/intern/rna_rigidbody.c
@@ -924,6 +924,12 @@ static void rna_def_rigidbody_object(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Collision Groups", "Collision Groups Rigid Body belongs to");
RNA_def_property_update(prop, NC_OBJECT | ND_POINTCACHE, "rna_RigidBodyOb_reset");
RNA_def_property_flag(prop, PROP_LIB_EXCEPTION);
+
+ /* effector weights */
+ prop = RNA_def_property(srna, "effector_weights", PROP_POINTER, PROP_NONE);
+ RNA_def_property_struct_type(prop, "EffectorWeights");
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ RNA_def_property_ui_text(prop, "Effector Weights", "");
}
static void rna_def_rigidbody_constraint(BlenderRNA *brna)