2023-08-15 16:20:26 +02:00
|
|
|
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
2023-07-04 04:55:22 +02:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
* \ingroup bke
|
|
|
|
* \brief A BVH for high poly meshes.
|
|
|
|
*/
|
|
|
|
|
2023-10-19 14:18:15 +02:00
|
|
|
#include <optional>
|
2023-07-28 14:53:05 +02:00
|
|
|
#include <string>
|
|
|
|
|
2023-12-02 20:05:29 +01:00
|
|
|
#include "BLI_bit_group_vector.hh"
|
2023-12-04 17:25:07 +01:00
|
|
|
#include "BLI_bounds_types.hh"
|
2023-07-04 04:55:22 +02:00
|
|
|
#include "BLI_compiler_compat.h"
|
2023-08-22 21:05:37 +02:00
|
|
|
#include "BLI_function_ref.hh"
|
2024-03-28 02:37:26 +01:00
|
|
|
#include "BLI_index_mask_fwd.hh"
|
2023-07-11 21:01:53 +02:00
|
|
|
#include "BLI_math_vector_types.hh"
|
2023-07-04 04:55:22 +02:00
|
|
|
#include "BLI_offset_indices.hh"
|
2023-11-09 11:00:58 +01:00
|
|
|
#include "BLI_span.hh"
|
2023-07-04 04:55:22 +02:00
|
|
|
#include "BLI_vector.hh"
|
|
|
|
|
|
|
|
#include "DNA_customdata_types.h"
|
|
|
|
|
|
|
|
/* For embedding CCGKey in iterator. */
|
|
|
|
#include "BKE_ccg.h"
|
2023-11-16 11:41:55 +01:00
|
|
|
#include "BKE_pbvh.hh"
|
2023-07-04 04:55:22 +02:00
|
|
|
|
2023-12-05 23:01:12 +01:00
|
|
|
#include "bmesh.hh"
|
2023-07-04 04:55:22 +02:00
|
|
|
|
|
|
|
struct BMLog;
|
|
|
|
struct BMesh;
|
|
|
|
struct CCGElem;
|
|
|
|
struct CCGKey;
|
|
|
|
struct CustomData;
|
|
|
|
struct IsectRayPrecalc;
|
|
|
|
struct Mesh;
|
|
|
|
struct PBVH;
|
|
|
|
struct PBVHNode;
|
|
|
|
struct SubdivCCG;
|
|
|
|
struct Image;
|
|
|
|
struct ImageUser;
|
2023-12-20 19:25:08 +01:00
|
|
|
namespace blender {
|
|
|
|
namespace bke {
|
|
|
|
enum class AttrDomain : int8_t;
|
|
|
|
}
|
|
|
|
namespace draw::pbvh {
|
2023-12-01 01:02:36 +01:00
|
|
|
struct PBVHBatches;
|
|
|
|
struct PBVH_GPU_Args;
|
2023-12-20 19:25:08 +01:00
|
|
|
} // namespace draw::pbvh
|
|
|
|
} // namespace blender
|
2023-07-04 04:55:22 +02:00
|
|
|
|
|
|
|
struct PBVHProxyNode {
|
2023-11-09 11:00:58 +01:00
|
|
|
blender::Vector<blender::float3> co;
|
2023-07-04 04:55:22 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct PBVHColorBufferNode {
|
2023-07-27 22:21:34 +02:00
|
|
|
float (*color)[4] = nullptr;
|
2023-07-04 04:55:22 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct PBVHPixels {
|
|
|
|
/**
|
|
|
|
* Storage for texture painting on PBVH level.
|
|
|
|
*
|
|
|
|
* Contains #blender::bke::pbvh::pixels::PBVHData
|
|
|
|
*/
|
|
|
|
void *data;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PBVHPixelsNode {
|
|
|
|
/**
|
|
|
|
* Contains triangle/pixel data used during texture painting.
|
|
|
|
*
|
|
|
|
* Contains #blender::bke::pbvh::pixels::NodeData.
|
|
|
|
*/
|
2023-07-27 22:21:34 +02:00
|
|
|
void *node_data = nullptr;
|
2023-07-04 04:55:22 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct PBVHFrustumPlanes {
|
|
|
|
float (*planes)[4];
|
|
|
|
int num_planes;
|
|
|
|
};
|
|
|
|
|
|
|
|
BLI_INLINE BMesh *BKE_pbvh_get_bmesh(PBVH *pbvh)
|
|
|
|
{
|
2024-01-04 21:07:48 +01:00
|
|
|
return ((PBVHPublic *)pbvh)->bm;
|
2023-07-04 04:55:22 +02:00
|
|
|
}
|
|
|
|
|
2023-09-26 14:21:07 +02:00
|
|
|
Mesh *BKE_pbvh_get_mesh(PBVH *pbvh);
|
|
|
|
|
2023-07-04 04:55:22 +02:00
|
|
|
BLI_INLINE PBVHVertRef BKE_pbvh_make_vref(intptr_t i)
|
|
|
|
{
|
|
|
|
PBVHVertRef ret = {i};
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_INLINE int BKE_pbvh_vertex_to_index(PBVH *pbvh, PBVHVertRef v)
|
|
|
|
{
|
|
|
|
return (BKE_pbvh_type(pbvh) == PBVH_BMESH && v.i != PBVH_REF_NONE ?
|
|
|
|
BM_elem_index_get((BMVert *)(v.i)) :
|
|
|
|
(v.i));
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_INLINE PBVHVertRef BKE_pbvh_index_to_vertex(PBVH *pbvh, int index)
|
|
|
|
{
|
|
|
|
switch (BKE_pbvh_type(pbvh)) {
|
|
|
|
case PBVH_FACES:
|
|
|
|
case PBVH_GRIDS:
|
|
|
|
return BKE_pbvh_make_vref(index);
|
|
|
|
case PBVH_BMESH:
|
|
|
|
return BKE_pbvh_make_vref((intptr_t)BKE_pbvh_get_bmesh(pbvh)->vtable[index]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return BKE_pbvh_make_vref(PBVH_REF_NONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Callbacks */
|
|
|
|
|
2023-12-15 00:20:46 +01:00
|
|
|
namespace blender::bke::pbvh {
|
2023-07-04 04:55:22 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Do a full rebuild with on Mesh data structure.
|
|
|
|
*/
|
2023-12-15 00:20:46 +01:00
|
|
|
PBVH *build_mesh(Mesh *mesh);
|
|
|
|
void update_mesh_pointers(PBVH *pbvh, Mesh *mesh);
|
2023-07-04 04:55:22 +02:00
|
|
|
/**
|
|
|
|
* Do a full rebuild with on Grids data structure.
|
|
|
|
*/
|
2023-12-15 00:20:46 +01:00
|
|
|
PBVH *build_grids(const CCGKey *key, Mesh *mesh, SubdivCCG *subdiv_ccg);
|
2023-07-04 04:55:22 +02:00
|
|
|
/**
|
|
|
|
* Build a PBVH from a BMesh.
|
|
|
|
*/
|
2023-12-15 00:20:46 +01:00
|
|
|
PBVH *build_bmesh(BMesh *bm, BMLog *log, int cd_vert_node_offset, int cd_face_node_offset);
|
|
|
|
|
2023-12-16 04:51:10 +01:00
|
|
|
void update_bmesh_offsets(PBVH *pbvh, int cd_vert_node_offset, int cd_face_node_offset);
|
2023-07-04 04:55:22 +02:00
|
|
|
|
2023-12-16 04:51:10 +01:00
|
|
|
void build_pixels(PBVH *pbvh, Mesh *mesh, Image *image, ImageUser *image_user);
|
|
|
|
void free(PBVH *pbvh);
|
2023-07-04 04:55:22 +02:00
|
|
|
|
|
|
|
/* Hierarchical Search in the BVH, two methods:
|
|
|
|
* - For each hit calling a callback.
|
|
|
|
* - Gather nodes in an array (easy to multi-thread) see blender::bke::pbvh::search_gather.
|
|
|
|
*/
|
|
|
|
|
2023-12-16 16:57:42 +01:00
|
|
|
void search_callback(PBVH &pbvh,
|
|
|
|
FunctionRef<bool(PBVHNode &)> filter_fn,
|
|
|
|
FunctionRef<void(PBVHNode &)> hit_fn);
|
2023-07-04 04:55:22 +02:00
|
|
|
|
|
|
|
/* Ray-cast
|
|
|
|
* the hit callback is called for all leaf nodes intersecting the ray;
|
|
|
|
* it's up to the callback to find the primitive within the leaves that is
|
|
|
|
* hit first */
|
|
|
|
|
2023-12-16 04:51:10 +01:00
|
|
|
void raycast(PBVH *pbvh,
|
2023-12-16 16:57:42 +01:00
|
|
|
FunctionRef<void(PBVHNode &node, float *tmin)> cb,
|
2023-12-16 04:51:10 +01:00
|
|
|
const float ray_start[3],
|
|
|
|
const float ray_normal[3],
|
|
|
|
bool original);
|
|
|
|
|
|
|
|
bool raycast_node(PBVH *pbvh,
|
|
|
|
PBVHNode *node,
|
|
|
|
float (*origco)[3],
|
|
|
|
bool use_origco,
|
|
|
|
Span<int> corner_verts,
|
|
|
|
Span<bool> hide_poly,
|
|
|
|
const float ray_start[3],
|
|
|
|
const float ray_normal[3],
|
|
|
|
IsectRayPrecalc *isect_precalc,
|
|
|
|
float *depth,
|
|
|
|
PBVHVertRef *active_vertex,
|
|
|
|
int *active_face_grid_index,
|
|
|
|
float *face_normal);
|
|
|
|
|
|
|
|
bool bmesh_node_raycast_detail(PBVHNode *node,
|
|
|
|
const float ray_start[3],
|
|
|
|
IsectRayPrecalc *isect_precalc,
|
|
|
|
float *depth,
|
|
|
|
float *r_edge_length);
|
2023-07-04 04:55:22 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* For orthographic cameras, project the far away ray segment points to the root node so
|
|
|
|
* we can have better precision.
|
2023-07-08 03:53:06 +02:00
|
|
|
*
|
|
|
|
* Note: the interval is not guaranteed to lie between ray_start and ray_end; this is
|
|
|
|
* not necessary for orthographic views and is impossible anyhow due to the necessity of
|
|
|
|
* projecting the far clipping plane into the local object space. This works out to
|
|
|
|
* dividing view3d->clip_end by the object scale, which for small object and large
|
|
|
|
* clip_end's can easily lead to floating-point overflows.
|
2023-07-04 04:55:22 +02:00
|
|
|
*/
|
2023-12-16 04:51:10 +01:00
|
|
|
void clip_ray_ortho(
|
2023-07-04 04:55:22 +02:00
|
|
|
PBVH *pbvh, bool original, float ray_start[3], float ray_end[3], float ray_normal[3]);
|
|
|
|
|
2023-12-16 04:51:10 +01:00
|
|
|
void find_nearest_to_ray(PBVH *pbvh,
|
2023-12-16 16:57:42 +01:00
|
|
|
const FunctionRef<void(PBVHNode &node, float *tmin)> fn,
|
2023-12-16 04:51:10 +01:00
|
|
|
const float ray_start[3],
|
|
|
|
const float ray_normal[3],
|
|
|
|
bool original);
|
|
|
|
|
|
|
|
bool find_nearest_to_ray_node(PBVH *pbvh,
|
|
|
|
PBVHNode *node,
|
|
|
|
float (*origco)[3],
|
|
|
|
bool use_origco,
|
|
|
|
Span<int> corner_verts,
|
|
|
|
Span<bool> hide_poly,
|
|
|
|
const float ray_start[3],
|
|
|
|
const float ray_normal[3],
|
|
|
|
float *depth,
|
|
|
|
float *dist_sq);
|
2023-07-04 04:55:22 +02:00
|
|
|
|
|
|
|
/* Drawing */
|
2023-12-16 04:51:10 +01:00
|
|
|
void set_frustum_planes(PBVH *pbvh, PBVHFrustumPlanes *planes);
|
|
|
|
void get_frustum_planes(const PBVH *pbvh, PBVHFrustumPlanes *planes);
|
|
|
|
|
|
|
|
void draw_cb(const Mesh &mesh,
|
|
|
|
PBVH *pbvh,
|
|
|
|
bool update_only_visible,
|
|
|
|
const PBVHFrustumPlanes &update_frustum,
|
|
|
|
const PBVHFrustumPlanes &draw_frustum,
|
|
|
|
FunctionRef<void(draw::pbvh::PBVHBatches *batches,
|
|
|
|
const draw::pbvh::PBVH_GPU_Args &args)> draw_fn);
|
|
|
|
|
|
|
|
} // namespace blender::bke::pbvh
|
2023-07-04 04:55:22 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the PBVH root's bounding box.
|
|
|
|
*/
|
2023-12-04 17:25:07 +01:00
|
|
|
blender::Bounds<blender::float3> BKE_pbvh_bounding_box(const PBVH *pbvh);
|
2023-07-04 04:55:22 +02:00
|
|
|
|
2023-12-08 22:40:06 +01:00
|
|
|
void BKE_pbvh_sync_visibility_from_verts(PBVH *pbvh, Mesh *mesh);
|
2023-07-04 04:55:22 +02:00
|
|
|
|
2023-12-15 00:20:46 +01:00
|
|
|
namespace blender::bke::pbvh {
|
|
|
|
|
2023-07-04 04:55:22 +02:00
|
|
|
/**
|
|
|
|
* Returns the number of visible quads in the nodes' grids.
|
|
|
|
*/
|
2023-12-15 00:20:46 +01:00
|
|
|
int count_grid_quads(const BitGroupVector<> &grid_visibility,
|
|
|
|
Span<int> grid_indices,
|
|
|
|
int gridsize,
|
|
|
|
int display_gridsize);
|
|
|
|
|
|
|
|
} // namespace blender::bke::pbvh
|
2023-07-04 04:55:22 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Multi-res level, only valid for type == #PBVH_GRIDS.
|
|
|
|
*/
|
|
|
|
const CCGKey *BKE_pbvh_get_grid_key(const PBVH *pbvh);
|
|
|
|
|
|
|
|
int BKE_pbvh_get_grid_num_verts(const PBVH *pbvh);
|
|
|
|
int BKE_pbvh_get_grid_num_faces(const PBVH *pbvh);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Only valid for type == #PBVH_BMESH.
|
|
|
|
*/
|
|
|
|
void BKE_pbvh_bmesh_detail_size_set(PBVH *pbvh, float detail_size);
|
|
|
|
|
|
|
|
enum PBVHTopologyUpdateMode {
|
|
|
|
PBVH_Subdivide = 1,
|
|
|
|
PBVH_Collapse = 2,
|
|
|
|
};
|
|
|
|
ENUM_OPERATORS(PBVHTopologyUpdateMode, PBVH_Collapse);
|
|
|
|
|
2023-12-16 04:51:10 +01:00
|
|
|
namespace blender::bke::pbvh {
|
|
|
|
|
2023-07-04 04:55:22 +02:00
|
|
|
/**
|
|
|
|
* Collapse short edges, subdivide long edges.
|
|
|
|
*/
|
2023-12-16 04:51:10 +01:00
|
|
|
bool bmesh_update_topology(PBVH *pbvh,
|
|
|
|
PBVHTopologyUpdateMode mode,
|
|
|
|
const float center[3],
|
|
|
|
const float view_normal[3],
|
|
|
|
float radius,
|
|
|
|
bool use_frontface,
|
|
|
|
bool use_projected);
|
|
|
|
|
|
|
|
} // namespace blender::bke::pbvh
|
2023-07-04 04:55:22 +02:00
|
|
|
|
|
|
|
/* Node Access */
|
|
|
|
|
|
|
|
void BKE_pbvh_node_mark_update(PBVHNode *node);
|
|
|
|
void BKE_pbvh_node_mark_update_mask(PBVHNode *node);
|
|
|
|
void BKE_pbvh_node_mark_update_color(PBVHNode *node);
|
|
|
|
void BKE_pbvh_node_mark_update_face_sets(PBVHNode *node);
|
|
|
|
void BKE_pbvh_node_mark_update_visibility(PBVHNode *node);
|
|
|
|
void BKE_pbvh_node_mark_rebuild_draw(PBVHNode *node);
|
|
|
|
void BKE_pbvh_node_mark_redraw(PBVHNode *node);
|
2024-01-26 11:24:55 +01:00
|
|
|
void BKE_pbvh_node_mark_positions_update(PBVHNode *node);
|
2023-07-04 04:55:22 +02:00
|
|
|
void BKE_pbvh_node_mark_topology_update(PBVHNode *node);
|
|
|
|
void BKE_pbvh_node_fully_hidden_set(PBVHNode *node, int fully_hidden);
|
2023-12-03 23:37:57 +01:00
|
|
|
bool BKE_pbvh_node_fully_hidden_get(const PBVHNode *node);
|
2023-07-04 04:55:22 +02:00
|
|
|
void BKE_pbvh_node_fully_masked_set(PBVHNode *node, int fully_masked);
|
2023-12-03 23:37:57 +01:00
|
|
|
bool BKE_pbvh_node_fully_masked_get(const PBVHNode *node);
|
2023-07-04 04:55:22 +02:00
|
|
|
void BKE_pbvh_node_fully_unmasked_set(PBVHNode *node, int fully_masked);
|
2023-12-03 23:37:57 +01:00
|
|
|
bool BKE_pbvh_node_fully_unmasked_get(const PBVHNode *node);
|
2023-07-04 04:55:22 +02:00
|
|
|
|
|
|
|
void BKE_pbvh_mark_rebuild_pixels(PBVH *pbvh);
|
|
|
|
|
2023-12-01 20:37:49 +01:00
|
|
|
blender::Span<int> BKE_pbvh_node_get_grid_indices(const PBVHNode &node);
|
|
|
|
|
2023-11-09 11:00:58 +01:00
|
|
|
int BKE_pbvh_node_num_unique_verts(const PBVH &pbvh, const PBVHNode &node);
|
2023-10-12 14:51:46 +02:00
|
|
|
blender::Span<int> BKE_pbvh_node_get_vert_indices(const PBVHNode *node);
|
|
|
|
blender::Span<int> BKE_pbvh_node_get_unique_vert_indices(const PBVHNode *node);
|
2024-03-12 19:55:04 +01:00
|
|
|
blender::Span<int> BKE_pbvh_node_get_corner_indices(const PBVHNode *node);
|
2023-12-06 23:30:11 +01:00
|
|
|
|
2023-12-14 21:31:12 +01:00
|
|
|
namespace blender::bke::pbvh {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gather the indices of all faces (not triangles) used by the node.
|
|
|
|
* For convenience, pass a reference to the data in the result.
|
|
|
|
*/
|
|
|
|
Span<int> node_face_indices_calc_mesh(const PBVH &pbvh, const PBVHNode &node, Vector<int> &faces);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gather the indices of all base mesh faces in the node.
|
|
|
|
* For convenience, pass a reference to the data in the result.
|
|
|
|
*/
|
|
|
|
Span<int> node_face_indices_calc_grids(const PBVH &pbvh, const PBVHNode &node, Vector<int> &faces);
|
|
|
|
|
|
|
|
} // namespace blender::bke::pbvh
|
|
|
|
|
2023-12-04 17:25:07 +01:00
|
|
|
blender::Bounds<blender::float3> BKE_pbvh_node_get_BB(const PBVHNode *node);
|
|
|
|
blender::Bounds<blender::float3> BKE_pbvh_node_get_original_BB(const PBVHNode *node);
|
2023-07-04 04:55:22 +02:00
|
|
|
|
2023-12-03 23:37:57 +01:00
|
|
|
float BKE_pbvh_node_get_tmin(const PBVHNode *node);
|
2023-07-04 04:55:22 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test if AABB is at least partially inside the #PBVHFrustumPlanes volume.
|
|
|
|
*/
|
2023-12-03 23:37:57 +01:00
|
|
|
bool BKE_pbvh_node_frustum_contain_AABB(const PBVHNode *node, const PBVHFrustumPlanes *frustum);
|
2023-07-04 04:55:22 +02:00
|
|
|
/**
|
|
|
|
* Test if AABB is at least partially outside the #PBVHFrustumPlanes volume.
|
|
|
|
*/
|
2023-12-03 23:37:57 +01:00
|
|
|
bool BKE_pbvh_node_frustum_exclude_AABB(const PBVHNode *node, const PBVHFrustumPlanes *frustum);
|
2023-07-04 04:55:22 +02:00
|
|
|
|
2023-10-19 14:18:15 +02:00
|
|
|
const blender::Set<BMVert *, 0> &BKE_pbvh_bmesh_node_unique_verts(PBVHNode *node);
|
|
|
|
const blender::Set<BMVert *, 0> &BKE_pbvh_bmesh_node_other_verts(PBVHNode *node);
|
|
|
|
const blender::Set<BMFace *, 0> &BKE_pbvh_bmesh_node_faces(PBVHNode *node);
|
|
|
|
|
2023-07-04 04:55:22 +02:00
|
|
|
/**
|
|
|
|
* In order to perform operations on the original node coordinates
|
|
|
|
* (currently just ray-cast), store the node's triangles and vertices.
|
|
|
|
*
|
|
|
|
* Skips triangles that are hidden.
|
|
|
|
*/
|
|
|
|
void BKE_pbvh_bmesh_node_save_orig(BMesh *bm, BMLog *log, PBVHNode *node, bool use_original);
|
|
|
|
void BKE_pbvh_bmesh_after_stroke(PBVH *pbvh);
|
|
|
|
|
2023-12-14 20:56:25 +01:00
|
|
|
namespace blender::bke::pbvh {
|
|
|
|
void update_bounds(PBVH &pbvh, int flags);
|
|
|
|
void update_mask(PBVH &pbvh);
|
|
|
|
void update_visibility(PBVH &pbvh);
|
|
|
|
void update_normals(PBVH &pbvh, SubdivCCG *subdiv_ccg);
|
|
|
|
} // namespace blender::bke::pbvh
|
2023-07-04 04:55:22 +02:00
|
|
|
|
2023-12-04 17:25:07 +01:00
|
|
|
blender::Bounds<blender::float3> BKE_pbvh_redraw_BB(PBVH *pbvh);
|
2023-12-18 21:06:45 +01:00
|
|
|
namespace blender::bke::pbvh {
|
|
|
|
IndexMask nodes_to_face_selection_grids(const SubdivCCG &subdiv_ccg,
|
|
|
|
Span<const PBVHNode *> nodes,
|
|
|
|
IndexMaskMemory &memory);
|
|
|
|
}
|
2023-12-04 03:21:03 +01:00
|
|
|
void BKE_pbvh_grids_update(PBVH *pbvh, const CCGKey *key);
|
2023-07-04 04:55:22 +02:00
|
|
|
void BKE_pbvh_subdiv_cgg_set(PBVH *pbvh, SubdivCCG *subdiv_ccg);
|
|
|
|
|
2023-11-16 18:29:52 +01:00
|
|
|
void BKE_pbvh_vert_coords_apply(PBVH *pbvh, blender::Span<blender::float3> vert_positions);
|
2023-12-03 23:37:57 +01:00
|
|
|
bool BKE_pbvh_is_deformed(const PBVH *pbvh);
|
2023-07-04 04:55:22 +02:00
|
|
|
|
|
|
|
/* Vertex Iterator. */
|
|
|
|
|
|
|
|
/* This iterator has quite a lot of code, but it's designed to:
|
|
|
|
* - allow the compiler to eliminate dead code and variables
|
|
|
|
* - spend most of the time in the relatively simple inner loop */
|
|
|
|
|
|
|
|
/* NOTE: PBVH_ITER_ALL does not skip hidden vertices,
|
|
|
|
* PBVH_ITER_UNIQUE does */
|
|
|
|
#define PBVH_ITER_ALL 0
|
|
|
|
#define PBVH_ITER_UNIQUE 1
|
|
|
|
|
|
|
|
struct PBVHVertexIter {
|
|
|
|
/* iteration */
|
|
|
|
int g;
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
int gx;
|
|
|
|
int gy;
|
|
|
|
int i;
|
|
|
|
int index;
|
|
|
|
PBVHVertRef vertex;
|
|
|
|
|
|
|
|
/* grid */
|
|
|
|
CCGKey key;
|
2023-11-29 18:34:24 +01:00
|
|
|
CCGElem *const *grids;
|
2023-07-04 04:55:22 +02:00
|
|
|
CCGElem *grid;
|
2023-12-02 20:05:29 +01:00
|
|
|
const blender::BitGroupVector<> *grid_hidden;
|
|
|
|
std::optional<blender::BoundedBitSpan> gh;
|
2023-07-27 22:14:08 +02:00
|
|
|
const int *grid_indices;
|
2023-07-04 04:55:22 +02:00
|
|
|
int totgrid;
|
|
|
|
int gridsize;
|
|
|
|
|
|
|
|
/* mesh */
|
2023-07-11 21:01:53 +02:00
|
|
|
blender::MutableSpan<blender::float3> vert_positions;
|
2023-08-24 16:47:55 +02:00
|
|
|
blender::Span<blender::float3> vert_normals;
|
2023-07-04 04:55:22 +02:00
|
|
|
const bool *hide_vert;
|
|
|
|
int totvert;
|
|
|
|
const int *vert_indices;
|
2023-09-26 14:21:07 +02:00
|
|
|
const float *vmask;
|
2023-07-04 04:55:22 +02:00
|
|
|
bool is_mesh;
|
|
|
|
|
|
|
|
/* bmesh */
|
2023-10-19 14:18:15 +02:00
|
|
|
std::optional<blender::Set<BMVert *, 0>::Iterator> bm_unique_verts;
|
|
|
|
std::optional<blender::Set<BMVert *, 0>::Iterator> bm_unique_verts_end;
|
|
|
|
std::optional<blender::Set<BMVert *, 0>::Iterator> bm_other_verts;
|
|
|
|
std::optional<blender::Set<BMVert *, 0>::Iterator> bm_other_verts_end;
|
2023-07-04 04:55:22 +02:00
|
|
|
CustomData *bm_vdata;
|
|
|
|
int cd_vert_mask_offset;
|
|
|
|
|
|
|
|
/* result: these are all computed in the macro, but we assume
|
|
|
|
* that compiler optimization's will skip the ones we don't use */
|
|
|
|
BMVert *bm_vert;
|
|
|
|
float *co;
|
2023-08-24 16:47:55 +02:00
|
|
|
const float *no;
|
|
|
|
const float *fno;
|
2023-09-28 00:21:21 +02:00
|
|
|
float mask;
|
2023-07-04 04:55:22 +02:00
|
|
|
bool visible;
|
|
|
|
};
|
|
|
|
|
|
|
|
void pbvh_vertex_iter_init(PBVH *pbvh, PBVHNode *node, PBVHVertexIter *vi, int mode);
|
|
|
|
|
|
|
|
#define BKE_pbvh_vertex_iter_begin(pbvh, node, vi, mode) \
|
|
|
|
pbvh_vertex_iter_init(pbvh, node, &vi, mode); \
|
|
|
|
\
|
|
|
|
for (vi.i = 0, vi.g = 0; vi.g < vi.totgrid; vi.g++) { \
|
|
|
|
if (vi.grids) { \
|
|
|
|
vi.width = vi.gridsize; \
|
|
|
|
vi.height = vi.gridsize; \
|
|
|
|
vi.index = vi.vertex.i = vi.grid_indices[vi.g] * vi.key.grid_area - 1; \
|
2023-09-28 14:56:26 +02:00
|
|
|
vi.grid = CCG_elem_offset(&vi.key, vi.grids[vi.grid_indices[vi.g]], -1); \
|
2023-07-04 04:55:22 +02:00
|
|
|
if (mode == PBVH_ITER_UNIQUE) { \
|
2023-12-02 20:05:29 +01:00
|
|
|
if (vi.grid_hidden) { \
|
|
|
|
vi.gh.emplace((*vi.grid_hidden)[vi.grid_indices[vi.g]]); \
|
|
|
|
} \
|
|
|
|
else { \
|
|
|
|
vi.gh.reset(); \
|
|
|
|
} \
|
2023-07-04 04:55:22 +02:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
else { \
|
|
|
|
vi.width = vi.totvert; \
|
|
|
|
vi.height = 1; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
for (vi.gy = 0; vi.gy < vi.height; vi.gy++) { \
|
|
|
|
for (vi.gx = 0; vi.gx < vi.width; vi.gx++, vi.i++) { \
|
|
|
|
if (vi.grid) { \
|
2023-09-28 14:56:26 +02:00
|
|
|
vi.grid = CCG_elem_next(&vi.key, vi.grid); \
|
2023-07-04 04:55:22 +02:00
|
|
|
vi.co = CCG_elem_co(&vi.key, vi.grid); \
|
|
|
|
vi.fno = CCG_elem_no(&vi.key, vi.grid); \
|
2023-09-28 00:21:21 +02:00
|
|
|
vi.mask = vi.key.has_mask ? *CCG_elem_mask(&vi.key, vi.grid) : 0.0f; \
|
2023-07-04 04:55:22 +02:00
|
|
|
vi.index++; \
|
|
|
|
vi.vertex.i++; \
|
|
|
|
vi.visible = true; \
|
|
|
|
if (vi.gh) { \
|
2023-12-02 20:05:29 +01:00
|
|
|
if ((*vi.gh)[vi.gy * vi.gridsize + vi.gx]) { \
|
2023-07-04 04:55:22 +02:00
|
|
|
continue; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
} \
|
2023-07-11 21:01:53 +02:00
|
|
|
else if (!vi.vert_positions.is_empty()) { \
|
2023-07-04 04:55:22 +02:00
|
|
|
vi.visible = !(vi.hide_vert && vi.hide_vert[vi.vert_indices[vi.gx]]); \
|
|
|
|
if (mode == PBVH_ITER_UNIQUE && !vi.visible) { \
|
|
|
|
continue; \
|
|
|
|
} \
|
|
|
|
vi.co = vi.vert_positions[vi.vert_indices[vi.gx]]; \
|
|
|
|
vi.no = vi.vert_normals[vi.vert_indices[vi.gx]]; \
|
|
|
|
vi.index = vi.vertex.i = vi.vert_indices[vi.i]; \
|
2023-09-28 00:21:21 +02:00
|
|
|
vi.mask = vi.vmask ? vi.vmask[vi.index] : 0.0f; \
|
2023-07-04 04:55:22 +02:00
|
|
|
} \
|
|
|
|
else { \
|
2023-10-19 14:18:15 +02:00
|
|
|
if (*vi.bm_unique_verts != *vi.bm_unique_verts_end) { \
|
|
|
|
vi.bm_vert = **vi.bm_unique_verts; \
|
|
|
|
(*vi.bm_unique_verts)++; \
|
2023-07-04 04:55:22 +02:00
|
|
|
} \
|
|
|
|
else { \
|
2023-10-19 14:18:15 +02:00
|
|
|
vi.bm_vert = **vi.bm_other_verts; \
|
|
|
|
(*vi.bm_other_verts)++; \
|
2023-07-04 04:55:22 +02:00
|
|
|
} \
|
|
|
|
vi.visible = !BM_elem_flag_test_bool(vi.bm_vert, BM_ELEM_HIDDEN); \
|
|
|
|
if (mode == PBVH_ITER_UNIQUE && !vi.visible) { \
|
|
|
|
continue; \
|
|
|
|
} \
|
|
|
|
vi.co = vi.bm_vert->co; \
|
|
|
|
vi.fno = vi.bm_vert->no; \
|
|
|
|
vi.vertex = BKE_pbvh_make_vref((intptr_t)vi.bm_vert); \
|
|
|
|
vi.index = BM_elem_index_get(vi.bm_vert); \
|
2023-09-28 00:21:21 +02:00
|
|
|
vi.mask = BM_ELEM_CD_GET_FLOAT(vi.bm_vert, vi.cd_vert_mask_offset); \
|
2023-07-04 04:55:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#define BKE_pbvh_vertex_iter_end \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
((void)0)
|
|
|
|
|
|
|
|
#define PBVH_FACE_ITER_VERTS_RESERVED 8
|
|
|
|
|
2023-11-09 11:00:58 +01:00
|
|
|
blender::MutableSpan<PBVHProxyNode> BKE_pbvh_node_get_proxies(PBVHNode *node);
|
2023-07-04 04:55:22 +02:00
|
|
|
void BKE_pbvh_node_free_proxies(PBVHNode *node);
|
2023-11-09 11:00:58 +01:00
|
|
|
PBVHProxyNode &BKE_pbvh_node_add_proxy(PBVH &pbvh, PBVHNode &node);
|
2023-07-04 04:55:22 +02:00
|
|
|
void BKE_pbvh_node_get_bm_orco_data(PBVHNode *node,
|
|
|
|
int (**r_orco_tris)[3],
|
|
|
|
int *r_orco_tris_num,
|
|
|
|
float (**r_orco_coords)[3],
|
|
|
|
BMVert ***r_orco_verts);
|
|
|
|
|
|
|
|
bool pbvh_has_mask(const PBVH *pbvh);
|
|
|
|
|
|
|
|
bool pbvh_has_face_sets(PBVH *pbvh);
|
|
|
|
|
2023-12-04 05:43:13 +01:00
|
|
|
blender::Span<blender::float3> BKE_pbvh_get_vert_positions(const PBVH *pbvh);
|
|
|
|
blender::MutableSpan<blender::float3> BKE_pbvh_get_vert_positions(PBVH *pbvh);
|
|
|
|
blender::Span<blender::float3> BKE_pbvh_get_vert_normals(const PBVH *pbvh);
|
2023-07-04 04:55:22 +02:00
|
|
|
|
|
|
|
PBVHColorBufferNode *BKE_pbvh_node_color_buffer_get(PBVHNode *node);
|
|
|
|
void BKE_pbvh_node_color_buffer_free(PBVH *pbvh);
|
2023-12-20 19:13:16 +01:00
|
|
|
bool BKE_pbvh_get_color_layer(Mesh *mesh,
|
|
|
|
CustomDataLayer **r_layer,
|
|
|
|
blender::bke::AttrDomain *r_domain);
|
2023-07-04 04:55:22 +02:00
|
|
|
|
|
|
|
/* Swaps colors at each element in indices (of domain pbvh->vcol_domain)
|
|
|
|
* with values in colors. */
|
|
|
|
void BKE_pbvh_swap_colors(PBVH *pbvh,
|
2023-10-13 09:44:35 +02:00
|
|
|
blender::Span<int> indices,
|
|
|
|
blender::MutableSpan<blender::float4> r_colors);
|
2023-07-04 04:55:22 +02:00
|
|
|
|
|
|
|
/* Stores colors from the elements in indices (of domain pbvh->vcol_domain)
|
|
|
|
* into colors. */
|
|
|
|
void BKE_pbvh_store_colors(PBVH *pbvh,
|
2023-10-13 09:44:35 +02:00
|
|
|
blender::Span<int> indices,
|
|
|
|
blender::MutableSpan<blender::float4> r_colors);
|
2023-07-04 04:55:22 +02:00
|
|
|
|
|
|
|
/* Like BKE_pbvh_store_colors but handles loop->vert conversion */
|
|
|
|
void BKE_pbvh_store_colors_vertex(PBVH *pbvh,
|
2023-10-13 09:44:35 +02:00
|
|
|
blender::Span<int> indices,
|
|
|
|
blender::MutableSpan<blender::float4> r_colors);
|
2023-07-04 04:55:22 +02:00
|
|
|
|
|
|
|
bool BKE_pbvh_is_drawing(const PBVH *pbvh);
|
|
|
|
|
2023-07-11 22:50:27 +02:00
|
|
|
void BKE_pbvh_update_active_vcol(PBVH *pbvh, Mesh *mesh);
|
2023-07-04 04:55:22 +02:00
|
|
|
|
|
|
|
void BKE_pbvh_vertex_color_set(PBVH *pbvh, PBVHVertRef vertex, const float color[4]);
|
|
|
|
void BKE_pbvh_vertex_color_get(const PBVH *pbvh, PBVHVertRef vertex, float r_color[4]);
|
|
|
|
|
|
|
|
void BKE_pbvh_ensure_node_loops(PBVH *pbvh);
|
|
|
|
int BKE_pbvh_debug_draw_gen_get(PBVHNode *node);
|
|
|
|
|
2024-01-05 16:35:39 +01:00
|
|
|
void BKE_pbvh_pmap_set(PBVH *pbvh, blender::GroupedSpan<int> vert_to_face_map);
|
2023-07-04 04:55:22 +02:00
|
|
|
|
|
|
|
namespace blender::bke::pbvh {
|
|
|
|
Vector<PBVHNode *> search_gather(PBVH *pbvh,
|
2023-08-22 21:05:37 +02:00
|
|
|
FunctionRef<bool(PBVHNode &)> scb,
|
2023-07-04 04:55:22 +02:00
|
|
|
PBVHNodeFlags leaf_flag = PBVH_Leaf);
|
|
|
|
Vector<PBVHNode *> gather_proxies(PBVH *pbvh);
|
|
|
|
|
2023-12-03 23:55:43 +01:00
|
|
|
void node_update_mask_mesh(Span<float> mask, PBVHNode &node);
|
|
|
|
void node_update_mask_grids(const CCGKey &key, Span<CCGElem *> grids, PBVHNode &node);
|
|
|
|
void node_update_mask_bmesh(int mask_offset, PBVHNode &node);
|
|
|
|
|
|
|
|
void node_update_visibility_mesh(Span<bool> hide_vert, PBVHNode &node);
|
|
|
|
void node_update_visibility_grids(const BitGroupVector<> &grid_hidden, PBVHNode &node);
|
|
|
|
void node_update_visibility_bmesh(PBVHNode &node);
|
|
|
|
|
2023-12-04 13:55:32 +01:00
|
|
|
void update_node_bounds_mesh(Span<float3> positions, PBVHNode &node);
|
|
|
|
void update_node_bounds_grids(const CCGKey &key, Span<CCGElem *> grids, PBVHNode &node);
|
|
|
|
void update_node_bounds_bmesh(PBVHNode &node);
|
|
|
|
|
2023-07-04 04:55:22 +02:00
|
|
|
} // namespace blender::bke::pbvh
|