Commit: 8e8d9779b799bd3a6cd02b0c7f64983e87c3e9b7 Author: Joseph Eagar Date: Tue Aug 2 16:40:26 2022 -0700 Branches: temp-sculpt-brush-channel https://developer.blender.org/rB8e8d9779b799bd3a6cd02b0c7f64983e87c3e9b7
temp-sculpt-brush-channel: Brush channel system This branch is slimmed down version of sculpt-dev's BrushChannel API. The main differences are: * BrushChannel wraps RNA properties instead of being a fully-formed property system on its own. The exception are BrushCurve properties which don't exist in RNA. * The brush command queue has been removed. * BrushChannels still store data (so the .fvalue .ivalue .vector .curve members are still there), but except for curves these are mere runtime caches filled in from RNA. * brush_channel_define.h still exists but no longer has all the property definitions; instead it merely defines which RNA properties are brush properties. * There is no global CurveMapping cache, that's really only needed for the command queue sytem. * Got rid of the awkward BRUSHSET_ macros. Instead, brush channel API methods that takes channel names are prefixed with _ and wrapped in unprefixed versions that do the compile-time name checking. Note that this is a work in progress =================================================================== M source/blender/CMakeLists.txt M source/blender/blenkernel/BKE_brush.h A source/blender/blenkernel/BKE_brush_channel.h M source/blender/blenkernel/CMakeLists.txt M source/blender/blenkernel/intern/brush.cc A source/blender/blenkernel/intern/brush_channel.cc A source/blender/blenkernel/intern/brush_channel_define.h A source/blender/makesdna/DNA_brush_channel_types.h M source/blender/makesdna/DNA_brush_types.h M source/blender/makesdna/DNA_scene_types.h M source/blender/makesrna/intern/CMakeLists.txt M source/blender/makesrna/intern/makesrna.c M source/blender/makesrna/intern/rna_brush.c A source/blender/makesrna/intern/rna_brush_channels.c M source/blender/makesrna/intern/rna_internal.h =================================================================== diff --git a/source/blender/CMakeLists.txt b/source/blender/CMakeLists.txt index 8ba6e7318bb..91f58474eb5 100644 --- a/source/blender/CMakeLists.txt +++ b/source/blender/CMakeLists.txt @@ -87,6 +87,7 @@ set(SRC_DNA_INC ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_workspace_types.h ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_world_types.h ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_xr_types.h + ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_brush_channel_types.h ) set(SRC_DNA_DEFAULTS_INC diff --git a/source/blender/blenkernel/BKE_brush.h b/source/blender/blenkernel/BKE_brush.h index 4d728002c87..a904b4d00ad 100644 --- a/source/blender/blenkernel/BKE_brush.h +++ b/source/blender/blenkernel/BKE_brush.h @@ -97,7 +97,11 @@ float BKE_brush_curve_strength_clamped(const struct Brush *br, float p, float le * Uses the brush curve control to find a strength value. */ float BKE_brush_curve_strength(const struct Brush *br, float p, float len); - +float BKE_brush_curve_strength_ex(int curve_preset, + const struct CurveMapping *curve, + float p, + const float len, + const bool invert); /* Sampling. */ /** diff --git a/source/blender/blenkernel/BKE_brush_channel.h b/source/blender/blenkernel/BKE_brush_channel.h new file mode 100644 index 00000000000..44ecc85ffca --- /dev/null +++ b/source/blender/blenkernel/BKE_brush_channel.h @@ -0,0 +1,203 @@ +#pragma once +#pragma once + +/* + * 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. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + */ + +/** \file + * \ingroup bke + * \brief New brush engine for sculpt + */ + +#include "RNA_types.h" + +/* +The new brush engine is based on command lists. These lists +will eventually be created by a node editor. + +Key is the concept of BrushChannels. A brush channel is +a logical parameter with a type, input settings (e.g. pen), +a falloff curve, etc. + +Brush channels have a concept of inheritance. There is a +BrushChannelSet (collection of channels) in Sculpt, +in Brush, and in BrushCommand. Inheritence behavior +is controller via BrushChannel->flag. + +This should completely replace UnifiedPaintSettings. +*/ + +#include "BLI_compiler_compat.h" +#include "DNA_brush_channel_types.h" +#include "DNA_texture_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct BrushChannel; +struct BlendWriter; +struct StructRNA; +struct BlendDataReader; +struct BlendLibReader; +struct ID; +struct BlendExpander; +struct Brush; +struct Sculpt; +struct LibraryForeachIDData; +struct UnifiedPaintSettings; + +#define make_builtin_ch_name(idname) BRUSH_BUILTIN_##idname + +//#define DEBUG_CURVE_MAPPING_ALLOC +#ifdef DEBUG_CURVE_MAPPING_ALLOC +void namestack_push(const char *name); +void *namestack_pop(void *passthru); +#endif + +typedef void (*BrushChannelIDCallback)(void *userdata, + struct ID *id, + BrushChannelSet *chset, + BrushChannel *ch); +/* TODO: clean up this struct */ +typedef struct BrushMappingDef { + int curve; + bool enabled; + bool inv; + bool inherit; + float min, max; + int blendmode; + float func_cutoff; + float factor; // if 0, will default to 1.0 + bool no_default; +} BrushMappingDef; + +typedef struct BrushMappingPreset { + // must match order of BRUSH_MAPPING_XXX enums + struct BrushMappingDef pressure, xtilt, ytilt, angle, speed, random, stroke_t; +} BrushMappingPreset; + +/* input mapping data */ +typedef struct BrushMappingData { + float pressure, xtilt, ytilt, angle, speed, random, stroke_t; +} BrushMappingData; + +#define MAX_BRUSH_ENUM_DEF 32 + +/* copy of PropertyEnumItem only with static char arrays instead of pointers + for strings */ +typedef struct BrushEnumDef { + int value; + const char identifier[64]; + char icon[32]; // don't forget when writing literals that icon here is a string, not an int! + const char name[64]; + const char description[512]; +} BrushEnumDef; + +/* + Defines a brush channel. Includes limits, UI data, + default values, etc. +*/ +typedef struct BrushChannelType { + char uiname[128], idname[64], tooltip[512], category[128]; + float min, max, soft_min, soft_max; + BrushMappingPreset mappings; + + int type, flag, ui_flag; + int subtype; + + bool user_defined; /* this is a user-defined channel; currently unused */ +} BrushChannelType; + +BrushChannelSet *BKE_brush_channelset_create(); +void BKE_brush_channelset_free(BrushChannelSet *chset); +void BKE_brush_channelset_ensure_channels(BrushChannelSet *chset, int sculpt_tool); +void BKE_brush_channelset_blend_read(BrushChannelSet *chset, struct BlendDataReader *reader); +void BKE_brush_channelset_blend_write(BrushChannelSet *chset, struct BlendWriter *writer); +/* +set up static type checker for BKE_brush_channel_XXX name-checking macros +*/ +#define BRUSH_CHANNEL_DEFINE_EXTERNAL +#include "intern/brush_channel_define.h" +#undef BRUSH_CHANNEL_DEFINE_EXTERNAL + +BrushChannel *_BKE_brush_channelset_ensure(BrushChannelSet *chset, const char *idname); +#define BKE_brush_channelset_ensure(chset, idname) \ + _BKE_brush_channelset_ensure(chset, make_builtin_ch_name(idname)) + +BrushChannel *_BKE_brush_channelset_lookup(BrushChannelSet *chset, const char *idname); +#define BKE_brush_channelset_lookup(chset, channel) \ + _BKE_brush_channelset_lookup(chset, make_builtin_ch_name(channel)) + +bool _BKE_brush_channelset_has(BrushChannelSet *chset, const char *idname); +#define BKE_brush_channelset_has(chset, channel) \ + _BKE_brush_channelset_has(chset, make_builtin_ch_name(channel)) + +/* Flags all channels with BRUSH_CHANNEL_NEEDS_EVALUATE so we + reevaluate values from RNA */ +void BKE_brush_channelset_begin(BrushChannelSet *chset, BrushChannelType *type); + +float _BKE_brush_channelset_float_get(struct Brush *br, + struct Scene *scene, + BrushChannelSet *chset, + const char *idname, + BrushMappingData *mapping); +#define BKE_brush_channelset_float_get(br, scene, chset, channel, mapdata) \ + _BKE_brush_channelset_float_get(br, scene, chset, make_builtin_ch_name(channel), mapdata) + +void _BKE_brush_channelset_float_set(struct Brush *br, + struct Scene *scene, + BrushChannelSet *chset, + const char *idname, + float f, + bool set_rna); + +BrushChannelSet *BKE_brush_channelset_copy(BrushChannelSet *chset); + +#define BKE_brush_channelset_float_set(br, scene, chset, channel, f, set_rna) \ + _BKE_brush_channelset_float_set(br, scene, chset, make_builtin_ch_name(channel), f, set_rna) + +BLI_INLINE const char *BKE_brush_mapping_type_to_typename(eBrushMappingType type) +{ + switch (type) { + case BRUSH_MAPPING_PRESSURE: + return "PRESSURE"; + case BRUSH_MAPPING_ANGLE: + return "ANGLE"; + case BRUSH_MAPPING_SPEED: + return "SPEED"; + case BRUSH_MAPPING_XTILT: + return "XTILT"; + case BRUSH_MAPPING_YTILT: + return "YTILT"; + case BRUSH_MAPPING_RANDOM: + return "RANDOM"; + case BRUSH_MAPPING_STROKE_T: + return "DISTANCE"; + default: + return "Error"; + } +} + +const char *BKE_brush_channel_category_get(BrushChannel *ch); +const void BKE_brush_channel_category_set(BrushChannel *ch, const char *category); + +#ifdef __cplusplus +} +#endif diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt index f76f7f5a968..7500a4094b2 100644 --- a/source/blender/blenkernel/CMakeLists.txt +++ b/source/blender/blenkernel/CMakeLists.txt @@ -86,6 +86,7 @@ set(SRC intern/blender_user_menu.c intern/blendfile.c intern/blendfile_link_append.c + intern/brush_channel.cc intern/boids.c intern/bpath.c intern/brush.cc @@ -340,6 +341,7 @@ set(SRC BKE_boids.h BKE_bpath.h BKE_brush.h + BKE_brush_channel.h BKE_bvhutils.h BKE_cachefile.h BKE_callbacks.h @@ -494,6 +496,7 @@ set(SRC nla_private.h particle_private.h tracking_private.h + intern/brush_channel_define.h intern/CCGSubSurf.h intern/CCGSubSurf_inline.h intern/CCGSubSurf_intern.h diff --git a/source/blender/blenkernel/intern/brush.cc b/source/blender/blenkernel/intern/brush.cc index 99733c8edb3..cdf56c62e63 100644 --- a/source/blender/blenkernel/intern/brush.cc +++ b/source/blender/blenkernel/intern/brush.cc @@ -21,6 +21,7 @@ #include "BKE_bpath.h" #include "BKE_brush.h" +#include "BKE_brush_channel.h" #include "BKE_colortools.h" #include "BKE_context.h" #include "BKE_gpencil.h" @@ -321,6 +322,19 @@ static void brush_blend_read_data(BlendDataReader *reader, ID *id) brush->preview = nullptr; brush->icon_imbuf = nullptr; + + BLO_read_data_address(reader, &brush->channels); + + if (brush->sculpt_tool) { + if (!brush->channels) { + brush->channels = BKE_brush_channelset_create(); + } + else { + BKE_brush_channelset_blend_read(brush->channels, reader); + } + + BKE_brush_channelset_ensure_channels(brush->channels, brush->sculpt_tool); + } } static void brush_blend_read_lib(BlendLibReader *reader, ID *id) @@ -2520,3 +2534,54 @@ struct ImBuf *BKE_brush_gen_radial_control @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs