GPv3: Hook modifier #118452

Merged
Falk David merged 11 commits from ChengduLittleA/blender:gp3-mod-hook into main 2024-02-21 14:20:56 +01:00
Member

Hook modifier migrated to Grease Pencil v3.

图片

Hook modifier migrated to Grease Pencil v3. ![图片](/attachments/83bcc77d-828c-4a39-ae0b-9344ae24fecc)
YimingWu added the
Interest
Grease Pencil
Module
Grease Pencil
labels 2024-02-19 09:40:39 +01:00
YimingWu added 1 commit 2024-02-19 09:40:49 +01:00
YimingWu added this to the Grease Pencil project 2024-02-19 09:41:23 +01:00
Falk David requested review from Falk David 2024-02-19 10:31:20 +01:00
Falk David requested changes 2024-02-19 12:02:32 +01:00
Falk David left a comment
Member

First pass

First pass
@ -0,0 +123,4 @@
};
/* Calculate the factor of falloff. */
static float gpencil_hook_falloff(const GreasePencilHookData_cb *tData, const float len_sq)
Member

gpencil_hook_falloff -> hook_falloff

`gpencil_hook_falloff` -> `hook_falloff`
ChengduLittleA marked this conversation as resolved
@ -0,0 +134,4 @@
if (tData->falloff_type == MOD_GREASE_PENCIL_HOOK_Falloff_Const) {
fac = 1.0f;
goto finally;
Member

Replace this with return tData->fac_orig;

Replace this with `return tData->fac_orig;`
ChengduLittleA marked this conversation as resolved
@ -0,0 +139,4 @@
else if (tData->falloff_type == MOD_GREASE_PENCIL_HOOK_Falloff_InvSquare) {
/* avoid sqrt below */
fac = 1.0f - (len_sq / tData->falloff_sq);
goto finally;
Member

Same as above.

Same as above.
ChengduLittleA marked this conversation as resolved
@ -0,0 +142,4 @@
goto finally;
}
fac = 1.0f - (math::sqrt(len_sq) / tData->falloff);
Member

make this float fac = ... and remove the float fac; declaration

make this `float fac = ...` and remove the `float fac;` declaration
ChengduLittleA marked this conversation as resolved
@ -0,0 +146,4 @@
switch (tData->falloff_type) {
case MOD_GREASE_PENCIL_HOOK_Falloff_Curve:
fac = BKE_curvemapping_evaluateF(tData->curfalloff, 0, fac);
Member

All of these cases can just return the value instead of assigning to fac

All of these cases can just return the value instead of assigning to `fac`
ChengduLittleA marked this conversation as resolved
@ -0,0 +167,4 @@
break;
}
finally:
Member

Remove this.

Remove this.
ChengduLittleA marked this conversation as resolved
@ -0,0 +170,4 @@
finally:
return fac * tData->fac_orig;
}
else {
Member

No need for else after return.

No need for else after return.
ChengduLittleA marked this conversation as resolved
@ -0,0 +176,4 @@
}
/* apply point deformation */
static void gpencil_hook_co_apply(GreasePencilHookData_cb *tData, float weight, float3 &position)
Member

This function seems unnecessary, I'd just put the code in the loop. That also removes the need for a GreasePencilHookData_cb struct.

This function seems unnecessary, I'd just put the code in the loop. That also removes the need for a `GreasePencilHookData_cb` struct.
ChengduLittleA marked this conversation as resolved
YimingWu added 1 commit 2024-02-19 12:25:01 +01:00
YimingWu added 1 commit 2024-02-19 12:28:52 +01:00
Falk David requested changes 2024-02-19 12:43:30 +01:00
Falk David left a comment
Member

Second pass

