[Bf-blender-cvs] [b7d3160] particles_refactor: Moved functions for object component data management (RigidBodyObject and RigidBodyCon) into rigidbody_objects.c as well.

Lukas Tönne noreply at git.blender.org
Tue Apr 22 12:07:12 CEST 2014


Commit: b7d3160133e6343dc8b162be00c37473bb136585
Author: Lukas Tönne
Date:   Tue Apr 1 17:47:25 2014 +0200
https://developer.blender.org/rBb7d3160133e6343dc8b162be00c37473bb136585

Moved functions for object component data management (RigidBodyObject
and RigidBodyCon) into rigidbody_objects.c as well.

===================================================================

M	source/blender/blenkernel/BKE_rigidbody.h
M	source/blender/blenkernel/intern/rigidbody.c
M	source/blender/blenkernel/intern/rigidbody_objects.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_rigidbody.h b/source/blender/blenkernel/BKE_rigidbody.h
index 53178de..21d79c9 100644
--- a/source/blender/blenkernel/BKE_rigidbody.h
+++ b/source/blender/blenkernel/BKE_rigidbody.h
@@ -46,22 +46,12 @@ struct Group;
 /* Memory Management */
 
 void BKE_rigidbody_free_world(struct RigidBodyWorld *rbw);
-void BKE_rigidbody_free_object(struct Object *ob);
-void BKE_rigidbody_free_constraint(struct Object *ob);
-
-/* ...... */
-
-struct RigidBodyOb *BKE_rigidbody_copy_object(struct Object *ob);
-struct RigidBodyCon *BKE_rigidbody_copy_constraint(struct Object *ob);
-void BKE_rigidbody_relink_constraint(struct RigidBodyCon *rbc);
 
 /* -------------- */
 /* Setup */
 
 /* create Blender-side settings data - physics objects not initialized yet */
 struct RigidBodyWorld *BKE_rigidbody_create_world(struct Scene *scene);
-struct RigidBodyOb *BKE_rigidbody_create_object(struct Scene *scene, struct Object *ob, short type);
-struct RigidBodyCon *BKE_rigidbody_create_constraint(struct Scene *scene, struct Object *ob, short type);
 
 /* initialize mempools, for readfile */
 void BKE_rigidbody_world_init_mempool(struct RigidBodyWorld *rbw);
@@ -80,18 +70,6 @@ void BKE_rigidbody_validate_sim_world(struct Scene *scene, struct RigidBodyWorld
 /* Utilities */
 
 struct RigidBodyWorld *BKE_rigidbody_get_world(struct Scene *scene);
-void BKE_rigidbody_remove_object(struct Scene *scene, struct Object *ob);
-void BKE_rigidbody_remove_constraint(struct Scene *scene, struct Object *ob);
-
-/* -------------- */
-/* Utility Macros */
-
-/* get mass of Rigid Body Object to supply to RigidBody simulators */
-#define RBO_GET_MASS(rbo) \
-	((rbo && ((rbo->type == RBO_TYPE_PASSIVE) || (rbo->flag & RBO_FLAG_KINEMATIC) || (rbo->flag & RBO_FLAG_DISABLED))) ? (0.0f) : (rbo->mass))
-/* get collision margin for Rigid Body Object, triangle mesh and cone shapes cannot embed margin, convex hull always uses custom margin */
-#define RBO_GET_MARGIN(rbo) \
-	((rbo->flag & RBO_FLAG_USE_MARGIN || rbo->shape == RB_SHAPE_CONVEXH || rbo->shape == RB_SHAPE_TRIMESH || rbo->shape == RB_SHAPE_CONE) ? (rbo->margin) : (0.04f))
 
 /* -------------- */
 /* Simulation */
@@ -103,11 +81,38 @@ void BKE_rigidbody_do_simulation(struct Scene *scene, float ctime);
 
 
 /* -------------- */
-/* rigidbody_objects.c */
+/* Objects (rigidbody_objects.c) */
+
+/* Main Simulation Sync */
 
 void BKE_rigidbody_objects_build(struct Scene *scene, struct RigidBodyWorld *rbw, bool rebuild);
 void BKE_rigidbody_objects_apply(struct Scene *scene, struct RigidBodyWorld *rbw);
+
+/* Transform Utils */
+
 void BKE_rigidbody_object_aftertrans_update(struct Object *ob, float loc[3], float rot[3], float quat[4], float rotAxis[3], float rotAngle);
 void BKE_rigidbody_object_apply_transforms(struct RigidBodyWorld *rbw, struct Object *ob, float ctime);
 
+/* Object Data Management */
+
+struct RigidBodyOb *BKE_rigidbody_create_object(struct Scene *scene, struct Object *ob, short type);
+void BKE_rigidbody_remove_object(struct Scene *scene, struct Object *ob);
+void BKE_rigidbody_free_object(struct Object *ob);
+struct RigidBodyOb *BKE_rigidbody_copy_object(struct Object *ob);
+
+struct RigidBodyCon *BKE_rigidbody_create_constraint(struct Scene *scene, struct Object *ob, short type);
+void BKE_rigidbody_remove_constraint(struct Scene *scene, struct Object *ob);
+void BKE_rigidbody_free_constraint(struct Object *ob);
+struct RigidBodyCon *BKE_rigidbody_copy_constraint(struct Object *ob);
+void BKE_rigidbody_relink_constraint(struct RigidBodyCon *rbc);
+
+/* Utility Macros */
+
+/* get mass of Rigid Body Object to supply to RigidBody simulators */
+#define RBO_GET_MASS(rbo) \
+	((rbo && ((rbo->type == RBO_TYPE_PASSIVE) || (rbo->flag & RBO_FLAG_KINEMATIC) || (rbo->flag & RBO_FLAG_DISABLED))) ? (0.0f) : (rbo->mass))
+/* get collision margin for Rigid Body Object, triangle mesh and cone shapes cannot embed margin, convex hull always uses custom margin */
+#define RBO_GET_MARGIN(rbo) \
+	((rbo->flag & RBO_FLAG_USE_MARGIN || rbo->shape == RB_SHAPE_CONVEXH || rbo->shape == RB_SHAPE_TRIMESH || rbo->shape == RB_SHAPE_CONE) ? (rbo->margin) : (0.04f))
+
 #endif /* __BKE_RIGIDBODY_H__ */
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index c7f563a..25276b1 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -161,103 +161,6 @@ void BKE_rigidbody_free_world(RigidBodyWorld *rbw)
 	MEM_freeN(rbw);
 }
 
