Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--intern/rigidbody/RBI_api.h2
-rw-r--r--intern/rigidbody/rb_bullet_api.cpp23
-rw-r--r--release/scripts/startup/bl_ui/properties_physics_rigidbody.py3
-rw-r--r--source/blender/blenkernel/intern/rigidbody.c11
-rw-r--r--source/blender/makesdna/DNA_rigidbody_types.h4
-rw-r--r--source/blender/makesrna/intern/rna_rigidbody.c5
6 files changed, 47 insertions, 1 deletions
diff --git a/intern/rigidbody/RBI_api.h b/intern/rigidbody/RBI_api.h
index 97e8e6891ff..2e7a996781b 100644
--- a/intern/rigidbody/RBI_api.h
+++ b/intern/rigidbody/RBI_api.h
@@ -247,6 +247,8 @@ extern void RB_shape_delete(rbCollisionShape *shape);
extern float RB_shape_get_margin(rbCollisionShape *shape);
extern void RB_shape_set_margin(rbCollisionShape *shape, float value);
+extern void RB_shape_trimesh_update(rbCollisionShape *shape, float *vertices, int num_verts, int vert_stride, float min[3], float max[3]);
+
/* ********************************** */
/* Constraints */
diff --git a/intern/rigidbody/rb_bullet_api.cpp b/intern/rigidbody/rb_bullet_api.cpp
index 31f7f386663..ef35d3b257b 100644
--- a/intern/rigidbody/rb_bullet_api.cpp
+++ b/intern/rigidbody/rb_bullet_api.cpp
@@ -763,6 +763,29 @@ rbCollisionShape *RB_shape_new_trimesh(rbMeshData *mesh)
return shape;
}
+void RB_shape_trimesh_update(rbCollisionShape *shape, float *vertices, int num_verts, int vert_stride, float min[3], float max[3])
+{
+ if (shape->mesh == NULL || num_verts != shape->mesh->num_vertices)
+ return;
+
+ for (int i = 0; i < num_verts; i++) {
+ float *vert = (float*)(((char*)vertices + i * vert_stride));
+ shape->mesh->vertices[i].x = vert[0];
+ shape->mesh->vertices[i].y = vert[1];
+ shape->mesh->vertices[i].z = vert[2];
+ }
+
+ if (shape->cshape->getShapeType() == SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE) {
+ btScaledBvhTriangleMeshShape *scaled_shape = (btScaledBvhTriangleMeshShape *)shape->cshape;
+ btBvhTriangleMeshShape *mesh_shape = scaled_shape->getChildShape();
+ mesh_shape->refitTree(btVector3(min[0], min[1], min[2]), btVector3(max[0], max[1], max[2]));
+ }
+ else if (shape->cshape->getShapeType() == GIMPACT_SHAPE_PROXYTYPE) {
+ btGImpactMeshShape *mesh_shape = (btGImpactMeshShape*)shape->cshape;
+ mesh_shape->updateBound();
+ }
+}
+
rbCollisionShape *RB_shape_new_gimpact_mesh(rbMeshData *mesh)
{
rbCollisionShape *shape = new rbCollisionShape;
diff --git a/release/scripts/startup/bl_ui/properties_physics_rigidbody.py b/release/scripts/startup/bl_ui/properties_physics_rigidbody.py
index 7a6c8e0a066..5f589c499d3 100644
--- a/release/scripts/startup/bl_ui/properties_physics_rigidbody.py
+++ b/release/scripts/startup/bl_ui/properties_physics_rigidbody.py
@@ -73,6 +73,9 @@ class PHYSICS_PT_rigid_body_collisions(PHYSICS_PT_rigidbody_panel, Panel):
if rbo.collision_shape in {'MESH', 'CONVEX_HULL'}:
layout.prop(rbo, "mesh_source", text="Source")
+ if rbo.collision_shape == 'MESH' and rbo.mesh_source == 'DEFORM':
+ layout.prop(rbo, "use_deform", text="Deforming")
+
split = layout.split()
col = split.column()
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index 22126b7e45d..868fa41b5c7 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -1030,6 +1030,17 @@ static void rigidbody_update_sim_ob(Scene *scene, RigidBodyWorld *rbw, Object *o
if (rbo->physics_object == NULL)
return;
+ if (rbo->shape == RB_SHAPE_TRIMESH && rbo->flag & RBO_FLAG_USE_DEFORM) {
+ DerivedMesh *dm = ob->derivedDeform;
+ if (dm) {
+ MVert *mvert = dm->getVertArray(dm);
+ int totvert = dm->getNumVerts(dm);
+ BoundBox *bb = BKE_object_boundbox_get(ob);
+
+ RB_shape_trimesh_update(rbo->physics_shape, (float*)mvert, totvert, sizeof(MVert), bb->vec[0], bb->vec[6]);
+ }
+ }
+
mat4_decompose(loc, rot, scale, ob->obmat);
/* update scale for all objects */
diff --git a/source/blender/makesdna/DNA_rigidbody_types.h b/source/blender/makesdna/DNA_rigidbody_types.h
index de23a3c2370..5d76ffe57b5 100644
--- a/source/blender/makesdna/DNA_rigidbody_types.h
+++ b/source/blender/makesdna/DNA_rigidbody_types.h
@@ -149,7 +149,9 @@ typedef enum eRigidBodyOb_Flag {
/* rigidbody is not dynamically simulated */
RBO_FLAG_DISABLED = (1 << 5),
/* collision margin is not embedded (only used by convex hull shapes for now) */
- RBO_FLAG_USE_MARGIN = (1 << 6)
+ RBO_FLAG_USE_MARGIN = (1 << 6),
+ /* collision shape deforms during simulation (only for passive triangle mesh shapes) */
+ RBO_FLAG_USE_DEFORM = (1 << 7)
} eRigidBodyOb_Flag;
/* RigidBody Collision Shape */
diff --git a/source/blender/makesrna/intern/rna_rigidbody.c b/source/blender/makesrna/intern/rna_rigidbody.c
index 34b0f6a335a..58fc9ab25d4 100644
--- a/source/blender/makesrna/intern/rna_rigidbody.c
+++ b/source/blender/makesrna/intern/rna_rigidbody.c
@@ -804,6 +804,11 @@ static void rna_def_rigidbody_object(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Kinematic", "Allow rigid body to be controlled by the animation system");
RNA_def_property_update(prop, NC_OBJECT | ND_POINTCACHE, "rna_RigidBodyOb_reset");
+ prop = RNA_def_property(srna, "use_deform", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "flag", RBO_FLAG_USE_DEFORM);
+ RNA_def_property_ui_text(prop, "Deforming", "Rigid body deforms during simulation");
+ RNA_def_property_update(prop, NC_OBJECT | ND_POINTCACHE, "rna_RigidBodyOb_reset");
+
/* Physics Parameters */
prop = RNA_def_property(srna, "mass", PROP_FLOAT, PROP_UNIT_MASS);
RNA_def_property_float_sdna(prop, NULL, "mass");