Blender  V3.3
rna_armature_api.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2009 Blender Foundation. All rights reserved. */
3 
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <time.h>
12 
13 #include "RNA_define.h"
14 
15 #include "rna_internal.h" /* own include */
16 
17 #ifdef RNA_RUNTIME
18 
19 # include <stddef.h>
20 
21 # include "DNA_armature_types.h"
22 
23 # include "BKE_armature.h"
24 # include "BLI_math_vector.h"
25 
26 static void rna_EditBone_align_roll(EditBone *ebo, float no[3])
27 {
28  ebo->roll = ED_armature_ebone_roll_to_vector(ebo, no, false);
29 }
30 
31 static float rna_Bone_do_envelope(Bone *bone, float vec[3])
32 {
33  float scale = (bone->flag & BONE_MULT_VG_ENV) == BONE_MULT_VG_ENV ? bone->weight : 1.0f;
34  return distfactor_to_bone(vec,
35  bone->arm_head,
36  bone->arm_tail,
37  bone->rad_head * scale,
38  bone->rad_tail * scale,
39  bone->dist * scale);
40 }
41 
42 static void rna_Bone_convert_local_to_pose(Bone *bone,
43  float r_matrix[16],
44  float matrix[16],
45  float matrix_local[16],
46  float parent_matrix[16],
47  float parent_matrix_local[16],
48  bool invert)
49 {
51  float offs_bone[4][4];
52  float(*bone_arm_mat)[4] = (float(*)[4])matrix_local;
53  float(*parent_pose_mat)[4] = (float(*)[4])parent_matrix;
54  float(*parent_arm_mat)[4] = (float(*)[4])parent_matrix_local;
55 
56  if (is_zero_m4(parent_pose_mat) || is_zero_m4(parent_arm_mat)) {
57  /* No parent case. */
59  bone->flag, bone->inherit_scale_mode, bone_arm_mat, NULL, NULL, &bpt);
60  }
61  else {
62  invert_m4_m4(offs_bone, parent_arm_mat);
63  mul_m4_m4m4(offs_bone, offs_bone, bone_arm_mat);
64 
66  bone->flag, bone->inherit_scale_mode, offs_bone, parent_arm_mat, parent_pose_mat, &bpt);
67  }
68 
69  if (invert) {
71  }
72 
73  BKE_bone_parent_transform_apply(&bpt, (float(*)[4])matrix, (float(*)[4])r_matrix);
74 }
75 
76 static void rna_Bone_MatrixFromAxisRoll(float axis[3], float roll, float r_matrix[9])
77 {
78  vec_roll_to_mat3(axis, roll, (float(*)[3])r_matrix);
79 }
80 
81 static void rna_Bone_AxisRollFromMatrix(float matrix[9],
82  float axis_override[3],
83  float r_axis[3],
84  float *r_roll)
85 {
86  float mat[3][3];
87 
88  normalize_m3_m3(mat, (float(*)[3])matrix);
89 
90  if (normalize_v3_v3(r_axis, axis_override) != 0.0f) {
91  mat3_vec_to_roll(mat, r_axis, r_roll);
92  }
93  else {
94  mat3_to_vec_roll(mat, r_axis, r_roll);
95  }
96 }
97 #else
98 
100 {
101  FunctionRNA *func;
102  PropertyRNA *parm;
103 
104  func = RNA_def_function(srna, "align_roll", "rna_EditBone_align_roll");
106  "Align the bone to a local-space roll so the Z axis "
107  "points in the direction of the vector given");
108  parm = RNA_def_float_vector(
109  func, "vector", 3, NULL, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
111 }
112 
114 {
115  PropertyRNA *parm;
116  FunctionRNA *func;
117 
118  func = RNA_def_function(srna, "evaluate_envelope", "rna_Bone_do_envelope");
119  RNA_def_function_ui_description(func, "Calculate bone envelope at given point");
120  parm = RNA_def_float_vector_xyz(func,
121  "point",
122  3,
123  NULL,
124  -FLT_MAX,
125  FLT_MAX,
126  "Point",
127  "Position in 3d space to evaluate",
128  -FLT_MAX,
129  FLT_MAX);
131  /* return value */
132  parm = RNA_def_float(
133  func, "factor", 0, -FLT_MAX, FLT_MAX, "Factor", "Envelope factor", -FLT_MAX, FLT_MAX);
134  RNA_def_function_return(func, parm);
135 
136  func = RNA_def_function(srna, "convert_local_to_pose", "rna_Bone_convert_local_to_pose");
138  "Transform a matrix from Local to Pose space (or back), taking "
139  "into account options like Inherit Scale and Local Location. "
140  "Unlike Object.convert_space, this uses custom rest and pose "
141  "matrices provided by the caller. If the parent matrices are "
142  "omitted, the bone is assumed to have no parent.");
143  parm = RNA_def_property(func, "matrix_return", PROP_FLOAT, PROP_MATRIX);
145  RNA_def_property_ui_text(parm, "", "The transformed matrix");
146  RNA_def_function_output(func, parm);
147  parm = RNA_def_property(func, "matrix", PROP_FLOAT, PROP_MATRIX);
149  RNA_def_property_ui_text(parm, "", "The matrix to transform");
151  parm = RNA_def_property(func, "matrix_local", PROP_FLOAT, PROP_MATRIX);
153  RNA_def_property_ui_text(parm, "", "The custom rest matrix of this bone (Bone.matrix_local)");
155  parm = RNA_def_property(func, "parent_matrix", PROP_FLOAT, PROP_MATRIX);
158  parm, "", "The custom pose matrix of the parent bone (PoseBone.matrix)");
159  parm = RNA_def_property(func, "parent_matrix_local", PROP_FLOAT, PROP_MATRIX);
162  parm, "", "The custom rest matrix of the parent bone (Bone.matrix_local)");
163  parm = RNA_def_boolean(func, "invert", false, "", "Convert from Pose to Local space");
164 
165  /* Conversions between Matrix and Axis + Roll representations. */
166  func = RNA_def_function(srna, "MatrixFromAxisRoll", "rna_Bone_MatrixFromAxisRoll");
167  RNA_def_function_ui_description(func, "Convert the axis + roll representation to a matrix");
169  parm = RNA_def_property(func, "axis", PROP_FLOAT, PROP_XYZ);
170  RNA_def_property_array(parm, 3);
171  RNA_def_property_ui_text(parm, "", "The main axis of the bone (tail - head)");
173  parm = RNA_def_property(func, "roll", PROP_FLOAT, PROP_NONE);
174  RNA_def_property_ui_text(parm, "", "The roll of the bone");
176  parm = RNA_def_property(func, "result_matrix", PROP_FLOAT, PROP_MATRIX);
178  RNA_def_property_ui_text(parm, "", "The resulting orientation matrix");
179  RNA_def_function_output(func, parm);
180 
181  func = RNA_def_function(srna, "AxisRollFromMatrix", "rna_Bone_AxisRollFromMatrix");
183  "Convert a rotational matrix to the axis + roll representation. "
184  "Note that the resulting value of the roll may not be as "
185  "expected if the matrix has shear or negative determinant.");
187  parm = RNA_def_property(func, "matrix", PROP_FLOAT, PROP_MATRIX);
189  RNA_def_property_ui_text(parm, "", "The orientation matrix of the bone");
191  parm = RNA_def_property(func, "axis", PROP_FLOAT, PROP_MATRIX);
192  RNA_def_property_array(parm, 3);
194  parm, "", "The optional override for the axis (finds closest approximation for the matrix)");
195  parm = RNA_def_property(func, "result_axis", PROP_FLOAT, PROP_XYZ);
196  RNA_def_property_array(parm, 3);
197  RNA_def_property_ui_text(parm, "", "The main axis of the bone");
198  RNA_def_function_output(func, parm);
199  parm = RNA_def_property(func, "result_roll", PROP_FLOAT, PROP_NONE);
200  RNA_def_property_ui_text(parm, "", "The roll of the bone");
201  RNA_def_function_output(func, parm);
202 }
203 
204 #endif
typedef float(TangentPoint)[2]
void mat3_vec_to_roll(const float mat[3][3], const float vec[3], float *r_roll)
Definition: armature.c:2067
float distfactor_to_bone(const float vec[3], const float b1[3], const float b2[3], float rad1, float rad2, float rdist)
void BKE_bone_parent_transform_invert(struct BoneParentTransform *bpt)
Definition: armature.c:1820
void vec_roll_to_mat3(const float vec[3], float roll, float r_mat[3][3])
Definition: armature.c:2211
void mat3_to_vec_roll(const float mat[3][3], float r_vec[3], float *r_roll)
Definition: armature.c:2056
void BKE_bone_parent_transform_calc_from_matrices(int bone_flag, int inherit_scale_mode, const float offs_bone[4][4], const float parent_arm_mat[4][4], const float parent_pose_mat[4][4], struct BoneParentTransform *r_bpt)
Definition: armature.c:1668
void BKE_bone_parent_transform_apply(const struct BoneParentTransform *bpt, const float inmat[4][4], float outmat[4][4])
Definition: armature.c:1836
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
Definition: math_matrix.c:259
void normalize_m3_m3(float R[3][3], const float M[3][3]) ATTR_NONNULL()
Definition: math_matrix.c:1927
bool invert_m4_m4(float R[4][4], const float A[4][4])
Definition: math_matrix.c:1287
bool is_zero_m4(const float mat[4][4])
Definition: math_matrix.c:2520
MINLINE float normalize_v3_v3(float r[3], const float a[3])
@ BONE_MULT_VG_ENV
@ PARM_REQUIRED
Definition: RNA_types.h:352
@ FUNC_NO_SELF
Definition: RNA_types.h:656
@ PROP_FLOAT
Definition: RNA_types.h:61
@ PROP_NEVER_NULL
Definition: RNA_types.h:239
@ PROP_MATRIX
Definition: RNA_types.h:158
@ PROP_XYZ
Definition: RNA_types.h:162
@ PROP_NONE
Definition: RNA_types.h:126
float ED_armature_ebone_roll_to_vector(const EditBone *bone, const float align_axis[3], const bool axis_only)
CCL_NAMESPACE_BEGIN ccl_device float invert(float color, float factor)
Definition: invert.h:8
void RNA_api_armature_edit_bone(StructRNA *srna)
void RNA_api_bone(StructRNA *srna)
PropertyRNA * RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, float default_value, float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
Definition: rna_define.c:3836
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, bool default_value, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3493
void RNA_def_function_return(FunctionRNA *func, PropertyRNA *ret)
Definition: rna_define.c:4312
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
Definition: rna_define.c:1645
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier, const char *call)
Definition: rna_define.c:4273
void RNA_def_function_output(FunctionRNA *UNUSED(func), PropertyRNA *ret)
Definition: rna_define.c:4337
void RNA_def_property_multi_array(PropertyRNA *prop, int dimension, const int length[])
Definition: rna_define.c:1598
PropertyRNA * RNA_def_float_vector(StructOrFunctionRNA *cont_, const char *identifier, int len, const float *default_value, float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
Definition: rna_define.c:3862
void RNA_def_property_array(PropertyRNA *prop, int length)
Definition: rna_define.c:1539
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
Definition: rna_define.c:4347
const int rna_matrix_dimsize_4x4[]
Definition: rna_define.c:1595
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
Definition: rna_define.c:1257
void RNA_def_function_flag(FunctionRNA *func, int flag)
Definition: rna_define.c:4342
const int rna_matrix_dimsize_3x3[]
Definition: rna_define.c:1594
PropertyRNA * RNA_def_float_vector_xyz(StructOrFunctionRNA *cont_, const char *identifier, int len, const float *default_value, float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
Definition: rna_define.c:3894
void RNA_def_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
Definition: rna_define.c:1518
float arm_head[3]
float arm_tail[3]
char inherit_scale_mode
float rad_head
float rad_tail
float dist
float weight
float roll
Definition: BKE_armature.h:50