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) 2001-2002 by NaN Holding BV. 17 * All rights reserved. 18 */ 19 20 /** \file 21 * \ingroup DNA 22 */ 23 24 #pragma once 25 26 #include "DNA_ID.h" 27 #include "DNA_defs.h" 28 #include "DNA_listBase.h" 29 #include "DNA_vec_types.h" 30 31 #define MAXTEXTBOX 256 /* used in readfile.c and editfont.c */ 32 33 struct AnimData; 34 struct CurveProfile; 35 struct EditFont; 36 struct GHash; 37 struct Ipo; 38 struct Key; 39 struct Material; 40 struct Object; 41 struct VFont; 42 43 /* These two Lines with # tell makesdna this struct can be excluded. */ 44 # 45 # 46 typedef struct PathPoint { 47 /** Grr, cant get rid of tilt yet. */ 48 float vec[4]; 49 float quat[4]; 50 float radius, weight; 51 } PathPoint; 52 53 /* These two Lines with # tell makesdna this struct can be excluded. */ 54 # 55 # 56 typedef struct Path { 57 struct PathPoint *data; 58 int len; 59 float totdist; 60 } Path; 61 62 /* These two Lines with # tell makesdna this struct can be excluded. */ 63 # 64 # 65 typedef struct BevPoint { 66 float vec[3], tilt, radius, weight, offset; 67 /** 2D Only. */ 68 float sina, cosa; 69 /** 3D Only. */ 70 float dir[3], tan[3], quat[4]; 71 short split_tag, dupe_tag; 72 } BevPoint; 73 74 /* These two Lines with # tell makesdna this struct can be excluded. */ 75 # 76 # 77 typedef struct BevList { 78 struct BevList *next, *prev; 79 int nr, dupe_nr; 80 int poly, hole; 81 int charidx; 82 int *segbevcount; 83 float *seglen; 84 BevPoint *bevpoints; 85 } BevList; 86 87 /** 88 * Keyframes on F-Curves (allows code reuse of Bezier eval code) and 89 * Points on Bezier Curves/Paths are generally BezTriples. 90 * 91 * \note #BezTriple.tilt location in struct is abused by Key system. 92 * 93 * \note vec in BezTriple looks like this: 94 * - vec[0][0] = x location of handle 1 95 * - vec[0][1] = y location of handle 1 96 * - vec[0][2] = z location of handle 1 (not used for FCurve Points(2d)) 97 * - vec[1][0] = x location of control point 98 * - vec[1][1] = y location of control point 99 * - vec[1][2] = z location of control point 100 * - vec[2][0] = x location of handle 2 101 * - vec[2][1] = y location of handle 2 102 * - vec[2][2] = z location of handle 2 (not used for FCurve Points(2d)) 103 */ 104 typedef struct BezTriple { 105 float vec[3][3]; 106 /** Tilt in 3D View. */ 107 float tilt; 108 /** Used for softbody goal weight. */ 109 float weight; 110 /** For bevel tapering & modifiers. */ 111 float radius; 112 113 /** Ipo: interpolation mode for segment from this BezTriple to the next. */ 114 char ipo; 115 116 /** H1, h2: the handle type of the two handles. */ 117 uint8_t h1, h2; 118 /** F1, f2, f3: used for selection status. */ 119 uint8_t f1, f2, f3; 120 121 /** Hide: used to indicate whether BezTriple is hidden (3D), 122 * type of keyframe (eBezTriple_KeyframeType). */ 123 char hide; 124 125 /** Easing: easing type for interpolation mode (eBezTriple_Easing). */ 126 char easing; 127 /** BEZT_IPO_BACK. */ 128 float back; 129 /** BEZT_IPO_ELASTIC. */ 130 float amplitude, period; 131 132 /** F5: used for auto handle to distinguish between normal handle and exception (extrema). */ 133 char f5; 134 char _pad[3]; 135 } BezTriple; 136 137 /** 138 * \note #BPoint.tilt location in struct is abused by Key system. 139 */ 140 typedef struct BPoint { 141 float vec[4]; 142 /** Tilt in 3D View. */ 143 float tilt; 144 /** Used for softbody goal weight. */ 145 float weight; 146 /** F1: selection status, hide: is point hidden or not. */ 147 uint8_t f1; 148 char _pad1[1]; 149 short hide; 150 /** User-set radius per point for beveling etc. */ 151 float radius; 152 char _pad[4]; 153 } BPoint; 154 155 /** 156 * \note Nurb name is misleading, since it can be used for polygons too, 157 * also, it should be NURBS (Nurb isn't the singular of Nurbs). 158 */ 159 typedef struct Nurb { 160 /** Multiple nurbs per curve object are allowed. */ 161 struct Nurb *next, *prev; 162 short type; 163 /** Index into material list. */ 164 short mat_nr; 165 short hide, flag; 166 /** Number of points in the U or V directions. */ 167 int pntsu, pntsv; 168 char _pad[4]; 169 /** Tessellation resolution in the U or V directions. */ 170 short resolu, resolv; 171 short orderu, orderv; 172 short flagu, flagv; 173 174 float *knotsu, *knotsv; 175 BPoint *bp; 176 BezTriple *bezt; 177 178 /** KEY_LINEAR, KEY_CARDINAL, KEY_BSPLINE. */ 179 short tilt_interp; 180 short radius_interp; 181 182 /* only used for dynamically generated Nurbs created from OB_FONT's */ 183 int charidx; 184 } Nurb; 185 186 typedef struct CharInfo { 187 short kern; 188 /** Index start at 1, unlike mesh & nurbs. */ 189 short mat_nr; 190 char flag; 191 char _pad[3]; 192 } CharInfo; 193 194 typedef struct TextBox { 195 float x, y, w, h; 196 } TextBox; 197 198 /* These two Lines with # tell makesdna this struct can be excluded. */ 199 # 200 # 201 typedef struct EditNurb { 202 /* base of nurbs' list (old Curve->editnurb) */ 203 ListBase nurbs; 204 205 /* index data for shape keys */ 206 struct GHash *keyindex; 207 208 /* shape key being edited */ 209 int shapenr; 210 211 /** 212 * ID data is older than edit-mode data. 213 * Set #Main.is_memfile_undo_flush_needed when enabling. 214 */ 215 char needs_flush_to_id; 216 217 } EditNurb; 218 219 typedef struct Curve { 220 ID id; 221 /** Animation data (must be immediately after id for utilities to use it). */ 222 struct AnimData *adt; 223 224 /** Actual data, called splines in rna. */ 225 ListBase nurb; 226 227 /** Edited data, not in file, use pointer so we can check for it. */ 228 EditNurb *editnurb; 229 230 struct Object *bevobj, *taperobj, *textoncurve; 231 /** Old animation system, deprecated for 2.5. */ 232 struct Ipo *ipo DNA_DEPRECATED; 233 struct Key *key; 234 struct Material **mat; 235 236 struct CurveProfile *bevel_profile; 237 238 /* texture space, copied as one block in editobject.c */ 239 float loc[3]; 240 float size[3]; 241 242 /** Creation-time type of curve datablock. */ 243 short type; 244 245 /** Keep a short because of BKE_object_obdata_texspace_get(). */ 246 short texflag; 247 char _pad0[6]; 248 short twist_mode; 249 float twist_smooth, smallcaps_scale; 250 251 int pathlen; 252 short bevresol, totcol; 253 int flag; 254 float width, ext1, ext2; 255 256 /* default */ 257 short resolu, resolv; 258 short resolu_ren, resolv_ren; 259 260 /* edit, index in nurb list */ 261 int actnu; 262 /* edit, index in active nurb (BPoint or BezTriple) */ 263 int actvert; 264 265 char overflow; 266 char spacemode, align_y; 267 char bevel_mode; 268 char _pad[2]; 269 270 /* font part */ 271 short lines; 272 float spacing, linedist, shear, fsize, wordspace, ulpos, ulheight; 273 float xof, yof; 274 float linewidth; 275 276 /* copy of EditFont vars (wchar_t aligned), 277 * warning! don't use in editmode (storage only) */ 278 int pos; 279 int selstart, selend; 280 281 /* text data */ 282 /** 283 * Number of characters (unicode code-points) 284 * This is the length of #Curve.strinfo and the result of `BLI_strlen_utf8(cu->str)`. 285 */ 286 int len_char32; 287 /** Number of bytes: `strlen(Curve.str)`. */ 288 int len; 289 char *str; 290 struct EditFont *editfont; 291 292 char family[64]; 293 struct VFont *vfont; 294 struct VFont *vfontb; 295 struct VFont *vfonti; 296 struct VFont *vfontbi; 297 298 struct TextBox *tb; 299 int totbox, actbox; 300 301 struct CharInfo *strinfo; 302 struct CharInfo curinfo; 303 /* font part end */ 304 305 /** Current evaltime - for use by Objects parented to curves. */ 306 float ctime; 307 float bevfac1, bevfac2; 308 char bevfac1_mapping, bevfac2_mapping; 309 310 char _pad2[6]; 311 float fsize_realtime; 312 313 void *batch_cache; 314 } Curve; 315 316 #define CURVE_VFONT_ANY(cu) ((cu)->vfont), ((cu)->vfontb), ((cu)->vfonti), ((cu)->vfontbi) 317 318 /* **************** CURVE ********************* */ 319 320 /* Curve.texflag */ 321 enum { 322 CU_AUTOSPACE = 1, 323 CU_AUTOSPACE_EVALUATED = 2, 324 }; 325 326 #if 0 /* Moved to overlay options in 2.8 */ 327 /* Curve.drawflag */ 328 enum { 329 CU_HIDE_HANDLES = 1 << 0, 330 CU_HIDE_NORMALS = 1 << 1, 331 }; 332 #endif 333 334 /* Curve.flag */ 335 enum { 336 CU_3D = 1 << 0, 337 CU_FRONT = 1 << 1, 338 CU_BACK = 1 << 2, 339 CU_PATH = 1 << 3, 340 CU_FOLLOW = 1 << 4, 341 /* CU_UV_ORCO = 1 << 5, */ /* DEPRECATED */ 342 CU_DEFORM_BOUNDS_OFF = 1 << 6, 343 CU_STRETCH = 1 << 7, 344 /* CU_OFFS_PATHDIST = 1 << 8, */ /* DEPRECATED */ 345 CU_FAST = 1 << 9, /* Font: no filling inside editmode */ 346 /* CU_RETOPO = 1 << 10, */ /* DEPRECATED */ 347 CU_DS_EXPAND = 1 << 11, 348 /** make use of the path radius if this is enabled (default for new curves) */ 349 CU_PATH_RADIUS = 1 << 12, 350 /** fill 2d curve after deformation */ 351 CU_DEFORM_FILL = 1 << 13, 352 /** fill bevel caps */ 353 CU_FILL_CAPS = 1 << 14, 354 /** map taper object to beveled area */ 355 CU_MAP_TAPER = 1 << 15, 356 }; 357 358 /* Curve.twist_mode */ 359 enum { 360 CU_TWIST_Z_UP = 0, 361 /* CU_TWIST_Y_UP = 1, */ /* not used yet */ 362 /* CU_TWIST_X_UP = 2, */ 363 CU_TWIST_MINIMUM = 3, 364 CU_TWIST_TANGENT = 4, 365 }; 366 367 /* Curve.bevfac1_mapping, Curve.bevfac2_mapping, bevel factor mapping */ 368 enum { 369 CU_BEVFAC_MAP_RESOLU = 0, 370 CU_BEVFAC_MAP_SEGMENT = 1, 371 CU_BEVFAC_MAP_SPLINE = 2, 372 }; 373 374 /* Curve.spacemode */ 375 enum { 376 CU_ALIGN_X_LEFT = 0, 377 CU_ALIGN_X_MIDDLE = 1, 378 CU_ALIGN_X_RIGHT = 2, 379 CU_ALIGN_X_JUSTIFY = 3, 380 CU_ALIGN_X_FLUSH = 4, 381 }; 382 383 /* Curve.align_y */ 384 enum { 385 CU_ALIGN_Y_TOP_BASELINE = 0, 386 CU_ALIGN_Y_TOP = 1, 387 CU_ALIGN_Y_CENTER = 2, 388 CU_ALIGN_Y_BOTTOM_BASELINE = 3, 389 CU_ALIGN_Y_BOTTOM = 4, 390 }; 391 392 /* Curve.bevel_mode */ 393 enum { 394 CU_BEV_MODE_ROUND = 0, 395 CU_BEV_MODE_OBJECT = 1, 396 CU_BEV_MODE_CURVE_PROFILE = 2, 397 }; 398 399 /* Curve.overflow. */ 400 enum { 401 CU_OVERFLOW_NONE = 0, 402 CU_OVERFLOW_SCALE = 1, 403 CU_OVERFLOW_TRUNCATE = 2, 404 }; 405 406 /* Nurb.flag */ 407 enum { 408 CU_SMOOTH = 1 << 0, 409 CU_2D = 1 << 3, /* moved from type since 2.4x */ 410 }; 411 412 /* Nurb.type */ 413 enum { 414 CU_POLY = 0, 415 CU_BEZIER = 1, 416 CU_BSPLINE = 2, 417 CU_CARDINAL = 3, 418 CU_NURBS = 4, 419 CU_TYPE = (CU_POLY | CU_BEZIER | CU_BSPLINE | CU_CARDINAL | CU_NURBS), 420 421 /* only for adding */ 422 CU_PRIMITIVE = 0xF00, 423 424 /* 2 or 4 points */ 425 CU_PRIM_CURVE = 0x100, 426 /* 8 points circle */ 427 CU_PRIM_CIRCLE = 0x200, 428 /* 4x4 patch Nurb */ 429 CU_PRIM_PATCH = 0x300, 430 CU_PRIM_TUBE = 0x400, 431 CU_PRIM_SPHERE = 0x500, 432 CU_PRIM_DONUT = 0x600, 433 /* 5 points, 5th order straight line (for anim path) */ 434 CU_PRIM_PATH = 0x700, 435 }; 436 437 /* Nurb.flagu, Nurb.flagv */ 438 enum { 439 CU_NURB_CYCLIC = 1 << 0, 440 CU_NURB_ENDPOINT = 1 << 1, 441 CU_NURB_BEZIER = 1 << 2, 442 }; 443 444 #define CU_ACT_NONE -1 445 446 /* *************** BEZTRIPLE **************** */ 447 448 /* BezTriple.f1,2,3 */ 449 typedef enum eBezTriple_Flag { 450 /* SELECT */ 451 BEZT_FLAG_TEMP_TAG = (1 << 1), /* always clear. */ 452 } eBezTriple_Flag; 453 454 /* h1 h2 (beztriple) */ 455 typedef enum eBezTriple_Handle { 456 HD_FREE = 0, 457 HD_AUTO = 1, 458 HD_VECT = 2, 459 HD_ALIGN = 3, 460 HD_AUTO_ANIM = 4, /* auto-clamped handles for animation */ 461 HD_ALIGN_DOUBLESIDE = 5, /* align handles, displayed both of them. used for masks */ 462 } eBezTriple_Handle; 463 464 /* f5 (beztriple) */ 465 typedef enum eBezTriple_Auto_Type { 466 HD_AUTOTYPE_NORMAL = 0, 467 HD_AUTOTYPE_SPECIAL = 1, 468 } eBezTriple_Auto_Type; 469 470 /* interpolation modes (used only for BezTriple->ipo) */ 471 typedef enum eBezTriple_Interpolation { 472 /* traditional interpolation */ 473 BEZT_IPO_CONST = 0, /* constant interpolation */ 474 BEZT_IPO_LIN = 1, /* linear interpolation */ 475 BEZT_IPO_BEZ = 2, /* bezier interpolation */ 476 477 /* easing equations */ 478 BEZT_IPO_BACK = 3, 479 BEZT_IPO_BOUNCE = 4, 480 BEZT_IPO_CIRC = 5, 481 BEZT_IPO_CUBIC = 6, 482 BEZT_IPO_ELASTIC = 7, 483 BEZT_IPO_EXPO = 8, 484 BEZT_IPO_QUAD = 9, 485 BEZT_IPO_QUART = 10, 486 BEZT_IPO_QUINT = 11, 487 BEZT_IPO_SINE = 12, 488 } eBezTriple_Interpolation; 489 490 /* easing modes (used only for Keyframes - BezTriple->easing) */ 491 typedef enum eBezTriple_Easing { 492 BEZT_IPO_EASE_AUTO = 0, 493 494 BEZT_IPO_EASE_IN = 1, 495 BEZT_IPO_EASE_OUT = 2, 496 BEZT_IPO_EASE_IN_OUT = 3, 497 } eBezTriple_Easing; 498 499 /* types of keyframe (used only for BezTriple->hide when BezTriple is used in F-Curves) */ 500 typedef enum eBezTriple_KeyframeType { 501 BEZT_KEYTYPE_KEYFRAME = 0, /* default - 'proper' Keyframe */ 502 BEZT_KEYTYPE_EXTREME = 1, /* 'extreme' keyframe */ 503 BEZT_KEYTYPE_BREAKDOWN = 2, /* 'breakdown' keyframe */ 504 BEZT_KEYTYPE_JITTER = 3, /* 'jitter' keyframe (for adding 'filler' secondary motion) */ 505 BEZT_KEYTYPE_MOVEHOLD = 4, /* one end of a 'moving hold' */ 506 } eBezTriple_KeyframeType; 507 508 /* checks if the given BezTriple is selected */ 509 #define BEZT_ISSEL_ANY(bezt) \ 510 (((bezt)->f2 & SELECT) || ((bezt)->f1 & SELECT) || ((bezt)->f3 & SELECT)) 511 #define BEZT_ISSEL_ALL(bezt) \ 512 (((bezt)->f2 & SELECT) && ((bezt)->f1 & SELECT) && ((bezt)->f3 & SELECT)) 513 #define BEZT_ISSEL_ALL_HIDDENHANDLES(v3d, bezt) \ 514 ((((v3d) != NULL) && ((v3d)->overlay.handle_display == CURVE_HANDLE_NONE)) ? \ 515 (bezt)->f2 & SELECT : \ 516 BEZT_ISSEL_ALL(bezt)) 517 #define BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, bezt) \ 518 ((((v3d) != NULL) && ((v3d)->overlay.handle_display == CURVE_HANDLE_NONE)) ? \ 519 (bezt)->f2 & SELECT : \ 520 BEZT_ISSEL_ANY(bezt)) 521 522 #define BEZT_SEL_ALL(bezt) \ 523 { \ 524 (bezt)->f1 |= SELECT; \ 525 (bezt)->f2 |= SELECT; \ 526 (bezt)->f3 |= SELECT; \ 527 } \ 528 ((void)0) 529 #define BEZT_DESEL_ALL(bezt) \ 530 { \ 531 (bezt)->f1 &= ~SELECT; \ 532 (bezt)->f2 &= ~SELECT; \ 533 (bezt)->f3 &= ~SELECT; \ 534 } \ 535 ((void)0) 536 537 #define BEZT_IS_AUTOH(bezt) \ 538 (ELEM((bezt)->h1, HD_AUTO, HD_AUTO_ANIM) && ELEM((bezt)->h2, HD_AUTO, HD_AUTO_ANIM)) 539 540 /* *************** CHARINFO **************** */ 541 542 /* CharInfo.flag */ 543 enum { 544 /* note: CU_CHINFO_WRAP, CU_CHINFO_SMALLCAPS_TEST and CU_CHINFO_TRUNCATE are set dynamically */ 545 CU_CHINFO_BOLD = 1 << 0, 546 CU_CHINFO_ITALIC = 1 << 1, 547 CU_CHINFO_UNDERLINE = 1 << 2, 548 /** wordwrap occurred here */ 549 CU_CHINFO_WRAP = 1 << 3, 550 CU_CHINFO_SMALLCAPS = 1 << 4, 551 /** set at runtime, checks if case switching is needed */ 552 CU_CHINFO_SMALLCAPS_CHECK = 1 << 5, 553 /** Set at runtime, indicates char that doesn't fit in text boxes. */ 554 CU_CHINFO_OVERFLOW = 1 << 6, 555 }; 556 557 /* mixed with KEY_LINEAR but define here since only curve supports */ 558 #define KEY_CU_EASE 3 559 560 /* indicates point has been seen during surface duplication */ 561 #define SURF_SEEN 4 562