Blender V4.3
anim_rna.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
9#include "ANIM_rna.hh"
10#include "BLI_vector.hh"
11#include "DNA_action_types.h"
12#include "RNA_access.hh"
13
14namespace blender::animrig {
15
17{
18 Vector<float> values;
19 if (RNA_property_array_check(prop)) {
20 const int length = RNA_property_array_length(ptr, prop);
21
22 switch (RNA_property_type(prop)) {
23 case PROP_BOOLEAN: {
24 bool *tmp_bool = static_cast<bool *>(MEM_malloc_arrayN(length, sizeof(bool), __func__));
25 RNA_property_boolean_get_array(ptr, prop, tmp_bool);
26 for (int i = 0; i < length; i++) {
27 values.append(float(tmp_bool[i]));
28 }
29 MEM_freeN(tmp_bool);
30 break;
31 }
32 case PROP_INT: {
33 int *tmp_int = static_cast<int *>(MEM_malloc_arrayN(length, sizeof(int), __func__));
34 RNA_property_int_get_array(ptr, prop, tmp_int);
35 for (int i = 0; i < length; i++) {
36 values.append(float(tmp_int[i]));
37 }
38 MEM_freeN(tmp_int);
39 break;
40 }
41 case PROP_FLOAT: {
42 values.reinitialize(length);
43 RNA_property_float_get_array(ptr, prop, &values[0]);
44 break;
45 }
46 default:
47 values.reinitialize(length);
48 break;
49 }
50 }
51 else {
52 switch (RNA_property_type(prop)) {
53 case PROP_BOOLEAN:
54 values.append(float(RNA_property_boolean_get(ptr, prop)));
55 break;
56 case PROP_INT:
57 values.append(float(RNA_property_int_get(ptr, prop)));
58 break;
59 case PROP_FLOAT:
60 values.append(RNA_property_float_get(ptr, prop));
61 break;
62 case PROP_ENUM:
63 values.append(float(RNA_property_enum_get(ptr, prop)));
64 break;
65 default:
66 values.append(0.0f);
67 }
68 }
69
70 return values;
71}
72
74{
75 switch (rotation_mode) {
76 case ROT_MODE_QUAT:
77 return "rotation_quaternion";
79 return "rotation_axis_angle";
80 default:
81 return "rotation_euler";
82 }
83}
84} // namespace blender::animrig
Helper functions for animation to interact with the RNA system.
eRotationModes
@ ROT_MODE_QUAT
@ ROT_MODE_AXISANGLE
@ PROP_FLOAT
Definition RNA_types.hh:67
@ PROP_BOOLEAN
Definition RNA_types.hh:65
@ PROP_ENUM
Definition RNA_types.hh:69
@ PROP_INT
Definition RNA_types.hh:66
SIMD_FORCE_INLINE btScalar length() const
Return the length of the vector.
Definition btVector3.h:257
void *(* MEM_malloc_arrayN)(size_t len, size_t size, const char *str)
Definition mallocn.cc:45
void MEM_freeN(void *vmemh)
Definition mallocn.cc:105
Vector< float > get_rna_values(PointerRNA *ptr, PropertyRNA *prop)
Definition anim_rna.cc:16
StringRef get_rotation_mode_path(eRotationModes rotation_mode)
Definition anim_rna.cc:73
float RNA_property_float_get(PointerRNA *ptr, PropertyRNA *prop)
bool RNA_property_array_check(PropertyRNA *prop)
void RNA_property_float_get_array(PointerRNA *ptr, PropertyRNA *prop, float *values)
void RNA_property_boolean_get_array(PointerRNA *ptr, PropertyRNA *prop, bool *values)
PropertyType RNA_property_type(PropertyRNA *prop)
bool RNA_property_boolean_get(PointerRNA *ptr, PropertyRNA *prop)
int RNA_property_int_get(PointerRNA *ptr, PropertyRNA *prop)
int RNA_property_array_length(PointerRNA *ptr, PropertyRNA *prop)
int RNA_property_enum_get(PointerRNA *ptr, PropertyRNA *prop)
void RNA_property_int_get_array(PointerRNA *ptr, PropertyRNA *prop, int *values)
PointerRNA * ptr
Definition wm_files.cc:4126