GPv3: Subdivide modifier #117056

Merged
Falk David merged 20 commits from ChengduLittleA/blender:gp3-mod-subdiv into main 2024-01-18 13:03:05 +01:00
Member

Ported stroke subdivide modifier to GPv3.

图片

Note: catmull smooth is not present in this modifier, all it does is to subdivide strokes. In versioning, the old subdiv modifier probably should be replaced into two modifiers Subdiv+Smooth combo using the new curve subdiv/smooth functions.

Ported stroke subdivide modifier to GPv3. ![图片](/attachments/90cb2ac0-206e-44a6-b058-bf8d39987d0b) Note: catmull smooth is not present in this modifier, all it does is to subdivide strokes. In versioning, the old subdiv modifier probably should be replaced into two modifiers Subdiv+Smooth combo using the new curve subdiv/smooth functions.
YimingWu added the
Interest
Grease Pencil
Module
Grease Pencil
labels 2024-01-12 09:41:05 +01:00
YimingWu added 3 commits 2024-01-12 09:41:15 +01:00
YimingWu added this to the Grease Pencil project 2024-01-12 09:41:27 +01:00
YimingWu added 2 commits 2024-01-16 02:52:39 +01:00
YimingWu added 3 commits 2024-01-17 07:12:35 +01:00
YimingWu changed title from WIP: GPv3: Subdivide modifier to GPv3: Subdivide modifier 2024-01-17 07:16:10 +01:00
YimingWu added 1 commit 2024-01-17 08:58:29 +01:00
66314237d1 Remove curve influence option
It's not effective anyway
YimingWu added 1 commit 2024-01-17 13:20:28 +01:00
YimingWu added 1 commit 2024-01-17 13:20:51 +01:00
Falk David requested changes 2024-01-17 14:27:58 +01:00
Falk David left a comment
Member

Some comments.

