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.
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.
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.
16 * The Original Code is Copyright (C) 2009 Blender Foundation.
17 * All rights reserved.
29 #include "BLI_utildefines.h"
31 #include "RNA_define.h"
33 #include "DNA_object_types.h"
35 /* #include "BLI_sys_types.h" */
37 #include "rna_internal.h" /* own include */
41 /* #include "DNA_anim_types.h" */
42 # include "BKE_armature.h"
43 # include "DNA_action_types.h" /* bPose */
45 static float rna_PoseBone_do_envelope(bPoseChannel *chan, float *vec)
47 Bone *bone = chan->bone;
49 float scale = (bone->flag & BONE_MULT_VG_ENV) == BONE_MULT_VG_ENV ? bone->weight : 1.0f;
51 return distfactor_to_bone(vec,
54 bone->rad_head * scale,
55 bone->rad_tail * scale,
59 static void rna_PoseBone_bbone_segment_matrix(
60 bPoseChannel *pchan, ReportList *reports, float mat_ret[16], int index, bool rest)
62 if (!pchan->bone || pchan->bone->segments <= 1) {
63 BKE_reportf(reports, RPT_ERROR, "Bone '%s' is not a B-Bone!", pchan->name);
66 if (pchan->runtime.bbone_segments != pchan->bone->segments) {
67 BKE_reportf(reports, RPT_ERROR, "Bone '%s' has out of date B-Bone segment data!", pchan->name);
70 if (index < 0 || index > pchan->runtime.bbone_segments) {
72 reports, RPT_ERROR, "Invalid index %d for B-Bone segments of '%s'!", index, pchan->name);
77 copy_m4_m4((float(*)[4])mat_ret, pchan->runtime.bbone_rest_mats[index].mat);
80 copy_m4_m4((float(*)[4])mat_ret, pchan->runtime.bbone_pose_mats[index].mat);
84 static void rna_PoseBone_compute_bbone_handles(bPoseChannel *pchan,
94 if (!pchan->bone || pchan->bone->segments <= 1) {
95 BKE_reportf(reports, RPT_ERROR, "Bone '%s' is not a B-Bone!", pchan->name);
99 BBoneSplineParameters params;
101 BKE_pchan_bbone_spline_params_get(pchan, rest, ¶ms);
102 BKE_pchan_bbone_handles_compute(
103 ¶ms, ret_h1, ret_roll1, ret_h2, ret_roll2, ease || offsets, offsets);
107 void RNA_api_pose(StructRNA *UNUSED(srna))
109 /* FunctionRNA *func; */
110 /* PropertyRNA *parm; */
113 void RNA_api_pose_channel(StructRNA *srna)
118 func = RNA_def_function(srna, "evaluate_envelope", "rna_PoseBone_do_envelope");
119 RNA_def_function_ui_description(func, "Calculate bone envelope at given point");
120 parm = RNA_def_float_vector_xyz(func,
127 "Position in 3d space to evaluate",
130 RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
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);
136 /* B-Bone segment matrices */
137 func = RNA_def_function(srna, "bbone_segment_matrix", "rna_PoseBone_bbone_segment_matrix");
138 RNA_def_function_ui_description(
139 func, "Retrieve the matrix of the joint between B-Bone segments if available");
140 RNA_def_function_flag(func, FUNC_USE_REPORTS);
141 parm = RNA_def_property(func, "matrix_return", PROP_FLOAT, PROP_MATRIX);
142 RNA_def_property_multi_array(parm, 2, rna_matrix_dimsize_4x4);
143 RNA_def_property_ui_text(parm, "", "The resulting matrix in bone local space");
144 RNA_def_function_output(func, parm);
145 parm = RNA_def_int(func, "index", 0, 0, INT_MAX, "", "Index of the segment endpoint", 0, 10000);
146 RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
147 parm = RNA_def_boolean(func, "rest", false, "", "Return the rest pose matrix");
149 /* B-Bone custom handle positions */
150 func = RNA_def_function(srna, "compute_bbone_handles", "rna_PoseBone_compute_bbone_handles");
151 RNA_def_function_ui_description(
152 func, "Retrieve the vectors and rolls coming from B-Bone custom handles");
153 RNA_def_function_flag(func, FUNC_USE_REPORTS);
154 parm = RNA_def_property(func, "handle1", PROP_FLOAT, PROP_XYZ);
155 RNA_def_property_array(parm, 3);
156 RNA_def_property_ui_text(
157 parm, "", "The direction vector of the start handle in bone local space");
158 RNA_def_function_output(func, parm);
159 parm = RNA_def_float(
160 func, "roll1", 0, -FLT_MAX, FLT_MAX, "", "Roll of the start handle", -FLT_MAX, FLT_MAX);
161 RNA_def_function_output(func, parm);
162 parm = RNA_def_property(func, "handle2", PROP_FLOAT, PROP_XYZ);
163 RNA_def_property_array(parm, 3);
164 RNA_def_property_ui_text(parm, "", "The direction vector of the end handle in bone local space");
165 RNA_def_function_output(func, parm);
166 parm = RNA_def_float(
167 func, "roll2", 0, -FLT_MAX, FLT_MAX, "", "Roll of the end handle", -FLT_MAX, FLT_MAX);
168 RNA_def_function_output(func, parm);
169 parm = RNA_def_boolean(func, "rest", false, "", "Return the rest pose state");
170 parm = RNA_def_boolean(func, "ease", false, "", "Apply scale from ease values");
171 parm = RNA_def_boolean(
172 func, "offsets", false, "", "Apply roll and curve offsets from bone properties");