[Bf-blender-cvs] [9d8dcff] temp_bullet_ghosts: API for compound collision shapes in the Blender RigidBody module.

Lukas Tönne noreply at git.blender.org
Wed Apr 29 09:08:03 CEST 2015


Commit: 9d8dcff46cd6cb35a9f3cfdca4190d5d0d1c1a0e
Author: Lukas Tönne
Date:   Wed Dec 31 14:32:30 2014 +0100
Branches: temp_bullet_ghosts
https://developer.blender.org/rB9d8dcff46cd6cb35a9f3cfdca4190d5d0d1c1a0e

API for compound collision shapes in the Blender RigidBody module.

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

M	intern/rigidbody/RBI_api.h
M	intern/rigidbody/rb_bullet_api.cpp

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

diff --git a/intern/rigidbody/RBI_api.h b/intern/rigidbody/RBI_api.h
index 607617c..1928230 100644
--- a/intern/rigidbody/RBI_api.h
+++ b/intern/rigidbody/RBI_api.h
@@ -262,6 +262,17 @@ rbCollisionShape *RB_shape_new_trimesh(rbMeshData *mesh);
 /* 2b - GImpact Meshes */
 rbCollisionShape *RB_shape_new_gimpact_mesh(rbMeshData *mesh);
 
+/* Setup (Compound) ---------- */
+
+rbCollisionShape *RB_shape_new_compound(bool enable_dynamic_aabb_tree);
+void RB_shape_compound_add_child_shape(rbCollisionShape *shape, const float loc[3], const float rot[4], rbCollisionShape *child);
+int RB_shape_compound_get_num_child_shapes(rbCollisionShape *shape);
+rbCollisionShape *RB_shape_compound_get_child_shape(rbCollisionShape *shape, int index);
+void RB_shape_compound_get_child_transform(rbCollisionShape *shape, int index, float mat[4][4]);
+/* Note: after updating transforms, RB_shape_compound_update_local_aabb should be called! */
+void RB_shape_compound_set_child_transform(rbCollisionShape *shape, int index, const float loc[3], const float rot[4]);
+void RB_shape_compound_update_local_aabb(rbCollisionShape *shape);
+
 
 /* Cleanup --------------------------- */
 
diff --git a/intern/rigidbody/rb_bullet_api.cpp b/intern/rigidbody/rb_bullet_api.cpp
index fc264f6..de9f7bb 100644
--- a/intern/rigidbody/rb_bullet_api.cpp
+++ b/intern/rigidbody/rb_bullet_api.cpp
@@ -896,6 +896,70 @@ rbCollisionShape *RB_shape_new_gimpact_mesh(rbMeshData *mesh)
 	return shape;
 }
 
+/* Setup (Compound) ---------- */
+
+rbCollisionShape *RB_shape_new_compound(bool enable_dynamic_aabb_tree)
+{
+	rbCollisionShape *shape = new rbCollisionShape;
+	shape->cshape = new btCompoundShape(enable_dynamic_aabb_tree);
+	shape->mesh = NULL;
+	return shape;
+}
+
+void RB_shape_compound_add_child_shape(rbCollisionShape *shape, const float loc[3], const float rot[4], rbCollisionShape *child)
+{
+	assert(shape->cshape->getShapeType() == COMPOUND_SHAPE_PROXYTYPE);
+	btCompoundShape *cshape = static_cast<btCompoundShape *>(shape->cshape);
+	
+	btTransform trans(btQuaternion(rot[1], rot[2], rot[3], rot[0]), btVector3(loc[0], loc[1], loc[2]));
+	cshape->addChildShape(trans, child->cshape);
+}
+
+int RB_shape_compound_get_num_child_shapes(rbCollisionShape *shape)
+{
+	assert(shape->cshape->getShapeType() == COMPOUND_SHAPE_PROXYTYPE);
+	btCompoundShape *cshape = static_cast<btCompoundShape *>(shape->cshape);
+	
+	return cshape->getNumChildShapes();
+}
+
+rbCollisionShape *RB_shape_compound_get_child_shape(rbCollisionShape *shape, int index)
+{
+	assert(shape->cshape->getShapeType() == COMPOUND_SHAPE_PROXYTYPE);
+	btCompoundShape *cshape = static_cast<btCompoundShape *>(shape->cshape);
+	
+	/* rbCollisionShape is just a typedef */
+	return reinterpret_cast<rbCollisionShape *>(cshape->getChildShape(index));
+}
+
+void RB_shape_compound_get_child_transform(rbCollisionShape *shape, int index, float mat[4][4])
+{
+	assert(shape->cshape->getShapeType() == COMPOUND_SHAPE_PROXYTYPE);
+	btCompoundShape *cshape = static_cast<btCompoundShape *>(shape->cshape);
+	
+	const btTransform &trans = cshape->getChildTransform(index);
+	trans.getOpenGLMatrix((btScalar *)mat);
+}
+
+void RB_shape_compound_set_child_transform(rbCollisionShape *shape, int index, const float loc[3], const float rot[4])
+{
+	assert(shape->cshape->getShapeType() == COMPOUND_SHAPE_PROXYTYPE);
+	btCompoundShape *cshape = static_cast<btCompoundShape *>(shape->cshape);
+	
+	btTransform trans(btQuaternion(rot[1], rot[2], rot[3], rot[0]), btVector3(loc[0], loc[1], loc[2]));
+	/* no AABB update at this point, callers must do this explicitly after updating transforms */
+	cshape->updateChildTransform(index, trans, false);
+}
+
+void RB_shape_compound_update_local_aabb(rbCollisionShape *shape)
+{
+	assert(shape->cshape->getShapeType() == COMPOUND_SHAPE_PROXYTYPE);
+	btCompoundShape *cshape = static_cast<btCompoundShape *>(shape->cshape);
+	
+	cshape->recalculateLocalAabb();
+}
+
+
 /* Cleanup --------------------------- */
 
 void RB_shape_delete(rbCollisionShape *shape)




More information about the Bf-blender-cvs mailing list