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 #pragma once
20 
21 /** \file
22  * \ingroup DNA
23  *
24  * This file defines structures for Shape-Keys (not animation keyframes),
25  * attached to Mesh, Curve and Lattice Data. Even though Key's are ID blocks they
26  * aren't intended to be shared between multiple data blocks as with other ID types.
27  */
28 
29 #include "DNA_ID.h"
30 #include "DNA_defs.h"
31 #include "DNA_listBase.h"
32 
33 struct AnimData;
34 struct Ipo;
35 
36 typedef struct KeyBlock {
37   struct KeyBlock *next, *prev;
38 
39   /**
40    * point in time   (Key->type == KEY_NORMAL) only,
41    * for historic reasons this is relative to (Key->ctime / 100),
42    * so this value increments by 0.1f per frame.
43    */
44   float pos;
45   /** influence (typically [0 - 1] but can be more), (Key->type == KEY_RELATIVE) only.*/
46   float curval;
47 
48   /** interpolation type (Key->type == KEY_NORMAL) only. */
49   short type;
50   char _pad1[2];
51 
52   /** relative == 0 means first key is reference, otherwise the index of Key->blocks */
53   short relative;
54   short flag;
55 
56   /** total number if items in the keyblock (compare with mesh/curve verts to check we match) */
57   int totelem;
58   /** for meshes only, match the unique number with the customdata layer */
59   int uid;
60 
61   /** array of shape key values, size is (Key->elemsize * KeyBlock->totelem) */
62   void *data;
63   /** MAX_NAME (unique name, user assigned) */
64   char name[64];
65   /** MAX_VGROUP_NAME (optional vertex group), array gets allocated into 'weights' when set */
66   char vgroup[64];
67 
68   /** ranges, for RNA and UI only to clamp 'curval' */
69   float slidermin;
70   float slidermax;
71 
72 } KeyBlock;
73 
74 typedef struct Key {
75   ID id;
76   /** Animation data (must be immediately after id for utilities to use it). */
77   struct AnimData *adt;
78 
79   /**
80    * commonly called 'Basis', (Key->type == KEY_RELATIVE) only.
81    * Looks like this is  _always_ 'key->block.first',
82    * perhaps later on it could be defined as some other KeyBlock - campbell
83    */
84   KeyBlock *refkey;
85 
86   /**
87    * This is not a regular string, although it is \0 terminated
88    * this is an array of (element_array_size, element_type) pairs
89    * (each one char) used for calculating shape key-blocks. */
90   char elemstr[32];
91   /** Size of each element in #KeyBlock.data, use for allocation and stride. */
92   int elemsize;
93   char _pad[4];
94 
95   /** list of KeyBlock's */
96   ListBase block;
97   /** old animation system, deprecated for 2.5 */
98   struct Ipo *ipo DNA_DEPRECATED;
99 
100   ID *from;
101 
102   /** (totkey == BLI_listbase_count(&key->block)) */
103   int totkey;
104   short flag;
105   /** absolute or relative shape key */
106   char type;
107   char _pad2;
108 
109   /** Only used when (Key->type == KEY_NORMAL), this value is used as a time slider,
110    * rather than using the scene's time, this value can be animated to give greater control */
111   float ctime;
112 
113   /**
114    * Can never be 0, this is used for detecting old data.
115    * current free UID for key-blocks.
116    */
117   int uidgen;
118 } Key;
119 
120 /* **************** KEY ********************* */
121 
122 /* Key->type: KeyBlocks are interpreted as... */
123 enum {
124   /* Sequential positions over time (using KeyBlock->pos and Key->ctime) */
125   KEY_NORMAL = 0,
126 
127   /* States to blend between (default) */
128   KEY_RELATIVE = 1,
129 };
130 
131 /* Key->flag */
132 enum {
133   KEY_DS_EXPAND = 1,
134 };
135 
136 /* KeyBlock->type */
137 enum {
138   KEY_LINEAR = 0,
139   KEY_CARDINAL = 1,
140   KEY_BSPLINE = 2,
141   KEY_CATMULL_ROM = 3,
142 };
143 
144 /* KeyBlock->flag */
145 enum {
146   KEYBLOCK_MUTE = (1 << 0),
147   KEYBLOCK_SEL = (1 << 1),
148   KEYBLOCK_LOCKED = (1 << 2),
149 };
150 
151 #define KEYELEM_FLOAT_LEN_COORD 3
152 
153 /* Curve key data layout constants */
154 #define KEYELEM_ELEM_SIZE_CURVE 3
155 
156 #define KEYELEM_ELEM_LEN_BPOINT 2
157 #define KEYELEM_FLOAT_LEN_BPOINT (KEYELEM_ELEM_LEN_BPOINT * KEYELEM_ELEM_SIZE_CURVE)
158 
159 #define KEYELEM_ELEM_LEN_BEZTRIPLE 4
160 #define KEYELEM_FLOAT_LEN_BEZTRIPLE (KEYELEM_ELEM_LEN_BEZTRIPLE * KEYELEM_ELEM_SIZE_CURVE)
161