[Bf-blender-cvs] [16cddb290e2] soc-2021-simulation-display: Physics: enabled drawing for convex hull collision shape and corrected scale of compound child shapes
soumya pochiraju
noreply at git.blender.org
Sun Jul 4 10:37:39 CEST 2021
Commit: 16cddb290e28cb1c14b52985207f38600f7b6f9d
Author: soumya pochiraju
Date: Sun Jul 4 12:16:58 2021 +0530
Branches: soc-2021-simulation-display
https://developer.blender.org/rB16cddb290e28cb1c14b52985207f38600f7b6f9d
Physics: enabled drawing for convex hull collision shape and corrected scale of compound child shapes
===================================================================
M intern/rigidbody/rb_bullet_api.cpp
M release/datafiles/locale
M release/scripts/addons
M release/scripts/addons_contrib
M source/blender/blenkernel/intern/rigidbody.c
M source/blender/draw/engines/overlay/overlay_extra.c
M source/blender/draw/engines/overlay/overlay_private.h
M source/blender/draw/intern/draw_cache.c
M source/blender/draw/intern/draw_cache.h
M source/blender/makesdna/DNA_rigidbody_types.h
M source/tools
===================================================================
diff --git a/intern/rigidbody/rb_bullet_api.cpp b/intern/rigidbody/rb_bullet_api.cpp
index cf079653678..425f65b346d 100644
--- a/intern/rigidbody/rb_bullet_api.cpp
+++ b/intern/rigidbody/rb_bullet_api.cpp
@@ -240,7 +240,6 @@ void RB_dworld_get_impulse(rbDynamicsWorld *world,
btManifoldPoint &pt = contactManifold->getContactPoint(j);
if (pt.getAppliedImpulse() > 0.f || -pt.getAppliedImpulse() > 0.f) {
num_impulse_points++;
- printf("getApplied:%f\n",pt.getAppliedImpulse());
}
}
@@ -938,6 +937,10 @@ rbCollisionShape *RB_shape_new_gimpact_mesh(rbMeshData *mesh)
return shape;
}
+void RB_mesh_collision_shape_draw_data(rbCollisionShape *shape) {
+
+}
+
/* Compound Shape ---------------- */
rbCollisionShape *RB_shape_new_compound()
diff --git a/release/datafiles/locale b/release/datafiles/locale
index 5ab29b1331d..78591466c33 160000
--- a/release/datafiles/locale
+++ b/release/datafiles/locale
@@ -1 +1 @@
-Subproject commit 5ab29b1331d2103dae634b987f121c4599459d7f
+Subproject commit 78591466c335ab055e11729d8af814ce7ce6edc9
diff --git a/release/scripts/addons b/release/scripts/addons
index 437ce51ab70..9fa75c889fb 160000
--- a/release/scripts/addons
+++ b/release/scripts/addons
@@ -1 +1 @@
-Subproject commit 437ce51ab70d18668b699883299ff82d9ed5f4e7
+Subproject commit 9fa75c889fb54651c83c73563397dd8c8c828443
diff --git a/release/scripts/addons_contrib b/release/scripts/addons_contrib
index 7d78c8a63f2..fd1bed98c9e 160000
--- a/release/scripts/addons_contrib
+++ b/release/scripts/addons_contrib
@@ -1 +1 @@
-Subproject commit 7d78c8a63f2f4b146f9327ddc0d567a5921b94ea
+Subproject commit fd1bed98c9e0a733451168eecc828cce460205d4
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index 5f53d198201..d25a0667540 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -38,6 +38,7 @@
#ifdef WITH_BULLET
# include "RBI_api.h"
+# include "RBI_hull_api.h"
#endif
#include "DNA_ID.h"
@@ -400,6 +401,67 @@ static rbCollisionShape *rigidbody_get_shape_convexhull_from_mesh(Object *ob,
return shape;
}
+static void rigidbody_store_convex_hull_draw_data(Object *ob) {
+ Mesh *hull_draw_data;
+
+ Mesh *mesh = NULL;
+ MVert *mvert = NULL;
+ int totvert = 0;
+
+ if (ob->type == OB_MESH && ob->data) {
+ mesh = rigidbody_get_mesh(ob);
+ mvert = (mesh) ? mesh->mvert : NULL;
+ totvert = (mesh) ? mesh->totvert : 0;
+ }
+ else {
+ CLOG_ERROR(&LOG, "cannot make Convex Hull collision shape for non-Mesh object");
+ }
+ float (*verts)[3] = MEM_malloc_arrayN(totvert, sizeof(float)*3, __func__);
+ for(int i=0; i<totvert; i++){
+ copy_v3_v3(verts[i], mvert[i].co);
+ }
+
+ plConvexHull hull = plConvexHullCompute((float(*)[3])verts, totvert);
+ free(verts);
+ const int num_verts = plConvexHullNumVertices(hull);
+ const int num_faces = num_verts <= 2 ? 0 : plConvexHullNumFaces(hull);
+ const int num_loops = num_verts <= 2 ? 0 : plConvexHullNumLoops(hull);
+
+ const int num_edges = num_verts == 2 ? 1 : num_verts < 2 ? 0 : num_loops / 2;
+ hull_draw_data = BKE_mesh_new_nomain(num_verts, num_edges, 0, num_loops, num_faces);
+
+ for (int i=0; i<num_verts; i++) {
+ float co[3];
+ int original_index;
+ plConvexHullGetVertex(hull, i, co, &original_index);
+
+ if (original_index >= 0 && original_index < totvert) {
+
+ copy_v3_v3(hull_draw_data->mvert[i].co, co);
+ }
+ else {
+ BLI_assert(!"Unexpected new vertex in hull output");
+ }
+ }
+
+ uint edge_index = 0;
+ for (int i=0; i<num_loops; i++) {
+ int v_from;
+ int v_to;
+ plConvexHullGetLoop(hull, i, &v_from, &v_to);
+
+
+ if (v_from < v_to) {
+ hull_draw_data->medge[edge_index].v1 = v_from;
+ hull_draw_data->medge[edge_index].v2 = v_to;
+ hull_draw_data->medge[edge_index].flag = ME_EDGEDRAW | ME_EDGERENDER;
+ edge_index++;
+ }
+ }
+
+ ob->rigidbody_object->col_shape_draw_data = hull_draw_data;
+
+}
/* create collision shape of mesh - triangulated mesh
* returns NULL if creation fails.
*/
@@ -565,6 +627,7 @@ static rbCollisionShape *rigidbody_validate_sim_shape_helper(RigidBodyWorld *rbw
0.04f :
0.0f; /* RB_TODO ideally we shouldn't directly change the margin here */
}
+ rigidbody_store_convex_hull_draw_data(ob);
break;
case RB_SHAPE_TRIMESH:
new_shape = rigidbody_get_shape_trimesh_from_mesh(ob);
@@ -1301,6 +1364,8 @@ RigidBodyOb *BKE_rigidbody_create_object(Scene *scene, Object *ob, short type)
zero_v3(rbo->vel);
+ rbo->col_shape_draw_data = NULL;
+
/* use triangle meshes for passive objects
* use convex hulls for active objects since dynamic triangle meshes are very unstable
*/
diff --git a/source/blender/draw/engines/overlay/overlay_extra.c b/source/blender/draw/engines/overlay/overlay_extra.c
index 9d25c06f028..21986972f0f 100644
--- a/source/blender/draw/engines/overlay/overlay_extra.c
+++ b/source/blender/draw/engines/overlay/overlay_extra.c
@@ -44,6 +44,7 @@
#include "DNA_fluid_types.h"
#include "DNA_lightprobe_types.h"
#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
#include "DNA_meta_types.h"
#include "DNA_modifier_types.h"
#include "DNA_pointcache_types.h"
@@ -53,6 +54,8 @@
#include "ED_view3d.h"
+#include "GPU_batch.h"
+
#include "overlay_private.h"
#include "draw_common.h"
@@ -235,6 +238,12 @@ void OVERLAY_extra_cache_init(OVERLAY_Data *vedata)
DRW_shgroup_uniform_vec4_copy(grp_sub, "color", G_draw.block.colorLibrary);
cb->center_deselected_lib = BUF_POINT(grp_sub, format);
}
+ {
+ sh = OVERLAY_shader_uniform_color();
+ cb->collision_shape = grp = DRW_shgroup_create(sh, extra_ps);
+ DRW_shgroup_uniform_vec4_copy(grp, "color", G_draw.block.colorLibrary);
+
+ }
}
}
@@ -360,6 +369,25 @@ void OVERLAY_empty_cache_populate(OVERLAY_Data *vedata, Object *ob)
}
}
+
+static void OVERLAY_convex_hull_collision_shape(OVERLAY_ExtraCallBuffers *cb,
+ OVERLAY_Data *data,
+ Object *ob)
+{
+
+ float color[4] = {0.0f, 0.0f, 0.0f, 1.0f};
+ GPUBatch *geom = DRW_convex_hull_batch_get(ob);
+ if(geom){
+ GPUShader *sh = OVERLAY_shader_uniform_color();
+ DRWShadingGroup *grp = DRW_shgroup_create(sh, data->psl->extra_ps[0]);
+ DRW_shgroup_uniform_vec4_copy(grp, "color", color);
+
+ DRW_shgroup_call_obmat(grp, geom, ob->obmat);
+ }
+
+
+}
+
static void OVERLAY_bounds(OVERLAY_ExtraCallBuffers *cb,
Object *ob,
const float *color,
@@ -383,6 +411,35 @@ static void OVERLAY_bounds(OVERLAY_ExtraCallBuffers *cb,
}
BKE_boundbox_calc_size_aabb(bb, size);
+ if(ob->parent) {
+ if(ob->parent->rigidbody_object) {
+ if(ob->parent->rigidbody_object->shape == RB_SHAPE_COMPOUND) {
+ float transform_mat[4][4];
+ float ob_size[3];
+ float parent_size[3];
+ mat4_to_size(ob_size, ob->obmat);
+ mat4_to_size(parent_size, ob->parent->obmat);
+ float transformed_obmat[4][4];
+ copy_m4_m4(transformed_obmat, ob->parent->obmat);
+ for(int i=0; i<3; i++){
+ for(int j=0; j<3; j++){
+ transformed_obmat[i][j] = transformed_obmat[i][j] * (ob_size[j]/parent_size[j]);
+ }
+ }
+ copy_m4_m4(transform_mat, ob->parent->obmat);
+ invert_m4(transform_mat);
+ mul_m4_m4m4(transform_mat, transform_mat, transformed_obmat);
+ /* This is the transform that is given to bullet while creating the collisions shapes,
+ * so the extra scale factor that is applied to the collision shape
+ * should be extracted from the same matrix. */
+ invert_m4(transform_mat);
+
+ mat4_to_size(parent_size, transform_mat);
+ copy_v3_v3(size, parent_size);
+
+ }
+ }
+ }
if (around_origin) {
zero_v3(center);
@@ -446,7 +503,7 @@ static void OVERLAY_bounds(OVERLAY_ExtraCallBuffers *cb,
copy_m4_m4(mat, tmp);
}
-static void OVERLAY_collision(OVERLAY_ExtraCallBuffers *cb, Object *ob, const float *color)
+static void OVERLAY_collision(OVERLAY_ExtraCallBuffers *cb, OVERLAY_Data *data, Object *ob, const float *color)
{
switch (ob->rigidbody_object->shape) {
case RB_SHAPE_BOX:
@@ -464,6 +521,8 @@ static void OVERLAY_collision(OVERLAY_ExtraCallBuffers *cb, Object *ob, const fl
case RB_SHAPE_CAPSULE:
OVERLAY_bounds(cb, ob, color, OB_BOUND_CAPSULE, true, NULL);
break;
+ case RB_SHAPE_CONVEXH:
+ OVERLAY_convex_hull_collision_shape(cb, data, ob);
}
}
@@ -2047,7 +2106,7 @@ void OVERLAY_extra_cache_populate(OVERLAY_Data *vedata, Object *ob)
OVERLAY_indicate_collision(vedata, ob);
}
else {
- OVERLAY_collision(cb, ob, color);
+ OVERLAY_collision(cb, vedata, ob, color);
}
#ifdef WITH_BULLET
if (ob->rigidbody_object->sim_display_options & RB_SIM_FORCES)
diff --git a/source/blender/draw/engines/overlay/overlay_private.h b/source/blender/draw/engines/overlay/overlay_private.h
index ec73aa5d7ac..4ffdf9bd246 100644
--- a/source/blender/draw/engines/overlay/overlay_private.h
+++ b/source/blender/draw/engines/overlay/overlay_private.h
@@ -211,6 +211,7 @@ typedef struct OVERLAY_ExtraCallBuffers {
DRWCallBuffer *speaker;
+ DRWShadingGroup *collision_shape;
DRWShadingGroup *extra_wire;
DRWShadingGroup *extra_loose_points;
} OVERLAY_ExtraCallBuffers;
diff --git a/source/blender/draw/intern/draw_cache.c b/source/blender/draw/intern/draw_cache.c
index d55da3ed83b..25791b862e7 100644
--- a/source/blender/draw/intern/draw_cache.c
+++ b/source/blender/draw/intern/draw_cache.c
@@ -22,11 +22,13 @@
#include "DNA_hair_types.h"
#include "DNA_lattice_types.h"
#include "DN
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list