4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21 * All rights reserved.
23 * The Original Code is: all of this file.
25 * Contributor(s): 2007 - Joshua Leung (major recode)
27 * ***** END GPL LICENSE BLOCK *****
30 #ifndef BKE_CONSTRAINT_H
31 #define BKE_CONSTRAINT_H
35 struct bConstraintTarget;
41 /* ---------------------------------------------------------------------------- */
46 /* special struct for use in constraint evaluation */
47 typedef struct bConstraintOb {
48 struct Scene *scene; /* for system time, part of deglobalization, code nicer later with local time (ton) */
49 struct Object *ob; /* if pchan, then armature that it comes from, otherwise constraint owner */
50 struct bPoseChannel *pchan; /* pose channel that owns the constraints being evaluated */
52 float matrix[4][4]; /* matrix where constraints are accumulated + solved */
53 float startmat[4][4]; /* original matrix (before constraint solving) */
55 short type; /* type of owner */
56 short rotOrder; /* rotation order for constraint owner (as defined in eEulerRotationOrders in BLI_math.h) */
59 /* ---------------------------------------------------------------------------- */
61 /* Callback format for performing operations on ID-pointers for Constraints */
62 typedef void (*ConstraintIDFunc)(struct bConstraint *con, struct ID **idpoin, void *userdata);
66 /* Constraint Type-Info (shorthand in code = cti):
67 * This struct provides function pointers for runtime, so that functions can be
68 * written more generally (with fewer/no special exceptions for various constraints).
70 * Callers of these functions must check that they actually point to something useful,
71 * as some constraints don't define some of these.
73 * Warning: it is not too advisable to reorder order of members of this struct,
74 * as you'll have to edit quite a few ($NUM_CONSTRAINT_TYPES) of these
77 typedef struct bConstraintTypeInfo {
79 short type; /* CONSTRAINT_TYPE_### */
80 short size; /* size in bytes of the struct */
81 char name[32]; /* name of constraint in interface */
82 char structName[32]; /* name of struct for SDNA */
84 /* data management function pointers - special handling */
85 /* free any data that is allocated separately (optional) */
86 void (*free_data)(struct bConstraint *con);
87 /* adjust pointer to other ID-data using ID_NEW(), but not to targets (optional) */
88 void (*relink_data)(struct bConstraint *con);
89 /* run the provided callback function on all the ID-blocks linked to the constraint */
90 void (*id_looper)(struct bConstraint *con, ConstraintIDFunc func, void *userdata);
91 /* copy any special data that is allocated separately (optional) */
92 void (*copy_data)(struct bConstraint *con, struct bConstraint *src);
93 /* set settings for data that will be used for bConstraint.data (memory already allocated using MEM_callocN) */
94 void (*new_data)(void *cdata);
96 /* target handling function pointers */
97 /* for multi-target constraints: return that list; otherwise make a temporary list (returns number of targets) */
98 int (*get_constraint_targets)(struct bConstraint *con, struct ListBase *list);
99 /* for single-target constraints only: flush data back to source data, and the free memory used */
100 void (*flush_constraint_targets)(struct bConstraint *con, struct ListBase *list, short nocopy);
103 /* set the ct->matrix for the given constraint target (at the given ctime) */
104 void (*get_target_matrix)(struct bConstraint *con, struct bConstraintOb *cob, struct bConstraintTarget *ct, float ctime);
105 /* evaluate the constraint for the given time */
106 void (*evaluate_constraint)(struct bConstraint *con, struct bConstraintOb *cob, struct ListBase *targets);
107 } bConstraintTypeInfo;
109 /* Function Prototypes for bConstraintTypeInfo's */
110 bConstraintTypeInfo *constraint_get_typeinfo(struct bConstraint *con);
111 bConstraintTypeInfo *get_constraint_typeinfo(int type);
113 /* ---------------------------------------------------------------------------- */
114 /* Useful macros for testing various common flag combinations */
116 /* Constraint Target Macros */
117 #define VALID_CONS_TARGET(ct) ((ct) && (ct->tar))
119 /* ---------------------------------------------------------------------------- */
121 /* Constraint function prototypes */
122 void unique_constraint_name(struct bConstraint *con, struct ListBase *list);
124 void free_constraints(struct ListBase *list);
125 void copy_constraints(struct ListBase *dst, const struct ListBase *src);
126 void relink_constraints(struct ListBase *list);
127 void id_loop_constraints(struct ListBase *list, ConstraintIDFunc func, void *userdata);
128 void free_constraint_data(struct bConstraint *con);
130 /* Constraint API function prototypes */
131 struct bConstraint *constraints_get_active(struct ListBase *list);
132 void constraints_set_active(ListBase *list, struct bConstraint *con);
134 struct bConstraint *add_ob_constraint(struct Object *ob, const char *name, short type);
135 struct bConstraint *add_pose_constraint(struct Object *ob, struct bPoseChannel *pchan, const char *name, short type);
137 int remove_constraint(ListBase *list, struct bConstraint *con);
138 int remove_constraint_index(ListBase *list, int index);
139 void remove_constraints_type(ListBase *list, short type, short last_only);
141 /* Constraints + Proxies function prototypes */
142 void extract_proxylocal_constraints(struct ListBase *dst, struct ListBase *src);
143 short proxylocked_constraints_owner(struct Object *ob, struct bPoseChannel *pchan);
145 /* Constraint Evaluation function prototypes */
146 struct bConstraintOb *constraints_make_evalob(struct Scene *scene, struct Object *ob, void *subdata, short datatype);
147 void constraints_clear_evalob(struct bConstraintOb *cob);
149 void constraint_mat_convertspace(struct Object *ob, struct bPoseChannel *pchan, float mat[][4], short from, short to);
151 void get_constraint_target_matrix(struct Scene *scene, struct bConstraint *con, int n, short ownertype, void *ownerdata, float mat[][4], float ctime);
152 void solve_constraints(struct ListBase *conlist, struct bConstraintOb *cob, float ctime);