Blender  V2.93
rna_armature_api.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2009 Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <time.h>
28 
29 #include "RNA_define.h"
30 
31 #include "rna_internal.h" /* own include */
32 
33 #ifdef RNA_RUNTIME
34 
35 # include <stddef.h>
36 
37 # include "DNA_armature_types.h"
38 
39 # include "BKE_armature.h"
40 # include "BLI_math_vector.h"
41 
42 static void rna_EditBone_align_roll(EditBone *ebo, float no[3])
43 {
44  ebo->roll = ED_armature_ebone_roll_to_vector(ebo, no, false);
45 }
46 
47 static float rna_Bone_do_envelope(Bone *bone, float *vec)
48 {
49  float scale = (bone->flag & BONE_MULT_VG_ENV) == BONE_MULT_VG_ENV ? bone->weight : 1.0f;
50  return distfactor_to_bone(vec,
51  bone->arm_head,
52  bone->arm_tail,
53  bone->rad_head * scale,
54  bone->rad_tail * scale,
55  bone->dist * scale);
56 }
57 
58 static void rna_Bone_convert_local_to_pose(Bone *bone,
59  float *r_matrix,
60  float *matrix,
61  float *matrix_local,
62  float *parent_matrix,
63  float *parent_matrix_local,
64  bool invert)
65 {
67  float offs_bone[4][4];
68  float(*bone_arm_mat)[4] = (float(*)[4])matrix_local;
69  float(*parent_pose_mat)[4] = (float(*)[4])parent_matrix;
70  float(*parent_arm_mat)[4] = (float(*)[4])parent_matrix_local;
71 
72  if (is_zero_m4(parent_pose_mat) || is_zero_m4(parent_arm_mat)) {
73  /* No parent case. */
75  bone->flag, bone->inherit_scale_mode, bone_arm_mat, NULL, NULL, &bpt);
76  }
77  else {
78  invert_m4_m4(offs_bone, parent_arm_mat);
79  mul_m4_m4m4(offs_bone, offs_bone, bone_arm_mat);
80 
82  bone->flag, bone->inherit_scale_mode, offs_bone, parent_arm_mat, parent_pose_mat, &bpt);
83  }
84 
85  if (invert) {
87  }
88 
89  BKE_bone_parent_transform_apply(&bpt, (float(*)[4])matrix, (float(*)[4])r_matrix);
90 }
91 
92 static void rna_Bone_MatrixFromAxisRoll(float *axis, float roll, float *r_matrix)
93 {
94  vec_roll_to_mat3(axis, roll, (float(*)[3])r_matrix);
95 }
96 
97 static void rna_Bone_AxisRollFromMatrix(float *matrix,
98  float *axis_override,
99  float *r_axis,
100  float *r_roll)
101 {
102  float mat[3][3];
103 
104  normalize_m3_m3(mat, (float(*)[3])matrix);
105 
106  if (normalize_v3_v3(r_axis, axis_override) != 0.0f) {
107  mat3_vec_to_roll(mat, r_axis, r_roll);
108  }
109  else {
110  mat3_to_vec_roll(mat, r_axis, r_roll);
111  }
112 }
113 #else
114 
116 {
117  FunctionRNA *func;
118  PropertyRNA *parm;
119 
120  func = RNA_def_function(srna, "align_roll", "rna_EditBone_align_roll");
122  "Align the bone to a localspace roll so the Z axis "
123  "points in the direction of the vector given");
124  parm = RNA_def_float_vector(
125  func, "vector", 3, NULL, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
127 }
128 
130 {
131  PropertyRNA *parm;
132  FunctionRNA *func;
133 
134  func = RNA_def_function(srna, "evaluate_envelope", "rna_Bone_do_envelope");
135  RNA_def_function_ui_description(func, "Calculate bone envelope at given point");
136  parm = RNA_def_float_vector_xyz(func,
137  "point",
138  3,
139  NULL,
140  -FLT_MAX,
141  FLT_MAX,
142  "Point",
143  "Position in 3d space to evaluate",
144  -FLT_MAX,
145  FLT_MAX);
147  /* return value */
148  parm = RNA_def_float(
149  func, "factor", 0, -FLT_MAX, FLT_MAX, "Factor", "Envelope factor", -FLT_MAX, FLT_MAX);
150  RNA_def_function_return(func, parm);
151 
152  func = RNA_def_function(srna, "convert_local_to_pose", "rna_Bone_convert_local_to_pose");
154  "Transform a matrix from Local to Pose space (or back), taking "
155  "into account options like Inherit Scale and Local Location. "
156  "Unlike Object.convert_space, this uses custom rest and pose "
157  "matrices provided by the caller. If the parent matrices are "
158  "omitted, the bone is assumed to have no parent.");
159  parm = RNA_def_property(func, "matrix_return", PROP_FLOAT, PROP_MATRIX);
161  RNA_def_property_ui_text(parm, "", "The transformed matrix");
162  RNA_def_function_output(func, parm);
163  parm = RNA_def_property(func, "matrix", PROP_FLOAT, PROP_MATRIX);
165  RNA_def_property_ui_text(parm, "", "The matrix to transform");
167  parm = RNA_def_property(func, "matrix_local", PROP_FLOAT, PROP_MATRIX);
169  RNA_def_property_ui_text(parm, "", "The custom rest matrix of this bone (Bone.matrix_local)");
171  parm = RNA_def_property(func, "parent_matrix", PROP_FLOAT, PROP_MATRIX);
174  parm, "", "The custom pose matrix of the parent bone (PoseBone.matrix)");
175  parm = RNA_def_property(func, "parent_matrix_local", PROP_FLOAT, PROP_MATRIX);
178  parm, "", "The custom rest matrix of the parent bone (Bone.matrix_local)");
179  parm = RNA_def_boolean(func, "invert", false, "", "Convert from Pose to Local space");
180 
181  /* Conversions between Matrix and Axis + Roll representations. */
182  func = RNA_def_function(srna, "MatrixFromAxisRoll", "rna_Bone_MatrixFromAxisRoll");
183  RNA_def_function_ui_description(func, "Convert the axis + roll representation to a matrix");
185  parm = RNA_def_property(func, "axis", PROP_FLOAT, PROP_XYZ);
186  RNA_def_property_array(parm, 3);
187  RNA_def_property_ui_text(parm, "", "The main axis of the bone (tail - head)");
189  parm = RNA_def_property(func, "roll", PROP_FLOAT, PROP_NONE);
190  RNA_def_property_ui_text(parm, "", "The roll of the bone");
192  parm = RNA_def_property(func, "result_matrix", PROP_FLOAT, PROP_MATRIX);
194  RNA_def_property_ui_text(parm, "", "The resulting orientation matrix");
195  RNA_def_function_output(func, parm);
196 
197  func = RNA_def_function(srna, "AxisRollFromMatrix", "rna_Bone_AxisRollFromMatrix");
199  "Convert a rotational matrix to the axis + roll representation. "
200  "Note that the resulting value of the roll may not be as "
201  "expected if the matrix has shear or negative determinant.");
203  parm = RNA_def_property(func, "matrix", PROP_FLOAT, PROP_MATRIX);
205  RNA_def_property_ui_text(parm, "", "The orientation matrix of the bone");
207  parm = RNA_def_property(func, "axis", PROP_FLOAT, PROP_MATRIX);
208  RNA_def_property_array(parm, 3);
210  parm, "", "The optional override for the axis (finds closest approximation for the matrix)");
211  parm = RNA_def_property(func, "result_axis", PROP_FLOAT, PROP_XYZ);
212  RNA_def_property_array(parm, 3);
213  RNA_def_property_ui_text(parm, "", "The main axis of the bone");
214  RNA_def_function_output(func, parm);
215  parm = RNA_def_property(func, "result_roll", PROP_FLOAT, PROP_NONE);
216  RNA_def_property_ui_text(parm, "", "The roll of the bone");
217  RNA_def_function_output(func, parm);
218 }
219 
220 #endif
typedef float(TangentPoint)[2]
void vec_roll_to_mat3(const float vec[3], const float roll, float r_mat[3][3])
Definition: armature.c:2212
void mat3_vec_to_roll(const float mat[3][3], const float vec[3], float *r_roll)
Definition: armature.c:2072
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:1796
void mat3_to_vec_roll(const float mat[3][3], float r_vec[3], float *r_roll)
Definition: armature.c:2059
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:1644
void BKE_bone_parent_transform_apply(const struct BoneParentTransform *bpt, const float inmat[4][4], float outmat[4][4])
Definition: armature.c:1812
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
Definition: math_matrix.c:262
void normalize_m3_m3(float R[3][3], const float M[3][3]) ATTR_NONNULL()
Definition: math_matrix.c:1934
bool invert_m4_m4(float R[4][4], const float A[4][4])
Definition: math_matrix.c:1278
bool is_zero_m4(const float mat[4][4])
Definition: math_matrix.c:2601
MINLINE float normalize_v3_v3(float r[3], const float a[3])
@ BONE_MULT_VG_ENV
@ PARM_REQUIRED
Definition: RNA_types.h:337
@ FUNC_NO_SELF
Definition: RNA_types.h:571
@ PROP_FLOAT
Definition: RNA_types.h:75
@ PROP_NEVER_NULL
Definition: RNA_types.h:225
@ PROP_MATRIX
Definition: RNA_types.h:144
@ PROP_XYZ
Definition: RNA_types.h:148
@ PROP_NONE
Definition: RNA_types.h:113
float ED_armature_ebone_roll_to_vector(const EditBone *bone, const float align_axis[3], const bool axis_only)
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:3825
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, bool default_value, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3481
void RNA_def_function_return(FunctionRNA *func, PropertyRNA *ret)
Definition: rna_define.c:4302
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
Definition: rna_define.c:1676
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier, const char *call)
Definition: rna_define.c:4262
void RNA_def_function_output(FunctionRNA *UNUSED(func), PropertyRNA *ret)
Definition: rna_define.c:4327
void RNA_def_property_multi_array(PropertyRNA *prop, int dimension, const int length[])
Definition: rna_define.c:1629
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:3851
void RNA_def_property_array(PropertyRNA *prop, int length)
Definition: rna_define.c:1568
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
Definition: rna_define.c:4337
const int rna_matrix_dimsize_4x4[]
Definition: rna_define.c:1626
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
Definition: rna_define.c:1279
void RNA_def_function_flag(FunctionRNA *func, int flag)
Definition: rna_define.c:4332
const int rna_matrix_dimsize_3x3[]
Definition: rna_define.c:1625
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:3883
void RNA_def_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
Definition: rna_define.c:1547
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:62
CCL_NAMESPACE_BEGIN ccl_device float invert(float color, float factor)
Definition: svm_invert.h:19