-/* Free RigidBody settings and sim instances */
-void BKE_rigidbody_free_object(Object *ob)
-{
-	RigidBodyOb *rbo = (ob) ? ob->rigidbody_object : NULL;
-
-	/* sanity check */
-	if (rbo == NULL)
-		return;
-
-	/* free physics references */
-	if (rbo->physics_object) {
-		rbo->physics_object = NULL;
-	}
-
-	if (rbo->physics_shape) {
-		RB_shape_delete(rbo->physics_shape);
-		rbo->physics_shape = NULL;
-	}
-
-	/* free data itself */
-	MEM_freeN(rbo);
-	ob->rigidbody_object = NULL;
-}
-
-/* Free RigidBody constraint and sim instance */
-void BKE_rigidbody_free_constraint(Object *ob)
-{
-	RigidBodyCon *rbc = (ob) ? ob->rigidbody_constraint : NULL;
-
-	/* sanity check */
-	if (rbc == NULL)
-		return;
-
-	/* free physics reference */
-	if (rbc->physics_constraint) {
-		RB_constraint_delete(rbc->physics_constraint);
-		rbc->physics_constraint = NULL;
-	}
-
-	/* free data itself */
-	MEM_freeN(rbc);
-	ob->rigidbody_constraint = NULL;
-}
-
-/* Copying Methods --------------------- */
-
-/* These just copy the data, clearing out references to physics objects.
- * Anything that uses them MUST verify that the copied object will
- * be added to relevant groups later...
- */
-
-RigidBodyOb *BKE_rigidbody_copy_object(Object *ob)
-{
-	RigidBodyOb *rboN = NULL;
-
-	if (ob->rigidbody_object) {
-		/* just duplicate the whole struct first (to catch all the settings) */
-		rboN = MEM_dupallocN(ob->rigidbody_object);
-
-		/* 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;
-}
-
-RigidBodyCon *BKE_rigidbody_copy_constraint(Object *ob)
-{
-	RigidBodyCon *rbcN = NULL;
-
-	if (ob->rigidbody_constraint) {
-		/* just duplicate the whole struct first (to catch all the settings) */
-		rbcN = MEM_dupallocN(ob->rigidbody_constraint);
-
-		/* tag object as needing to be verified */
-		rbcN->flag |= RBC_FLAG_NEEDS_VALIDATE;
-
-		/* clear out all the fields which need to be revalidated later */
-		rbcN->physics_constraint = NULL;
-	}
-
-	/* return new copy of settings */
-	return rbcN;
-}
-
-/* preserve relationships between constraints and rigid bodies after duplication */
-void BKE_rigidbody_relink_constraint(RigidBodyCon *rbc)
-{
-	ID_NEW(rbc->ob1);
-	ID_NEW(rbc->ob2);
-}
-
 /* ************************************** */
 /* Setup Utilities - Validate Sim Instances */
 