Some comments.
@ -1129,12 +1129,12 @@ static int add_material_from_template(Main &bmain, Object &ob, const ColorTempla
return index;
}
static bke::CurvesGeometry create_drawing_data(const Span<float3> positions,
Member

These changes shouldn't be in the PR.

These changes shouldn't be in the PR.
ChengduLittleA marked this conversation as resolved
@ -200,6 +200,13 @@ IndexMask retrieve_editable_and_selected_elements(Object &object,
bke::AttrDomain selection_domain,
IndexMaskMemory &memory);
bke::CurvesGeometry create_drawing_data(const Span<float3> positions,
Member

These changes shouldn't be in the PR.

These changes shouldn't be in the PR.
Author
Member

Should I create a separate PR for exposing this create_drawing_data function?

Wait.. Ignore, I don't know why this is here...

~~Should I create a separate PR for exposing this `create_drawing_data` function?~~ Wait.. Ignore, I don't know why this is here...
ChengduLittleA marked this conversation as resolved
@ -2486,6 +2487,7 @@ typedef enum VolumeToMeshFlag {
VOLUME_TO_MESH_USE_SMOOTH_SHADE = 1 << 0,
} VolumeToMeshFlag;
/* enum is kept in legacy dna. */
Member

What is this comment for?

What is this comment for?
ChengduLittleA marked this conversation as resolved
@ -2550,0 +2555,4 @@
GreasePencilModifierInfluenceData influence;
/** `GreasePencilSubdivModifierFlag`. */
int flag;
/** Factor of subdivision. */
Member

Factor of subdivision -> Number of subdivisions

`Factor of subdivision` -> `Number of subdivisions`
ChengduLittleA marked this conversation as resolved
@ -0,0 +98,4 @@
static void deform_stroke(ModifierData *md,
Depsgraph * /*depsgraph*/,
Object *ob,
bke::greasepencil::Drawing *drawing)
Member

Pass the drawing by reference: bke::greasepencil::Drawing &drawing

Pass the drawing by reference: `bke::greasepencil::Drawing &drawing`
ChengduLittleA marked this conversation as resolved
@ -0,0 +102,4 @@
{
GreasePencilSubdivModifierData *mmd = (GreasePencilSubdivModifierData *)md;
if (mmd->level < 1) {
Member

Shouldn't this check be in modify_geometry_set ?

Shouldn't this check be in `modify_geometry_set` ?
ChengduLittleA marked this conversation as resolved
@ -0,0 +122,4 @@
bke::GeometrySet *geometry_set)
{
GreasePencilSubdivModifierData *mmd = (GreasePencilSubdivModifierData *)md;
GreasePencil *gp = geometry_set->get_grease_pencil_for_write();
Member

Put this after the check below and use a reference like so:

GreasePencil &grease_pencil = *geometry_set->get_grease_pencil_for_write();
Put this after the check below and use a reference like so: ``` GreasePencil &grease_pencil = *geometry_set->get_grease_pencil_for_write(); ```
ChengduLittleA marked this conversation as resolved
@ -0,0 +123,4 @@
{
GreasePencilSubdivModifierData *mmd = (GreasePencilSubdivModifierData *)md;
GreasePencil *gp = geometry_set->get_grease_pencil_for_write();
const int frame = DEG_get_evaluated_scene(ctx->depsgraph)->r.cfra;
Member

frame -> current_frame

`frame` -> `current_frame`
ChengduLittleA marked this conversation as resolved
@ -0,0 +125,4 @@
GreasePencil *gp = geometry_set->get_grease_pencil_for_write();
const int frame = DEG_get_evaluated_scene(ctx->depsgraph)->r.cfra;
if (!gp) {
Member

Use !geometry_set->has_grease_pencil()

Use `!geometry_set->has_grease_pencil()`
ChengduLittleA marked this conversation as resolved
@ -0,0 +130,4 @@
}
IndexMaskMemory mask_memory;
IndexMask layer_mask = modifier::greasepencil::get_filtered_layer_mask(
Member

const IndexMask

`const IndexMask`
ChengduLittleA marked this conversation as resolved
@ -0,0 +174,4 @@
}
ModifierTypeInfo modifierType_GreasePencilSubdiv = {
/*idname*/ "Grese Pencil Subdiv Modifier",
Member

"Grese Pencil Subdiv Modifier" -> "GreasePencilSubdivModifier"

`"Grese Pencil Subdiv Modifier"` -> `"GreasePencilSubdivModifier"`
ChengduLittleA marked this conversation as resolved
@ -0,0 +175,4 @@
ModifierTypeInfo modifierType_GreasePencilSubdiv = {
/*idname*/ "Grese Pencil Subdiv Modifier",
/*name*/ N_("Subdiv Modifier"),
Member

"Subdivide"

`"Subdivide"`
ChengduLittleA marked this conversation as resolved
YimingWu added 1 commit 2024-01-17 15:04:22 +01:00
Falk David reviewed 2024-01-17 15:09:05 +01:00
@ -0,0 +123,4 @@
return;
}
GreasePencil *gp = geometry_set->get_grease_pencil_for_write();
Member

GreasePencil &grease_pencil = *geometry_set->get_grease_pencil_for_write();

`GreasePencil &grease_pencil = *geometry_set->get_grease_pencil_for_write();`
ChengduLittleA marked this conversation as resolved
Falk David requested changes 2024-01-17 15:13:43 +01:00
Falk David left a comment
Member

This looks very close now!

This looks very close now!
@ -0,0 +55,4 @@
static void init_data(ModifierData *md)
{
GreasePencilSubdivModifierData *gpmd = (GreasePencilSubdivModifierData *)md;
Member

C++ casts, same for the rest of the file

C++ casts, same for the rest of the file
ChengduLittleA marked this conversation as resolved
@ -0,0 +95,4 @@
modifier::greasepencil::read_influence_data(reader, &mmd->influence);
}
static void deform_stroke(ModifierData *md,
Member

I guess this function should now be named deform_drawing since it acts on one drawing at a time.

I guess this function should now be named `deform_drawing` since it acts on one drawing at a time.
ChengduLittleA marked this conversation as resolved
YimingWu added 1 commit 2024-01-17 15:13:55 +01:00
YimingWu added 1 commit 2024-01-17 15:22:08 +01:00
YimingWu added 1 commit 2024-01-17 15:25:40 +01:00
Falk David approved these changes 2024-01-17 15:38:30 +01:00
Falk David left a comment
Member

Nice! Looks good!

Nice! Looks good!
Hans Goudey requested changes 2024-01-17 15:49:24 +01:00
@ -7680,0 +7708,4 @@
prop = RNA_def_property(srna, "open_influence_panel", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(
prop, nullptr, "flag", MOD_GREASE_PENCIL_OPACITY_OPEN_INFLUENCE_PANEL);
Member

This can use rna_def_modifier_panel_open_prop

This can use `rna_def_modifier_panel_open_prop`
ChengduLittleA marked this conversation as resolved
@ -0,0 +8,4 @@
#include "BLI_array.hh"
#include "BLI_index_mask.hh"
#include "BLI_math_matrix.h"
Member

Looks like some unused includes here

Looks like some unused includes here
ChengduLittleA marked this conversation as resolved
@ -0,0 +97,4 @@
modifier::greasepencil::read_influence_data(reader, &mmd->influence);
}
static void deform_drawing(ModifierData *md,
Member

Use references for pointer arguments that shouldn't be null

Use references for pointer arguments that shouldn't be null
ChengduLittleA marked this conversation as resolved
@ -0,0 +108,4 @@
const IndexMask strokes = modifier::greasepencil::get_filtered_stroke_mask(
ob, drawing.strokes_for_write(), mmd->influence, memory);
VArray<int> cuts = VArray<int>::ForSingle(mmd->level, drawing.strokes().points_num());
Member

Seems like this should use something more like 2^mmd->level, otherwise this changes behavior compared to GPv2

Seems like this should use something more like `2^mmd->level`, otherwise this changes behavior compared to GPv2
Member

Although this is true, I would like to keep this the way it is now and handle old values during versioning.

Although this is true, I would like to keep this the way it is now and handle old values during versioning.
Member

Sounds good. That can be mentioned in the commit message then.

Sounds good. That can be mentioned in the commit message then.
Member

Yes, there is also #114419 where I try to document this :D

Yes, there is also https://projects.blender.org/blender/blender/issues/114419 where I try to document this :D
ChengduLittleA marked this conversation as resolved
YimingWu added 2 commits 2024-01-18 06:51:40 +01:00
Pratik Borhade reviewed 2024-01-18 07:47:22 +01:00
@ -7680,0 +7713,4 @@
prop = RNA_def_property(srna, "level", PROP_INT, PROP_NONE);
RNA_def_property_int_sdna(prop, nullptr, "level");
RNA_def_property_range(prop, 0, 16);
RNA_def_property_ui_range(prop, 0.0, 5.0, 1, 0);
Member

soft min/max should be int values, no? :)

soft min/max should be int values, no? :)
Author
Member

humm looks like everywhere else uses float so I'm not sure. It's just what the function accepts

humm looks like everywhere else uses float so I'm not sure. It's just what the function accepts
ChengduLittleA marked this conversation as resolved
Pratik Borhade reviewed 2024-01-18 07:55:14 +01:00
@ -7680,0 +7701,4 @@
rna_def_modifier_grease_pencil_layer_filter(srna);
rna_def_modifier_grease_pencil_material_filter(
srna, "rna_GreasePencilOpacityModifier_material_filter_set");
Member

This looks wrong. Should be rna_GreasePencilSubdivModifier_material_filter_set. Same for vgroup

And possibly also need to include RNA_MOD_GREASE_PENCIL_MATERIAL_FILTER_SET(GreasePencilSubdiv) if I understood correctly.

Wait but I haven't tested your PR locally yet, will do that :)

This looks wrong. Should be `rna_GreasePencilSubdivModifier_material_filter_set`. Same for vgroup And possibly also need to include `RNA_MOD_GREASE_PENCIL_MATERIAL_FILTER_SET(GreasePencilSubdiv)` if I understood correctly. Wait but I haven't tested your PR locally yet, will do that :)
Author
Member

Yepp thanks for pointing that out. I thought it was for a generic function. Looks like I need to rename that.

Yepp thanks for pointing that out. I thought it was for a generic function. Looks like I need to rename that.
Member

Looks good otherwise 😅

Looks good otherwise 😅
ChengduLittleA marked this conversation as resolved
YimingWu added 1 commit 2024-01-18 08:27:30 +01:00
Falk David reviewed 2024-01-18 10:15:31 +01:00
@ -7680,0 +7715,4 @@
prop = RNA_def_property(srna, "level", PROP_INT, PROP_NONE);
RNA_def_property_int_sdna(prop, nullptr, "level");
RNA_def_property_range(prop, 0, 16);
RNA_def_property_ui_range(prop, 0.0, 5.0, 1, 0);
Member

Hm I don't think these ranges make sense anymore (because of the 2^n thing previously). Have you tested the modifier with these limits? I think we should go up to 32 (2^5) and make the maximum 65536 (2^16).

Hm I don't think these ranges make sense anymore (because of the 2^n thing previously). Have you tested the modifier with these limits? I think we should go up to 32 (2^5) and make the maximum 65536 (2^16).
Author
Member

Good point... since the algorithm is different now.

Good point... since the algorithm is different now.
ChengduLittleA marked this conversation as resolved
YimingWu added 1 commit 2024-01-18 10:23:53 +01:00
Falk David requested changes 2024-01-18 11:02:23 +01:00
Falk David left a comment
Member

Tested this locally and found some issues.

Tested this locally and found some issues.
@ -7680,0 +7717,4 @@
/* Since the new subdiv algorithm uses linear cut count, we set the limits as 2^n the old value
* to get the same range as before. */
RNA_def_property_range(prop, 0, 2 ^ 16);
RNA_def_property_ui_range(prop, 0, 2 ^ 5, 1, 0);
Member

😅 This won't work. The ^ is the bitwise xor operator. You should just write in the values. 65536 and 32.

😅 This won't work. The `^` is the bitwise xor operator. You should just write in the values. `65536` and `32`.
ChengduLittleA marked this conversation as resolved
@ -0,0 +174,4 @@
/*struct_name*/ "GreasePencilSubdivModifierData",
/*struct_size*/ sizeof(GreasePencilSubdivModifierData),
/*srna*/ &RNA_GreasePencilSubdivModifier,
/*type*/ ModifierTypeType::Nonconstructive,
Member

The type is not right, this should be ModifierTypeType::Constructive.

The type is not right, this should be `ModifierTypeType::Constructive`.
Author
Member

But this modifier essentially deletes previous strokes and create new ones?

But this modifier essentially deletes previous strokes and create new ones?
Member

Hm maybe @JacquesLucke can clarify what should be used?

Hm maybe @JacquesLucke can clarify what should be used?
Member

Constructive seems right. Also see modifierType_Subsurf.

`Constructive` seems right. Also see `modifierType_Subsurf`.
filedescriptor marked this conversation as resolved
@ -0,0 +175,4 @@
/*struct_size*/ sizeof(GreasePencilSubdivModifierData),
/*srna*/ &RNA_GreasePencilSubdivModifier,
/*type*/ ModifierTypeType::Nonconstructive,
/*flags*/ eModifierTypeFlag_AcceptsGreasePencil,
Member

There are some missing flags here. Use

static_cast<ModifierTypeFlag>(eModifierTypeFlag_AcceptsGreasePencil |
                                  eModifierTypeFlag_SupportsEditmode |
                                  eModifierTypeFlag_EnableInEditmode)
There are some missing flags here. Use ``` static_cast<ModifierTypeFlag>(eModifierTypeFlag_AcceptsGreasePencil | eModifierTypeFlag_SupportsEditmode | eModifierTypeFlag_EnableInEditmode) ```
filedescriptor marked this conversation as resolved
YimingWu force-pushed gp3-mod-subdiv from 7d94c0c64b to d703724517 2024-01-18 11:54:57 +01:00 Compare
Member

@blender-bot build

@blender-bot build
Falk David approved these changes 2024-01-18 12:06:47 +01:00
Falk David left a comment
Member

Alright, accepting this 👍 Will kick a build and when that goes through I think we're ready to merge.

Alright, accepting this 👍 Will kick a build and when that goes through I think we're ready to merge.
Falk David merged commit 4d387843e9 into main 2024-01-18 13:03:05 +01:00
Falk David referenced this issue from a commit 2024-01-18 13:03:07 +01:00
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
5 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#117056
No description provided.