GPv3: Opacity modifier #116946
|
@ -46,6 +46,7 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
|
|||
|
||||
def draw(self, _context):
|
||||
layout = self.layout
|
||||
ob_type = _context.object.type
|
||||
LukasTonne marked this conversation as resolved
Outdated
|
||||
layout.operator("wm.call_menu", text="Add Modifier", icon='ADD').name = "OBJECT_MT_modifier_add"
|
||||
layout.template_modifiers()
|
||||
|
||||
|
@ -71,7 +72,7 @@ class OBJECT_MT_modifier_add(ModifierAddMenu, Menu):
|
|||
if geometry_nodes_supported:
|
||||
self.operator_modifier_add(layout, 'NODES')
|
||||
layout.separator()
|
||||
if ob_type in {'MESH', 'CURVE', 'FONT', 'SURFACE', 'LATTICE'}:
|
||||
if ob_type in {'MESH', 'CURVE', 'FONT', 'SURFACE', 'LATTICE', 'GREASEPENCIL'}:
|
||||
layout.menu("OBJECT_MT_modifier_add_edit")
|
||||
if ob_type in {'MESH', 'CURVE', 'FONT', 'SURFACE', 'VOLUME'}:
|
||||
layout.menu("OBJECT_MT_modifier_add_generate")
|
||||
|
@ -105,6 +106,8 @@ class OBJECT_MT_modifier_add_edit(ModifierAddMenu, Menu):
|
|||
self.operator_modifier_add(layout, 'VERTEX_WEIGHT_EDIT')
|
||||
self.operator_modifier_add(layout, 'VERTEX_WEIGHT_MIX')
|
||||
self.operator_modifier_add(layout, 'VERTEX_WEIGHT_PROXIMITY')
|
||||
if ob_type == 'GREASEPENCIL':
|
||||
self.operator_modifier_add(layout, 'GREASE_PENCIL_OPACITY')
|
||||
layout.template_modifier_asset_menu_items(catalog_path=self.bl_label)
|
||||
|
||||
|
||||
|
|
|
@ -93,6 +93,7 @@ typedef enum ModifierType {
|
|||
eModifierType_MeshToVolume = 58,
|
||||
eModifierType_VolumeDisplace = 59,
|
||||
eModifierType_VolumeToMesh = 60,
|
||||
eModifierType_GreasePencilOpacity = 61,
|
||||
NUM_MODIFIER_TYPES,
|
||||
} ModifierType;
|
||||
|
||||
|
@ -2484,3 +2485,8 @@ typedef enum VolumeToMeshResolutionMode {
|
|||
typedef enum VolumeToMeshFlag {
|
||||
VOLUME_TO_MESH_USE_SMOOTH_SHADE = 1 << 0,
|
||||
} VolumeToMeshFlag;
|
||||
|
||||
typedef struct GreasePencilOpacityModifierData {
|
||||
ModifierData modifier;
|
||||
|
||||
} GreasePencilOpacityModifierData;
|
||||
|
|
|
@ -100,6 +100,11 @@ const EnumPropertyItem rna_enum_object_modifier_type_items[] = {
|
|||
ICON_MOD_VERTEX_WEIGHT,
|
||||
"Vertex Weight Proximity",
|
||||
"Set the vertex group weights based on the distance to another target object"},
|
||||
{eModifierType_GreasePencilOpacity,
|
||||
"GREASE_PENCIL_OPACITY",
|
||||
ICON_MOD_OPACITY,
|
||||
"Opacity",
|
||||
"Opacity of the strokes"},
|
||||
LukasTonne marked this conversation as resolved
Outdated
Hans Goudey
commented
I know this is just copying the old description, might as well fix it though `Opacity of the strokes` -> `Change the opacity of the strokes`
I know this is just copying the old description, might as well fix it though
|
||||
|
||||
RNA_ENUM_ITEM_HEADING(N_("Generate"), nullptr),
|
||||
{eModifierType_Array,
|
||||
|
@ -7423,6 +7428,22 @@ static void rna_def_modifier_volume_to_mesh(BlenderRNA *brna)
|
|||
RNA_define_lib_overridable(false);
|
||||
}
|
||||
|
||||
static void rna_def_modifier_grease_pencil_opacity(BlenderRNA *brna)
|
||||
{
|
||||
StructRNA *srna;
|
||||
|
||||
srna = RNA_def_struct(brna, "GreasePencilOpacityModifier", "Modifier");
|
||||
RNA_def_struct_ui_text(srna, "Grease Pencil Opacity Modifier", "");
|
||||
RNA_def_struct_sdna(srna, "GreasePencilOpacityModifierData");
|
||||
RNA_def_struct_ui_icon(srna, ICON_MOD_OPACITY);
|
||||
|
||||
RNA_define_lib_overridable(true);
|
||||
|
||||
// TODO
|
||||
|
||||
RNA_define_lib_overridable(false);
|
||||
}
|
||||
|
||||
void RNA_def_modifier(BlenderRNA *brna)
|
||||
{
|
||||
StructRNA *srna;
|
||||
|
@ -7583,6 +7604,7 @@ void RNA_def_modifier(BlenderRNA *brna)
|
|||
rna_def_modifier_mesh_to_volume(brna);
|
||||
rna_def_modifier_volume_displace(brna);
|
||||
rna_def_modifier_volume_to_mesh(brna);
|
||||
rna_def_modifier_grease_pencil_opacity(brna);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -44,6 +44,7 @@ set(SRC
|
|||
intern/MOD_edgesplit.cc
|
||||
intern/MOD_explode.cc
|
||||
intern/MOD_fluid.cc
|
||||
intern/MOD_grease_pencil_opacity.cc
|
||||
intern/MOD_hook.cc
|
||||
intern/MOD_laplaciandeform.cc
|
||||
intern/MOD_laplaciansmooth.cc
|
||||
|
|
|
@ -73,6 +73,7 @@ extern ModifierTypeInfo modifierType_Nodes;
|
|||
extern ModifierTypeInfo modifierType_MeshToVolume;
|
||||
extern ModifierTypeInfo modifierType_VolumeDisplace;
|
||||
extern ModifierTypeInfo modifierType_VolumeToMesh;
|
||||
extern ModifierTypeInfo modifierType_GreasePencilOpacity;
|
||||
|
||||
/* MOD_util.cc */
|
||||
|
||||
|
|
|
@ -0,0 +1,151 @@
|
|||
/* SPDX-FileCopyrightText: 2005 Blender Authors
|
||||
LukasTonne marked this conversation as resolved
Outdated
Hans Goudey
commented
Copyright year can be updated Copyright year can be updated
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
/** \file
|
||||
* \ingroup modifiers
|
||||
*/
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#include "DNA_defaults.h"
|
||||
#include "DNA_modifier_types.h"
|
||||
|
||||
#include "BKE_modifier.hh"
|
||||
|
||||
#include "BLO_read_write.hh"
|
||||
|
||||
#include "UI_interface.hh"
|
||||
#include "UI_resources.hh"
|
||||
|
||||
#include "BLT_translation.h"
|
||||
|
||||
#include "WM_types.hh"
|
||||
|
||||
#include "RNA_access.hh"
|
||||
#include "RNA_enum_types.hh"
|
||||
#include "RNA_prototypes.h"
|
||||
|
||||
#include "MOD_modifiertypes.hh"
|
||||
#include "MOD_ui_common.hh"
|
||||
|
||||
namespace blender {
|
||||
|
||||
static void init_data(ModifierData *md)
|
||||
{
|
||||
GreasePencilOpacityModifierData *omd = (GreasePencilOpacityModifierData *)md;
|
||||
|
||||
BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(omd, modifier));
|
||||
|
||||
MEMCPY_STRUCT_AFTER(omd, DNA_struct_default_get(GreasePencilOpacityModifierData), modifier);
|
||||
|
||||
// TODO
|
||||
}
|
||||
|
||||
static void copy_data(const ModifierData *md, ModifierData *target, const int flag)
|
||||
{
|
||||
const GreasePencilOpacityModifierData *omd = (const GreasePencilOpacityModifierData *)md;
|
||||
GreasePencilOpacityModifierData *tomd = (GreasePencilOpacityModifierData *)target;
|
||||
|
||||
BKE_modifier_copydata_generic(md, target, flag);
|
||||
|
||||
// TODO
|
||||
UNUSED_VARS(omd, tomd);
|
||||
}
|
||||
|
||||
static void required_data_mask(ModifierData *md, CustomData_MeshMasks *r_cddata_masks)
|
||||
{
|
||||
GreasePencilOpacityModifierData *omd = (GreasePencilOpacityModifierData *)md;
|
||||
|
||||
// TODO
|
||||
LukasTonne marked this conversation as resolved
Outdated
Hans Goudey
commented
You can write You can write `const auto *` with the cast, it might keep it on one line
|
||||
UNUSED_VARS(omd, r_cddata_masks);
|
||||
}
|
||||
|
||||
static void free_data(ModifierData *md)
|
||||
{
|
||||
GreasePencilOpacityModifierData *omd = (GreasePencilOpacityModifierData *)md;
|
||||
|
||||
// TODO
|
||||
UNUSED_VARS(omd);
|
||||
}
|
||||
|
||||
static void modify_geometry_set(ModifierData *md,
|
||||
const ModifierEvalContext *ctx,
|
||||
bke::GeometrySet *geometry_set)
|
||||
{
|
||||
GreasePencilOpacityModifierData *omd = (GreasePencilOpacityModifierData *)md;
|
||||
|
||||
// TODO
|
||||
UNUSED_VARS(omd, ctx, geometry_set);
|
||||
}
|
||||
|
||||
static void panel_draw(const bContext * /*C*/, Panel *panel)
|
||||
{
|
||||
LukasTonne marked this conversation as resolved
Hans Goudey
commented
You should just be able to retrieve the vertex group as an attribute You should just be able to retrieve the vertex group as an attribute
Lukas Tönne
commented
Took some explaining from @filedescriptor how this works (maybe a good topic for technical docs?). As far as i understand the Took some explaining from @filedescriptor how this works (maybe a good topic for technical docs?). As far as i understand the `VArray` wrapper for the `curves->deform_verts()` is ok here, since we're only using a single vertex group. For something like the armature modifier i'd guess we still want to use the `MDeformVert` directly.
Hans Goudey
commented
Right, exactly Right, exactly
|
||||
uiLayout *layout = panel->layout;
|
||||
|
||||
PointerRNA ob_ptr;
|
||||
PointerRNA *ptr = modifier_panel_get_property_pointers(panel, &ob_ptr);
|
||||
|
||||
uiLayoutSetPropSep(layout, true);
|
||||
|
||||
// TODO
|
||||
|
||||
modifier_panel_end(layout, ptr);
|
||||
}
|
||||
|
||||
static void panel_register(ARegionType *region_type)
|
||||
{
|
||||
LukasTonne marked this conversation as resolved
Outdated
Hans Goudey
commented
Use the * operator overload to just store the VArray directly here Use the * operator overload to just store the VArray directly here
|
||||
modifier_panel_register(region_type, eModifierType_GreasePencilOpacity, panel_draw);
|
||||
}
|
||||
|
||||
static void blend_write(BlendWriter *writer, const ID * /*id_owner*/, const ModifierData *md)
|
||||
{
|
||||
const GreasePencilOpacityModifierData *omd = (const GreasePencilOpacityModifierData *)md;
|
||||
|
||||
BLO_write_struct(writer, GreasePencilOpacityModifierData, omd);
|
||||
}
|
||||
|
||||
static void blend_read(BlendDataReader *reader, ModifierData *md)
|
||||
{
|
||||
GreasePencilOpacityModifierData *omd = (GreasePencilOpacityModifierData *)md;
|
||||
UNUSED_VARS(reader, omd);
|
||||
}
|
||||
|
||||
} // namespace blender
|
||||
|
||||
ModifierTypeInfo modifierType_GreasePencilOpacity = {
|
||||
/*idname*/ "GreasePencilOpacity",
|
||||
/*name*/ N_("GreasePencilOpacity"),
|
||||
/*struct_name*/ "GreasePencilOpacityModifierData",
|
||||
/*struct_size*/ sizeof(GreasePencilOpacityModifierData),
|
||||
/*srna*/ &RNA_GreasePencilOpacityModifier,
|
||||
/*type*/ ModifierTypeType::NonGeometrical,
|
||||
/*flags*/
|
||||
static_cast<ModifierTypeFlag>(
|
||||
eModifierTypeFlag_AcceptsGreasePencil | eModifierTypeFlag_SupportsEditmode |
|
||||
LukasTonne marked this conversation as resolved
Outdated
Pratik Borhade
commented
remove this and pass remove this and pass `vgroup_weight` to clamp fn? 😅
Lukas Tönne
commented
Haha yeah, this is the result of me trying to make sense of the logic of the old modifier. Haha yeah, this is the result of me trying to make sense of the logic of the old modifier.
|
||||
eModifierTypeFlag_EnableInEditmode | eModifierTypeFlag_SupportsMapping),
|
||||
/*icon*/ ICON_MOD_OPACITY,
|
||||
|
||||
/*copy_data*/ blender::copy_data,
|
||||
|
||||
/*deform_verts*/ nullptr,
|
||||
/*deform_matrices*/ nullptr,
|
||||
/*deform_verts_EM*/ nullptr,
|
||||
/*deform_matrices_EM*/ nullptr,
|
||||
Iliya Katushenock
commented
Wondering if this could be made much clean by using Wondering if this could be made much clean by using `DefaultMixer`?
Lukas Tönne
commented
That seems a bit unnecessary here.
I'd prefer to not try and "fix" this too much, since the primary purpose is compatibility with GP2. That seems a bit unnecessary here.
- The attributes are all floats, no need to handle different types.
- The math is weird and undocumented. In the "uniform" mode it uses `1 - current` as some kind of cutoff point, and then allows ramping up the influence to 2.0, presumably so one can reach full opacity/hardness again. It all seems very ad-hoc.
I'd prefer to not try and "fix" this too much, since the primary purpose is compatibility with GP2.
|
||||
/*modify_mesh*/ nullptr,
|
||||
/*modify_geometry_set*/ blender::modify_geometry_set,
|
||||
|
||||
/*init_data*/ blender::init_data,
|
||||
/*required_data_mask*/ blender::required_data_mask,
|
||||
/*free_data*/ blender::free_data,
|
||||
/*is_disabled*/ nullptr,
|
||||
/*update_depsgraph*/ nullptr,
|
||||
/*depends_on_time*/ nullptr,
|
||||
/*depends_on_normals*/ nullptr,
|
||||
/*foreach_ID_link*/ nullptr,
|
||||
/*foreach_tex_link*/ nullptr,
|
||||
/*free_runtime_data*/ nullptr,
|
||||
/*panel_register*/ blender::panel_register,
|
||||
/*blend_write*/ blender::blend_write,
|
||||
/*blend_read*/ blender::blend_read,
|
||||
};
|
|
@ -270,5 +270,6 @@ void modifier_type_init(ModifierTypeInfo *types[])
|
|||
INIT_TYPE(VolumeDisplace);
|
||||
INIT_TYPE(VolumeToMesh);
|
||||
INIT_TYPE(Nodes);
|
||||
INIT_TYPE(GreasePencilOpacity);
|
||||
#undef INIT_TYPE
|
||||
}
|
||||
|
|
Was this added by mistake? I don't see where
ob_type
is used here.