Blender V5.3
BKE_paint.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2009 by Nicholas Bishop. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
10
11#include <variant>
12
13#include "BKE_paint_types.hh"
14
15#include "BLI_array.hh"
16#include "BLI_bit_vector.hh"
17#include "BLI_enum_flags.hh"
20#include "BLI_offset_indices.hh"
21#include "BLI_ordered_edge.hh"
22#include "BLI_set.hh"
23#include "BLI_shared_cache.hh"
24#include "BLI_string_ref.hh"
25#include "BLI_utility_mixins.hh"
26#include "BLI_vector.hh"
27
28#include "BKE_paint_types.hh"
29
30#include "DNA_brush_enums.h"
31#include "DNA_meshdata_types.h"
32#include "DNA_object_enums.h"
33#include "DNA_scene_types.h"
34
35namespace blender {
36
38struct BMFace;
39struct BMLog;
40struct BMVert;
41struct BMesh;
42struct BlendDataReader;
43struct BlendWriter;
44struct Brush;
46struct CurveMapping;
47struct Depsgraph;
48struct EnumPropertyItem;
49namespace bke {
50enum class AttrDomain : int8_t;
51namespace pbvh {
52class Tree;
53}
54} // namespace bke
56namespace expand {
57struct Cache;
58}
59namespace filter {
60struct Cache;
61}
62struct StrokeCache;
63} // namespace ed::sculpt_paint
64struct GHash;
65struct GridPaintMask;
66struct Image;
67struct ImagePool;
68struct ImageUser;
69struct KeyBlock;
70struct Main;
71struct Mesh;
72struct MDeformVert;
74struct Object;
75struct Paint;
76struct PaintCurve;
77enum class PaintMode : int8_t;
79struct Palette;
80struct PaletteColor;
81struct RegionView3D;
82struct Scene;
83struct Sculpt;
84struct SculptSession;
85struct SubdivCCG;
86struct Tex;
87struct ToolSettings;
89struct View3D;
90struct ViewLayer;
91struct bContext;
92struct bToolRef;
93
94/* overlay invalidation */
100#define PAINT_SYMM_AREA_DEFAULT 0
101
108
109#define PAINT_SYMM_AREAS 8
110
121
122/* Palettes. */
123
124Palette *BKE_palette_add(Main *bmain, const char *name);
130void BKE_palette_clear(Palette *palette);
131
132void BKE_palette_color_set(PaletteColor *color, const float rgb[3]);
134
135/* Paint curves. */
136
137PaintCurve *BKE_paint_curve_add(Main *bmain, const char *name);
138
142bool BKE_paint_ensure(ToolSettings *ts, Paint **r_paint);
146void BKE_paint_init(Main *bmain, Scene *sce, PaintMode mode, bool ensure_brushes = true);
153void BKE_paint_copy(const Paint *src, Paint *dst, int flag);
154
159
160void BKE_paint_cavity_curve_preset(Paint *paint, int preset);
161
163
168std::optional<int> BKE_paint_get_brush_type_from_obmode(const Brush *brush, eObjectMode ob_mode);
169std::optional<int> BKE_paint_get_brush_type_from_paintmode(const Brush *brush, PaintMode mode);
170Paint *BKE_paint_get_active(const Main &bmain, Scene *sce, ViewLayer *view_layer);
174
175/* Paint brush retrieval and assignment. */
176
180 bke::paint::AssetCategory asset_category,
181 const char *name);
182
187bool BKE_paint_can_use_brush(const Paint *paint, const Brush *brush);
188
209bool BKE_paint_brush_set(Main *bmain,
210 Paint *paint,
211 const AssetWeakReference &brush_asset_reference);
213bool BKE_paint_brush_set_essentials(Main *bmain, Paint *paint, const char *name);
215 AssetWeakReference &&asset_weak_reference);
218 FunctionRef<void(AssetWeakReference &weak_ref)> fn);
219
220std::optional<AssetWeakReference> BKE_paint_brush_type_default_reference(
221 bke::paint::AssetCategory asset_category, std::optional<int> brush_type);
235
236/* Paint palette. */
237
241
245bool BKE_paint_select_face_test(const Object *ob);
249bool BKE_paint_select_vert_test(const Object *ob);
258bool BKE_paint_select_elem_test(const Object *ob);
263bool BKE_paint_always_hide_test(const Object *ob);
264
265/* Partial visibility. */
266
270bool BKE_paint_is_grid_face_hidden(BoundedBitSpan grid_hidden, int gridsize, int x, int y);
275
276/* Paint masks. */
277
278float BKE_paint_grid_paint_mask(const GridPaintMask *gpm, uint level, uint x, uint y);
279
280void BKE_paint_face_set_overlay_color_get(int face_set, int seed, uchar r_color[4]);
281
282/* Stroke related. */
283
284namespace bke::paint {
285bool supports_scene_size(PaintMode paint_mode, const Brush &brush);
286bool supports_symmetry_tiling(PaintMode paint_mode, const Brush &brush);
287} // namespace bke::paint
288
289/* Random values are generated on each new stroke so each stroke
290 * gets a different starting point in the perlin noise. */
292
294 const Brush &brush,
295 const float mouse_pos[2],
296 PaintMode paint_mode,
297 bool in_stroke,
298 bool is_first_dab);
299void BKE_paint_update_brush_rake_rotation(Paint &paint, const Brush &brush, float rotation);
300
301namespace bke::paint {
302float3 stroke_get_average(const Paint *paint, const Object *ob);
304void stroke_track_location(Paint &paint, float3 location);
305void stroke_set_location(Paint &paint, float3 location);
306} // namespace bke::paint
307
309 const float3 &initial_hsv_jitter,
310 const float distance,
311 const float pressure,
312 const float3 &color);
313
314/* .blend I/O */
315
317void BKE_paint_blend_read_data(BlendDataReader *reader, const Scene *scene, Paint *paint);
318
319/* Data used for displaying extra visuals while using the Pose brush */
324
326 /* Indexed by base mesh vertex index.
327 *
328 * TODO: Evaluate whether a BitVector or a Set works better for memory footprint and lookup. */
330
332};
333
334/* Data used for displaying extra visuals while using the Boundary brush. */
340
342 /* Max distance used to calculate neighborhood information. */
344
345 /* Indexed by vertex, stores the vertex index of its fake neighbor if available. */
347};
348
356
357using ActiveVert = std::variant<std::monostate, int, BMVert *>;
358
359/* Helper return struct for associated data. */
365
367 /* The current active shapekey for the mesh. Only non-null for Type::Mesh */
369
370 /* Edges to adjacent faces. */
374
375 /* Vertices to adjacent edges. */
379
380 /* BMesh for dynamic topology sculpting */
381 BMesh *bm = nullptr;
382 /* Undo/redo log for dynamic topology sculpting */
383 BMLog *bm_log = nullptr;
384
386 /* Limit surface/grids. */
388
389 /* BVH tree acceleration structure */
390 std::unique_ptr<bke::pbvh::Tree> pbvh;
391
392 /* Object is deformed with some modifiers. */
394 /* Coords of deformed mesh but without stroke displacement. */
396 /* Crazy-space deformation matrices. */
398
405
406 /* Pool for texture evaluations. */
407 ImagePool *tex_pool = nullptr;
408
412
413 /* Cursor data and active vertex for tools */
414 std::optional<int> active_face_index;
415 std::optional<int> active_grid_index;
416
417 /* When active, the cursor draws with faded colors, indicating that there is an action
418 * enabled.
419 */
420 bool draw_faded_cursor = false;
421 float cursor_radius = 0.0f;
424 std::optional<float3> cursor_sampled_normal;
426
427 /* TODO(jbakker): Replace rv3d and v3d with ViewContext */
428 RegionView3D *rv3d = nullptr;
429 View3D *v3d = nullptr;
430
431 /* Dynamic mesh preview */
433
434 /* Pose Brush Preview */
435 std::unique_ptr<SculptPoseIKChainPreview> pose_ik_chain_preview;
436
437 /* Boundary Brush Preview */
438 std::unique_ptr<SculptBoundaryPreview> boundary_preview;
439
440 /* "Persistent" positions and normals for multires. (For mesh the
441 * ".sculpt_persistent_co" attribute is used, etc.). */
442 struct {
446
447 /* The stored state for the SubdivCCG at the time of attribute population, used to roughly
448 * determine if the topology when accessed at a current point in time is equivalent to when
449 * it was originally stored. */
450 int grids_num = -1;
451 int grid_size = -1;
453
454 /* Contains information used by tools and brushes that require different logic based on boundary
455 * elements. Typically used for anything which needs to consider neighbor values.
456 *
457 * Not used for Dyntopo */
458 std::unique_ptr<SculptBoundaryInfoCache> boundary_info_cache;
460
461 /* Transform operator */
463 /* TODO: Switch this and other `pivot_rot` to C++, so this can be `Quaternion::identity` */
464 float4 pivot_rot = float4(1.0f, 0.0f, 0.0f, 0.0f);
466
468 float4 init_pivot_rot = float4(1.0f, 0.0f, 0.0f, 0.0f);
470
472 float4 prev_pivot_rot = float4(1.0f, 0.0f, 0.0f, 0.0f);
474
476
481 bool needs_flush_to_id = false;
482
490
494 std::optional<std::string> last_paint_canvas_key = {};
496
497 std::unique_ptr<SculptTopologyIslandCache> topology_island_cache;
498
499 private:
500 /* In general, this value is expected to be valid (non-empty) as long as the cursor is over the
501 * mesh. Changing the underlying mesh type (e.g. enabling dyntopo, changing multires levels)
502 * should invalidate this value.
503 */
504 ActiveVert active_vert_ = {};
505
506 /* This value should always exist except when the cursor has never been over the mesh, or when
507 * the underlying mesh type has changed and the last `active_vert_` value no longer corresponds
508 * to a value that can be correctly interpreted */
509 ActiveVert last_active_vert_ = {};
510
511 public:
514
515 ActiveVert active_vert() const;
516
518
528 int active_vert_index() const;
529 int last_active_vert_index() const;
530
540 float3 active_vert_position(const Depsgraph &depsgraph, const Object &object) const;
541
542 void set_active_vert(ActiveVert vert);
543 void clear_active_elements(bool persist_last_active);
544
552 std::optional<PersistentMultiresData> persistent_multires_data();
553};
554
559
563void BKE_sculptsession_update_for_edit(Depsgraph *depsgraph, Object *ob_orig, bool is_paint_tool);
565void BKE_sculptsession_update_after_eval(Depsgraph *depsgraph, Object *ob_eval);
566
571bool BKE_sculptsession_use_pbvh_draw(const Object *ob, const RegionView3D *rv3d);
572
578
584int BKE_sculpt_get_grid_num_verts(const Object &object);
585int BKE_sculpt_get_grid_num_faces(const Object &object);
586
595void BKE_sculpt_mask_layers_ensure(Depsgraph *depsgraph,
596 Main *bmain,
597 Object *ob,
599
601
602namespace bke::object {
603
604pbvh::Tree &pbvh_ensure(Depsgraph &depsgraph, Object &object);
605
612pbvh::Tree *pbvh_get(Object &object);
613const pbvh::Tree *pbvh_get(const Object &object);
614
615} // namespace bke::object
616bool BKE_object_sculpt_use_dyntopo(const Object *object);
617
618/* paint_canvas.cc */
619
620using CanvasImageUser = std::variant<ImageUser, ImageUser *>;
621using CanvasImageData = std::pair<Image *, CanvasImageUser>;
622
627std::string BKE_paint_canvas_key_get(ImagePaintSettings &settings, Object *ob);
628
629std::optional<CanvasImageData> BKE_paint_canvas_image_get(const ImagePaintSettings &settings,
630 Object &object);
631std::optional<StringRef> BKE_paint_canvas_uvmap_name_get(const ImagePaintSettings &settings,
632 Object *ob);
636
637} // namespace blender
#define C
Definition RandGen.cpp:29
NonCopyable(const NonCopyable &other)=delete
NonMovable(NonMovable &&other)=delete
float distance(float, float) RET
ENUM_OPERATORS(Layer::Flags)
pbvh::Tree & pbvh_ensure(Depsgraph &depsgraph, Object &object)
pbvh::Tree * pbvh_get(Object &object)
void stroke_track_location(Paint &paint, float3 location)
bool supports_symmetry_tiling(PaintMode paint_mode, const Brush &brush)
void set_overlay_brush_override(Paint &paint, eOverlayFlags flag)
void stroke_set_location(Paint &paint, float3 location)
void invalidate_overlay_all(Scene &scene)
float3 stroke_get_average(const Paint *paint, const Object *ob)
void reset_overlay_flag(Paint &paint, eOverlayControlFlags flag)
void paint_stroke_reset_location(Paint &paint)
bool supports_scene_size(PaintMode paint_mode, const Brush &brush)
void invalidate_overlay_tex(Scene &scene, const Tex *tex)
void invalidate_cursor_overlay(Scene &scene, CurveMapping *curve)
eOverlayControlFlags get_overlay_flags(const Paint &paint)
void cursor_reinitialize_textures(Paint &paint)
BMesh Iterators.
void BKE_sculptsession_free(Object *ob)
void BKE_palette_color_set(PaletteColor *color, const float rgb[3])
eObjectMode BKE_paint_object_mode_from_paintmode(PaintMode mode)
std::pair< Image *, CanvasImageUser > CanvasImageData
Definition BKE_paint.hh:621
bool BKE_object_sculpt_use_dyntopo(const Object *object)
std::variant< std::monostate, int, BMVert * > ActiveVert
Definition BKE_paint.hh:357
MultiresModifierData * BKE_sculpt_multires_active(const Scene *scene, Object *ob)
unsigned int uint
Definition BKE_text.h:55
void BKE_paint_brushes_set_default_references(ToolSettings *ts)
bool BKE_paint_brush_set_default(Main *bmain, Paint *paint)
std::optional< AssetWeakReference > BKE_paint_brush_type_default_reference(bke::paint::AssetCategory asset_category, std::optional< int > brush_type)
void BKE_sculpt_sync_face_visibility_to_grids(const Mesh &mesh, SubdivCCG &subdiv_ccg)
bool BKE_paint_calculate_rake_rotation(Paint &paint, const Brush &brush, const float mouse_pos[2], PaintMode paint_mode, bool in_stroke, bool is_first_dab)
ePaintSymmetryAreas
Definition BKE_paint.hh:102
@ PAINT_SYMM_AREA_X
Definition BKE_paint.hh:103
@ PAINT_SYMM_AREA_Z
Definition BKE_paint.hh:105
@ PAINT_SYMM_AREA_Y
Definition BKE_paint.hh:104
void BKE_paint_settings_foreach_mode(ToolSettings *ts, FunctionRef< void(Paint &paint)> fn)
void BKE_paint_previous_asset_reference_clear(Paint *paint)
void BKE_sculptsession_update_before_eval(Object *ob_eval)
int BKE_sculpt_get_grid_num_faces(const Object &object)
void BKE_sculptsession_bm_to_me(Object *ob)
void BKE_paint_copy(const Paint *src, Paint *dst, int flag)
void BKE_paint_mesh_automasking_settings_ensure(Paint &paint)
void BKE_sculptsession_free_pbvh(Object &object)
bool BKE_paint_is_grid_face_hidden(BoundedBitSpan grid_hidden, int gridsize, int x, int y)
void BKE_sculpt_mask_layers_ensure(Depsgraph *depsgraph, Main *bmain, Object *ob, MultiresModifierData *mmd)
VecBase< float, 4 > float4
std::optional< int > BKE_paint_get_brush_type_from_paintmode(const Brush *brush, PaintMode mode)
PaintCurve * BKE_paint_curve_add(Main *bmain, const char *name)
std::variant< ImageUser, ImageUser * > CanvasImageUser
Definition BKE_paint.hh:620
void BKE_palette_color_sync_legacy(PaletteColor *color)
Brush * BKE_paint_brush_from_essentials(Main *bmain, bke::paint::AssetCategory asset_category, const char *name)
unsigned char uchar
Definition BKE_text.h:58
void BKE_sculptsession_update_after_eval(Depsgraph *depsgraph, Object *ob_eval)
bool BKE_paint_select_elem_test(const Object *ob)
void BKE_paint_blend_read_data(BlendDataReader *reader, const Scene *scene, Paint *paint)
void BKE_paint_brushes_ensure(Main *bmain, Paint *paint)
Palette * BKE_paint_palette(Paint *paint)
float3 BKE_paint_seed_hsv_jitter()
void BKE_paint_init(Main *bmain, Scene *sce, PaintMode mode, bool ensure_brushes=true)
CurveMapping * BKE_paint_default_curve_inverted()
Definition scene.cc:166
int BKE_sculpt_get_grid_num_verts(const Object &object)
PaintMode BKE_paintmode_get_from_tool(const bToolRef *tref)
CurveMapping * BKE_sculpt_default_cavity_curve()
Definition scene.cc:142
void BKE_paint_foreach_asset_weak_reference(Paint &paint, FunctionRef< void(AssetWeakReference &weak_ref)> fn)
std::optional< StringRef > BKE_paint_canvas_uvmap_name_get(const ImagePaintSettings &settings, Object *ob)
bool BKE_paint_always_hide_test(const Object *ob)
bool BKE_paint_brush_set(Paint *paint, Brush *brush)
void BKE_paint_cavity_curve_preset(Paint *paint, int preset)
void BKE_paint_update_brush_rake_rotation(Paint &paint, const Brush &brush, float rotation)
bool BKE_paint_select_face_test(const Object *ob)
void BKE_paint_previous_asset_reference_set(Paint *paint, AssetWeakReference &&asset_weak_reference)
float BKE_paint_grid_paint_mask(const GridPaintMask *gpm, uint level, uint x, uint y)
void BKE_sculpt_color_layer_create_if_needed(Object *object)
void BKE_palette_color_remove(Palette *palette, PaletteColor *color)
void BKE_paint_curve_clamp_endpoint_add_index(PaintCurve *pc, int add_index)
std::optional< CanvasImageData > BKE_paint_canvas_image_get(const ImagePaintSettings &settings, Object &object)
PaletteColor * BKE_palette_color_add(Palette *palette)
void BKE_sculptsession_free_deformMats(SculptSession *ss)
const Brush * BKE_paint_brush_for_read(const Paint *paint)
const EnumPropertyItem * BKE_paint_get_tool_enum_from_paintmode(PaintMode mode)
bool BKE_sculptsession_use_pbvh_draw(const Object *ob, const RegionView3D *rv3d)
bool BKE_paint_can_use_brush(const Paint *paint, const Brush *brush)
void BKE_paint_free(Paint *paint)
Paint * BKE_paint_get_active_from_context(const bContext *C)
void BKE_paint_face_set_overlay_color_get(int face_set, int seed, uchar r_color[4])
Paint * BKE_paint_get_active_from_paintmode(Scene *sce, PaintMode mode)
bool BKE_paint_is_bmesh_face_hidden(const BMFace *f)
std::optional< int > BKE_paint_get_brush_type_from_obmode(const Brush *brush, eObjectMode ob_mode)
void BKE_sculptsession_update_for_edit(Depsgraph *depsgraph, Object *ob_orig, bool is_paint_tool)
CurveMapping * BKE_paint_default_curve()
Definition scene.cc:157
Brush * BKE_paint_brush(Paint *paint)
bool BKE_paint_select_grease_pencil_test(const Object *ob)
void BKE_palette_clear(Palette *palette)
bool BKE_paint_ensure_from_paintmode(Scene *sce, PaintMode mode)
VecBase< float, 3 > float3
bool BKE_paint_select_vert_test(const Object *ob)
bool BKE_paint_ensure(ToolSettings *ts, Paint **r_paint)
bool BKE_paint_brush_set_essentials(Main *bmain, Paint *paint, const char *name)
void BKE_paint_brushes_validate(Main *bmain, Paint *paint)
float3 BKE_paint_randomize_color(const BrushColorJitterSettings &color_jitter, const float3 &initial_hsv_jitter, const float distance, const float pressure, const float3 &color)
std::string BKE_paint_canvas_key_get(ImagePaintSettings &settings, Object *ob)
PaintMode BKE_paintmode_get_active_from_context(const bContext *C)
void BKE_paint_palette_set(Paint *paint, Palette *palette)
Paint * BKE_paint_get_active(const Main &bmain, Scene *sce, ViewLayer *view_layer)
signed char int8_t
Definition BKE_text.h:76
void BKE_paint_blend_write(BlendWriter *writer, Paint *paint)
Palette * BKE_palette_add(Main *bmain, const char *name)
MutableSpan< float > displacements
Definition BKE_paint.hh:363
Vector< std::pair< float3, float3 > > edges
Definition BKE_paint.hh:336
std::unique_ptr< SculptBoundaryInfoCache > boundary_info_cache
Definition BKE_paint.hh:458
ed::sculpt_paint::StrokeCache * cache
Definition BKE_paint.hh:409
std::optional< std::string > last_paint_canvas_key
Definition BKE_paint.hh:494
std::optional< int > active_face_index
Definition BKE_paint.hh:414
Array< int > vert_to_edge_offsets
Definition BKE_paint.hh:376
Array< int > vert_to_edge_indices
Definition BKE_paint.hh:377
KeyBlock * shapekey_active
Definition BKE_paint.hh:368
void clear_active_elements(bool persist_last_active)
Array< float3, 0 > deform_cos
Definition BKE_paint.hh:395
GroupedSpan< int > vert_to_edge_map
Definition BKE_paint.hh:378
std::optional< float3 > cursor_sampled_normal
Definition BKE_paint.hh:424
Array< int > edge_to_face_offsets
Definition BKE_paint.hh:371
std::unique_ptr< SculptTopologyIslandCache > topology_island_cache
Definition BKE_paint.hh:497
void set_active_vert(ActiveVert vert)
SculptFakeNeighbors fake_neighbors
Definition BKE_paint.hh:459
float3 active_vert_position(const Depsgraph &depsgraph, const Object &object) const
std::optional< int > active_grid_index
Definition BKE_paint.hh:415
std::unique_ptr< SculptBoundaryPreview > boundary_preview
Definition BKE_paint.hh:438
std::optional< PersistentMultiresData > persistent_multires_data()
ed::sculpt_paint::filter::Cache * filter_cache
Definition BKE_paint.hh:410
Array< float3x3, 0 > deform_imats
Definition BKE_paint.hh:397
Array< int > edge_to_face_indices
Definition BKE_paint.hh:372
MultiresModifierData * multires_modifier
Definition BKE_paint.hh:385
SharedCache< Vector< float3 > > vert_normals_deform
Definition BKE_paint.hh:403
struct blender::SculptSession::@037313230252170341305206315164127110104334247060 persistent
GroupedSpan< int > edge_to_face_map
Definition BKE_paint.hh:373
ed::sculpt_paint::expand::Cache * expand_cache
Definition BKE_paint.hh:411
Array< int > preview_verts
Definition BKE_paint.hh:432
std::unique_ptr< bke::pbvh::Tree > pbvh
Definition BKE_paint.hh:390
SharedCache< Vector< float3 > > face_normals_deform
Definition BKE_paint.hh:404
std::unique_ptr< SculptPoseIKChainPreview > pose_ik_chain_preview
Definition BKE_paint.hh:435
RegionView3D * rv3d
Definition BKE_paint.hh:428