GPv3: Array modifier #117722

Merged
YimingWu merged 4 commits from ChengduLittleA/blender:gp3-mod-array into main 2024-02-01 15:59:01 +01:00
Member

Grease Pencil Array modifier migrated to GPv3.

All features working as expected.

图片

Grease Pencil Array modifier migrated to GPv3. All features working as expected. ![图片](/attachments/17991229-81b7-4eda-81c0-a92297a438b4)
YimingWu added the
Interest
Grease Pencil
Module
Grease Pencil
labels 2024-02-01 13:12:35 +01:00
YimingWu added 2 commits 2024-02-01 13:12:50 +01:00
YimingWu added this to the Grease Pencil project 2024-02-01 13:13:49 +01:00
Falk David requested changes 2024-02-01 13:33:49 +01:00
Falk David left a comment
Member

First quick pass.

First quick pass.
@ -0,0 +152,4 @@
std::optional<blender::Bounds<float3>> bounds = filtered_curves.bounds_min_max();
if (bounds.has_value()) {
size = bounds.value().max - bounds.value().min;
/* Need a minimum size (for flat drawings). */
Member

I'm not sure I understand the comment. Drawings won't have a size that's zero unless everything is in the same point.

I'm not sure I understand the comment. Drawings won't have a size that's zero unless everything is in the same point.
Author
Member

This was there in the original modifier. I guess for stuff like the default objects, they are flat on exactly 1 axis so it's gonna have 0 size on that axis. I don't think this is needed, but for consistency with old modifier maybe we keep it here?

This was there in the original modifier. I guess for stuff like the default objects, they are flat on exactly 1 axis so it's gonna have 0 size on that axis. I don't think this is needed, but for consistency with old modifier maybe we keep it here?
@ -0,0 +161,4 @@
float3x3 rand;
for (int j = 0; j < 3; j++) {
const uint3 primes(2, 3, 7);
double3 offset(0.0, 0.0, 0.0);
Member

double3 offset(0.0);

`double3 offset(0.0);`
ChengduLittleA marked this conversation as resolved
@ -0,0 +180,4 @@
}
}
/* Calculate Random matrix. */
float3 loc, rot;
Member

This whole thing can be written as:

return math::from_loc_rot_scale<float4x4>(mmd.rnd_offset * rand[0], mmd.rnd_rot * rand[1], float3(1.0f) + mmd.rnd_scale * rand[2]);
This whole thing can be written as: ``` return math::from_loc_rot_scale<float4x4>(mmd.rnd_offset * rand[0], mmd.rnd_rot * rand[1], float3(1.0f) + mmd.rnd_scale * rand[2]); ```
ChengduLittleA marked this conversation as resolved
@ -0,0 +192,4 @@
float4x4 current_offset = float4x4::identity();
for (const int elem_id : IndexRange(1, mmd.count)) {
float4x4 mat, mat_offset;
get_array_matrix(ob, mmd, elem_id, mat, mat_offset);
Member

I'm not sure why this function can't just return a single matrix. Either you multiply into current_offset or you overwrite it, but you never need these two different matrices.

I'm not sure why this function can't just return a single matrix. Either you multiply into `current_offset` or you overwrite it, but you never need these two different matrices.
ChengduLittleA marked this conversation as resolved
YimingWu added 1 commit 2024-02-01 13:45:09 +01:00
Hans Goudey requested changes 2024-02-01 15:10:42 +01:00
Hans Goudey left a comment
Member

Looking good generally, just have a few comments

Looking good generally, just have a few comments
@ -0,0 +103,4 @@
offset = float3(0.0f);
}
const float4x4 r_mat = math::from_loc_rot_scale<float4x4, float3, 3>(offset, rot, scale);
Member

from_loc_rot_scale<float4x4>( should do the trick, the other template parameters can be deduced automatically

`from_loc_rot_scale<float4x4>(` should do the trick, the other template parameters can be deduced automatically
Member

Also rot and scale are always zero.. better to use from_location then, and not do unnecessary work

Also `rot` and `scale` are always zero.. better to use `from_location` then, and not do unnecessary work
ChengduLittleA marked this conversation as resolved
@ -0,0 +111,4 @@
if (mmd.flag & MOD_GREASE_PENCIL_ARRAY_USE_OFFSET) {
mat_offset[3] += mmd.offset;
}
obinv = math::invert(float4x4(ob.object_to_world));
Member

Declare variables at the same place they're initialized

Declare variables at the same place they're initialized
ChengduLittleA marked this conversation as resolved
@ -0,0 +115,4 @@
return mat_offset * obinv * float4x4(mmd.object->object_to_world);
}
else {
Member

else after return is unnecessary

else after return is unnecessary
ChengduLittleA marked this conversation as resolved
@ -0,0 +162,4 @@
}
}
auto get_rand_matrix = [&](const int elem_id) {
Member

Could this be a separate function rather than a lambda? Seems nicer to get it out of the way. And maybe passing GreasePencilArrayModifierData would be enough.

Could this be a separate function rather than a lambda? Seems nicer to get it out of the way. And maybe passing `GreasePencilArrayModifierData` would be enough.
Author
Member

Good point. However per-stroke elem_id is needed for BLI_halton_3d like the legacy implementation.

Good point. However per-stroke `elem_id` is needed for `BLI_halton_3d` like the legacy implementation.
Member

Sure, I mean with two arguments, the modifier data and the index

Sure, I mean with two arguments, the modifier data and the index
ChengduLittleA marked this conversation as resolved
@ -0,0 +241,4 @@
*/
bke::CurvesGeometry copy = bke::CurvesGeometry(src_curves);
drawing.strokes_for_write() = create_array_copies(*ctx.object, mmd, src_curves, copy);
Member

std::move(copy)

`std::move(copy)`
ChengduLittleA marked this conversation as resolved
@ -0,0 +247,4 @@
bke::CurvesGeometry masked_curves = bke::curves_copy_curve_selection(
src_curves, curves_mask, {});
drawing.strokes_for_write() = create_array_copies(*ctx.object, mmd, src_curves, masked_curves);
Member

std::move(masked_curves)

`std::move(masked_curves)`
Author
Member

It will give me this error if I use std::move :

error: cannot bind non-const lvalue reference of type ‘blender::bke::CurvesGeometry&’ to an rvalue of type ‘std::remove_reference<blender::bke::CurvesGeometry&>::type’ {aka ‘blender::bke::CurvesGeometry’}
It will give me this error if I use `std::move` : ``` error: cannot bind non-const lvalue reference of type ‘blender::bke::CurvesGeometry&’ to an rvalue of type ‘std::remove_reference<blender::bke::CurvesGeometry&>::type’ {aka ‘blender::bke::CurvesGeometry’} ```
Member

Ah, in this case the argument to create_array_copies doesn't need to be a reference

Ah, in this case the argument to `create_array_copies` doesn't need to be a reference
ChengduLittleA marked this conversation as resolved
YimingWu added 1 commit 2024-02-01 15:48:35 +01:00
Hans Goudey approved these changes 2024-02-01 15:54:20 +01:00
YimingWu merged commit e1ce3c3cc7 into main 2024-02-01 15:59:01 +01:00
YimingWu referenced this issue from a commit 2024-02-01 15:59:01 +01:00
YimingWu deleted branch gp3-mod-array 2024-02-01 15:59:03 +01:00
YimingWu referenced this issue from a commit 2024-02-05 10:56:05 +01:00
Member

@ChengduLittleA You can open this PR again by either pushing your local gp3-mod-array branch to your fork (and then creating a PR) or if you don't have the branch anymore, you can do:

git checkout main
git cherry-pick --no-commit e1ce3c3cc783155e7a729491620bdd88473c3fdd
git checkout -b gpv3-array-modifier
git commit
git push <your-remote>
@ChengduLittleA You can open this PR again by either pushing your local `gp3-mod-array` branch to your fork (and then creating a PR) or if you don't have the branch anymore, you can do: ``` git checkout main git cherry-pick --no-commit e1ce3c3cc783155e7a729491620bdd88473c3fdd git checkout -b gpv3-array-modifier git commit git push <your-remote> ```
Jonas Dichelle referenced this issue from a commit 2024-02-08 17:29: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
3 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#117722
No description provided.