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"
40 struct GpencilModifierData;
52 struct RigidBodyWorld;
53 struct HookModifierData;
55 struct HookGpencilModifierData;
58 #include "DNA_object_enums.h"
60 void BKE_object_workob_clear(struct Object *workob);
61 void BKE_object_workob_calc_parent(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct Object *workob);
63 void BKE_object_transform_copy(struct Object *ob_tar, const struct Object *ob_src);
64 void BKE_object_copy_softbody(struct Object *ob_dst, const struct Object *ob_src, const int flag);
65 struct ParticleSystem *BKE_object_copy_particlesystem(struct ParticleSystem *psys, const int flag);
66 void BKE_object_copy_particlesystems(struct Object *ob_dst, const struct Object *ob_src, const int flag);
67 void BKE_object_free_particlesystems(struct Object *ob);
68 void BKE_object_free_softbody(struct Object *ob);
69 void BKE_object_free_curve_cache(struct Object *ob);
71 void BKE_object_free(struct Object *ob);
72 void BKE_object_free_derived_caches(struct Object *ob);
73 void BKE_object_free_derived_mesh_caches(struct Object *ob);
74 void BKE_object_free_caches(struct Object *object);
76 void BKE_object_modifier_hook_reset(struct Object *ob, struct HookModifierData *hmd);
77 void BKE_object_modifier_gpencil_hook_reset(struct Object *ob, struct HookGpencilModifierData *hmd);
78 bool BKE_object_modifier_gpencil_use_time(struct Object *ob, struct GpencilModifierData *md);
80 bool BKE_object_shaderfx_use_time(struct Object *ob, struct ShaderFxData *md);
82 bool BKE_object_support_modifier_type_check(const struct Object *ob, int modifier_type);
84 void BKE_object_link_modifiers(struct Scene *scene, struct Object *ob_dst, const struct Object *ob_src);
85 void BKE_object_free_modifiers(struct Object *ob, const int flag);
86 void BKE_object_free_shaderfx(struct Object *ob, const int flag);
88 void BKE_object_make_proxy(struct Main *bmain, struct Object *ob, struct Object *target, struct Object *gob);
89 void BKE_object_copy_proxy_drivers(struct Object *ob, struct Object *target);
91 bool BKE_object_exists_check(struct Main *bmain, const struct Object *obtest);
92 bool BKE_object_is_in_editmode(const struct Object *ob);
93 bool BKE_object_is_in_editmode_vgroup(const struct Object *ob);
94 bool BKE_object_is_in_wpaint_select_vert(const struct Object *ob);
95 bool BKE_object_has_mode_data(const struct Object *ob, eObjectMode object_mode);
96 bool BKE_object_is_mode_compat(const struct Object *ob, eObjectMode object_mode);
98 bool BKE_object_data_is_in_editmode(const struct ID *id);
100 typedef enum eObjectVisibilityResult {
102 OB_VISIBLE_PARTICLES = 2,
103 OB_VISIBLE_INSTANCES = 4,
104 OB_VISIBLE_ALL = (OB_VISIBLE_SELF | OB_VISIBLE_PARTICLES | OB_VISIBLE_INSTANCES),
105 } eObjectVisibilityResult;
107 int BKE_object_visibility(const struct Object *ob, const int dag_eval_mode);
109 void BKE_object_init(struct Object *ob);
110 struct Object *BKE_object_add_only_object(
112 int type, const char *name)
113 ATTR_NONNULL(1) ATTR_RETURNS_NONNULL;
114 struct Object *BKE_object_add(
115 struct Main *bmain, struct Scene *scene, struct ViewLayer *view_layer,
116 int type, const char *name)
117 ATTR_NONNULL(1, 2, 3) ATTR_RETURNS_NONNULL;
118 struct Object *BKE_object_add_from(
119 struct Main *bmain, struct Scene *scene, struct ViewLayer *view_layer,
120 int type, const char *name, struct Object *ob_src)
121 ATTR_NONNULL(1, 2, 3, 6) ATTR_RETURNS_NONNULL;
122 struct Object *BKE_object_add_for_data(
123 struct Main *bmain, struct ViewLayer *view_layer,
124 int type, const char *name, struct ID *data, bool do_id_user) ATTR_RETURNS_NONNULL;
125 void *BKE_object_obdata_add_from_type(
127 int type, const char *name)
130 void BKE_object_copy_data(struct Main *bmain, struct Object *ob_dst, const struct Object *ob_src, const int flag);
131 struct Object *BKE_object_copy(struct Main *bmain, const struct Object *ob);
132 void BKE_object_make_local(struct Main *bmain, struct Object *ob, const bool lib_local);
133 void BKE_object_make_local_ex(struct Main *bmain, struct Object *ob, const bool lib_local, const bool clear_proxy);
134 bool BKE_object_is_libdata(const struct Object *ob);
135 bool BKE_object_obdata_is_libdata(const struct Object *ob);
137 void BKE_object_obdata_size_init(struct Object *ob, const float scale);
139 void BKE_object_scale_to_mat3(struct Object *ob, float mat[3][3]);
140 void BKE_object_rot_to_mat3(struct Object *ob, float mat[3][3], bool use_drot);
141 void BKE_object_mat3_to_rot(struct Object *ob, float mat[3][3], bool use_compat);
142 void BKE_object_to_mat3(struct Object *ob, float mat[3][3]);
143 void BKE_object_to_mat4(struct Object *ob, float mat[4][4]);
144 void BKE_object_apply_mat4(struct Object *ob, float mat[4][4], const bool use_compat, const bool use_parent);
145 void BKE_object_apply_mat4_ex(struct Object *ob, float mat[4][4], struct Object *parent, float parentinv[4][4], const bool use_compat);
146 void BKE_object_matrix_local_get(struct Object *ob, float mat[4][4]);
148 bool BKE_object_pose_context_check(const struct Object *ob);
149 struct Object *BKE_object_pose_armature_get(struct Object *ob);
150 struct Object *BKE_object_pose_armature_get_visible(struct Object *ob, struct ViewLayer *view_layer, struct View3D *v3d);
152 struct Object **BKE_object_pose_array_get_ex(struct ViewLayer *view_layer, struct View3D *v3d, unsigned int *r_objects_len, bool unique);
153 struct Object **BKE_object_pose_array_get_unique(struct ViewLayer *view_layer, struct View3D *v3d, unsigned int *r_objects_len);
154 struct Object **BKE_object_pose_array_get(struct ViewLayer *view_layer, struct View3D *v3d, unsigned int *r_objects_len);
156 struct Base **BKE_object_pose_base_array_get_ex(struct ViewLayer *view_layer, struct View3D *v3d, unsigned int *r_bases_len, bool unique);
157 struct Base **BKE_object_pose_base_array_get_unique(struct ViewLayer *view_layer, struct View3D *v3d, unsigned int *r_bases_len);
158 struct Base **BKE_object_pose_base_array_get(struct ViewLayer *view_layer, struct View3D *v3d, unsigned int *r_bases_len);
160 void BKE_object_get_parent_matrix(
161 struct Object *ob, struct Object *par, float parentmat[4][4]);
162 void BKE_object_get_parent_matrix_for_dupli(
163 struct Object *ob, struct Object *par, float dupli_ctime, int dupli_transflag, float parentmat[4][4]);
164 void BKE_object_where_is_calc(
165 struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob);
166 void BKE_object_where_is_calc_ex(
167 struct Depsgraph *depsgraph, struct Scene *scene, struct RigidBodyWorld *rbw,
168 struct Object *ob, float r_originmat[3][3]);
169 void BKE_object_where_is_calc_time(
170 struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, float ctime);
171 void BKE_object_where_is_calc_time_for_dupli(
172 struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, float ctime, int dupli_transflag);
173 void BKE_object_where_is_calc_time_ex(
174 struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, float ctime, int dupli_transflag,
175 struct RigidBodyWorld *rbw, float r_originmat[3][3]);
176 void BKE_object_where_is_calc_mat4(struct Object *ob, float obmat[4][4]);
178 /* possibly belong in own moduke? */
179 struct BoundBox *BKE_boundbox_alloc_unit(void);
180 void BKE_boundbox_init_from_minmax(struct BoundBox *bb, const float min[3], const float max[3]);
181 void BKE_boundbox_calc_center_aabb(const struct BoundBox *bb, float r_cent[3]);
182 void BKE_boundbox_calc_size_aabb(const struct BoundBox *bb, float r_size[3]);
183 void BKE_boundbox_minmax(const struct BoundBox *bb, float obmat[4][4], float r_min[3], float r_max[3]);
185 struct BoundBox *BKE_object_boundbox_get(struct Object *ob);
186 void BKE_object_dimensions_get(struct Object *ob, float vec[3]);
187 void BKE_object_dimensions_set(struct Object *ob, const float value[3]);
188 void BKE_object_empty_draw_type_set(struct Object *ob, const int value);
189 void BKE_object_boundbox_flag(struct Object *ob, int flag, const bool set);
190 void BKE_object_boundbox_calc_from_mesh(struct Object *ob, struct Mesh *me_eval);
191 void BKE_object_minmax(struct Object *ob, float r_min[3], float r_max[3], const bool use_hidden);
192 bool BKE_object_minmax_dupli(
193 struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob,
194 float r_min[3], float r_max[3], const bool use_hidden);
196 /* sometimes min-max isn't enough, we need to loop over each point */
197 void BKE_object_foreach_display_point(
198 struct Object *ob, float obmat[4][4],
199 void (*func_cb)(const float[3], void *), void *user_data);
200 void BKE_scene_foreach_display_point(
201 struct Depsgraph *depsgraph,
202 void (*func_cb)(const float[3], void *), void *user_data);
204 bool BKE_object_parent_loop_check(const struct Object *parent, const struct Object *ob);
206 void *BKE_object_tfm_backup(struct Object *ob);
207 void BKE_object_tfm_restore(struct Object *ob, void *obtfm_pt);
209 typedef struct ObjectTfmProtectedChannels {
210 float loc[3], dloc[3];
211 float size[3], dscale[3];
212 float rot[3], drot[3];
213 float quat[4], dquat[4];
214 float rotAxis[3], drotAxis[3];
215 float rotAngle, drotAngle;
216 } ObjectTfmProtectedChannels;
218 void BKE_object_tfm_protected_backup(
219 const struct Object *ob,
220 ObjectTfmProtectedChannels *obtfm);
222 void BKE_object_tfm_protected_restore(
224 const ObjectTfmProtectedChannels *obtfm,
225 const short protectflag);
228 void BKE_object_eval_reset(
229 struct Object *ob_eval);
231 /* Dependency graph evaluation callbacks. */
232 void BKE_object_eval_local_transform(
233 struct Depsgraph *depsgraph,
235 void BKE_object_eval_parent(
236 struct Depsgraph *depsgraph,
238 void BKE_object_eval_constraints(
239 struct Depsgraph *depsgraph,
242 void BKE_object_eval_transform_final(
243 struct Depsgraph *depsgraph, struct Object *ob);
245 bool BKE_object_eval_proxy_copy(
246 struct Depsgraph *depsgraph,
247 struct Object *object);
248 void BKE_object_eval_uber_transform(
249 struct Depsgraph *depsgraph,
251 void BKE_object_eval_uber_data(
252 struct Depsgraph *depsgraph,
256 void BKE_object_eval_boundbox(struct Depsgraph *depsgraph,
257 struct Object *object);
258 void BKE_object_synchronize_to_original(struct Depsgraph *depsgraph,
259 struct Object *object);
261 void BKE_object_eval_ptcache_reset(
262 struct Depsgraph *depsgraph,
264 struct Object *object);
266 void BKE_object_eval_transform_all(
267 struct Depsgraph *depsgraph,
269 struct Object *object);
271 void BKE_object_eval_update_shading(
272 struct Depsgraph *depsgraph,
273 struct Object *object);
274 void BKE_object_data_select_update(
275 struct Depsgraph *depsgraph,
276 struct ID *object_data);
278 void BKE_object_eval_flush_base_flags(
279 struct Depsgraph *depsgraph,
280 struct Scene *scene, const int view_layer_index,
281 struct Object *object, int base_index,
282 const bool is_from_set);
284 void BKE_object_handle_data_update(struct Depsgraph *depsgraph,
287 void BKE_object_handle_update(struct Depsgraph *depsgraph,
288 struct Scene *scene, struct Object *ob);
289 void BKE_object_handle_update_ex(
290 struct Depsgraph *depsgraph,
291 struct Scene *scene, struct Object *ob,
292 struct RigidBodyWorld *rbw,
293 const bool do_proxy_update);
294 void BKE_object_sculpt_modifiers_changed(struct Object *ob);
296 int BKE_object_obdata_texspace_get(struct Object *ob, short **r_texflag, float **r_loc, float **r_size, float **r_rot);
298 struct Mesh *BKE_object_get_evaluated_mesh(const struct Depsgraph *depsgraph, struct Object *ob);
299 struct Mesh *BKE_object_get_final_mesh(struct Object *object);
300 struct Mesh *BKE_object_get_pre_modified_mesh(struct Object *object);
301 struct Mesh *BKE_object_get_original_mesh(struct Object *object);
303 int BKE_object_insert_ptcache(struct Object *ob);
304 void BKE_object_delete_ptcache(struct Object *ob, int index);
305 struct KeyBlock *BKE_object_shapekey_insert(struct Main *bmain, struct Object *ob, const char *name, const bool from_mix);
306 bool BKE_object_shapekey_remove(struct Main *bmain, struct Object *ob, struct KeyBlock *kb);
307 bool BKE_object_shapekey_free(struct Main *bmain, struct Object *ob);
309 bool BKE_object_flag_test_recursive(const struct Object *ob, short flag);
311 bool BKE_object_is_child_recursive(const struct Object *ob_parent, const struct Object *ob_child);
312 bool BKE_object_is_animated(struct Scene *scene, struct Object *ob);
314 /* return ModifierMode flag */
315 int BKE_object_is_modified(struct Scene *scene, struct Object *ob);
316 int BKE_object_is_deform_modified(struct Scene *scene, struct Object *ob);
318 struct MovieClip *BKE_object_movieclip_get(struct Scene *scene, struct Object *ob, bool use_default);
320 void BKE_object_runtime_reset(struct Object *object);
321 void BKE_object_runtime_reset_on_copy(struct Object *object);
323 void BKE_object_batch_cache_dirty_tag(struct Object *ob);
325 /* this function returns a superset of the scenes selection based on relationships */
327 typedef enum eObRelationTypes {
328 OB_REL_NONE = 0, /* just the selection as is */
329 OB_REL_PARENT = (1 << 0), /* immediate parent */
330 OB_REL_PARENT_RECURSIVE = (1 << 1), /* parents up to root of selection tree*/
331 OB_REL_CHILDREN = (1 << 2), /* immediate children */
332 OB_REL_CHILDREN_RECURSIVE = (1 << 3), /* All children */
333 OB_REL_MOD_ARMATURE = (1 << 4), /* Armatures related to the selected objects */
334 OB_REL_SCENE_CAMERA = (1 << 5), /* you might want the scene camera too even if unselected? */
337 typedef enum eObjectSet {
338 OB_SET_SELECTED, /* Selected Objects */
339 OB_SET_VISIBLE, /* Visible Objects */
340 OB_SET_ALL /* All Objects */
343 struct LinkNode *BKE_object_relational_superset(
344 struct ViewLayer *view_layer, eObjectSet objectSet, eObRelationTypes includeFilter);
345 struct LinkNode *BKE_object_groups(struct Main *bmain, struct Object *ob);
346 void BKE_object_groups_clear(struct Main *bmain, struct Object *object);
348 struct KDTree *BKE_object_as_kdtree(struct Object *ob, int *r_tot);
350 bool BKE_object_modifier_use_time(struct Object *ob, struct ModifierData *md);
352 bool BKE_object_modifier_update_subframe(
353 struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob,
354 bool update_mesh, int parent_recursion, float frame, int type);
356 void BKE_object_type_set_empty_for_versioning(struct Object *ob);
358 bool BKE_object_empty_image_is_visible_in_view3d(const struct Object *ob, const struct RegionView3D *rv3d);