[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [30014] branches/soc-2010-aligorith-2: Bullet SoC - Influence Controls:
Joshua Leung
aligorith at gmail.com
Tue Jul 6 09:33:47 CEST 2010
Revision: 30014
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30014
Author: aligorith
Date: 2010-07-06 09:33:47 +0200 (Tue, 06 Jul 2010)
Log Message:
-----------
Bullet SoC - Influence Controls:
It is now possible to control the amount the physics simulation contributes to a simulation, and the transform channels this occurs for.
Modified Paths:
--------------
branches/soc-2010-aligorith-2/release/scripts/ui/properties_physics_rigidbody.py
branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/depsgraph.c
branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/rigidbody.c
branches/soc-2010-aligorith-2/source/blender/makesdna/DNA_rigidbody_types.h
branches/soc-2010-aligorith-2/source/blender/makesrna/intern/rna_rigidbody.c
Modified: branches/soc-2010-aligorith-2/release/scripts/ui/properties_physics_rigidbody.py
===================================================================
--- branches/soc-2010-aligorith-2/release/scripts/ui/properties_physics_rigidbody.py 2010-07-06 06:43:21 UTC (rev 30013)
+++ branches/soc-2010-aligorith-2/release/scripts/ui/properties_physics_rigidbody.py 2010-07-06 07:33:47 UTC (rev 30014)
@@ -62,6 +62,11 @@
col = layout.column()
col.prop(rbo, "mass")
+ col = layout.column(align=1)
+ col.label(text="Influence:")
+ col.prop(rbo, "follow_simulation", text="")
+ col.prop(rbo, "influence")
+
class PHYSICS_PT_rigid_body_collisions(PHYSICS_PT_rigidbody_panel):
bl_label = "Rigid Body Collisions"
Modified: branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/depsgraph.c
===================================================================
--- branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/depsgraph.c 2010-07-06 06:43:21 UTC (rev 30013)
+++ branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/depsgraph.c 2010-07-06 07:33:47 UTC (rev 30014)
@@ -2044,7 +2044,7 @@
if(object_modifiers_use_time(ob)) ob->recalc |= OB_RECALC_DATA;
if((ob->pose) && (ob->pose->flag & POSE_CONSTRAINTS_TIMEDEPEND)) ob->recalc |= OB_RECALC_DATA;
- if(ob->rigidbodySettings) ob->recalc |= OB_RECALC;
+ if(ob->rigidbodySettings) ob->recalc |= OB_RECALC_OB;
{
AnimData *adt= BKE_animdata_from_id((ID *)ob->data);
Modified: branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/rigidbody.c
===================================================================
--- branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/rigidbody.c 2010-07-06 06:43:21 UTC (rev 30013)
+++ branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/rigidbody.c 2010-07-06 07:33:47 UTC (rev 30014)
@@ -307,7 +307,6 @@
/* helper for BKE_rigidbody_create_object() - determines the collision shape from the boundbox type */
-// TODO: should we just use the ob->boundbox setting instead to make life easier?
static int get_shape_from_boundbox (Object *ob)
{
switch (ob->boundtype) {
@@ -349,6 +348,7 @@
/* set default settings */
rbo->type = type;
+ rbo->influence = (type == RBO_TYPE_ACTIVE)? 1.0f : 0.0f;
rbo->mass = 1.0f;
@@ -445,7 +445,8 @@
static void rigidbody_update_sim_world (Scene *scene, RigidBodyWorld *rbw)
{
- /* update gravity */
+ /* update gravity, since this RNA setting is not part of RigidBody settings */
+ // TODO: this might change cache status if we stepped backwards then did this...
rbSetGravity(rbw->physics_world, scene->physics_settings.gravity);
}
@@ -465,6 +466,52 @@
/* ------------------ */
+static void rigidbody_update_blender_ob (Scene *scene, RigidBodyWorld *rbw, Object *ob, RigidBodyOb *rbo)
+{
+ float mat[4][4];
+
+ /* get transform matrix from Bullet */
+ rbGetTransformMatrix(rbo->physics_object, mat);
+
+ /* copy transforms to Blender object
+ * - only if RigidBody results are wanted
+ * - influence describes amount of physics-result to keep
+ */
+ if (rbo->influence != 0.0f) {
+ /* remove components we don't want copied over in the final result */
+ if (rbo->uses_tfms == RBO_TRANSFORMS_ONLY_LOC) {
+ /* replacing rotation */
+ VECCOPY(mat[0], ob->obmat[0]);
+ VECCOPY(mat[1], ob->obmat[1]);
+ VECCOPY(mat[2], ob->obmat[2]);
+ }
+ else if (rbo->uses_tfms == RBO_TRANSFORMS_ONLY_ROT) {
+ /* replacing location */
+ VECCOPY(mat[3], ob->obmat[3]);
+ }
+
+ // XXX: if we supplied a normalised copy to Bullet, we'll need to reapply scale here...
+
+ /* set new obmatrix */
+ if (rbo->influence < 1.0f) {
+ /* need to blend between results, so make temp copy of current matrix before continuing */
+ float smat[4][4];
+
+ copy_m4_m4(smat, ob->obmat);
+ blend_m4_m4m4(ob->obmat, mat, smat, (1.0f - rbo->influence));
+ }
+ else {
+ /* special case where hopefully we can save some accuracy + speed */
+ copy_m4_m4(ob->obmat, mat);
+ }
+ }
+
+ /* also, write new matrix to motion cache for potential restoring later */
+ // TODO: code me!
+}
+
+/* ------------------ */
+
/* Run RigidBody simulation for the specified physics world */
void BKE_rigidbody_do_simulation (Scene *scene, RigidBodyWorld *rbw, float ctime)
{
@@ -572,7 +619,7 @@
*/
rbStepSimulationAdv(rbw->physics_world, timestep, rbw->max_substeps, rbw->fixed_timestep);
- /* grab current scene settings from the physics world */
+ /* grab current scene state from the physics world */
// TODO: could some of this be automated using motionstates?
for (go = rbw->group->gobject.first; go; go = go->next) {
Object *ob = go->ob;
@@ -580,13 +627,9 @@
if (ob) {
RigidBodyOb *rbo = ob->rigidbodySettings;
- /* get transform matrix from Bullet */
- // XXX: if we supplied a normalised copy to Bullet, we'll need to reapply scale here...
- // TODO: need to implement code to only grab certain components from this result...
- rbGetTransformMatrix(rbo->physics_object, ob->obmat);
+ /* store new transforms, and also write to cache */
+ rigidbody_update_blender_ob(scene, rbw, ob, rbo);
- // TODO: write new matrix to motion cache for potential restoring later
-
// DEBUG
printf("\t%s: new pos - %f %f %f \n", ob->id.name+2, ob->obmat[3][0], ob->obmat[3][1], ob->obmat[3][2]);
}
Modified: branches/soc-2010-aligorith-2/source/blender/makesdna/DNA_rigidbody_types.h
===================================================================
--- branches/soc-2010-aligorith-2/source/blender/makesdna/DNA_rigidbody_types.h 2010-07-06 06:43:21 UTC (rev 30013)
+++ branches/soc-2010-aligorith-2/source/blender/makesdna/DNA_rigidbody_types.h 2010-07-06 07:33:47 UTC (rev 30014)
@@ -101,6 +101,10 @@
int flag; /* (eRigidBodyOb_Flag) */
+ float influence; /* amount simulation results contribute to final result */
+ short uses_tfms; /* (eRigidBodyOb_Transforms) */
+ short pad;
+
/* Physics Parameters */
float mass; /* how much object 'weighs' (i.e. absolute 'amount of stuff' it holds) */
@@ -113,7 +117,6 @@
/* Participation types for RigidBodyOb */
// XXX: how do we represent objects switching between anim and sim? allow changing this during anim?
-// XXX: should we just dump this setting in favour of the 'dynamic' flag? or get rid of that instead?
typedef enum eRigidBodyOb_Type {
/* active geometry participant in simulation. is directly controlled by sim */
RBO_TYPE_ACTIVE = 0,
@@ -150,6 +153,16 @@
RB_SHAPE_COMPOUND,
} eRigidBody_Shape;
+/* Options for transforms to use from Bullet */
+typedef enum eRigidBodyOb_Transforms {
+ /* all transforms are inherited (default) */
+ RBO_TRANSFORMS_ALL = 0,
+ /* only location */
+ RBO_TRANSFORMS_ONLY_LOC,
+ /* only rotation */
+ RBO_TRANSFORMS_ONLY_ROT,
+} eRigidBodyOb_Transforms;
+
/* ******************************** */
#endif // DNA_RIGIDBODY_TYPES_H
Modified: branches/soc-2010-aligorith-2/source/blender/makesrna/intern/rna_rigidbody.c
===================================================================
--- branches/soc-2010-aligorith-2/source/blender/makesrna/intern/rna_rigidbody.c 2010-07-06 06:43:21 UTC (rev 30013)
+++ branches/soc-2010-aligorith-2/source/blender/makesrna/intern/rna_rigidbody.c 2010-07-06 07:33:47 UTC (rev 30014)
@@ -224,12 +224,6 @@
RNA_def_property_ui_text(prop, "Enabled", "Simulation will be evaluated");
RNA_def_property_update(prop, NC_SCENE, NULL);
- // XXX: temp setting... maybe we'll have a more elegant solution later when settings force updates automatically...
- prop=RNA_def_property(srna, "force_update", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "recalc", RBW_RECALC_REBUILD);
- RNA_def_property_ui_text(prop, "Force Update Hack", "Hack to force sim settings to get rebuilt");
- RNA_def_property_update(prop, NC_SCENE, NULL);
-
/* start frame */
prop= RNA_def_property(srna, "frame_start", PROP_INT, PROP_TIME);
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
@@ -241,7 +235,7 @@
/* timesteps */
prop= RNA_def_property(srna, "fixed_time_step", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "fixed_timestep");
- RNA_def_property_ui_text(prop, "Fixed Time Step", "Size of substeps physics simulator internally uses to take desired time-step (smaller steps are more accurate)");
+ RNA_def_property_ui_text(prop, "Fixed Time Step", "Size of substeps physics simulator internally uses when stepping the simulation (smaller steps are more accurate)");
RNA_def_property_update(prop, NC_SCENE, NULL);
prop= RNA_def_property(srna, "max_sub_steps", PROP_INT, PROP_NONE);
@@ -255,9 +249,16 @@
static void rna_def_rigidbody_object(BlenderRNA *brna)
{
+ static EnumPropertyItem rigidbody_ob_transforms_items[] = {
+ {RBO_TRANSFORMS_ALL, "ALL", 0, "All - LocRot", "Location and Rotation"},
+ {RBO_TRANSFORMS_ONLY_LOC, "LOC", 0, "Location Only", ""},
+ {RBO_TRANSFORMS_ONLY_ROT, "ROT", 0, "Rotation Only", ""},
+ {0, NULL, 0, NULL, NULL}};
+
StructRNA *srna;
PropertyRNA *prop;
+
srna= RNA_def_struct(brna, "RigidBodyObject", NULL);
RNA_def_struct_sdna(srna, "RigidBodyOb");
RNA_def_struct_ui_text(srna, "Rigid Body Object", "Settings for object participating in Rigid Body Simulation");
@@ -278,6 +279,19 @@
RNA_def_property_ui_text(prop, "Collision Shape", "Collision Shape of object in Rigid Body Simulations");
// TODO: setup necessary updates for this setting
+ /* Blender Interaction */
+ prop= RNA_def_property(srna, "follow_simulation", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_sdna(prop, NULL, "uses_tfms");
+ RNA_def_property_enum_items(prop, rigidbody_ob_transforms_items);
+ RNA_def_property_ui_text(prop, "Follow Simulation", "Transform channels from simulation results to use");
+ // TODO: setup necessary updates for this setting
+
+ prop= RNA_def_property(srna, "influence", PROP_FLOAT, PROP_FACTOR);
+ RNA_def_property_float_sdna(prop, NULL, "influence");
+ RNA_def_property_range(prop, 0.0f, 1.0f);
+ RNA_def_property_ui_text(prop, "Influence", "Amount of influence simulation results have on the final results");
+ // TODO: setup necessary updates for this setting
+
/* Physics Parameters */
prop= RNA_def_property(srna, "mass", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "mass");
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list