Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpencil_modifiers/intern/MOD_gpencilsubdiv.c
- This file was moved from source/blender/modifiers/intern/MOD_gpencilsubdiv.c.
| Show All 30 Lines | |||||
| #include <stdio.h> | #include <stdio.h> | ||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.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_math.h" | #include "BLI_math.h" | ||||
| #include "BLI_utildefines.h" | #include "BLI_utildefines.h" | ||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_gpencil.h" | #include "BKE_gpencil.h" | ||||
| #include "BKE_gpencil_modifier.h" | |||||
| #include "DEG_depsgraph.h" | #include "DEG_depsgraph.h" | ||||
| #include "MOD_modifiertypes.h" | |||||
| #include "MOD_gpencil_util.h" | #include "MOD_gpencil_util.h" | ||||
| #include "MOD_gpencil_modifiertypes.h" | |||||
| static void initData(ModifierData *md) | static void initData(GpencilModifierData *md) | ||||
| { | { | ||||
| SubdivGpencilModifierData *gpmd = (SubdivGpencilModifierData *)md; | SubdivGpencilModifierData *gpmd = (SubdivGpencilModifierData *)md; | ||||
| gpmd->pass_index = 0; | gpmd->pass_index = 0; | ||||
| gpmd->level = 1; | gpmd->level = 1; | ||||
| gpmd->layername[0] = '\0'; | gpmd->layername[0] = '\0'; | ||||
| } | } | ||||
| 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); | ||||
| } | } | ||||
| /* subdivide stroke to get more control points */ | /* subdivide stroke to get more control points */ | ||||
| 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) | ||||
| { | { | ||||
| SubdivGpencilModifierData *mmd = (SubdivGpencilModifierData *)md; | SubdivGpencilModifierData *mmd = (SubdivGpencilModifierData *)md; | ||||
| bGPDspoint *temp_points; | bGPDspoint *temp_points; | ||||
| int totnewpoints, oldtotpoints; | int totnewpoints, oldtotpoints; | ||||
| int i2; | int i2; | ||||
| 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, | ||||
| mmd->flag & GP_SUBDIV_INVERT_LAYER, mmd->flag & GP_SUBDIV_INVERT_PASS)) | mmd->flag & GP_SUBDIV_INVERT_LAYER, mmd->flag & GP_SUBDIV_INVERT_PASS)) | ||||
| { | { | ||||
| return; | return; | ||||
| } | } | ||||
| /* loop as many times as levels */ | /* loop as many times as levels */ | ||||
| for (int s = 0; s < mmd->level; s++) { | for (int s = 0; s < mmd->level; s++) { | ||||
| totnewpoints = gps->totpoints - 1; | totnewpoints = gps->totpoints - 1; | ||||
| /* duplicate points in a temp area */ | /* duplicate points in a temp area */ | ||||
| temp_points = MEM_dupallocN(gps->points); | temp_points = MEM_dupallocN(gps->points); | ||||
| oldtotpoints = gps->totpoints; | oldtotpoints = gps->totpoints; | ||||
| /* resize the points arrys */ | /* resize the points arrys */ | ||||
| gps->totpoints += totnewpoints; | gps->totpoints += totnewpoints; | ||||
| gps->points = MEM_recallocN(gps->points, sizeof(*gps->points) * gps->totpoints); | gps->points = MEM_recallocN(gps->points, sizeof(*gps->points) * gps->totpoints); | ||||
| gps->points = MEM_recallocN(gps->dvert, sizeof(*gps->dvert) * gps->totpoints); | gps->dvert = MEM_recallocN(gps->dvert, sizeof(*gps->dvert) * gps->totpoints); | ||||
| gps->flag |= GP_STROKE_RECALC_CACHES; | gps->flag |= GP_STROKE_RECALC_CACHES; | ||||
| /* move points from last to first to new place */ | /* move points from last to first to new place */ | ||||
| i2 = gps->totpoints - 1; | i2 = gps->totpoints - 1; | ||||
| for (int i = oldtotpoints - 1; i > 0; i--) { | for (int i = oldtotpoints - 1; i > 0; i--) { | ||||
| bGPDspoint *pt = &temp_points[i]; | bGPDspoint *pt = &temp_points[i]; | ||||
| bGPDspoint *pt_final = &gps->points[i2]; | bGPDspoint *pt_final = &gps->points[i2]; | ||||
| ▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | if ((mmd->flag & GP_SUBDIV_SIMPLE) == 0) { | ||||
| /* free temp memory */ | /* free temp memory */ | ||||
| MEM_SAFE_FREE(temp_points); | MEM_SAFE_FREE(temp_points); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void gp_bakeModifier( | static void gp_bakeModifier( | ||||
| struct Main *UNUSED(bmain), Depsgraph *depsgraph, | struct Main *UNUSED(bmain), Depsgraph *depsgraph, | ||||
| ModifierData *md, Object *ob) | GpencilModifierData *md, Object *ob) | ||||
| { | { | ||||
| bGPdata *gpd = ob->data; | bGPdata *gpd = ob->data; | ||||
| 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) { | ||||
| for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) { | for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) { | ||||
| gp_deformStroke(md, depsgraph, ob, gpl, gps); | gp_deformStroke(md, depsgraph, ob, gpl, gps); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| ModifierTypeInfo modifierType_Gpencil_Subdiv = { | GpencilModifierTypeInfo modifierType_Gpencil_Subdiv = { | ||||
| /* name */ "Subdivision", | /* name */ "Subdivision", | ||||
| /* structName */ "SubdivGpencilModifierData", | /* structName */ "SubdivGpencilModifierData", | ||||
| /* structSize */ sizeof(SubdivGpencilModifierData), | /* structSize */ sizeof(SubdivGpencilModifierData), | ||||
| /* type */ eModifierTypeType_Gpencil, | /* type */ eGpencilModifierTypeType_Gpencil, | ||||
| /* flags */ eModifierTypeFlag_GpencilMod | eModifierTypeFlag_SupportsEditmode, | /* flags */ eGpencilModifierTypeFlag_GpencilMod | 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 */ NULL, | /* freeData */ NULL, | ||||
| /* isDisabled */ NULL, | /* isDisabled */ NULL, | ||||
| /* updateDepsgraph */ NULL, | /* updateDepsgraph */ NULL, | ||||
| /* dependsOnTime */ NULL, | /* dependsOnTime */ NULL, | ||||
| /* dependsOnNormals */ NULL, | /* dependsOnNormals */ NULL, | ||||
| /* foreachObjectLink */ NULL, | /* foreachObjectLink */ NULL, | ||||
| /* foreachIDLink */ NULL, | /* foreachIDLink */ NULL, | ||||
| /* foreachTexLink */ NULL, | /* foreachTexLink */ NULL, | ||||
| }; | }; | ||||