Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/rigidbody.c
| Show All 31 Lines | |||||
| #include <stdio.h> | #include <stdio.h> | ||||
| #include <string.h> | #include <string.h> | ||||
| #include <stddef.h> | #include <stddef.h> | ||||
| #include <float.h> | #include <float.h> | ||||
| #include <math.h> | #include <math.h> | ||||
| #include <limits.h> | #include <limits.h> | ||||
| #include "CLG_log.h" | |||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #include "BLI_math.h" | #include "BLI_math.h" | ||||
| #ifdef WITH_BULLET | #ifdef WITH_BULLET | ||||
| # include "RBI_api.h" | # include "RBI_api.h" | ||||
| #endif | #endif | ||||
| Show All 20 Lines | |||||
| # include "BKE_global.h" | # include "BKE_global.h" | ||||
| # include "BKE_library.h" | # include "BKE_library.h" | ||||
| # include "BKE_library_query.h" | # include "BKE_library_query.h" | ||||
| #endif | #endif | ||||
| #include "DEG_depsgraph.h" | #include "DEG_depsgraph.h" | ||||
| #include "DEG_depsgraph_query.h" | #include "DEG_depsgraph_query.h" | ||||
| #ifdef WITH_BULLET | |||||
| static CLG_LogRef LOG = {"bke.rigidbody"}; | |||||
| #endif | |||||
| /* ************************************** */ | /* ************************************** */ | ||||
| /* Memory Management */ | /* Memory Management */ | ||||
| /* Freeing Methods --------------------- */ | /* Freeing Methods --------------------- */ | ||||
| #ifdef WITH_BULLET | #ifdef WITH_BULLET | ||||
| static void rigidbody_update_ob_array(RigidBodyWorld *rbw); | static void rigidbody_update_ob_array(RigidBodyWorld *rbw); | ||||
| ▲ Show 20 Lines • Show All 202 Lines • ▼ Show 20 Lines | static rbCollisionShape *rigidbody_get_shape_convexhull_from_mesh(Object *ob, float margin, bool *can_embed) | ||||
| int totvert = 0; | int totvert = 0; | ||||
| if (ob->type == OB_MESH && ob->data) { | if (ob->type == OB_MESH && ob->data) { | ||||
| mesh = rigidbody_get_mesh(ob); | mesh = rigidbody_get_mesh(ob); | ||||
| mvert = (mesh) ? mesh->mvert : NULL; | mvert = (mesh) ? mesh->mvert : NULL; | ||||
| totvert = (mesh) ? mesh->totvert : 0; | totvert = (mesh) ? mesh->totvert : 0; | ||||
| } | } | ||||
| else { | else { | ||||
| printf("ERROR: cannot make Convex Hull collision shape for non-Mesh object\n"); | CLOG_ERROR(&LOG, "cannot make Convex Hull collision shape for non-Mesh object"); | ||||
| } | } | ||||
| if (totvert) { | if (totvert) { | ||||
| shape = RB_shape_new_convex_hull((float *)mvert, sizeof(MVert), totvert, margin, can_embed); | shape = RB_shape_new_convex_hull((float *)mvert, sizeof(MVert), totvert, margin, can_embed); | ||||
| } | } | ||||
| else { | else { | ||||
| printf("ERROR: no vertices to define Convex Hull collision shape with\n"); | CLOG_ERROR(&LOG, "no vertices to define Convex Hull collision shape with"); | ||||
| } | } | ||||
| return shape; | return shape; | ||||
| } | } | ||||
| /* create collision shape of mesh - triangulated mesh | /* create collision shape of mesh - triangulated mesh | ||||
| * returns NULL if creation fails. | * returns NULL if creation fails. | ||||
| */ | */ | ||||
| Show All 18 Lines | if (ob->type == OB_MESH) { | ||||
| mvert = mesh->mvert; | mvert = mesh->mvert; | ||||
| totvert = mesh->totvert; | totvert = mesh->totvert; | ||||
| looptri = BKE_mesh_runtime_looptri_ensure(mesh); | looptri = BKE_mesh_runtime_looptri_ensure(mesh); | ||||
| tottri = mesh->runtime.looptris.len; | tottri = mesh->runtime.looptris.len; | ||||
| mloop = mesh->mloop; | mloop = mesh->mloop; | ||||
| /* sanity checking - potential case when no data will be present */ | /* sanity checking - potential case when no data will be present */ | ||||
| if ((totvert == 0) || (tottri == 0)) { | if ((totvert == 0) || (tottri == 0)) { | ||||
| printf("WARNING: no geometry data converted for Mesh Collision Shape (ob = %s)\n", ob->id.name + 2); | CLOG_WARN(&LOG, "no geometry data converted for Mesh Collision Shape (ob = %s)", ob->id.name + 2); | ||||
| } | } | ||||
| else { | else { | ||||
| rbMeshData *mdata; | rbMeshData *mdata; | ||||
| int i; | int i; | ||||
| /* init mesh data for collision shape */ | /* init mesh data for collision shape */ | ||||
| mdata = RB_trimesh_data_new(tottri, totvert); | mdata = RB_trimesh_data_new(tottri, totvert); | ||||
| Show All 31 Lines | else { | ||||
| shape = RB_shape_new_trimesh(mdata); | shape = RB_shape_new_trimesh(mdata); | ||||
| } | } | ||||
| else { | else { | ||||
| shape = RB_shape_new_gimpact_mesh(mdata); | shape = RB_shape_new_gimpact_mesh(mdata); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| printf("ERROR: cannot make Triangular Mesh collision shape for non-Mesh object\n"); | CLOG_ERROR(&LOG, "cannot make Triangular Mesh collision shape for non-Mesh object"); | ||||
| } | } | ||||
| return shape; | return shape; | ||||
| } | } | ||||
| /* Create new physics sim collision shape for object and store it, | /* Create new physics sim collision shape for object and store it, | ||||
| * or remove the existing one first and replace... | * or remove the existing one first and replace... | ||||
| */ | */ | ||||
| ▲ Show 20 Lines • Show All 1,450 Lines • Show Last 20 Lines | |||||