36#ifdef USE_KDOPBVH_WATERTIGHT
63 return idist * m_dist;
87 const float *t0, *t1, *t2, *t3;
88 t0 =
data->vert_positions[face->
v1];
89 t1 =
data->vert_positions[face->
v2];
90 t2 =
data->vert_positions[face->
v3];
91 t3 = face->
v4 ? &
data->vert_positions[face->
v4].x :
nullptr;
94 float nearest_tmp[3], dist_sq;
99 if (dist_sq < nearest->dist_sq) {
100 nearest->
index = index;
119 const int3 &tri =
data->corner_tris[index];
120 const float *vtri_co[3] = {
121 data->vert_positions[
data->corner_verts[tri[0]]],
122 data->vert_positions[
data->corner_verts[tri[1]]],
123 data->vert_positions[
data->corner_verts[tri[2]]],
125 float nearest_tmp[3], dist_sq;
130 if (dist_sq < nearest->dist_sq) {
131 nearest->
index = index;
152 const float *t0, *t1, *t2, *t3;
153 t0 =
data->vert_positions[face->
v1];
154 t1 =
data->vert_positions[face->
v2];
155 t2 =
data->vert_positions[face->
v3];
156 t3 = face->
v4 ? &
data->vert_positions[face->
v4].x :
nullptr;
160 if (ray->
radius == 0.0f) {
167 if (dist >= 0 && dist < hit->dist) {
189 const int3 &tri =
data->corner_tris[index];
190 const float *vtri_co[3] = {
191 positions[
data->corner_verts[tri[0]]],
192 positions[
data->corner_verts[tri[1]]],
193 positions[
data->corner_verts[tri[2]]],
197 if (ray->
radius == 0.0f) {
204 if (dist >= 0 && dist < hit->dist) {
226 const int2 edge =
data->edges[index];
227 float nearest_tmp[3], dist_sq;
229 const float *t0, *t1;
230 t0 = positions[edge[0]];
231 t1 = positions[edge[1]];
236 if (dist_sq < nearest->dist_sq) {
237 nearest->
index = index;
260 const float dist =
len_v3v3(r1, i1);
261 if (dist < hit->dist) {
281 const float *
v =
data->vert_positions[index];
299 const int2 edge =
data->edges[index];
302 const float *v1, *
v2, *r1;
303 float r2[3], i1[3], i2[3];
304 v1 = positions[edge[0]];
305 v2 = positions[edge[1]];
319 const float dist =
len_v3v3(r1, i2);
320 if (dist < hit->dist) {
325 else if (e_fac > 1.0f) {
353 data.vert_positions = positions;
356 data.nearest_callback =
nullptr;
375 data.vert_positions = positions;
397 data.vert_positions = positions;
411 data.vert_positions = positions;
412 data.corner_verts = corner_verts;
413 data.corner_tris = corner_tris;
431 if (elems_num == 0) {
434 return std::unique_ptr<BVHTree, BVHTreeDeleter>(
BLI_bvhtree_new(elems_num, 0.0f, 2, 6));
465 const int2 &edge = edges[edge_i];
490 for (
const int i :
faces.index_range()) {
514 copy_v3_v3(co[0], positions[corner_verts[corner_tris[tri][0]]]);
515 copy_v3_v3(co[1], positions[corner_verts[corner_tris[tri][1]]]);
516 copy_v3_v3(co[2], positions[corner_verts[corner_tris[tri][2]]]);
546 copy_v3_v3(co[0], positions[corner_verts[corner_tris[tri][0]]]);
547 copy_v3_v3(co[1], positions[corner_verts[corner_tris[tri][1]]]);
548 copy_v3_v3(co[2], positions[corner_verts[corner_tris[tri][2]]]);
585 for (
const int vert : {edges[
i][0], edges[
i][1]}) {
586 if (verts_mask[vert]) {
587 verts_mask[vert].reset();
595 if (verts_mask[vert] && hide_vert[vert]) {
596 verts_mask[vert].reset();
617 for (
const int i :
faces.index_range()) {
621 for (
const int edge : corner_edges.
slice(
faces[
i])) {
622 if (edge_mask[edge]) {
623 edge_mask[edge].reset();
631 if (edge_mask[edge] && hide_edge[edge]) {
632 edge_mask[edge].reset();
647 this->
runtime->bvh_cache_loose_verts.ensure([&](std::unique_ptr<BVHTree, BVHTreeDeleter> &
data) {
658 using namespace blender;
659 using namespace blender::bke;
660 const Span<float3> positions = this->vert_positions();
661 this->
runtime->bvh_cache_loose_verts_no_hidden.ensure(
662 [&](std::unique_ptr<BVHTree, BVHTreeDeleter> &
data) {
664 IndexMaskMemory memory;
673 using namespace blender;
674 using namespace blender::bke;
675 const Span<float3> positions = this->vert_positions();
676 this->
runtime->bvh_cache_verts.ensure([&](std::unique_ptr<BVHTree, BVHTreeDeleter> &
data) {
684 using namespace blender;
685 using namespace blender::bke;
686 const Span<float3> positions = this->vert_positions();
687 const Span<int2> edges = this->edges();
688 this->
runtime->bvh_cache_loose_edges.ensure([&](std::unique_ptr<BVHTree, BVHTreeDeleter> &
data) {
689 const LooseEdgeCache &loose_edges = this->loose_edges();
690 IndexMaskMemory memory;
695 this->
runtime->bvh_cache_loose_edges.data().get(), positions, edges);
700 using namespace blender;
701 using namespace blender::bke;
702 const Span<float3> positions = this->vert_positions();
703 const Span<int2> edges = this->edges();
704 this->
runtime->bvh_cache_loose_edges_no_hidden.ensure(
705 [&](std::unique_ptr<BVHTree, BVHTreeDeleter> &
data) {
707 IndexMaskMemory memory;
711 this->
runtime->bvh_cache_loose_edges_no_hidden.data().get(), positions, edges);
716 using namespace blender;
717 using namespace blender::bke;
718 const Span<float3> positions = this->vert_positions();
719 const Span<int2> edges = this->edges();
720 this->
runtime->bvh_cache_edges.ensure([&](std::unique_ptr<BVHTree, BVHTreeDeleter> &
data) {
728 using namespace blender;
729 using namespace blender::bke;
734 const Span<float3> positions = this->vert_positions();
735 this->
runtime->bvh_cache_faces.ensure([&](std::unique_ptr<BVHTree, BVHTreeDeleter> &
data) {
739 this->
runtime->bvh_cache_faces.data().get(), positions, legacy_faces.
data());
744 using namespace blender;
745 using namespace blender::bke;
746 const Span<float3> positions = this->vert_positions();
747 const Span<int> corner_verts = this->corner_verts();
748 const Span<int3> corner_tris = this->corner_tris();
750 const VArray hide_poly = *
attributes.lookup<
bool>(
".hide_poly", AttrDomain::Face);
752 return this->bvh_corner_tris();
754 this->
runtime->bvh_cache_corner_tris_no_hidden.ensure(
755 [&](std::unique_ptr<BVHTree, BVHTreeDeleter> &
data) {
756 const OffsetIndices<int>
faces = this->
faces();
757 IndexMaskMemory memory;
759 faces.index_range(), VArraySpan(hide_poly), memory);
770 using namespace blender;
771 using namespace blender::bke;
772 const Span<float3> positions = this->vert_positions();
773 const Span<int> corner_verts = this->corner_verts();
774 const Span<int3> corner_tris = this->corner_tris();
775 this->
runtime->bvh_cache_corner_tris.ensure([&](std::unique_ptr<BVHTree, BVHTreeDeleter> &
data) {
779 this->
runtime->bvh_cache_corner_tris.data().get(), positions, corner_verts, corner_tris);
786 if (faces_mask.
size() ==
mesh.faces_num) {
787 return mesh.bvh_corner_tris();
790 mesh.vert_positions(),
mesh.faces(),
mesh.corner_verts(),
mesh.corner_tris(), faces_mask);
795 if (edges_mask.
size() ==
mesh.edges_num) {
796 return mesh.bvh_edges();
803 if (verts_mask.
size() ==
mesh.verts_num) {
804 return mesh.bvh_verts();
820 data.positions = positions;
821 data.nearest_callback =
nullptr;
830 data.positions = positions;
835 std::unique_ptr<BVHTree, BVHTreeDeleter>
tree,
const Span<float3> positions)
846 return pointcloud.bvh_tree();
859 this->
runtime->bvh_cache.ensure([&](std::unique_ptr<BVHTree, BVHTreeDeleter> &
data) {
const void * CustomData_get_layer(const CustomData *data, eCustomDataType type)
General operations for point clouds.
BVHTree * BLI_bvhtree_new(int maxsize, float epsilon, char tree_type, char axis)
void BLI_bvhtree_balance(BVHTree *tree)
void BLI_bvhtree_insert(BVHTree *tree, int index, const float co[3], int numpoints)
MINLINE float square_f(float a)
int isect_line_line_v3(const float v1[3], const float v2[3], const float v3[3], const float v4[3], float r_i1[3], float r_i2[3])
float closest_to_line_segment_v3(float r_close[3], const float p[3], const float l1[3], const float l2[3])
void closest_on_tri_to_point_v3(float r[3], const float p[3], const float v1[3], const float v2[3], const float v3[3])
bool isect_sweeping_sphere_tri_v3(const float p1[3], const float p2[3], float radius, const float v0[3], const float v1[3], const float v2[3], float *r_lambda, float ipoint[3])
bool isect_ray_tri_watertight_v3(const float ray_origin[3], const struct IsectRayPrecalc *isect_precalc, const float v0[3], const float v1[3], const float v2[3], float *r_lambda, float r_uv[2])
float line_point_factor_v3(const float p[3], const float l1[3], const float l2[3])
float normal_tri_v3(float n[3], const float v1[3], const float v2[3], const float v3[3])
bool isect_ray_tri_epsilon_v3(const float ray_origin[3], const float ray_direction[3], const float v0[3], const float v1[3], const float v2[3], float *r_lambda, float r_uv[2], float epsilon)
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE bool equals_v3v3(const float v1[3], const float v2[3]) ATTR_WARN_UNUSED_RESULT
MINLINE float dot_v3v3v3(const float p[3], const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE float len_squared_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void madd_v3_v3v3fl(float r[3], const float a[3], const float b[3], float f)
MINLINE float normalize_v3(float n[3])
BMesh const char void * data
ATTR_WARN_UNUSED_RESULT const BMVert * v2
ATTR_WARN_UNUSED_RESULT const BMVert * v
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
static IndexMask from_bits(BitSpan bits, IndexMaskMemory &memory)
static IndexMask from_bools_inverse(const VArray< bool > &bools, IndexMaskMemory &memory)
constexpr const T * data() const
constexpr IndexRange index_range() const
constexpr Span slice(int64_t start, int64_t size) const
constexpr int64_t size() const
constexpr IndexRange index_range() const
IndexRange index_range() const
GAttributeReader lookup_or_default(StringRef attribute_id, AttrDomain domain, AttrType data_type, const void *default_value=nullptr) const
void foreach_index_optimized(Fn &&fn) const
void foreach_index(Fn &&fn) const
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
int face_triangles_num(const int face_size)
IndexRange face_triangles_range(OffsetIndices< int > faces, int face_i)
static BVHTreeFromPointCloud create_pointcloud_tree_data(const BVHTree *tree, const Span< float3 > positions)
static std::unique_ptr< BVHTree, BVHTreeDeleter > create_tree_from_legacy_faces(const Span< float3 > positions, const Span< MFace > faces)
BVHTreeFromMesh bvhtree_from_mesh_corner_tris_ex(Span< float3 > vert_positions, OffsetIndices< int > faces, Span< int > corner_verts, Span< int3 > corner_tris, const IndexMask &faces_mask)
static void mesh_verts_spherecast(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit)
static std::unique_ptr< BVHTree, BVHTreeDeleter > create_tree_from_verts(const Span< float3 > positions, const IndexMask &verts_mask)
static BitVector loose_verts_no_hidden_mask_get(const Mesh &mesh)
float bvhtree_sphereray_tri_intersection(const BVHTreeRay *ray, float radius, float m_dist, const float v0[3], const float v1[3], const float v2[3])
static BVHTreeFromMesh create_tris_tree_data(const BVHTree *tree, const Span< float3 > positions, const Span< int > corner_verts, const Span< int3 > corner_tris)
static std::unique_ptr< BVHTree, BVHTreeDeleter > bvhtree_new_common(int elems_num)
static void mesh_corner_tris_spherecast(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit)
static BVHTreeFromMesh create_edges_tree_data(const BVHTree *tree, const Span< float3 > positions, const Span< int2 > edges)
static BVHTreeFromMesh create_legacy_faces_tree_data(const BVHTree *tree, const Span< float3 > positions, const MFace *face)
BVHTreeFromMesh bvhtree_from_mesh_edges_init(const Mesh &mesh, const IndexMask &edges_mask)
static std::unique_ptr< BVHTree, BVHTreeDeleter > create_tree_from_tris(const Span< float3 > positions, const Span< int > corner_verts, const Span< int3 > corner_tris)
float bvhtree_ray_tri_intersection(const BVHTreeRay *ray, float m_dist, const float v0[3], const float v1[3], const float v2[3])
BVHTreeFromMesh bvhtree_from_mesh_tris_init(const Mesh &mesh, const IndexMask &faces_mask)
static BVHTreeFromMesh create_verts_tree_data(const BVHTree *tree, const Span< float3 > positions)
static void mesh_edges_spherecast(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit)
static BVHTreeFromPointCloud create_points_tree_data(const BVHTree *tree, const Span< float3 > positions)
static std::unique_ptr< BVHTree, BVHTreeDeleter > create_tree_from_edges(const Span< float3 > positions, const Span< int2 > edges, const IndexMask &edges_mask)
BVHTreeFromMesh bvhtree_from_mesh_edges_ex(Span< float3 > vert_positions, Span< int2 > edges, const IndexMask &edges_mask)
static void mesh_corner_tris_nearest_point(void *userdata, int index, const float co[3], BVHTreeNearest *nearest)
BVHTreeFromMesh bvhtree_from_mesh_verts_init(const Mesh &mesh, const IndexMask &verts_mask)
BVHTreeFromMesh bvhtree_from_mesh_verts_ex(Span< float3 > vert_positions, const IndexMask &verts_mask)
static void mesh_faces_nearest_point(void *userdata, int index, const float co[3], BVHTreeNearest *nearest)
static void mesh_verts_spherecast_do(int index, const float v[3], const BVHTreeRay *ray, BVHTreeRayHit *hit)
static BitVector loose_edges_no_hidden_mask_get(const Mesh &mesh)
static void mesh_edges_nearest_point(void *userdata, int index, const float co[3], BVHTreeNearest *nearest)
BVHTreeFromPointCloud bvhtree_from_pointcloud_get(const PointCloud &pointcloud, const IndexMask &points_mask)
static void mesh_faces_spherecast(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit)
VecBase< int32_t, 2 > int2
VecBase< int32_t, 3 > int3
struct IsectRayPrecalc * isect_precalc
MeshRuntimeHandle * runtime
PointCloudRuntimeHandle * runtime
blender::BitVector is_loose_bits