Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/gpencil_modifier.c
| Show All 37 Lines | |||||
| #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_gpencil_modifier_types.h" | ||||
| #include "BKE_library.h" | #include "BKE_library.h" | ||||
| #include "BKE_library_query.h" | #include "BKE_library_query.h" | ||||
| #include "BKE_gpencil.h" | #include "BKE_gpencil.h" | ||||
| #include "BKE_lattice.h" | #include "BKE_lattice.h" | ||||
| #include "BKE_material.h" | |||||
| #include "BKE_gpencil_modifier.h" | #include "BKE_gpencil_modifier.h" | ||||
| #include "BKE_object.h" | #include "BKE_object.h" | ||||
| #include "DEG_depsgraph.h" | #include "DEG_depsgraph.h" | ||||
| #include "DEG_depsgraph_query.h" | #include "DEG_depsgraph_query.h" | ||||
| #include "MOD_gpencil_modifiertypes.h" | #include "MOD_gpencil_modifiertypes.h" | ||||
| ▲ Show 20 Lines • Show All 387 Lines • ▼ Show 20 Lines | void BKE_gpencil_eval_geometry(Depsgraph *depsgraph, bGPdata *gpd) | ||||
| DEG_debug_print_eval(depsgraph, __func__, gpd->id.name, gpd); | DEG_debug_print_eval(depsgraph, __func__, gpd->id.name, gpd); | ||||
| int ctime = (int)DEG_get_ctime(depsgraph); | int ctime = (int)DEG_get_ctime(depsgraph); | ||||
| /* update active frame */ | /* update active frame */ | ||||
| for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) { | for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) { | ||||
| gpl->actframe = BKE_gpencil_layer_getframe(gpl, ctime, GP_GETFRAME_USE_PREV); | gpl->actframe = BKE_gpencil_layer_getframe(gpl, ctime, GP_GETFRAME_USE_PREV); | ||||
| } | } | ||||
| /* TODO: Move "derived_gpf" logic here from DRW_gpencil_populate_datablock()? | |||||
| * This would be better than inventing our own logic for this stuff... | |||||
| */ | |||||
| /* TODO: Move the following code to "BKE_gpencil_eval_done()" (marked as an exit node) | |||||
| * later when there's more happening here. For now, let's just keep this in here to avoid | |||||
| * needing to have one more node slowing down evaluation... | |||||
| */ | |||||
| if (DEG_is_active(depsgraph)) { | if (DEG_is_active(depsgraph)) { | ||||
| bGPdata *gpd_orig = (bGPdata *)DEG_get_original_id(&gpd->id); | bGPdata *gpd_orig = (bGPdata *)DEG_get_original_id(&gpd->id); | ||||
| /* sync "actframe" changes back to main-db too, | /* sync "actframe" changes back to main-db too, | ||||
| * so that editing tools work with copy-on-write | * so that editing tools work with copy-on-write | ||||
| * when the current frame changes | * when the current frame changes | ||||
| */ | */ | ||||
| for (bGPDlayer *gpl = gpd_orig->layers.first; gpl; gpl = gpl->next) { | for (bGPDlayer *gpl = gpd_orig->layers.first; gpl; gpl = gpl->next) { | ||||
| ▲ Show 20 Lines • Show All 244 Lines • ▼ Show 20 Lines | 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]; | ||||
| copy_v3_v3(&pt_final->x, &pt->x); | copy_v3_v3(&pt_final->x, &pt->x); | ||||
| pt_final->pressure = pt->pressure; | pt_final->pressure = pt->pressure; | ||||
| pt_final->strength = pt->strength; | pt_final->strength = pt->strength; | ||||
| pt_final->time = pt->time; | pt_final->time = pt->time; | ||||
| pt_final->flag = pt->flag; | pt_final->flag = pt->flag; | ||||
| pt_final->runtime.pt_orig = pt->runtime.pt_orig; | |||||
| pt_final->runtime.idx_orig = pt->runtime.idx_orig; | |||||
| if (gps->dvert != NULL) { | if (gps->dvert != NULL) { | ||||
| dvert = &temp_dverts[i]; | dvert = &temp_dverts[i]; | ||||
| dvert_final = &gps->dvert[i2]; | dvert_final = &gps->dvert[i2]; | ||||
| dvert_final->totweight = dvert->totweight; | dvert_final->totweight = dvert->totweight; | ||||
| dvert_final->dw = dvert->dw; | dvert_final->dw = dvert->dw; | ||||
| } | } | ||||
| i2 -= 2; | i2 -= 2; | ||||
| } | } | ||||
| /* interpolate mid points */ | /* interpolate mid points */ | ||||
| i2 = 1; | i2 = 1; | ||||
| for (int i = 0; i < oldtotpoints - 1; i++) { | for (int i = 0; i < oldtotpoints - 1; i++) { | ||||
| bGPDspoint *pt = &temp_points[i]; | bGPDspoint *pt = &temp_points[i]; | ||||
| bGPDspoint *next = &temp_points[i + 1]; | bGPDspoint *next = &temp_points[i + 1]; | ||||
| bGPDspoint *pt_final = &gps->points[i2]; | bGPDspoint *pt_final = &gps->points[i2]; | ||||
| /* add a half way point */ | /* add a half way point */ | ||||
| interp_v3_v3v3(&pt_final->x, &pt->x, &next->x, 0.5f); | interp_v3_v3v3(&pt_final->x, &pt->x, &next->x, 0.5f); | ||||
| pt_final->pressure = interpf(pt->pressure, next->pressure, 0.5f); | pt_final->pressure = interpf(pt->pressure, next->pressure, 0.5f); | ||||
| pt_final->strength = interpf(pt->strength, next->strength, 0.5f); | pt_final->strength = interpf(pt->strength, next->strength, 0.5f); | ||||
| CLAMP(pt_final->strength, GPENCIL_STRENGTH_MIN, 1.0f); | CLAMP(pt_final->strength, GPENCIL_STRENGTH_MIN, 1.0f); | ||||
| pt_final->time = interpf(pt->time, next->time, 0.5f); | pt_final->time = interpf(pt->time, next->time, 0.5f); | ||||
| pt_final->runtime.pt_orig = NULL; | |||||
| if (gps->dvert != NULL) { | if (gps->dvert != NULL) { | ||||
| dvert = &temp_dverts[i]; | dvert = &temp_dverts[i]; | ||||
| dvert_next = &temp_dverts[i + 1]; | dvert_next = &temp_dverts[i + 1]; | ||||
| dvert_final = &gps->dvert[i2]; | dvert_final = &gps->dvert[i2]; | ||||
| dvert_final->totweight = dvert->totweight; | dvert_final->totweight = dvert->totweight; | ||||
| dvert_final->dw = MEM_dupallocN(dvert->dw); | dvert_final->dw = MEM_dupallocN(dvert->dw); | ||||
| Show All 29 Lines | if ((flag & GP_SUBDIV_SIMPLE) == 0) { | ||||
| /* move point */ | /* move point */ | ||||
| interp_v3_v3v3(&pt_final->x, &pt->x, &next->x, 0.5f); | interp_v3_v3v3(&pt_final->x, &pt->x, &next->x, 0.5f); | ||||
| } | } | ||||
| /* free temp memory */ | /* free temp memory */ | ||||
| MEM_SAFE_FREE(temp_points); | MEM_SAFE_FREE(temp_points); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* Copy frame but do not assign new memory */ | |||||
| static void gpencil_frame_copy_noalloc(Object *ob, bGPDframe *gpf, bGPDframe *eval_gpf) | |||||
antoniov: maybe better naming is `gpencil_frame_copy` | |||||
| { | |||||
| eval_gpf->prev = gpf->prev; | |||||
| eval_gpf->next = gpf->next; | |||||
| eval_gpf->framenum = gpf->framenum; | |||||
| eval_gpf->flag = gpf->flag; | |||||
| eval_gpf->key_type = gpf->key_type; | |||||
| eval_gpf->runtime = gpf->runtime; | |||||
| copy_m4_m4(eval_gpf->runtime.parent_obmat, gpf->runtime.parent_obmat); | |||||
| /* copy strokes */ | |||||
| BLI_listbase_clear(&eval_gpf->strokes); | |||||
| for (bGPDstroke *gps_src = gpf->strokes.first; gps_src; gps_src = gps_src->next) { | |||||
| /* make copy of source stroke */ | |||||
| bGPDstroke *gps_dst = BKE_gpencil_stroke_duplicate(gps_src); | |||||
| /* copy color to temp fields to apply temporal changes in the stroke */ | |||||
| MaterialGPencilStyle *gp_style = BKE_material_gpencil_settings_get(ob, gps_src->mat_nr + 1); | |||||
| copy_v4_v4(gps_dst->runtime.tmp_stroke_rgba, gp_style->stroke_rgba); | |||||
| copy_v4_v4(gps_dst->runtime.tmp_fill_rgba, gp_style->fill_rgba); | |||||
| /* Save original pointers for using in edit and select operators. */ | |||||
| gps_dst->runtime.gps_orig = gps_src; | |||||
| for (int i = 0; i < gps_src->totpoints; i++) { | |||||
| bGPDspoint *pt_dst = &gps_dst->points[i]; | |||||
| pt_dst->runtime.pt_orig = &gps_src->points[i]; | |||||
| pt_dst->runtime.idx_orig = i; | |||||
| } | |||||
| BLI_addtail(&eval_gpf->strokes, gps_dst); | |||||
| } | |||||
| } | |||||
| /* Ensure there is a evaluated frame */ | |||||
| static void gpencil_evaluated_frame_ensure( | |||||
Done Inline Actions@brech maybe gpencil_derived_frame_ensure is better naming? antoniov: @brech maybe `gpencil_derived_frame_ensure` is better naming? | |||||
| int idx, Object *ob, bGPDlayer *gpl, bGPDframe *gpf, bGPDframe **eval_gpf) | |||||
| { | |||||
| /* create evaluated frames array data or expand */ | |||||
| bGPDframe *evaluated_frames = ob->runtime.gpencil_evaluated_frames; | |||||
| *eval_gpf = &evaluated_frames[idx]; | |||||
| /* If already exist a evaluated frame create a new one. */ | |||||
| if (*eval_gpf != NULL) { | |||||
| /* first clear temp data */ | |||||
| BKE_gpencil_free_frame_runtime_data(*eval_gpf); | |||||
| } | |||||
| /* copy data (do not assign new memory)*/ | |||||
| gpencil_frame_copy_noalloc(ob, gpf, *eval_gpf); | |||||
| } | |||||
| /* Calculate gpencil modifiers */ | |||||
| void BKE_gpencil_modifiers_calc(Depsgraph *depsgraph, Scene *scene, Object *ob) | |||||
| { | |||||
| /* use original data to set reference pointers to original data */ | |||||
| Object *ob_orig = DEG_get_original_object(ob); | |||||
| bGPdata *gpd = (bGPdata *)ob_orig->data; | |||||
| const bool is_multiedit = (bool)GPENCIL_MULTIEDIT_SESSIONS_ON(gpd); | |||||
| const bool simplify_modif = GPENCIL_SIMPLIFY_MODIF(scene, false); | |||||
| const bool is_render = (bool)(DEG_get_mode(depsgraph) == DAG_EVAL_RENDER); | |||||
| const bool time_remap = BKE_gpencil_has_time_modifiers(ob); | |||||
| int cfra_eval = (int)DEG_get_ctime(depsgraph); | |||||
| /* Create array of evaluated frames equal to number of layers. */ | |||||
| ob->runtime.gpencil_tot_layers = BLI_listbase_count(&gpd->layers); | |||||
| CLAMP_MIN(ob->runtime.gpencil_tot_layers, 1); | |||||
| if (ob->runtime.gpencil_evaluated_frames == NULL) { | |||||
| ob->runtime.gpencil_evaluated_frames = MEM_callocN( | |||||
| sizeof(struct bGPDframe) * ob->runtime.gpencil_tot_layers, __func__); | |||||
| } | |||||
| else { | |||||
| ob->runtime.gpencil_evaluated_frames = MEM_recallocN(ob->runtime.gpencil_evaluated_frames, | |||||
| sizeof(struct bGPDframe) * | |||||
| ob->runtime.gpencil_tot_layers); | |||||
| } | |||||
| /* Init general modifiers data. */ | |||||
| if (ob->greasepencil_modifiers.first) { | |||||
| BKE_gpencil_lattice_init(ob); | |||||
| } | |||||
| /* ***************************************************************** | |||||
| * Loop all layers, duplicate data and apply modifiers. | |||||
| * | |||||
| * ******************************************************************/ | |||||
| int idx = 0; | |||||
| for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) { | |||||
| /* Remap frame (Time modifier) */ | |||||
| int remap_cfra = cfra_eval; | |||||
| if ((time_remap) && (!simplify_modif)) { | |||||
| remap_cfra = BKE_gpencil_time_modifier(depsgraph, scene, ob, gpl, cfra_eval, is_render); | |||||
| } | |||||
| bGPDframe *gpf = BKE_gpencil_layer_getframe(gpl, remap_cfra, GP_GETFRAME_USE_PREV); | |||||
| if (gpf == NULL) { | |||||
| idx++; | |||||
| continue; | |||||
| } | |||||
| /* Create a duplicate data set of stroke to modify. */ | |||||
| bGPDframe *eval_gpf = NULL; | |||||
| gpencil_evaluated_frame_ensure(idx, ob, gpl, gpf, &eval_gpf); | |||||
| /* Skip all if some disable flag is enabled. */ | |||||
| if ((ob->greasepencil_modifiers.first == NULL) || (is_multiedit) || (simplify_modif)) { | |||||
| idx++; | |||||
| continue; | |||||
| } | |||||
| /* Apply geometry modifiers (create new geometry). */ | |||||
| if (BKE_gpencil_has_geometry_modifiers(ob)) { | |||||
| BKE_gpencil_geometry_modifiers(depsgraph, ob, gpl, eval_gpf, is_render); | |||||
| } | |||||
| /* Loop all strokes and deform them. */ | |||||
| for (bGPDstroke *gps = eval_gpf->strokes.first; gps; gps = gps->next) { | |||||
| /* Apply modifiers that only deform geometry */ | |||||
| BKE_gpencil_stroke_modifiers(depsgraph, ob, gpl, eval_gpf, gps, is_render); | |||||
| } | |||||
| idx++; | |||||
| } | |||||
| /* Clear any lattice data. */ | |||||
| if (ob->greasepencil_modifiers.first) { | |||||
| BKE_gpencil_lattice_clear(ob); | |||||
| } | |||||
| } | |||||
maybe better naming is gpencil_frame_copy