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