Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpencil_modifiers/intern/MOD_gpencillattice.c
- This file was moved from source/blender/modifiers/intern/MOD_gpencillattice.c.
| Show All 28 Lines | |||||
| */ | */ | ||||
| #include <stdio.h> | #include <stdio.h> | ||||
| #include "DNA_meshdata_types.h" | #include "DNA_meshdata_types.h" | ||||
| #include "DNA_scene_types.h" | #include "DNA_scene_types.h" | ||||
| #include "DNA_object_types.h" | #include "DNA_object_types.h" | ||||
| #include "DNA_gpencil_types.h" | #include "DNA_gpencil_types.h" | ||||
| #include "DNA_gpencil_modifier_types.h" | |||||
| #include "BLI_utildefines.h" | #include "BLI_utildefines.h" | ||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_deform.h" | #include "BKE_deform.h" | ||||
| #include "BKE_gpencil.h" | #include "BKE_gpencil.h" | ||||
| #include "BKE_gpencil_modifier.h" | |||||
| #include "BKE_modifier.h" | |||||
| #include "BKE_lattice.h" | #include "BKE_lattice.h" | ||||
| #include "BKE_library_query.h" | #include "BKE_library_query.h" | ||||
| #include "BKE_scene.h" | #include "BKE_scene.h" | ||||
| #include "BKE_main.h" | #include "BKE_main.h" | ||||
| #include "BKE_layer.h" | #include "BKE_layer.h" | ||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #include "MOD_modifiertypes.h" | |||||
| #include "MOD_gpencil_util.h" | #include "MOD_gpencil_util.h" | ||||
| #include "MOD_gpencil_modifiertypes.h" | |||||
| #include "DEG_depsgraph.h" | #include "DEG_depsgraph.h" | ||||
| #include "DEG_depsgraph_build.h" | #include "DEG_depsgraph_build.h" | ||||
| #include "DEG_depsgraph_query.h" | |||||
| static void initData(ModifierData *md) | static void initData(GpencilModifierData *md) | ||||
| { | { | ||||
| LatticeGpencilModifierData *gpmd = (LatticeGpencilModifierData *)md; | LatticeGpencilModifierData *gpmd = (LatticeGpencilModifierData *)md; | ||||
| gpmd->pass_index = 0; | gpmd->pass_index = 0; | ||||
| gpmd->layername[0] = '\0'; | gpmd->layername[0] = '\0'; | ||||
| gpmd->vgname[0] = '\0'; | gpmd->vgname[0] = '\0'; | ||||
| gpmd->object = NULL; | gpmd->object = NULL; | ||||
| gpmd->cache_data = NULL; | gpmd->cache_data = NULL; | ||||
| gpmd->strength = 1.0f; | gpmd->strength = 1.0f; | ||||
| } | } | ||||
| static void copyData(const ModifierData *md, ModifierData *target) | static void copyData(const GpencilModifierData *md, GpencilModifierData *target) | ||||
| { | { | ||||
| modifier_copyData_generic(md, target); | BKE_gpencil_modifier_copyData_generic(md, target); | ||||
| } | } | ||||
| static void gp_deformStroke( | static void gp_deformStroke( | ||||
| ModifierData *md, Depsgraph *UNUSED(depsgraph), | GpencilModifierData *md, Depsgraph *UNUSED(depsgraph), | ||||
| Object *ob, bGPDlayer *gpl, bGPDstroke *gps) | Object *ob, bGPDlayer *gpl, bGPDstroke *gps) | ||||
| { | { | ||||
| LatticeGpencilModifierData *mmd = (LatticeGpencilModifierData *)md; | LatticeGpencilModifierData *mmd = (LatticeGpencilModifierData *)md; | ||||
| int vindex = defgroup_name_index(ob, mmd->vgname); | int vindex = defgroup_name_index(ob, mmd->vgname); | ||||
| float weight = 1.0f; | float weight = 1.0f; | ||||
| if (!is_stroke_affected_by_modifier(ob, | if (!is_stroke_affected_by_modifier(ob, | ||||
| mmd->layername, mmd->pass_index, 3, gpl, gps, | mmd->layername, mmd->pass_index, 3, gpl, gps, | ||||
| Show All 20 Lines | static void gp_deformStroke( | ||||
| } | } | ||||
| } | } | ||||
| /* FIXME: Ideally we be doing this on a copy of the main depsgraph | /* FIXME: Ideally we be doing this on a copy of the main depsgraph | ||||
| * (i.e. one where we don't have to worry about restoring state) | * (i.e. one where we don't have to worry about restoring state) | ||||
| */ | */ | ||||
| static void gp_bakeModifier( | static void gp_bakeModifier( | ||||
| Main *bmain, Depsgraph *depsgraph, | Main *bmain, Depsgraph *depsgraph, | ||||
| ModifierData *md, Object *ob) | GpencilModifierData *md, Object *ob) | ||||
| { | { | ||||
| LatticeGpencilModifierData *mmd = (LatticeGpencilModifierData *)md; | LatticeGpencilModifierData *mmd = (LatticeGpencilModifierData *)md; | ||||
| Scene *scene = md->scene; | Scene *scene = md->scene; | ||||
| struct LatticeDeformData *ldata = NULL; | struct LatticeDeformData *ldata = NULL; | ||||
| bGPdata *gpd = ob->data; | bGPdata *gpd = ob->data; | ||||
| int oldframe = CFRA; | int oldframe = (int)DEG_get_ctime(depsgraph); | ||||
| if (mmd->object == NULL) | if (mmd->object == NULL) | ||||
| return; | return; | ||||
| for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) { | for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) { | ||||
| for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) { | for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) { | ||||
| /* apply lattice effects on this frame | /* apply lattice effects on this frame | ||||
| * NOTE: this assumes that we don't want lattice animation on non-keyframed frames | * NOTE: this assumes that we don't want lattice animation on non-keyframed frames | ||||
| Show All 18 Lines | if (ldata) { | ||||
| mmd->cache_data = NULL; | mmd->cache_data = NULL; | ||||
| } | } | ||||
| /* return frame state and DB to original state */ | /* return frame state and DB to original state */ | ||||
| CFRA = oldframe; | CFRA = oldframe; | ||||
| BKE_scene_graph_update_for_newframe(depsgraph, bmain); | BKE_scene_graph_update_for_newframe(depsgraph, bmain); | ||||
| } | } | ||||
| static void freeData(ModifierData *md) | static void freeData(GpencilModifierData *md) | ||||
| { | { | ||||
| LatticeGpencilModifierData *mmd = (LatticeGpencilModifierData *)md; | LatticeGpencilModifierData *mmd = (LatticeGpencilModifierData *)md; | ||||
| struct LatticeDeformData *ldata = (struct LatticeDeformData *)mmd->cache_data; | struct LatticeDeformData *ldata = (struct LatticeDeformData *)mmd->cache_data; | ||||
| /* free deform data */ | /* free deform data */ | ||||
| if (ldata) { | if (ldata) { | ||||
| end_latt_deform(ldata); | end_latt_deform(ldata); | ||||
| } | } | ||||
| } | } | ||||
| static bool isDisabled(ModifierData *md, int UNUSED(userRenderParams)) | static bool isDisabled(GpencilModifierData *md, int UNUSED(userRenderParams)) | ||||
| { | { | ||||
| LatticeGpencilModifierData *mmd = (LatticeGpencilModifierData *)md; | LatticeGpencilModifierData *mmd = (LatticeGpencilModifierData *)md; | ||||
| return !mmd->object; | return !mmd->object; | ||||
| } | } | ||||
| static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx) | static void updateDepsgraph(GpencilModifierData *md, const ModifierUpdateDepsgraphContext *ctx) | ||||
| { | { | ||||
| LatticeGpencilModifierData *lmd = (LatticeGpencilModifierData *)md; | LatticeGpencilModifierData *lmd = (LatticeGpencilModifierData *)md; | ||||
| if (lmd->object != NULL) { | if (lmd->object != NULL) { | ||||
| DEG_add_object_relation(ctx->node, lmd->object, DEG_OB_COMP_GEOMETRY, "Lattice Modifier"); | DEG_add_object_relation(ctx->node, lmd->object, DEG_OB_COMP_GEOMETRY, "Lattice Modifier"); | ||||
| DEG_add_object_relation(ctx->node, lmd->object, DEG_OB_COMP_TRANSFORM, "Lattice Modifier"); | DEG_add_object_relation(ctx->node, lmd->object, DEG_OB_COMP_TRANSFORM, "Lattice Modifier"); | ||||
| } | } | ||||
| DEG_add_object_relation(ctx->node, ctx->object, DEG_OB_COMP_TRANSFORM, "Lattice Modifier"); | DEG_add_object_relation(ctx->node, ctx->object, DEG_OB_COMP_TRANSFORM, "Lattice Modifier"); | ||||
| } | } | ||||
| static void foreachObjectLink( | static void foreachObjectLink( | ||||
| ModifierData *md, Object *ob, | GpencilModifierData *md, Object *ob, | ||||
| ObjectWalkFunc walk, void *userData) | ObjectWalkFunc walk, void *userData) | ||||
| { | { | ||||
| LatticeGpencilModifierData *mmd = (LatticeGpencilModifierData *)md; | LatticeGpencilModifierData *mmd = (LatticeGpencilModifierData *)md; | ||||
| walk(userData, ob, &mmd->object, IDWALK_CB_NOP); | walk(userData, ob, &mmd->object, IDWALK_CB_NOP); | ||||
| } | } | ||||
| ModifierTypeInfo modifierType_Gpencil_Lattice = { | GpencilModifierTypeInfo modifierType_Gpencil_Lattice = { | ||||
| /* name */ "Lattice", | /* name */ "Lattice", | ||||
| /* structName */ "LatticeGpencilModifierData", | /* structName */ "LatticeGpencilModifierData", | ||||
| /* structSize */ sizeof(LatticeGpencilModifierData), | /* structSize */ sizeof(LatticeGpencilModifierData), | ||||
| /* type */ eModifierTypeType_Gpencil, | /* type */ eGpencilModifierTypeType_Gpencil, | ||||
| /* flags */ eModifierTypeFlag_GpencilMod | eModifierTypeFlag_Single | eModifierTypeFlag_SupportsEditmode, | /* flags */ eGpencilModifierTypeFlag_Single | eGpencilModifierTypeFlag_SupportsEditmode, | ||||
| /* copyData */ copyData, | /* copyData */ copyData, | ||||
| /* deformVerts_DM */ NULL, | |||||
| /* deformMatrices_DM */ NULL, | |||||
| /* deformVertsEM_DM */ NULL, | |||||
| /* deformMatricesEM_DM*/NULL, | |||||
| /* applyModifier_DM */ NULL, | |||||
| /* applyModifierEM_DM */NULL, | |||||
| /* deformVerts */ NULL, | |||||
| /* deformMatrices */ NULL, | |||||
| /* deformVertsEM */ NULL, | |||||
| /* deformMatricesEM */ NULL, | |||||
| /* applyModifier */ NULL, | |||||
| /* applyModifierEM */ NULL, | |||||
| /* gp_deformStroke */ gp_deformStroke, | /* gp_deformStroke */ gp_deformStroke, | ||||
| /* gp_generateStrokes */ NULL, | /* gp_generateStrokes */ NULL, | ||||
| /* gp_bakeModifier */ gp_bakeModifier, | /* gp_bakeModifier */ gp_bakeModifier, | ||||
| /* initData */ initData, | /* initData */ initData, | ||||
| /* requiredDataMask */ NULL, | |||||
| /* freeData */ freeData, | /* freeData */ freeData, | ||||
| /* isDisabled */ isDisabled, | /* isDisabled */ isDisabled, | ||||
| /* updateDepsgraph */ updateDepsgraph, | /* updateDepsgraph */ updateDepsgraph, | ||||
| /* dependsOnTime */ NULL, | /* dependsOnTime */ NULL, | ||||
| /* dependsOnNormals */ NULL, | |||||
| /* foreachObjectLink */ foreachObjectLink, | /* foreachObjectLink */ foreachObjectLink, | ||||
| /* foreachIDLink */ NULL, | /* foreachIDLink */ NULL, | ||||
| /* foreachTexLink */ NULL, | /* foreachTexLink */ NULL, | ||||
| }; | }; | ||||