Changeset View
Changeset View
Standalone View
Standalone View
source/blender/python/mathutils/mathutils_bvhtree.c
| Show First 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | |||||
| struct Depsgraph *depsgraph; | struct Depsgraph *depsgraph; | ||||
| struct Scene *scene; | struct Scene *scene; | ||||
| Mesh *mesh; | Mesh *mesh; | ||||
| bool use_deform = true; | bool use_deform = true; | ||||
| bool use_cage = false; | bool use_cage = false; | ||||
| bool free_mesh = false; | bool free_mesh = false; | ||||
| const MLoopTri *lt; | const MLoopTri *lt; | ||||
| const MLoop *mloop; | const int *corner_verts; | ||||
| float(*coords)[3] = NULL; | float(*coords)[3] = NULL; | ||||
| uint(*tris)[3] = NULL; | uint(*tris)[3] = NULL; | ||||
| uint coords_len, tris_len; | uint coords_len, tris_len; | ||||
| float epsilon = 0.0f; | float epsilon = 0.0f; | ||||
| if (!PyArg_ParseTupleAndKeywords(args, | if (!PyArg_ParseTupleAndKeywords(args, | ||||
| kwargs, | kwargs, | ||||
| Show All 24 Lines | |||||
| tris_len = (uint)BKE_mesh_runtime_looptri_len(mesh); | tris_len = (uint)BKE_mesh_runtime_looptri_len(mesh); | ||||
| coords_len = (uint)mesh->totvert; | coords_len = (uint)mesh->totvert; | ||||
| coords = MEM_mallocN(sizeof(*coords) * (size_t)coords_len, __func__); | coords = MEM_mallocN(sizeof(*coords) * (size_t)coords_len, __func__); | ||||
| tris = MEM_mallocN(sizeof(*tris) * (size_t)tris_len, __func__); | tris = MEM_mallocN(sizeof(*tris) * (size_t)tris_len, __func__); | ||||
| memcpy(coords, BKE_mesh_vert_positions(mesh), sizeof(float[3]) * (size_t)mesh->totvert); | memcpy(coords, BKE_mesh_vert_positions(mesh), sizeof(float[3]) * (size_t)mesh->totvert); | ||||
| mloop = BKE_mesh_loops(mesh); | corner_verts = BKE_mesh_corner_verts(mesh); | ||||
| } | } | ||||
| { | { | ||||
| BVHTree *tree; | BVHTree *tree; | ||||
| uint i; | uint i; | ||||
| int *orig_index = NULL; | int *orig_index = NULL; | ||||
| float(*orig_normal)[3] = NULL; | float(*orig_normal)[3] = NULL; | ||||
| tree = BLI_bvhtree_new((int)tris_len, epsilon, PY_BVH_TREE_TYPE_DEFAULT, PY_BVH_AXIS_DEFAULT); | tree = BLI_bvhtree_new((int)tris_len, epsilon, PY_BVH_TREE_TYPE_DEFAULT, PY_BVH_AXIS_DEFAULT); | ||||
| if (tree) { | if (tree) { | ||||
| orig_index = MEM_mallocN(sizeof(*orig_index) * (size_t)tris_len, __func__); | orig_index = MEM_mallocN(sizeof(*orig_index) * (size_t)tris_len, __func__); | ||||
| if (!BKE_mesh_poly_normals_are_dirty(mesh)) { | if (!BKE_mesh_poly_normals_are_dirty(mesh)) { | ||||
| orig_normal = MEM_dupallocN(BKE_mesh_poly_normals_ensure(mesh)); | orig_normal = MEM_dupallocN(BKE_mesh_poly_normals_ensure(mesh)); | ||||
| } | } | ||||
| for (i = 0; i < tris_len; i++, lt++) { | for (i = 0; i < tris_len; i++, lt++) { | ||||
| float co[3][3]; | float co[3][3]; | ||||
| tris[i][0] = mloop[lt->tri[0]].v; | tris[i][0] = (uint)corner_verts[lt->tri[0]]; | ||||
| tris[i][1] = mloop[lt->tri[1]].v; | tris[i][1] = (uint)corner_verts[lt->tri[1]]; | ||||
| tris[i][2] = mloop[lt->tri[2]].v; | tris[i][2] = (uint)corner_verts[lt->tri[2]]; | ||||
| copy_v3_v3(co[0], coords[tris[i][0]]); | copy_v3_v3(co[0], coords[tris[i][0]]); | ||||
| copy_v3_v3(co[1], coords[tris[i][1]]); | copy_v3_v3(co[1], coords[tris[i][1]]); | ||||
| copy_v3_v3(co[2], coords[tris[i][2]]); | copy_v3_v3(co[2], coords[tris[i][2]]); | ||||
| BLI_bvhtree_insert(tree, (int)i, co[0], 3); | BLI_bvhtree_insert(tree, (int)i, co[0], 3); | ||||
| orig_index[i] = (int)lt->poly; | orig_index[i] = (int)lt->poly; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines | |||||