38#ifdef USE_KDOPBVH_WATERTIGHT
65 return idist * m_dist;
89 const float *t0, *t1, *t2, *t3;
90 t0 =
data->vert_positions[face->
v1];
91 t1 =
data->vert_positions[face->
v2];
92 t2 =
data->vert_positions[face->
v3];
93 t3 = face->
v4 ? &
data->vert_positions[face->
v4].x :
nullptr;
96 float nearest_tmp[3], dist_sq;
101 if (dist_sq < nearest->dist_sq) {
122 const float *vtri_co[3] = {
123 data->vert_positions[
data->corner_verts[tri[0]]],
124 data->vert_positions[
data->corner_verts[tri[1]]],
125 data->vert_positions[
data->corner_verts[tri[2]]],
127 float nearest_tmp[3], dist_sq;
132 if (dist_sq < nearest->dist_sq) {
154 const float *t0, *t1, *t2, *t3;
155 t0 =
data->vert_positions[face->
v1];
156 t1 =
data->vert_positions[face->
v2];
157 t2 =
data->vert_positions[face->
v3];
158 t3 = face->
v4 ? &
data->vert_positions[face->
v4].x :
nullptr;
162 if (ray->
radius == 0.0f) {
169 if (dist >= 0 && dist < hit->dist) {
192 const float *vtri_co[3] = {
193 positions[
data->corner_verts[tri[0]]],
194 positions[
data->corner_verts[tri[1]]],
195 positions[
data->corner_verts[tri[2]]],
199 if (ray->
radius == 0.0f) {
206 if (dist >= 0 && dist < hit->dist) {
229 float nearest_tmp[3], dist_sq;
231 const float *t0, *t1;
232 t0 = positions[edge[0]];
233 t1 = positions[edge[1]];
238 if (dist_sq < nearest->dist_sq) {
262 const float dist =
len_v3v3(r1, i1);
263 if (dist < hit->dist) {
304 const float *v1, *
v2, *r1;
305 float r2[3], i1[3], i2[3];
306 v1 = positions[edge[0]];
307 v2 = positions[edge[1]];
321 const float dist =
len_v3v3(r1, i2);
322 if (dist < hit->dist) {
327 else if (e_fac > 1.0f) {
355 data.vert_positions = positions;
358 data.nearest_callback =
nullptr;
367 data.owned_tree = std::move(tree);
377 data.vert_positions = positions;
389 data.owned_tree = std::move(tree);
399 data.vert_positions = positions;
413 data.vert_positions = positions;
414 data.corner_verts = corner_verts;
415 data.corner_tris = corner_tris;
427 data.owned_tree = std::move(tree);
433 if (elems_num == 0) {
436 return std::unique_ptr<BVHTree, BVHTreeDeleter>(
BLI_bvhtree_new(elems_num, 0.0f, 2, 6));
467 const int2 &edge = edges[edge_i];
516 copy_v3_v3(co[0], positions[corner_verts[corner_tris[tri][0]]]);
517 copy_v3_v3(co[1], positions[corner_verts[corner_tris[tri][1]]]);
518 copy_v3_v3(co[2], positions[corner_verts[corner_tris[tri][2]]]);
531 const bool map_global_indices)
533 if (faces_mask.
size() == faces.
size()) {
550 copy_v3_v3(co[0], positions[corner_verts[corner_tris[tri][0]]]);
551 copy_v3_v3(co[1], positions[corner_verts[corner_tris[tri][1]]]);
552 copy_v3_v3(co[2], positions[corner_verts[corner_tris[tri][2]]]);
553 const int index = map_global_indices ? tri : i;
567 const bool map_global_indices)
571 vert_positions, faces, corner_verts, corner_tris, faces_mask, map_global_indices),
579 int count =
mesh.verts_num;
593 for (
const int vert : {edges[i][0], edges[i][1]}) {
594 if (verts_mask[vert]) {
595 verts_mask[vert].reset();
603 if (verts_mask[vert] && hide_vert[vert]) {
604 verts_mask[vert].reset();
614 int count =
mesh.edges_num;
629 for (
const int edge : corner_edges.
slice(faces[i])) {
630 if (edge_mask[edge]) {
631 edge_mask[edge].reset();
639 if (edge_mask[edge] && hide_edge[edge]) {
640 edge_mask[edge].reset();
650bke::BVHTreeFromMesh Mesh::bvh_loose_verts()
const
662 using namespace blender::bke;
663 const Span<float3> positions = this->vert_positions();
665 [&](std::unique_ptr<BVHTree, BVHTreeDeleter> &
data) {
667 IndexMaskMemory memory;
676 using namespace blender::bke;
678 const Span<float3> positions = this->vert_positions();
686 using namespace blender::bke;
687 const Span<float3> positions = this->vert_positions();
688 const Span<int2> edges = this->edges();
698 using namespace blender::bke;
699 const Span<float3> positions = this->vert_positions();
700 const Span<int2> edges = this->edges();
702 [&](std::unique_ptr<BVHTree, BVHTreeDeleter> &
data) {
704 IndexMaskMemory memory;
713 using namespace blender::bke;
715 const Span<int2> edges = this->edges();
723 using namespace blender::bke;
724 const Span<float3> positions = this->vert_positions();
725 const Span<int2> edges = this->edges();
734 using namespace blender::bke;
739 const Span<float3> positions = this->vert_positions();
749 using namespace blender::bke;
750 const Span<float3> positions = this->vert_positions();
751 const Span<int> corner_verts = this->corner_verts();
752 const Span<int3> corner_tris = this->corner_tris();
753 const AttributeAccessor attributes = this->attributes();
754 const VArray hide_poly = *attributes.
lookup<
bool>(
".hide_poly", AttrDomain::Face);
756 return this->bvh_corner_tris();
759 [&](std::unique_ptr<BVHTree, BVHTreeDeleter> &
data) {
760 const OffsetIndices<int> faces = this->faces();
761 IndexMaskMemory memory;
763 faces.
index_range(), VArraySpan(hide_poly), memory);
765 positions, faces, corner_verts, corner_tris, visible_faces,
true);
775 using namespace blender::bke;
776 const Span<float3> positions = this->vert_positions();
777 const Span<int> corner_verts = this->corner_verts();
778 const Span<int3> corner_tris = this->corner_tris();
788 using namespace blender::bke::bvh;
802 using namespace blender::bke;
804 const Span<float3> positions = this->positions();
General operations for point clouds.
constexpr const T * data() const
constexpr IndexRange index_range() const
static IndexMask from_bits(BitSpan bits, LinearAllocator<> &memory)
static IndexMask from_bools_inverse(Span< bool > bools, LinearAllocator<> &memory)
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 name, AttrDomain domain, AttrType data_type, const void *default_value=nullptr) const
GAttributeReader lookup(const StringRef name) const
static Tree from_single_mesh(const Mesh &mesh)
static Tree from_edges(Span< float3 > positions, Span< int2 > edges, const IndexMask &mask)
static Tree from_points(Span< float3 > positions, const IndexMask &mask)
void foreach_index_optimized(Fn &&fn, Mode mode=exec_mode::serial) const
void foreach_index(Fn &&fn, Mode mode=exec_mode::serial) const
IndexRange index_range() const
int face_triangles_num(const int face_size)
IndexRange face_triangles_range(OffsetIndices< int > faces, int face_i)
static std::unique_ptr< BVHTree, BVHTreeDeleter > create_tree_from_legacy_faces(const Span< float3 > positions, const Span< MFace > faces)
static void mesh_verts_spherecast(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit)
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, bool map_global_indices=true)
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)
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])
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 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_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)
static void mesh_faces_spherecast(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit)
MINLINE void madd_v3_v3v3fl(float r[3], const float a[3], const float b[3], float f)
MINLINE float len_squared_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
float line_point_factor_v3(const float p[3], const float l1[3], const float l2[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])
MINLINE float dot_v3v3v3(const float p[3], const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
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])
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])
void BLI_bvhtree_balance(BVHTree *tree)
float closest_to_line_segment_v3(float r_close[3], const float p[3], const float l1[3], const float l2[3])
ATTR_WARN_UNUSED_RESULT const BMVert * v
float normal_tri_v3(float n[3], const float v1[3], const float v2[3], const float v3[3])
MINLINE bool equals_v3v3(const float v1[3], const float v2[3]) ATTR_WARN_UNUSED_RESULT
VecBase< int32_t, 2 > int2
VecBase< int32_t, 3 > int3
BMesh const char void * data
BVHTree * BLI_bvhtree_new(int maxsize, float epsilon, char tree_type, char axis)
const void * CustomData_get_layer(const CustomData *data, eCustomDataType type)
MINLINE float normalize_v3(float n[3])
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
ATTR_WARN_UNUSED_RESULT const BMVert * v2
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])
void BLI_bvhtree_insert(BVHTree *tree, int index, const float co[3], int numpoints)
MINLINE float square_f(float a)
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
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])
void mask(PageMask &srt, TileMaps &tilemaps, const uint3 global_id, const uint local_tile_index)
struct IsectRayPrecalc * isect_precalc
bke::MeshRuntime * runtime
bke::PointCloudRuntime * runtime
SharedCache< std::unique_ptr< BVHTree, BVHTreeDeleter > > bvh_cache_loose_verts
SharedCache< std::unique_ptr< BVHTree, BVHTreeDeleter > > bvh_cache_loose_edges_no_hidden
SharedCache< bke::bvh::Tree > bvh_embree_tris_cache
SharedCache< std::unique_ptr< BVHTree, BVHTreeDeleter > > bvh_cache_corner_tris
SharedCache< bke::bvh::Tree > bvh_embree_edges_cache
SharedCache< std::unique_ptr< BVHTree, BVHTreeDeleter > > bvh_cache_edges
SharedCache< std::unique_ptr< BVHTree, BVHTreeDeleter > > bvh_cache_loose_verts_no_hidden
SharedCache< bke::bvh::Tree > bvh_embree_verts_cache
SharedCache< std::unique_ptr< BVHTree, BVHTreeDeleter > > bvh_cache_loose_edges
SharedCache< std::unique_ptr< BVHTree, BVHTreeDeleter > > bvh_cache_faces
SharedCache< std::unique_ptr< BVHTree, BVHTreeDeleter > > bvh_cache_corner_tris_no_hidden
SharedCache< bke::bvh::Tree > bvh_cache