2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19 * All rights reserved.
21 * The Original Code is: all of this file.
23 * Contributor(s): 2007 - Joshua Leung (major recode)
25 * ***** END GPL LICENSE BLOCK *****
28 #ifndef __BKE_CONSTRAINT_H__
29 #define __BKE_CONSTRAINT_H__
31 /** \file BKE_constraint.h
33 * \author Joshua Leung (major recode 2007)
38 struct bConstraintTarget;
45 /* ---------------------------------------------------------------------------- */
50 /* special struct for use in constraint evaluation */
51 typedef struct bConstraintOb {
52 /** to get evaluated armature. */
53 struct Depsgraph *depsgraph;
54 /** for system time, part of deglobalization, code nicer later with local time (ton) */
56 /** if pchan, then armature that it comes from, otherwise constraint owner */
58 /** pose channel that owns the constraints being evaluated */
59 struct bPoseChannel *pchan;
61 /** matrix where constraints are accumulated + solved */
63 /** original matrix (before constraint solving) */
68 /** rotation order for constraint owner (as defined in eEulerRotationOrders in BLI_math.h) */
72 /* ---------------------------------------------------------------------------- */
74 /* Callback format for performing operations on ID-pointers for Constraints */
75 typedef void (*ConstraintIDFunc)(struct bConstraint *con, struct ID **idpoin, bool is_reference, void *userdata);
80 * Constraint Type-Info (shorthand in code = cti):
81 * This struct provides function pointers for runtime, so that functions can be
82 * written more generally (with fewer/no special exceptions for various constraints).
84 * Callers of these functions must check that they actually point to something useful,
85 * as some constraints don't define some of these.
88 * it is not too advisable to reorder order of members of this struct,
89 * as you'll have to edit quite a few #NUM_CONSTRAINT_TYPES of these
92 typedef struct bConstraintTypeInfo {
94 /** CONSTRAINT_TYPE_### */
96 /** size in bytes of the struct */
98 /** name of constraint in interface */
100 /** name of struct for SDNA */
103 /* data management function pointers - special handling */
104 /** free any data that is allocated separately (optional) */
105 void (*free_data)(struct bConstraint *con);
106 /** run the provided callback function on all the ID-blocks linked to the constraint */
107 void (*id_looper)(struct bConstraint *con, ConstraintIDFunc func, void *userdata);
108 /** copy any special data that is allocated separately (optional) */
109 void (*copy_data)(struct bConstraint *con, struct bConstraint *src);
110 /** set settings for data that will be used for bConstraint.data (memory already allocated using MEM_callocN) */
111 void (*new_data)(void *cdata);
113 /* target handling function pointers */
114 /** for multi-target constraints: return that list; otherwise make a temporary list (returns number of targets) */
115 int (*get_constraint_targets)(struct bConstraint *con, struct ListBase *list);
116 /** for single-target constraints only: flush data back to source data, and the free memory used */
117 void (*flush_constraint_targets)(struct bConstraint *con, struct ListBase *list, bool no_copy);
120 /** set the ct->matrix for the given constraint target (at the given ctime) */
121 void (*get_target_matrix)(struct Depsgraph *depsgraph, struct bConstraint *con, struct bConstraintOb *cob, struct bConstraintTarget *ct, float ctime);
122 /** evaluate the constraint for the given time */
123 void (*evaluate_constraint)(struct bConstraint *con, struct bConstraintOb *cob, struct ListBase *targets);
124 } bConstraintTypeInfo;
126 /* Function Prototypes for bConstraintTypeInfo's */
127 const bConstraintTypeInfo *BKE_constraint_typeinfo_get(struct bConstraint *con);
128 const bConstraintTypeInfo *BKE_constraint_typeinfo_from_type(int type);
131 /* ---------------------------------------------------------------------------- */
133 /* Constraint function prototypes */
134 void BKE_constraint_unique_name(struct bConstraint *con, struct ListBase *list);
136 struct bConstraint *BKE_constraint_duplicate_ex(struct bConstraint *src, const int flag, const bool do_extern);
138 void BKE_constraints_free(struct ListBase *list);
139 void BKE_constraints_free_ex(struct ListBase *list, bool do_id_user);
140 void BKE_constraints_copy(struct ListBase *dst, const struct ListBase *src, bool do_extern);
141 void BKE_constraints_copy_ex(struct ListBase *dst, const struct ListBase *src, const int flag, bool do_extern);
142 void BKE_constraints_id_loop(struct ListBase *list, ConstraintIDFunc func, void *userdata);
143 void BKE_constraint_free_data(struct bConstraint *con);
144 void BKE_constraint_free_data_ex(struct bConstraint *con, bool do_id_user);
146 bool BKE_constraint_target_uses_bbone(struct bConstraint *con, struct bConstraintTarget *ct);
148 /* Constraint API function prototypes */
149 struct bConstraint *BKE_constraints_active_get(struct ListBase *list);
150 void BKE_constraints_active_set(ListBase *list, struct bConstraint *con);
151 struct bConstraint *BKE_constraints_find_name(struct ListBase *list, const char *name);
153 struct bConstraint *BKE_constraint_find_from_target(struct Object *ob, struct bConstraintTarget *tgt, struct bPoseChannel **r_pchan);
155 struct bConstraint *BKE_constraint_add_for_object(struct Object *ob, const char *name, short type);
156 struct bConstraint *BKE_constraint_add_for_pose(struct Object *ob, struct bPoseChannel *pchan, const char *name, short type);
158 bool BKE_constraint_remove_ex(ListBase *list, struct Object *ob, struct bConstraint *con, bool clear_dep);
159 bool BKE_constraint_remove(ListBase *list, struct bConstraint *con);
161 /* Constraints + Proxies function prototypes */
162 void BKE_constraints_proxylocal_extract(struct ListBase *dst, struct ListBase *src);
163 bool BKE_constraints_proxylocked_owner(struct Object *ob, struct bPoseChannel *pchan);
165 /* Constraint Evaluation function prototypes */
166 struct bConstraintOb *BKE_constraints_make_evalob(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, void *subdata, short datatype);
167 void BKE_constraints_clear_evalob(struct bConstraintOb *cob);
169 void BKE_constraint_mat_convertspace(
170 struct Object *ob, struct bPoseChannel *pchan, float mat[4][4], short from, short to, const bool keep_scale);
172 void BKE_constraint_target_matrix_get(struct Depsgraph *depsgraph, struct Scene *scene, struct bConstraint *con,
173 int n, short ownertype, void *ownerdata, float mat[4][4], float ctime);
174 void BKE_constraint_targets_for_solving_get(struct Depsgraph *depsgraph, struct bConstraint *con, struct bConstraintOb *ob, struct ListBase *targets, float ctime);
175 void BKE_constraints_solve(struct Depsgraph *depsgraph, struct ListBase *conlist, struct bConstraintOb *cob, float ctime);