Blender V5.3
rna_armature.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cstdlib>
10
11#include "BLI_math_constants.hh"
13
14#include "BLT_translation.hh"
15
16#include "RNA_define.hh"
17
18#include "rna_internal.hh"
19
20#include "DNA_armature_types.h"
21
22#include "ED_anim_api.hh"
23
24#include "WM_api.hh"
25#include "WM_types.hh"
26
27namespace blender {
28
29/* Bone Collection Color Sets */
31 {0, "DEFAULT", 0, "Default Colors", ""},
32 {1, "THEME01", ICON_COLORSET_01_VEC, "01 - Theme Color Set", ""},
33 {2, "THEME02", ICON_COLORSET_02_VEC, "02 - Theme Color Set", ""},
34 {3, "THEME03", ICON_COLORSET_03_VEC, "03 - Theme Color Set", ""},
35 {4, "THEME04", ICON_COLORSET_04_VEC, "04 - Theme Color Set", ""},
36 {5, "THEME05", ICON_COLORSET_05_VEC, "05 - Theme Color Set", ""},
37 {6, "THEME06", ICON_COLORSET_06_VEC, "06 - Theme Color Set", ""},
38 {7, "THEME07", ICON_COLORSET_07_VEC, "07 - Theme Color Set", ""},
39 {8, "THEME08", ICON_COLORSET_08_VEC, "08 - Theme Color Set", ""},
40 {9, "THEME09", ICON_COLORSET_09_VEC, "09 - Theme Color Set", ""},
41 {10, "THEME10", ICON_COLORSET_10_VEC, "10 - Theme Color Set", ""},
42 {11, "THEME11", ICON_COLORSET_11_VEC, "11 - Theme Color Set", ""},
43 {12, "THEME12", ICON_COLORSET_12_VEC, "12 - Theme Color Set", ""},
44 {13, "THEME13", ICON_COLORSET_13_VEC, "13 - Theme Color Set", ""},
45 {14, "THEME14", ICON_COLORSET_14_VEC, "14 - Theme Color Set", ""},
46 {15, "THEME15", ICON_COLORSET_15_VEC, "15 - Theme Color Set", ""},
47 {16, "THEME16", ICON_COLORSET_16_VEC, "16 - Theme Color Set", ""},
48 {17, "THEME17", ICON_COLORSET_17_VEC, "17 - Theme Color Set", ""},
49 {18, "THEME18", ICON_COLORSET_18_VEC, "18 - Theme Color Set", ""},
50 {19, "THEME19", ICON_COLORSET_19_VEC, "19 - Theme Color Set", ""},
51 {20, "THEME20", ICON_COLORSET_20_VEC, "20 - Theme Color Set", ""},
52 {-1, "CUSTOM", 0, "Custom Color Set", ""},
53 {0, nullptr, 0, nullptr, nullptr},
54};
55#ifdef RNA_RUNTIME
56constexpr int COLOR_SETS_MAX_THEMED_INDEX = 20;
57#endif
58
59} // namespace blender
60
61#ifdef RNA_RUNTIME
62
63# include <fmt/format.h>
64
65# include "BLI_math_vector_c.hh"
66# include "BLI_string.hh"
67# include "BLI_string_utf8.hh"
68
69# include "BKE_action.hh"
70# include "BKE_context.hh"
71# include "BKE_global.hh"
72# include "BKE_idprop.hh"
73# include "BKE_lib_id.hh"
74# include "BKE_main.hh"
75# include "BKE_report.hh"
76
77# include "BKE_armature.hh"
78# include "ED_armature.hh"
79
81
82# include "DEG_depsgraph.hh"
83# include "DEG_depsgraph_build.hh"
84
85# ifndef NDEBUG
86# include "ANIM_armature_iter.hh"
87# endif
88
89namespace blender {
90
91static void rna_Armature_update(Main * /*bmain*/, Scene * /*scene*/, PointerRNA *ptr)
92{
93 ID *id = ptr->owner_id;
94
96}
97
98static void rna_Armature_update_data(Main * /*bmain*/, Scene * /*scene*/, PointerRNA *ptr)
99{
100 ID *id = ptr->owner_id;
101
102 DEG_id_tag_update(id, 0);
104 // WM_main_add_notifier(NC_OBJECT|ND_POSE, nullptr);
105}
106
107static void rna_Armature_dependency_update(Main *bmain, Scene * /*scene*/, PointerRNA *ptr)
108{
109 ID *id = ptr->owner_id;
110
112
113 DEG_id_tag_update(id, 0);
115}
116
117static void rna_Armature_act_bone_set(PointerRNA *ptr, PointerRNA value, ReportList * /*reports*/)
118{
119 bArmature *arm = static_cast<bArmature *>(ptr->data);
120
121 if (!value) {
122 arm->act_bone = nullptr;
123 }
124 else {
125 if (value.owner_id != &arm->id) {
126 Object *ob = id_cast<Object *>(value.owner_id);
127
128 if (GS(ob->id.name) != ID_OB || (ob->data != id_cast<const ID *>(arm))) {
129 printf("ERROR: armature set active bone - new active does not come from this armature\n");
130 return;
131 }
132 }
133
134 arm->act_bone = static_cast<Bone *>(value.data);
135 arm->act_bone->flag |= BONE_SELECTED;
136 }
137}
138
139static void rna_Armature_act_edit_bone_set(PointerRNA *ptr,
140 PointerRNA value,
141 ReportList * /*reports*/)
142{
143 bArmature *arm = static_cast<bArmature *>(ptr->data);
144
145 if (!value) {
146 arm->act_edbone = nullptr;
147 }
148 else {
149 if (value.owner_id != &arm->id) {
150 /* raise an error! */
151 }
152 else {
153 arm->act_edbone = static_cast<EditBone *>(value.data);
154 (static_cast<EditBone *>(arm->act_edbone))->flag |= BONE_SELECTED;
155 }
156 }
157}
158
159static EditBone *rna_Armature_edit_bone_new(bArmature *arm, ReportList *reports, const char *name)
160{
161 if (arm->edbo == nullptr) {
162 BKE_reportf(reports,
163 RPT_ERROR,
164 "Armature '%s' not in edit mode, cannot add an editbone",
165 arm->id.name + 2);
166 return nullptr;
167 }
168 return ED_armature_ebone_add(arm, name);
169}
170
171static void rna_Armature_edit_bone_remove(bArmature *arm,
172 ReportList *reports,
173 PointerRNA *ebone_ptr)
174{
175 EditBone *ebone = static_cast<EditBone *>(ebone_ptr->data);
176 if (arm->edbo == nullptr) {
177 BKE_reportf(reports,
178 RPT_ERROR,
179 "Armature '%s' not in edit mode, cannot remove an editbone",
180 arm->id.name + 2);
181 return;
182 }
183
184 if (BLI_findindex(arm->edbo, ebone) == -1) {
185 BKE_reportf(reports,
186 RPT_ERROR,
187 "Armature '%s' does not contain bone '%s'",
188 arm->id.name + 2,
189 ebone->name);
190 return;
191 }
192
193 ED_armature_ebone_remove(arm, ebone);
194 ebone_ptr->invalidate();
195}
196
197static void rna_iterator_bone_collections_all_begin(CollectionPropertyIterator *iter,
198 PointerRNA *ptr)
199{
200 bArmature *arm = static_cast<bArmature *>(ptr->data);
202 ptr,
203 arm->collection_array,
204 sizeof(BoneCollection *),
205 arm->collection_array_num,
206 false,
207 nullptr);
208}
209static int rna_iterator_bone_collections_all_length(PointerRNA *ptr)
210{
211 bArmature *arm = static_cast<bArmature *>(ptr->data);
212 return arm->collection_array_num;
213}
214
215static void rna_iterator_bone_collections_roots_begin(CollectionPropertyIterator *iter,
216 PointerRNA *ptr)
217{
218 bArmature *arm = static_cast<bArmature *>(ptr->data);
220 ptr,
221 arm->collection_array,
222 sizeof(BoneCollection *),
223 arm->collection_root_count,
224 false,
225 nullptr);
226}
227static int rna_iterator_bone_collections_roots_length(PointerRNA *ptr)
228{
229 bArmature *arm = static_cast<bArmature *>(ptr->data);
230 return arm->collection_root_count;
231}
232
233static PointerRNA rna_BoneCollections_active_get(PointerRNA *ptr)
234{
235 bArmature *arm = static_cast<bArmature *>(ptr->data);
236 BoneCollection *bcoll = arm->runtime->active_collection;
237 /* Work around an issue in the RNA code generator. Or my (Sybren) understanding of it. In any
238 * case, without this hand-written getter, the generated getter will actually use &bcoll instead
239 * of bcoll, resulting in the wrong pointer value. */
240 return RNA_pointer_create_with_parent(*ptr, RNA_BoneCollection, bcoll);
241}
242static void rna_BoneCollections_active_set(PointerRNA *ptr,
243 PointerRNA value,
244 struct ReportList * /*reports*/)
245{
246 bArmature *arm = static_cast<bArmature *>(ptr->data);
247 BoneCollection *bcoll = static_cast<BoneCollection *>(value.data);
249}
250
251static void rna_iterator_bone_collection_children_begin(CollectionPropertyIterator *iter,
252 PointerRNA *ptr)
253{
254 bArmature *arm = id_cast<bArmature *>(ptr->owner_id);
255 const BoneCollection *bcoll = static_cast<BoneCollection *>(ptr->data);
257 ptr,
258 arm->collection_array + bcoll->child_index,
259 sizeof(BoneCollection *),
260 bcoll->child_count,
261 false,
262 nullptr);
263}
264static int rna_iterator_bone_collection_children_length(PointerRNA *ptr)
265{
266 const BoneCollection *bcoll = static_cast<BoneCollection *>(ptr->data);
267 return bcoll->child_count;
268}
269
270static PointerRNA rna_BoneCollection_parent_get(PointerRNA *ptr)
271{
272 bArmature *arm = id_cast<bArmature *>(ptr->owner_id);
273 const BoneCollection *bcoll = static_cast<BoneCollection *>(ptr->data);
274
275 /* Note that this performs two scans of the array. This might look bad, but as
276 * long as `Object.children` still loops in Python over all of
277 * `bpy.data.objects`, this should also be acceptable. */
278 using namespace animrig;
279 const int bcoll_index = armature_bonecoll_find_index(arm, bcoll);
280 const int parent_index = armature_bonecoll_find_parent_index(arm, bcoll_index);
281
282 if (parent_index < 0) {
283 return {};
284 }
285
286 BoneCollection *parent = arm->collection_array[parent_index];
287 return RNA_pointer_create_discrete(&arm->id, RNA_BoneCollection, parent);
288}
289
290static void rna_BoneCollection_parent_set(PointerRNA *ptr,
291 PointerRNA value,
292 struct ReportList *reports)
293{
294 using namespace animrig;
295
296 BoneCollection *self = static_cast<BoneCollection *>(ptr->data);
297 BoneCollection *to_parent = static_cast<BoneCollection *>(value.data);
298
299 bArmature *armature = id_cast<bArmature *>(ptr->owner_id);
300
301 const int from_bcoll_index = armature_bonecoll_find_index(armature, self);
302 const int from_parent_index = armature_bonecoll_find_parent_index(armature, from_bcoll_index);
303 const int to_parent_index = armature_bonecoll_find_index(armature, to_parent);
304
305 if (to_parent_index >= 0) {
306 /* No need to check for parenthood cycles when the bone collection is turned into a root. */
307 if (to_parent_index == from_bcoll_index ||
308 armature_bonecoll_is_descendant_of(armature, from_bcoll_index, to_parent_index))
309 {
310 BKE_report(reports, RPT_ERROR, "Cannot make a bone collection a descendant of itself");
311 return;
312 }
313 }
314
316 armature, from_bcoll_index, -1, from_parent_index, to_parent_index);
317
319}
320
321static int rna_BoneCollections_active_index_get(PointerRNA *ptr)
322{
323 bArmature *arm = static_cast<bArmature *>(ptr->data);
324 return arm->runtime->active_collection_index;
325}
326
327static void rna_BoneCollections_active_index_set(PointerRNA *ptr, const int bone_collection_index)
328{
329 bArmature *arm = static_cast<bArmature *>(ptr->data);
330 ANIM_armature_bonecoll_active_index_set(arm, bone_collection_index);
331
333}
334
335static void rna_BoneCollections_active_index_range(
336 PointerRNA *ptr, int *min, int *max, int * /*softmin*/, int * /*softmax*/)
337{
338 bArmature *arm = static_cast<bArmature *>(ptr->data);
339
340 /* TODO: Figure out what this function actually is used for, as we may want to protect the first
341 * collection (i.e. the default collection that should remain first). */
342 *min = 0;
343 *max = max_ii(0, arm->collection_array_num - 1);
344}
345
346static BoneCollection *rna_BoneCollections_new(bArmature *armature,
347 ReportList *reports,
348 const char *name,
349 BoneCollection *parent)
350{
351 if (parent == nullptr) {
352 BoneCollection *bcoll = ANIM_armature_bonecoll_new(armature, name);
354 return bcoll;
355 }
356
357 const int32_t parent_index = animrig::armature_bonecoll_find_index(armature, parent);
358 if (parent_index < 0) {
359 BKE_reportf(reports,
360 RPT_ERROR,
361 "Bone collection '%s' not found in Armature '%s'",
362 parent->name,
363 armature->id.name + 2);
364 return nullptr;
365 }
366
367 BoneCollection *bcoll = ANIM_armature_bonecoll_new(armature, name, parent_index);
369 return bcoll;
370}
371
372static void rna_BoneCollections_active_name_set(PointerRNA *ptr, const char *name)
373{
374 bArmature *arm = static_cast<bArmature *>(ptr->data);
376}
377
378static void rna_BoneCollections_move(bArmature *arm, ReportList *reports, int from, int to)
379{
380 const int count = arm->collection_array_num;
381 if (from < 0 || from >= count || to < 0 || to >= count ||
382 (from != to && !ANIM_armature_bonecoll_move_to_index(arm, from, to)))
383 {
384 BKE_reportf(reports, RPT_ERROR, "Cannot move collection from index '%d' to '%d'", from, to);
385 }
386
388}
389
390static void rna_BoneCollection_name_set(PointerRNA *ptr, const char *name)
391{
392 bArmature *arm = id_cast<bArmature *>(ptr->owner_id);
393 BoneCollection *bcoll = static_cast<BoneCollection *>(ptr->data);
394
395 ANIM_armature_bonecoll_name_set(*G_MAIN, arm, bcoll, name);
396}
397
398static void rna_BoneCollection_is_visible_set(PointerRNA *ptr, const bool is_visible)
399{
400 bArmature *arm = id_cast<bArmature *>(ptr->owner_id);
401 BoneCollection *bcoll = static_cast<BoneCollection *>(ptr->data);
402
403 ANIM_armature_bonecoll_is_visible_set(arm, bcoll, is_visible);
404}
405
406static bool rna_BoneCollection_is_visible_effectively_get(PointerRNA *ptr)
407{
408 const bArmature *arm = id_cast<bArmature *>(ptr->owner_id);
409 const BoneCollection *bcoll = static_cast<BoneCollection *>(ptr->data);
411}
412
413static void rna_BoneCollection_is_solo_set(PointerRNA *ptr, const bool is_solo)
414{
415 bArmature *arm = id_cast<bArmature *>(ptr->owner_id);
416 BoneCollection *bcoll = static_cast<BoneCollection *>(ptr->data);
417
418 ANIM_armature_bonecoll_solo_set(arm, bcoll, is_solo);
419}
420
421static void rna_BoneCollection_is_expanded_set(PointerRNA *ptr, const bool is_expanded)
422{
423 BoneCollection *bcoll = static_cast<BoneCollection *>(ptr->data);
424 ANIM_armature_bonecoll_is_expanded_set(bcoll, is_expanded);
425}
426
427static std::optional<std::string> rna_BoneCollection_path(const PointerRNA *ptr)
428{
429 const BoneCollection *bcoll = static_cast<const BoneCollection *>(ptr->data);
430 char name_esc[sizeof(bcoll->name) * 2];
431 BLI_str_escape(name_esc, bcoll->name, sizeof(name_esc));
432 return fmt::format("collections_all[\"{}\"]", name_esc);
433}
434
435static IDProperty **rna_BoneCollection_idprops(PointerRNA *ptr)
436{
437 BoneCollection *bcoll = static_cast<BoneCollection *>(ptr->data);
438 return &bcoll->prop;
439}
440
441static IDProperty **rna_BoneCollection_system_idprops(PointerRNA *ptr)
442{
443 BoneCollection *bcoll = static_cast<BoneCollection *>(ptr->data);
444 return &bcoll->system_properties;
445}
446
447static void rna_BoneCollectionMemberships_clear(Bone *bone)
448{
451}
452
453static bool rna_BoneCollection_is_editable_get(PointerRNA *ptr)
454{
455 bArmature *arm = reinterpret_cast<bArmature *>(ptr->owner_id);
456 BoneCollection *bcoll = static_cast<BoneCollection *>(ptr->data);
457 return ANIM_armature_bonecoll_is_editable(arm, bcoll);
458}
459
460static int rna_BoneCollection_index_get(PointerRNA *ptr)
461{
462 bArmature *arm = reinterpret_cast<bArmature *>(ptr->owner_id);
463 BoneCollection *bcoll = static_cast<BoneCollection *>(ptr->data);
464 return animrig::armature_bonecoll_find_index(arm, bcoll);
465}
466
467static int rna_BoneCollection_child_number_get(PointerRNA *ptr)
468{
469 bArmature *arm = reinterpret_cast<bArmature *>(ptr->owner_id);
470 BoneCollection *bcoll = static_cast<BoneCollection *>(ptr->data);
472}
473static void rna_BoneCollection_child_number_set(PointerRNA *ptr, const int new_child_number)
474{
475 bArmature *arm = reinterpret_cast<bArmature *>(ptr->owner_id);
476 BoneCollection *bcoll = static_cast<BoneCollection *>(ptr->data);
477 animrig::armature_bonecoll_child_number_set(arm, bcoll, new_child_number);
479}
480
481/* BoneCollection.bones iterator functions. */
482
483static void rna_BoneCollection_bones_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
484{
485 bArmature *arm = id_cast<bArmature *>(ptr->owner_id);
486 if (arm->edbo) {
487 iter->valid = false;
488 BKE_reportf(nullptr, RPT_WARNING, "`Collection.bones` is not available in armature edit mode");
489 return;
490 }
491
492 BoneCollection *bcoll = static_cast<BoneCollection *>(ptr->data);
493 rna_iterator_listbase_begin(iter, ptr, &bcoll->bones, nullptr);
494}
495
496static PointerRNA rna_BoneCollection_bones_get(CollectionPropertyIterator *iter)
497{
498 ListBaseIterator *lb_iter = &iter->internal.listbase;
499 BoneCollectionMember *member = reinterpret_cast<BoneCollectionMember *>(lb_iter->link);
500 return RNA_pointer_create_with_parent(iter->parent, RNA_Bone, member->bone);
501}
502
503/* Bone.collections iterator functions. */
504
505static void rna_Bone_collections_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
506{
507 Bone *bone = static_cast<Bone *>(ptr->data);
508 ListBaseT<BoneCollectionReference> bone_collection_refs = bone->runtime.collections;
509 rna_iterator_listbase_begin(iter, ptr, &bone_collection_refs, nullptr);
510}
511
512static PointerRNA rna_Bone_collections_get(CollectionPropertyIterator *iter)
513{
514 ListBaseIterator *lb_iter = &iter->internal.listbase;
515 BoneCollectionReference *bcoll_ref = reinterpret_cast<BoneCollectionReference *>(lb_iter->link);
516 return RNA_pointer_create_with_parent(iter->parent, RNA_BoneCollection, bcoll_ref->bcoll);
517}
518
519/* EditBone.collections iterator functions. */
520
521static void rna_EditBone_collections_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
522{
523 EditBone *ebone = static_cast<EditBone *>(ptr->data);
524 ListBaseT<BoneCollectionReference> bone_collection_refs = ebone->bone_collections;
525 rna_iterator_listbase_begin(iter, ptr, &bone_collection_refs, nullptr);
526}
527
528/* Armature.collections library override support. */
529static bool rna_Armature_collections_override_apply(Main *bmain,
531{
532 PointerRNA *ptr_src = &rnaapply_ctx.ptr_src;
533 PointerRNA *ptr_dst = &rnaapply_ctx.ptr_dst;
534 PropertyRNA *prop_dst = rnaapply_ctx.prop_dst;
535 PointerRNA *ptr_item_dst = &rnaapply_ctx.ptr_item_dst;
536 PointerRNA *ptr_item_src = &rnaapply_ctx.ptr_item_src;
537 IDOverrideLibraryPropertyOperation *opop = rnaapply_ctx.liboverride_operation;
538
539 switch (opop->operation) {
541 /* This is the case this function was written for: adding new bone collections. It will be
542 * handled below this switch. */
543 break;
545 /* NOTE(@sybren): These are stored by Blender when overridable properties are changed on the
546 * root collections, However, these are *also* created on the `armature.collections_all`
547 * property, which is actually where these per-collection overrides are handled.
548 * This doesn't seem to be proper behavior, but I also don't want to spam the console about
549 * this as this is not something a user could fix. */
550 return false;
551 default:
552 /* Any other operation is simply not supported, and also not expected to exist. */
553 printf("Unsupported RNA override operation on armature collections, ignoring\n");
554 return false;
555 }
556
557 const bArmature *arm_src = id_cast<bArmature *>(ptr_src->owner_id);
558 bArmature *arm_dst = id_cast<bArmature *>(ptr_dst->owner_id);
559 BoneCollection *bcoll_anchor = static_cast<BoneCollection *>(ptr_item_dst->data);
560 BoneCollection *bcoll_src = static_cast<BoneCollection *>(ptr_item_src->data);
562 arm_dst, arm_src, bcoll_anchor, bcoll_src);
563
564 if (!ID_IS_LINKED(&arm_dst->id)) {
565 /* Mark this bone collection as local override, so that certain operations can be allowed. */
567 }
568
569 RNA_property_update_main(bmain, nullptr, ptr_dst, prop_dst);
570 return true;
571}
572
573static std::optional<std::string> rna_BoneColor_path_posebone(const PointerRNA *ptr)
574{
575 /* Find the bPoseChan that owns this BoneColor. */
576 const uint8_t *bcolor_ptr = static_cast<const uint8_t *>(ptr->data);
577 const uint8_t *bone_ptr = bcolor_ptr - offsetof(bPoseChannel, color);
578 const bPoseChannel *bone = reinterpret_cast<const bPoseChannel *>(bone_ptr);
579
580# ifndef NDEBUG
581 /* Sanity check that the above pointer magic actually worked. */
582 BLI_assert(GS(ptr->owner_id->name) == ID_OB);
583 const Object *ob = reinterpret_cast<const Object *>(ptr->owner_id);
584 bool found = false;
585 for (bPoseChannel &checkBone : ob->pose->chanbase) {
586 if (&checkBone.color == ptr->data) {
587 BLI_assert_msg(&checkBone == bone,
588 "pointer magic to find the pose bone failed (found the wrong bone)");
589 found = true;
590 break;
591 }
592 }
593 BLI_assert_msg(found, "pointer magic to find the pose bone failed (did not find the bone)");
594# endif
595
596 char name_esc[sizeof(bone->name) * 2];
597 BLI_str_escape(name_esc, bone->name, sizeof(name_esc));
598 return fmt::format("pose.bones[\"{}\"].color", name_esc);
599}
600
601static std::optional<std::string> rna_BoneColor_path_bone(const PointerRNA *ptr)
602{
603 /* Find the Bone that owns this BoneColor. */
604 const uint8_t *bcolor_ptr = static_cast<const uint8_t *>(ptr->data);
605 const uint8_t *bone_ptr = bcolor_ptr - offsetof(Bone, color);
606 const Bone *bone = reinterpret_cast<const Bone *>(bone_ptr);
607
608# ifndef NDEBUG
609 /* Sanity check that the above pointer magic actually worked. */
610 BLI_assert(GS(ptr->owner_id->name) == ID_AR);
611 const bArmature *arm = reinterpret_cast<const bArmature *>(ptr->owner_id);
612
613 bool found = false;
614 animrig::ANIM_armature_foreach_bone(&arm->bonebase, [&](const Bone *checkBone) {
615 if (&checkBone->color == ptr->data) {
616 BLI_assert_msg(checkBone == bone,
617 "pointer magic to find the pose bone failed (found the wrong bone)");
618 found = true;
619 }
620 });
621 BLI_assert_msg(found, "pointer magic to find the pose bone failed (did not find the bone)");
622# endif
623
624 char name_esc[sizeof(bone->name) * 2];
625 BLI_str_escape(name_esc, bone->name, sizeof(name_esc));
626 return fmt::format("bones[\"{}\"].color", name_esc);
627}
628
629static std::optional<std::string> rna_BoneColor_path_editbone(const PointerRNA *ptr)
630{
631 /* Find the Bone that owns this BoneColor. */
632 const uint8_t *bcolor_ptr = static_cast<const uint8_t *>(ptr->data);
633 const uint8_t *bone_ptr = bcolor_ptr - offsetof(EditBone, color);
634 const EditBone *bone = reinterpret_cast<const EditBone *>(bone_ptr);
635
636# ifndef NDEBUG
637 /* Sanity check that the above pointer magic actually worked. */
638 BLI_assert(GS(ptr->owner_id->name) == ID_AR);
639 const bArmature *arm = reinterpret_cast<const bArmature *>(ptr->owner_id);
640
641 bool found = false;
642 for (const EditBone &checkBone : *arm->edbo) {
643 if (&checkBone.color == ptr->data) {
644 BLI_assert_msg(&checkBone == bone,
645 "pointer magic to find the pose bone failed (found the wrong bone)");
646 found = true;
647 break;
648 }
649 }
650 BLI_assert_msg(found, "pointer magic to find the pose bone failed (did not find the bone)");
651# endif
652
653 char name_esc[sizeof(bone->name) * 2];
654 BLI_str_escape(name_esc, bone->name, sizeof(name_esc));
655 return fmt::format("bones[\"{}\"].color", name_esc);
656}
657
658static std::optional<std::string> rna_BoneColor_path(const PointerRNA *ptr)
659{
660 const ID *owner = ptr->owner_id;
661 BLI_assert_msg(owner, "expecting all bone colors to have an owner");
662
663 switch (GS(owner->name)) {
664 case ID_OB:
665 return rna_BoneColor_path_posebone(ptr);
666 case ID_AR: {
667 const bArmature *arm = reinterpret_cast<const bArmature *>(owner);
668 if (arm->edbo == nullptr) {
669 return rna_BoneColor_path_bone(ptr);
670 }
671 return rna_BoneColor_path_editbone(ptr);
672 }
673 default:
674 BLI_assert_msg(false, "expected object or armature");
675 return std::nullopt;
676 }
677}
678
679void rna_BoneColor_palette_index_set(PointerRNA *ptr, const int new_palette_index)
680{
681 if (new_palette_index < -1 || new_palette_index > COLOR_SETS_MAX_THEMED_INDEX) {
682 BKE_reportf(nullptr, RPT_ERROR, "Invalid color palette index: %d", new_palette_index);
683 return;
684 }
685
686 BoneColor *bcolor = static_cast<BoneColor *>(ptr->data);
687 bcolor->palette_index = new_palette_index;
688
689 ID *id = ptr->owner_id;
690 DEG_id_tag_update(id, ID_RECALC_SYNC_TO_EVAL);
692}
693
694bool rna_BoneColor_is_custom_get(PointerRNA *ptr)
695{
696 BoneColor *bcolor = static_cast<BoneColor *>(ptr->data);
697 return bcolor->palette_index < 0;
698}
699
700static void rna_BoneColor_update(Main * /*bmain*/, Scene * /*scene*/, PointerRNA *ptr)
701{
702 /* Ugly hack to trigger the setting of the SACTION_RUNTIME_FLAG_NEED_CHAN_SYNC flag on the
703 * animation editors, which in turn calls ANIM_sync_animchannels_to_data(C) with the right
704 * context.
705 *
706 * Without this, changes to the bone colors are not reflected on the bActionGroup colors.
707 */
709}
710
711static void rna_Armature_redraw_data(Main * /*bmain*/, Scene * /*scene*/, PointerRNA *ptr)
712{
713 ID *id = ptr->owner_id;
714
715 DEG_id_tag_update(id, ID_RECALC_SYNC_TO_EVAL);
718}
719
720/* Unselect bones when hidden or not selectable. */
721static void rna_EditBone_hide_update(Main * /*bmain*/, Scene * /*scene*/, PointerRNA *ptr)
722{
723 bArmature *arm = id_cast<bArmature *>(ptr->owner_id);
724 EditBone *ebone = static_cast<EditBone *>(ptr->data);
725
726 if (ebone->flag & (BONE_HIDDEN_A | BONE_UNSELECTABLE)) {
727 ebone->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL);
728 }
729
731 DEG_id_tag_update(&arm->id, ID_RECALC_SYNC_TO_EVAL);
732}
733
734/* Unselect bones when hidden or not selectable. */
735static void rna_Bone_hide_update(Main * /*bmain*/, Scene * /*scene*/, PointerRNA *ptr)
736{
737 bArmature *arm = id_cast<bArmature *>(ptr->owner_id);
738 Bone *bone = static_cast<Bone *>(ptr->data);
739 if (bone->flag & (BONE_HIDDEN_A | BONE_UNSELECTABLE)) {
740 bone->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL);
741 }
742
744 DEG_id_tag_update(&arm->id, ID_RECALC_SYNC_TO_EVAL);
745}
746
747/* called whenever a bone is renamed */
748static void rna_Bone_update_renamed(Main * /*bmain*/, Scene * /*scene*/, PointerRNA *ptr)
749{
750 ID *id = ptr->owner_id;
751
752 /* Redraw Outliner / Dope-sheet. */
754
755 /* update animation channels */
757}
758
759static std::optional<std::string> rna_Bone_path(const PointerRNA *ptr)
760{
761 const ID *id = ptr->owner_id;
762 const Bone *bone = static_cast<const Bone *>(ptr->data);
763 char name_esc[sizeof(bone->name) * 2];
764
765 BLI_str_escape(name_esc, bone->name, sizeof(name_esc));
766
767 /* special exception for trying to get the path where ID-block is Object
768 * - this will be assumed to be from a Pose Bone...
769 */
770 if (id) {
771 if (GS(id->name) == ID_OB) {
772 return fmt::format("pose.bones[\"{}\"].bone", name_esc);
773 }
774 }
775
776 /* from armature... */
777 return fmt::format("bones[\"{}\"]", name_esc);
778}
779
780static IDProperty **rna_Bone_idprops(PointerRNA *ptr)
781{
782 Bone *bone = static_cast<Bone *>(ptr->data);
783 return &bone->prop;
784}
785
786static IDProperty **rna_Bone_system_idprops(PointerRNA *ptr)
787{
788 Bone *bone = static_cast<Bone *>(ptr->data);
789 return &bone->system_properties;
790}
791
792static std::optional<std::string> rna_EditBone_path(const PointerRNA *ptr)
793{
794 EditBone *ebone = static_cast<EditBone *>(ptr->data);
795 char name_esc[sizeof(ebone->name) * 2];
796
797 BLI_str_escape(name_esc, ebone->name, sizeof(name_esc));
798 return fmt::format("edit_bones[\"{}\"]", name_esc);
799}
800
801static IDProperty **rna_EditBone_idprops(PointerRNA *ptr)
802{
803 EditBone *ebone = static_cast<EditBone *>(ptr->data);
804 return &ebone->prop;
805}
806
807static IDProperty **rna_EditBone_system_idprops(PointerRNA *ptr)
808{
809 EditBone *ebone = static_cast<EditBone *>(ptr->data);
810 return &ebone->system_properties;
811}
812
813static void rna_EditBone_name_set(PointerRNA *ptr, const char *value)
814{
815 bArmature *arm = id_cast<bArmature *>(ptr->owner_id);
816 EditBone *ebone = static_cast<EditBone *>(ptr->data);
817 char oldname[sizeof(ebone->name)], newname[sizeof(ebone->name)];
818
819 /* need to be on the stack */
820 STRNCPY_UTF8(newname, value);
821 STRNCPY(oldname, ebone->name);
822
824 ED_armature_bone_rename(G_MAIN, arm, oldname, newname);
825}
826
827static void rna_Bone_name_set(PointerRNA *ptr, const char *value)
828{
829 bArmature *arm = id_cast<bArmature *>(ptr->owner_id);
830 Bone *bone = static_cast<Bone *>(ptr->data);
831 char oldname[sizeof(bone->name)], newname[sizeof(bone->name)];
832
833 /* need to be on the stack */
834 STRNCPY_UTF8(newname, value);
835 STRNCPY(oldname, bone->name);
836
838 ED_armature_bone_rename(G_MAIN, arm, oldname, newname);
839}
840
841static void rna_EditBone_connected_check(EditBone *ebone)
842{
843 if (ebone->parent) {
844 if (ebone->flag & BONE_CONNECTED) {
845 /* Attach this bone to its parent */
846 copy_v3_v3(ebone->head, ebone->parent->tail);
847
848 if (ebone->flag & BONE_ROOTSEL) {
849 ebone->parent->flag |= BONE_TIPSEL;
850 }
851 }
852 else if (!(ebone->parent->flag & BONE_ROOTSEL)) {
853 ebone->parent->flag &= ~BONE_TIPSEL;
854 }
855 }
856}
857
858static void rna_EditBone_connected_set(PointerRNA *ptr, bool value)
859{
860 EditBone *ebone = static_cast<EditBone *>(ptr->data);
861
862 if (value) {
863 ebone->flag |= BONE_CONNECTED;
864 }
865 else {
866 ebone->flag &= ~BONE_CONNECTED;
867 }
868
869 rna_EditBone_connected_check(ebone);
870}
871
872static PointerRNA rna_EditBone_parent_get(PointerRNA *ptr)
873{
874 EditBone *data = static_cast<EditBone *>(ptr->data);
875 return RNA_pointer_create_with_parent(*ptr, RNA_EditBone, data->parent);
876}
877
878static void rna_EditBone_parent_set(PointerRNA *ptr, PointerRNA value, ReportList * /*reports*/)
879{
880 EditBone *ebone = static_cast<EditBone *>(ptr->data);
881 EditBone *pbone, *parbone = static_cast<EditBone *>(value.data);
882
883 if (parbone == nullptr) {
884 if (ebone->parent && !(ebone->parent->flag & BONE_ROOTSEL)) {
885 ebone->parent->flag &= ~BONE_TIPSEL;
886 }
887
888 ebone->parent = nullptr;
889 ebone->flag &= ~BONE_CONNECTED;
890 }
891 else {
892 /* within same armature */
893 if (value.owner_id != ptr->owner_id) {
894 return;
895 }
896
897 /* make sure this is a valid child */
898 if (parbone == ebone) {
899 return;
900 }
901
902 for (pbone = parbone->parent; pbone; pbone = pbone->parent) {
903 if (pbone == ebone) {
904 return;
905 }
906 }
907
908 ebone->parent = parbone;
909 rna_EditBone_connected_check(ebone);
910 }
911}
912
913static void rna_EditBone_matrix_get(PointerRNA *ptr, float *values)
914{
915 EditBone *ebone = static_cast<EditBone *>(ptr->data);
916 ED_armature_ebone_to_mat4(ebone, reinterpret_cast<float (*)[4]>(values));
917}
918
919static void rna_EditBone_matrix_set(PointerRNA *ptr, const float *values)
920{
921 EditBone *ebone = static_cast<EditBone *>(ptr->data);
922 ED_armature_ebone_from_mat4(ebone, reinterpret_cast<float (*)[4]>(const_cast<float *>(values)));
923}
924
925static float rna_EditBone_length_get(PointerRNA *ptr)
926{
927 EditBone *ebone = static_cast<EditBone *>(ptr->data);
928 return len_v3v3(ebone->head, ebone->tail);
929}
930
931static void rna_EditBone_length_set(PointerRNA *ptr, float length)
932{
933 EditBone *ebone = static_cast<EditBone *>(ptr->data);
934 float delta[3];
935
936 sub_v3_v3v3(delta, ebone->tail, ebone->head);
937 if (normalize_v3(delta) == 0.0f) {
938 /* Zero length means directional information is lost. Choose arbitrary direction to avoid
939 * getting stuck. */
940 delta[2] = 1.0f;
941 }
942
943 madd_v3_v3v3fl(ebone->tail, ebone->head, delta, length);
944}
945
946static void rna_Bone_bbone_handle_update(Main *bmain, Scene *scene, PointerRNA *ptr)
947{
948 bArmature *arm = id_cast<bArmature *>(ptr->owner_id);
949 Bone *bone = static_cast<Bone *>(ptr->data);
950
951 /* Update all users of this armature after changing B-Bone handles. */
952 for (Object *obt = bmain->objects.first(); obt; obt = static_cast<Object *>(obt->id.next)) {
953 if (obt->data == id_cast<ID *>(arm) && obt->pose) {
954 bPoseChannel *pchan = BKE_pose_channel_find_name(obt->pose, bone->name);
955
956 if (pchan && pchan->bone_get(*obt) == bone) {
957 BKE_pchan_rebuild_bbone_handles(obt->pose, {pchan, bone});
958 DEG_id_tag_update(&obt->id, ID_RECALC_SYNC_TO_EVAL);
959 }
960 }
961 }
962
963 rna_Armature_dependency_update(bmain, scene, ptr);
964}
965
966static PointerRNA rna_EditBone_bbone_prev_get(PointerRNA *ptr)
967{
968 EditBone *data = static_cast<EditBone *>(ptr->data);
969 return RNA_pointer_create_with_parent(*ptr, RNA_EditBone, data->bbone_prev);
970}
971
972static void rna_EditBone_bbone_prev_set(PointerRNA *ptr,
973 PointerRNA value,
974 ReportList * /*reports*/)
975{
976 EditBone *ebone = static_cast<EditBone *>(ptr->data);
977 EditBone *hbone = static_cast<EditBone *>(value.data);
978
979 /* Within the same armature? */
980 if (hbone == nullptr || value.owner_id == ptr->owner_id) {
981 ebone->bbone_prev = hbone;
982 }
983}
984
985static void rna_Bone_bbone_prev_set(PointerRNA *ptr, PointerRNA value, ReportList * /*reports*/)
986{
987 Bone *bone = static_cast<Bone *>(ptr->data);
988 Bone *hbone = static_cast<Bone *>(value.data);
989
990 /* Within the same armature? */
991 if (hbone == nullptr || value.owner_id == ptr->owner_id) {
992 bone->bbone_prev = hbone;
993 }
994}
995
996static PointerRNA rna_EditBone_bbone_next_get(PointerRNA *ptr)
997{
998 EditBone *data = static_cast<EditBone *>(ptr->data);
999 return RNA_pointer_create_with_parent(*ptr, RNA_EditBone, data->bbone_next);
1000}
1001
1002static void rna_EditBone_bbone_next_set(PointerRNA *ptr,
1003 PointerRNA value,
1004 ReportList * /*reports*/)
1005{
1006 EditBone *ebone = static_cast<EditBone *>(ptr->data);
1007 EditBone *hbone = static_cast<EditBone *>(value.data);
1008
1009 /* Within the same armature? */
1010 if (hbone == nullptr || value.owner_id == ptr->owner_id) {
1011 ebone->bbone_next = hbone;
1012 }
1013}
1014
1015static void rna_Bone_bbone_next_set(PointerRNA *ptr, PointerRNA value, ReportList * /*reports*/)
1016{
1017 Bone *bone = static_cast<Bone *>(ptr->data);
1018 Bone *hbone = static_cast<Bone *>(value.data);
1019
1020 /* Within the same armature? */
1021 if (hbone == nullptr || value.owner_id == ptr->owner_id) {
1022 bone->bbone_next = hbone;
1023 }
1024}
1025
1026static PointerRNA rna_EditBone_color_get(PointerRNA *ptr)
1027{
1028 EditBone *data = static_cast<EditBone *>(ptr->data);
1029 return RNA_pointer_create_with_parent(*ptr, RNA_BoneColor, &data->color);
1030}
1031
1032static void rna_Armature_editbone_transform_update(Main *bmain, Scene *scene, PointerRNA *ptr)
1033{
1034 bArmature *arm = id_cast<bArmature *>(ptr->owner_id);
1035 EditBone *ebone = static_cast<EditBone *>(ptr->data);
1036 EditBone *child;
1037
1038 /* update our parent */
1039 if (ebone->parent && ebone->flag & BONE_CONNECTED) {
1040 copy_v3_v3(ebone->parent->tail, ebone->head);
1041 ebone->parent->rad_tail = ebone->rad_head;
1042 }
1043
1044 /* update our children if necessary */
1045 for (child = arm->edbo->first(); child; child = child->next) {
1046 if (child->parent == ebone && (child->flag & BONE_CONNECTED)) {
1047 copy_v3_v3(child->head, ebone->tail);
1048 child->rad_head = ebone->rad_tail;
1049 }
1050 }
1051
1052 if (arm->flag & ARM_MIRROR_EDIT) {
1054 }
1055
1056 rna_Armature_update_data(bmain, scene, ptr);
1057}
1058
1059static void rna_Armature_bones_next(CollectionPropertyIterator *iter)
1060{
1061 ListBaseIterator *internal = &iter->internal.listbase;
1062 Bone *bone = reinterpret_cast<Bone *>(internal->link);
1063
1064 if (bone->childbase.first()) {
1065 internal->link = bone->childbase.first_as<Link>();
1066 }
1067 else if (bone->next) {
1068 internal->link = reinterpret_cast<Link *>(bone->next);
1069 }
1070 else {
1071 internal->link = nullptr;
1072
1073 do {
1074 bone = bone->parent;
1075 if (bone && bone->next) {
1076 internal->link = reinterpret_cast<Link *>(bone->next);
1077 break;
1078 }
1079 } while (bone);
1080 }
1081
1082 iter->valid = (internal->link != nullptr);
1083}
1084
1085/* not essential, but much faster than the default lookup function */
1086static bool rna_Armature_bones_lookup_string(PointerRNA *ptr, const char *key, PointerRNA *r_ptr)
1087{
1088 bArmature *arm = static_cast<bArmature *>(ptr->data);
1089 Bone *bone = BKE_armature_find_bone_name(arm, key);
1090 if (bone) {
1091 rna_pointer_create_with_ancestors(*ptr, RNA_Bone, bone, *r_ptr);
1092 return true;
1093 }
1094 else {
1095 return false;
1096 }
1097}
1098
1099static bool rna_Armature_is_editmode_get(PointerRNA *ptr)
1100{
1101 bArmature *arm = id_cast<bArmature *>(ptr->owner_id);
1102 return (arm->edbo != nullptr);
1103}
1104
1105static void rna_Armature_transform(bArmature *arm, const float mat[16])
1106{
1107 ED_armature_transform(arm, reinterpret_cast<const float (*)[4]>(mat), true);
1108}
1109
1110static int rna_Armature_relation_line_position_get(PointerRNA *ptr)
1111{
1112 bArmature *arm = static_cast<bArmature *>(ptr->data);
1113 /* Translate the bitflag to an EnumPropertyItem prop_relation_lines_items item ID. */
1114 return (arm->flag & ARM_DRAW_RELATION_FROM_HEAD) ? 1 : 0;
1115}
1116
1117static void rna_Armature_relation_line_position_set(PointerRNA *ptr, const int value)
1118{
1119 bArmature *arm = static_cast<bArmature *>(ptr->data);
1120
1121 /* Translate the EnumPropertyItem prop_relation_lines_items item ID to a bitflag */
1122 switch (value) {
1123 case 0:
1124 arm->flag &= ~ARM_DRAW_RELATION_FROM_HEAD;
1125 break;
1126 case 1:
1127 arm->flag |= ARM_DRAW_RELATION_FROM_HEAD;
1128 break;
1129 default:
1130 return;
1131 }
1132}
1133
1134} // namespace blender
1135
1136#else
1137
1138namespace blender {
1139
1141{
1142 StructRNA *srna;
1143 PropertyRNA *prop;
1144
1145 srna = RNA_def_struct(brna, "BoneColor", nullptr);
1146 RNA_def_struct_ui_text(srna, "BoneColor", "Theme color or custom color of a bone");
1147 RNA_def_struct_ui_icon(srna, ICON_BONE_DATA);
1148 RNA_def_struct_path_func(srna, "rna_BoneColor_path");
1149
1150 prop = RNA_def_property(srna, "palette", PROP_ENUM, PROP_NONE);
1151 RNA_def_property_enum_sdna(prop, nullptr, "palette_index");
1153 RNA_def_property_enum_funcs(prop, nullptr, "rna_BoneColor_palette_index_set", nullptr);
1156 RNA_def_property_ui_text(prop, "Color Set", "Color palette to use");
1157 RNA_def_property_update(prop, 0, "rna_BoneColor_update");
1158
1159 prop = RNA_def_property(srna, "is_custom", PROP_BOOLEAN, PROP_NONE);
1160 RNA_def_property_boolean_funcs(prop, "rna_BoneColor_is_custom_get", nullptr);
1163 prop,
1164 "Use Custom Color",
1165 "A color palette is user-defined, instead of using a theme-defined one");
1166
1167 prop = RNA_def_property(srna, "custom", PROP_POINTER, PROP_NONE);
1169 RNA_def_property_struct_type(prop, "ThemeBoneColorSet");
1173 prop, "Custom", "The custom bone colors, used when palette is 'CUSTOM'");
1174 RNA_def_property_update(prop, 0, "rna_BoneColor_update");
1175}
1176
1177void rna_def_bone_curved_common(StructRNA *srna, bool is_posebone, bool is_editbone)
1178{
1179 /* NOTE: The pose-mode values get applied over the top of the edit-mode ones. */
1180
1181# define RNA_DEF_CURVEBONE_UPDATE(prop, is_posebone, is_editbone) \
1182 { \
1183 if (is_posebone) { \
1184 RNA_def_property_update(prop, NC_OBJECT | ND_POSE, "rna_Pose_update"); \
1185 } \
1186 else if (is_editbone) { \
1187 RNA_def_property_update(prop, 0, "rna_Armature_editbone_transform_update"); \
1188 } \
1189 else { \
1190 RNA_def_property_update(prop, 0, "rna_Armature_update_data"); \
1191 } \
1192 } \
1193 ((void)0)
1194
1195 PropertyRNA *prop;
1196
1197 /* Roll In/Out */
1198 prop = RNA_def_property(srna, "bbone_rollin", PROP_FLOAT, PROP_ANGLE);
1199 RNA_def_property_float_sdna(prop, nullptr, "roll1");
1200 RNA_def_property_ui_range(prop, -M_PI * 2, M_PI * 2, 10, 2);
1202 prop, "Roll In", "Roll offset for the start of the B-Bone, adjusts twist");
1203 RNA_DEF_CURVEBONE_UPDATE(prop, is_posebone, is_editbone);
1204
1205 prop = RNA_def_property(srna, "bbone_rollout", PROP_FLOAT, PROP_ANGLE);
1206 RNA_def_property_float_sdna(prop, nullptr, "roll2");
1207 RNA_def_property_ui_range(prop, -M_PI * 2, M_PI * 2, 10, 2);
1209 prop, "Roll Out", "Roll offset for the end of the B-Bone, adjusts twist");
1210 RNA_DEF_CURVEBONE_UPDATE(prop, is_posebone, is_editbone);
1211
1212 if (is_posebone == false) {
1213 prop = RNA_def_property(srna, "use_endroll_as_inroll", PROP_BOOLEAN, PROP_NONE);
1215 prop, "Inherit End Roll", "Add Roll Out of the Start Handle bone to the Roll In value");
1216 RNA_def_property_boolean_sdna(prop, nullptr, "bbone_flag", BBONE_ADD_PARENT_END_ROLL);
1218 RNA_def_property_update(prop, 0, "rna_Armature_dependency_update");
1219 }
1220
1221 /* Curve X/Y Offsets */
1222 prop = RNA_def_property(srna, "bbone_curveinx", PROP_FLOAT, PROP_NONE);
1223 RNA_def_property_float_sdna(prop, nullptr, "curve_in_x");
1226 prop, "In X", "X-axis handle offset for start of the B-Bone's curve, adjusts curvature");
1227 RNA_DEF_CURVEBONE_UPDATE(prop, is_posebone, is_editbone);
1228
1229 prop = RNA_def_property(srna, "bbone_curveinz", PROP_FLOAT, PROP_NONE);
1230 RNA_def_property_float_sdna(prop, nullptr, "curve_in_z");
1233 prop, "In Z", "Z-axis handle offset for start of the B-Bone's curve, adjusts curvature");
1234 RNA_DEF_CURVEBONE_UPDATE(prop, is_posebone, is_editbone);
1235
1236 prop = RNA_def_property(srna, "bbone_curveoutx", PROP_FLOAT, PROP_NONE);
1237 RNA_def_property_float_sdna(prop, nullptr, "curve_out_x");
1240 prop, "Out X", "X-axis handle offset for end of the B-Bone's curve, adjusts curvature");
1241 RNA_DEF_CURVEBONE_UPDATE(prop, is_posebone, is_editbone);
1242
1243 prop = RNA_def_property(srna, "bbone_curveoutz", PROP_FLOAT, PROP_NONE);
1244 RNA_def_property_float_sdna(prop, nullptr, "curve_out_z");
1247 prop, "Out Z", "Z-axis handle offset for end of the B-Bone's curve, adjusts curvature");
1248 RNA_DEF_CURVEBONE_UPDATE(prop, is_posebone, is_editbone);
1249
1250 /* Ease In/Out */
1251 prop = RNA_def_property(srna, "bbone_easein", PROP_FLOAT, PROP_NONE);
1252 RNA_def_property_float_sdna(prop, nullptr, "ease1");
1253 RNA_def_property_ui_range(prop, -5.0f, 5.0f, 1, 3);
1254 RNA_def_property_float_default(prop, is_posebone ? 0.0f : 1.0f);
1255 RNA_def_property_ui_text(prop, "Ease In", "Length of first Bézier Handle (for B-Bones only)");
1257 RNA_DEF_CURVEBONE_UPDATE(prop, is_posebone, is_editbone);
1258
1259 prop = RNA_def_property(srna, "bbone_easeout", PROP_FLOAT, PROP_NONE);
1260 RNA_def_property_float_sdna(prop, nullptr, "ease2");
1261 RNA_def_property_ui_range(prop, -5.0f, 5.0f, 1, 3);
1262 RNA_def_property_float_default(prop, is_posebone ? 0.0f : 1.0f);
1263 RNA_def_property_ui_text(prop, "Ease Out", "Length of second Bézier Handle (for B-Bones only)");
1265 RNA_DEF_CURVEBONE_UPDATE(prop, is_posebone, is_editbone);
1266
1267 if (is_posebone == false) {
1268 prop = RNA_def_property(srna, "use_scale_easing", PROP_BOOLEAN, PROP_NONE);
1270 prop, "Scale Easing", "Multiply the final easing values by the Scale In/Out Y factors");
1271 RNA_def_property_boolean_sdna(prop, nullptr, "bbone_flag", BBONE_SCALE_EASING);
1272 RNA_DEF_CURVEBONE_UPDATE(prop, is_posebone, is_editbone);
1273 }
1274
1275 /* Scale In/Out */
1276 prop = RNA_def_property(srna, "bbone_scalein", PROP_FLOAT, PROP_XYZ);
1277 RNA_def_property_float_sdna(prop, nullptr, "scale_in");
1278 RNA_def_property_array(prop, 3);
1280 RNA_def_property_ui_range(prop, 0.0f, FLT_MAX, 1, 3);
1283 prop,
1284 "Scale In",
1285 "Scale factors for the start of the B-Bone, adjusts thickness (for tapering effects)");
1286 RNA_DEF_CURVEBONE_UPDATE(prop, is_posebone, is_editbone);
1287
1288 prop = RNA_def_property(srna, "bbone_scaleout", PROP_FLOAT, PROP_XYZ);
1289 RNA_def_property_float_sdna(prop, nullptr, "scale_out");
1290 RNA_def_property_array(prop, 3);
1292 RNA_def_property_ui_range(prop, 0.0f, FLT_MAX, 1, 3);
1295 prop,
1296 "Scale Out",
1297 "Scale factors for the end of the B-Bone, adjusts thickness (for tapering effects)");
1298 RNA_DEF_CURVEBONE_UPDATE(prop, is_posebone, is_editbone);
1299
1300# undef RNA_DEF_CURVEBONE_UPDATE
1301}
1302
1303static void rna_def_bone_common(StructRNA *srna, int editbone)
1304{
1305 static const EnumPropertyItem prop_bbone_handle_type[] = {
1307 "AUTO",
1308 0,
1309 "Automatic",
1310 "Use connected parent and children to compute the handle"},
1312 "ABSOLUTE",
1313 0,
1314 "Absolute",
1315 "Use the position of the specified bone to compute the handle"},
1317 "RELATIVE",
1318 0,
1319 "Relative",
1320 "Use the offset of the specified bone from rest pose to compute the handle"},
1322 "TANGENT",
1323 0,
1324 "Tangent",
1325 "Use the orientation of the specified bone to compute the handle, ignoring the location"},
1326 {0, nullptr, 0, nullptr, nullptr},
1327 };
1328
1329 static const EnumPropertyItem prop_bbone_mapping_mode[] = {
1331 "STRAIGHT",
1332 0,
1333 "Straight",
1334 "Fast mapping that is good for most situations, but ignores the rest pose "
1335 "curvature of the B-Bone"},
1337 "CURVED",
1338 0,
1339 "Curved",
1340 "Slower mapping that gives better deformation for B-Bones that are sharply "
1341 "curved in rest pose"},
1342 {0, nullptr, 0, nullptr, nullptr},
1343 };
1344
1345 static const EnumPropertyItem prop_inherit_scale_mode[] = {
1346 {BONE_INHERIT_SCALE_FULL, "FULL", 0, "Full", "Inherit all effects of parent scaling"},
1348 "FIX_SHEAR",
1349 0,
1350 "Fix Shear",
1351 "Inherit scaling, but remove shearing of the child in the rest orientation"},
1353 "ALIGNED",
1354 0,
1355 "Aligned",
1356 "Rotate non-uniform parent scaling to align with the child, applying parent X "
1357 "scale to child X axis, and so forth"},
1359 "AVERAGE",
1360 0,
1361 "Average",
1362 "Inherit uniform scaling representing the overall change in the volume of the parent"},
1363 {BONE_INHERIT_SCALE_NONE, "NONE", 0, "None", "Completely ignore parent scaling"},
1365 "NONE_LEGACY",
1366 0,
1367 "None (Legacy)",
1368 "Ignore parent scaling without compensating for parent shear. "
1369 "Replicates the effect of disabling the original Inherit Scale checkbox."},
1370 {0, nullptr, 0, nullptr, nullptr},
1371 };
1372
1373 static const EnumPropertyItem prop_drawtype_items[] = {
1375 "ARMATURE_DEFINED",
1376 0,
1377 "Armature Defined",
1378 "Use display mode from armature (default)"},
1379 {ARM_DRAW_TYPE_OCTA, "OCTAHEDRAL", 0, "Octahedral", "Display bones as octahedral shape"},
1380 {ARM_DRAW_TYPE_STICK, "STICK", 0, "Stick", "Display bones as simple 2D lines with dots"},
1382 "BBONE",
1383 0,
1384 "B-Bone",
1385 "Display bones as boxes, showing subdivision and B-Splines"},
1387 "ENVELOPE",
1388 0,
1389 "Envelope",
1390 "Display bones as extruded spheres, showing deformation influence volume"},
1392 "WIRE",
1393 0,
1394 "Wire",
1395 "Display bones as thin wires, showing subdivision and B-Splines"},
1396 {0, nullptr, 0, nullptr, nullptr},
1397 };
1398
1399 PropertyRNA *prop;
1400
1401 /* strings */
1402 prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
1403 RNA_def_property_string_sdna(prop, nullptr, "name");
1404 RNA_def_property_ui_text(prop, "Name", "");
1405 RNA_def_struct_name_property(srna, prop);
1406 if (editbone) {
1407 RNA_def_property_string_funcs(prop, nullptr, nullptr, "rna_EditBone_name_set");
1408 }
1409 else {
1410 RNA_def_property_string_funcs(prop, nullptr, nullptr, "rna_Bone_name_set");
1411 }
1412 RNA_def_property_update(prop, 0, "rna_Bone_update_renamed");
1413
1415
1416 prop = RNA_def_property(srna, "color", PROP_POINTER, PROP_NONE);
1417 RNA_def_property_struct_type(prop, "BoneColor");
1419 if (editbone) {
1420 RNA_def_property_pointer_funcs(prop, "rna_EditBone_color_get", nullptr, nullptr, nullptr);
1421 }
1422
1423 prop = RNA_def_property(srna, "display_type", PROP_ENUM, PROP_NONE);
1424 RNA_def_property_enum_sdna(prop, nullptr, "drawtype");
1425 RNA_def_property_enum_items(prop, prop_drawtype_items);
1426 RNA_def_property_ui_text(prop, "Display Type", "");
1427 RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
1429
1430 /* flags */
1431 prop = RNA_def_property(srna, "use_connect", PROP_BOOLEAN, PROP_NONE);
1432 RNA_def_property_boolean_sdna(prop, nullptr, "flag", BONE_CONNECTED);
1433 if (editbone) {
1434 RNA_def_property_boolean_funcs(prop, nullptr, "rna_EditBone_connected_set");
1435 }
1436 else {
1438 }
1440 prop, "Connected", "When bone has a parent, bone's head is stuck to the parent's tail");
1441 RNA_def_property_update(prop, 0, "rna_Armature_update_data");
1442
1443 prop = RNA_def_property(srna, "use_inherit_rotation", PROP_BOOLEAN, PROP_NONE);
1445 RNA_def_property_boolean_negative_sdna(prop, nullptr, "flag", BONE_HINGE);
1447 prop, "Inherit Rotation", "Bone inherits rotation or scale from parent bone");
1448 RNA_def_property_update(prop, 0, "rna_Armature_update_data");
1449
1450 prop = RNA_def_property(srna, "use_envelope_multiply", PROP_BOOLEAN, PROP_NONE);
1451 RNA_def_property_boolean_sdna(prop, nullptr, "flag", BONE_MULT_VG_ENV);
1453 prop,
1454 "Multiply Vertex Group with Envelope",
1455 "When deforming bone, multiply effects of Vertex Group weights with Envelope influence");
1456 RNA_def_property_update(prop, 0, "rna_Armature_update_data");
1457
1458 prop = RNA_def_property(srna, "use_deform", PROP_BOOLEAN, PROP_NONE);
1460 RNA_def_property_ui_text(prop, "Deform", "Enable Bone to deform geometry");
1461 RNA_def_property_update(prop, 0, "rna_Armature_update_data");
1462
1463 prop = RNA_def_property(srna, "inherit_scale", PROP_ENUM, PROP_NONE);
1465 prop, "Inherit Scale", "Specifies how the bone inherits scaling from the parent bone");
1466 RNA_def_property_enum_sdna(prop, nullptr, "inherit_scale_mode");
1467 RNA_def_property_enum_items(prop, prop_inherit_scale_mode);
1468 RNA_def_property_update(prop, 0, "rna_Armature_update_data");
1469
1470 prop = RNA_def_property(srna, "use_local_location", PROP_BOOLEAN, PROP_NONE);
1472 RNA_def_property_ui_text(prop, "Local Location", "Bone location is set in local space");
1474 RNA_def_property_update(prop, 0, "rna_Armature_update_data");
1475
1476 prop = RNA_def_property(srna, "use_relative_parent", PROP_BOOLEAN, PROP_NONE);
1478 prop, "Relative Parenting", "Object children will use relative transform, like deform");
1480 RNA_def_property_update(prop, 0, "rna_Armature_update_data");
1481
1482 prop = RNA_def_property(srna, "show_wire", PROP_BOOLEAN, PROP_NONE);
1483 RNA_def_property_boolean_sdna(prop, nullptr, "flag", BONE_DRAWWIRE);
1485 prop,
1486 "Display Wire",
1487 "Bone is always displayed in wireframe regardless of viewport shading mode "
1488 "(useful for non-obstructive custom bone shapes)");
1489 RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
1490
1491 /* XXX: use_cyclic_offset is deprecated in 2.5. May/may not return */
1492 prop = RNA_def_property(srna, "use_cyclic_offset", PROP_BOOLEAN, PROP_NONE);
1495 prop,
1496 "Cyclic Offset",
1497 "When bone does not have a parent, it receives cyclic offset effects (Deprecated)");
1498 RNA_def_property_update(prop, 0, "rna_Armature_update_data");
1499
1500 prop = RNA_def_property(srna, "hide_select", PROP_BOOLEAN, PROP_NONE);
1501 RNA_def_property_boolean_sdna(prop, nullptr, "flag", BONE_UNSELECTABLE);
1502 RNA_def_property_ui_text(prop, "Selectable", "Bone is able to be selected");
1503 if (editbone) {
1504 RNA_def_property_update(prop, 0, "rna_EditBone_hide_update");
1505 }
1506 else {
1507 RNA_def_property_update(prop, 0, "rna_Bone_hide_update");
1508 }
1509
1510 /* Number values */
1511 /* envelope deform settings */
1512 prop = RNA_def_property(srna, "envelope_distance", PROP_FLOAT, PROP_DISTANCE);
1513 if (editbone) {
1514 RNA_def_property_update(prop, 0, "rna_Armature_editbone_transform_update");
1515 }
1516 else {
1517 RNA_def_property_update(prop, 0, "rna_Armature_update_data");
1518 }
1519 RNA_def_property_float_sdna(prop, nullptr, "dist");
1520 RNA_def_property_range(prop, 0.0f, 1000.0f);
1522 prop, "Envelope Deform Distance", "Bone deformation distance (for Envelope deform only)");
1523
1524 prop = RNA_def_property(srna, "envelope_weight", PROP_FLOAT, PROP_NONE);
1525 RNA_def_property_float_sdna(prop, nullptr, "weight");
1526 RNA_def_property_range(prop, 0.0f, 1000.0f);
1528 prop, "Envelope Deform Weight", "Bone deformation weight (for Envelope deform only)");
1529 RNA_def_property_update(prop, 0, "rna_Armature_update_data");
1530
1531 prop = RNA_def_property(srna, "head_radius", PROP_FLOAT, PROP_DISTANCE);
1532 if (editbone) {
1533 RNA_def_property_update(prop, 0, "rna_Armature_editbone_transform_update");
1534 }
1535 else {
1536 RNA_def_property_update(prop, 0, "rna_Armature_update_data");
1537 }
1538 RNA_def_property_float_sdna(prop, nullptr, "rad_head");
1539 /* XXX: range is 0 to limit, where `limit = 10000.0f * std::max(1.0, view3d->grid)`. */
1540 // RNA_def_property_range(prop, 0, 1000);
1541 RNA_def_property_ui_range(prop, 0.01, 100, 0.1, 3);
1543 prop, "Envelope Head Radius", "Radius of head of bone (for Envelope deform only)");
1544
1545 prop = RNA_def_property(srna, "tail_radius", PROP_FLOAT, PROP_DISTANCE);
1546 if (editbone) {
1547 RNA_def_property_update(prop, 0, "rna_Armature_editbone_transform_update");
1548 }
1549 else {
1550 RNA_def_property_update(prop, 0, "rna_Armature_update_data");
1551 }
1552 RNA_def_property_float_sdna(prop, nullptr, "rad_tail");
1553 /* XXX range is 0 to limit, where limit = `10000.0f * std::max(1.0, view3d->grid)`. */
1554 // RNA_def_property_range(prop, 0, 1000);
1555 RNA_def_property_ui_range(prop, 0.01, 100, 0.1, 3);
1557 prop, "Envelope Tail Radius", "Radius of tail of bone (for Envelope deform only)");
1558
1559 /* b-bones deform settings */
1560 prop = RNA_def_property(srna, "bbone_segments", PROP_INT, PROP_NONE);
1561 if (editbone) {
1562 RNA_def_property_update(prop, 0, "rna_Armature_editbone_transform_update");
1563 }
1564 else {
1565 RNA_def_property_update(prop, 0, "rna_Armature_dependency_update");
1566 }
1567 RNA_def_property_int_sdna(prop, nullptr, "segments");
1568 RNA_def_property_range(prop, 1, 32);
1570 prop, "B-Bone Segments", "Number of subdivisions of bone (for B-Bones only)");
1571
1572 prop = RNA_def_property(srna, "bbone_mapping_mode", PROP_ENUM, PROP_NONE);
1573 RNA_def_property_enum_sdna(prop, nullptr, "bbone_mapping_mode");
1574 RNA_def_property_enum_items(prop, prop_bbone_mapping_mode);
1577 prop,
1578 "B-Bone Vertex Mapping Mode",
1579 "Selects how the vertices are mapped to B-Bone segments based on their position");
1580 RNA_def_property_update(prop, 0, "rna_Armature_update_data");
1581
1582 prop = RNA_def_property(srna, "bbone_x", PROP_FLOAT, PROP_NONE);
1583 if (editbone) {
1584 RNA_def_property_update(prop, 0, "rna_Armature_editbone_transform_update");
1585 }
1586 else {
1587 RNA_def_property_update(prop, 0, "rna_Armature_update_data");
1588 }
1589 RNA_def_property_float_sdna(prop, nullptr, "xwidth");
1592 RNA_def_property_ui_text(prop, "B-Bone Display X Width", "B-Bone X size");
1593
1594 prop = RNA_def_property(srna, "bbone_z", PROP_FLOAT, PROP_NONE);
1595 if (editbone) {
1596 RNA_def_property_update(prop, 0, "rna_Armature_editbone_transform_update");
1597 }
1598 else {
1599 RNA_def_property_update(prop, 0, "rna_Armature_update_data");
1600 }
1601 RNA_def_property_float_sdna(prop, nullptr, "zwidth");
1604 RNA_def_property_ui_text(prop, "B-Bone Display Z Width", "B-Bone Z size");
1605
1606 /* B-Bone Start Handle settings. */
1607 prop = RNA_def_property(srna, "bbone_handle_type_start", PROP_ENUM, PROP_NONE);
1608 RNA_def_property_enum_sdna(prop, nullptr, "bbone_prev_type");
1609 RNA_def_property_enum_items(prop, prop_bbone_handle_type);
1612 prop, "B-Bone Start Handle Type", "Selects how the start handle of the B-Bone is computed");
1613 RNA_def_property_update(prop, 0, "rna_Armature_dependency_update");
1614
1615 prop = RNA_def_property(srna, "bbone_custom_handle_start", PROP_POINTER, PROP_NONE);
1616 RNA_def_property_pointer_sdna(prop, nullptr, "bbone_prev");
1617 RNA_def_property_struct_type(prop, editbone ? "EditBone" : "Bone");
1618 if (editbone) {
1620 prop, "rna_EditBone_bbone_prev_get", "rna_EditBone_bbone_prev_set", nullptr, nullptr);
1621 RNA_def_property_update(prop, 0, "rna_Armature_dependency_update");
1622 }
1623 else {
1624 RNA_def_property_pointer_funcs(prop, nullptr, "rna_Bone_bbone_prev_set", nullptr, nullptr);
1625 RNA_def_property_update(prop, 0, "rna_Bone_bbone_handle_update");
1626 }
1630 prop, "B-Bone Start Handle", "Bone that serves as the start handle for the B-Bone curve");
1631
1632 prop = RNA_def_property(srna, "bbone_handle_use_scale_start", PROP_BOOLEAN, PROP_NONE);
1634 prop,
1635 "Start Handle Scale",
1636 "Multiply B-Bone Scale In channels by the local scale values of the start handle. "
1637 "This is done after the Scale Easing option and isn't affected by it.");
1639 prop, nullptr, "bbone_prev_flag", BBONE_HANDLE_SCALE_X, 3);
1640 RNA_def_property_update(prop, 0, "rna_Armature_update_data");
1641
1642 prop = RNA_def_property(srna, "bbone_handle_use_ease_start", PROP_BOOLEAN, PROP_NONE);
1644 prop,
1645 "Start Handle Ease",
1646 "Multiply the B-Bone Ease In channel by the local Y scale value of the start handle. "
1647 "This is done after the Scale Easing option and isn't affected by it.");
1648 RNA_def_property_boolean_sdna(prop, nullptr, "bbone_prev_flag", BBONE_HANDLE_SCALE_EASE);
1649 RNA_def_property_update(prop, 0, "rna_Armature_update_data");
1650
1651 /* B-Bone End Handle settings. */
1652 prop = RNA_def_property(srna, "bbone_handle_type_end", PROP_ENUM, PROP_NONE);
1653 RNA_def_property_enum_sdna(prop, nullptr, "bbone_next_type");
1654 RNA_def_property_enum_items(prop, prop_bbone_handle_type);
1657 prop, "B-Bone End Handle Type", "Selects how the end handle of the B-Bone is computed");
1658 RNA_def_property_update(prop, 0, "rna_Armature_dependency_update");
1659
1660 prop = RNA_def_property(srna, "bbone_custom_handle_end", PROP_POINTER, PROP_NONE);
1661 RNA_def_property_pointer_sdna(prop, nullptr, "bbone_next");
1662 RNA_def_property_struct_type(prop, editbone ? "EditBone" : "Bone");
1663 if (editbone) {
1665 prop, "rna_EditBone_bbone_next_get", "rna_EditBone_bbone_next_set", nullptr, nullptr);
1666 RNA_def_property_update(prop, 0, "rna_Armature_dependency_update");
1667 }
1668 else {
1669 RNA_def_property_pointer_funcs(prop, nullptr, "rna_Bone_bbone_next_set", nullptr, nullptr);
1670 RNA_def_property_update(prop, 0, "rna_Bone_bbone_handle_update");
1671 }
1675 prop, "B-Bone End Handle", "Bone that serves as the end handle for the B-Bone curve");
1676
1677 prop = RNA_def_property(srna, "bbone_handle_use_scale_end", PROP_BOOLEAN, PROP_NONE);
1679 prop,
1680 "End Handle Scale",
1681 "Multiply B-Bone Scale Out channels by the local scale values of the end handle. "
1682 "This is done after the Scale Easing option and isn't affected by it.");
1684 prop, nullptr, "bbone_next_flag", BBONE_HANDLE_SCALE_X, 3);
1685 RNA_def_property_update(prop, 0, "rna_Armature_update_data");
1686
1687 prop = RNA_def_property(srna, "bbone_handle_use_ease_end", PROP_BOOLEAN, PROP_NONE);
1689 prop,
1690 "End Handle Ease",
1691 "Multiply the B-Bone Ease Out channel by the local Y scale value of the end handle. "
1692 "This is done after the Scale Easing option and isn't affected by it.");
1693 RNA_def_property_boolean_sdna(prop, nullptr, "bbone_next_flag", BBONE_HANDLE_SCALE_EASE);
1694 RNA_def_property_update(prop, 0, "rna_Armature_update_data");
1695
1697}
1698
1701{
1702 StructRNA *srna;
1703 FunctionRNA *func;
1704
1705 RNA_def_property_srna(cprop, "BoneCollectionMemberships");
1706 srna = RNA_def_struct(brna, "BoneCollectionMemberships", nullptr);
1707 RNA_def_struct_sdna(srna, "Bone");
1709 srna, "Bone Collection Memberships", "The Bone Collections that contain this Bone");
1710
1711 /* Bone.collections.clear(...) */
1712 func = RNA_def_function(srna, "clear", "rna_BoneCollectionMemberships_clear");
1713 RNA_def_function_ui_description(func, "Remove this bone from all bone collections");
1714}
1715
1716/* Err... bones should not be directly edited (only edit-bones should be...). */
1717static void rna_def_bone(BlenderRNA *brna)
1718{
1719 StructRNA *srna;
1720 PropertyRNA *prop;
1721
1722 srna = RNA_def_struct(brna, "Bone", nullptr);
1723 RNA_def_struct_ui_text(srna, "Bone", "Bone in an Armature data-block");
1724 RNA_def_struct_ui_icon(srna, ICON_BONE_DATA);
1725 RNA_def_struct_path_func(srna, "rna_Bone_path");
1726 RNA_def_struct_idprops_func(srna, "rna_Bone_idprops");
1727 RNA_def_struct_system_idprops_func(srna, "rna_Bone_system_idprops");
1728
1729 /* pointers/collections */
1730 /* parent (pointer) */
1731 prop = RNA_def_property(srna, "parent", PROP_POINTER, PROP_NONE);
1732 RNA_def_property_struct_type(prop, "Bone");
1733 RNA_def_property_pointer_sdna(prop, nullptr, "parent");
1735 RNA_def_property_ui_text(prop, "Parent", "Parent bone (in same Armature)");
1736 RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
1737
1738 /* children (collection) */
1739 prop = RNA_def_property(srna, "children", PROP_COLLECTION, PROP_NONE);
1740 RNA_def_property_collection_sdna(prop, nullptr, "childbase", nullptr);
1741 RNA_def_property_struct_type(prop, "Bone");
1743 RNA_def_property_ui_text(prop, "Children", "Bones which are children of this bone");
1744
1745 prop = RNA_def_property(srna, "collections", PROP_COLLECTION, PROP_NONE);
1746 RNA_def_property_struct_type(prop, "BoneCollection");
1748 "rna_Bone_collections_begin",
1749 "rna_iterator_listbase_next",
1750 "rna_iterator_listbase_end",
1751 "rna_Bone_collections_get",
1752 nullptr,
1753 nullptr,
1754 nullptr,
1755 nullptr);
1757 RNA_def_property_ui_text(prop, "Collections", "Bone Collections that contain this bone");
1759
1760 rna_def_bone_common(srna, 0);
1761 rna_def_bone_curved_common(srna, false, false);
1762
1764
1765 prop = RNA_def_property(srna, "hide", PROP_BOOLEAN, PROP_NONE);
1766 RNA_def_property_boolean_sdna(prop, nullptr, "flag", BONE_HIDDEN_A);
1767 RNA_def_property_ui_text(prop, "Hide", "Bone is not visible when it is in Edit Mode");
1768 RNA_def_property_ui_icon(prop, ICON_RESTRICT_VIEW_OFF, -1);
1769 RNA_def_property_update(prop, 0, "rna_Bone_hide_update");
1770
1771 /* XXX better matrix descriptions possible (Arystan) */
1772 prop = RNA_def_property(srna, "matrix", PROP_FLOAT, PROP_MATRIX);
1773 RNA_def_property_float_sdna(prop, nullptr, "bone_mat");
1777 prop, "Bone Matrix", "3" BLI_STR_UTF8_MULTIPLICATION_SIGN "3 bone matrix");
1778
1779 prop = RNA_def_property(srna, "matrix_local", PROP_FLOAT, PROP_MATRIX);
1780 RNA_def_property_float_sdna(prop, nullptr, "arm_mat");
1784 "Bone Armature-Relative Matrix",
1786 "4 bone matrix relative to armature");
1787
1788 prop = RNA_def_property(srna, "tail", PROP_FLOAT, PROP_TRANSLATION);
1789 RNA_def_property_float_sdna(prop, nullptr, "tail");
1790 RNA_def_property_array(prop, 3);
1793 prop, "Tail", "Location of tail end of the bone relative to its parent");
1795
1796 prop = RNA_def_property(srna, "tail_local", PROP_FLOAT, PROP_TRANSLATION);
1797 RNA_def_property_float_sdna(prop, nullptr, "arm_tail");
1798 RNA_def_property_array(prop, 3);
1801 prop, "Armature-Relative Tail", "Location of tail end of the bone relative to armature");
1803
1804 prop = RNA_def_property(srna, "head", PROP_FLOAT, PROP_TRANSLATION);
1805 RNA_def_property_float_sdna(prop, nullptr, "head");
1806 RNA_def_property_array(prop, 3);
1809 prop, "Head", "Location of head end of the bone relative to its parent");
1811
1812 prop = RNA_def_property(srna, "head_local", PROP_FLOAT, PROP_TRANSLATION);
1813 RNA_def_property_float_sdna(prop, nullptr, "arm_head");
1814 RNA_def_property_array(prop, 3);
1817 prop, "Armature-Relative Head", "Location of head end of the bone relative to armature");
1819
1820 prop = RNA_def_property(srna, "length", PROP_FLOAT, PROP_DISTANCE);
1821 RNA_def_property_float_sdna(prop, nullptr, "length");
1823 RNA_def_property_ui_text(prop, "Length", "Length of the bone");
1824
1826
1827 RNA_api_bone(srna);
1828}
1829
1831{
1832 StructRNA *srna;
1833 PropertyRNA *prop;
1834
1835 srna = RNA_def_struct(brna, "EditBone", nullptr);
1836 RNA_def_struct_sdna(srna, "EditBone");
1837 RNA_def_struct_path_func(srna, "rna_EditBone_path");
1838 RNA_def_struct_idprops_func(srna, "rna_EditBone_idprops");
1839 RNA_def_struct_system_idprops_func(srna, "rna_EditBone_system_idprops");
1840 RNA_def_struct_ui_text(srna, "Edit Bone", "Edit mode bone in an armature data-block");
1841 RNA_def_struct_ui_icon(srna, ICON_BONE_DATA);
1842
1843 prop = RNA_def_property(srna, "collections", PROP_COLLECTION, PROP_NONE);
1844 RNA_def_property_struct_type(prop, "BoneCollection");
1846 "rna_EditBone_collections_begin",
1847 "rna_iterator_listbase_next",
1848 "rna_iterator_listbase_end",
1849 "rna_Bone_collections_get",
1850 nullptr,
1851 nullptr,
1852 nullptr,
1853 nullptr);
1856 RNA_def_property_ui_text(prop, "Collections", "Bone Collections that contain this bone");
1857
1858 RNA_define_verify_sdna(false); /* not in sdna */
1859
1860 prop = RNA_def_property(srna, "parent", PROP_POINTER, PROP_NONE);
1861 RNA_def_property_struct_type(prop, "EditBone");
1863 prop, "rna_EditBone_parent_get", "rna_EditBone_parent_set", nullptr, nullptr);
1865 RNA_def_property_ui_text(prop, "Parent", "Parent edit bone (in same Armature)");
1866 RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
1867
1868 prop = RNA_def_property(srna, "roll", PROP_FLOAT, PROP_ANGLE);
1869 RNA_def_property_float_sdna(prop, nullptr, "roll");
1870 RNA_def_property_ui_range(prop, -M_PI * 2, M_PI * 2, 10, 2);
1871 RNA_def_property_ui_text(prop, "Roll", "Bone rotation around head-tail axis");
1873 RNA_def_property_update(prop, 0, "rna_Armature_editbone_transform_update");
1874
1875 prop = RNA_def_property(srna, "head", PROP_FLOAT, PROP_TRANSLATION);
1876 RNA_def_property_float_sdna(prop, nullptr, "head");
1878 RNA_def_property_array(prop, 3);
1879 RNA_def_property_ui_text(prop, "Head", "Location of head end of the bone");
1881 RNA_def_property_update(prop, 0, "rna_Armature_editbone_transform_update");
1882
1883 prop = RNA_def_property(srna, "tail", PROP_FLOAT, PROP_TRANSLATION);
1884 RNA_def_property_float_sdna(prop, nullptr, "tail");
1886 RNA_def_property_array(prop, 3);
1887 RNA_def_property_ui_text(prop, "Tail", "Location of tail end of the bone");
1889 RNA_def_property_update(prop, 0, "rna_Armature_editbone_transform_update");
1890
1891 prop = RNA_def_property(srna, "length", PROP_FLOAT, PROP_DISTANCE);
1893 prop, "rna_EditBone_length_get", "rna_EditBone_length_set", nullptr);
1896 RNA_def_property_ui_text(prop, "Length", "Length of the bone. Changing moves the tail end.");
1898 RNA_def_property_update(prop, 0, "rna_Armature_editbone_transform_update");
1899
1900 rna_def_bone_common(srna, 1);
1901 rna_def_bone_curved_common(srna, false, true);
1902
1903 prop = RNA_def_property(srna, "hide", PROP_BOOLEAN, PROP_NONE);
1904 RNA_def_property_boolean_sdna(prop, nullptr, "flag", BONE_HIDDEN_A);
1905 RNA_def_property_ui_text(prop, "Hide", "Bone is not visible when in Edit Mode");
1907 RNA_def_property_update(prop, 0, "rna_EditBone_hide_update");
1908
1909 prop = RNA_def_property(srna, "lock", PROP_BOOLEAN, PROP_NONE);
1911 RNA_def_property_ui_text(prop, "Lock", "Bone is not able to be transformed when in Edit Mode");
1913 RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
1914
1915 prop = RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE);
1916 RNA_def_property_boolean_sdna(prop, nullptr, "flag", BONE_SELECTED);
1917 RNA_def_property_ui_text(prop, "Select", "");
1919 RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
1920
1921 prop = RNA_def_property(srna, "select_head", PROP_BOOLEAN, PROP_NONE);
1922 RNA_def_property_boolean_sdna(prop, nullptr, "flag", BONE_ROOTSEL);
1923 RNA_def_property_ui_text(prop, "Head Select", "");
1925 RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
1926
1927 prop = RNA_def_property(srna, "select_tail", PROP_BOOLEAN, PROP_NONE);
1928 RNA_def_property_boolean_sdna(prop, nullptr, "flag", BONE_TIPSEL);
1929 RNA_def_property_ui_text(prop, "Tail Select", "");
1931 RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
1932
1933 /* calculated and read only, not actual data access */
1934 prop = RNA_def_property(srna, "matrix", PROP_FLOAT, PROP_MATRIX);
1935 // RNA_def_property_float_sdna(prop, nullptr, ""); /* Doesn't access any real data. */
1937 // RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1938 RNA_def_property_flag(prop, PROP_THICK_WRAP); /* no reference to original data */
1940 prop,
1941 "Edit Bone Matrix",
1942 "Matrix combining location and rotation of the bone (head position, direction and roll), "
1943 "in armature space (does not include/support bone's length/size)");
1945 prop, "rna_EditBone_matrix_get", "rna_EditBone_matrix_set", nullptr);
1946
1948
1950}
1951
1952/* `armature.bones.*`. */
1954{
1955 StructRNA *srna;
1956 PropertyRNA *prop;
1957
1958 // FunctionRNA *func;
1959 // PropertyRNA *parm;
1960
1961 RNA_def_property_srna(cprop, "ArmatureBones");
1962 srna = RNA_def_struct(brna, "ArmatureBones", nullptr);
1963 RNA_def_struct_sdna(srna, "bArmature");
1964 RNA_def_struct_ui_text(srna, "Armature Bones", "Collection of armature bones");
1965
1966 prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
1967 RNA_def_property_struct_type(prop, "Bone");
1968 RNA_def_property_pointer_sdna(prop, nullptr, "act_bone");
1970 RNA_def_property_ui_text(prop, "Active Bone", "Armature's active bone");
1971 RNA_def_property_pointer_funcs(prop, nullptr, "rna_Armature_act_bone_set", nullptr, nullptr);
1972 RNA_def_property_update(prop, 0, "rna_Armature_update");
1973
1974 /* TODO: redraw. */
1975 // RNA_def_property_collection_active(prop, prop_act);
1976}
1977
1978/* `armature.bones.*`. */
1980{
1981 StructRNA *srna;
1982 PropertyRNA *prop;
1983
1984 FunctionRNA *func;
1985 PropertyRNA *parm;
1986
1987 RNA_def_property_srna(cprop, "ArmatureEditBones");
1988 srna = RNA_def_struct(brna, "ArmatureEditBones", nullptr);
1989 RNA_def_struct_sdna(srna, "bArmature");
1990 RNA_def_struct_ui_text(srna, "Armature EditBones", "Collection of armature edit bones");
1991
1992 prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
1993 RNA_def_property_struct_type(prop, "EditBone");
1994 RNA_def_property_pointer_sdna(prop, nullptr, "act_edbone");
1996 RNA_def_property_ui_text(prop, "Active EditBone", "Armatures active edit bone");
1997 RNA_def_property_update(prop, 0, "rna_Armature_update");
1999 prop, nullptr, "rna_Armature_act_edit_bone_set", nullptr, nullptr);
2000
2001 /* TODO: redraw. */
2002 // RNA_def_property_collection_active(prop, prop_act);
2003
2004 /* add target */
2005 func = RNA_def_function(srna, "new", "rna_Armature_edit_bone_new");
2007 RNA_def_function_ui_description(func, "Add a new bone");
2008 parm = RNA_def_string(func, "name", "Object", 0, "", "New name for the bone");
2010 /* return type */
2011 parm = RNA_def_pointer(func, "bone", "EditBone", "", "Newly created edit bone");
2013 RNA_def_function_return(func, parm);
2014
2015 /* remove target */
2016 func = RNA_def_function(srna, "remove", "rna_Armature_edit_bone_remove");
2018 RNA_def_function_ui_description(func, "Remove an existing bone from the armature");
2019 /* Target to remove. */
2020 parm = RNA_def_pointer(func, "bone", "EditBone", "", "EditBone to remove");
2023}
2024
2027{
2028 StructRNA *srna;
2029 PropertyRNA *prop;
2030
2031 FunctionRNA *func;
2032 PropertyRNA *parm;
2033
2034 RNA_def_property_srna(cprop, "BoneCollections");
2035 srna = RNA_def_struct(brna, "BoneCollections", nullptr);
2036 RNA_def_struct_sdna(srna, "bArmature");
2038 srna, "Armature Bone Collections", "The Bone Collections of this Armature");
2039
2040 prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
2041 RNA_def_property_struct_type(prop, "BoneCollection");
2042 RNA_def_property_pointer_sdna(prop, nullptr, "runtime->active_collection");
2046 prop, "rna_BoneCollections_active_get", "rna_BoneCollections_active_set", nullptr, nullptr);
2047 RNA_def_property_ui_text(prop, "Active Collection", "Armature's active bone collection");
2049
2050 prop = RNA_def_property(srna, "active_index", PROP_INT, PROP_NONE);
2051 RNA_def_property_int_sdna(prop, nullptr, "runtime->active_collection_index");
2055 prop,
2056 "Active Collection Index",
2057 "The index of the Armature's active bone collection; -1 when there "
2058 "is no active collection. Note that this is indexing the underlying array of bone "
2059 "collections, which may not be in the order you expect. Root collections are listed first, "
2060 "and siblings are always sequential. Apart from that, bone collections can be in any order, "
2061 "and thus incrementing or decrementing this index can make the active bone collection jump "
2062 "around in unexpected ways. For a more predictable interface, use ``active`` or "
2063 "``active_name``.");
2065 "rna_BoneCollections_active_index_get",
2066 "rna_BoneCollections_active_index_set",
2067 "rna_BoneCollections_active_index_range");
2069
2070 prop = RNA_def_property(srna, "active_name", PROP_STRING, PROP_NONE);
2071 RNA_def_property_string_sdna(prop, nullptr, "active_collection_name");
2072 /* TODO: For some reason the overrides system doesn't register a new operation when this property
2073 * changes. Needs further investigation to figure out why & fix it. */
2076 "Active Collection Name",
2077 "The name of the Armature's active bone collection; empty when there "
2078 "is no active collection");
2079 RNA_def_property_string_funcs(prop, nullptr, nullptr, "rna_BoneCollections_active_name_set");
2081
2082 prop = RNA_def_property(srna, "is_solo_active", PROP_BOOLEAN, PROP_NONE);
2085 prop,
2086 "Solo Active",
2087 "Read-only flag that indicates there is at least one bone collection marked as 'solo'");
2089
2090 /* Armature.collections.new(...) */
2091 func = RNA_def_function(srna, "new", "rna_BoneCollections_new");
2092 RNA_def_function_ui_description(func, "Add a new empty bone collection to the armature");
2094 parm = RNA_def_string(func,
2095 "name",
2096 nullptr,
2097 0,
2098 "Name",
2099 "Name of the new collection. Blender will ensure it is unique within the "
2100 "collections of the Armature.");
2102 parm = RNA_def_pointer(
2103 func,
2104 "parent",
2105 "BoneCollection",
2106 "Parent Collection",
2107 "If not None, the new bone collection becomes a child of this collection");
2108 /* Return value. */
2109 parm = RNA_def_pointer(
2110 func, "bonecollection", "BoneCollection", "", "Newly created bone collection");
2112 RNA_def_function_return(func, parm);
2113
2114 /* Armature.collections.remove(...) */
2115 func = RNA_def_function(srna, "remove", "ANIM_armature_bonecoll_remove");
2117 func,
2118 "Remove the bone collection from the armature. If this bone collection has any children, "
2119 "they will be reassigned to their grandparent; in other words, the children will take the "
2120 "place of the removed bone collection.");
2121 parm = RNA_def_pointer(func,
2122 "bone_collection",
2123 "BoneCollection",
2124 "Bone Collection",
2125 "The bone collection to remove");
2127
2128 /* Armature.collections.move(...) */
2129 func = RNA_def_function(srna, "move", "rna_BoneCollections_move");
2131 "Move a bone collection to a different position in the "
2132 "collection list. This can only be used to reorder siblings, "
2133 "and not to change parent-child relationships.");
2135 parm = RNA_def_int(
2136 func, "from_index", -1, INT_MIN, INT_MAX, "From Index", "Index to move", 0, 10000);
2138 parm = RNA_def_int(func, "to_index", -1, INT_MIN, INT_MAX, "To Index", "Target index", 0, 10000);
2140}
2141
2143{
2144 StructRNA *srna;
2145 PropertyRNA *prop;
2146
2147 FunctionRNA *func;
2148 PropertyRNA *parm;
2149
2150 static const EnumPropertyItem prop_drawtype_items[] = {
2152 "OCTAHEDRAL",
2153 0,
2154 "Octahedral",
2155 "Display bones as octahedral shape (default)"},
2156 {ARM_DRAW_TYPE_STICK, "STICK", 0, "Stick", "Display bones as simple 2D lines with dots"},
2158 "BBONE",
2159 0,
2160 "B-Bone",
2161 "Display bones as boxes, showing subdivision and B-Splines"},
2163 "ENVELOPE",
2164 0,
2165 "Envelope",
2166 "Display bones as extruded spheres, showing deformation influence volume"},
2168 "WIRE",
2169 0,
2170 "Wire",
2171 "Display bones as thin wires, showing subdivision and B-Splines"},
2172 {0, nullptr, 0, nullptr, nullptr},
2173 };
2174
2175 static const EnumPropertyItem prop_pose_position_items[] = {
2176 {0, "POSE", 0, "Pose Position", "Show armature in posed state"},
2177 {ARM_RESTPOS,
2178 "REST",
2179 0,
2180 "Rest Position",
2181 "Show Armature in binding pose state (no posing possible)"},
2182 {0, nullptr, 0, nullptr, nullptr},
2183 };
2184 static const EnumPropertyItem prop_relation_lines_items[] = {
2185 {0, "TAIL", 0, "Tail", "Draw the relationship line from the parent tail to the child head"},
2186 {1, "HEAD", 0, "Head", "Draw the relationship line from the parent head to the child head"},
2187 {0, nullptr, 0, nullptr, nullptr},
2188 };
2189
2190 srna = RNA_def_struct(brna, "Armature", "ID");
2192 srna,
2193 "Armature",
2194 "Armature data-block containing a hierarchy of bones, usually used for rigging characters");
2195 RNA_def_struct_ui_icon(srna, ICON_ARMATURE_DATA);
2196 RNA_def_struct_sdna(srna, "bArmature");
2197
2198 func = RNA_def_function(srna, "transform", "rna_Armature_transform");
2199 RNA_def_function_ui_description(func, "Transform armature bones by a matrix");
2200 parm = RNA_def_float_matrix(func, "matrix", 4, 4, nullptr, 0.0f, 0.0f, "", "Matrix", 0.0f, 0.0f);
2202
2203 /* Animation Data */
2205
2207
2208 /* Collection Properties */
2209 prop = RNA_def_property(srna, "bones", PROP_COLLECTION, PROP_NONE);
2210 RNA_def_property_collection_sdna(prop, nullptr, "bonebase", nullptr);
2212 nullptr,
2213 "rna_Armature_bones_next",
2214 nullptr,
2215 nullptr,
2216 nullptr,
2217 nullptr,
2218 "rna_Armature_bones_lookup_string",
2219 nullptr);
2220 RNA_def_property_struct_type(prop, "Bone");
2221 RNA_def_property_ui_text(prop, "Bones", "");
2222 rna_def_armature_bones(brna, prop);
2223
2224 prop = RNA_def_property(srna, "edit_bones", PROP_COLLECTION, PROP_NONE);
2225 RNA_def_property_collection_sdna(prop, nullptr, "edbo", nullptr);
2226 RNA_def_property_struct_type(prop, "EditBone");
2227 RNA_def_property_ui_text(prop, "Edit Bones", "");
2228 rna_def_armature_edit_bones(brna, prop);
2229
2230 /* Bone Collection properties. */
2231 prop = RNA_def_property(srna, "collections", PROP_COLLECTION, PROP_NONE);
2232 RNA_def_property_struct_type(prop, "BoneCollection");
2234 "rna_iterator_bone_collections_roots_begin",
2235 "rna_iterator_array_next",
2236 "rna_iterator_array_end",
2237 "rna_iterator_array_dereference_get",
2238 "rna_iterator_bone_collections_roots_length",
2239 nullptr, /* TODO */
2240 nullptr, /* TODO */
2241 nullptr);
2242 RNA_def_property_ui_text(prop, "Bone Collections (Roots)", "");
2245 prop, nullptr, nullptr, "rna_Armature_collections_override_apply");
2248 rna_def_armature_collections(brna, prop);
2249
2250 prop = RNA_def_property(srna, "collections_all", PROP_COLLECTION, PROP_NONE);
2251 RNA_def_property_struct_type(prop, "BoneCollection");
2253 "rna_iterator_bone_collections_all_begin",
2254 "rna_iterator_array_next",
2255 "rna_iterator_array_end",
2256 "rna_iterator_array_dereference_get",
2257 "rna_iterator_bone_collections_all_length",
2258 nullptr, /* TODO */
2259 nullptr, /* TODO */
2260 nullptr);
2262 prop, "Bone Collections (All)", "List of all bone collections of the armature");
2264 /* Overrides on `armature.collections_all` are only there to override specific properties, like
2265 * is_visible.
2266 *
2267 * New Bone collections are added as overrides via the `armature.collections` (the roots)
2268 * property. It's up to its 'apply' function to also copy the children of a
2269 * library-override-added root. */
2271
2272 /* Enum values */
2273 prop = RNA_def_property(srna, "pose_position", PROP_ENUM, PROP_NONE);
2274 RNA_def_property_enum_bitflag_sdna(prop, nullptr, "flag");
2275 RNA_def_property_enum_items(prop, prop_pose_position_items);
2277 prop, "Pose Position", "Show armature in binding pose or final posed state");
2278 RNA_def_property_update(prop, 0, "rna_Armature_update_data");
2280
2281 prop = RNA_def_property(srna, "display_type", PROP_ENUM, PROP_NONE);
2282 RNA_def_property_enum_sdna(prop, nullptr, "drawtype");
2283 RNA_def_property_enum_items(prop, prop_drawtype_items);
2284 RNA_def_property_ui_text(prop, "Display Type", "");
2285 RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
2287
2288 /* flag */
2289 prop = RNA_def_property(srna, "show_axes", PROP_BOOLEAN, PROP_NONE);
2290 RNA_def_property_boolean_sdna(prop, nullptr, "flag", ARM_DRAWAXES);
2291 RNA_def_property_ui_text(prop, "Display Axes", "Display bone axes");
2292 RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
2294
2295 prop = RNA_def_property(srna, "axes_position", PROP_FLOAT, PROP_FACTOR);
2296 RNA_def_property_float_sdna(prop, nullptr, "axes_position");
2297 RNA_def_property_range(prop, 0.0, 1.0);
2298 RNA_def_property_ui_range(prop, 0.0, 1.0, 10, 1);
2300 "Axes Position",
2301 "The position for the axes on the bone. Increasing the value moves it "
2302 "closer to the tip; decreasing moves it closer to the root.");
2303 RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
2304
2305 RNA_define_verify_sdna(false); /* This property does not live in DNA. */
2306 prop = RNA_def_property(srna, "relation_line_position", PROP_ENUM, PROP_NONE);
2307 RNA_def_property_enum_items(prop, prop_relation_lines_items);
2309 "Relation Line Position",
2310 "The start position of the relation lines from parent to child bones");
2311 RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
2314 "rna_Armature_relation_line_position_get",
2315 "rna_Armature_relation_line_position_set",
2316 nullptr);
2317 RNA_define_verify_sdna(true); /* Restore default. */
2318
2319 prop = RNA_def_property(srna, "show_names", PROP_BOOLEAN, PROP_NONE);
2320 RNA_def_property_boolean_sdna(prop, nullptr, "flag", ARM_DRAWNAMES);
2321 RNA_def_property_ui_text(prop, "Display Names", "Display bone names");
2322 RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
2324
2325 prop = RNA_def_property(srna, "use_mirror_x", PROP_BOOLEAN, PROP_NONE);
2326 RNA_def_property_boolean_sdna(prop, nullptr, "flag", ARM_MIRROR_EDIT);
2328 prop, "X-Axis Mirror", "Apply changes to matching bone on opposite side of X-Axis");
2329 RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
2331
2332 prop = RNA_def_property(srna, "show_bone_custom_shapes", PROP_BOOLEAN, PROP_NONE);
2335 prop, "Display Custom Bone Shapes", "Display bones with their custom shapes");
2336 RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
2337
2338 prop = RNA_def_property(srna, "show_bone_colors", PROP_BOOLEAN, PROP_NONE);
2339 RNA_def_property_boolean_sdna(prop, nullptr, "flag", ARM_COL_CUSTOM);
2340 RNA_def_property_ui_text(prop, "Display Bone Colors", "Display bone colors");
2341 RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
2342
2343 prop = RNA_def_property(srna, "is_editmode", PROP_BOOLEAN, PROP_NONE);
2344 RNA_def_property_boolean_funcs(prop, "rna_Armature_is_editmode_get", nullptr);
2346 RNA_def_property_ui_text(prop, "Is Editmode", "True when used in editmode");
2347
2349}
2350
2352{
2353 StructRNA *srna;
2354 PropertyRNA *prop;
2355
2356 srna = RNA_def_struct(brna, "BoneCollection", nullptr);
2357 RNA_def_struct_ui_text(srna, "BoneCollection", "Bone collection in an Armature data-block");
2358 RNA_def_struct_path_func(srna, "rna_BoneCollection_path");
2359 RNA_def_struct_idprops_func(srna, "rna_BoneCollection_idprops");
2360 RNA_def_struct_system_idprops_func(srna, "rna_BoneCollection_system_idprops");
2361
2362 prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
2363 RNA_def_property_string_sdna(prop, nullptr, "name");
2364 RNA_def_property_ui_text(prop, "Name", "Unique within the Armature");
2365 RNA_def_struct_name_property(srna, prop);
2366 RNA_def_property_string_funcs(prop, nullptr, nullptr, "rna_BoneCollection_name_set");
2368
2369 prop = RNA_def_property(srna, "is_expanded", PROP_BOOLEAN, PROP_NONE);
2372 prop, "Expanded", "This bone collection is expanded in the bone collections tree view");
2375 RNA_def_property_boolean_funcs(prop, nullptr, "rna_BoneCollection_is_expanded_set");
2377
2378 prop = RNA_def_property(srna, "is_visible", PROP_BOOLEAN, PROP_NONE);
2382 prop, "Visible", "Bones in this collection will be visible in pose/object mode");
2385 RNA_def_property_boolean_funcs(prop, nullptr, "rna_BoneCollection_is_visible_set");
2387
2388 prop = RNA_def_property(srna, "is_visible_ancestors", PROP_BOOLEAN, PROP_NONE);
2391 "Ancestors Effectively Visible",
2392 "True when all of the ancestors of this bone collection are marked as "
2393 "visible; always True for root bone collections");
2395
2396 prop = RNA_def_property(srna, "is_visible_effectively", PROP_BOOLEAN, PROP_NONE);
2397 RNA_def_property_boolean_funcs(prop, "rna_BoneCollection_is_visible_effectively_get", nullptr);
2399 prop,
2400 "Effective Visibility",
2401 "Whether this bone collection is effectively visible in the viewport. This is True when "
2402 "this bone collection and all of its ancestors are visible, or when it is marked as "
2403 "'solo'.");
2405
2406 prop = RNA_def_property(srna, "is_solo", PROP_BOOLEAN, PROP_NONE);
2407 RNA_def_property_boolean_sdna(prop, nullptr, "flags", BONE_COLLECTION_SOLO);
2409 prop, "Solo", "Show only this bone collection, and others also marked as 'solo'");
2412 RNA_def_property_boolean_funcs(prop, nullptr, "rna_BoneCollection_is_solo_set");
2414
2415 prop = RNA_def_property(srna, "is_local_override", PROP_BOOLEAN, PROP_NONE);
2418 prop,
2419 "Is Local Override",
2420 "This collection was added via a library override in the current blend file");
2422
2423 prop = RNA_def_property(srna, "is_editable", PROP_BOOLEAN, PROP_NONE);
2424 RNA_def_property_boolean_funcs(prop, "rna_BoneCollection_is_editable_get", nullptr);
2426 "Is Editable",
2427 "This collection is owned by a local Armature, or was added via a "
2428 "library override in the current blend file");
2430
2431 prop = RNA_def_property(srna, "bones", PROP_COLLECTION, PROP_NONE);
2432 RNA_def_property_struct_type(prop, "Bone");
2434 "rna_BoneCollection_bones_begin",
2435 "rna_iterator_listbase_next",
2436 "rna_iterator_listbase_end",
2437 "rna_BoneCollection_bones_get",
2438 nullptr,
2439 nullptr,
2440 nullptr,
2441 nullptr);
2445 "Bones",
2446 "Bones assigned to this bone collection. In armature edit mode this "
2447 "will always return an empty list of bones, as the bone collection "
2448 "memberships are only synchronized when exiting edit mode.");
2449
2450 prop = RNA_def_property(srna, "children", PROP_COLLECTION, PROP_NONE);
2451 RNA_def_property_struct_type(prop, "BoneCollection");
2453 "rna_iterator_bone_collection_children_begin",
2454 "rna_iterator_array_next",
2455 "rna_iterator_array_end",
2456 "rna_iterator_array_dereference_get",
2457 "rna_iterator_bone_collection_children_length",
2458 nullptr, /* TODO */
2459 nullptr, /* TODO */
2460 nullptr);
2463
2464 prop = RNA_def_property(srna, "parent", PROP_POINTER, PROP_NONE);
2465 RNA_def_property_struct_type(prop, "BoneCollection");
2469 prop, "rna_BoneCollection_parent_get", "rna_BoneCollection_parent_set", nullptr, nullptr);
2471 "Parent",
2472 "Parent bone collection. Note that accessing this requires a scan of "
2473 "all the bone collections to find the parent.");
2474
2475 prop = RNA_def_property(srna, "index", PROP_INT, PROP_NONE);
2476 RNA_def_property_int_funcs(prop, "rna_BoneCollection_index_get", nullptr, nullptr);
2480 prop,
2481 "Index",
2482 "Index of this bone collection in the armature.collections_all array. Note that finding "
2483 "this index requires a scan of all the bone collections, so do access this with care.");
2484
2485 prop = RNA_def_property(srna, "child_number", PROP_INT, PROP_NONE);
2488 prop, "rna_BoneCollection_child_number_get", "rna_BoneCollection_child_number_set", nullptr);
2490 prop,
2491 "Child Number",
2492 "Index of this collection into its parent's list of children. Note that finding "
2493 "this index requires a scan of all the bone collections, so do access this with care.");
2494
2496}
2497
2499{
2500 rna_def_bonecolor(brna);
2502 rna_def_armature(brna);
2503 rna_def_bone(brna);
2504 rna_def_edit_bone(brna);
2505}
2506
2507} // namespace blender
2508
2509#endif
Iterators for armatures.
C++ functions to deal with Armature collections (i.e. the successor of bone layers).
Blender kernel action and pose functionality.
#define G_MAIN
#define M_PI
#define STRNCPY_UTF8(dst, src)
#define BLI_STR_UTF8_MULTIPLICATION_SIGN
#define BLT_I18NCONTEXT_ID_ARMATURE
#define ID_IS_LINKED(_id)
Definition DNA_ID.h:697
#define RNA_TRANSLATION_PREC_DEFAULT
Definition RNA_types.hh:272
#define NC_GEOM
Definition WM_types.hh:406
#define ND_DATA
Definition WM_types.hh:552
#define NC_ANIMATION
Definition WM_types.hh:401
#define ND_BONE_COLLECTION
Definition WM_types.hh:515
#define NA_RENAME
Definition WM_types.hh:638
#define ND_BONE_SELECT
Definition WM_types.hh:491
#define NC_OBJECT
Definition WM_types.hh:392
#define ND_ANIMCHAN
Definition WM_types.hh:539
#define NC_SPACE
Definition WM_types.hh:405
#define ND_SPACE_OUTLINER
Definition WM_types.hh:570
#define BLI_assert(a)
#define BLI_assert_msg(a, msg)
btScalar max
Definition scene.h:133
#define offsetof(t, d)
#define FLT_MAX
#define INT_MAX
float length(VecOp< float, D >) RET
ccl_device_inline void copy_v3_v3(ccl_private float *r, const float3 val)
int armature_bonecoll_find_index(const bArmature *armature, const BoneCollection *bcoll)
int armature_bonecoll_child_number_set(bArmature *armature, BoneCollection *bcoll, int new_child_number)
bool armature_bonecoll_is_descendant_of(const bArmature *armature, int potential_parent_index, int potential_descendant_index)
int armature_bonecoll_find_parent_index(const bArmature *armature, int bcoll_index)
int armature_bonecoll_child_number_find(const bArmature *armature, const BoneCollection *bcoll)
int armature_bonecoll_move_to_parent(bArmature *armature, int from_bcoll_index, int to_child_num, int from_parent_index, int to_parent_index)
BMesh Iterators.
void WM_main_add_notifier(uint type, void *reference)
MINLINE void madd_v3_v3v3fl(float r[3], const float a[3], const float b[3], float f)
void RNA_def_property_srna(PropertyRNA *prop, const char *type)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description)
void ANIM_armature_bonecoll_is_expanded_set(BoneCollection *bcoll, bool is_expanded)
static void rna_def_armature_bones(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
char * STRNCPY(char(&dst)[N], const char *src)
void RNA_def_struct_ui_icon(StructRNA *srna, int icon)
void RNA_def_property_string_sdna(PropertyRNA *prop, const char *structname, const char *propname)
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
void RNA_def_property_boolean_bitset_array_sdna(PropertyRNA *prop, const char *structname, const char *propname, const int64_t booleanbit, const int length)
@ RPT_WARNING
Definition BKE_report.hh:40
void RNA_def_property_boolean_negative_sdna(PropertyRNA *prop, const char *structname, const char *propname, int64_t booleanbit)
void RNA_def_property_override_funcs(PropertyRNA *prop, const char *diff, const char *store, const char *apply)
static void rna_def_bone_collection_memberships(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_api_bone(StructRNA *srna)
void RNA_property_update_main(Main *bmain, Scene *scene, PointerRNA *ptr, PropertyRNA *prop)
void RNA_def_property_float_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
void RNA_def_property_pointer_sdna(PropertyRNA *prop, const char *structname, const char *propname)
void RNA_def_property_pointer_funcs(PropertyRNA *prop, const char *get, const char *set, const char *type_fn, const char *poll)
void RNA_def_property_collection_sdna(PropertyRNA *prop, const char *structname, const char *propname, const char *lengthpropname)
void ANIM_armature_bonecoll_active_index_set(bArmature *armature, int bone_collection_index)
static void rna_def_armature(BlenderRNA *brna)
void RNA_def_property_boolean_funcs(PropertyRNA *prop, const char *get, const char *set)
void RNA_def_property_multi_array(PropertyRNA *prop, int dimension, const int length[])
void RNA_def_struct_system_idprops_func(StructRNA *srna, const char *system_idproperties)
BoneCollection * ANIM_armature_bonecoll_new(bArmature *armature, const char *name, int parent_index=-1)
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
@ FUNC_USE_REPORTS
void RNA_define_lib_overridable(const bool make_overridable)
PropertyRNA * RNA_def_pointer(StructOrFunctionRNA *cont_, const char *identifier, const char *type, const char *ui_name, const char *ui_description)
void rna_pointer_create_with_ancestors(const PointerRNA &parent, StructRNA *type, void *data, PointerRNA &r_ptr)
void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
MINLINE int max_ii(int a, int b)
static void rna_def_bone(BlenderRNA *brna)
void RNA_def_armature(BlenderRNA *brna)
@ ARM_DRAW_RELATION_FROM_HEAD
@ LIBOVERRIDE_OP_INSERT_AFTER
Definition DNA_ID.h:200
@ LIBOVERRIDE_OP_REPLACE
Definition DNA_ID.h:188
static void rna_def_bonecolor(BlenderRNA *brna)
void RNA_def_property_enum_bitflag_sdna(PropertyRNA *prop, const char *structname, const char *propname)
void ED_armature_ebone_transform_mirror_update(bArmature *arm, EditBone *ebo, bool check_select)
void RNA_def_property_ui_range(PropertyRNA *prop, double min, double max, double step, int precision)
void RNA_def_property_float_sdna(PropertyRNA *prop, const char *structname, const char *propname)
@ PROPOVERRIDE_LIBRARY_INSERTION
Definition RNA_types.hh:614
@ PROPOVERRIDE_OVERRIDABLE_LIBRARY
Definition RNA_types.hh:588
@ PROPOVERRIDE_IGNORE
Definition RNA_types.hh:609
@ PROPOVERRIDE_NO_COMPARISON
Definition RNA_types.hh:596
void RNA_def_property_float_default(PropertyRNA *prop, float value)
void rna_def_animdata_common(StructRNA *srna)
void ED_armature_bone_rename(Main *bmain, bArmature *arm, const char *oldnamep, const char *newnamep)
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier_c_str, int type, int subtype)
BoneCollection * ANIM_armature_bonecoll_insert_copy_after(bArmature *armature_dst, const bArmature *armature_src, const BoneCollection *anchor_in_dst, const BoneCollection *bcoll_to_copy)
void RNA_api_bonecollection(StructRNA *srna)
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:593
void ANIM_armature_bonecoll_unassign_all(Bone *bone)
void RNA_def_struct_sdna(StructRNA *srna, const char *structname)
void RNA_def_parameter_clear_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item)
void ED_armature_ebone_from_mat4(EditBone *ebone, const float mat[4][4])
@ PROP_BOOLEAN
Definition RNA_types.hh:210
@ PROP_POINTER
Definition RNA_types.hh:215
@ PROP_STRING
Definition RNA_types.hh:213
@ PROP_COLLECTION
Definition RNA_types.hh:216
void RNA_def_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
void RNA_def_property_collection_funcs(PropertyRNA *prop, const char *begin, const char *next, const char *end, const char *get, const char *length, const char *lookupint, const char *lookupstring, const char *assignint)
void RNA_def_property_int_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
void DEG_id_tag_update(ID *id, unsigned int flags)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
BMesh const char void * data
void RNA_def_property_override_flag(PropertyRNA *prop, PropertyOverrideFlag flag)
static void rna_def_bonecollection(BlenderRNA *brna)
void RNA_def_property_boolean_sdna(PropertyRNA *prop, const char *structname, const char *propname, int64_t booleanbit)
void RNA_def_property_range(PropertyRNA *prop, double min, double max)
char char size_t BLI_str_escape(char *__restrict dst, StringRef src, size_t dst_maxncpy) ATTR_NONNULL(1)
unsigned char uint8_t
Definition BKE_text.h:79
void RNA_def_struct_path_func(StructRNA *srna, const char *path)
@ ARM_DRAW_TYPE_ARMATURE_DEFINED
void RNA_def_function_return(FunctionRNA *func, PropertyRNA *ret)
void ED_armature_transform(bArmature *arm, const float mat[4][4], const bool do_props)
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
void ED_armature_ebone_to_mat4(EditBone *ebone, float r_mat[4][4])
void RNA_def_property_enum_funcs(PropertyRNA *prop, const char *get, const char *set, const char *item)
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier_c_str, const char *call)
void ANIM_armature_bonecoll_active_name_set(bArmature *armature, const char *name)
void RNA_def_property_enum_sdna(PropertyRNA *prop, const char *structname, const char *propname)
void RNA_def_property_boolean_default(PropertyRNA *prop, bool value)
void RNA_def_property_translation_context(PropertyRNA *prop, const char *context)
void RNA_def_property_clear_flag(PropertyRNA *prop, PropertyFlag flag)
void RNA_def_struct_idprops_func(StructRNA *srna, const char *idproperties)
MINLINE float normalize_v3(float n[3])
void ED_armature_ebone_remove(bArmature *arm, EditBone *exBone)
void RNA_def_function_flag(FunctionRNA *func, FunctionFlag flag)
const EnumPropertyItem rna_enum_color_palettes_items[]
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
static void rna_def_bone_common(StructRNA *srna, int editbone)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Definition report.cc:191
void RNA_api_armature_edit_bone(StructRNA *srna)
@ BONE_INHERIT_SCALE_NONE_LEGACY
@ BONE_INHERIT_SCALE_FIX_SHEAR
EditBone * ED_armature_ebone_add(bArmature *arm, const char *name)
void rna_def_bone_curved_common(StructRNA *srna, bool is_posebone, bool is_editbone)
void ANIM_armature_bonecoll_active_set(bArmature *armature, BoneCollection *bcoll)
static void rna_def_armature_collections(BlenderRNA *brna, PropertyRNA *cprop)
StructRNA * RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from)
@ ID_RECALC_SYNC_TO_EVAL
Definition DNA_ID.h:1118
ID_Type GS(const char *name)
Definition DNA_ID.h:410
void BKE_pchan_rebuild_bbone_handles(bPose *pose, bke::PChanBone pchanbone)
@ PROP_EDITABLE
Definition RNA_types.hh:376
@ PROP_PROPORTIONAL
Definition RNA_types.hh:419
@ PROP_THICK_WRAP
Definition RNA_types.hh:493
@ PROP_PTR_NO_OWNERSHIP
Definition RNA_types.hh:465
@ PROP_NEVER_NULL
Definition RNA_types.hh:447
@ PROP_ANIMATABLE
Definition RNA_types.hh:389
@ PROP_LIB_EXCEPTION
Definition RNA_types.hh:382
void RNA_def_property_int_sdna(PropertyRNA *prop, const char *structname, const char *propname)
static void rna_def_armature_edit_bones(BlenderRNA *brna, PropertyRNA *cprop)
signed int int32_t
Definition BKE_text.h:78
void RNA_def_property_update(PropertyRNA *prop, int noteflag, const char *func)
PointerRNA RNA_pointer_create_with_parent(const PointerRNA &parent, StructRNA *type, void *data)
void DEG_relations_tag_update(Main *bmain)
void ANIM_armature_bonecoll_name_set(Main &bmain, bArmature *armature, BoneCollection *bcoll, const char *name)
static void rna_def_edit_bone(BlenderRNA *brna)
@ BONE_COLLECTION_OVERRIDE_LIBRARY_LOCAL
@ BONE_COLLECTION_ANCESTORS_VISIBLE
void RNA_def_property_string_funcs(PropertyRNA *prop, const char *get, const char *length, const char *set)
void RNA_define_verify_sdna(bool verify)
bool ANIM_armature_bonecoll_move_to_index(bArmature *armature, int from_index, int to_index)
void ANIM_armature_bonecoll_is_visible_set(bArmature *armature, BoneCollection *bcoll, bool is_visible)
PropertyRNA * RNA_def_float_matrix(StructOrFunctionRNA *cont_, const char *identifier, const int rows, const int columns, const float *default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
@ PROP_FACTOR
Definition RNA_types.hh:308
@ PROP_TRANSLATION
Definition RNA_types.hh:318
@ PROP_MATRIX
Definition RNA_types.hh:322
@ PROP_DISTANCE
Definition RNA_types.hh:313
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
@ PARM_REQUIRED
Definition RNA_types.hh:631
@ PARM_RNAPTR
Definition RNA_types.hh:633
void rna_iterator_listbase_begin(CollectionPropertyIterator *iter, PointerRNA *ptr, ListBase *lb, IteratorSkipFunc skip)
void RNA_def_struct_name_property(StructRNA *srna, PropertyRNA *prop, const bool allow_replace)
bool ANIM_armature_bonecoll_is_visible_effectively(const bArmature *armature, const BoneCollection *bcoll)
bool BKE_id_is_in_global_main(ID *id)
Definition lib_id.cc:2759
void RNA_def_property_array(PropertyRNA *prop, int length)
const int rna_matrix_dimsize_4x4[]
void RNA_def_property_ui_icon(PropertyRNA *prop, int icon, int consecutive)
Bone * BKE_armature_find_bone_name(bArmature *arm, const char *name)
bPoseChannel * BKE_pose_channel_find_name(const bPose *pose, const char *name)
void rna_iterator_array_begin(CollectionPropertyIterator *iter, PointerRNA *ptr, void *data, size_t itemsize, int64_t length, bool free_ptr, IteratorSkipFunc skip)
void ANIM_armature_bonecoll_solo_set(bArmature *armature, BoneCollection *bcoll, bool is_solo)
bool ANIM_armature_bonecoll_is_editable(const bArmature *armature, const BoneCollection *bcoll)
const int rna_matrix_dimsize_3x3[]
#define RNA_DEF_CURVEBONE_UPDATE(prop, is_posebone, is_editbone)
#define min(a, b)
Definition sort.cc:38
ustring name
Definition graph/node.h:178
struct IDProperty * system_properties
ListBaseT< BoneCollectionReference > collections
Bone_Runtime runtime
ListBaseT< BoneCollectionReference > bone_collections
bke::bArmature_Runtime * runtime