Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpencil_modifiers/intern/MOD_gpencilhook.c
- This file was moved from source/blender/modifiers/intern/MOD_gpencilhook.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 "DNA_modifier_types.h" | |||||
| #include "BLI_math.h" | #include "BLI_math.h" | ||||
| #include "BLI_utildefines.h" | #include "BLI_utildefines.h" | ||||
| #include "BKE_action.h" | #include "BKE_action.h" | ||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_colortools.h" | #include "BKE_colortools.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_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" | ||||
| /* temp struct to hold data */ | /* temp struct to hold data */ | ||||
| struct GPHookData_cb { | struct GPHookData_cb { | ||||
| struct CurveMapping *curfalloff; | struct CurveMapping *curfalloff; | ||||
| char falloff_type; | char falloff_type; | ||||
| float falloff; | float falloff; | ||||
| float falloff_sq; | float falloff_sq; | ||||
| float fac_orig; | float fac_orig; | ||||
| unsigned int use_falloff : 1; | unsigned int use_falloff : 1; | ||||
| unsigned int use_uniform : 1; | unsigned int use_uniform : 1; | ||||
| float cent[3]; | float cent[3]; | ||||
| float mat_uniform[3][3]; | float mat_uniform[3][3]; | ||||
| float mat[4][4]; | float mat[4][4]; | ||||
| }; | }; | ||||
| static void initData(ModifierData *md) | static void initData(GpencilModifierData *md) | ||||
| { | { | ||||
| HookGpencilModifierData *gpmd = (HookGpencilModifierData *)md; | HookGpencilModifierData *gpmd = (HookGpencilModifierData *)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->force = 0.5f; | gpmd->force = 0.5f; | ||||
| gpmd->falloff_type = eGPHook_Falloff_Smooth; | gpmd->falloff_type = eGPHook_Falloff_Smooth; | ||||
| gpmd->curfalloff = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); | gpmd->curfalloff = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); | ||||
| if (gpmd->curfalloff) { | if (gpmd->curfalloff) { | ||||
| curvemapping_initialize(gpmd->curfalloff); | curvemapping_initialize(gpmd->curfalloff); | ||||
| } | } | ||||
| } | } | ||||
| static void copyData(const ModifierData *md, ModifierData *target) | static void copyData(const GpencilModifierData *md, GpencilModifierData *target) | ||||
| { | { | ||||
| HookGpencilModifierData *gmd = (HookGpencilModifierData *)md; | HookGpencilModifierData *gmd = (HookGpencilModifierData *)md; | ||||
| HookGpencilModifierData *tgmd = (HookGpencilModifierData *)target; | HookGpencilModifierData *tgmd = (HookGpencilModifierData *)target; | ||||
| if (tgmd->curfalloff != NULL) { | if (tgmd->curfalloff != NULL) { | ||||
| curvemapping_free(tgmd->curfalloff); | curvemapping_free(tgmd->curfalloff); | ||||
| tgmd->curfalloff = NULL; | tgmd->curfalloff = NULL; | ||||
| } | } | ||||
| modifier_copyData_generic(md, target); | BKE_gpencil_modifier_copyData_generic(md, target); | ||||
| tgmd->curfalloff = curvemapping_copy(gmd->curfalloff); | tgmd->curfalloff = curvemapping_copy(gmd->curfalloff); | ||||
| } | } | ||||
| /* calculate factor of fallof */ | /* calculate factor of fallof */ | ||||
| static float gp_hook_falloff(const struct GPHookData_cb *tData, const float len_sq) | static float gp_hook_falloff(const struct GPHookData_cb *tData, const float len_sq) | ||||
| { | { | ||||
| BLI_assert(tData->falloff_sq); | BLI_assert(tData->falloff_sq); | ||||
| ▲ Show 20 Lines • Show All 74 Lines • ▼ Show 20 Lines | if (fac) { | ||||
| float co_tmp[3]; | float co_tmp[3]; | ||||
| mul_v3_m4v3(co_tmp, tData->mat, &pt->x); | mul_v3_m4v3(co_tmp, tData->mat, &pt->x); | ||||
| interp_v3_v3v3(&pt->x, &pt->x, co_tmp, fac * weight); | interp_v3_v3v3(&pt->x, &pt->x, co_tmp, fac * weight); | ||||
| } | } | ||||
| } | } | ||||
| /* deform stroke */ | /* deform stroke */ | ||||
| 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) | ||||
| { | { | ||||
| HookGpencilModifierData *mmd = (HookGpencilModifierData *)md; | HookGpencilModifierData *mmd = (HookGpencilModifierData *)md; | ||||
| if (!mmd->object) { | if (!mmd->object) { | ||||
| return; | return; | ||||
| } | } | ||||
| int vindex = defgroup_name_index(ob, mmd->vgname); | int vindex = defgroup_name_index(ob, mmd->vgname); | ||||
| ▲ Show 20 Lines • Show All 54 Lines • ▼ Show 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) | ||||
| { | { | ||||
| HookGpencilModifierData *mmd = (HookGpencilModifierData *)md; | HookGpencilModifierData *mmd = (HookGpencilModifierData *)md; | ||||
| Scene *scene = md->scene; | Scene *scene = md->scene; | ||||
| bGPdata *gpd = ob->data; | bGPdata *gpd = ob->data; | ||||
| int oldframe = CFRA; | int oldframe = CFRA; | ||||
| if (mmd->object == NULL) | if (mmd->object == NULL) | ||||
| return; | return; | ||||
| Show All 13 Lines | for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) { | ||||
| } | } | ||||
| } | } | ||||
| /* 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) | ||||
| { | { | ||||
| HookGpencilModifierData *mmd = (HookGpencilModifierData *)md; | HookGpencilModifierData *mmd = (HookGpencilModifierData *)md; | ||||
| if (mmd->curfalloff) { | if (mmd->curfalloff) { | ||||
| curvemapping_free(mmd->curfalloff); | curvemapping_free(mmd->curfalloff); | ||||
| } | } | ||||
| } | } | ||||
| static bool isDisabled(ModifierData *md, int UNUSED(userRenderParams)) | static bool isDisabled(GpencilModifierData *md, int UNUSED(userRenderParams)) | ||||
| { | { | ||||
| HookGpencilModifierData *mmd = (HookGpencilModifierData *)md; | HookGpencilModifierData *mmd = (HookGpencilModifierData *)md; | ||||
| return !mmd->object; | return !mmd->object; | ||||
| } | } | ||||
| static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx) | static void updateDepsgraph(GpencilModifierData *md, const ModifierUpdateDepsgraphContext *ctx) | ||||
| { | { | ||||
| HookGpencilModifierData *lmd = (HookGpencilModifierData *)md; | HookGpencilModifierData *lmd = (HookGpencilModifierData *)md; | ||||
| if (lmd->object != NULL) { | if (lmd->object != NULL) { | ||||
| DEG_add_object_relation(ctx->node, lmd->object, DEG_OB_COMP_GEOMETRY, "Hook Modifier"); | DEG_add_object_relation(ctx->node, lmd->object, DEG_OB_COMP_GEOMETRY, "Hook Modifier"); | ||||
| DEG_add_object_relation(ctx->node, lmd->object, DEG_OB_COMP_TRANSFORM, "Hook Modifier"); | DEG_add_object_relation(ctx->node, lmd->object, DEG_OB_COMP_TRANSFORM, "Hook Modifier"); | ||||
| } | } | ||||
| DEG_add_object_relation(ctx->node, ctx->object, DEG_OB_COMP_TRANSFORM, "Hook Modifier"); | DEG_add_object_relation(ctx->node, ctx->object, DEG_OB_COMP_TRANSFORM, "Hook Modifier"); | ||||
| } | } | ||||
| static void foreachObjectLink( | static void foreachObjectLink( | ||||
| ModifierData *md, Object *ob, | GpencilModifierData *md, Object *ob, | ||||
| ObjectWalkFunc walk, void *userData) | ObjectWalkFunc walk, void *userData) | ||||
| { | { | ||||
| HookGpencilModifierData *mmd = (HookGpencilModifierData *)md; | HookGpencilModifierData *mmd = (HookGpencilModifierData *)md; | ||||
| walk(userData, ob, &mmd->object, IDWALK_CB_NOP); | walk(userData, ob, &mmd->object, IDWALK_CB_NOP); | ||||
| } | } | ||||
| ModifierTypeInfo modifierType_Gpencil_Hook = { | GpencilModifierTypeInfo modifierType_Gpencil_Hook = { | ||||
| /* name */ "Hook", | /* name */ "Hook", | ||||
| /* structName */ "HookGpencilModifierData", | /* structName */ "HookGpencilModifierData", | ||||
| /* structSize */ sizeof(HookGpencilModifierData), | /* structSize */ sizeof(HookGpencilModifierData), | ||||
| /* type */ eModifierTypeType_Gpencil, | /* type */ eGpencilModifierTypeType_Gpencil, | ||||
| /* flags */ eModifierTypeFlag_GpencilMod, | /* flags */ eGpencilModifierTypeFlag_GpencilMod, | ||||
| /* 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, | /* dependsOnNormals */ NULL, | ||||
| /* foreachObjectLink */ foreachObjectLink, | /* foreachObjectLink */ foreachObjectLink, | ||||
| /* foreachIDLink */ NULL, | /* foreachIDLink */ NULL, | ||||
| /* foreachTexLink */ NULL, | /* foreachTexLink */ NULL, | ||||
| }; | }; | ||||