Commit: 1aa54d4921c2e8d7114f463a940c169ee573f557 Author: Sebastian Parborg Date: Wed Sep 2 14:14:47 2020 +0200 Branches: master https://developer.blender.org/rB1aa54d4921c2e8d7114f463a940c169ee573f557
Make rigidbody simulation handle animated objects gracefully The animated objects was not updated for each internal substep for the rigidbody sim. This would lead to unstable simulations or very annoying clipping artifacts. Updated the code to use explicit substeps and tie it to the scene frame rate. Fix T47402: Properly updating the animated objects fixes the reported issue. Reviewed By: Brecht, Jacques Differential Revision: http://developer.blender.org/D8762 =================================================================== M extern/bullet2/CMakeLists.txt M intern/rigidbody/CMakeLists.txt M intern/rigidbody/RBI_api.h A intern/rigidbody/RBI_hull_api.h M intern/rigidbody/rb_bullet_api.cpp A intern/rigidbody/rb_convex_hull_api.cpp M release/scripts/startup/bl_ui/properties_scene.py M source/blender/blenkernel/CMakeLists.txt M source/blender/blenkernel/intern/rigidbody.c M source/blender/blenlib/BLI_math_vector.h M source/blender/blenlib/intern/math_vector_inline.c M source/blender/blenloader/intern/versioning_290.c M source/blender/bmesh/CMakeLists.txt M source/blender/bmesh/operators/bmo_hull.c M source/blender/makesdna/DNA_rigidbody_types.h M source/blender/makesdna/intern/dna_rename_defs.h M source/blender/makesrna/intern/rna_rigidbody.c M source/blender/modifiers/CMakeLists.txt =================================================================== diff --git a/extern/bullet2/CMakeLists.txt b/extern/bullet2/CMakeLists.txt index 9d0557ded7d..fd043bb9048 100644 --- a/extern/bullet2/CMakeLists.txt +++ b/extern/bullet2/CMakeLists.txt @@ -18,6 +18,19 @@ # All rights reserved. # ***** END GPL LICENSE BLOCK ***** +# avoid noisy warnings +if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang") + add_c_flag( + "-Wno-unused-result -Wno-unused-variable -Wno-unused-but-set-variable -Wno-reorder" + ) + remove_cc_flag( + "-Wmissing-declarations" + ) +endif() + +# Use double precision to make simulations of small objects stable. +add_definitions(-DBT_USE_DOUBLE_PRECISION) + set(INC . src diff --git a/intern/rigidbody/CMakeLists.txt b/intern/rigidbody/CMakeLists.txt index 77d88548e1b..91cfc312bd2 100644 --- a/intern/rigidbody/CMakeLists.txt +++ b/intern/rigidbody/CMakeLists.txt @@ -18,6 +18,8 @@ # All rights reserved. # ***** END GPL LICENSE BLOCK ***** +add_definitions(-DBT_USE_DOUBLE_PRECISION) + set(INC . ) @@ -28,7 +30,9 @@ set(INC_SYS set(SRC rb_bullet_api.cpp + rb_convex_hull_api.cpp + RBI_hull_api.h RBI_api.h ) diff --git a/intern/rigidbody/RBI_api.h b/intern/rigidbody/RBI_api.h index 07cda49e04b..2e09f8952cb 100644 --- a/intern/rigidbody/RBI_api.h +++ b/intern/rigidbody/RBI_api.h @@ -200,10 +200,12 @@ void RB_body_set_scale(rbRigidBody *body, const float scale[3]); /* ............ */ -/* Get RigidBody's position as vector */ +/* Get RigidBody's position as a vector */ void RB_body_get_position(rbRigidBody *body, float v_out[3]); -/* Get RigidBody's orientation as quaternion */ +/* Get RigidBody's orientation as a quaternion */ void RB_body_get_orientation(rbRigidBody *body, float v_out[4]); +/* Get RigidBody's local scale as a vector */ +void RB_body_get_scale(rbRigidBody *object, float v_out[3]); /* ............ */ diff --git a/intern/rigidbody/RBI_hull_api.h b/intern/rigidbody/RBI_hull_api.h new file mode 100644 index 00000000000..9d2dc5034db --- /dev/null +++ b/intern/rigidbody/RBI_hull_api.h @@ -0,0 +1,43 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2020 Blender Foundation, + * All rights reserved. + */ + +#ifndef __RB_HULL_API_H__ +#define __RB_HULL_API_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct plConvexHull__ { + int unused; +} * plConvexHull; + +plConvexHull plConvexHullCompute(float (*coords)[3], int count); +void plConvexHullDelete(plConvexHull hull); +int plConvexHullNumVertices(plConvexHull hull); +int plConvexHullNumFaces(plConvexHull hull); +void plConvexHullGetVertex(plConvexHull hull, int n, float coords[3], int *original_index); +int plConvexHullGetFaceSize(plConvexHull hull, int n); +void plConvexHullGetFaceVertices(plConvexHull hull, int n, int *vertices); + +#ifdef __cplusplus +} +#endif + +#endif /* __RB_HULL_API_H__ */ diff --git a/intern/rigidbody/rb_bullet_api.cpp b/intern/rigidbody/rb_bullet_api.cpp index b5814055cf8..daa377a7b55 100644 --- a/intern/rigidbody/rb_bullet_api.cpp +++ b/intern/rigidbody/rb_bullet_api.cpp @@ -649,6 +649,16 @@ void RB_body_get_orientation(rbRigidBody *object, float v_out[4]) copy_quat_btquat(v_out, body->getWorldTransform().getRotation()); } +void RB_body_get_scale(rbRigidBody *object, float v_out[3]) +{ + btRigidBody *body = object->body; + + btCollisionShape *cshape = body->getCollisionShape(); + /* The body should have a collision shape when we try to set the scale. */ + btAssert(cshape); + copy_v3_btvec3(v_out, cshape->getLocalScaling()); +} + /* ............ */ /* Overrides for simulation */ diff --git a/intern/rigidbody/rb_convex_hull_api.cpp b/intern/rigidbody/rb_convex_hull_api.cpp new file mode 100644 index 00000000000..c5893a4c808 --- /dev/null +++ b/intern/rigidbody/rb_convex_hull_api.cpp @@ -0,0 +1,83 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2020 Blender Foundation, + * All rights reserved. + */ + +#include "LinearMath/btConvexHullComputer.h" +#include "RBI_hull_api.h" + +plConvexHull plConvexHullCompute(float (*coords)[3], int count) +{ + btConvexHullComputer *computer = new btConvexHullComputer; + computer->compute(reinterpret_cast<float *>(coords), sizeof(*coords), count, 0, 0); + return reinterpret_cast<plConvexHull>(computer); +} + +void plConvexHullDelete(plConvexHull hull) +{ + btConvexHullComputer *computer(reinterpret_cast<btConvexHullComputer *>(hull)); + delete computer; +} + +int plConvexHullNumVertices(plConvexHull hull) +{ + btConvexHullComputer *computer(reinterpret_cast<btConvexHullComputer *>(hull)); + return computer->vertices.size(); +} + +int plConvexHullNumFaces(plConvexHull hull) +{ + btConvexHullComputer *computer(reinterpret_cast<btConvexHullComputer *>(hull)); + return computer->faces.size(); +} + +void plConvexHullGetVertex(plConvexHull hull, int n, float coords[3], int *original_index) +{ + btConvexHullComputer *computer(reinterpret_cast<btConvexHullComputer *>(hull)); + const btVector3 &v(computer->vertices[n]); + coords[0] = v[0]; + coords[1] = v[1]; + coords[2] = v[2]; + (*original_index) = computer->original_vertex_index[n]; +} + +int plConvexHullGetFaceSize(plConvexHull hull, int n) +{ + btConvexHullComputer *computer(reinterpret_cast<btConvexHullComputer *>(hull)); + const btConvexHullComputer::Edge *e_orig, *e; + int count; + + for (e_orig = &computer->edges[computer->faces[n]], e = e_orig, count = 0; + count == 0 || e != e_orig; + e = e->getNextEdgeOfFace(), count++) { + ; + } + return count; +} + +void plConvexHullGetFaceVertices(plConvexHull hull, int n, int *vertices) +{ + btConvexHullComputer *computer(reinterpret_cast<btConvexHullComputer *>(hull)); + const btConvexHullComputer::Edge *e_orig, *e; + int count; + + for (e_orig = &computer->edges[computer->faces[n]], e = e_orig, count = 0; + count == 0 || e != e_orig; + e = e->getNextEdgeOfFace(), count++) { + vertices[count] = e->getTargetVertex(); + } +} diff --git a/release/scripts/startup/bl_ui/properties_scene.py b/release/scripts/startup/bl_ui/properties_scene.py index 22f455fe5be..df4793cab19 100644 --- a/release/scripts/startup/bl_ui/properties_scene.py +++ b/release/scripts/startup/bl_ui/properties_scene.py @@ -385,8 +385,8 @@ class SCENE_PT_rigid_body_world_settings(RigidBodySubPanel, Panel): col.prop(rbw, "use_split_impulse") col = col.column() - col.prop(rbw, "steps_per_second", text="Steps Per Second") - col.prop(rbw, "solver_iterations", text="Solver Iterations") + col.prop(rbw, "substeps_per_frame") + col.prop(rbw, "solver_iterations") class SCENE_PT_rigid_body_cache(RigidBodySubPanel, Panel): diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt index 6f32eb8a90f..bf3077b7743 100644 --- a/source/blender/blenkernel/CMakeLists.txt +++ b/source/blender/blenkernel/CMakeLists.txt @@ -482,9 +482,15 @@ if(WITH_BULLET) list(APPEND INC ../../../intern/rigidbody ) + + if(NOT WITH_SYSTEM_BULLET) + list(APPEND LIB + extern_bullet + ) + endif() + list(APPEND LIB bf_intern_rigidbody - extern_bullet ${BULLET_LIBRARIES} ) diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c index 95a8b3b3c15..00b993296d0 100644 --- a/source/blender/blenkernel/intern/rigidbody.c +++ b/source/blender/blenkernel/intern/rigidbody.c @@ -1180,7 +1180,10 @@ RigidBodyWorld *BKE_rigidbody_create_world(Scene *scene) rbw->time_scale = 1.0f; - rbw->steps_per_second = 60; /* Bullet default (60 Hz) */ + /* Most high quality Bullet example files has an internal framerate of 240hz. + * The blender default scene has a frame rate of 24, so take 10 substeps (24fps * 10). + */ + rbw->substeps_per_frame = 10; rbw->num_solver_iterations = 10; /* 10 is bullet default */ rbw->shared->pointcache = BKE_ptcache_add(&(rbw->shared->ptcaches)); @@ -1651,10 +1654,6 @@ static void rigidbody_update_sim_world(Scene *scene, RigidBodyWorld *rbw) static void rigidbody_update_sim_ob( Depsgraph *depsgraph, Scene *scene, RigidBodyWorld *rbw, Object *ob, RigidBodyOb *rbo) { - float loc[3]; - float rot[4]; - float scale[3]; - /* only update if rigid body exists */ if (rbo->shared->physics_object == NULL) { return; @@ -1680,14 +1679,21 @@ static void rigidbody_update_sim_ob( } } - mat4_decompose(loc, rot, scale, ob->obmat); + if (!(rbo->flag & RBO_FLAG_KINEMATIC)) { + /* update scale for all non kinematic objects */ + float new_scale[3], old_scale[3]; + mat4_to_size(new_scale, ob->obmat); + RB_body_get_scale(rbo->shared->physics_object, old_scale); - /* update scale for all objects */ - RB_body_set_scale(rbo->s @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs