GPencil: Enable binding to deforming meshes #100301
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
11 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#100301
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
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?
CLICK HERE FOR THE VIDEO!
Most up-to-date code here, for Blender 3.5 Release branch
(#105935)
I am Elisabetta Abbattista. I work at MAD Entertainment, an animation studio you may recognize because of my co-workers’ involvement in the community – such as Ivan Cappiello and Corrado Piscitelli. We work with Blender and everyday we look for new techniques for our production. Lately we’ve been using Grease Pencil quite a lot, because we found it an amazing and versatile tool, though it still has a long way to go and a big room for improvement. We would like to improve Blender for everyone, so we thought that a good way to give some new functionality to Grease Pencil without giving up all its current features would be giving it a new modifier – the Grease Pencil equivalent of Surface Deform.
Reasons: we have rigged models with grease pencil strokes drawn on them. These gp’s should move together with the rigged models, but their weighting process is tedious and inaccurate. They should hang onto the mesh surface and deform along with it or a dedicated mesh cage.
Surface deform modifier implementation for grease pencil
What I’m looking for:
Feedback from developers about the actual feasibility of the goals and methods. I will post updates about the work done so far on the new modifier. The work is currently just started.
How we are going to do it:
The grease pencil surface deform modifier should use the surface of a mesh to deform a grease pencil stroke. So all the computation made on the target mesh should be taken as it is from the “MOD_surfacedeform.c” file – this includes especially the functions “computeBindWeights” and “bindVert”. The internal weight system of the Surface Deform modifier helps smooth the deformation.
WORK DONE SO FAR
I started off copying the file MOD_surfacedeform.c from the /modifiers/intern/ folder, renamed it and put it in
/source/blender/gpencil_modifiers/intern/MOD_gpencilsurdeform.c
I copied off the data structures in /source/blender/makesdna/DNA_gpencil_modifier_types.h
and the main defaults DNA_gpencil_modifier_defaults.h
I added the Bind operator in /source/blender/editors/object/object_gpencil_modifier.c
and its reference in /source/blender/editors/object/object_ops.c
I also added all the references needed to add the modifier to the modifier list: /source/blender/gpencil_modifiers/MOD_gpencil_modifiertypes.h
/source/blender/gpencil_modifiers/intern/MOD_gpencil_util.c
/source/blender/makesdna/intern/dna_defaults.c
I added the RNA:
/source/blender/makesrna/intern/rna_gpencil_modifier.c
Finally, I edited the CmakeLists.txt accordingly.
I decided to internally name the new modifier “SurDeform” because of the name of the data structure: “SurfaceDeformGpencilModifierData” was too long and it overflowed. On the contrary, “SurDeformGpencilModifierData” is ok. I changed every internal name accordingly (modifierType_Gpencil_SurDeform, GPENCIL_OT_gpencilsurdeform_bind,
eGpencilModifierType_SurDeform, MOD_gpencilsurdeform.c) to avoid any confusion.
Now in the MOD_gpencilsurdeform.c file, I needed to fit the mesh modifier functions to the grease pencil modifier.
First off, the “deformVerts” function becomes “deformStroke”. This is tricky because we don’t have access to all the points in the grease pencil, but only the current stroke, and the strokes are evaluated one at a time.
So I added an extra structure in the makesdna/DNA_gpencil_modifier_types.h file: SDefGPStroke. I also renamed SDefBind and SdefVert to SDefGPBind and SDefGPVert.
The SDefGPStroke structure’s first variable, “verts”, is a pointer to the verts array of instances of the SDefGPVert structure.
Then it also contains “stroke_verts_num”, which is the total number of verts in the stroke, analogue to its SurfaceDeformModifierData counterpart.
A pointer to an array of SDefGPStroke’s is kept in the SurDeformGPencilModifierData structure.
The array of SDefGPStroke’s is allocated through a new function I made for the purpose in the MOD_gpencilsurdeform.c file, “static bool first_bind(uint strokes_num, SurDeformGpencilModifierData *smd)”. It is called during the first stroke’s bind, as the name suggests, and it’s only called if the pointer gps→prev is NULL, where “gps” is the bGPDstroke
passed to the deformStroke function, meaning this is the first stroke. This is because when the modifier calculation is forced outside of the depsgraph’s evaluation to execute the bind function, though the Bind operator, it should also cycle through each stroke and launch the bind function every time.
Accordingly, I edited the copyData and freeData functions, to include the new allocated array. I also edited these functions to fit the grease pencil modifier way, replacing the “BKE” functions with their grease pencil counterparts.
The flagsystem is unchanged. I disabled for now the extra functionalities of the modifier, because I ‘m not sure they can be useful in grease pencil but that will be addressed in the future, after the basic implementation of the modifier. Because of this, the only working flag is GP_MOD_SDEF_BIND and seems to work as intended, both as an indicator for the operator UI display of text (“Bind”/”Unbind”) and as an indicator of whether or not to proceed with the evaluation; it also makes an appearance in the isDisabled function, as a condition that has to be met for the modifier to be not considered disabled.
So what works now?
The modifier can be added on a Grease Pencil object; its UI and RNA properties work, so it can also be edited via Python. The Bind operator also works and can execute bind, and display “Bind” or “Unbind” text in the right way.
Now on to the things that don’t work yet.
Other proposals
- My version of the grease to mesh addon creates the geometry using bmesh.
- Masks are not yet supported.
- Materials are currently created with vertex colors and some corrective nodes, due to gamma issues issues with reading and recreating the grease pencil colors.
Added subscriber: @bettiabba
Added subscribers: @filedescriptor, @ChengduLittleA, @antoniov
Very interesting proposal. This modifier is a common request that I have received but hadn't time to look at it because I'm not an expert in the mesh deformation code.
Some general ideas:
About the code, the best is create a patch and keep updating it during the process. In this way different developers can look at your code and help you yo fix small issues or give you ideas.
I'm really very excited to see what are you going to do.
About add-ons, We have a claymation add-on that converts GPencil to meshes and with some improvements not included in Simon code, for example materials, and other code simplifications because I added some C core functions since Simon created the original add-on.
CC: @filedescriptor @ChengduLittleA
Enable grease pencil binding to deforming meshesto GPencil: Enable binding to deforming meshesChanged status from 'Needs Triage' to: 'Confirmed'
Added subscribers: @mendio, @pepe-school-land
Added subscriber: @Yuro
Added subscriber: @hamza-el-barmaki
Added subscriber: @icappiello
Progress update:
The stroke deformation finally works! I submitted a diff file and attached it to this task. https://developer.blender.org/D16692
Currently working:
Currently not working:
Warning about the diff patch:
It's a patch for Blender 3.3. I worked on a fork of the blender-v3.3-release branch, because new GP modifiers are being added to the master branch and this caused a conflict of memory, so I switched to an old, stable release to have a more stable working enviromnent.
Progress update:
Currentky working:
Issue I'm investigating right now:
Going to post updated code soon!
Progress update:
I updated the diff once more. Soon a video showcasing the modifier is going to come out!
I will demonstrate the two ues of the modifier:
Now working:
Not yet working:
Added subscriber: @AdamEarle
What is it that you are really wanting to achieve here?
Can you create a fake example or diagram of the purpose? If I'm incorrect, apologies. This sounds like trying to get automatic tweens through some kind of rigging setup.
If so there is another way that this can be approached that could be more basic than the current approach and less technical for the animator on setup.
Added subscriber: @PaoloAcampora
Added subscriber: @4thDimension
Here is the explanatory video: https://youtu.be/fiS-5CTulRM
WOW! Great presentation! It's exactly what I thought you were doing. I can see how everybody will be going crazy over this feature for hybrid animation. I am curious as to why you went in this direction, but that is for another time and space.
I will leave by saying, well done and my thoughts are with you so you can bring it across the finish line.
Great work and great video Elisabetta! I definitely have to test it :)
Added subscriber: @MaxCajazeiras
Added subscriber: @JorgeVP
Big news! I finished porting the modifier to the Main Branch!
While I was working something else changed... The system for publishing diffs.
So instead of moving the diff to a new system, I followed the tutorial and published the Main Branch version directly:
#105139
Patch for Blender 3.5 coming soon! (Useful if your production is using this version of Blender)
Update time! I've only been working on the blender-v3.5-release branch lately.
I finally uploaded the patch: #105935
What works now:
What doesn't work yet: