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: all of this file.
20 * Contributor(s): none yet.
22 * ***** END GPL LICENSE BLOCK *****
25 #ifndef __BKE_OBJECT_H__
26 #define __BKE_OBJECT_H__
28 /** \file BKE_object.h
30 * \brief General operations, lookup, etc. for blender objects.
36 #include "BLI_compiler_attrs.h"
39 struct EvaluationContext;
45 struct BulletSoftBody;
48 struct RigidBodyWorld;
49 struct HookModifierData;
52 void BKE_object_workob_clear(struct Object *workob);
53 void BKE_object_workob_calc_parent(struct Scene *scene, struct Object *ob, struct Object *workob);
55 void BKE_object_transform_copy(struct Object *ob_tar, const struct Object *ob_src);
56 struct SoftBody *copy_softbody(const struct SoftBody *sb, bool copy_caches);
57 struct BulletSoftBody *copy_bulletsoftbody(struct BulletSoftBody *sb);
58 void BKE_object_copy_softbody(struct Object *ob_dst, const struct Object *ob_src);
59 void BKE_object_free_softbody(struct Object *ob);
60 void BKE_object_free_bulletsoftbody(struct Object *ob);
61 void BKE_object_free_curve_cache(struct Object *ob);
62 void BKE_object_update_base_layer(struct Scene *scene, struct Object *ob);
64 void BKE_object_free(struct Object *ob);
65 void BKE_object_free_ex(struct Object *ob, bool do_id_user);
66 void BKE_object_free_derived_caches(struct Object *ob);
67 void BKE_object_free_caches(struct Object *object);
69 void BKE_object_modifier_hook_reset(struct Object *ob, struct HookModifierData *hmd);
71 bool BKE_object_support_modifier_type_check(struct Object *ob, int modifier_type);
73 void BKE_object_link_modifiers(struct Object *ob_dst, const struct Object *ob_src);
74 void BKE_object_free_modifiers(struct Object *ob);
76 void BKE_object_make_proxy(struct Object *ob, struct Object *target, struct Object *gob);
77 void BKE_object_copy_proxy_drivers(struct Object *ob, struct Object *target);
79 void BKE_object_unlink(struct Main *bmain, struct Object *ob);
80 bool BKE_object_exists_check(struct Object *obtest);
81 bool BKE_object_is_in_editmode(struct Object *ob);
82 bool BKE_object_is_in_editmode_vgroup(struct Object *ob);
83 bool BKE_object_is_in_wpaint_select_vert(struct Object *ob);
85 void BKE_object_init(struct Object *ob);
86 struct Object *BKE_object_add_only_object(
88 int type, const char *name)
89 ATTR_NONNULL(1) ATTR_RETURNS_NONNULL;
90 struct Object *BKE_object_add(
91 struct Main *bmain, struct Scene *scene,
92 int type, const char *name)
93 ATTR_NONNULL(1, 2) ATTR_RETURNS_NONNULL;
94 void *BKE_object_obdata_add_from_type(
96 int type, const char *name)
99 void BKE_object_lod_add(struct Object *ob);
100 void BKE_object_lod_sort(struct Object *ob);
101 bool BKE_object_lod_remove(struct Object *ob, int level);
102 void BKE_object_lod_update(struct Object *ob, const float camera_position[3]);
103 bool BKE_object_lod_is_usable(struct Object *ob, struct Scene *scene);
104 struct Object *BKE_object_lod_meshob_get(struct Object *ob, struct Scene *scene);
105 struct Object *BKE_object_lod_matob_get(struct Object *ob, struct Scene *scene);
107 struct Object *BKE_object_copy_ex(struct Main *bmain, struct Object *ob, bool copy_caches);
108 struct Object *BKE_object_copy(struct Object *ob);
109 void BKE_object_make_local(struct Object *ob);
110 bool BKE_object_is_libdata(struct Object *ob);
111 bool BKE_object_obdata_is_libdata(struct Object *ob);
113 void BKE_object_obdata_size_init(struct Object *ob, const float scale);
115 void BKE_object_scale_to_mat3(struct Object *ob, float mat[3][3]);
116 void BKE_object_rot_to_mat3(struct Object *ob, float mat[3][3], bool use_drot);
117 void BKE_object_mat3_to_rot(struct Object *ob, float mat[3][3], bool use_compat);
118 void BKE_object_to_mat3(struct Object *ob, float mat[3][3]);
119 void BKE_object_to_mat4(struct Object *ob, float mat[4][4]);
120 void BKE_object_apply_mat4(struct Object *ob, float mat[4][4], const bool use_compat, const bool use_parent);
121 void BKE_object_matrix_local_get(struct Object *ob, float mat[4][4]);
123 bool BKE_object_pose_context_check(struct Object *ob);
124 struct Object *BKE_object_pose_armature_get(struct Object *ob);
126 void BKE_object_get_parent_matrix(struct Scene *scene, struct Object *ob, struct Object *par, float parentmat[4][4]);
127 void BKE_object_where_is_calc(struct Scene *scene, struct Object *ob);
128 void BKE_object_where_is_calc_ex(struct Scene *scene, struct RigidBodyWorld *rbw, struct Object *ob, float r_originmat[3][3]);
129 void BKE_object_where_is_calc_time(struct Scene *scene, struct Object *ob, float ctime);
130 void BKE_object_where_is_calc_time_ex(struct Scene *scene, struct Object *ob, float ctime,
131 struct RigidBodyWorld *rbw, float r_originmat[3][3]);
132 void BKE_object_where_is_calc_mat4(struct Scene *scene, struct Object *ob, float obmat[4][4]);
134 /* possibly belong in own moduke? */
135 struct BoundBox *BKE_boundbox_alloc_unit(void);
136 void BKE_boundbox_init_from_minmax(struct BoundBox *bb, const float min[3], const float max[3]);
137 bool BKE_boundbox_ray_hit_check(
138 const struct BoundBox *bb,
139 const float ray_start[3], const float ray_normal[3],
141 void BKE_boundbox_calc_center_aabb(const struct BoundBox *bb, float r_cent[3]);
142 void BKE_boundbox_calc_size_aabb(const struct BoundBox *bb, float r_size[3]);
143 void BKE_boundbox_minmax(const struct BoundBox *bb, float obmat[4][4], float r_min[3], float r_max[3]);
144 void BKE_boundbox_scale(struct BoundBox *bb_dst, const struct BoundBox *bb_src, float scale);
145 struct BoundBox *BKE_boundbox_ensure_minimum_dimensions(
146 struct BoundBox *bb, struct BoundBox *bb_temp, const float epsilon);
148 struct BoundBox *BKE_object_boundbox_get(struct Object *ob);
149 void BKE_object_dimensions_get(struct Object *ob, float vec[3]);
150 void BKE_object_dimensions_set(struct Object *ob, const float value[3]);
151 void BKE_object_empty_draw_type_set(struct Object *ob, const int value);
152 void BKE_object_boundbox_flag(struct Object *ob, int flag, const bool set);
153 void BKE_object_minmax(struct Object *ob, float r_min[3], float r_max[3], const bool use_hidden);
154 bool BKE_object_minmax_dupli(struct Scene *scene, struct Object *ob, float r_min[3], float r_max[3], const bool use_hidden);
156 /* sometimes min-max isn't enough, we need to loop over each point */
157 void BKE_object_foreach_display_point(struct Object *ob, float obmat[4][4],
158 void (*func_cb)(const float[3], void *), void *user_data);
159 void BKE_scene_foreach_display_point(struct Scene *scene,
162 void (*func_cb)(const float[3], void *), void *user_data);
164 bool BKE_object_parent_loop_check(const struct Object *parent, const struct Object *ob);
166 void *BKE_object_tfm_backup(struct Object *ob);
167 void BKE_object_tfm_restore(struct Object *ob, void *obtfm_pt);
169 typedef struct ObjectTfmProtectedChannels {
170 float loc[3], dloc[3];
171 float size[3], dscale[3];
172 float rot[3], drot[3];
173 float quat[4], dquat[4];
174 float rotAxis[3], drotAxis[3];
175 float rotAngle, drotAngle;
176 } ObjectTfmProtectedChannels;
178 void BKE_object_tfm_protected_backup(const struct Object *ob,
179 ObjectTfmProtectedChannels *obtfm);
181 void BKE_object_tfm_protected_restore(struct Object *ob,
182 const ObjectTfmProtectedChannels *obtfm,
183 const short protectflag);
185 /* Dependency graph evaluation callbacks. */
186 void BKE_object_eval_local_transform(struct EvaluationContext *eval_ctx,
189 void BKE_object_eval_parent(struct EvaluationContext *eval_ctx,
192 void BKE_object_eval_constraints(struct EvaluationContext *eval_ctx,
195 void BKE_object_eval_done(struct EvaluationContext *eval_ctx, struct Object *ob);
197 void BKE_object_eval_modifier(struct EvaluationContext *eval_ctx,
200 struct ModifierData *md);
201 void BKE_object_eval_uber_transform(struct EvaluationContext *eval_ctx,
204 void BKE_object_eval_uber_data(struct EvaluationContext *eval_ctx,
208 void BKE_object_eval_proxy_backlink(struct EvaluationContext *eval_ctx, struct Object *ob);
210 void BKE_object_handle_data_update(struct EvaluationContext *eval_ctx,
213 void BKE_object_handle_update(struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob);
214 void BKE_object_handle_update_ex(struct EvaluationContext *eval_ctx,
215 struct Scene *scene, struct Object *ob,
216 struct RigidBodyWorld *rbw,
217 const bool do_proxy_update);
218 void BKE_object_sculpt_modifiers_changed(struct Object *ob);
220 int BKE_object_obdata_texspace_get(struct Object *ob, short **r_texflag, float **r_loc, float **r_size, float **r_rot);
222 int BKE_object_insert_ptcache(struct Object *ob);
223 void BKE_object_delete_ptcache(struct Object *ob, int index);
224 struct KeyBlock *BKE_object_shapekey_insert(struct Object *ob, const char *name, const bool from_mix);
225 bool BKE_object_shapekey_remove(struct Main *bmain, struct Object *ob, struct KeyBlock *kb);
226 bool BKE_object_shapekey_free(struct Main *bmain, struct Object *ob);
228 bool BKE_object_flag_test_recursive(const struct Object *ob, short flag);
230 bool BKE_object_is_child_recursive(struct Object *ob_parent, struct Object *ob_child);
231 bool BKE_object_is_animated(struct Scene *scene, struct Object *ob);
233 /* return ModifierMode flag */
234 int BKE_object_is_modified(struct Scene *scene, struct Object *ob);
235 int BKE_object_is_deform_modified(struct Scene *scene, struct Object *ob);
237 void BKE_object_relink(struct Object *ob);
238 void BKE_object_data_relink(struct Object *ob);
240 struct MovieClip *BKE_object_movieclip_get(struct Scene *scene, struct Object *ob, bool use_default);
242 /* this function returns a superset of the scenes selection based on relationships */
244 typedef enum eObRelationTypes {
245 OB_REL_NONE = 0, /* just the selection as is */
246 OB_REL_PARENT = (1 << 0), /* immediate parent */
247 OB_REL_PARENT_RECURSIVE = (1 << 1), /* parents up to root of selection tree*/
248 OB_REL_CHILDREN = (1 << 2), /* immediate children */
249 OB_REL_CHILDREN_RECURSIVE = (1 << 3), /* All children */
250 OB_REL_MOD_ARMATURE = (1 << 4), /* Armatures related to the selected objects */
251 OB_REL_SCENE_CAMERA = (1 << 5), /* you might want the scene camera too even if unselected? */
254 typedef enum eObjectSet {
255 OB_SET_SELECTED, /* Selected Objects */
256 OB_SET_VISIBLE, /* Visible Objects */
257 OB_SET_ALL /* All Objects */
260 struct LinkNode *BKE_object_relational_superset(struct Scene *scene, eObjectSet objectSet, eObRelationTypes includeFilter);
261 struct LinkNode *BKE_object_groups(struct Object *ob);
262 void BKE_object_groups_clear(struct Scene *scene, struct Base *base, struct Object *object);
264 struct KDTree *BKE_object_as_kdtree(struct Object *ob, int *r_tot);
266 bool BKE_object_modifier_use_time(struct Object *ob, struct ModifierData *md);
268 bool BKE_object_modifier_update_subframe(struct Scene *scene, struct Object *ob, bool update_mesh,
269 int parent_recursion, float frame,