@@ -907,122 +810,6 @@ void BKE_rigidbody_world_groups_relink(RigidBodyWorld *rbw)
 		rbw->effector_weights->group = (Group *)rbw->effector_weights->group->id.newid;
 }
 
-/* Add rigid body settings to the specified object */
-RigidBodyOb *BKE_rigidbody_create_object(Scene *scene, Object *ob, short type)
-{
-	RigidBodyOb *rbo;
-	RigidBodyWorld *rbw = scene->rigidbody_world;
-
-	/* sanity checks
-	 *	- rigidbody world must exist
-	 *	- object must exist
-	 *	- cannot add rigid body if it already exists
-	 */
-	if (ob == NULL || (ob->rigidbody_object != NULL))
-		return NULL;
-
-	/* create new settings data, and link it up */
-	rbo = MEM_callocN(sizeof(RigidBodyOb), "RigidBodyOb");
-
-	/* set default settings */
-	rbo->type = type;
-
-	rbo->mass = 1.0f;
-
-	rbo->friction = 0.5f; /* best when non-zero. 0.5 is Bullet default */
-	rbo->restitution = 0.0f; /* best when zero. 0.0 is Bullet default */
-
-	rbo->margin = 0.04f; /* 0.04 (in meters) is Bullet default */
-
-	rbo->lin_sleep_thresh = 0.4f; /* 0.4 is half of Bullet default */
-	rbo->ang_sleep_thresh = 0.5f; /* 0.5 is half of Bullet default */
-
-	rbo->lin_damping = 0.04f; /* 0.04 is game engine default */
-	rbo->ang_damping = 0.1f; /* 0.1 is game engine default */
-
-	rbo->col_groups = 1;
-
-	/* use triangle meshes for passive objects
-	 * use convex hulls for active objects since dynamic triangle meshes are very unstable
-	 */
-	if (type == RBO_TYPE_ACTIVE)
-		rbo->shape = RB_SHAPE_CONVEXH;
-	else
-		rbo->shape = RB_SHAPE_TRIMESH;
-
-	rbo->mesh_source = RBO_MESH_DEFORM;
-
-	/* set initial transform */
-	mat4_to_loc_quat(rbo->pos, rbo->orn, ob->obmat);
-
-	/* flag cache as outdated */
-	BKE_rigidbody_cache_reset(rbw);
-
-	/* return this object */
-	return rbo;
-}
-
-/* Add rigid body constraint to the specified object */
-RigidBodyCon *BKE_rigidbody_create_constraint(Scene *scene, Object *ob, short type)
-{
-	RigidBodyCon *rbc;
-	RigidBodyWorld *rbw = scene->rigidbody_world;
-
-	/* sanity checks
-	 *	- rigidbody world must exist
-	 *	- object must exist
-	 *	- cannot add constraint if it already exists
-	 */
-	if (ob == NULL || (ob->rigidbody_constraint != NULL))
-		return NULL;
-
-	/* create new settings data, and link it up */
-	rbc = MEM_callocN(sizeof(RigidBodyCon), "RigidBodyCon");
-
-	/* set default settings */
-	rbc->type = type;
-
-	rbc->ob1 = NULL;
-	rbc->ob2 = NULL;
-
-	rbc->flag |= RBC_FLAG_ENABLED;
-	rbc->flag |= RBC_FLAG_DISABLE_COLLISIONS;
-
-	rbc->breaking_threshold = 10.0f; /* no good default here, just use 10 for now */
-	rbc->num_solver_iterations = 10; /* 10 is Bullet default */
-
-	rbc->limit_lin_x_lower = -1.0f;
-	rbc->limit_lin_x_upper = 1.0f;
-	rbc->limit_lin_y_lower = -1.0f;
-	rbc->limit_lin_y_upper = 1.0f;
-	rbc->limit_lin_z_lower = -1.0f;
-	rbc->limit_lin_z_upper = 1.0f;
-	rbc->limit_ang_x_lower = -M_PI_4;
-	rbc->limit_ang_x_upper = M_PI_4;
-	rbc->limit_ang_y_lower = -M_PI_4;
-	rbc->limit_ang_y_upper = M_PI_4;
-	rbc->limit_ang_z_lower = -M_PI_4;
-	rbc->limit_ang_z_upper = M_PI_4;
-
-	rbc->spring_damping_x = 0.5f;
-	rbc->spring_damping_y = 0.5f;
-	rbc->spring_damping_z = 0.5f;
-	rbc->spring_stiffness_x = 10.0f;
-	rbc->spring_stiffness_y = 10.0f;
-	rbc->spring_stif

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list