# Surface Deform Modifier for Grease Pencil ### Overview of the project This modifier has been developed by @bettiabba at *MAD Entertainment* for the animation studio feature films development and it's based on Surface Deform Modifier for meshes code. The project aims to bring a better integration between GP strokes and 3D animated characters. ### Modifier Implementation The *Surface Deform modifier* allows an arbitrary mesh surface to control the deformation the Grease Pencil, essentially transferring its motion/deformation. There are two main uses for this: 1. Easy rigging of elaborate GP drawings. Make them follow a rigged mesh cage with clean topolgy. 2. Making GP drawn details follow a mesh. Frames can be added dynamically making it a powerful tool of 3D and 2D blending. :::info :information_source: Info The modifier will work better with lines rather than fills. This is not a modifier limitation, it's rather an issue with the current grease pencil filling algorithm. In order to make the fills work correctly they should have an internal tassellation. Whenever the GP fills will get a tasselation algorithm, the modifier will be able to deform fills correctly. ::: ### Options **Target** The object to which to bind. :::warning :warning: Warning Target Mesh Validity While there are no restrictions with regard to the modified mesh, the target object’s mesh has a few constraints, which if not followed, will prevent a successful binding: * It must not contain edges with more than two faces. * It must not contain concave faces. * It must not contain overlapping vertices (doubles). * It must not contain faces with collinear edges. ::: **Interpolation Falloff** How much a vertex bound to one face of the target will be affected by the surrounding faces. This essentially controls how smooth the deformations are. This setting only applies when binding; it can be set differently for different frames but not changed retroactively. :::info :information_source: Note While lower values result in smoother deformations, they may also introduce slight artifacts. ::: **Strenght** The overall amount of influence the modifier has on deforming the GP. **Vertex Group** Allows you to define the influence per vertex (point). - **Invert** <kbd> <-> </kbd> Inverts the influence of the selected vertex group, meaning that the group now represents points that **will not** be deformed by the modifier. The setting reverses the weight values of the group. ### Binding Operators :::info :information_source: Note until a bound frame is visible, this modifier will have no effect at all. When a bound frame is visible, any change in the target mesh will deform the Grease Pencil. ::: **Bind All** Each frame of the modified Grease Pencil gets bound to the state the target mesh is in that timeline frame, all layers at once. **Bind Current Frame** The current frame of the modified Grease Pencil gets bound to the state the target mesh is in the current timeline frame,all layers at once. The current frame is the Grease Pencil frame that is visible right now due to the current timeline position. **Unbind All** Executing this frees all the frames of the modified Grease Pencil from the target, and resets it to its original shape. **Unbind Current Frame** Executing this frees just the current frame of the modified Grease Pencil from the target, and resets it to its original shape. The current frame is the Grease Pencil frame that is visible right now due to the current timeline position. :::info :information_source: Note The GP’s are bound with regard to global coordinates, but later transformations on the objects are ignored. This means that one can freely transform the target after binding, without affecting the modified object. The modified mesh will only pick up changes to the target object’s mesh itself. ::: :::info :information_source: Note The further a mesh deviates from the target mesh surface, the more likely it is to get undesirable artifacts. For this reason it is recommended to have a clean topology on the binding mesh; the topology should follow the pattern of the drawing as closely as possible. ::: :::warning :warning: Warning When a frame is bound, on the timeline it will turn the same color of the scrubbing background to indicate it is bound and locked. The locked frame cannot be moved or removed on the timeline. To move the frame, please unbind or bake it first. ::: ### Baking The purpose of the bake panel is to bake the deformation of the modifier on the grease pencil, creating new, unbound keyframes. All layers are baked at once. :::info :information_source: Note the freshly baked frames are unbound. They can be bound if desired. This note is also the text at the bottom of the panel, to avoid any confusion. ::: **Bake Current Frame** Bakes the frame at the current timeline position. **Bake Range** Bakes all the frame in the range specified below. **Range start** The start of the frame range to be baked. **Range end** The end of the frame range to be baked. **Fill range** Click on the clock icon at the side of the range to use the *Fill range* operator. It fills the range start and end fields with the current timeline's start and end. ## USAGE GUIDE ### Basic Usage 1. select your grease pencil drawing, then add the surface deform modifier. The modifier can be found under <kbd> Add Modifier > Deform </kbd> list. <img style="display:block;margin:48px left;padding:20px;border:1px #eee;width:75%;" src="https://hackmd.io/_uploads/SJi7p9QET.png" /> 2. in the <kbd> target </kbd> field, select your target mesh 3. click <kbd> Bind All </kbd> <img style="display:block;margin:48px left;padding:30px;border:1px #eee;width:50%;" src="https://hackmd.io/_uploads/BkNQC5mVp.png" /> You can at this point rig, animate or make a cloth simulation with your target mesh as you would normally do and the GP drawing should deform accordingly. <img style="display:block;margin:48px left;padding:30px;border:1px #eee;width:75%;" src="https://hackmd.io/_uploads/ryw9Gj7VT.png"/> ### Advanced Usage 1. create a new blank GP 2. add the <kbd>Surface Deform</kbd> modifier and select your target. 3. Draw on your target mesh with the <kbd> Surface </kbd> stroke placement active. :::info Please note that viewport overlays should be off, otherwise the strokes will stick to anything found in the viewport including *bone widgets, cameras, lights, etc.* ::: 4. Click on the <kbd> bind current frame </kbd> or <kbd>bind all</kbd> button. 5. Scrub on the timeline, then draw another stroke upon your target mesh. 6. Click again on the <kbd> bind current frame </kbd> to bind the newly created GP keyframe Repeat points 5 and 6 to create and bind any new GP keyframe If you want to interpolate bound GP strokes, you can bake the involved keyframe range. At this point all the strokes in the range are unbound and will act as a regular GP drawing, so you can use all the bundled GP tools to edit them. When edits are over, or the interpolation is made, the resulting keyframes can be bound back to the target mesh. ## FURTHER DEVELOPMENT At this moment the only way to effectively interpolate a GP keyframe is to bake it first. This method has some limitations: 1. GP onion skinning overlay tends to intersect the target mesh, making the interpolation process difficult if the <kbd>in front</kbd> option is disabled on the GP object. 2. since GP storkes have to be baked in order to be edited, the interpolation happens in world space without taking in account the supposed tranform applied by the deformer. Both these issues could be solved by including an interpolation operator in the modifier itself so that users could create a new interpolated keyframe between two bound ones whilst taking the deformation in account. ## OTHER RELATED PROJECTS