48 const Span<int> neighbors = vert_neighbors[i];
50 dst[i] = src[verts[i]];
97 result += positions[coord.to_index(key)] * factor;
102template<
bool use_factors>
117 if constexpr (use_factors) {
122 const int node_verts_start = i * key.
grid_area;
123 const int grid = grids[i];
131 const int node_vert_index = node_verts_start + offset;
134 if constexpr (use_factors) {
135 if (factors[node_vert_index] == 0.0f) {
136 new_positions[node_vert_index] = positions[vert];
150 faces, corner_verts, boundary_verts, boundary_edges, subdiv_ccg, coord))
160 faces, corner_verts, boundary_verts, boundary_edges, subdiv_ccg, coord);
166 new_positions[node_vert_index] = positions[vert];
185 faces, corner_verts, boundary_verts, boundary_edges, subdiv_ccg, grids, {}, new_positions);
219 const int grid = grids[i];
220 const int node_verts_start = i * key.
grid_area;
227 const int node_vert_index = node_verts_start + offset;
254 for (
BMVert *vert : verts) {
257 for (
const BMVert *neighbor : neighbors) {
285 for (
const BMVert *vert : verts) {
299 for (
BMVert *vert : verts) {
306template<
bool use_factors>
313 if constexpr (use_factors) {
319 for (
BMVert *vert : verts) {
320 if constexpr (use_factors) {
321 if (factors[i] == 0.0f) {
322 new_positions[i] =
float3(vert->co);
330 new_positions[i] =
float3(vert->co);
353 float avg_co[3] = {0.0f, 0.0f, 0.0f};
364 BMVert *v_other = (
e->v1 ==
v) ?
e->v2 :
e->v1;
372 float fac =
dot_v3v3(vec, direction);
373 fac = fac * fac - 0.5f;
398 const GSpan color_attribute,
408 const Span<int> neighbors = vert_neighbors[i];
409 for (
const int vert : neighbors) {
411 faces, corner_verts, vert_to_face_map, color_attribute, color_domain, vert);
434 const float3 weighted_o = orig_positions[i] * alpha;
435 const float3 weighted_q = positions[i] * (1.0f - alpha);
436 const float3 d = weighted_o + weighted_q;
452 float3 b_current_vert = average_laplacian_disp[i] * (1.0f -
beta);
453 b_current_vert += laplacian_disp[i] *
beta;
454 translations[i] = -b_current_vert;
460 const float3 &smoothed_position)
465 float3 smooth_closest_plane;
468 return smooth_closest_plane - current_position;
477 for (
const int vert : neighbors) {
478 const float3 to_neighbor = vert_positions[vert] - current_position;
486 const float3 ¤t_position,
492 const float3 to_neighbor = positions[coord.to_index(key)] - current_position;
503 for (
BMVert *vert : neighbors) {
504 const float3 neighbor_pos = vert->co;
505 const float3 to_neighbor = neighbor_pos - current_position;
520 const bool filter_boundary_face_sets,
532 if (factors[i] == 0.0f) {
533 translations[i] =
float3(0);
540 if (neighbors.
size() <= 2) {
541 translations[i] =
float3(0);
545 const bool is_boundary = boundary_verts[verts[i]];
551 if (filter_boundary_face_sets) {
552 neighbors.
remove_if([&](
const int vert) {
558 translations[i] =
float3(0);
566 if (is_boundary && neighbors.
size() == 2) {
569 translations[i] =
float3(0);
574 normal = vert_normals[verts[i]];
578 vert_positions[verts[i]], normal, smoothed_position);
580 translations[i] = translation * factors[i];
592 const bool filter_boundary_face_sets,
603 const int node_start = i * key.
grid_area;
607 const int node_vert = node_start + offset;
609 if (factors[node_vert] == 0.0f) {
610 translations[node_vert] =
float3(0);
624 if (neighbors.
size() <= 2) {
625 translations[node_vert] =
float3(0);
630 faces, corner_verts, boundary_verts, boundary_edges, subdiv_ccg, coord);
635 faces, corner_verts, boundary_verts, boundary_edges, subdiv_ccg, neighbor);
639 if (filter_boundary_face_sets) {
642 faces, corner_verts, vert_to_face_map, face_sets, subdiv_ccg, neighbor);
647 translations[node_vert] =
float3(0);
655 if (is_boundary && neighbors.
size() == 2) {
658 translations[node_vert] =
float3(0);
663 normal = normals[vert];
667 positions[vert], normal, smoothed_position);
669 translations[node_vert] = translation * factors[node_vert];
677 const int face_set_offset,
678 const bool filter_boundary_face_sets,
689 for (
BMVert *vert : verts) {
690 if (factors[i] == 0.0f) {
691 translations[i] =
float3(0);
699 if (neighbors.
size() <= 2) {
700 translations[i] =
float3(0);
710 if (filter_boundary_face_sets) {
717 translations[i] =
float3(0);
726 if (is_boundary && neighbors.
size() == 2) {
729 translations[i] =
float3(0);
740 translations[i] = translation * factors[i];
746 const int iterations,
762 switch (
pbvh.type()) {
775 for ([[maybe_unused]]
const int _ :
IndexRange(iterations)) {
778 LocalData &tls = all_tls.
local();
787 tls.neighbor_offsets,
805 for ([[maybe_unused]]
const int _ :
IndexRange(iterations)) {
807 [&](
const int node_index) {
808 LocalData &tls = all_tls.
local();
812 tls.new_factors.resize(grid_verts_num);
821 const int node_start = i * key.
grid_area;
823 key, grid_hidden, grids[i], [&](
const int offset) {
824 data[i] = new_factors[node_start + offset];
835 for ([[maybe_unused]]
const int _ :
IndexRange(iterations)) {
837 [&](
const int node_index) {
838 LocalData &tls = all_tls.
local();
842 tls.new_factors.resize(verts.
size());
847 for (
const BMVert *vert : verts) {
A BVH for high poly meshes.
#define PRF_scope(category)
#define BM_elem_index_get(ele)
#define BM_elem_flag_test(ele, hflag)
#define BM_ITER_ELEM(ele, iter, data, itype)
Span< T > as_span() const
MutableSpan< T > as_mutable_span()
constexpr IndexRange()=default
constexpr int64_t size() const
constexpr Span< T > as_span() const
bool contains(const Key &key) const
constexpr int64_t size() const
constexpr IndexRange index_range() const
constexpr bool is_empty() const
int64_t remove_if(Predicate &&predicate)
GAttributeReader lookup(const StringRef name) const
void foreach_index(Fn &&fn, Mode mode=exec_mode::serial) const
ccl_device_inline float beta(const float x, const float y)
T mix_indices(const Span< T > src, const Span< int > indices)
IndexRange grid_range(const int grid_area, const int grid)
pbvh::Tree * pbvh_get(Object &object)
IndexMask all_leaf_nodes(const Tree &pbvh, IndexMaskMemory &memory)
bool vert_is_boundary(const GroupedSpan< int > vert_to_face_map, const Span< bool > hide_poly, const BitSpan boundary_verts, const int vert)
float4 color_vert_get(OffsetIndices< int > faces, Span< int > corner_verts, GroupedSpan< int > vert_to_face_map, GSpan color_attribute, bke::AttrDomain color_domain, int vert)
bool vert_has_unique_face_set(const GroupedSpan< int > vert_to_face_map, const Span< int > face_sets, int vert)
Span< int > node_visible_verts(const bke::pbvh::MeshNode &node, const Span< bool > hide_vert, Vector< int, bke::pbvh::MESH_LEAF_LIMIT > &indices)
static void neighbor_position_average_interior_bmesh_impl(const Set< BMVert *, 0 > &verts, const Span< float > factors, const MutableSpan< float3 > new_positions)
void average_data_bmesh(const Span< T > src, const Set< BMVert *, 0 > &verts, const MutableSpan< T > dst)
void neighbor_position_average_interior_grids(const OffsetIndices< int > faces, const Span< int > corner_verts, const BitSpan boundary_verts, const Set< OrderedEdge > &boundary_edges, const SubdivCCG &subdiv_ccg, const Span< int > grids, const MutableSpan< float3 > new_positions)
static float3 translation_to_plane(const float3 ¤t_position, const float3 &normal, const float3 &smoothed_position)
static float3 calc_boundary_normal_corner(const float3 ¤t_position, const Span< float3 > vert_positions, const Span< int > neighbors)
void neighbor_data_average_mesh(const Span< T > src, const GroupedSpan< int > vert_neighbors, const MutableSpan< T > dst)
void neighbor_color_average(const OffsetIndices< int > faces, const Span< int > corner_verts, const GroupedSpan< int > vert_to_face_map, const GSpan color_attribute, const bke::AttrDomain color_domain, const GroupedSpan< int > vert_neighbors, const MutableSpan< float4 > smooth_colors)
void calc_relaxed_translations_faces(const Span< float3 > vert_positions, const Span< float3 > vert_normals, const OffsetIndices< int > faces, const Span< int > corner_verts, const GroupedSpan< int > vert_to_face_map, const BitSpan boundary_verts, const Set< OrderedEdge > &boundary_edges, const Span< int > face_sets, const Span< bool > hide_poly, const bool filter_boundary_face_sets, const Span< int > verts, const Span< float > factors, const MutableSpan< float3 > translations)
void neighbor_data_average_mesh_check_loose(const Span< T > src, const Span< int > verts, const GroupedSpan< int > vert_neighbors, const MutableSpan< T > dst)
void neighbor_position_average_interior_bmesh(const Set< BMVert *, 0 > &verts, const Span< float > factors, const MutableSpan< float3 > new_positions)
static float3 average_positions(const CCGKey &key, const Span< float3 > positions, const Span< SubdivCCGCoord > coords)
void surface_smooth_laplacian_step(const Span< float3 > positions, const Span< float3 > orig_positions, const Span< float3 > average_positions, const float alpha, MutableSpan< float3 > laplacian_disp, MutableSpan< float3 > translations)
void surface_smooth_displace_step(const Span< float3 > laplacian_disp, const Span< float3 > average_laplacian_disp, const float beta, const MutableSpan< float3 > translations)
void bmesh_four_neighbor_average(float avg[3], const float3 &direction, const BMVert *v)
void average_data_grids(const SubdivCCG &subdiv_ccg, const Span< T > src, const Span< int > grids, const MutableSpan< T > dst)
void blur_geometry_data_array(const Object &object, const int iterations, const MutableSpan< float > data)
static void neighbor_position_average_interior_grids_impl(const OffsetIndices< int > faces, const Span< int > corner_verts, const BitSpan boundary_verts, const Set< OrderedEdge > &boundary_edges, const SubdivCCG &subdiv_ccg, const Span< int > grids, const Span< float > factors, const MutableSpan< float3 > new_positions)
void calc_relaxed_translations_bmesh(const Set< BMVert *, 0 > &verts, const Span< float3 > positions, const int face_set_offset, const bool filter_boundary_face_sets, const Span< float > factors, const MutableSpan< float3 > translations)
void neighbor_position_average_bmesh(const Set< BMVert *, 0 > &verts, const MutableSpan< float3 > new_positions)
void calc_relaxed_translations_grids(const SubdivCCG &subdiv_ccg, const OffsetIndices< int > faces, const Span< int > corner_verts, const Span< int > face_sets, const GroupedSpan< int > vert_to_face_map, const BitSpan boundary_verts, const Set< OrderedEdge > &boundary_edges, const Span< int > grids, const bool filter_boundary_face_sets, const Span< float > factors, const MutableSpan< float3 > translations)
GroupedSpan< int > calc_vert_neighbors(OffsetIndices< int > faces, Span< int > corner_verts, GroupedSpan< int > vert_to_face, Span< bool > hide_poly, Span< int > verts, Vector< int > &r_offset_data, Vector< int > &r_data)
Vector< BMVert *, 64 > BMeshNeighborVerts
void scatter_data_mesh(Span< T > src, Span< int > indices, MutableSpan< T > dst)
Span< BMVert * > vert_neighbors_get_interior_bmesh(BMVert &vert, BMeshNeighborVerts &r_neighbors)
Span< BMVert * > vert_neighbors_get_bmesh(BMVert &vert, BMeshNeighborVerts &r_neighbors)
Span< int > vert_neighbors_get_mesh(const OffsetIndices< int > faces, const Span< int > corner_verts, const GroupedSpan< int > vert_to_face, const Span< bool > hide_poly, const int vert, Vector< int > &r_neighbors)
void scatter_data_grids(const SubdivCCG &subdiv_ccg, Span< T > node_data, Span< int > grids, MutableSpan< T > dst)
constexpr ParallelGrainSize grain_size(int grain_size)
T safe_divide(const T &a, const T &b)
MatBase< T, NumCol, NumRow > normalize(const MatBase< T, NumCol, NumRow > &a)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void closest_to_plane_v3(float r_close[3], const float plane[4], const float pt[3])
MINLINE void copy_v3_v3(float r[3], const float a[3])
ATTR_WARN_UNUSED_RESULT const BMVert * v
void plane_from_point_normal_v3(float r_plane[4], const float plane_co[3], const float plane_no[3])
bool BM_vert_is_boundary(const BMVert *v)
CCGKey BKE_subdiv_ccg_key_top_level(const SubdivCCG &subdiv_ccg)
MINLINE void sub_v3_v3(float r[3], const float a[3])
VecBase< float, 4 > float4
void BKE_subdiv_ccg_neighbor_coords_get(const SubdivCCG &subdiv_ccg, const SubdivCCGCoord &coord, bool include_duplicates, SubdivCCGNeighbors &r_neighbors)
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
BMesh const char void * data
Vector< SubdivCCGCoord, 256 > SubdivCCGNeighborCoords
BLI_INLINE bool BM_edge_is_boundary(const BMEdge *e) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
MINLINE void zero_v3(float r[3])
int CCG_grid_xy_to_index(const int grid_size, const int x, const int y)
MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f)
MINLINE float normalize_v3(float n[3])
MINLINE void add_v3_v3(float r[3], const float a[3])
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
void BKE_subdiv_ccg_foreach_visible_grid_vert(const CCGKey &key, const BitGroupVector<> &grid_hidden, const int grid, const Fn &fn)
VecBase< float, 3 > float3
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
const Set< BMVert *, 0 > & BKE_pbvh_bmesh_node_unique_verts(bke::pbvh::BMeshNode *node)
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
OrderedEdge(const int v1, const int v2)
int to_index(const CCGKey &key) const
SubdivCCGNeighborCoords coords
Array< float3 > positions
IndexRange index_range() const