[Bf-blender-cvs] [04c3690299c] temp_bmesh_multires: Sculpt dyntopo: Roughed out skeleton of new brush engine API
Joseph Eagar
noreply at git.blender.org
Fri Sep 17 05:47:17 CEST 2021
Commit: 04c3690299c51b79412fe395c2507a28fbae7b56
Author: Joseph Eagar
Date: Thu Sep 16 20:29:33 2021 -0700
Branches: temp_bmesh_multires
https://developer.blender.org/rB04c3690299c51b79412fe395c2507a28fbae7b56
Sculpt dyntopo: Roughed out skeleton of new brush engine API
Command Lists
* The new system will be based on command lists
generated by (eventually) a node editor.
* For now, the lists will be hardcoded.
* Idea is to make a minimal viable
brush engine that won't cause file breakage
when the upgrade to node-based brushes happen.
Brush Channels
* Wrote new structures and API to wrange
brush parameters: BrushChannel.
* Supports, floats, ints, enums, bitmasks,
with plans for vec3 and vec4.
* This will replace UnifiedPaintStruct,
most of the members of Brush and the
DynTopoSettings struct.
* Brush channels can
be mapped to various input device
channels (e.g. pen pressure); each
mapping has its own associated curve
(CurveMapping instance) and bounds.
Brush channel inheritence chaining
* Brush channels can form inheritence chains
* Channel sets are stored in three places:
in the scene toolsettings, in Brush, and in
individual brush commands.
* Node groups will also have a channel set.
* Channels in each set can be flagged to
inherit from the parent set.
* Inheritence happens in seperate merged
channel sets at runtime. The final
Brush channels live in Brush->channels_final,
while the final command channels live in
BrushCommand->params_final.
===================================================================
A source/blender/blenkernel/BKE_brush_engine.h
M source/blender/blenkernel/CMakeLists.txt
M source/blender/blenkernel/intern/brush.c
A source/blender/blenkernel/intern/brush_engine.c
M source/blender/blenkernel/intern/scene.c
M source/blender/editors/sculpt_paint/sculpt_brush_machine.c
M source/blender/makesdna/DNA_brush_enums.h
M source/blender/makesdna/DNA_brush_types.h
M source/blender/makesdna/DNA_scene_types.h
A source/blender/makesdna/DNA_sculpt_brush_types.h
M source/blender/makesdna/intern/CMakeLists.txt
M source/blender/makesdna/intern/makesdna.c
M source/blender/makesrna/intern/CMakeLists.txt
M source/blender/makesrna/intern/makesrna.c
A source/blender/makesrna/intern/rna_brush_engine.c
M source/blender/makesrna/intern/rna_internal.h
===================================================================
diff --git a/source/blender/blenkernel/BKE_brush_engine.h b/source/blender/blenkernel/BKE_brush_engine.h
new file mode 100644
index 00000000000..5695cae3649
--- /dev/null
+++ b/source/blender/blenkernel/BKE_brush_engine.h
@@ -0,0 +1,129 @@
+#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
+ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#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.
+*/
+struct BrushChannel;
+
+#include "BLO_read_write.h"
+#include "DNA_sculpt_brush_types.h"
+
+typedef struct BrushMappingDef {
+ int curve;
+ bool enabled;
+ bool inv;
+ float min, max;
+ int blendmode;
+} BrushMappingDef;
+
+typedef struct BrushMappingPreset {
+ // must match order of BRUSH_MAPPING_XXX enums
+ struct BrushMappingDef pressure, xtilt, ytilt, angle, speed;
+} BrushMappingPreset;
+
+#define MAX_BRUSH_ENUM_DEF 32
+
+typedef struct BrushEnumDef {
+ EnumPropertyItem items[MAX_BRUSH_ENUM_DEF];
+} BrushEnumDef;
+
+typedef struct BrushChannelType {
+ char name[32], idname[32];
+ float min, max, soft_min, soft_max;
+ BrushMappingPreset mappings;
+
+ int type, flag;
+ int ivalue;
+ float fvalue;
+ BrushEnumDef enumdef; // if an enum type
+} BrushChannelType;
+
+typedef struct BrushCommand {
+ int tool;
+ struct BrushChannelSet *params;
+ struct BrushChannelSet *params_final;
+ int totparam;
+} BrushCommand;
+
+typedef struct BrushCommandList {
+ BrushCommand *commands;
+ int totcommand;
+} BrushCommandList;
+
+void BKE_brush_channel_free(BrushChannel *ch);
+void BKE_brush_channel_copy(BrushChannel *dst, BrushChannel *src);
+void BKE_brush_channel_init(BrushChannel *ch, BrushChannelType *def);
+BrushChannelSet *BKE_brush_channelset_create();
+
+void BKE_brush_channelset_free(BrushChannelSet *chset);
+void BKE_brush_channelset_add(BrushChannelSet *chset, BrushChannel *ch);
+
+BrushChannel *BKE_brush_channelset_lookup(BrushChannelSet *chset, const char *idname);
+
+bool BKE_brush_channelset_has(BrushChannelSet *chset, const char *idname);
+
+void BKE_brush_channelset_add_builtin(BrushChannelSet *chset, const char *idname);
+bool BKE_brush_channelset_ensure_builtin(BrushChannelSet *chset, const char *idname);
+
+void BKE_brush_channelset_merge(BrushChannelSet *dst,
+ BrushChannelSet *child,
+ BrushChannelSet *parent);
+
+void BKE_brush_resolve_channels(struct Brush *brush, struct Sculpt *sd);
+int BKE_brush_channel_get_int(BrushChannelSet *chset, char *idname);
+float BKE_brush_channel_get_float(BrushChannelSet *chset, char *idname);
+float BKE_brush_channel_set_float(BrushChannelSet *chset, char *idname, float val);
+void BKE_brush_init_toolsettings(struct Sculpt *sd);
+void BKE_brush_builtin_create(struct Brush *brush, int tool);
+BrushCommandList *BKE_brush_commandlist_create();
+void BKE_brush_commandlist_free(BrushCommandList *cl);
+BrushCommand *BKE_brush_commandlist_add(BrushCommandList *cl);
+BrushCommand *BKE_brush_command_init(BrushCommand *command, int tool);
+void BKE_builtin_commandlist_create(BrushChannelSet *chset, BrushCommandList *cl, int tool);
+void BKE_brush_channelset_read(BlendDataReader *reader, BrushChannelSet *cset);
+void BKE_brush_channelset_write(BlendWriter *writer, BrushChannelSet *cset);
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index c652632aca8..56a221ff09b 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -289,7 +289,8 @@ set(SRC
intern/workspace.c
intern/world.c
intern/writeavi.c
-
+ intern/brush_engine.c
+
BKE_DerivedMesh.h
BKE_action.h
BKE_action.hh
@@ -451,6 +452,7 @@ set(SRC
BKE_workspace.h
BKE_world.h
BKE_writeavi.h
+ BKE_brush_engine.h
nla_private.h
particle_private.h
diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c
index 7d7b13fe872..552708722ad 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -34,6 +34,7 @@
#include "BLT_translation.h"
#include "BKE_brush.h"
+#include "BKE_brush_engine.h"
#include "BKE_colortools.h"
#include "BKE_context.h"
#include "BKE_gpencil.h"
@@ -262,12 +263,21 @@ static void brush_blend_write(BlendWriter *writer, ID *id, const void *id_addres
if (brush->gradient) {
BLO_write_struct(writer, ColorBand, brush->gradient);
}
+
+ if (brush->channels) {
+ BKE_brush_channelset_write(writer, brush->channels);
+ }
}
static void brush_blend_read_data(BlendDataReader *reader, ID *id)
{
Brush *brush = (Brush *)id;
+ if (brush->channels) {
+ BLO_read_data_address(reader, &brush->channels);
+ BKE_brush_channelset_read(reader, brush->channels);
+ }
+
if (brush->dyntopo.radius_scale == 0.0f) {
brush->dyntopo.radius_scale = 1.0f;
brush->dyntopo.inherit |= DYNTOPO_INHERIT_RADIUS_SCALE;
diff --git a/source/blender/blenkernel/intern/brush_engine.c b/source/blender/blenkernel/intern/brush_engine.c
new file mode 100644
index 00000000000..a917c92879e
--- /dev/null
+++ b/source/blender/blenkernel/intern/brush_engine.c
@@ -0,0 +1,667 @@
+#include "MEM_guardedalloc.h"
+
+#include "BLI_alloca.h"
+#include "BLI_array.h"
+#include "BLI_bitmap.h"
+#include "BLI_compiler_attrs.h"
+#include "BLI_compiler_compat.h"
+#include "BLI_listbase.h"
+#include "BLI_math.h"
+#include "BLI_memarena.h"
+
+#include "DNA_brush_enums.h"
+#include "DNA_brush_types.h"
+#include "DNA_color_types.h"
+#include "DNA_curveprofile_types.h"
+#include "DNA_node_types.h"
+#include "DNA_sculpt_brush_types.h"
+
+#include "BKE_brush.h"
+#include "BKE_colorband.h"
+#include "BKE_colortools.h"
+#include "BKE_context.h"
+#include "BKE_node.h"
+#include "BKE_paint.h"
+
+#include "BKE_brush_engine.h"
+#include "BKE_curveprofile.h"
+
+#include "BLO_read_write.h"
+
+#define ICON_NONE -1
+
+/*
+Brush command lists.
+
+Command lists are built dynamically from
+brush flags, pen input settings, etc.
+
+Eventually they will be generated by node
+networks. BrushCommandPreset will be
+generated from the node group inputs.
+*/
+
+/* clang-format off */
+BrushChannelType brush_builtin_channels[] = {
+ {
+ .name = "Radius",
+ .idname = "RADIUS",
+ .min = 0.001f,
+ .type = BRUSH_CHANNEL_FLOAT,
+ .max = 2048.0f,
+ .soft_min = 0.1f,
+ .soft_max = 1024.0f,
+ .mappings = {
+ .pressure = {.curve = CURVE_PRESET_SMOOTH, .min = 0.0f, .max = 1.0f, .enabled = false},
+ }
+ },
+ {
+ .name = "Strength",
+ .idname = "STRENGTH",
+ .min = -1.0f,
+ .type = BRUSH_CHANNEL_FLOAT,
+ .max = 4.0f,
+ .soft_min = 0.0f,
+ .soft_max = 1.0f,
+ .mappings = {
+ .pressure = {.curve = CURVE_PRESET_SMOOTH, .min = 0.0f, .max = 1.0f, .enabled = true},
+ }
+ },
+ {
+ .name = "Spacing",
+ .idname = "SPACING",
+ .min = 0.001f,
+ .type = BRUSH_CHANNEL_FLOAT,
+ .max = 4.0f,
+ .soft_min = 0.005f,
+ .soft_max = 2.0f,
+ .mappings = {
+ .pressure = {.curve = CURVE_PRESET_SMOOTH, .min = 0.0f, .max = 1.0f, .enabled = true},
+ }
+ },
+ {
+ .name = "Autosmooth",
+ .idname = "AUTOSMOOTH",
+ .type = BRUSH_CHANNEL_FLOAT,
+ .min = -1.0f,
+ .max = 4.0f,
+ .soft_min = 0.0f,
+ .soft_max = 1.0f,
+ .mappings = {
+ .pressure = {.curve = CURVE_PRESET_SMOOTH, .min = 0.0f, .max = 1.0f, .enabled = false, .inv = true},
+ }
+ },
+ {
+ .name = "Topology Rake",
+ .idname = "TOPOLOGY_RAKE",
+ .type = BRUSH_CHANNEL_FLOAT,
+ .min = -1.0f,
+ .max = 4.0f,
+ .soft_min = 0.0f,
+ .soft_max = 1.0f,
+ .mappings = {
+ .pressure = {.curve = CURVE_PRESET_SMOOTH, .min = 0.0f, .max = 1.0f, .enabled = false},
+ }
+ },
+ {
+ .name = "Autosmooth Radius Scale",
+ .idname = "AUTOSMOOTH_RADIUS_SCALE",
+ .type = BRUSH_CHANNEL_FLOAT,
+ .min = 0.0001f,
+ .max = 25.0f,
+ .soft_min = 0.1f,
+ .soft_max = 4.0f,
+ .mappings = {
+ .pressure = {.curve = CURVE_PRESET_SMOOTH, .min = 0.0f, .max = 1.0f, .enabled = false},
+ }
+ },
+ {
+ .name = "Rake Radius Scale",
+ .idname = "TOPOLOGY_RAKE_RADIUS_SCALE",
+ .type = BRUSH_CHANNEL_FLOAT,
+ .min = 0.0001f,
+ .max = 25.0f,
+ .soft_min = 0.1f,
+ .soft_max = 4.0f,
+ .mappings = {
+ .pressure = {.curve = CURVE_PRESET_SMOOTH, .min = 0.0f, .max = 1.0f, .enabled = false},
+ }
+ },
+ {
+ .name = "Face Set Slide",
+ .idname = "FSET_SLIDE",
+ .type = BRUSH_CHANNEL_FLOAT,
+ .min = 0.0001f,
+ .max = 1.0f,
+ .soft_min = 0.1f,
+ .soft_max = 1.0f,
+ .mappings = {
+ .pressure = {.curve = CURVE_PRESET_SMOOTH, .min = 0.0f, .max = 1.0f, .enabled = false},
+ }
+ },
+ {
+ .name = "Boundary Smooth",
+ .idname = "BOUNDARY_SMOOTH",
+ .type = BRUSH_CHANNEL_FLOAT,
+ .min = 0.0001f,
+ .ma
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list