[Bf-blender-cvs] [2e55359] temp_bullet_ghosts: "Init" variants of shape constructor functions for simple implicit shapes.

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


Commit: 2e553592ac8989c7eb8a025343a286009cacfec3
Author: Lukas Tönne
Date:   Thu Jan 1 15:26:59 2015 +0100
Branches: temp_bullet_ghosts
https://developer.blender.org/rB2e553592ac8989c7eb8a025343a286009cacfec3

"Init" variants of shape constructor functions for simple implicit
shapes.

These functions allow external memory allocation (using the associated
***_size values) for efficiency. An array or memory pool can then be
used to create lots of shapes and initialize them with the internal
Bullet data using the API.

Note that doing this for mesh-based shapes (triangle mesh, GImpact and
convex hull shapes) is not very useful, because they allocate data
internally and should not be created in massive numbers. The init
variants are supposed to be used for small fixed-size shapes (boxes,
spheres, etc.) which can then be combined into compound shapes.

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

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 b407e01..6b5b670 100644
--- a/intern/rigidbody/RBI_api.h
+++ b/intern/rigidbody/RBI_api.h
@@ -241,10 +241,24 @@ void RB_ghost_set_scale(rbGhostObject *object, const float scale[3]);
 /* Setup (Standard Shapes) ----------- */
 
 rbCollisionShape *RB_shape_new_box(float x, float y, float z);
+rbCollisionShape *RB_shape_init_box(void *mem, float x, float y, float z);
+extern const size_t RB_shape_size_box;
+
 rbCollisionShape *RB_shape_new_sphere(float radius);
+rbCollisionShape *RB_shape_init_sphere(void *mem, float radius);
+extern const size_t RB_shape_size_sphere;
+
 rbCollisionShape *RB_shape_new_capsule(float radius, float height);
+rbCollisionShape *RB_shape_init_capsule(void *mem, float radius, float height);
+extern const size_t RB_shape_size_capsule;
+
 rbCollisionShape *RB_shape_new_cone(float radius, float height);
+rbCollisionShape *RB_shape_init_cone(void *mem, float radius, float height);
+extern const size_t RB_shape_size_cone;
+
 rbCollisionShape *RB_shape_new_cylinder(float radius, float height);
+rbCollisionShape *RB_shape_init_cylinder(void *mem, float radius, float height);
+extern const size_t RB_shape_size_cylinder;
 
 /* Setup (Convex Hull) ------------ */
 
diff --git a/intern/rigidbody/rb_bullet_api.cpp b/intern/rigidbody/rb_bullet_api.cpp
index c1d170d..d4d4950 100644
--- a/intern/rigidbody/rb_bullet_api.cpp
+++ b/intern/rigidbody/rb_bullet_api.cpp
@@ -860,26 +860,61 @@ rbCollisionShape *RB_shape_new_box(float x, float y, float z)
 	return new rbBoxShape(x, y, z);
 }
 
+rbCollisionShape *RB_shape_init_box(void *mem, float x, float y, float z)
+{
+	return new (mem) rbBoxShape(x, y, z);
+}
+
+const size_t RB_shape_size_box = sizeof(rbBoxShape);
+
 rbCollisionShape *RB_shape_new_sphere(float radius)
 {
 	return new rbSphereShape(radius);
 }
 
+rbCollisionShape *RB_shape_init_sphere(void *mem, float radius)
+{
+	return new (mem) rbSphereShape(radius);
+}
+
+const size_t RB_shape_size_sphere = sizeof(rbSphereShape);
+
 rbCollisionShape *RB_shape_new_capsule(float radius, float height)
 {
 	return new rbCapsuleShape(radius, height);
 }
 
+rbCollisionShape *RB_shape_init_capsule(void *mem, float radius, float height)
+{
+	return new (mem) rbCapsuleShape(radius, height);
+}
+
+const size_t RB_shape_size_capsule = sizeof(rbCapsuleShape);
+
 rbCollisionShape *RB_shape_new_cone(float radius, float height)
 {
 	return new rbConeShape(radius, height);
 }
 
+rbCollisionShape *RB_shape_init_cone(void *mem, float radius, float height)
+{
+	return new (mem) rbConeShape(radius, height);
+}
+
+const size_t RB_shape_size_cone = sizeof(rbConeShape);
+
 rbCollisionShape *RB_shape_new_cylinder(float radius, float height)
 {
 	return new rbCylinderShape(radius, height);
 }
 
+rbCollisionShape *RB_shape_init_cylinder(void *mem, float radius, float height)
+{
+	return new (mem) rbCylinderShape(radius, height);
+}
+
+const size_t RB_shape_size_cylinder = sizeof(rbCylinderShape);
+
 /* Setup (Convex Hull) ------------ */
 
 rbCollisionShape *RB_shape_new_convex_hull(float *verts, int stride, int count, float margin, bool *can_embed)




More information about the Bf-blender-cvs mailing list