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) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  */
19 
20 #pragma once
21 
22 /** \file
23  * \ingroup bke
24  * \brief Blender kernel action and pose functionality.
25  */
26 
27 #include "DNA_listBase.h"
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 /* The following structures are defined in DNA_action_types.h, and DNA_anim_types.h */
34 struct AnimationEvalContext;
35 struct FCurve;
36 struct Main;
37 struct Object;
38 struct bAction;
39 struct bActionGroup;
40 struct bItasc;
41 struct bPose;
42 struct bPoseChannel;
43 struct bPoseChannel_Runtime;
44 
45 /* Action Lib Stuff ----------------- */
46 
47 /* Allocate a new bAction with the given name */
48 struct bAction *BKE_action_add(struct Main *bmain, const char name[]);
49 
50 /* Action API ----------------- */
51 
52 /* types of transforms applied to the given item
53  * - these are the return flags for action_get_item_transforms()
54  */
55 typedef enum eAction_TransformFlags {
56   /* location */
57   ACT_TRANS_LOC = (1 << 0),
58   /* rotation */
59   ACT_TRANS_ROT = (1 << 1),
60   /* scaling */
61   ACT_TRANS_SCALE = (1 << 2),
62 
63   /* bbone shape - for all the parameters, provided one is set */
64   ACT_TRANS_BBONE = (1 << 3),
65 
66   /* strictly not a transform, but custom properties are also
67    * quite often used in modern rigs
68    */
69   ACT_TRANS_PROP = (1 << 4),
70 
71   /* all flags */
72   ACT_TRANS_ONLY = (ACT_TRANS_LOC | ACT_TRANS_ROT | ACT_TRANS_SCALE),
73   ACT_TRANS_ALL = (ACT_TRANS_ONLY | ACT_TRANS_PROP),
74 } eAction_TransformFlags;
75 
76 /* Return flags indicating which transforms the given object/posechannel has
77  * - if 'curves' is provided, a list of links to these curves are also returned
78  *   whose nodes WILL NEED FREEING
79  */
80 short action_get_item_transforms(struct bAction *act,
81                                  struct Object *ob,
82                                  struct bPoseChannel *pchan,
83                                  ListBase *curves);
84 
85 /* Some kind of bounding box operation on the action */
86 void calc_action_range(const struct bAction *act, float *start, float *end, short incl_modifiers);
87 
88 /* Does action have any motion data at all? */
89 bool action_has_motion(const struct bAction *act);
90 
91 /* Action Groups API ----------------- */
92 
93 /* Get the active action-group for an Action */
94 struct bActionGroup *get_active_actiongroup(struct bAction *act);
95 
96 /* Make the given Action Group the active one */
97 void set_active_action_group(struct bAction *act, struct bActionGroup *agrp, short select);
98 
99 /* Sync colors used for action/bone group with theme settings */
100 void action_group_colors_sync(struct bActionGroup *grp, const struct bActionGroup *ref_grp);
101 
102 /* Add a new action group with the given name to the action */
103 struct bActionGroup *action_groups_add_new(struct bAction *act, const char name[]);
104 
105 /* Add given channel into (active) group  */
106 void action_groups_add_channel(struct bAction *act,
107                                struct bActionGroup *agrp,
108                                struct FCurve *fcurve);
109 
110 /* Remove the given channel from all groups */
111 void action_groups_remove_channel(struct bAction *act, struct FCurve *fcu);
112 
113 /* Reconstruct group channel pointers. */
114 void BKE_action_groups_reconstruct(struct bAction *act);
115 
116 /* Find a group with the given name */
117 struct bActionGroup *BKE_action_group_find_name(struct bAction *act, const char name[]);
118 
119 /* Clear all 'temp' flags on all groups */
120 void action_groups_clear_tempflags(struct bAction *act);
121 
122 /* Pose API ----------------- */
123 
124 void BKE_pose_channel_free(struct bPoseChannel *pchan);
125 void BKE_pose_channel_free_ex(struct bPoseChannel *pchan, bool do_id_user);
126 
127 void BKE_pose_channel_runtime_reset(struct bPoseChannel_Runtime *runtime);
128 void BKE_pose_channel_runtime_reset_on_copy(struct bPoseChannel_Runtime *runtime);
129 
130 void BKE_pose_channel_runtime_free(struct bPoseChannel_Runtime *runtime);
131 
132 void BKE_pose_channel_free_bbone_cache(struct bPoseChannel_Runtime *runtime);
133 
134 void BKE_pose_channels_free(struct bPose *pose);
135 void BKE_pose_channels_free_ex(struct bPose *pose, bool do_id_user);
136 
137 void BKE_pose_channels_hash_make(struct bPose *pose);
138 void BKE_pose_channels_hash_free(struct bPose *pose);
139 
140 void BKE_pose_channels_remove(struct Object *ob,
141                               bool (*filter_fn)(const char *bone_name, void *user_data),
142                               void *user_data);
143 
144 void BKE_pose_free_data_ex(struct bPose *pose, bool do_id_user);
145 void BKE_pose_free_data(struct bPose *pose);
146 void BKE_pose_free(struct bPose *pose);
147 void BKE_pose_free_ex(struct bPose *pose, bool do_id_user);
148 void BKE_pose_copy_data_ex(struct bPose **dst,
149                            const struct bPose *src,
150                            const int flag,
151                            const bool copy_constraints);
152 void BKE_pose_copy_data(struct bPose **dst, const struct bPose *src, const bool copy_constraints);
153 void BKE_pose_channel_copy_data(struct bPoseChannel *pchan, const struct bPoseChannel *pchan_from);
154 void BKE_pose_channel_session_uuid_generate(struct bPoseChannel *pchan);
155 struct bPoseChannel *BKE_pose_channel_find_name(const struct bPose *pose, const char *name);
156 struct bPoseChannel *BKE_pose_channel_active(struct Object *ob);
157 struct bPoseChannel *BKE_pose_channel_active_or_first_selected(struct Object *ob);
158 struct bPoseChannel *BKE_pose_channel_verify(struct bPose *pose, const char *name);
159 struct bPoseChannel *BKE_pose_channel_get_mirrored(const struct bPose *pose, const char *name);
160 
161 void BKE_pose_check_uuids_unique_and_report(const struct bPose *pose);
162 
163 #ifndef NDEBUG
164 bool BKE_pose_channels_is_valid(const struct bPose *pose);
165 #endif
166 
167 /* sets constraint flags */
168 void BKE_pose_update_constraint_flags(struct bPose *pose);
169 
170 /* tag constraint flags for update */
171 void BKE_pose_tag_update_constraint_flags(struct bPose *pose);
172 
173 /* return the name of structure pointed by pose->ikparam */
174 const char *BKE_pose_ikparam_get_name(struct bPose *pose);
175 
176 /* allocate and initialize pose->ikparam according to pose->iksolver */
177 void BKE_pose_ikparam_init(struct bPose *pose);
178 
179 /* initialize a bItasc structure with default value */
180 void BKE_pose_itasc_init(struct bItasc *itasc);
181 
182 /* Checks if a bone is part of an IK chain or not */
183 bool BKE_pose_channel_in_IK_chain(struct Object *ob, struct bPoseChannel *pchan);
184 
185 /* clears BONE_UNKEYED flags for frame changing */
186 // XXX to be deprecated for a more general solution in animsys...
187 void framechange_poses_clear_unkeyed(struct Main *bmain);
188 
189 /* Bone Groups API --------------------- */
190 
191 /* Adds a new bone-group */
192 struct bActionGroup *BKE_pose_add_group(struct bPose *pose, const char *name);
193 
194 /* Remove a bone-group */
195 void BKE_pose_remove_group(struct bPose *pose, struct bActionGroup *grp, const int index);
196 /* Remove the matching bone-group from its index */
197 void BKE_pose_remove_group_index(struct bPose *pose, const int index);
198 
199 /* Assorted Evaluation ----------------- */
200 
201 /* Used for the Action Constraint */
202 void what_does_obaction(struct Object *ob,
203                         struct Object *workob,
204                         struct bPose *pose,
205                         struct bAction *act,
206                         char groupname[],
207                         const struct AnimationEvalContext *anim_eval_context);
208 
209 /* for proxy */
210 void BKE_pose_copy_pchan_result(struct bPoseChannel *pchanto,
211                                 const struct bPoseChannel *pchanfrom);
212 bool BKE_pose_copy_result(struct bPose *to, struct bPose *from);
213 /* Clear transforms. */
214 void BKE_pose_rest(struct bPose *pose, bool selected_bones_only);
215 
216 /* Tag pose for recalc. Also tag all related data to be recalc. */
217 void BKE_pose_tag_recalc(struct Main *bmain, struct bPose *pose);
218 
219 #ifdef __cplusplus
220 };
221 #endif
222