Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenkernel/intern/bvhutils.cc')
-rw-r--r--source/blender/blenkernel/intern/bvhutils.cc122
1 files changed, 61 insertions, 61 deletions
diff --git a/source/blender/blenkernel/intern/bvhutils.cc b/source/blender/blenkernel/intern/bvhutils.cc
index afc3e525143..bb536188c9e 100644
--- a/source/blender/blenkernel/intern/bvhutils.cc
+++ b/source/blender/blenkernel/intern/bvhutils.cc
@@ -28,6 +28,7 @@
#include "MEM_guardedalloc.h"
+using blender::float3;
using blender::Span;
using blender::VArray;
@@ -233,14 +234,14 @@ static void mesh_faces_nearest_point(void *userdata,
BVHTreeNearest *nearest)
{
const BVHTreeFromMesh *data = (BVHTreeFromMesh *)userdata;
- const MVert *vert = data->vert;
+ const float(*positions)[3] = data->positions;
const MFace *face = data->face + index;
const float *t0, *t1, *t2, *t3;
- t0 = vert[face->v1].co;
- t1 = vert[face->v2].co;
- t2 = vert[face->v3].co;
- t3 = face->v4 ? vert[face->v4].co : nullptr;
+ t0 = positions[face->v1];
+ t1 = positions[face->v2];
+ t2 = positions[face->v3];
+ t3 = face->v4 ? positions[face->v4] : nullptr;
do {
float nearest_tmp[3], dist_sq;
@@ -268,12 +269,12 @@ static void mesh_looptri_nearest_point(void *userdata,
BVHTreeNearest *nearest)
{
const BVHTreeFromMesh *data = (BVHTreeFromMesh *)userdata;
- const MVert *vert = data->vert;
+ const float(*positions)[3] = data->positions;
const MLoopTri *lt = &data->looptri[index];
const float *vtri_co[3] = {
- vert[data->loop[lt->tri[0]].v].co,
- vert[data->loop[lt->tri[1]].v].co,
- vert[data->loop[lt->tri[2]].v].co,
+ positions[data->loop[lt->tri[0]].v],
+ positions[data->loop[lt->tri[1]].v],
+ positions[data->loop[lt->tri[2]].v],
};
float nearest_tmp[3], dist_sq;
@@ -329,14 +330,14 @@ static void mesh_faces_spherecast(void *userdata,
BVHTreeRayHit *hit)
{
const BVHTreeFromMesh *data = (BVHTreeFromMesh *)userdata;
- const MVert *vert = data->vert;
+ const float(*positions)[3] = data->positions;
const MFace *face = &data->face[index];
const float *t0, *t1, *t2, *t3;
- t0 = vert[face->v1].co;
- t1 = vert[face->v2].co;
- t2 = vert[face->v3].co;
- t3 = face->v4 ? vert[face->v4].co : nullptr;
+ t0 = positions[face->v1];
+ t1 = positions[face->v2];
+ t2 = positions[face->v3];
+ t3 = face->v4 ? positions[face->v4] : nullptr;
do {
float dist;
@@ -368,12 +369,12 @@ static void mesh_looptri_spherecast(void *userdata,
BVHTreeRayHit *hit)
{
const BVHTreeFromMesh *data = (BVHTreeFromMesh *)userdata;
- const MVert *vert = data->vert;
+ const float(*positions)[3] = data->positions;
const MLoopTri *lt = &data->looptri[index];
const float *vtri_co[3] = {
- vert[data->loop[lt->tri[0]].v].co,
- vert[data->loop[lt->tri[1]].v].co,
- vert[data->loop[lt->tri[2]].v].co,
+ positions[data->loop[lt->tri[0]].v],
+ positions[data->loop[lt->tri[1]].v],
+ positions[data->loop[lt->tri[2]].v],
};
float dist;
@@ -438,13 +439,13 @@ static void mesh_edges_nearest_point(void *userdata,
BVHTreeNearest *nearest)
{
const BVHTreeFromMesh *data = (BVHTreeFromMesh *)userdata;
- const MVert *vert = data->vert;
+ const float(*positions)[3] = data->positions;
const MEdge *edge = data->edge + index;
float nearest_tmp[3], dist_sq;
const float *t0, *t1;
- t0 = vert[edge->v1].co;
- t1 = vert[edge->v2].co;
+ t0 = positions[edge->v1];
+ t1 = positions[edge->v2];
closest_to_line_segment_v3(nearest_tmp, co, t0, t1);
dist_sq = len_squared_v3v3(nearest_tmp, co);
@@ -503,7 +504,7 @@ static void mesh_verts_spherecast(void *userdata,
BVHTreeRayHit *hit)
{
const BVHTreeFromMesh *data = (BVHTreeFromMesh *)userdata;
- const float *v = data->vert[index].co;
+ const float *v = data->positions[index];
mesh_verts_spherecast_do(index, v, ray, hit);
}
@@ -520,15 +521,15 @@ static void mesh_edges_spherecast(void *userdata,
BVHTreeRayHit *hit)
{
const BVHTreeFromMesh *data = (BVHTreeFromMesh *)userdata;
- const MVert *vert = data->vert;
+ const float(*positions)[3] = data->positions;
const MEdge *edge = &data->edge[index];
const float radius_sq = square_f(ray->radius);
float dist;
const float *v1, *v2, *r1;
float r2[3], i1[3], i2[3];
- v1 = vert[edge->v1].co;
- v2 = vert[edge->v2].co;
+ v1 = positions[edge->v1];
+ v2 = positions[edge->v2];
/* In case we get a zero-length edge, handle it as a point! */
if (equals_v3v3(v1, v2)) {
@@ -571,7 +572,7 @@ static void mesh_edges_spherecast(void *userdata,
static void bvhtree_from_mesh_setup_data(BVHTree *tree,
const BVHCacheType bvh_cache_type,
- const MVert *vert,
+ const float (*positions)[3],
const MEdge *edge,
const MFace *face,
const MLoop *loop,
@@ -583,7 +584,7 @@ static void bvhtree_from_mesh_setup_data(BVHTree *tree,
r_data->tree = tree;
- r_data->vert = vert;
+ r_data->positions = reinterpret_cast<const float(*)[3]>(positions);
r_data->edge = edge;
r_data->face = face;
r_data->loop = loop;
@@ -701,7 +702,7 @@ static BVHTree *bvhtree_from_editmesh_verts_create_tree(float epsilon,
static BVHTree *bvhtree_from_mesh_verts_create_tree(float epsilon,
int tree_type,
int axis,
- const MVert *vert,
+ const float (*positions)[3],
const int verts_num,
const BLI_bitmap *verts_mask,
int verts_num_active)
@@ -723,7 +724,7 @@ static BVHTree *bvhtree_from_mesh_verts_create_tree(float epsilon,
if (verts_mask && !BLI_BITMAP_TEST_BOOL(verts_mask, i)) {
continue;
}
- BLI_bvhtree_insert(tree, i, vert[i].co, 1);
+ BLI_bvhtree_insert(tree, i, positions[i], 1);
}
BLI_assert(BLI_bvhtree_get_len(tree) == verts_num_active);
}
@@ -760,7 +761,7 @@ BVHTree *bvhtree_from_editmesh_verts(
}
BVHTree *bvhtree_from_mesh_verts_ex(BVHTreeFromMesh *data,
- const MVert *vert,
+ const float (*positions)[3],
const int verts_num,
const BLI_bitmap *verts_mask,
int verts_num_active,
@@ -770,14 +771,14 @@ BVHTree *bvhtree_from_mesh_verts_ex(BVHTreeFromMesh *data,
{
BVHTree *tree = nullptr;
tree = bvhtree_from_mesh_verts_create_tree(
- epsilon, tree_type, axis, vert, verts_num, verts_mask, verts_num_active);
+ epsilon, tree_type, axis, positions, verts_num, verts_mask, verts_num_active);
bvhtree_balance(tree, false);
if (data) {
/* Setup BVHTreeFromMesh */
bvhtree_from_mesh_setup_data(
- tree, BVHTREE_FROM_VERTS, vert, nullptr, nullptr, nullptr, nullptr, nullptr, data);
+ tree, BVHTREE_FROM_VERTS, positions, nullptr, nullptr, nullptr, nullptr, nullptr, data);
}
return tree;
@@ -828,7 +829,7 @@ static BVHTree *bvhtree_from_editmesh_edges_create_tree(float epsilon,
return tree;
}
-static BVHTree *bvhtree_from_mesh_edges_create_tree(const MVert *vert,
+static BVHTree *bvhtree_from_mesh_edges_create_tree(const float (*positions)[3],
const MEdge *edge,
const int edge_num,
const BLI_bitmap *edges_mask,
@@ -855,8 +856,8 @@ static BVHTree *bvhtree_from_mesh_edges_create_tree(const MVert *vert,
continue;
}
float co[2][3];
- copy_v3_v3(co[0], vert[edge[i].v1].co);
- copy_v3_v3(co[1], vert[edge[i].v2].co);
+ copy_v3_v3(co[0], positions[edge[i].v1]);
+ copy_v3_v3(co[1], positions[edge[i].v2]);
BLI_bvhtree_insert(tree, i, co[0], 2);
}
@@ -894,7 +895,7 @@ BVHTree *bvhtree_from_editmesh_edges(
}
BVHTree *bvhtree_from_mesh_edges_ex(BVHTreeFromMesh *data,
- const MVert *vert,
+ const float (*positions)[3],
const MEdge *edge,
const int edges_num,
const BLI_bitmap *edges_mask,
@@ -905,14 +906,14 @@ BVHTree *bvhtree_from_mesh_edges_ex(BVHTreeFromMesh *data,
{
BVHTree *tree = nullptr;
tree = bvhtree_from_mesh_edges_create_tree(
- vert, edge, edges_num, edges_mask, edges_num_active, epsilon, tree_type, axis);
+ positions, edge, edges_num, edges_mask, edges_num_active, epsilon, tree_type, axis);
bvhtree_balance(tree, false);
if (data) {
/* Setup BVHTreeFromMesh */
bvhtree_from_mesh_setup_data(
- tree, BVHTREE_FROM_EDGES, vert, edge, nullptr, nullptr, nullptr, nullptr, data);
+ tree, BVHTREE_FROM_EDGES, positions, edge, nullptr, nullptr, nullptr, nullptr, data);
}
return tree;
@@ -927,7 +928,7 @@ BVHTree *bvhtree_from_mesh_edges_ex(BVHTreeFromMesh *data,
static BVHTree *bvhtree_from_mesh_faces_create_tree(float epsilon,
int tree_type,
int axis,
- const MVert *vert,
+ const float (*positions)[3],
const MFace *face,
const int faces_num,
const BLI_bitmap *faces_mask,
@@ -947,18 +948,18 @@ static BVHTree *bvhtree_from_mesh_faces_create_tree(float epsilon,
// printf("%s: building BVH, total=%d\n", __func__, numFaces);
tree = BLI_bvhtree_new(faces_num_active, epsilon, tree_type, axis);
if (tree) {
- if (vert && face) {
+ if (positions && face) {
for (int i = 0; i < faces_num; i++) {
float co[4][3];
if (faces_mask && !BLI_BITMAP_TEST_BOOL(faces_mask, i)) {
continue;
}
- copy_v3_v3(co[0], vert[face[i].v1].co);
- copy_v3_v3(co[1], vert[face[i].v2].co);
- copy_v3_v3(co[2], vert[face[i].v3].co);
+ copy_v3_v3(co[0], positions[face[i].v1]);
+ copy_v3_v3(co[1], positions[face[i].v2]);
+ copy_v3_v3(co[2], positions[face[i].v3]);
if (face[i].v4) {
- copy_v3_v3(co[3], vert[face[i].v4].co);
+ copy_v3_v3(co[3], positions[face[i].v4]);
}
BLI_bvhtree_insert(tree, i, co[0], face[i].v4 ? 4 : 3);
@@ -1029,7 +1030,7 @@ static BVHTree *bvhtree_from_editmesh_looptri_create_tree(float epsilon,
static BVHTree *bvhtree_from_mesh_looptri_create_tree(float epsilon,
int tree_type,
int axis,
- const MVert *vert,
+ const float (*positions)[3],
const MLoop *mloop,
const MLoopTri *looptri,
const int looptri_num,
@@ -1050,16 +1051,16 @@ static BVHTree *bvhtree_from_mesh_looptri_create_tree(float epsilon,
// printf("%s: building BVH, total=%d\n", __func__, numFaces);
tree = BLI_bvhtree_new(looptri_num_active, epsilon, tree_type, axis);
if (tree) {
- if (vert && looptri) {
+ if (positions && looptri) {
for (int i = 0; i < looptri_num; i++) {
float co[3][3];
if (looptri_mask && !BLI_BITMAP_TEST_BOOL(looptri_mask, i)) {
continue;
}
- copy_v3_v3(co[0], vert[mloop[looptri[i].tri[0]].v].co);
- copy_v3_v3(co[1], vert[mloop[looptri[i].tri[1]].v].co);
- copy_v3_v3(co[2], vert[mloop[looptri[i].tri[2]].v].co);
+ copy_v3_v3(co[0], positions[mloop[looptri[i].tri[0]].v]);
+ copy_v3_v3(co[1], positions[mloop[looptri[i].tri[1]].v]);
+ copy_v3_v3(co[2], positions[mloop[looptri[i].tri[2]].v]);
BLI_bvhtree_insert(tree, i, co[0], 3);
}
@@ -1101,7 +1102,7 @@ BVHTree *bvhtree_from_editmesh_looptri(
}
BVHTree *bvhtree_from_mesh_looptri_ex(BVHTreeFromMesh *data,
- const struct MVert *vert,
+ const float (*positions)[3],
const struct MLoop *mloop,
const struct MLoopTri *looptri,
const int looptri_num,
@@ -1115,7 +1116,7 @@ BVHTree *bvhtree_from_mesh_looptri_ex(BVHTreeFromMesh *data,
tree = bvhtree_from_mesh_looptri_create_tree(epsilon,
tree_type,
axis,
- vert,
+ positions,
mloop,
looptri,
looptri_num,
@@ -1127,7 +1128,7 @@ BVHTree *bvhtree_from_mesh_looptri_ex(BVHTreeFromMesh *data,
if (data) {
/* Setup BVHTreeFromMesh */
bvhtree_from_mesh_setup_data(
- tree, BVHTREE_FROM_LOOPTRI, vert, nullptr, nullptr, mloop, looptri, nullptr, data);
+ tree, BVHTREE_FROM_LOOPTRI, positions, nullptr, nullptr, mloop, looptri, nullptr, data);
}
return tree;
@@ -1135,7 +1136,6 @@ BVHTree *bvhtree_from_mesh_looptri_ex(BVHTreeFromMesh *data,
static BLI_bitmap *loose_verts_map_get(const MEdge *medge,
int edges_num,
- const MVert * /*mvert*/,
int verts_num,
int *r_loose_vert_num)
{
@@ -1229,14 +1229,15 @@ BVHTree *BKE_bvhtree_from_mesh_get(struct BVHTreeFromMesh *data,
looptri = BKE_mesh_runtime_looptri_ensure(mesh);
looptri_len = BKE_mesh_runtime_looptri_len(mesh);
}
- const Span<MVert> verts = mesh->verts();
+ const Span<float3> positions = mesh->positions();
+ const float(*c_positions)[3] = reinterpret_cast<const float(*)[3]>(positions.data());
const Span<MEdge> edges = mesh->edges();
const Span<MLoop> loops = mesh->loops();
/* Setup BVHTreeFromMesh */
bvhtree_from_mesh_setup_data(nullptr,
bvh_cache_type,
- verts.data(),
+ c_positions,
edges.data(),
(const MFace *)CustomData_get_layer(&mesh->fdata, CD_MFACE),
loops.data(),
@@ -1262,12 +1263,11 @@ BVHTree *BKE_bvhtree_from_mesh_get(struct BVHTreeFromMesh *data,
switch (bvh_cache_type) {
case BVHTREE_FROM_LOOSEVERTS:
- mask = loose_verts_map_get(
- edges.data(), mesh->totedge, verts.data(), mesh->totvert, &mask_bits_act_len);
+ mask = loose_verts_map_get(edges.data(), mesh->totedge, mesh->totvert, &mask_bits_act_len);
ATTR_FALLTHROUGH;
case BVHTREE_FROM_VERTS:
data->tree = bvhtree_from_mesh_verts_create_tree(
- 0.0f, tree_type, 6, verts.data(), mesh->totvert, mask, mask_bits_act_len);
+ 0.0f, tree_type, 6, c_positions, mesh->totvert, mask, mask_bits_act_len);
break;
case BVHTREE_FROM_LOOSEEDGES:
@@ -1275,7 +1275,7 @@ BVHTree *BKE_bvhtree_from_mesh_get(struct BVHTreeFromMesh *data,
ATTR_FALLTHROUGH;
case BVHTREE_FROM_EDGES:
data->tree = bvhtree_from_mesh_edges_create_tree(
- verts.data(), edges.data(), mesh->totedge, mask, mask_bits_act_len, 0.0f, tree_type, 6);
+ c_positions, edges.data(), mesh->totedge, mask, mask_bits_act_len, 0.0f, tree_type, 6);
break;
case BVHTREE_FROM_FACES:
@@ -1284,7 +1284,7 @@ BVHTree *BKE_bvhtree_from_mesh_get(struct BVHTreeFromMesh *data,
0.0f,
tree_type,
6,
- verts.data(),
+ c_positions,
(const MFace *)CustomData_get_layer(&mesh->fdata, CD_MFACE),
mesh->totface,
nullptr,
@@ -1304,7 +1304,7 @@ BVHTree *BKE_bvhtree_from_mesh_get(struct BVHTreeFromMesh *data,
data->tree = bvhtree_from_mesh_looptri_create_tree(0.0f,
tree_type,
6,
- verts.data(),
+ c_positions,
loops.data(),
looptri,
looptri_len,