GPv3: Hook modifier #118452
No reviewers
Labels
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
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#118452
Loading…
Reference in New Issue
No description provided.
Delete Branch "ChengduLittleA/blender:gp3-mod-hook"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Hook modifier migrated to Grease Pencil v3.
First pass
@ -0,0 +123,4 @@
};
/* Calculate the factor of falloff. */
static float gpencil_hook_falloff(const GreasePencilHookData_cb *tData, const float len_sq)
gpencil_hook_falloff
->hook_falloff
@ -0,0 +134,4 @@
if (tData->falloff_type == MOD_GREASE_PENCIL_HOOK_Falloff_Const) {
fac = 1.0f;
goto finally;
Replace this with
return tData->fac_orig;
@ -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;
Same as above.
@ -0,0 +142,4 @@
goto finally;
}
fac = 1.0f - (math::sqrt(len_sq) / tData->falloff);
make this
float fac = ...
and remove thefloat fac;
declaration@ -0,0 +146,4 @@
switch (tData->falloff_type) {
case MOD_GREASE_PENCIL_HOOK_Falloff_Curve:
fac = BKE_curvemapping_evaluateF(tData->curfalloff, 0, fac);
All of these cases can just return the value instead of assigning to
fac
@ -0,0 +167,4 @@
break;
}
finally:
Remove this.
@ -0,0 +170,4 @@
finally:
return fac * tData->fac_orig;
}
else {
No need for else after return.
@ -0,0 +176,4 @@
}
/* apply point deformation */
static void gpencil_hook_co_apply(GreasePencilHookData_cb *tData, float weight, float3 &position)
This function seems unnecessary, I'd just put the code in the loop. That also removes the need for a
GreasePencilHookData_cb
struct.Second pass
@ -0,0 +116,4 @@
if (len_sq > falloff_sq) {
return 0.0f;
}
if (len_sq > 0.0f) {
make this
len_sq <= 0.0f
andreturn fac_orig;
@ -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;
;
^
@ -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. */
Use
ATTR_FALLTHROUGH
@ -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;
const
@ -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;
const
@ -0,0 +239,4 @@
fac = fac_orig;
}
if (fac) {
This should be a bit more explicit since
fac
is afloat
. Does this meanfac != 0.0f
?@ -0,0 +240,4 @@
}
if (fac) {
float3 co_tmp = math::transform_point(use_mat, positions[point]);
const
@blender-bot build
Looks good to me.
@ -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.
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.
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());
I would be surprised if this line is needed.
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.We can also keep it. I see that other code does the same indeed.
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");
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).@ -0,0 +327,4 @@
ModifierTypeInfo modifierType_GreasePencilHook = {
/*idname*/ "GreasePencilHookModifier",
/*name*/ N_("Hoook"),
"Hoook"
->"Hook"
@blender-bot build