1 /* 2 * This program is free software; you can redistribute it and/or 3 * modify it under the terms of the GNU General Public License 4 * as published by the Free Software Foundation; either version 2 5 * of the License, or (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * GNU General Public License for more details. 11 * 12 * You should have received a copy of the GNU General Public License 13 * along with this program; if not, write to the Free Software Foundation, 14 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 * 16 * The Original Code is Copyright (C) 2008, Blender Foundation 17 * This is a new part of Blender 18 */ 19 20 /** \file 21 * \ingroup editors 22 */ 23 24 #pragma once 25 26 #ifdef __cplusplus 27 extern "C" { 28 #endif 29 30 struct ID; 31 struct ListBase; 32 struct PointerRNA; 33 34 struct Brush; 35 struct GP_SpaceConversion; 36 struct GpRandomSettings; 37 struct bGPDframe; 38 struct bGPDlayer; 39 struct bGPDspoint; 40 struct bGPDstroke; 41 struct bGPdata; 42 struct tGPspoint; 43 44 struct ARegion; 45 struct Depsgraph; 46 struct Main; 47 struct RegionView3D; 48 struct ReportList; 49 struct Scene; 50 struct ScrArea; 51 struct SnapObjectContext; 52 struct ToolSettings; 53 struct View3D; 54 struct ViewLayer; 55 struct bContext; 56 57 struct Material; 58 struct Object; 59 60 struct KeyframeEditData; 61 struct bAnimContext; 62 63 struct wmKeyConfig; 64 struct wmOperator; 65 66 /* Reproject stroke modes. */ 67 typedef enum eGP_ReprojectModes { 68 /* Axis */ 69 GP_REPROJECT_FRONT = 0, 70 GP_REPROJECT_SIDE, 71 GP_REPROJECT_TOP, 72 /* On same plane, parallel to view-plane. */ 73 GP_REPROJECT_VIEW, 74 /* Reprojected on to the scene geometry */ 75 GP_REPROJECT_SURFACE, 76 /* Reprojected on 3D cursor orientation */ 77 GP_REPROJECT_CURSOR, 78 /* Keep equals (used in some operators) */ 79 GP_REPROJECT_KEEP, 80 } eGP_ReprojectModes; 81 82 /* ------------- Grease-Pencil Runtime Data ---------------- */ 83 84 /* Temporary 'Stroke Point' data (2D / screen-space) 85 * 86 * Used as part of the 'stroke cache' used during drawing of new strokes 87 */ 88 typedef struct tGPspoint { 89 /** Coordinates x and y of cursor (in relative to area). */ 90 float x, y; 91 /** Pressure of tablet at this point. */ 92 float pressure; 93 /** Pressure of tablet at this point for alpha factor. */ 94 float strength; 95 /** Time relative to stroke start (used when converting to path). */ 96 float time; 97 /** Factor of uv along the stroke. */ 98 float uv_fac; 99 /** UV rotation for dot mode. */ 100 float uv_rot; 101 /** Random value. */ 102 float rnd[3]; 103 /** Random flag. */ 104 bool rnd_dirty; 105 /** Point vertex color. */ 106 float vert_color[4]; 107 } tGPspoint; 108 109 /* ----------- Grease Pencil Tools/Context ------------- */ 110 111 /* Context-dependent */ 112 struct bGPdata **ED_gpencil_data_get_pointers(const struct bContext *C, struct PointerRNA *r_ptr); 113 114 struct bGPdata *ED_gpencil_data_get_active(const struct bContext *C); 115 struct bGPdata *ED_gpencil_data_get_active_evaluated(const struct bContext *C); 116 117 /* Context independent (i.e. each required part is passed in instead) */ 118 struct bGPdata **ED_gpencil_data_get_pointers_direct(struct ScrArea *area, 119 struct Object *ob, 120 struct PointerRNA *r_ptr); 121 struct bGPdata *ED_gpencil_data_get_active_direct(struct ScrArea *area, struct Object *ob); 122 123 struct bGPdata *ED_annotation_data_get_active(const struct bContext *C); 124 struct bGPdata **ED_annotation_data_get_pointers(const struct bContext *C, 125 struct PointerRNA *r_ptr); 126 struct bGPdata **ED_annotation_data_get_pointers_direct(struct ID *screen_id, 127 struct ScrArea *area, 128 struct Scene *scene, 129 struct PointerRNA *r_ptr); 130 struct bGPdata *ED_annotation_data_get_active_direct(struct ID *screen_id, 131 struct ScrArea *area, 132 struct Scene *scene); 133 134 bool ED_gpencil_data_owner_is_annotation(struct PointerRNA *owner_ptr); 135 136 /* 3D View */ 137 bool ED_gpencil_has_keyframe_v3d(struct Scene *scene, struct Object *ob, int cfra); 138 139 /* ----------- Stroke Editing Utilities ---------------- */ 140 141 bool ED_gpencil_stroke_can_use_direct(const struct ScrArea *area, const struct bGPDstroke *gps); 142 bool ED_gpencil_stroke_can_use(const struct bContext *C, const struct bGPDstroke *gps); 143 bool ED_gpencil_stroke_color_use(struct Object *ob, 144 const struct bGPDlayer *gpl, 145 const struct bGPDstroke *gps); 146 147 /* ----------- Grease Pencil Operators ----------------- */ 148 149 void ED_keymap_gpencil(struct wmKeyConfig *keyconf); 150 151 void ED_operatortypes_gpencil(void); 152 void ED_operatormacros_gpencil(void); 153 154 /* ------------- Copy-Paste Buffers -------------------- */ 155 156 /* Strokes copybuf */ 157 void ED_gpencil_strokes_copybuf_free(void); 158 159 /* ------------ Grease-Pencil Drawing API ------------------ */ 160 /* drawgpencil.c */ 161 162 void ED_annotation_draw_2dimage(const struct bContext *C); 163 void ED_annotation_draw_view2d(const struct bContext *C, bool onlyv2d); 164 void ED_annotation_draw_view3d(struct Scene *scene, 165 struct Depsgraph *depsgraph, 166 struct View3D *v3d, 167 struct ARegion *region, 168 bool only3d); 169 void ED_annotation_draw_ex(struct Scene *scene, 170 struct bGPdata *gpd, 171 int winx, 172 int winy, 173 const int cfra, 174 const char spacetype); 175 176 /* ----------- Grease-Pencil AnimEdit API ------------------ */ 177 bool ED_gpencil_layer_frames_looper(struct bGPDlayer *gpl, 178 struct Scene *scene, 179 bool (*gpf_cb)(struct bGPDframe *, struct Scene *)); 180 void ED_gpencil_layer_make_cfra_list(struct bGPDlayer *gpl, ListBase *elems, bool onlysel); 181 182 bool ED_gpencil_layer_frame_select_check(struct bGPDlayer *gpl); 183 void ED_gpencil_layer_frame_select_set(struct bGPDlayer *gpl, short mode); 184 void ED_gpencil_layer_frames_select_box(struct bGPDlayer *gpl, 185 float min, 186 float max, 187 short select_mode); 188 void ED_gpencil_layer_frames_select_region(struct KeyframeEditData *ked, 189 struct bGPDlayer *gpl, 190 short tool, 191 short select_mode); 192 void ED_gpencil_select_frames(struct bGPDlayer *gpl, short select_mode); 193 void ED_gpencil_select_frame(struct bGPDlayer *gpl, int selx, short select_mode); 194 195 bool ED_gpencil_layer_frames_delete(struct bGPDlayer *gpl); 196 void ED_gpencil_layer_frames_duplicate(struct bGPDlayer *gpl); 197 198 void ED_gpencil_layer_frames_keytype_set(struct bGPDlayer *gpl, short type); 199 200 void ED_gpencil_layer_snap_frames(struct bGPDlayer *gpl, struct Scene *scene, short mode); 201 void ED_gpencil_layer_mirror_frames(struct bGPDlayer *gpl, struct Scene *scene, short mode); 202 203 void ED_gpencil_anim_copybuf_free(void); 204 bool ED_gpencil_anim_copybuf_copy(struct bAnimContext *ac); 205 bool ED_gpencil_anim_copybuf_paste(struct bAnimContext *ac, const short copy_mode); 206 207 /* ------------ Grease-Pencil Undo System ------------------ */ 208 int ED_gpencil_session_active(void); 209 int ED_undo_gpencil_step(struct bContext *C, int step, const char *name); 210 211 /* ------------ Grease-Pencil Armature ------------------ */ 212 bool ED_gpencil_add_armature(const struct bContext *C, 213 struct ReportList *reports, 214 struct Object *ob, 215 struct Object *ob_arm); 216 bool ED_gpencil_add_armature_weights(const struct bContext *C, 217 struct ReportList *reports, 218 struct Object *ob, 219 struct Object *ob_arm, 220 int mode); 221 222 /* Add Lattice modifier using Parent operator */ 223 bool ED_gpencil_add_lattice_modifier(const struct bContext *C, 224 struct ReportList *reports, 225 struct Object *ob, 226 struct Object *ob_latt); 227 228 /* keep this aligned with gpencil_armature enum */ 229 #define GP_PAR_ARMATURE_NAME 0 230 #define GP_PAR_ARMATURE_AUTO 1 231 232 /* ------------ Transformation Utilities ------------ */ 233 234 /* reset parent matrix for all layers */ 235 void ED_gpencil_reset_layers_parent(struct Depsgraph *depsgraph, 236 struct Object *obact, 237 struct bGPdata *gpd); 238 239 /* cursor utilities */ 240 void ED_gpencil_brush_draw_eraser(struct Brush *brush, int x, int y); 241 242 /* ----------- Add Primitive Utilities -------------- */ 243 244 void ED_gpencil_create_monkey(struct bContext *C, struct Object *ob, float mat[4][4]); 245 void ED_gpencil_create_stroke(struct bContext *C, struct Object *ob, float mat[4][4]); 246 247 /* ------------ Object Utilities ------------ */ 248 struct Object *ED_gpencil_add_object(struct bContext *C, 249 const float loc[3], 250 unsigned short local_view_bits); 251 void ED_gpencil_add_defaults(struct bContext *C, struct Object *ob); 252 /* set object modes */ 253 void ED_gpencil_setup_modes(struct bContext *C, struct bGPdata *gpd, int newmode); 254 bool ED_object_gpencil_exit(struct Main *bmain, struct Object *ob); 255 256 void ED_gpencil_project_stroke_to_plane(const struct Scene *scene, 257 const struct Object *ob, 258 const struct RegionView3D *rv3d, 259 struct bGPDstroke *gps, 260 const float origin[3], 261 const int axis); 262 void ED_gpencil_project_point_to_plane(const struct Scene *scene, 263 const struct Object *ob, 264 const struct RegionView3D *rv3d, 265 const float origin[3], 266 const int axis, 267 struct bGPDspoint *pt); 268 void ED_gpencil_drawing_reference_get(const struct Scene *scene, 269 const struct Object *ob, 270 char align_flag, 271 float vec[3]); 272 void ED_gpencil_project_stroke_to_view(struct bContext *C, 273 struct bGPDlayer *gpl, 274 struct bGPDstroke *gps); 275 276 void ED_gpencil_stroke_reproject(struct Depsgraph *depsgraph, 277 const struct GP_SpaceConversion *gsc, 278 struct SnapObjectContext *sctx, 279 struct bGPDlayer *gpl, 280 struct bGPDframe *gpf, 281 struct bGPDstroke *gps, 282 const eGP_ReprojectModes mode, 283 const bool keep_original); 284 285 /* set sculpt cursor */ 286 void ED_gpencil_toggle_brush_cursor(struct bContext *C, bool enable, void *customdata); 287 288 /* vertex groups */ 289 void ED_gpencil_vgroup_assign(struct bContext *C, struct Object *ob, float weight); 290 void ED_gpencil_vgroup_remove(struct bContext *C, struct Object *ob); 291 void ED_gpencil_vgroup_select(struct bContext *C, struct Object *ob); 292 void ED_gpencil_vgroup_deselect(struct bContext *C, struct Object *ob); 293 294 /* join objects */ 295 int ED_gpencil_join_objects_exec(struct bContext *C, struct wmOperator *op); 296 297 /* texture coordinate utilities */ 298 void ED_gpencil_tpoint_to_point(struct ARegion *region, 299 float origin[3], 300 const struct tGPspoint *tpt, 301 struct bGPDspoint *pt); 302 void ED_gpencil_update_color_uv(struct Main *bmain, struct Material *mat); 303 304 /* extend selection to stroke intersections 305 * returns: 306 * 0 - No hit 307 * 1 - Hit in point A 308 * 2 - Hit in point B 309 * 3 - Hit in point A and B 310 */ 311 int ED_gpencil_select_stroke_segment(struct bGPDlayer *gpl, 312 struct bGPDstroke *gps, 313 struct bGPDspoint *pt, 314 bool select, 315 bool insert, 316 const float scale, 317 float r_hita[3], 318 float r_hitb[3]); 319 320 void ED_gpencil_select_toggle_all(struct bContext *C, int action); 321 322 /* Ensure stroke sbuffer size is enough */ 323 struct tGPspoint *ED_gpencil_sbuffer_ensure(struct tGPspoint *buffer_array, 324 int *buffer_size, 325 int *buffer_used, 326 const bool clear); 327 void ED_gpencil_sbuffer_update_eval(struct bGPdata *gpd, struct Object *ob_eval); 328 329 /* Tag all scene grease pencil object to update. */ 330 void ED_gpencil_tag_scene_gpencil(struct Scene *scene); 331 332 /* Vertex color set. */ 333 void ED_gpencil_fill_vertex_color_set(struct ToolSettings *ts, 334 struct Brush *brush, 335 struct bGPDstroke *gps); 336 void ED_gpencil_point_vertex_color_set(struct ToolSettings *ts, 337 struct Brush *brush, 338 struct bGPDspoint *pt, 339 struct tGPspoint *tpt); 340 void ED_gpencil_sbuffer_vertex_color_set(struct Depsgraph *depsgraph, 341 struct Object *ob, 342 struct ToolSettings *ts, 343 struct Brush *brush, 344 struct Material *material, 345 float random_color[3], 346 float pen_pressure); 347 void ED_gpencil_init_random_settings(struct Brush *brush, 348 const int mval[2], 349 struct GpRandomSettings *random_settings); 350 351 bool ED_gpencil_stroke_check_collision(struct GP_SpaceConversion *gsc, 352 struct bGPDstroke *gps, 353 const float mouse[2], 354 const int radius, 355 const float diff_mat[4][4]); 356 bool ED_gpencil_stroke_point_is_inside(struct bGPDstroke *gps, 357 struct GP_SpaceConversion *gsc, 358 int mouse[2], 359 const float diff_mat[4][4]); 360 361 #ifdef __cplusplus 362 } 363 #endif 364