2012-12-30 18:25:36 +00:00
|
|
|
/*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup bli
|
2013-09-12 03:02:50 +00:00
|
|
|
*/
|
|
|
|
|
|
2012-12-30 18:25:36 +00:00
|
|
|
/* Axis-aligned bounding box */
|
|
|
|
|
typedef struct {
|
|
|
|
|
float bmin[3], bmax[3];
|
|
|
|
|
} BB;
|
|
|
|
|
|
|
|
|
|
/* Axis-aligned bounding box with centroid */
|
|
|
|
|
typedef struct {
|
|
|
|
|
float bmin[3], bmax[3], bcentroid[3];
|
|
|
|
|
} BBC;
|
|
|
|
|
|
2012-12-30 18:28:36 +00:00
|
|
|
/* Note: this structure is getting large, might want to split it into
|
|
|
|
|
* union'd structs */
|
2012-12-30 18:25:36 +00:00
|
|
|
struct PBVHNode {
|
|
|
|
|
/* Opaque handle for drawing code */
|
2014-01-02 22:22:36 +02:00
|
|
|
struct GPU_PBVH_Buffers *draw_buffers;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-30 18:25:36 +00:00
|
|
|
/* Voxel bounds */
|
|
|
|
|
BB vb;
|
|
|
|
|
BB orig_vb;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-30 18:25:36 +00:00
|
|
|
/* For internal nodes, the offset of the children in the PBVH
|
|
|
|
|
* 'nodes' array. */
|
|
|
|
|
int children_offset;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-30 18:25:36 +00:00
|
|
|
/* Pointer into the PBVH prim_indices array and the number of
|
|
|
|
|
* primitives used by this leaf node.
|
|
|
|
|
*
|
|
|
|
|
* Used for leaf nodes in both mesh- and multires-based PBVHs.
|
|
|
|
|
*/
|
|
|
|
|
int *prim_indices;
|
|
|
|
|
unsigned int totprim;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-30 18:25:36 +00:00
|
|
|
/* Array of indices into the mesh's MVert array. Contains the
|
|
|
|
|
* indices of all vertices used by faces that are within this
|
|
|
|
|
* node's bounding box.
|
|
|
|
|
*
|
|
|
|
|
* Note that a vertex might be used by a multiple faces, and
|
|
|
|
|
* these faces might be in different leaf nodes. Such a vertex
|
|
|
|
|
* will appear in the vert_indices array of each of those leaf
|
|
|
|
|
* nodes.
|
|
|
|
|
*
|
|
|
|
|
* In order to support cases where you want access to multiple
|
|
|
|
|
* nodes' vertices without duplication, the vert_indices array
|
|
|
|
|
* is ordered such that the first part of the array, up to
|
|
|
|
|
* index 'uniq_verts', contains "unique" vertex indices. These
|
|
|
|
|
* vertices might not be truly unique to this node, but if
|
|
|
|
|
* they appear in another node's vert_indices array, they will
|
|
|
|
|
* be above that node's 'uniq_verts' value.
|
|
|
|
|
*
|
|
|
|
|
* Used for leaf nodes in a mesh-based PBVH (not multires.)
|
|
|
|
|
*/
|
2015-07-12 03:49:47 +10:00
|
|
|
const int *vert_indices;
|
2012-12-30 18:25:36 +00:00
|
|
|
unsigned int uniq_verts, face_verts;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-30 18:25:36 +00:00
|
|
|
/* An array mapping face corners into the vert_indices
|
|
|
|
|
* array. The array is sized to match 'totprim', and each of
|
|
|
|
|
* the face's corners gets an index into the vert_indices
|
|
|
|
|
* array, in the same order as the corners in the original
|
2016-07-06 19:15:47 +10:00
|
|
|
* MLoopTri.
|
2012-12-30 18:25:36 +00:00
|
|
|
*
|
|
|
|
|
* Used for leaf nodes in a mesh-based PBVH (not multires.)
|
|
|
|
|
*/
|
2016-07-06 19:15:47 +10:00
|
|
|
const int (*face_vert_indices)[3];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-30 18:25:36 +00:00
|
|
|
/* Indicates whether this node is a leaf or not; also used for
|
|
|
|
|
* marking various updates that need to be applied. */
|
2012-12-30 18:28:36 +00:00
|
|
|
PBVHNodeFlags flag : 16;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-30 18:25:36 +00:00
|
|
|
/* Used for raycasting: how close bb is to the ray point. */
|
|
|
|
|
float tmin;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-30 18:26:11 +00:00
|
|
|
/* Scalar displacements for sculpt mode's layer brush. */
|
|
|
|
|
float *layer_disp;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-30 18:25:36 +00:00
|
|
|
int proxy_count;
|
|
|
|
|
PBVHProxyNode *proxies;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-30 18:28:36 +00:00
|
|
|
/* Dyntopo */
|
2014-04-08 14:45:48 +10:00
|
|
|
GSet *bm_faces;
|
2013-08-25 20:03:45 +00:00
|
|
|
GSet *bm_unique_verts;
|
|
|
|
|
GSet *bm_other_verts;
|
2012-12-30 18:28:36 +00:00
|
|
|
float (*bm_orco)[3];
|
|
|
|
|
int (*bm_ortri)[3];
|
|
|
|
|
int bm_tot_ortri;
|
Sculpt Vertex Colors: Initial implementation
Sculpt Vertex Colors is a painting system that runs inside sculpt mode, reusing all its tools and optimizations. This provides much better performance, easier to maintain code and more advanced features (new brush engine, filters, symmetry options, masks and face sets compatibility...). This is also the initial step for future features like vertex painting in Multires and brushes that can sculpt and paint at the same time.
This commit includes:
- SCULPT_UNDO_COLOR for undo support in sculpt mode
- SCULPT_UPDATE_COLOR and PBVH flags and rendering
- Sculpt Color API functions
- Sculpt capability for sculpt tools (only enabled in the Paint Brush for now)
- Rendering support in workbench (default to Sculpt Vertex Colors except in Vertex Paint)
- Conversion operator between MPropCol (Sculpt Vertex Colors) and MLoopCol (Vertex Paint)
- Remesher reprojection in the Voxel Remehser
- Paint Brush and Smear Brush with color smoothing in alt-smooth mode
- Parameters for the new brush engine (density, opacity, flow, wet paint mixing, tip scale) implemented in Sculpt Vertex Colors
- Color Filter
- Color picker (uses S shortcut, replaces smooth)
- Color selector in the top bar
Reviewed By: brecht
Maniphest Tasks: T72866
Differential Revision: https://developer.blender.org/D5975
2020-06-22 20:05:28 +02:00
|
|
|
|
|
|
|
|
/* Used to store the brush color during a stroke and composite it over the original color */
|
|
|
|
|
PBVHColorBufferNode color_buffer;
|
2012-12-30 18:25:36 +00:00
|
|
|
};
|
|
|
|
|
|
2012-12-30 18:28:36 +00:00
|
|
|
typedef enum {
|
2019-01-15 23:57:49 +11:00
|
|
|
PBVH_DYNTOPO_SMOOTH_SHADING = 1,
|
2012-12-30 18:28:36 +00:00
|
|
|
} PBVHFlags;
|
|
|
|
|
|
|
|
|
|
typedef struct PBVHBMeshLog PBVHBMeshLog;
|
|
|
|
|
|
2012-12-30 18:25:36 +00:00
|
|
|
struct PBVH {
|
|
|
|
|
PBVHType type;
|
2012-12-30 18:28:36 +00:00
|
|
|
PBVHFlags flags;
|
2012-12-30 18:25:36 +00:00
|
|
|
|
|
|
|
|
PBVHNode *nodes;
|
|
|
|
|
int node_mem_count, totnode;
|
|
|
|
|
|
|
|
|
|
int *prim_indices;
|
|
|
|
|
int totprim;
|
|
|
|
|
int totvert;
|
|
|
|
|
|
|
|
|
|
int leaf_limit;
|
|
|
|
|
|
|
|
|
|
/* Mesh data */
|
2019-10-09 19:03:57 +02:00
|
|
|
const struct Mesh *mesh;
|
2012-12-30 18:25:36 +00:00
|
|
|
MVert *verts;
|
2015-07-17 03:36:03 +10:00
|
|
|
const MPoly *mpoly;
|
|
|
|
|
const MLoop *mloop;
|
|
|
|
|
const MLoopTri *looptri;
|
2012-12-30 18:25:36 +00:00
|
|
|
CustomData *vdata;
|
2019-04-16 14:00:16 +02:00
|
|
|
CustomData *ldata;
|
2020-03-05 14:53:23 +01:00
|
|
|
CustomData *pdata;
|
|
|
|
|
|
|
|
|
|
int face_sets_color_seed;
|
2020-03-09 20:10:56 +01:00
|
|
|
int face_sets_color_default;
|
2020-04-01 01:03:20 +02:00
|
|
|
int *face_sets;
|
2012-12-30 18:25:36 +00:00
|
|
|
|
|
|
|
|
/* Grid Data */
|
|
|
|
|
CCGKey gridkey;
|
|
|
|
|
CCGElem **grids;
|
|
|
|
|
void **gridfaces;
|
|
|
|
|
const DMFlagMat *grid_flag_mats;
|
|
|
|
|
int totgrid;
|
2013-07-22 23:20:48 +00:00
|
|
|
BLI_bitmap **grid_hidden;
|
2012-12-30 18:25:36 +00:00
|
|
|
|
|
|
|
|
/* Only used during BVH build and update,
|
|
|
|
|
* don't need to remain valid after */
|
2013-07-22 23:20:48 +00:00
|
|
|
BLI_bitmap *vert_bitmap;
|
2012-12-30 18:25:36 +00:00
|
|
|
|
|
|
|
|
#ifdef PERFCNTRS
|
|
|
|
|
int perf_modified;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* flag are verts/faces deformed */
|
2014-02-03 18:55:59 +11:00
|
|
|
bool deformed;
|
2018-01-15 11:38:56 +01:00
|
|
|
bool show_mask;
|
2020-03-05 14:53:23 +01:00
|
|
|
bool show_face_sets;
|
2020-05-19 17:53:26 +10:00
|
|
|
bool respect_hide;
|
2012-12-30 18:28:36 +00:00
|
|
|
|
|
|
|
|
/* Dynamic topology */
|
|
|
|
|
BMesh *bm;
|
|
|
|
|
float bm_max_edge_len;
|
|
|
|
|
float bm_min_edge_len;
|
2014-04-17 19:02:55 +03:00
|
|
|
int cd_vert_node_offset;
|
|
|
|
|
int cd_face_node_offset;
|
2012-12-30 18:28:36 +00:00
|
|
|
|
2020-03-12 17:51:39 +01:00
|
|
|
float planes[6][4];
|
|
|
|
|
int num_planes;
|
|
|
|
|
|
2012-12-30 18:28:36 +00:00
|
|
|
struct BMLog *bm_log;
|
2020-04-01 01:03:20 +02:00
|
|
|
struct SubdivCCG *subdiv_ccg;
|
2012-12-30 18:25:36 +00:00
|
|
|
};
|
|
|
|
|
|
2012-12-30 18:28:36 +00:00
|
|
|
/* pbvh.c */
|
|
|
|
|
void BB_reset(BB *bb);
|
|
|
|
|
void BB_expand(BB *bb, const float co[3]);
|
|
|
|
|
void BB_expand_with_bb(BB *bb, BB *bb2);
|
|
|
|
|
void BBC_update_centroid(BBC *bbc);
|
|
|
|
|
int BB_widest_axis(const BB *bb);
|
|
|
|
|
void pbvh_grow_nodes(PBVH *bvh, int totnode);
|
2015-07-17 04:15:24 +10:00
|
|
|
bool ray_face_intersection_quad(const float ray_start[3],
|
2019-06-17 09:16:13 -03:00
|
|
|
struct IsectRayPrecalc *isect_precalc,
|
2021-04-28 13:13:43 -05:00
|
|
|
const float t0[3],
|
|
|
|
|
const float t1[3],
|
|
|
|
|
const float t2[3],
|
|
|
|
|
const float t3[3],
|
2017-10-05 21:06:04 +11:00
|
|
|
float *depth);
|
2015-07-17 04:15:24 +10:00
|
|
|
bool ray_face_intersection_tri(const float ray_start[3],
|
2019-06-17 09:16:13 -03:00
|
|
|
struct IsectRayPrecalc *isect_precalc,
|
2021-04-29 21:25:34 -05:00
|
|
|
const float t0[3],
|
|
|
|
|
const float t1[3],
|
|
|
|
|
const float t2[3],
|
2017-10-05 21:06:04 +11:00
|
|
|
float *depth);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-10-05 21:16:25 +11:00
|
|
|
bool ray_face_nearest_quad(const float ray_start[3],
|
|
|
|
|
const float ray_normal[3],
|
2021-04-28 13:13:43 -05:00
|
|
|
const float t0[3],
|
|
|
|
|
const float t1[3],
|
|
|
|
|
const float t2[3],
|
|
|
|
|
const float t3[3],
|
2017-10-05 21:16:25 +11:00
|
|
|
float *r_depth,
|
|
|
|
|
float *r_dist_sq);
|
|
|
|
|
bool ray_face_nearest_tri(const float ray_start[3],
|
|
|
|
|
const float ray_normal[3],
|
2021-04-28 13:13:43 -05:00
|
|
|
const float t0[3],
|
|
|
|
|
const float t1[3],
|
|
|
|
|
const float t2[3],
|
2017-10-05 21:16:25 +11:00
|
|
|
float *r_depth,
|
|
|
|
|
float *r_dist_sq);
|
|
|
|
|
|
2012-12-30 18:28:36 +00:00
|
|
|
void pbvh_update_BB_redraw(PBVH *bvh, PBVHNode **nodes, int totnode, int flag);
|
|
|
|
|
|
|
|
|
|
/* pbvh_bmesh.c */
|
2014-04-08 14:45:48 +10:00
|
|
|
bool pbvh_bmesh_node_raycast(PBVHNode *node,
|
2014-03-24 12:59:36 +11:00
|
|
|
const float ray_start[3],
|
2019-08-30 16:27:31 +02:00
|
|
|
const float ray_normal[3],
|
2019-06-17 09:16:13 -03:00
|
|
|
struct IsectRayPrecalc *isect_precalc,
|
2014-03-24 12:59:36 +11:00
|
|
|
float *dist,
|
2019-08-30 16:27:31 +02:00
|
|
|
bool use_original,
|
|
|
|
|
int *r_active_vertex_index,
|
|
|
|
|
float *r_face_normal);
|
2017-10-05 21:16:25 +11:00
|
|
|
bool pbvh_bmesh_node_nearest_to_ray(PBVHNode *node,
|
|
|
|
|
const float ray_start[3],
|
|
|
|
|
const float ray_normal[3],
|
|
|
|
|
float *depth,
|
|
|
|
|
float *dist_sq,
|
|
|
|
|
bool use_original);
|
2014-03-24 12:59:36 +11:00
|
|
|
|
2012-12-30 18:28:36 +00:00
|
|
|
void pbvh_bmesh_normals_update(PBVHNode **nodes, int totnode);
|