[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [31164] branches/soc-2010-aligorith-2/ source/blender: Bullet SoC - Bugfix: Duplicating objects now duplicates RigidBody settings too ( and hooks up the duplicates to the same sims).
Joshua Leung
aligorith at gmail.com
Sun Aug 8 14:12:48 CEST 2010
Revision: 31164
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=31164
Author: aligorith
Date: 2010-08-08 14:12:48 +0200 (Sun, 08 Aug 2010)
Log Message:
-----------
Bullet SoC - Bugfix: Duplicating objects now duplicates RigidBody settings too (and hooks up the duplicates to the same sims). This is handy for creating many Rigid Bodies which perform the same thing (until I consider again allow instancing to do this)
Modified Paths:
--------------
branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/rigidbody.c
branches/soc-2010-aligorith-2/source/blender/editors/object/object_add.c
branches/soc-2010-aligorith-2/source/blender/makesdna/DNA_rigidbody_types.h
Modified: branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/rigidbody.c
===================================================================
--- branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/rigidbody.c 2010-08-08 11:47:56 UTC (rev 31163)
+++ branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/rigidbody.c 2010-08-08 12:12:48 UTC (rev 31164)
@@ -143,13 +143,29 @@
/* Copying Methods --------------------- */
-/* Make a copy of Rigid Body settings for given Object, returning a new copy
- * that can be used later...
+/* Make a copy of Rigid Body settings for given Object
+ * - This just copies the data, clearing out references to physics objects.
+ * - Anything that uses this MUST verify that the copied object will
+ * be added to relevant groups later...
*/
RigidBodyOb *BKE_rigidbody_copy_object (Object *ob)
{
- // FIXME: this cannot be linked to scenes correctly... we need some correction logic!
- return NULL;
+ RigidBodyOb *rboN = NULL;
+
+ if (ob->rigidbodySettings) {
+ /* just duplicate the whole struct first (to catch all the settings) */
+ rboN = MEM_dupallocN(ob->rigidbodySettings);
+
+ /* tag object as needing to be verified */
+ rboN->flag |= RBO_FLAG_NEEDS_VALIDATE;
+
+ /* clear out all the fields which need to be revalidated later */
+ rboN->physics_object = NULL;
+ rboN->physics_shape = NULL;
+ }
+
+ /* return new copy of settings */
+ return rboN;
}
/* ************************************** */
@@ -759,7 +775,12 @@
rbo = ob->rigidbodySettings;
}
- else if (rbw->recalc & RBW_RECALC_REBUILD) {
+ else if (rbo->flag & RBO_FLAG_NEEDS_VALIDATE) {
+ /* there are settings, but the object(s) must be rebuilt (i.e. after being duplicated) */
+ BKE_rigidbody_validate_sim_object(rbw, ob, 1);
+ rbo->flag &= ~RBO_FLAG_NEEDS_VALIDATE;
+ }
+ else if (rbw->recalc & RBW_RECALC_REBUILD) {
/* there are settings, but the object(s) must be rebuilt (i.e. after file-reload) */
BKE_rigidbody_validate_sim_object(rbw, ob, 1);
}
Modified: branches/soc-2010-aligorith-2/source/blender/editors/object/object_add.c
===================================================================
--- branches/soc-2010-aligorith-2/source/blender/editors/object/object_add.c 2010-08-08 11:47:56 UTC (rev 31163)
+++ branches/soc-2010-aligorith-2/source/blender/editors/object/object_add.c 2010-08-08 12:12:48 UTC (rev 31164)
@@ -1466,7 +1466,11 @@
BLI_addhead(&scene->base, basen); /* addhead: prevent eternal loop */
basen->object= obn;
- if(basen->flag & OB_FROMGROUP) {
+ /* 1) duplis should end up in same group as the original
+ * 2) Rigid Body sim participants MUST always be part of a group...
+ */
+ // XXX: is 2) really a good measure here?
+ if((basen->flag & OB_FROMGROUP) || (ob->rigidbodySettings)) {
Group *group;
for(group= G.main->group.first; group; group= group->id.next) {
if(object_in_group(ob, group))
@@ -1477,7 +1481,6 @@
/* duplicates using userflags */
#if 0 // XXX old animation system
if(dupflag & USER_DUP_IPO) {
- bConstraintChannel *chan;
id= (ID *)obn->ipo;
if(id) {
@@ -1485,15 +1488,6 @@
else obn->ipo= copy_ipo(obn->ipo);
id->us--;
}
- /* Handle constraint ipos */
- for (chan=obn->constraintChannels.first; chan; chan=chan->next){
- id= (ID *)chan->ipo;
- if(id) {
- ID_NEW_US( chan->ipo)
- else chan->ipo= copy_ipo(chan->ipo);
- id->us--;
- }
- }
}
if(dupflag & USER_DUP_ACT){ /* Not buttons in the UI to modify this, add later? */
id= (ID *)obn->action;
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-08-08 11:47:56 UTC (rev 31163)
+++ branches/soc-2010-aligorith-2/source/blender/makesdna/DNA_rigidbody_types.h 2010-08-08 12:12:48 UTC (rev 31164)
@@ -142,6 +142,8 @@
* - affects Bullet "activation state" of the corresponding Rigid Body
*/
RBO_FLAG_DYNAMIC_EVAL = (1<<0),
+ /* rigidbody needs to be validated (usually set after duplicating and not hooked up yet) */
+ RBO_FLAG_NEEDS_VALIDATE = (1<<1),
} eRigidBodyOb_Flag;
/* RigidBody Collision Shape */
More information about the Bf-blender-cvs
mailing list