GPv3: Opacity modifier #116946
|
@ -152,8 +152,8 @@ typedef enum {
|
|||
*/
|
||||
eModifierFlag_Active = (1 << 2),
|
||||
/**
|
||||
* Only set on modifiers in evaluated objects. The flag indicates that the user modified inputs
|
||||
* to the modifier which might invalidate simulation caches.
|
||||
* Only set on modifiers in evaluated objects. The flag indicates that the user modified
|
||||
* inputs to the modifier which might invalidate simulation caches.
|
||||
LukasTonne marked this conversation as resolved
Outdated
|
||||
*/
|
||||
eModifierFlag_UserModified = (1 << 3),
|
||||
} ModifierFlag;
|
||||
|
|
|
@ -45,6 +45,7 @@ set(SRC
|
|||
intern/MOD_explode.cc
|
||||
intern/MOD_fluid.cc
|
||||
intern/MOD_grease_pencil_opacity.cc
|
||||
intern/MOD_grease_pencil_util.cc
|
||||
intern/MOD_hook.cc
|
||||
intern/MOD_laplaciandeform.cc
|
||||
intern/MOD_laplaciansmooth.cc
|
||||
|
@ -98,6 +99,7 @@ set(SRC
|
|||
|
||||
MOD_modifiertypes.hh
|
||||
MOD_nodes.hh
|
||||
intern/MOD_grease_pencil_util.hh
|
||||
intern/MOD_meshcache_util.hh
|
||||
intern/MOD_solidify_util.hh
|
||||
intern/MOD_ui_common.hh
|
||||
|
|
|
@ -10,11 +10,17 @@
|
|||
|
||||
#include "DNA_defaults.h"
|
||||
#include "DNA_modifier_types.h"
|
||||
#include "DNA_scene_types.h"
|
||||
|
||||
#include "BKE_curves.hh"
|
||||
#include "BKE_geometry_set.hh"
|
||||
#include "BKE_grease_pencil.hh"
|
||||
#include "BKE_modifier.hh"
|
||||
|
||||
#include "BLO_read_write.hh"
|
||||
|
||||
#include "DEG_depsgraph_query.hh"
|
||||
|
||||
#include "UI_interface.hh"
|
||||
#include "UI_resources.hh"
|
||||
|
||||
|
@ -26,11 +32,16 @@
|
|||
#include "RNA_enum_types.hh"
|
||||
#include "RNA_prototypes.h"
|
||||
|
||||
#include "MOD_grease_pencil_util.hh"
|
||||
#include "MOD_modifiertypes.hh"
|
||||
#include "MOD_ui_common.hh"
|
||||
|
||||
namespace blender {
|
||||
|
||||
using bke::greasepencil::Drawing;
|
||||
using bke::greasepencil::FramesMapKey;
|
||||
using bke::greasepencil::Layer;
|
||||
|
||||
static void init_data(ModifierData *md)
|
||||
{
|
||||
GreasePencilOpacityModifierData *omd = (GreasePencilOpacityModifierData *)md;
|
||||
|
@ -69,14 +80,43 @@ static void free_data(ModifierData *md)
|
|||
UNUSED_VARS(omd);
|
||||
}
|
||||
|
||||
static void modify_curves(ModifierData *md,
|
||||
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
|
||||
const ModifierEvalContext * /*ctx*/,
|
||||
bke::CurvesGeometry &curves)
|
||||
{
|
||||
GreasePencilOpacityModifierData *omd = (GreasePencilOpacityModifierData *)md;
|
||||
UNUSED_VARS(omd);
|
||||
|
||||
bke::MutableAttributeAccessor attributes = curves.attributes_for_write();
|
||||
bke::SpanAttributeWriter<float> opacities = attributes.lookup_or_add_for_write_span<float>(
|
||||
"opacity", bke::AttrDomain::Point);
|
||||
|
||||
for (const int i : opacities.span.index_range()) {
|
||||
opacities.span[i] *= 0.5f;
|
||||
}
|
||||
|
||||
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
|
||||
opacities.finish();
|
||||
}
|
||||
|
||||
static void modify_geometry_set(ModifierData *md,
|
||||
const ModifierEvalContext *ctx,
|
||||
bke::GeometrySet *geometry_set)
|
||||
{
|
||||
GreasePencilOpacityModifierData *omd = (GreasePencilOpacityModifierData *)md;
|
||||
const Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph);
|
||||
const int frame = scene->r.cfra;
|
||||
|
||||
// TODO
|
||||
UNUSED_VARS(omd, ctx, geometry_set);
|
||||
GreasePencilOpacityModifierData *omd = (GreasePencilOpacityModifierData *)md;
|
||||
UNUSED_VARS(omd);
|
||||
|
||||
GreasePencil *grease_pencil = geometry_set->get_grease_pencil_for_write();
|
||||
if (grease_pencil == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
Vector<Drawing *> drawings = greasepencil::get_drawings_for_write(*grease_pencil, frame);
|
||||
for (Drawing *drawing : drawings) {
|
||||
modify_curves(md, ctx, drawing->strokes_for_write());
|
||||
}
|
||||
}
|
||||
|
||||
static void panel_draw(const bContext * /*C*/, Panel *panel)
|
||||
|
@ -119,7 +159,7 @@ ModifierTypeInfo modifierType_GreasePencilOpacity = {
|
|||
/*struct_name*/ "GreasePencilOpacityModifierData",
|
||||
/*struct_size*/ sizeof(GreasePencilOpacityModifierData),
|
||||
/*srna*/ &RNA_GreasePencilOpacityModifier,
|
||||
/*type*/ ModifierTypeType::NonGeometrical,
|
||||
/*type*/ ModifierTypeType::Nonconstructive,
|
||||
/*flags*/
|
||||
static_cast<ModifierTypeFlag>(
|
||||
eModifierTypeFlag_AcceptsGreasePencil | eModifierTypeFlag_SupportsEditmode |
|
||||
LukasTonne marked this conversation as resolved
Hans Goudey
commented
`points_range` -> `points` is the cononical variable name here. "range" is already described by the type
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
/* SPDX-FileCopyrightText: 2011 by Bastien Montagne. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
/** \file
|
||||
* \ingroup modifiers
|
||||
*/
|
||||
|
||||
#include "MOD_grease_pencil_util.hh"
|
||||
|
||||
#include "BLI_set.hh"
|
||||
|
||||
#include "DNA_grease_pencil_types.h"
|
||||
|
||||
#include "BKE_grease_pencil.hh"
|
||||
|
||||
namespace blender::greasepencil {
|
||||
|
||||
using bke::greasepencil::Drawing;
|
||||
using bke::greasepencil::Layer;
|
||||
|
||||
Vector<bke::greasepencil::Drawing *> get_drawings_for_write(GreasePencil &grease_pencil, int frame)
|
||||
{
|
||||
/* Set of unique drawing indices. */
|
||||
Set<int> drawing_indices;
|
||||
for (Layer *layer : grease_pencil.layers_for_write()) {
|
||||
const int drawing_index = layer->drawing_index_at(frame);
|
||||
if (drawing_index >= 0) {
|
||||
drawing_indices.add(drawing_index);
|
||||
}
|
||||
}
|
||||
|
||||
/* List of owned drawings, ignore drawing references to other data blocks. */
|
||||
Vector<bke::greasepencil::Drawing *> drawings;
|
||||
for (const int drawing_index : drawing_indices) {
|
||||
GreasePencilDrawingBase *drawing_base = grease_pencil.drawing(drawing_index);
|
||||
if (drawing_base->type == GP_DRAWING) {
|
||||
GreasePencilDrawing *drawing = reinterpret_cast<GreasePencilDrawing *>(drawing_base);
|
||||
drawings.append(&drawing->wrap());
|
||||
}
|
||||
}
|
||||
return drawings;
|
||||
}
|
||||
|
||||
} // namespace blender::greasepencil
|
|
@ -0,0 +1,23 @@
|
|||
/* SPDX-FileCopyrightText: 2011 by Bastien Montagne. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
/** \file
|
||||
* \ingroup modifiers
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "BLI_vector.hh"
|
||||
|
||||
struct GreasePencil;
|
||||
namespace blender::bke::greasepencil {
|
||||
class Drawing;
|
||||
}
|
||||
|
||||
namespace blender::greasepencil {
|
||||
|
||||
Vector<bke::greasepencil::Drawing *> get_drawings_for_write(GreasePencil &grease_pencil,
|
||||
int frame);
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Looks like a
clang-format
issue here.