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), Roland Hess
22 * ***** END GPL LICENSE BLOCK *****
27 #include "RNA_define.h"
28 #include "RNA_types.h"
30 #include "rna_internal.h"
32 #include "DNA_action_types.h"
33 #include "DNA_armature_types.h"
34 #include "DNA_constraint_types.h"
35 #include "DNA_object_types.h"
36 #include "DNA_scene_types.h"
42 #include "BLI_arithb.h"
44 #include "BKE_context.h"
45 #include "BKE_depsgraph.h"
46 #include "BKE_idprop.h"
48 #include "ED_armature.h"
50 static void rna_Pose_update(bContext *C, PointerRNA *ptr)
52 // XXX when to use this? ob->pose->flag |= (POSE_LOCKED|POSE_DO_UNLOCK);
54 DAG_object_flush_update(CTX_data_scene(C), ptr->id.data, OB_RECALC_DATA);
57 IDProperty *rna_PoseChannel_idproperties(PointerRNA *ptr, int create)
59 bPoseChannel *pchan= ptr->data;
61 if(create && !pchan->prop) {
62 IDPropertyTemplate val = {0};
63 pchan->prop= IDP_New(IDP_GROUP, val, "RNA_PoseChannel group");
69 static void rna_PoseChannel_euler_rotation_get(PointerRNA *ptr, float *value)
71 bPoseChannel *pchan= ptr->data;
73 if(pchan->rotmode == PCHAN_ROT_QUAT)
74 QuatToEul(pchan->quat, value);
76 VECCOPY(value, pchan->eul);
79 static void rna_PoseChannel_euler_rotation_set(PointerRNA *ptr, const float *value)
81 bPoseChannel *pchan= ptr->data;
83 if(pchan->rotmode == PCHAN_ROT_QUAT)
84 EulToQuat((float*)value, pchan->quat);
86 VECCOPY(pchan->eul, value);
89 static void rna_PoseChannel_name_set(PointerRNA *ptr, const char *value)
91 Object *ob= (Object*)ptr->id.data;
92 bPoseChannel *pchan= (bPoseChannel*)ptr->data;
93 char oldname[32], newname[32];
95 /* need to be on the stack */
96 BLI_strncpy(newname, value, 32);
97 BLI_strncpy(oldname, pchan->name, 32);
99 ED_armature_bone_rename(ob->data, oldname, newname);
102 static int rna_PoseChannel_has_ik_get(PointerRNA *ptr)
104 Object *ob= (Object*)ptr->id.data;
105 bPoseChannel *pchan= (bPoseChannel*)ptr->data;
107 return ED_pose_channel_in_IK_chain(ob, pchan);
112 /* users shouldn't be editing pose channel data directly -- better to set ipos and let blender calc pose_channel stuff */
113 /* it's going to be weird for users to find IK flags and other such here, instead of in bone where they would expect them
114 -- is there any way to put a doc in bone, pointing them here? */
116 static void rna_def_pose_channel(BlenderRNA *brna)
118 static EnumPropertyItem prop_rotmode_items[] = {
119 {PCHAN_ROT_QUAT, "QUATERNION", 0, "Quaternion (WXYZ)", "No Gimbal Lock (default)"},
120 {PCHAN_ROT_EUL, "EULER", 0, "Euler (XYZ)", "Prone to Gimbal Lock"},
121 {0, NULL, 0, NULL, NULL}};
126 srna= RNA_def_struct(brna, "PoseChannel", NULL);
127 RNA_def_struct_sdna(srna, "bPoseChannel");
128 RNA_def_struct_ui_text(srna, "Pose Channel", "Channel defining pose data for a bone in a Pose.");
129 RNA_def_struct_idproperties_func(srna, "rna_PoseChannel_idproperties");
131 prop= RNA_def_property(srna, "constraints", PROP_COLLECTION, PROP_NONE);
132 RNA_def_property_struct_type(prop, "Constraint");
133 RNA_def_property_ui_text(prop, "Constraints", "Constraints that act on this PoseChannel.");
135 prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
136 RNA_def_property_string_funcs(prop, NULL, NULL, "rna_PoseChannel_name_set");
137 RNA_def_property_ui_text(prop, "Name", "");
138 RNA_def_struct_name_property(srna, prop);
140 prop= RNA_def_property(srna, "has_ik", PROP_BOOLEAN, PROP_NONE);
141 RNA_def_property_boolean_funcs(prop, "rna_PoseChannel_has_ik_get", NULL);
142 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
143 RNA_def_property_ui_text(prop, "Has IK", "Is part of an IK chain.");
144 RNA_def_property_update(prop, NC_OBJECT|ND_POSE|ND_TRANSFORM, "rna_Pose_update");
146 prop= RNA_def_property(srna, "ik_dof_x", PROP_BOOLEAN, PROP_NONE);
147 RNA_def_property_boolean_negative_sdna(prop, NULL, "ikflag", BONE_IK_NO_XDOF);
148 RNA_def_property_ui_text(prop, "IK X DoF", "Allow movement around the X axis.");
149 RNA_def_property_update(prop, NC_OBJECT|ND_POSE|ND_TRANSFORM, "rna_Pose_update");
151 prop= RNA_def_property(srna, "ik_dof_y", PROP_BOOLEAN, PROP_NONE);
152 RNA_def_property_boolean_negative_sdna(prop, NULL, "ikflag", BONE_IK_NO_YDOF);
153 RNA_def_property_ui_text(prop, "IK Y DoF", "Allow movement around the Y axis.");
154 RNA_def_property_update(prop, NC_OBJECT|ND_POSE|ND_TRANSFORM, "rna_Pose_update");
156 prop= RNA_def_property(srna, "ik_dof_z", PROP_BOOLEAN, PROP_NONE);
157 RNA_def_property_boolean_negative_sdna(prop, NULL, "ikflag", BONE_IK_NO_ZDOF);
158 RNA_def_property_ui_text(prop, "IK Z DoF", "Allow movement around the Z axis.");
159 RNA_def_property_update(prop, NC_OBJECT|ND_POSE|ND_TRANSFORM, "rna_Pose_update");
161 prop= RNA_def_property(srna, "ik_limit_x", PROP_BOOLEAN, PROP_NONE);
162 RNA_def_property_boolean_sdna(prop, NULL, "ikflag", BONE_IK_XLIMIT);
163 RNA_def_property_ui_text(prop, "IK X Limit", "Limit movement around the X axis.");
164 RNA_def_property_update(prop, NC_OBJECT|ND_POSE|ND_TRANSFORM, "rna_Pose_update");
166 prop= RNA_def_property(srna, "ik_limit_y", PROP_BOOLEAN, PROP_NONE);
167 RNA_def_property_boolean_sdna(prop, NULL, "ikflag", BONE_IK_YLIMIT);
168 RNA_def_property_ui_text(prop, "IK Y Limit", "Limit movement around the Y axis.");
169 RNA_def_property_update(prop, NC_OBJECT|ND_POSE|ND_TRANSFORM, "rna_Pose_update");
171 prop= RNA_def_property(srna, "ik_limit_z", PROP_BOOLEAN, PROP_NONE);
172 RNA_def_property_boolean_sdna(prop, NULL, "ikflag", BONE_IK_ZLIMIT);
173 RNA_def_property_ui_text(prop, "IK Z Limit", "Limit movement around the Z axis.");
174 RNA_def_property_update(prop, NC_OBJECT|ND_POSE|ND_TRANSFORM, "rna_Pose_update");
176 prop= RNA_def_property(srna, "selected", PROP_BOOLEAN, PROP_NONE);
177 RNA_def_property_boolean_sdna(prop, NULL, "selectflag", BONE_SELECTED);
178 RNA_def_property_ui_text(prop, "Selected", "");
180 /* XXX note: bone groups are stored internally as bActionGroups :) - Aligorith */
181 prop= RNA_def_property(srna, "bone_group_index", PROP_INT, PROP_NONE);
182 RNA_def_property_int_sdna(prop, NULL, "agrp_index");
183 RNA_def_property_ui_text(prop, "Bone Group Index", "Bone Group this pose channel belongs to (0=no group).");
185 prop= RNA_def_property(srna, "path_start_frame", PROP_INT, PROP_NONE);
186 RNA_def_property_int_sdna(prop, NULL, "pathsf");
187 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
188 RNA_def_property_ui_text(prop, "Bone Paths Calculation Start Frame", "Starting frame of range of frames to use for Bone Path calculations.");
189 RNA_def_property_update(prop, NC_OBJECT|ND_POSE|ND_TRANSFORM, "rna_Pose_update");
191 prop= RNA_def_property(srna, "path_end_frame", PROP_INT, PROP_NONE);
192 RNA_def_property_int_sdna(prop, NULL, "pathef");
193 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
194 RNA_def_property_ui_text(prop, "Bone Paths Calculation End Frame", "End frame of range of frames to use for Bone Path calculations.");
195 RNA_def_property_update(prop, NC_OBJECT|ND_POSE|ND_TRANSFORM, "rna_Pose_update");
197 prop= RNA_def_property(srna, "bone", PROP_POINTER, PROP_NEVER_NULL);
198 RNA_def_property_struct_type(prop, "Bone");
199 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
200 RNA_def_property_ui_text(prop, "Bone", "Bone associated with this Pose Channel.");
202 prop= RNA_def_property(srna, "parent", PROP_POINTER, PROP_NONE);
203 RNA_def_property_struct_type(prop, "PoseChannel");
204 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
205 RNA_def_property_ui_text(prop, "Parent", "Parent of this pose channel.");
207 prop= RNA_def_property(srna, "child", PROP_POINTER, PROP_NONE);
208 RNA_def_property_struct_type(prop, "PoseChannel");
209 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
210 RNA_def_property_ui_text(prop, "Child", "Child of this pose channel.");
212 prop= RNA_def_property(srna, "location", PROP_FLOAT, PROP_VECTOR);
213 RNA_def_property_float_sdna(prop, NULL, "loc");
214 RNA_def_property_ui_text(prop, "Location", "");
215 RNA_def_property_update(prop, NC_OBJECT|ND_POSE|ND_TRANSFORM, "rna_Pose_update");
217 prop= RNA_def_property(srna, "scale", PROP_FLOAT, PROP_VECTOR);
218 RNA_def_property_float_sdna(prop, NULL, "size");
219 RNA_def_property_ui_text(prop, "Scale", "");
220 RNA_def_property_update(prop, NC_OBJECT|ND_POSE|ND_TRANSFORM, "rna_Pose_update");
222 prop= RNA_def_property(srna, "rotation", PROP_FLOAT, PROP_ROTATION);
223 RNA_def_property_float_sdna(prop, NULL, "quat");
224 RNA_def_property_ui_text(prop, "Rotation", "Rotation in Quaternions.");
225 RNA_def_property_update(prop, NC_OBJECT|ND_POSE|ND_TRANSFORM, "rna_Pose_update");
227 prop= RNA_def_property(srna, "euler_rotation", PROP_FLOAT, PROP_ROTATION);
228 RNA_def_property_float_sdna(prop, NULL, "eul");
229 RNA_def_property_float_funcs(prop, "rna_PoseChannel_euler_rotation_get", "rna_PoseChannel_euler_rotation_set", NULL);
230 RNA_def_property_ui_text(prop, "Rotation (Euler)", "Rotation in Eulers.");
231 RNA_def_property_update(prop, NC_OBJECT|ND_POSE|ND_TRANSFORM, "rna_Pose_update");
233 prop= RNA_def_property(srna, "rotation_mode", PROP_ENUM, PROP_NONE);
234 RNA_def_property_enum_sdna(prop, NULL, "rotmode");
235 RNA_def_property_enum_items(prop, prop_rotmode_items);
236 RNA_def_property_ui_text(prop, "Rotation Mode", "");
237 RNA_def_property_update(prop, NC_OBJECT|ND_POSE|ND_TRANSFORM, "rna_Pose_update");
239 /* These three matrix properties await an implementation of the PROP_MATRIX subtype, which currently doesn't exist. */
240 /* prop= RNA_def_property(srna, "channel_matrix", PROP_FLOAT, PROP_MATRIX);
241 RNA_def_property_struct_type(prop, "chan_mat");
242 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
243 RNA_def_property_ui_text(prop, "Channel Matrix", "4x4 matrix, before constraints.");*/
245 /* kaito says this should be not user-editable; I disagree; power users should be able to force this in python; he's the boss. */
246 /* prop= RNA_def_property(srna, "pose_matrix", PROP_FLOAT, PROP_MATRIX);
247 RNA_def_property_struct_type(prop, "pose_mat");
248 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
249 RNA_def_property_ui_text(prop, "Pose Matrix", "Final 4x4 matrix for this channel.");
251 prop= RNA_def_property(srna, "constraint_inverse_matrix", PROP_FLOAT, PROP_MATRIX);
252 RNA_def_property_struct_type(prop, "constinv");
253 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
254 RNA_def_property_ui_text(prop, "Constraint Inverse Matrix", "4x4 matrix, defines transform from final position to unconstrained position."); */
256 prop= RNA_def_property(srna, "pose_head", PROP_FLOAT, PROP_VECTOR);
257 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
258 RNA_def_property_ui_text(prop, "Pose Head Position", "Location of head of the channel's bone.");
260 prop= RNA_def_property(srna, "pose_tail", PROP_FLOAT, PROP_VECTOR);
261 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
262 RNA_def_property_ui_text(prop, "Pose Tail Position", "Location of tail of the channel's bone.");
264 prop= RNA_def_property(srna, "ik_min_x", PROP_FLOAT, PROP_ROTATION);
265 RNA_def_property_float_sdna(prop, NULL, "limitmin[0]");
266 RNA_def_property_range(prop, -180.0f, 0.0f);
267 RNA_def_property_ui_text(prop, "IK X Minimum", "Minimum angles for IK Limit");
268 RNA_def_property_update(prop, NC_OBJECT|ND_POSE|ND_TRANSFORM, "rna_Pose_update");
270 prop= RNA_def_property(srna, "ik_max_x", PROP_FLOAT, PROP_ROTATION);
271 RNA_def_property_float_sdna(prop, NULL, "limitmax[0]");
272 RNA_def_property_range(prop, 0.0f, 180.0f);
273 RNA_def_property_ui_text(prop, "IK X Maximum", "Maximum angles for IK Limit");
274 RNA_def_property_update(prop, NC_OBJECT|ND_POSE|ND_TRANSFORM, "rna_Pose_update");
276 prop= RNA_def_property(srna, "ik_min_y", PROP_FLOAT, PROP_ROTATION);
277 RNA_def_property_float_sdna(prop, NULL, "limitmin[1]");
278 RNA_def_property_range(prop, -180.0f, 0.0f);
279 RNA_def_property_ui_text(prop, "IK Y Minimum", "Minimum angles for IK Limit");
280 RNA_def_property_update(prop, NC_OBJECT|ND_POSE|ND_TRANSFORM, "rna_Pose_update");
282 prop= RNA_def_property(srna, "ik_max_y", PROP_FLOAT, PROP_ROTATION);
283 RNA_def_property_float_sdna(prop, NULL, "limitmax[1]");
284 RNA_def_property_range(prop, 0.0f, 180.0f);
285 RNA_def_property_ui_text(prop, "IK Y Maximum", "Maximum angles for IK Limit");
286 RNA_def_property_update(prop, NC_OBJECT|ND_POSE|ND_TRANSFORM, "rna_Pose_update");
288 prop= RNA_def_property(srna, "ik_min_z", PROP_FLOAT, PROP_ROTATION);
289 RNA_def_property_float_sdna(prop, NULL, "limitmin[2]");
290 RNA_def_property_range(prop, -180.0f, 0.0f);
291 RNA_def_property_ui_text(prop, "IK Z Minimum", "Minimum angles for IK Limit");
292 RNA_def_property_update(prop, NC_OBJECT|ND_POSE|ND_TRANSFORM, "rna_Pose_update");
294 prop= RNA_def_property(srna, "ik_max_z", PROP_FLOAT, PROP_ROTATION);
295 RNA_def_property_float_sdna(prop, NULL, "limitmax[2]");
296 RNA_def_property_range(prop, 0.0f, 180.0f);
297 RNA_def_property_ui_text(prop, "IK Z Maximum", "Maximum angles for IK Limit");
298 RNA_def_property_update(prop, NC_OBJECT|ND_POSE|ND_TRANSFORM, "rna_Pose_update");
300 prop= RNA_def_property(srna, "ik_stiffness_x", PROP_FLOAT, PROP_NONE);
301 RNA_def_property_float_sdna(prop, NULL, "stiffness[0]");
302 RNA_def_property_range(prop, 0.0f, 0.99f);
303 RNA_def_property_ui_text(prop, "IK X Stiffness", "IK stiffness around the X axis.");
304 RNA_def_property_update(prop, NC_OBJECT|ND_POSE|ND_TRANSFORM, "rna_Pose_update");
306 prop= RNA_def_property(srna, "ik_stiffness_y", PROP_FLOAT, PROP_NONE);
307 RNA_def_property_float_sdna(prop, NULL, "stiffness[1]");
308 RNA_def_property_range(prop, 0.0f, 0.99f);
309 RNA_def_property_ui_text(prop, "IK Y Stiffness", "IK stiffness around the Y axis.");
310 RNA_def_property_update(prop, NC_OBJECT|ND_POSE|ND_TRANSFORM, "rna_Pose_update");
312 prop= RNA_def_property(srna, "ik_stiffness_z", PROP_FLOAT, PROP_NONE);
313 RNA_def_property_float_sdna(prop, NULL, "stiffness[2]");
314 RNA_def_property_range(prop, 0.0f, 0.99f);
315 RNA_def_property_ui_text(prop, "IK Z Stiffness", "IK stiffness around the Z axis.");
316 RNA_def_property_update(prop, NC_OBJECT|ND_POSE|ND_TRANSFORM, "rna_Pose_update");
318 prop= RNA_def_property(srna, "ik_stretch", PROP_FLOAT, PROP_NONE);
319 RNA_def_property_float_sdna(prop, NULL, "ikstretch");
320 RNA_def_property_range(prop, 0.0f,1.0f);
321 RNA_def_property_ui_text(prop, "IK Stretch", "Allow scaling of the bone for IK.");
322 RNA_def_property_update(prop, NC_OBJECT|ND_POSE|ND_TRANSFORM, "rna_Pose_update");
324 prop= RNA_def_property(srna, "custom", PROP_POINTER, PROP_NONE);
325 RNA_def_property_ui_text(prop, "Custom Object", "Object that defines custom draw type for this bone.");
326 RNA_def_property_update(prop, NC_OBJECT|ND_POSE|ND_TRANSFORM, "rna_Pose_update");
328 prop= RNA_def_property(srna, "lock_location", PROP_BOOLEAN, PROP_VECTOR);
329 RNA_def_property_boolean_sdna(prop, NULL, "protectflag", OB_LOCK_LOCX);
330 RNA_def_property_array(prop, 3);
331 RNA_def_property_ui_text(prop, "Lock Location", "Lock editing of location in the interface.");
333 prop= RNA_def_property(srna, "lock_rotation", PROP_BOOLEAN, PROP_VECTOR);
334 RNA_def_property_boolean_sdna(prop, NULL, "protectflag", OB_LOCK_ROTX);
335 RNA_def_property_array(prop, 3);
336 RNA_def_property_ui_text(prop, "Lock Rotation", "Lock editing of rotation in the interface.");
338 prop= RNA_def_property(srna, "lock_scale", PROP_BOOLEAN, PROP_VECTOR);
339 RNA_def_property_boolean_sdna(prop, NULL, "protectflag", OB_LOCK_SCALEX);
340 RNA_def_property_array(prop, 3);
341 RNA_def_property_ui_text(prop, "Lock Scale", "Lock editing of scale in the interface.");
344 void RNA_def_pose(BlenderRNA *brna)
349 rna_def_pose_channel(brna);
351 srna= RNA_def_struct(brna, "Pose", NULL);
352 RNA_def_struct_sdna(srna, "bPose");
353 RNA_def_struct_ui_text(srna, "Pose", "A collection of pose channels, including settings for animating bones.");
355 prop= RNA_def_property(srna, "pose_channels", PROP_COLLECTION, PROP_NONE);
356 RNA_def_property_collection_sdna(prop, NULL, "chanbase", NULL);
357 RNA_def_property_struct_type(prop, "PoseChannel");
358 RNA_def_property_ui_text(prop, "Pose Channels", "Individual pose channels for the armature.");
360 /* commented for now... missing info... */
361 /*prop= RNA_def_property(srna, "action_groups", PROP_COLLECTION, PROP_NONE);
362 RNA_def_property_collection_sdna(prop, NULL, "agroups", NULL);
363 RNA_def_property_struct_type(prop, "ActionGroup");
364 RNA_def_property_ui_text(prop, "Action Groups", "Groups of bones.");*/