Second pass
@ -0,0 +116,4 @@
if (len_sq > falloff_sq) {
return 0.0f;
}
if (len_sq > 0.0f) {
Member

make this len_sq <= 0.0f and return fac_orig;

make this `len_sq <= 0.0f` and `return fac_orig;`
ChengduLittleA marked this conversation as resolved
@ -0,0 +136,4 @@
return (3.0f * fac * fac - 2.0f * fac * fac * fac) * fac_orig;
case MOD_GREASE_PENCIL_HOOK_Falloff_Root:
return math::sqrt(fac) * fac_orig;
;
Member

^

^
ChengduLittleA marked this conversation as resolved
@ -0,0 +140,4 @@
break;
case MOD_GREASE_PENCIL_HOOK_Falloff_Sphere:
return math::sqrt(2 * fac - fac * fac) * fac_orig;
case MOD_GREASE_PENCIL_HOOK_Falloff_Linear: /* Pass. */
Member

Use ATTR_FALLTHROUGH

Use `ATTR_FALLTHROUGH`
ChengduLittleA marked this conversation as resolved
@ -0,0 +171,4 @@
const float falloff = (mmd.falloff_type == eHook_Falloff_None) ? 0.0f : mmd.falloff;
const float falloff_sq = square_f(falloff);
const float fac_orig = mmd.force;
bool use_falloff = falloff_sq != 0.0f;
Member

const

`const`
ChengduLittleA marked this conversation as resolved
@ -0,0 +172,4 @@
const float falloff_sq = square_f(falloff);
const float fac_orig = mmd.force;
bool use_falloff = falloff_sq != 0.0f;
bool use_uniform = (mmd.flag & MOD_GRAESE_PENCIL_HOOK_UNIFORM_SPACE) != 0;
Member

const

`const`
ChengduLittleA marked this conversation as resolved
@ -0,0 +239,4 @@
fac = fac_orig;
}
if (fac) {
Member

This should be a bit more explicit since fac is a float. Does this mean fac != 0.0f ?

This should be a bit more explicit since `fac` is a `float`. Does this mean `fac != 0.0f` ?
ChengduLittleA marked this conversation as resolved
@ -0,0 +240,4 @@
}
if (fac) {
float3 co_tmp = math::transform_point(use_mat, positions[point]);
Member

const

`const`
ChengduLittleA marked this conversation as resolved
YimingWu added 1 commit 2024-02-19 12:52:32 +01:00
buildbot/vexp-code-patch-lint Build done. Details
buildbot/vexp-code-patch-linux-x86_64 Build done. Details
buildbot/vexp-code-patch-windows-amd64 Build done. Details
buildbot/vexp-code-patch-darwin-arm64 Build done. Details
buildbot/vexp-code-patch-darwin-x86_64 Build done. Details
buildbot/vexp-code-patch-coordinator Build done. Details
568058da39
Cleanups
Falk David requested review from Lukas Tönne 2024-02-19 12:57:35 +01:00
Member

@blender-bot build

@blender-bot build
Falk David approved these changes 2024-02-19 13:58:36 +01:00
Falk David left a comment
Member

Looks good to me.

Looks good to me.
Iliya Katushenock reviewed 2024-02-19 17:32:23 +01:00
@ -0,0 +174,4 @@
const bool use_falloff = falloff_sq != 0.0f;
const bool use_uniform = (mmd.flag & MOD_GRAESE_PENCIL_HOOK_UNIFORM_SPACE) != 0;
float3x3 mat_uniform;

Please, always try to create value of varible only once.

const float3x3 mat_uniform = use_uniform ? float3x3(float4x4(mmd.parentinv)); : float3x3::identity();
float3x3 mat_uniform;
...
mat_uniform = float3x3(float4x4(mmd.parentinv));
...
something another

First one much easert to read than second. Always try to create just another one temporal variable, and make sure this variable will be const.

Please, always try to create value of varible only once. ```Cpp const float3x3 mat_uniform = use_uniform ? float3x3(float4x4(mmd.parentinv)); : float3x3::identity(); ``` ```Cpp float3x3 mat_uniform; ... mat_uniform = float3x3(float4x4(mmd.parentinv)); ... something another ``` First one much easert to read than second. Always try to create just another one temporal variable, and make sure this variable will be const.
ChengduLittleA marked this conversation as resolved
YimingWu added 2 commits 2024-02-20 01:28:29 +01:00
YimingWu added 1 commit 2024-02-20 01:31:27 +01:00
Falk David requested changes 2024-02-20 10:55:56 +01:00
Falk David left a comment
Member

Found another thing

Found another thing
@ -0,0 +191,4 @@
/* Just object target. */
dmat = mmd.object->object_to_world();
}
ob.runtime->world_to_object = math::invert(ob.object_to_world());
Member

I would be surprised if this line is needed.

I would be surprised if this line is needed.
Author
Member

I'm not sure. This is what insides the original modifier code. I will now change the line below to use ob.world_to_object() directly then.

I'm not sure. This is what insides the original modifier code. I will now change the line below to use `ob.world_to_object()` directly then.
Member

We can also keep it. I see that other code does the same indeed.

We can also keep it. I see that other code does the same indeed.
ChengduLittleA marked this conversation as resolved
YimingWu added 1 commit 2024-02-20 12:23:20 +01:00
YimingWu added 1 commit 2024-02-21 08:08:16 +01:00
Falk David requested changes 2024-02-21 10:28:33 +01:00
Falk David left a comment
Member

Some more comments

Some more comments
@ -0,0 +77,4 @@
{
auto *mmd = reinterpret_cast<GreasePencilHookModifierData *>(md);
if (mmd->object != nullptr) {
DEG_add_object_relation(ctx->node, mmd->object, DEG_OB_COMP_GEOMETRY, "Hook Modifier");
Member

There shouldn't be a DEG_OB_COMP_GEOMETRY relation. We only ever use the transform of the object. Using this results in depsgraph warnings (since e.g. empties don't have geometry).

There shouldn't be a `DEG_OB_COMP_GEOMETRY` relation. We only ever use the transform of the object. Using this results in depsgraph warnings (since e.g. empties don't have geometry).
ChengduLittleA marked this conversation as resolved
@ -0,0 +327,4 @@
ModifierTypeInfo modifierType_GreasePencilHook = {
/*idname*/ "GreasePencilHookModifier",
/*name*/ N_("Hoook"),
Member

"Hoook" -> "Hook"

`"Hoook"` -> `"Hook"`
ChengduLittleA marked this conversation as resolved
YimingWu added 1 commit 2024-02-21 13:01:20 +01:00
YimingWu added 1 commit 2024-02-21 13:02:22 +01:00
buildbot/vexp-code-patch-lint Build done. Details
buildbot/vexp-code-patch-linux-x86_64 Build done. Details
buildbot/vexp-code-patch-darwin-arm64 Build done. Details
buildbot/vexp-code-patch-darwin-x86_64 Build done. Details
buildbot/vexp-code-patch-windows-amd64 Build done. Details
buildbot/vexp-code-patch-coordinator Build done. Details
46e15cc687
Merge branch 'main' into gp3-mod-hook
Member

@blender-bot build

@blender-bot build
Falk David approved these changes 2024-02-21 14:20:20 +01:00
Falk David referenced this issue from a commit 2024-02-21 14:20:56 +01:00
Falk David merged commit 2225ce8202 into main 2024-02-21 14:20:56 +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#118452
No description provided.