Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/rigidbody.c
| Show First 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | |||||
| if (mesh == NULL) { | if (mesh == NULL) { | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| const float(*positions)[3] = BKE_mesh_vert_positions(mesh); | const float(*positions)[3] = BKE_mesh_vert_positions(mesh); | ||||
| totvert = mesh->totvert; | totvert = mesh->totvert; | ||||
| looptri = BKE_mesh_runtime_looptri_ensure(mesh); | looptri = BKE_mesh_runtime_looptri_ensure(mesh); | ||||
| tottri = BKE_mesh_runtime_looptri_len(mesh); | tottri = BKE_mesh_runtime_looptri_len(mesh); | ||||
| const MLoop *mloop = BKE_mesh_loops(mesh); | const int *corner_verts = BKE_mesh_corner_verts(mesh); | ||||
| /* 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)) { | ||||
| CLOG_WARN( | CLOG_WARN( | ||||
| &LOG, "no geometry data converted for Mesh Collision Shape (ob = %s)", ob->id.name + 2); | &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); | ||||
| RB_trimesh_add_vertices(mdata, (float *)positions, totvert, sizeof(float[3])); | RB_trimesh_add_vertices(mdata, (float *)positions, totvert, sizeof(float[3])); | ||||
| /* loop over all faces, adding them as triangles to the collision shape | /* loop over all faces, adding them as triangles to the collision shape | ||||
| * (so for some faces, more than triangle will get added) | * (so for some faces, more than triangle will get added) | ||||
| */ | */ | ||||
| if (positions && looptri) { | if (positions && looptri) { | ||||
| for (i = 0; i < tottri; i++) { | for (i = 0; i < tottri; i++) { | ||||
| /* add first triangle - verts 1,2,3 */ | /* add first triangle - verts 1,2,3 */ | ||||
| const MLoopTri *lt = &looptri[i]; | const MLoopTri *lt = &looptri[i]; | ||||
| int vtri[3]; | int vtri[3]; | ||||
| vtri[0] = mloop[lt->tri[0]].v; | vtri[0] = corner_verts[lt->tri[0]]; | ||||
| vtri[1] = mloop[lt->tri[1]].v; | vtri[1] = corner_verts[lt->tri[1]]; | ||||
| vtri[2] = mloop[lt->tri[2]].v; | vtri[2] = corner_verts[lt->tri[2]]; | ||||
| RB_trimesh_add_triangle_indices(mdata, i, UNPACK3(vtri)); | RB_trimesh_add_triangle_indices(mdata, i, UNPACK3(vtri)); | ||||
| } | } | ||||
| } | } | ||||
| RB_trimesh_finish(mdata); | RB_trimesh_finish(mdata); | ||||
| /* construct collision shape | /* construct collision shape | ||||
| ▲ Show 20 Lines • Show All 184 Lines • ▼ Show 20 Lines | |||||
| if (mesh == NULL) { | if (mesh == NULL) { | ||||
| return; | return; | ||||
| } | } | ||||
| const float(*positions)[3] = BKE_mesh_vert_positions(mesh); | const float(*positions)[3] = BKE_mesh_vert_positions(mesh); | ||||
| totvert = mesh->totvert; | totvert = mesh->totvert; | ||||
| lt = BKE_mesh_runtime_looptri_ensure(mesh); | lt = BKE_mesh_runtime_looptri_ensure(mesh); | ||||
| tottri = BKE_mesh_runtime_looptri_len(mesh); | tottri = BKE_mesh_runtime_looptri_len(mesh); | ||||
| const MLoop *mloop = BKE_mesh_loops(mesh); | const int *corner_verts = BKE_mesh_corner_verts(mesh); | ||||
| if (totvert > 0 && tottri > 0) { | if (totvert > 0 && tottri > 0) { | ||||
| BKE_mesh_calc_volume(positions, totvert, lt, tottri, mloop, &volume, NULL); | BKE_mesh_calc_volume(positions, totvert, lt, tottri, corner_verts, &volume, NULL); | ||||
| const float volume_scale = mat4_to_volume_scale(ob->object_to_world); | const float volume_scale = mat4_to_volume_scale(ob->object_to_world); | ||||
| volume *= fabsf(volume_scale); | volume *= fabsf(volume_scale); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| /* rough estimate from boundbox as fallback */ | /* rough estimate from boundbox as fallback */ | ||||
| /* XXX could implement other types of geometry here (curves, etc.) */ | /* XXX could implement other types of geometry here (curves, etc.) */ | ||||
| volume = size[0] * size[1] * size[2]; | volume = size[0] * size[1] * size[2]; | ||||
| ▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | |||||
| if (mesh == NULL) { | if (mesh == NULL) { | ||||
| return; | return; | ||||
| } | } | ||||
| const float(*positions)[3] = BKE_mesh_vert_positions(mesh); | const float(*positions)[3] = BKE_mesh_vert_positions(mesh); | ||||
| totvert = mesh->totvert; | totvert = mesh->totvert; | ||||
| looptri = BKE_mesh_runtime_looptri_ensure(mesh); | looptri = BKE_mesh_runtime_looptri_ensure(mesh); | ||||
| tottri = BKE_mesh_runtime_looptri_len(mesh); | tottri = BKE_mesh_runtime_looptri_len(mesh); | ||||
| const MLoop *mloop = BKE_mesh_loops(mesh); | |||||
| if (totvert > 0 && tottri > 0) { | if (totvert > 0 && tottri > 0) { | ||||
| BKE_mesh_calc_volume(positions, totvert, looptri, tottri, mloop, NULL, r_center); | BKE_mesh_calc_volume( | ||||
| positions, totvert, looptri, tottri, BKE_mesh_corner_verts(mesh), NULL, r_center); | |||||
| } | } | ||||
| } | } | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* --------------------- */ | /* --------------------- */ | ||||
| ▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines | |||||