16#if defined(__GNUC__) && !defined(__clang__)
17# pragma GCC diagnostic push
18# pragma GCC diagnostic ignored "-Wdeprecated-copy"
33#if defined(__GNUC__) && !defined(__clang__)
34# pragma GCC diagnostic pop
63#define ANIM_FEEDBACK 0.8
228 bPoseChannel *curchan, *pchan_root =
nullptr, *chanlist[256], **oldchan;
232 int a, t, segcount = 0, size, newsize, *oldparent, parent, rootbone, treecount;
238 pchan_tip = pchan_tip->
parent;
241 rootbone =
data->rootbone;
243 for (curchan = pchan_tip; curchan; curchan = curchan->
parent) {
244 pchan_root = curchan;
246 if (++segcount > 255) {
250 if (segcount == rootbone) {
260 if (curchan->
iktree.is_empty() ==
false) {
276 for (rootbone = segcount, segcount = 0, curchan = pchan_tip; segcount < rootbone;
277 segcount++, curchan = curchan->
parent)
279 chanlist[segcount] = curchan;
289 tree = pchan_root->
iktree.first();
291 if (tree ==
nullptr) {
301 for (a = 0; a < segcount; a++) {
302 tree->
pchan[a] = chanlist[segcount - a - 1];
305 target->
tip = segcount - 1;
319 while (a < size && t < tree->totchannel) {
321 for (; t < tree->
totchannel && tree->
pchan[t] != chanlist[segcount - a - 1]; t++) {
327 for (; a < size && t < tree->
totchannel && tree->
pchan[t] == chanlist[segcount - a - 1];
334 segcount = segcount - a;
338 for (parent = a - 1; parent < tree->
totchannel; parent++) {
339 if (tree->
pchan[parent] == chanlist[segcount - 1]->
parent) {
351 oldchan = tree->
pchan;
359 MEM_delete(oldparent);
362 for (a = 0; a < segcount; a++) {
400 if (
data->tar ==
nullptr) {
426 if (
pose->runtime->ikdata) {
427 return static_cast<IK_Data *
>(
pose->runtime->ikdata);
436 return static_cast<IK_Data *
>(
pose->runtime->ikdata);
466 double qy =
R(0, 2) -
R(2, 0);
467 double qw =
R(0, 0) +
R(1, 1) +
R(2, 2) + 1;
510static void GetEulerXYZ(
const KDL::Rotation &
R,
double &
X,
double &
Y,
double &
Z)
685 double q_rest[3], q[3],
length;
709 polerot.
UnitZ(-poledir);
776 for (i = 0, error = 0.0, value = values->
values; i < values->number; i++, value++) {
784 for (i = 0, error = 0.0, value = values->
values; i < values->number; i++, value++) {
812 switch (condata->
mode) {
825 switch (condata->
mode) {
928 for (
uint i = 0; i < _nvalues; i++, dof++) {
945 for (a = 0, ikchan = ikscene->
channels; a < ikscene->numchan; a++, ikchan++) {
946 pchan = tree->
pchan[a];
947 ikchan->
pchan = pchan;
1062 njoint += ikchan->
ndof;
1086 for (joint = a = 0, ikchan = ikscene->
channels;
1087 a < ikscene->numchan && joint < ikscene->numjoint;
1090 pchan = ikchan->
pchan;
1091 bone = pchan->bone_get(*ikscene->
blArmature);
1110 joint += ikchan->
ndof;
1130 for (joint = a = 0, ikchan = ikscene->
channels;
1131 a < ikscene->numchan && joint < ikscene->numjoint;
1134 pchan = ikchan->
pchan;
1135 bone = pchan->bone_get(*ikscene->
blArmature);
1141 joint += ikchan->
ndof;
1178 ikscene->
scene = scene;
1191 switch (ikparam->
solver) {
1208 std::string root(
"root");
1210 std::vector<double> weights;
1218 for (a = 0, ikchan = ikscene->
channels; a < tree->totchannel; a++, ikchan++) {
1219 pchan = ikchan->
pchan;
1220 bone = pchan->bone_get(*ob);
1226 fl[0][0], fl[1][0], fl[2][0], fl[0][1], fl[1][1], fl[2][1], fl[0][2], fl[1][2], fl[2][2]);
1231 float R_parmat[3][3];
1232 float iR_parmat[3][3];
1243 start[0] = start[1] = start[2] = 0.0f;
1271 weight[0] = (1.0 - pchan->
stiffness[0]);
1272 weight[1] = (1.0 - pchan->
stiffness[1]);
1273 weight[2] = (1.0 - pchan->
stiffness[2]);
1284 weights.push_back(weight[0]);
1290 weights.push_back(weight[1]);
1296 weights.push_back(weight[2]);
1301 weights.push_back(weight[0]);
1307 weights.push_back(weight[1]);
1313 weights.push_back(weight[0]);
1314 weights.push_back(weight[2]);
1320 weights.push_back(weight[2]);
1326 weights.push_back(weight[1]);
1333 weights.push_back(weight[0]);
1334 weights.push_back(weight[2]);
1340 weights.push_back(weight[1]);
1346 weights.push_back(weight[0]);
1347 weights.push_back(weight[1]);
1348 weights.push_back(weight[2]);
1358 weight[1] = (1.0 -
min_ff(1.0 - ikstretch, 1.0f - 0.001f));
1359 weights.push_back(weight[1]);
1366 ikchan->
tail = joint;
1367 ikchan->
head = parent;
1449 for (numtarget = 0, polarcon =
nullptr,
ret =
true, target = tree->
targets.first(); target;
1450 target = target->
next)
1458 ikscene->
targets.push_back(iktarget);
1460 if (iktarget->
ee == -1) {
1465 const Bone *bone = pchan->bone_get(*ob);
1470 iktarget->
owner = ob;
1480 polarcon = target->
con;
1485 if (numtarget == 1 && polarcon) {
1494 std::string armname;
1509 assert(Wq.cols() ==
int(weights.size()));
1510 for (
int q = 0; q < Wq.cols(); q++) {
1511 Wq(q, q) = weights[q];
1517 float invBaseFrame[4][4];
1521 float baseFrame[4][4];
1523 const Bone *bone = pchan->bone_get(*ob);
1533 for (t = 0; t < ikscene->
targets.size(); t++) {
1539 uint controltype, bone_count;
1545 for (bone_count = 0, bone_length = 0.0f, a = iktarget->
channel; a >= 0;
1546 a = tree->
parent[a], bone_count++)
1549 const Bone *bone = pchan->bone_get(*ob);
1552 bone_length /= bone_count;
1555 const Bone *bone = pchan->bone_get(*ob);
1572 switch (condata->
type) {
1670 ikdata->
first = ikscene;
1675 tree->
targets.free_no_destruct();
1677 MEM_delete(tree->
pchan);
1680 MEM_delete(tree->
parent);
1696 float scale =
len_v3(ob->object_to_world().ptr()[1]);
1701 scene = scene->
next)
1722 for (i = 0, ikchan = ikscene->
channels; i < ikscene->numchan; i++, ikchan++) {
1732 for (i = 0, ikchan = ikscene->
channels; i < ikscene->numchan; i++, ikchan++) {
1744 for (i = ikscene->
targets.size(); i > 0; i--) {
1756 double timestamp = ctime * frtime + 2147483.648;
1757 double timestep = frtime;
1760 bool simulation =
true;
1779 if (ikscene->
cache && !reiterate && simulation) {
1791 timestep = sts / 1000.0;
1795 ikscene->
scene->
update(timestamp, timestep, numstep,
false, !reiterate, simulation);
1798 for (i = 0; i < ikparam->
numiter; i++) {
1804 ikscene->
scene->
update(timestamp, timestep, numstep,
true,
false, simulation);
1808 ikscene->
scene->
update(timestamp, 0.0, 1,
true,
true,
true);
1812 for (i = ikscene->
targets.size(); i > 0; i--) {
1829 double q_rest[3], q[3];
1836 for (i = 0, ikchan = ikscene->
channels; i < ikscene->numchan; i++, ikchan++) {
1853 if (!arm->
getSegment(ikchan->
tail, 3, joint, q_rest[0], q[0], tip)) {
1868 pchan = ikchan->
pchan;
1886 if (i < ikscene->numchan) {
1935 if (ikscene->channels[0].pchan == pchan_root) {
1937 execute_scene(depsgraph, scene, ikscene, ikparam, ctime, timestep);
1951 if (
pose->runtime->ikdata) {
1958 pose->runtime->ikdata =
nullptr;
1964 if (
pose->runtime->ikdata) {
1969 scene->cache->clearCacheFrom(
nullptr, 1);
1977 if (
pose->runtime->ikdata &&
pose->ikparam) {
1981 double armlength = ikscene->armature->getArmLength();
1988 ikscene->armature->setControlParameter(
1997 ikscene->armature->setControlParameter(
2013 switch (
data->type) {
Blender kernel action and pose functionality.
#define mul_m4_series(...)
#define CONSTRAINT_ID_ALL
Object is a sort of wrapper for general info.
Read Blender memory allocation and freeing.
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
represents a frame transformation in 3D space (rotation + translation)
Rotation M
Orientation of the Frame.
void setValue(float *oglmat)
void getValue(float *oglmat) const
Vector p
origine of the Frame
void resize(unsigned int newSize)
This class encapsulates a simple joint, that is with one parameterized degree of freedom and with sca...
const JointType & getType() const
represents rotations in 3 dimensional space.
Vector GetRot() const
Returns a vector with the direction of the equiv. axis and its norm is angle.
Rotation Inverse() const
Gives back the inverse rotation matrix of *this.
Vector UnitY() const
Access to the underlying unitvectors of the rotation matrix.
Vector UnitZ() const
Access to the underlying unitvectors of the rotation matrix.
Vector UnitX() const
Access to the underlying unitvectors of the rotation matrix.
static Rotation RotX(double angle)
The Rot... static functions give the value of the appropriate rotation matrix back.
Vector2 GetXZRot() const
Returns a 2D vector representing the equivalent rotation in the XZ plane that brings the Y axis onto ...
void setValue(float *oglmat)
static Rotation RotY(double angle)
The Rot... static functions give the value of the appropriate rotation matrix back.
static Rotation RotZ(double angle)
The Rot... static functions give the value of the appropriate rotation matrix back.
void GetValue(double *xy) const
store vector components in array
A concrete implementation of a 3 dimensional vector class.
bool addSegment(const std::string &segment_name, const std::string &hook_name, const Joint &joint, const double &q_rest, const Frame &f_tip=F_identity, const Inertia &M=Inertia::Zero())
int addLimitConstraint(const std::string &segment_name, unsigned int dof, double _min, double _max)
bool getRelativeFrame(Frame &result, const std::string &segment_name, const std::string &base_name=m_root)
virtual const Frame & getPose(const unsigned int end_effector)
int addConstraint(const std::string &segment_name, ConstraintCallback _function, void *_param=NULL, bool _freeParam=false, bool _substep=false)
virtual int addEndEffector(const std::string &name)
bool getSegment(const std::string &segment_name, const unsigned int q_size, const Joint *&p_joint, double &q_rest, double &q, const Frame *&p_tip)
double getMaxEndEffectorChange()
virtual bool setJointArray(const KDL::JntArray &joints)
double getMaxJointChange()
const void * getPreviousCacheItem(const void *device, int channel, CacheTS *timestamp)
bool setControlParameter(int id, ConstraintAction action, double value, double timestep=0.0)
void substep(bool _substep)
virtual EIGEN_MAKE_ALIGNED_OPERATOR_NEW bool registerCallback(ConstraintCallback _function, void *_param)
virtual const ConstraintValues * getControlParameters(unsigned int *_nvalues)=0
virtual unsigned int getNrOfConstraints()
virtual e_matrix & getWq()
bool setCallback(MovingFrameCallback _function, void *_param)
virtual const KDL::Frame & getPose(const unsigned int end_effector=0)
bool addSolver(Solver *_solver)
bool addConstraintSet(const std::string &name, ConstraintSet *task, const std::string &object1, const std::string &object2, const std::string &ee1="", const std::string &ee2="")
bool update(double timestamp, double timestep, unsigned int numsubstep=1, bool reiterate=false, bool cache=true, bool interpolate=true)
bool addCache(Cache *_cache)
bool addObject(const std::string &name, Object *object, UncontrolledObject *base=&Object::world, const std::string &baseFrame="")
virtual void setParam(SolverParam param, double value)=0
IMETHOD void SetToZero(Vector &v)
float length(VecOp< float, D >) RET
float3x3 scale(float3x3 mat, float2 scale)
ccl_device_inline dual3 fabs(const ccl_private dual3 &a)
INLINE Rall1d< T, V, S > sin(const Rall1d< T, V, S > &arg)
INLINE Rall1d< T, V, S > sqrt(const Rall1d< T, V, S > &arg)
INLINE Rall1d< T, V, S > atan2(const Rall1d< T, V, S > &y, const Rall1d< T, V, S > &x)
INLINE Rall1d< T, V, S > sqr(const Rall1d< T, V, S > &arg)
const double PI
the value of pi
INLINE Rall1d< T, V, S > cos(const Rall1d< T, V, S > &arg)
double epsilon
default precision while comparing with Equal(..,..) functions. Initialized at 0.0000001.
Vector Normalize(const Vector &, double eps=epsilon)
MINLINE float min_ff(float a, float b)
static int initialize_chain(Object *, bPoseChannel *pchan_tip, bConstraint *con)
void mul_m3_v3(const float M[3][3], float r[3])
static bool base_callback(const iTaSC::Timestamp ×tamp, const iTaSC::Frame &, iTaSC::Frame &next, void *param)
MINLINE void copy_v3_v3(float r[3], const float a[3])
void copy_m3_m4(float m1[3][3], const float m2[4][4])
@ CONSTRAINT_TYPE_KINEMATIC
static IK_Scene * convert_tree(Depsgraph *depsgraph, Scene *blscene, Object *ob, bPoseChannel *pchan, float ctime)
static bool distance_callback(const iTaSC::Timestamp ×tamp, iTaSC::ConstraintValues *const _values, uint, void *_param)
bool invert_m3_m3(float inverse[3][3], const float mat[3][3])
static int init_scene(Object *ob)
void normalize_m3(float R[3][3]) ATTR_NONNULL()
float normalize_qt(float q[4])
bool invert_m4_m4(float inverse[4][4], const float mat[4][4])
void BKE_pose_where_is_bone(Depsgraph *depsgraph, Scene *scene, Object *ob, bPoseChannel *pchan, float ctime, bool do_extra)
static int initialize_scene(Object *ob, bPoseChannel *pchan_tip)
void axis_angle_to_mat3(float R[3][3], const float axis[3], float angle)
void blend_m4_m4m4(float out[4][4], const float dst[4][4], const float src[4][4], float srcweight)
static bool constraint_valid(bConstraint *con)
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
void itasc_initialize_tree(Depsgraph *depsgraph, Scene *scene, Object *ob, float ctime)
static bool target_callback(const iTaSC::Timestamp &, const iTaSC::Frame &, iTaSC::Frame &next, void *param)
static void execute_scene(Depsgraph *depsgraph, Scene *blscene, IK_Scene *ikscene, bItasc *ikparam, float ctime, float frtime)
void itasc_release_tree(Scene *, Object *, float)
static bool joint_callback(const iTaSC::Timestamp &, iTaSC::ConstraintValues *const _values, uint _nvalues, void *_param)
static void pose_rest(IK_Scene *ikscene)
MINLINE void mul_v3_fl(float r[3], float f)
void normalize_m4(float R[4][4]) ATTR_NONNULL()
static void create_scene(Depsgraph *depsgraph, Scene *scene, Object *ob, float ctime)
void eulO_to_mat3(float M[3][3], const float e[3], short order)
void quat_to_mat3(float m[3][3], const float q[4])
static bool is_cartesian_constraint(bConstraint *)
void itasc_clear_cache(bPose *pose)
static void GetJointRotation(KDL::Rotation &boneRot, int type, double *rot)
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
void mul_m4_m4m3(float R[4][4], const float A[4][4], const float B[3][3])
BMesh const char void * data
void unit_m4(float m[4][4])
static double EulerAngleFromMatrix(const KDL::Rotation &R, int axis)
MINLINE float len_v3(const float a[3]) ATTR_WARN_UNUSED_RESULT
static void copypose_error(const iTaSC::ConstraintValues *values, uint, IK_Target *iktarget)
@ ITASC_INITIAL_REITERATION
@ ITASC_TRANSLATE_ROOT_BONES
void itasc_test_constraint(Object *, bConstraint *cons)
static bool copypose_callback(const iTaSC::Timestamp &, iTaSC::ConstraintValues *const _values, uint, void *_param)
@ CONSTRAINT_IK_TARGETAXIS
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
static void convert_pose(IK_Scene *ikscene)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
void unit_m3(float m[3][3])
void(*)(const iTaSC::ConstraintValues *values, uint nvalues, IK_Target *iktarget) ErrorCallback
static int convert_channels(Depsgraph *depsgraph, IK_Scene *ikscene, PoseTree *tree, float ctime)
static void distance_error(const iTaSC::ConstraintValues *values, uint, IK_Target *iktarget)
void itasc_execute_tree(Depsgraph *depsgraph, Scene *scene, Object *ob, bPoseChannel *pchan_root, float ctime)
@ CONSTRAINT_OBTYPE_OBJECT
void BKE_constraint_target_matrix_get(struct Depsgraph *depsgraph, struct Scene *scene, struct bConstraint *con, int index, short ownertype, void *ownerdata, float mat[4][4], float ctime)
static double ComputeTwist(const KDL::Rotation &R)
void itasc_update_param(bPose *pose)
void copy_m4_m4(float m1[4][4], const float m2[4][4])
static void RemoveEulerAngleFromMatrix(KDL::Rotation &R, double angle, int axis)
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
static IK_Data * get_ikdata(bPose *pose)
void itasc_clear_data(bPose *pose)
void BKE_pose_itasc_init(bItasc *itasc)
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
bConstraint * polarConstraint
std::vector< IK_Target * > targets
iTaSC::Armature * armature
iTaSC::MovingFrame * base
bPoseChannel * rootChannel
std::string constraintName
bConstraint * blenderConstraint
iTaSC::MovingFrame * target
ErrorCallback errorCallback
iTaSC::ConstraintSet * constraint
float(* basis_change)[3][3]
ListBaseT< PoseTarget > targets
ePose_IKSolverType iksolver
struct bPoseChannel * parent
ListBaseT< struct PoseTree > iktree
ListBaseT< struct bConstraint > constraints
ePchan_ConstFlag constflag
bke::bPoseRuntime * runtime
ListBaseT< bPoseChannel > chanbase
struct ConstraintSingleValue * values