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.
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.
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.
17 #ifndef __BKE_OBJECT_H__
18 #define __BKE_OBJECT_H__
22 * \brief General operations, lookup, etc. for blender objects.
28 #include "BLI_compiler_attrs.h"
33 struct GpencilModifierData;
34 struct HookGpencilModifierData;
35 struct HookModifierData;
43 struct RigidBodyWorld;
50 #include "DNA_object_enums.h"
52 void BKE_object_workob_clear(struct Object *workob);
53 void BKE_object_workob_calc_parent(struct Depsgraph *depsgraph, 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 void BKE_object_copy_softbody(struct Object *ob_dst, const struct Object *ob_src, const int flag);
57 struct ParticleSystem *BKE_object_copy_particlesystem(struct ParticleSystem *psys, const int flag);
58 void BKE_object_copy_particlesystems(struct Object *ob_dst, const struct Object *ob_src, const int flag);
59 void BKE_object_free_particlesystems(struct Object *ob);
60 void BKE_object_free_softbody(struct Object *ob);
61 void BKE_object_free_curve_cache(struct Object *ob);
63 void BKE_object_free(struct Object *ob);
64 void BKE_object_free_derived_caches(struct Object *ob);
65 void BKE_object_free_derived_mesh_caches(struct Object *ob);
66 void BKE_object_free_caches(struct Object *object);
68 void BKE_object_modifier_hook_reset(struct Object *ob, struct HookModifierData *hmd);
69 void BKE_object_modifier_gpencil_hook_reset(struct Object *ob, struct HookGpencilModifierData *hmd);
70 bool BKE_object_modifier_gpencil_use_time(struct Object *ob, struct GpencilModifierData *md);
72 bool BKE_object_shaderfx_use_time(struct Object *ob, struct ShaderFxData *md);
74 bool BKE_object_support_modifier_type_check(const struct Object *ob, int modifier_type);
76 void BKE_object_link_modifiers(struct Scene *scene, struct Object *ob_dst, const struct Object *ob_src);
77 void BKE_object_free_modifiers(struct Object *ob, const int flag);
78 void BKE_object_free_shaderfx(struct Object *ob, const int flag);
80 void BKE_object_make_proxy(struct Main *bmain, struct Object *ob, struct Object *target, struct Object *gob);
81 void BKE_object_copy_proxy_drivers(struct Object *ob, struct Object *target);
83 bool BKE_object_exists_check(struct Main *bmain, const struct Object *obtest);
84 bool BKE_object_is_in_editmode(const struct Object *ob);
85 bool BKE_object_is_in_editmode_vgroup(const struct Object *ob);
86 bool BKE_object_is_in_wpaint_select_vert(const struct Object *ob);
87 bool BKE_object_has_mode_data(const struct Object *ob, eObjectMode object_mode);
88 bool BKE_object_is_mode_compat(const struct Object *ob, eObjectMode object_mode);
90 bool BKE_object_data_is_in_editmode(const struct ID *id);
92 typedef enum eObjectVisibilityResult {
94 OB_VISIBLE_PARTICLES = 2,
95 OB_VISIBLE_INSTANCES = 4,
96 OB_VISIBLE_ALL = (OB_VISIBLE_SELF | OB_VISIBLE_PARTICLES | OB_VISIBLE_INSTANCES),
97 } eObjectVisibilityResult;
99 int BKE_object_visibility(const struct Object *ob, const int dag_eval_mode);
101 void BKE_object_init(struct Object *ob);
102 struct Object *BKE_object_add_only_object(
104 int type, const char *name)
105 ATTR_NONNULL(1) ATTR_RETURNS_NONNULL;
106 struct Object *BKE_object_add(
107 struct Main *bmain, struct Scene *scene, struct ViewLayer *view_layer,
108 int type, const char *name)
109 ATTR_NONNULL(1, 2, 3) ATTR_RETURNS_NONNULL;
110 struct Object *BKE_object_add_from(
111 struct Main *bmain, struct Scene *scene, struct ViewLayer *view_layer,
112 int type, const char *name, struct Object *ob_src)
113 ATTR_NONNULL(1, 2, 3, 6) ATTR_RETURNS_NONNULL;
114 struct Object *BKE_object_add_for_data(
115 struct Main *bmain, struct ViewLayer *view_layer,
116 int type, const char *name, struct ID *data, bool do_id_user) ATTR_RETURNS_NONNULL;
117 void *BKE_object_obdata_add_from_type(
119 int type, const char *name)
122 void BKE_object_copy_data(struct Main *bmain, struct Object *ob_dst, const struct Object *ob_src, const int flag);
123 struct Object *BKE_object_copy(struct Main *bmain, const struct Object *ob);
124 void BKE_object_make_local(struct Main *bmain, struct Object *ob, const bool lib_local);
125 void BKE_object_make_local_ex(struct Main *bmain, struct Object *ob, const bool lib_local, const bool clear_proxy);
126 bool BKE_object_is_libdata(const struct Object *ob);
127 bool BKE_object_obdata_is_libdata(const struct Object *ob);
129 struct Object *BKE_object_duplicate(struct Main *bmain, const struct Object *ob, const int dupflag);
131 void BKE_object_obdata_size_init(struct Object *ob, const float scale);
133 void BKE_object_scale_to_mat3(struct Object *ob, float mat[3][3]);
134 void BKE_object_rot_to_mat3(struct Object *ob, float mat[3][3], bool use_drot);
135 void BKE_object_mat3_to_rot(struct Object *ob, float mat[3][3], bool use_compat);
136 void BKE_object_to_mat3(struct Object *ob, float mat[3][3]);
137 void BKE_object_to_mat4(struct Object *ob, float mat[4][4]);
138 void BKE_object_apply_mat4(struct Object *ob, float mat[4][4], const bool use_compat, const bool use_parent);
139 void BKE_object_apply_mat4_ex(struct Object *ob, float mat[4][4], struct Object *parent, float parentinv[4][4], const bool use_compat);
140 void BKE_object_matrix_local_get(struct Object *ob, float mat[4][4]);
142 bool BKE_object_pose_context_check(const struct Object *ob);
143 struct Object *BKE_object_pose_armature_get(struct Object *ob);
144 struct Object *BKE_object_pose_armature_get_visible(struct Object *ob, struct ViewLayer *view_layer, struct View3D *v3d);
146 struct Object **BKE_object_pose_array_get_ex(struct ViewLayer *view_layer, struct View3D *v3d, unsigned int *r_objects_len, bool unique);
147 struct Object **BKE_object_pose_array_get_unique(struct ViewLayer *view_layer, struct View3D *v3d, unsigned int *r_objects_len);
148 struct Object **BKE_object_pose_array_get(struct ViewLayer *view_layer, struct View3D *v3d, unsigned int *r_objects_len);
150 struct Base **BKE_object_pose_base_array_get_ex(struct ViewLayer *view_layer, struct View3D *v3d, unsigned int *r_bases_len, bool unique);
151 struct Base **BKE_object_pose_base_array_get_unique(struct ViewLayer *view_layer, struct View3D *v3d, unsigned int *r_bases_len);
152 struct Base **BKE_object_pose_base_array_get(struct ViewLayer *view_layer, struct View3D *v3d, unsigned int *r_bases_len);
154 void BKE_object_get_parent_matrix(
155 struct Object *ob, struct Object *par, float parentmat[4][4]);
156 void BKE_object_where_is_calc(
157 struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob);
158 void BKE_object_where_is_calc_ex(
159 struct Depsgraph *depsgraph, struct Scene *scene, struct RigidBodyWorld *rbw,
160 struct Object *ob, float r_originmat[3][3]);
161 void BKE_object_where_is_calc_time(
162 struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, float ctime);
163 void BKE_object_where_is_calc_mat4(struct Object *ob, float obmat[4][4]);
165 /* possibly belong in own moduke? */
166 struct BoundBox *BKE_boundbox_alloc_unit(void);
167 void BKE_boundbox_init_from_minmax(struct BoundBox *bb, const float min[3], const float max[3]);
168 void BKE_boundbox_calc_center_aabb(const struct BoundBox *bb, float r_cent[3]);
169 void BKE_boundbox_calc_size_aabb(const struct BoundBox *bb, float r_size[3]);
170 void BKE_boundbox_minmax(const struct BoundBox *bb, float obmat[4][4], float r_min[3], float r_max[3]);
172 struct BoundBox *BKE_object_boundbox_get(struct Object *ob);
173 void BKE_object_dimensions_get(struct Object *ob, float vec[3]);
174 void BKE_object_dimensions_set(struct Object *ob, const float value[3], int axis_mask);
175 void BKE_object_empty_draw_type_set(struct Object *ob, const int value);
176 void BKE_object_boundbox_flag(struct Object *ob, int flag, const bool set);
177 void BKE_object_boundbox_calc_from_mesh(struct Object *ob, struct Mesh *me_eval);
178 void BKE_object_minmax(struct Object *ob, float r_min[3], float r_max[3], const bool use_hidden);
179 bool BKE_object_minmax_dupli(
180 struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob,
181 float r_min[3], float r_max[3], const bool use_hidden);
183 /* sometimes min-max isn't enough, we need to loop over each point */
184 void BKE_object_foreach_display_point(
185 struct Object *ob, float obmat[4][4],
186 void (*func_cb)(const float[3], void *), void *user_data);
187 void BKE_scene_foreach_display_point(
188 struct Depsgraph *depsgraph,
189 void (*func_cb)(const float[3], void *), void *user_data);
191 bool BKE_object_parent_loop_check(const struct Object *parent, const struct Object *ob);
193 void *BKE_object_tfm_backup(struct Object *ob);
194 void BKE_object_tfm_restore(struct Object *ob, void *obtfm_pt);
196 typedef struct ObjectTfmProtectedChannels {
197 float loc[3], dloc[3];
198 float scale[3], dscale[3];
199 float rot[3], drot[3];
200 float quat[4], dquat[4];
201 float rotAxis[3], drotAxis[3];
202 float rotAngle, drotAngle;
203 } ObjectTfmProtectedChannels;
205 void BKE_object_tfm_protected_backup(
206 const struct Object *ob,
207 ObjectTfmProtectedChannels *obtfm);
209 void BKE_object_tfm_protected_restore(
211 const ObjectTfmProtectedChannels *obtfm,
212 const short protectflag);
214 void BKE_object_tfm_copy(
215 struct Object *object_dst,
216 const struct Object *object_src);
218 void BKE_object_eval_reset(
219 struct Object *ob_eval);
221 /* Dependency graph evaluation callbacks. */
222 void BKE_object_eval_local_transform(
223 struct Depsgraph *depsgraph,
225 void BKE_object_eval_parent(
226 struct Depsgraph *depsgraph,
228 void BKE_object_eval_constraints(
229 struct Depsgraph *depsgraph,
232 void BKE_object_eval_transform_final(
233 struct Depsgraph *depsgraph, struct Object *ob);
235 bool BKE_object_eval_proxy_copy(
236 struct Depsgraph *depsgraph,
237 struct Object *object);
238 void BKE_object_eval_uber_transform(
239 struct Depsgraph *depsgraph,
241 void BKE_object_eval_uber_data(
242 struct Depsgraph *depsgraph,
246 void BKE_object_eval_boundbox(struct Depsgraph *depsgraph,
247 struct Object *object);
248 void BKE_object_synchronize_to_original(struct Depsgraph *depsgraph,
249 struct Object *object);
251 void BKE_object_eval_ptcache_reset(
252 struct Depsgraph *depsgraph,
254 struct Object *object);
256 void BKE_object_eval_transform_all(
257 struct Depsgraph *depsgraph,
259 struct Object *object);
261 void BKE_object_eval_update_shading(
262 struct Depsgraph *depsgraph,
263 struct Object *object);
264 void BKE_object_data_select_update(
265 struct Depsgraph *depsgraph,
266 struct ID *object_data);
268 void BKE_object_eval_eval_base_flags(
269 struct Depsgraph *depsgraph,
270 struct Scene *scene, const int view_layer_index,
271 struct Object *object, int base_index,
272 const bool is_from_set);
274 void BKE_object_handle_data_update(struct Depsgraph *depsgraph,
277 void BKE_object_handle_update(struct Depsgraph *depsgraph,
278 struct Scene *scene, struct Object *ob);
279 void BKE_object_handle_update_ex(
280 struct Depsgraph *depsgraph,
281 struct Scene *scene, struct Object *ob,
282 struct RigidBodyWorld *rbw,
283 const bool do_proxy_update);
284 void BKE_object_sculpt_modifiers_changed(struct Object *ob);
286 void BKE_object_sculpt_data_create(struct Object *ob);
288 int BKE_object_obdata_texspace_get(struct Object *ob, short **r_texflag, float **r_loc, float **r_size, float **r_rot);
290 struct Mesh *BKE_object_get_evaluated_mesh(const struct Depsgraph *depsgraph, struct Object *ob);
291 struct Mesh *BKE_object_get_final_mesh(struct Object *object);
292 struct Mesh *BKE_object_get_pre_modified_mesh(struct Object *object);
293 struct Mesh *BKE_object_get_original_mesh(struct Object *object);
295 int BKE_object_insert_ptcache(struct Object *ob);
296 void BKE_object_delete_ptcache(struct Object *ob, int index);
297 struct KeyBlock *BKE_object_shapekey_insert(struct Main *bmain, struct Object *ob, const char *name, const bool from_mix);
298 bool BKE_object_shapekey_remove(struct Main *bmain, struct Object *ob, struct KeyBlock *kb);
299 bool BKE_object_shapekey_free(struct Main *bmain, struct Object *ob);
301 bool BKE_object_flag_test_recursive(const struct Object *ob, short flag);
303 bool BKE_object_is_child_recursive(const struct Object *ob_parent, const struct Object *ob_child);
304 bool BKE_object_is_animated(struct Scene *scene, struct Object *ob);
306 /* return ModifierMode flag */
307 int BKE_object_is_modified(struct Scene *scene, struct Object *ob);
308 int BKE_object_is_deform_modified(struct Scene *scene, struct Object *ob);
310 int BKE_object_scenes_users_get(struct Main *bmain, struct Object *ob);
312 struct MovieClip *BKE_object_movieclip_get(struct Scene *scene, struct Object *ob, bool use_default);
314 void BKE_object_runtime_reset(struct Object *object);
315 void BKE_object_runtime_reset_on_copy(struct Object *object, const int flag);
317 void BKE_object_batch_cache_dirty_tag(struct Object *ob);
319 /* this function returns a superset of the scenes selection based on relationships */
321 typedef enum eObRelationTypes {
322 OB_REL_NONE = 0, /* just the selection as is */
323 OB_REL_PARENT = (1 << 0), /* immediate parent */
324 OB_REL_PARENT_RECURSIVE = (1 << 1), /* parents up to root of selection tree*/
325 OB_REL_CHILDREN = (1 << 2), /* immediate children */
326 OB_REL_CHILDREN_RECURSIVE = (1 << 3), /* All children */
327 OB_REL_MOD_ARMATURE = (1 << 4), /* Armatures related to the selected objects */
328 OB_REL_SCENE_CAMERA = (1 << 5), /* you might want the scene camera too even if unselected? */
331 typedef enum eObjectSet {
332 OB_SET_SELECTED, /* Selected Objects */
333 OB_SET_VISIBLE, /* Visible Objects */
334 OB_SET_ALL /* All Objects */
337 struct LinkNode *BKE_object_relational_superset(
338 struct ViewLayer *view_layer, eObjectSet objectSet, eObRelationTypes includeFilter);
339 struct LinkNode *BKE_object_groups(struct Main *bmain, struct Object *ob);
340 void BKE_object_groups_clear(struct Main *bmain, struct Object *object);
342 struct KDTree *BKE_object_as_kdtree(struct Object *ob, int *r_tot);
344 bool BKE_object_modifier_use_time(struct Object *ob, struct ModifierData *md);
346 bool BKE_object_modifier_update_subframe(
347 struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob,
348 bool update_mesh, int parent_recursion, float frame, int type);
350 void BKE_object_type_set_empty_for_versioning(struct Object *ob);
352 bool BKE_object_empty_image_is_visible_in_view3d(const struct Object *ob, const struct RegionView3D *rv3d);