2023-08-15 16:20:26 +02:00
|
|
|
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
Sculpt: Multithreading & PBVH Changes
* Sculpting, normal update and bounding box code is now multithreaded
using OpenMP.
* Fix a number of update issues: normals on node boundaries, outdated
bounding boxes, partial redraw, .. . There's probably still a few
left, but should be better now.
* Clicking once now does a single paint instead of two (was also
painting on mouse up event).
* Smooth shading now is enabled for the full mesh when the first face
uses it (so it can be tested at least).
Implementation Notes:
* PBVH search can now be done either using a callback or bt gathering the
nodes in an array. The latter makes multithreading with OpenMP easier.
* Normals update code is now inside PBVH, was doing it per node before but
should do all faces first and only then vertices.
* Instead of using search modes + 1 modified flag, now nodes get 4 flags
to indicate what needs to be updated for them, found that this makes it
easier for me to understand the code and fix update bugs.
* PBVHNode is now exposed as an abstract type, I think this makes it more
clear what is happening than having it's data passed as part of callback
functions.
* Active_verts list was replaced by looping over nodes and the vertices
inside them. However the grab brush still uses the active_verts system,
will fix that later.
* Some micro-optimizations, like avoiding a few multiplications/divisions,
using local variables instead of pointers, or looping over fewer vertices
to update the bounding boxes.
2009-11-02 19:47:03 +01:00
|
|
|
|
2012-12-30 19:31:31 +01:00
|
|
|
#pragma once
|
Sculpt: Multithreading & PBVH Changes
* Sculpting, normal update and bounding box code is now multithreaded
using OpenMP.
* Fix a number of update issues: normals on node boundaries, outdated
bounding boxes, partial redraw, .. . There's probably still a few
left, but should be better now.
* Clicking once now does a single paint instead of two (was also
painting on mouse up event).
* Smooth shading now is enabled for the full mesh when the first face
uses it (so it can be tested at least).
Implementation Notes:
* PBVH search can now be done either using a callback or bt gathering the
nodes in an array. The latter makes multithreading with OpenMP easier.
* Normals update code is now inside PBVH, was doing it per node before but
should do all faces first and only then vertices.
* Instead of using search modes + 1 modified flag, now nodes get 4 flags
to indicate what needs to be updated for them, found that this makes it
easier for me to understand the code and fix update bugs.
* PBVHNode is now exposed as an abstract type, I think this makes it more
clear what is happening than having it's data passed as part of callback
functions.
* Active_verts list was replaced by looping over nodes and the vertices
inside them. However the grab brush still uses the active_verts system,
will fix that later.
* Some micro-optimizations, like avoiding a few multiplications/divisions,
using local variables instead of pointers, or looping over fewer vertices
to update the bounding boxes.
2009-11-02 19:47:03 +01:00
|
|
|
|
2019-02-17 22:08:12 +01:00
|
|
|
/** \file
|
|
|
|
* \ingroup bke
|
2023-12-26 16:45:53 +01:00
|
|
|
* \brief External data structures for PBVH. Does not include internal data structures.
|
2011-02-18 14:58:08 +01:00
|
|
|
*/
|
|
|
|
|
2023-07-04 04:55:22 +02:00
|
|
|
#include "BLI_utildefines.h"
|
2019-10-09 16:27:04 +02:00
|
|
|
|
Sculpt: Multithreading & PBVH Changes
* Sculpting, normal update and bounding box code is now multithreaded
using OpenMP.
* Fix a number of update issues: normals on node boundaries, outdated
bounding boxes, partial redraw, .. . There's probably still a few
left, but should be better now.
* Clicking once now does a single paint instead of two (was also
painting on mouse up event).
* Smooth shading now is enabled for the full mesh when the first face
uses it (so it can be tested at least).
Implementation Notes:
* PBVH search can now be done either using a callback or bt gathering the
nodes in an array. The latter makes multithreading with OpenMP easier.
* Normals update code is now inside PBVH, was doing it per node before but
should do all faces first and only then vertices.
* Instead of using search modes + 1 modified flag, now nodes get 4 flags
to indicate what needs to be updated for them, found that this makes it
easier for me to understand the code and fix update bugs.
* PBVHNode is now exposed as an abstract type, I think this makes it more
clear what is happening than having it's data passed as part of callback
functions.
* Active_verts list was replaced by looping over nodes and the vertices
inside them. However the grab brush still uses the active_verts system,
will fix that later.
* Some micro-optimizations, like avoiding a few multiplications/divisions,
using local variables instead of pointers, or looping over fewer vertices
to update the bounding boxes.
2009-11-02 19:47:03 +01:00
|
|
|
struct PBVHNode;
|
2023-07-04 04:55:22 +02:00
|
|
|
struct BMesh;
|
2009-10-27 20:53:34 +01:00
|
|
|
|
2023-11-16 12:00:12 +01:00
|
|
|
enum PBVHType {
|
2022-07-30 04:01:32 +02:00
|
|
|
PBVH_FACES,
|
|
|
|
PBVH_GRIDS,
|
|
|
|
PBVH_BMESH,
|
2023-11-16 12:00:12 +01:00
|
|
|
};
|
2022-07-30 04:01:32 +02:00
|
|
|
|
2024-01-05 17:16:57 +01:00
|
|
|
/* #PBVHNodeFlags is needed by `DRW_render.hh` and `draw_cache.cc`. */
|
2023-11-16 12:00:12 +01:00
|
|
|
enum PBVHNodeFlags {
|
2023-07-04 04:55:22 +02:00
|
|
|
PBVH_Leaf = 1 << 0,
|
2022-07-30 04:01:32 +02:00
|
|
|
|
2023-07-04 04:55:22 +02:00
|
|
|
PBVH_UpdateNormals = 1 << 1,
|
|
|
|
PBVH_UpdateBB = 1 << 2,
|
|
|
|
PBVH_UpdateOriginalBB = 1 << 3,
|
|
|
|
PBVH_UpdateDrawBuffers = 1 << 4,
|
|
|
|
PBVH_UpdateRedraw = 1 << 5,
|
|
|
|
PBVH_UpdateMask = 1 << 6,
|
|
|
|
PBVH_UpdateVisibility = 1 << 8,
|
2022-07-30 04:01:32 +02:00
|
|
|
|
2023-07-04 04:55:22 +02:00
|
|
|
PBVH_RebuildDrawBuffers = 1 << 9,
|
|
|
|
PBVH_FullyHidden = 1 << 10,
|
|
|
|
PBVH_FullyMasked = 1 << 11,
|
|
|
|
PBVH_FullyUnmasked = 1 << 12,
|
|
|
|
|
|
|
|
PBVH_UpdateTopology = 1 << 13,
|
|
|
|
PBVH_UpdateColor = 1 << 14,
|
|
|
|
PBVH_RebuildPixels = 1 << 15,
|
|
|
|
PBVH_TexLeaf = 1 << 16,
|
2023-07-31 03:50:54 +02:00
|
|
|
/** Used internally by `pbvh_bmesh.cc`. */
|
|
|
|
PBVH_TopologyUpdated = 1 << 17,
|
2023-11-16 12:00:12 +01:00
|
|
|
};
|
2023-07-04 04:55:22 +02:00
|
|
|
ENUM_OPERATORS(PBVHNodeFlags, PBVH_TopologyUpdated);
|
2023-01-20 01:53:43 +01:00
|
|
|
|
|
|
|
/* A few C++ methods to play nice with sets and maps. */
|
2023-11-16 11:41:55 +01:00
|
|
|
#define PBVH_REF_CXX_METHODS(Class) \
|
|
|
|
bool operator==(const Class b) const \
|
|
|
|
{ \
|
|
|
|
return i == b.i; \
|
|
|
|
} \
|
|
|
|
uint64_t hash() const \
|
|
|
|
{ \
|
|
|
|
return i; \
|
|
|
|
}
|
2023-01-20 01:53:43 +01:00
|
|
|
|
2023-11-16 12:00:12 +01:00
|
|
|
struct PBVHVertRef {
|
2022-07-30 04:01:32 +02:00
|
|
|
intptr_t i;
|
2023-01-20 01:53:43 +01:00
|
|
|
|
|
|
|
PBVH_REF_CXX_METHODS(PBVHVertRef)
|
2023-11-16 12:00:12 +01:00
|
|
|
};
|
2022-07-30 04:01:32 +02:00
|
|
|
|
|
|
|
#define PBVH_REF_NONE -1LL
|
|
|
|
|
2023-07-04 04:55:22 +02:00
|
|
|
/* Public members of PBVH, used for inlined functions. */
|
|
|
|
struct PBVHPublic {
|
|
|
|
PBVHType type;
|
2023-11-16 12:00:12 +01:00
|
|
|
BMesh *bm;
|
2023-07-04 04:55:22 +02:00
|
|
|
};
|
2019-05-04 01:39:35 +02:00
|
|
|
|
2023-11-16 12:00:12 +01:00
|
|
|
struct PBVH;
|
|
|
|
struct PBVHNode;
|
2019-09-27 14:44:45 +02:00
|
|
|
|
2023-12-26 16:45:53 +01:00
|
|
|
inline PBVHType BKE_pbvh_type(const PBVH *pbvh)
|
2022-07-30 04:01:32 +02:00
|
|
|
{
|
2023-11-16 12:00:12 +01:00
|
|
|
return ((const PBVHPublic *)pbvh)->type;
|
2022-07-30 04:01:32 +02:00
|
|
|
}
|
|
|
|
|
2023-11-09 13:23:41 +01:00
|
|
|
/* Needed for the render engines integration. */
|
2023-07-04 04:55:22 +02:00
|
|
|
void BKE_pbvh_is_drawing_set(PBVH *pbvh, bool val);
|
2022-08-16 02:01:17 +02:00
|
|
|
void BKE_pbvh_draw_debug_cb(PBVH *pbvh,
|
|
|
|
void (*draw_fn)(PBVHNode *node,
|
|
|
|
void *user_data,
|
|
|
|
const float bmin[3],
|
|
|
|
const float bmax[3],
|
|
|
|
PBVHNodeFlags flag),
|
|
|
|
void *user_data);
|