1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
|
/**
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Contributor(s): Blender Foundation (2008).
*
* ***** END GPL LICENSE BLOCK *****
*/
#include <stdlib.h>
#include "RNA_define.h"
#include "RNA_types.h"
#include "rna_internal.h"
#include "DNA_ID.h"
#include "DNA_curve_types.h"
#include "DNA_key_types.h"
#include "DNA_lattice_types.h"
#include "DNA_mesh_types.h"
#ifdef RNA_RUNTIME
static Key *rna_ShapeKey_find_key(ID *id)
{
switch(GS(id->name)) {
case ID_CU: return ((Curve*)id)->key;
case ID_KE: return (Key*)id;
case ID_LT: return ((Lattice*)id)->key;
case ID_ME: return ((Mesh*)id)->key;
default: return NULL;
}
}
static void *rna_ShapeKey_relative_key_get(PointerRNA *ptr)
{
Key *key= rna_ShapeKey_find_key(ptr->id.data);
KeyBlock *kb= (KeyBlock*)ptr->data, *kbrel;
int a;
if(key && kb->relative < key->totkey)
for(a=0, kbrel=key->block.first; kbrel; kbrel=kbrel->next, a++)
if(a == kb->relative)
return kbrel;
return NULL;
}
static float rna_ShapeKeyPoint_co_get(PointerRNA *ptr, int index)
{
float *vec= (float*)ptr->data;
return vec[index];
}
static void rna_ShapeKeyPoint_co_set(PointerRNA *ptr, int index, float value)
{
float *vec= (float*)ptr->data;
vec[index]= value;
}
static float rna_ShapeKeyCurvePoint_tilt_get(PointerRNA *ptr)
{
float *vec= (float*)ptr->data;
return vec[3];
}
static void rna_ShapeKeyCurvePoint_tilt_set(PointerRNA *ptr, float value)
{
float *vec= (float*)ptr->data;
vec[3]= value;
}
static float rna_ShapeKeyBezierPoint_co_get(PointerRNA *ptr, int index)
{
float *vec= (float*)ptr->data;
return vec[index+3];
}
static void rna_ShapeKeyBezierPoint_co_set(PointerRNA *ptr, int index, float value)
{
float *vec= (float*)ptr->data;
vec[index+3]= value;
}
static float rna_ShapeKeyBezierPoint_handle_1_co_get(PointerRNA *ptr, int index)
{
float *vec= (float*)ptr->data;
return vec[index];
}
static void rna_ShapeKeyBezierPoint_handle_1_co_set(PointerRNA *ptr, int index, float value)
{
float *vec= (float*)ptr->data;
vec[index]= value;
}
static float rna_ShapeKeyBezierPoint_handle_2_co_get(PointerRNA *ptr, int index)
{
float *vec= (float*)ptr->data;
return vec[6+index];
}
static void rna_ShapeKeyBezierPoint_handle_2_co_set(PointerRNA *ptr, int index, float value)
{
float *vec= (float*)ptr->data;
vec[6+index]= value;
}
/*static float rna_ShapeKeyBezierPoint_tilt_get(PointerRNA *ptr)
{
float *vec= (float*)ptr->data;
return vec[10];
}
static void rna_ShapeKeyBezierPoint_tilt_set(PointerRNA *ptr, float value)
{
float *vec= (float*)ptr->data;
vec[10]= value;
}*/
static void rna_ShapeKey_data_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
Key *key= rna_ShapeKey_find_key(ptr->id.data);
KeyBlock *kb= (KeyBlock*)ptr->data;
Curve *cu;
Nurb *nu;
int tot= kb->totelem, size= key->elemsize;
if(GS(key->from->name) == ID_CU) {
cu= (Curve*)key->from;
nu= cu->nurb.first;
if(nu->bezt) {
tot /= 3;
size *= 3;
}
}
rna_iterator_array_begin(iter, (void*)kb->data, size, tot, NULL);
}
static int rna_ShapeKey_data_length(PointerRNA *ptr)
{
Key *key= rna_ShapeKey_find_key(ptr->id.data);
KeyBlock *kb= (KeyBlock*)ptr->data;
Curve *cu;
Nurb *nu;
int tot= kb->totelem;
if(GS(key->from->name) == ID_CU) {
cu= (Curve*)key->from;
nu= cu->nurb.first;
if(nu->bezt)
tot /= 3;
}
return tot;
}
static StructRNA *rna_ShapeKey_data_type(CollectionPropertyIterator *iter)
{
Key *key= rna_ShapeKey_find_key(iter->parent.id.data);
Curve *cu;
Nurb *nu;
if(GS(key->from->name) == ID_CU) {
cu= (Curve*)key->from;
nu= cu->nurb.first;
if(nu->bezt)
return &RNA_ShapeKeyBezierPoint;
else
return &RNA_ShapeKeyCurvePoint;
}
else
return &RNA_ShapeKeyPoint;
}
#else
static void rna_def_keydata(BlenderRNA *brna)
{
StructRNA *srna;
PropertyRNA *prop;
srna= RNA_def_struct(brna, "ShapeKeyPoint", NULL);
RNA_def_struct_ui_text(srna, "Shape Key Point", "DOC_BROKEN");
prop= RNA_def_property(srna, "co", PROP_FLOAT, PROP_VECTOR);
RNA_def_property_array(prop, 3);
RNA_def_property_float_funcs(prop, "rna_ShapeKeyPoint_co_get", "rna_ShapeKeyPoint_co_set", NULL);
RNA_def_property_ui_text(prop, "Location", "");
srna= RNA_def_struct(brna, "ShapeKeyCurvePoint", NULL);
RNA_def_struct_ui_text(srna, "Shape Key Curve Point", "DOC_BROKEN");
prop= RNA_def_property(srna, "co", PROP_FLOAT, PROP_VECTOR);
RNA_def_property_array(prop, 3);
RNA_def_property_float_funcs(prop, "rna_ShapeKeyPoint_co_get", "rna_ShapeKeyPoint_co_set", NULL);
RNA_def_property_ui_text(prop, "Location", "");
prop= RNA_def_property(srna, "tilt", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_funcs(prop, "rna_ShapeKeyCurvePoint_tilt_get", "rna_ShapeKeyCurvePoint_tilt_set", NULL);
RNA_def_property_ui_text(prop, "Tilt", "");
srna= RNA_def_struct(brna, "ShapeKeyBezierPoint", NULL);
RNA_def_struct_ui_text(srna, "Shape Key Bezier Point", "DOC_BROKEN");
prop= RNA_def_property(srna, "co", PROP_FLOAT, PROP_VECTOR);
RNA_def_property_array(prop, 3);
RNA_def_property_float_funcs(prop, "rna_ShapeKeyBezierPoint_co_get", "rna_ShapeKeyBezierPoint_co_set", NULL);
RNA_def_property_ui_text(prop, "Location", "");
prop= RNA_def_property(srna, "handle_1_co", PROP_FLOAT, PROP_VECTOR);
RNA_def_property_array(prop, 3);
RNA_def_property_float_funcs(prop, "rna_ShapeKeyBezierPoint_handle_1_co_get", "rna_ShapeKeyBezierPoint_handle_1_co_set", NULL);
RNA_def_property_ui_text(prop, "Handle 1 Location", "");
prop= RNA_def_property(srna, "handle_2_co", PROP_FLOAT, PROP_VECTOR);
RNA_def_property_array(prop, 3);
RNA_def_property_float_funcs(prop, "rna_ShapeKeyBezierPoint_handle_2_co_get", "rna_ShapeKeyBezierPoint_handle_2_co_set", NULL);
RNA_def_property_ui_text(prop, "Handle 2 Location", "");
/* appears to be unused currently
prop= RNA_def_property(srna, "tilt", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_funcs(prop, "rna_ShapeKeyBezierPoint_tilt_get", "rna_ShapeKeyBezierPoint_tilt_set", NULL);
RNA_def_property_ui_text(prop, "Tilt", "");*/
}
static void rna_def_keyblock(BlenderRNA *brna)
{
StructRNA *srna;
PropertyRNA *prop;
static EnumPropertyItem prop_keyblock_type_items[] = {
{KEY_LINEAR, "KEY_LINEAR", "Linear", ""},
{KEY_CARDINAL, "KEY_CARDINAL", "Cardinal", ""},
{KEY_BSPLINE, "KEY_BSPLINE", "BSpline", ""},
{0, NULL, NULL, NULL}};
srna= RNA_def_struct(brna, "ShapeKey", NULL);
RNA_def_struct_ui_text(srna, "Shape Key", "DOC_BROKEN");
RNA_def_struct_sdna(srna, "KeyBlock");
prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
RNA_def_property_ui_text(prop, "Name", "");
RNA_def_struct_name_property(srna, prop);
/* keys need to be sorted to edit this */
prop= RNA_def_property(srna, "frame", PROP_FLOAT, PROP_NONE);
RNA_def_property_flag(prop, PROP_NOT_EDITABLE);
RNA_def_property_float_sdna(prop, NULL, "pos");
RNA_def_property_ui_text(prop, "Frame", "Frame for absolute keys.");
/* the current value isn't easily editable this way, it's linked to an IPO.
* these seem to be mostly the values that are being written to, not edited */
prop= RNA_def_property(srna, "value", PROP_FLOAT, PROP_NONE);
RNA_def_property_flag(prop, PROP_NOT_EDITABLE);
RNA_def_property_float_sdna(prop, NULL, "curval");
RNA_def_property_ui_text(prop, "Value", "Value of shape key at the current frame.");
prop= RNA_def_property(srna, "interpolation", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "type");
RNA_def_property_enum_items(prop, prop_keyblock_type_items);
RNA_def_property_ui_text(prop, "Interpolation", "Interpolation type.");
prop= RNA_def_property(srna, "vertex_group", PROP_STRING, PROP_NONE);
RNA_def_property_string_sdna(prop, NULL, "vgroup");
RNA_def_property_ui_text(prop, "Vertex Group", "Vertex weight group, to blend with basis shape.");
prop= RNA_def_property(srna, "relative_key", PROP_POINTER, PROP_NONE);
RNA_def_property_flag(prop, PROP_NOT_EDITABLE);
RNA_def_property_struct_type(prop, "ShapeKey");
RNA_def_property_ui_text(prop, "Relative Key", "Shape used as a relative key.");
RNA_def_property_pointer_funcs(prop, "rna_ShapeKey_relative_key_get", NULL, NULL);
prop= RNA_def_property(srna, "mute", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", KEYBLOCK_MUTE);
RNA_def_property_ui_text(prop, "Mute", "Mute this shape key.");
prop= RNA_def_property(srna, "slider_min", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "slidermin");
RNA_def_property_range(prop, -10.0f, 10.0f);
RNA_def_property_ui_text(prop, "Slider Min", "Minimum for slider.");
prop= RNA_def_property(srna, "slider_max", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "slidermax");
RNA_def_property_range(prop, -10.0f, 10.0f);
RNA_def_property_ui_text(prop, "Slider Max", "Maximum for slider.");
prop= RNA_def_property(srna, "data", PROP_COLLECTION, PROP_NONE);
RNA_def_property_collection_sdna(prop, NULL, "data", "totelem");
RNA_def_property_ui_text(prop, "Data", "");
RNA_def_property_collection_funcs(prop, "rna_ShapeKey_data_begin", 0, 0, 0, "rna_ShapeKey_data_type", "rna_ShapeKey_data_length", 0, 0);
}
static void rna_def_key(BlenderRNA *brna)
{
StructRNA *srna;
PropertyRNA *prop;
srna= RNA_def_struct(brna, "Key", "ID");
RNA_def_struct_ui_text(srna, "Key", "DOC_BROKEN");
prop= RNA_def_property(srna, "reference_key", PROP_POINTER, PROP_NONE);
RNA_def_property_flag(prop, PROP_NOT_EDITABLE);
RNA_def_property_pointer_sdna(prop, NULL, "refkey");
RNA_def_property_ui_text(prop, "Reference Key", "");
prop= RNA_def_property(srna, "shape_keys", PROP_COLLECTION, PROP_NONE);
RNA_def_property_collection_sdna(prop, NULL, "block", NULL);
RNA_def_property_struct_type(prop, "ShapeKey");
RNA_def_property_ui_text(prop, "Shape Keys", "");
rna_def_ipo_common(srna);
prop= RNA_def_property(srna, "user", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_sdna(prop, NULL, "from");
RNA_def_property_ui_text(prop, "User", "Datablock using these shape keys.");
prop= RNA_def_property(srna, "relative", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "type", KEY_RELATIVE);
RNA_def_property_ui_text(prop, "Relative", "Makes shape keys relative.");
prop= RNA_def_property(srna, "slurph", PROP_INT, PROP_UNSIGNED);
RNA_def_property_int_sdna(prop, NULL, "slurph");
RNA_def_property_range(prop, -500, 500);
RNA_def_property_ui_text(prop, "Slurph", "Creates a delay in amount of frames in applying keypositions, first vertex goes first.");
}
void RNA_def_key(BlenderRNA *brna)
{
rna_def_key(brna);
rna_def_keyblock(brna);
rna_def_keydata(brna);
}
#endif
|