4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * Contributor(s): Blender Foundation (2008).
22 * ***** END GPL LICENSE BLOCK *****
27 #include "RNA_define.h"
28 #include "RNA_types.h"
30 #include "rna_internal.h"
33 #include "DNA_curve_types.h"
34 #include "DNA_key_types.h"
35 #include "DNA_lattice_types.h"
36 #include "DNA_mesh_types.h"
40 static Key *rna_ShapeKey_find_key(ID *id)
42 switch(GS(id->name)) {
43 case ID_CU: return ((Curve*)id)->key;
44 case ID_KE: return (Key*)id;
45 case ID_LT: return ((Lattice*)id)->key;
46 case ID_ME: return ((Mesh*)id)->key;
51 static PointerRNA rna_ShapeKey_relative_key_get(PointerRNA *ptr)
53 Key *key= rna_ShapeKey_find_key(ptr->id.data);
54 KeyBlock *kb= (KeyBlock*)ptr->data, *kbrel;
57 if(key && kb->relative < key->totkey)
58 for(a=0, kbrel=key->block.first; kbrel; kbrel=kbrel->next, a++)
60 return rna_pointer_inherit_refine(ptr, &RNA_ShapeKey, kbrel);
62 return rna_pointer_inherit_refine(ptr, NULL, NULL);
65 static void rna_ShapeKeyPoint_co_get(PointerRNA *ptr, float *values)
67 float *vec= (float*)ptr->data;
74 static void rna_ShapeKeyPoint_co_set(PointerRNA *ptr, const float *values)
76 float *vec= (float*)ptr->data;
83 static float rna_ShapeKeyCurvePoint_tilt_get(PointerRNA *ptr)
85 float *vec= (float*)ptr->data;
89 static void rna_ShapeKeyCurvePoint_tilt_set(PointerRNA *ptr, float value)
91 float *vec= (float*)ptr->data;
95 static void rna_ShapeKeyBezierPoint_co_get(PointerRNA *ptr, float *values)
97 float *vec= (float*)ptr->data;
104 static void rna_ShapeKeyBezierPoint_co_set(PointerRNA *ptr, const float *values)
106 float *vec= (float*)ptr->data;
113 static void rna_ShapeKeyBezierPoint_handle_1_co_get(PointerRNA *ptr, float *values)
115 float *vec= (float*)ptr->data;
122 static void rna_ShapeKeyBezierPoint_handle_1_co_set(PointerRNA *ptr, const float *values)
124 float *vec= (float*)ptr->data;
131 static void rna_ShapeKeyBezierPoint_handle_2_co_get(PointerRNA *ptr, float *values)
133 float *vec= (float*)ptr->data;
140 static void rna_ShapeKeyBezierPoint_handle_2_co_set(PointerRNA *ptr, const float *values)
142 float *vec= (float*)ptr->data;
149 /*static float rna_ShapeKeyBezierPoint_tilt_get(PointerRNA *ptr)
151 float *vec= (float*)ptr->data;
155 static void rna_ShapeKeyBezierPoint_tilt_set(PointerRNA *ptr, float value)
157 float *vec= (float*)ptr->data;
161 static void rna_ShapeKey_data_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
163 Key *key= rna_ShapeKey_find_key(ptr->id.data);
164 KeyBlock *kb= (KeyBlock*)ptr->data;
167 int tot= kb->totelem, size= key->elemsize;
169 if(GS(key->from->name) == ID_CU) {
170 cu= (Curve*)key->from;
179 rna_iterator_array_begin(iter, (void*)kb->data, size, tot, NULL);
182 static int rna_ShapeKey_data_length(PointerRNA *ptr)
184 Key *key= rna_ShapeKey_find_key(ptr->id.data);
185 KeyBlock *kb= (KeyBlock*)ptr->data;
188 int tot= kb->totelem;
190 if(GS(key->from->name) == ID_CU) {
191 cu= (Curve*)key->from;
201 static PointerRNA rna_ShapeKey_data_get(CollectionPropertyIterator *iter)
203 Key *key= rna_ShapeKey_find_key(iter->parent.id.data);
208 if(GS(key->from->name) == ID_CU) {
209 cu= (Curve*)key->from;
213 type= &RNA_ShapeKeyBezierPoint;
215 type= &RNA_ShapeKeyCurvePoint;
218 type= &RNA_ShapeKeyPoint;
220 return rna_pointer_inherit_refine(&iter->parent, type, rna_iterator_array_get(iter));
225 static void rna_def_keydata(BlenderRNA *brna)
230 srna= RNA_def_struct(brna, "ShapeKeyPoint", NULL);
231 RNA_def_struct_ui_text(srna, "Shape Key Point", "Point in a shape key.");
233 prop= RNA_def_property(srna, "co", PROP_FLOAT, PROP_VECTOR);
234 RNA_def_property_array(prop, 3);
235 RNA_def_property_float_funcs(prop, "rna_ShapeKeyPoint_co_get", "rna_ShapeKeyPoint_co_set", NULL);
236 RNA_def_property_ui_text(prop, "Location", "");
238 srna= RNA_def_struct(brna, "ShapeKeyCurvePoint", NULL);
239 RNA_def_struct_ui_text(srna, "Shape Key Curve Point", "Point in a shape key for curves.");
241 prop= RNA_def_property(srna, "co", PROP_FLOAT, PROP_VECTOR);
242 RNA_def_property_array(prop, 3);
243 RNA_def_property_float_funcs(prop, "rna_ShapeKeyPoint_co_get", "rna_ShapeKeyPoint_co_set", NULL);
244 RNA_def_property_ui_text(prop, "Location", "");
246 prop= RNA_def_property(srna, "tilt", PROP_FLOAT, PROP_NONE);
247 RNA_def_property_float_funcs(prop, "rna_ShapeKeyCurvePoint_tilt_get", "rna_ShapeKeyCurvePoint_tilt_set", NULL);
248 RNA_def_property_ui_text(prop, "Tilt", "");
250 srna= RNA_def_struct(brna, "ShapeKeyBezierPoint", NULL);
251 RNA_def_struct_ui_text(srna, "Shape Key Bezier Point", "Point in a shape key for bezier curves.");
253 prop= RNA_def_property(srna, "co", PROP_FLOAT, PROP_VECTOR);
254 RNA_def_property_array(prop, 3);
255 RNA_def_property_float_funcs(prop, "rna_ShapeKeyBezierPoint_co_get", "rna_ShapeKeyBezierPoint_co_set", NULL);
256 RNA_def_property_ui_text(prop, "Location", "");
258 prop= RNA_def_property(srna, "handle_1_co", PROP_FLOAT, PROP_VECTOR);
259 RNA_def_property_array(prop, 3);
260 RNA_def_property_float_funcs(prop, "rna_ShapeKeyBezierPoint_handle_1_co_get", "rna_ShapeKeyBezierPoint_handle_1_co_set", NULL);
261 RNA_def_property_ui_text(prop, "Handle 1 Location", "");
263 prop= RNA_def_property(srna, "handle_2_co", PROP_FLOAT, PROP_VECTOR);
264 RNA_def_property_array(prop, 3);
265 RNA_def_property_float_funcs(prop, "rna_ShapeKeyBezierPoint_handle_2_co_get", "rna_ShapeKeyBezierPoint_handle_2_co_set", NULL);
266 RNA_def_property_ui_text(prop, "Handle 2 Location", "");
268 /* appears to be unused currently
269 prop= RNA_def_property(srna, "tilt", PROP_FLOAT, PROP_NONE);
270 RNA_def_property_float_funcs(prop, "rna_ShapeKeyBezierPoint_tilt_get", "rna_ShapeKeyBezierPoint_tilt_set", NULL);
271 RNA_def_property_ui_text(prop, "Tilt", "");*/
274 static void rna_def_keyblock(BlenderRNA *brna)
279 static EnumPropertyItem prop_keyblock_type_items[] = {
280 {KEY_LINEAR, "KEY_LINEAR", "Linear", ""},
281 {KEY_CARDINAL, "KEY_CARDINAL", "Cardinal", ""},
282 {KEY_BSPLINE, "KEY_BSPLINE", "BSpline", ""},
283 {0, NULL, NULL, NULL}};
285 srna= RNA_def_struct(brna, "ShapeKey", NULL);
286 RNA_def_struct_ui_text(srna, "Shape Key", "Shape key in a shape keys datablock.");
287 RNA_def_struct_sdna(srna, "KeyBlock");
289 prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
290 RNA_def_property_ui_text(prop, "Name", "");
291 RNA_def_struct_name_property(srna, prop);
293 /* keys need to be sorted to edit this */
294 prop= RNA_def_property(srna, "frame", PROP_FLOAT, PROP_NONE);
295 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
296 RNA_def_property_float_sdna(prop, NULL, "pos");
297 RNA_def_property_ui_text(prop, "Frame", "Frame for absolute keys.");
299 /* for now, this is editable directly, as users can set this even if they're not animating them (to test results) */
300 prop= RNA_def_property(srna, "value", PROP_FLOAT, PROP_NONE);
301 RNA_def_property_float_sdna(prop, NULL, "curval");
302 RNA_def_property_ui_text(prop, "Value", "Value of shape key at the current frame.");
304 prop= RNA_def_property(srna, "interpolation", PROP_ENUM, PROP_NONE);
305 RNA_def_property_enum_sdna(prop, NULL, "type");
306 RNA_def_property_enum_items(prop, prop_keyblock_type_items);
307 RNA_def_property_ui_text(prop, "Interpolation", "Interpolation type.");
309 prop= RNA_def_property(srna, "vertex_group", PROP_STRING, PROP_NONE);
310 RNA_def_property_string_sdna(prop, NULL, "vgroup");
311 RNA_def_property_ui_text(prop, "Vertex Group", "Vertex weight group, to blend with basis shape.");
313 prop= RNA_def_property(srna, "relative_key", PROP_POINTER, PROP_NONE);
314 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
315 RNA_def_property_struct_type(prop, "ShapeKey");
316 RNA_def_property_ui_text(prop, "Relative Key", "Shape used as a relative key.");
317 RNA_def_property_pointer_funcs(prop, "rna_ShapeKey_relative_key_get", NULL);
319 prop= RNA_def_property(srna, "mute", PROP_BOOLEAN, PROP_NONE);
320 RNA_def_property_boolean_sdna(prop, NULL, "flag", KEYBLOCK_MUTE);
321 RNA_def_property_ui_text(prop, "Mute", "Mute this shape key.");
323 prop= RNA_def_property(srna, "slider_min", PROP_FLOAT, PROP_NONE);
324 RNA_def_property_float_sdna(prop, NULL, "slidermin");
325 RNA_def_property_range(prop, -10.0f, 10.0f);
326 RNA_def_property_ui_text(prop, "Slider Min", "Minimum for slider.");
328 prop= RNA_def_property(srna, "slider_max", PROP_FLOAT, PROP_NONE);
329 RNA_def_property_float_sdna(prop, NULL, "slidermax");
330 RNA_def_property_range(prop, -10.0f, 10.0f);
331 RNA_def_property_ui_text(prop, "Slider Max", "Maximum for slider.");
333 prop= RNA_def_property(srna, "data", PROP_COLLECTION, PROP_NONE);
334 RNA_def_property_collection_sdna(prop, NULL, "data", "totelem");
335 RNA_def_property_struct_type(prop, "UnknownType");
336 RNA_def_property_ui_text(prop, "Data", "");
337 RNA_def_property_collection_funcs(prop, "rna_ShapeKey_data_begin", 0, 0, "rna_ShapeKey_data_get", "rna_ShapeKey_data_length", 0, 0);
340 static void rna_def_key(BlenderRNA *brna)
345 srna= RNA_def_struct(brna, "Key", "ID");
346 RNA_def_struct_ui_text(srna, "Key", "Shape keys datablock containing different shapes of geometric datablocks.");
348 prop= RNA_def_property(srna, "reference_key", PROP_POINTER, PROP_NEVER_NULL);
349 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
350 RNA_def_property_pointer_sdna(prop, NULL, "refkey");
351 RNA_def_property_ui_text(prop, "Reference Key", "");
353 prop= RNA_def_property(srna, "keys", PROP_COLLECTION, PROP_NONE);
354 RNA_def_property_collection_sdna(prop, NULL, "block", NULL);
355 RNA_def_property_struct_type(prop, "ShapeKey");
356 RNA_def_property_ui_text(prop, "Keys", "Shape keys.");
358 rna_def_animdata_common(srna);
360 prop= RNA_def_property(srna, "user", PROP_POINTER, PROP_NEVER_NULL);
361 RNA_def_property_pointer_sdna(prop, NULL, "from");
362 RNA_def_property_ui_text(prop, "User", "Datablock using these shape keys.");
364 prop= RNA_def_property(srna, "relative", PROP_BOOLEAN, PROP_NONE);
365 RNA_def_property_boolean_sdna(prop, NULL, "type", KEY_RELATIVE);
366 RNA_def_property_ui_text(prop, "Relative", "Makes shape keys relative.");
368 prop= RNA_def_property(srna, "slurph", PROP_INT, PROP_UNSIGNED);
369 RNA_def_property_int_sdna(prop, NULL, "slurph");
370 RNA_def_property_range(prop, -500, 500);
371 RNA_def_property_ui_text(prop, "Slurph", "Creates a delay in amount of frames in applying keypositions, first vertex goes first.");
374 void RNA_def_key(BlenderRNA *brna)
377 rna_def_keyblock(brna);
378 rna_def_keydata(brna);