Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/gpencil/gpencil_paint.c
| Show First 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | |||||
| #include "BKE_brush.h" | #include "BKE_brush.h" | ||||
| #include "BKE_colortools.h" | #include "BKE_colortools.h" | ||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_deform.h" | #include "BKE_deform.h" | ||||
| #include "BKE_global.h" | #include "BKE_global.h" | ||||
| #include "BKE_gpencil.h" | #include "BKE_gpencil.h" | ||||
| #include "BKE_gpencil_curve.h" | #include "BKE_gpencil_curve.h" | ||||
| #include "BKE_gpencil_geom.h" | #include "BKE_gpencil_geom.h" | ||||
| #include "BKE_gpencil_update_cache.h" | |||||
| #include "BKE_layer.h" | #include "BKE_layer.h" | ||||
| #include "BKE_main.h" | #include "BKE_main.h" | ||||
| #include "BKE_material.h" | #include "BKE_material.h" | ||||
| #include "BKE_paint.h" | #include "BKE_paint.h" | ||||
| #include "BKE_report.h" | #include "BKE_report.h" | ||||
| #include "BKE_screen.h" | #include "BKE_screen.h" | ||||
| #include "BKE_tracking.h" | #include "BKE_tracking.h" | ||||
| ▲ Show 20 Lines • Show All 1,269 Lines • ▼ Show 20 Lines | static void gpencil_stroke_newfrombuffer(tGPsdata *p) | ||||
| /* In Multiframe mode, duplicate the stroke in other frames. */ | /* In Multiframe mode, duplicate the stroke in other frames. */ | ||||
| if (GPENCIL_MULTIEDIT_SESSIONS_ON(p->gpd)) { | if (GPENCIL_MULTIEDIT_SESSIONS_ON(p->gpd)) { | ||||
| const bool tail = (ts->gpencil_flags & GP_TOOL_FLAG_PAINT_ONBACK); | const bool tail = (ts->gpencil_flags & GP_TOOL_FLAG_PAINT_ONBACK); | ||||
| BKE_gpencil_stroke_copy_to_keyframes(gpd, gpl, p->gpf, gps, tail); | BKE_gpencil_stroke_copy_to_keyframes(gpd, gpl, p->gpf, gps, tail); | ||||
| } | } | ||||
| gpencil_update_cache(p->gpd); | gpencil_update_cache(p->gpd); | ||||
| BKE_gpencil_tag_full_update(p->gpd, gpl, p->gpf, NULL); | |||||
| } | } | ||||
| /* --- 'Eraser' for 'Paint' Tool ------ */ | /* --- 'Eraser' for 'Paint' Tool ------ */ | ||||
| /* only erase stroke points that are visible */ | /* only erase stroke points that are visible */ | ||||
| static bool gpencil_stroke_eraser_is_occluded( | static bool gpencil_stroke_eraser_is_occluded( | ||||
| tGPsdata *p, bGPDlayer *gpl, bGPDspoint *pt, const int x, const int y) | tGPsdata *p, bGPDlayer *gpl, bGPDspoint *pt, const int x, const int y) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 751 Lines • ▼ Show 20 Lines | if (gpd->runtime.sbuffer) { | ||||
| MEM_SAFE_FREE(gpd->runtime.sbuffer); | MEM_SAFE_FREE(gpd->runtime.sbuffer); | ||||
| gpd->runtime.sbuffer = NULL; | gpd->runtime.sbuffer = NULL; | ||||
| } | } | ||||
| /* clear flags */ | /* clear flags */ | ||||
| gpd->runtime.sbuffer_used = 0; | gpd->runtime.sbuffer_used = 0; | ||||
| gpd->runtime.sbuffer_size = 0; | gpd->runtime.sbuffer_size = 0; | ||||
| gpd->runtime.sbuffer_sflag = 0; | gpd->runtime.sbuffer_sflag = 0; | ||||
| /* This update is required for update-on-write because the sbuffer data is not longer overwritten | |||||
| * by a copy-on-write. */ | |||||
| ED_gpencil_sbuffer_update_eval(gpd, p->ob_eval); | |||||
| p->inittime = 0.0; | p->inittime = 0.0; | ||||
| } | } | ||||
| static void gpencil_session_free(tGPsdata *p) | static void gpencil_session_free(tGPsdata *p) | ||||
| { | { | ||||
| if (p->rng != NULL) { | if (p->rng != NULL) { | ||||
| BLI_rng_free(p->rng); | BLI_rng_free(p->rng); | ||||
| } | } | ||||
| Show All 12 Lines | static void gpencil_paint_initstroke(tGPsdata *p, | ||||
| Scene *scene = p->scene; | Scene *scene = p->scene; | ||||
| ToolSettings *ts = scene->toolsettings; | ToolSettings *ts = scene->toolsettings; | ||||
| bool changed = false; | bool changed = false; | ||||
| /* get active layer (or add a new one if non-existent) */ | /* get active layer (or add a new one if non-existent) */ | ||||
| p->gpl = BKE_gpencil_layer_active_get(p->gpd); | p->gpl = BKE_gpencil_layer_active_get(p->gpd); | ||||
| if (p->gpl == NULL) { | if (p->gpl == NULL) { | ||||
| p->gpl = BKE_gpencil_layer_addnew(p->gpd, DATA_("GP_Layer"), true, false); | p->gpl = BKE_gpencil_layer_addnew(p->gpd, DATA_("GP_Layer"), true, false); | ||||
| BKE_gpencil_tag_full_update(p->gpd, NULL, NULL, NULL); | |||||
| changed = true; | changed = true; | ||||
| if (p->custom_color[3]) { | if (p->custom_color[3]) { | ||||
| copy_v3_v3(p->gpl->color, p->custom_color); | copy_v3_v3(p->gpl->color, p->custom_color); | ||||
| } | } | ||||
| } | } | ||||
| /* Recalculate layer transform matrix to avoid problems if props are animated. */ | /* Recalculate layer transform matrix to avoid problems if props are animated. */ | ||||
| loc_eul_size_to_mat4(p->gpl->layer_mat, p->gpl->location, p->gpl->rotation, p->gpl->scale); | loc_eul_size_to_mat4(p->gpl->layer_mat, p->gpl->location, p->gpl->rotation, p->gpl->scale); | ||||
| ▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | if (IS_AUTOKEY_ON(scene)) { | ||||
| add_frame_mode = GP_GETFRAME_ADD_NEW; | add_frame_mode = GP_GETFRAME_ADD_NEW; | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| add_frame_mode = GP_GETFRAME_USE_PREV; | add_frame_mode = GP_GETFRAME_USE_PREV; | ||||
| } | } | ||||
| bool need_tag = p->gpl->actframe == NULL; | bool need_tag = p->gpl->actframe == NULL; | ||||
| bGPDframe *actframe = p->gpl->actframe; | |||||
| p->gpf = BKE_gpencil_layer_frame_get(p->gpl, CFRA, add_frame_mode); | p->gpf = BKE_gpencil_layer_frame_get(p->gpl, CFRA, add_frame_mode); | ||||
| /* Only if there wasn't an active frame, need update. */ | /* Only if there wasn't an active frame, need update. */ | ||||
| if (need_tag) { | if (need_tag) { | ||||
| DEG_id_tag_update(&p->gpd->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY); | DEG_id_tag_update(&p->gpd->id, ID_RECALC_GEOMETRY); | ||||
| } | |||||
| if (actframe != p->gpl->actframe) { | |||||
| BKE_gpencil_tag_full_update(p->gpd, p->gpl, NULL, NULL); | |||||
| } | } | ||||
| if (p->gpf == NULL) { | if (p->gpf == NULL) { | ||||
| p->status = GP_STATUS_ERROR; | p->status = GP_STATUS_ERROR; | ||||
| if (!IS_AUTOKEY_ON(scene)) { | if (!IS_AUTOKEY_ON(scene)) { | ||||
| BKE_report(p->reports, RPT_INFO, "No available frame for creating stroke"); | BKE_report(p->reports, RPT_INFO, "No available frame for creating stroke"); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 1,756 Lines • Show Last 20 Lines | |||||