Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/object.c
| Show First 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | |||||
| #include "DNA_material_types.h" | #include "DNA_material_types.h" | ||||
| #include "DNA_meta_types.h" | #include "DNA_meta_types.h" | ||||
| #include "DNA_mesh_types.h" | #include "DNA_mesh_types.h" | ||||
| #include "DNA_meshdata_types.h" | #include "DNA_meshdata_types.h" | ||||
| #include "DNA_movieclip_types.h" | #include "DNA_movieclip_types.h" | ||||
| #include "DNA_scene_types.h" | #include "DNA_scene_types.h" | ||||
| #include "DNA_screen_types.h" | #include "DNA_screen_types.h" | ||||
| #include "DNA_sequence_types.h" | #include "DNA_sequence_types.h" | ||||
| #include "DNA_shader_fx_types.h" | |||||
| #include "DNA_smoke_types.h" | #include "DNA_smoke_types.h" | ||||
| #include "DNA_space_types.h" | #include "DNA_space_types.h" | ||||
| #include "DNA_view3d_types.h" | #include "DNA_view3d_types.h" | ||||
| #include "DNA_world_types.h" | #include "DNA_world_types.h" | ||||
| #include "DNA_object_types.h" | #include "DNA_object_types.h" | ||||
| #include "DNA_lightprobe_types.h" | #include "DNA_lightprobe_types.h" | ||||
| #include "DNA_rigidbody_types.h" | #include "DNA_rigidbody_types.h" | ||||
| ▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | |||||
| #include "BKE_object_facemap.h" | #include "BKE_object_facemap.h" | ||||
| #include "BKE_paint.h" | #include "BKE_paint.h" | ||||
| #include "BKE_particle.h" | #include "BKE_particle.h" | ||||
| #include "BKE_pointcache.h" | #include "BKE_pointcache.h" | ||||
| #include "BKE_lightprobe.h" | #include "BKE_lightprobe.h" | ||||
| #include "BKE_rigidbody.h" | #include "BKE_rigidbody.h" | ||||
| #include "BKE_scene.h" | #include "BKE_scene.h" | ||||
| #include "BKE_sequencer.h" | #include "BKE_sequencer.h" | ||||
| #include "BKE_shader_fx.h" | |||||
| #include "BKE_speaker.h" | #include "BKE_speaker.h" | ||||
| #include "BKE_softbody.h" | #include "BKE_softbody.h" | ||||
| #include "BKE_subsurf.h" | #include "BKE_subsurf.h" | ||||
| #include "BKE_material.h" | #include "BKE_material.h" | ||||
| #include "BKE_camera.h" | #include "BKE_camera.h" | ||||
| #include "BKE_image.h" | #include "BKE_image.h" | ||||
| #include "BKE_gpencil.h" | #include "BKE_gpencil.h" | ||||
| ▲ Show 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | void BKE_object_free_modifiers(Object *ob, const int flag) | ||||
| /* same for softbody */ | /* same for softbody */ | ||||
| BKE_object_free_softbody(ob); | BKE_object_free_softbody(ob); | ||||
| /* modifiers may have stored data in the DM cache */ | /* modifiers may have stored data in the DM cache */ | ||||
| BKE_object_free_derived_caches(ob); | BKE_object_free_derived_caches(ob); | ||||
| } | } | ||||
| void BKE_object_free_shaderfx(Object *ob, const int flag) | |||||
| { | |||||
| ShaderFxData *fx; | |||||
| while ((fx = BLI_pophead(&ob->shader_fx))) { | |||||
| BKE_shaderfx_free_ex(fx, flag); | |||||
| } | |||||
| } | |||||
| void BKE_object_modifier_hook_reset(Object *ob, HookModifierData *hmd) | void BKE_object_modifier_hook_reset(Object *ob, HookModifierData *hmd) | ||||
| { | { | ||||
| /* reset functionality */ | /* reset functionality */ | ||||
| if (hmd->object) { | if (hmd->object) { | ||||
| bPoseChannel *pchan = BKE_pose_channel_find_name(hmd->object->pose, hmd->subtarget); | bPoseChannel *pchan = BKE_pose_channel_find_name(hmd->object->pose, hmd->subtarget); | ||||
| if (hmd->subtarget[0] && pchan) { | if (hmd->subtarget[0] && pchan) { | ||||
| float imat[4][4], mat[4][4]; | float imat[4][4], mat[4][4]; | ||||
| ▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | bool BKE_object_support_modifier_type_check(const Object *ob, int modifier_type) | ||||
| return true; | return true; | ||||
| } | } | ||||
| void BKE_object_link_modifiers(Scene *scene, struct Object *ob_dst, const struct Object *ob_src) | void BKE_object_link_modifiers(Scene *scene, struct Object *ob_dst, const struct Object *ob_src) | ||||
| { | { | ||||
| ModifierData *md; | ModifierData *md; | ||||
| BKE_object_free_modifiers(ob_dst, 0); | BKE_object_free_modifiers(ob_dst, 0); | ||||
| if (!ELEM(ob_dst->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_LATTICE, OB_GPENCIL)) { | if (!ELEM(ob_dst->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_LATTICE)) { | ||||
| /* only objects listed above can have modifiers and linking them to objects | /* only objects listed above can have modifiers and linking them to objects | ||||
| * which doesn't have modifiers stack is quite silly */ | * which doesn't have modifiers stack is quite silly */ | ||||
| return; | return; | ||||
| } | } | ||||
| for (md = ob_src->modifiers.first; md; md = md->next) { | for (md = ob_src->modifiers.first; md; md = md->next) { | ||||
| ModifierData *nmd = NULL; | ModifierData *nmd = NULL; | ||||
| ▲ Show 20 Lines • Show All 158 Lines • ▼ Show 20 Lines | |||||
| /** Free (or release) any data used by this object (does not free the object itself). */ | /** Free (or release) any data used by this object (does not free the object itself). */ | ||||
| void BKE_object_free(Object *ob) | void BKE_object_free(Object *ob) | ||||
| { | { | ||||
| BKE_animdata_free((ID *)ob, false); | BKE_animdata_free((ID *)ob, false); | ||||
| /* BKE_<id>_free shall never touch to ID->us. Never ever. */ | /* BKE_<id>_free shall never touch to ID->us. Never ever. */ | ||||
| BKE_object_free_modifiers(ob, LIB_ID_CREATE_NO_USER_REFCOUNT); | BKE_object_free_modifiers(ob, LIB_ID_CREATE_NO_USER_REFCOUNT); | ||||
| BKE_object_free_shaderfx(ob, LIB_ID_CREATE_NO_USER_REFCOUNT); | |||||
| MEM_SAFE_FREE(ob->mat); | MEM_SAFE_FREE(ob->mat); | ||||
| MEM_SAFE_FREE(ob->matbits); | MEM_SAFE_FREE(ob->matbits); | ||||
| MEM_SAFE_FREE(ob->iuser); | MEM_SAFE_FREE(ob->iuser); | ||||
| MEM_SAFE_FREE(ob->bb); | MEM_SAFE_FREE(ob->bb); | ||||
| BLI_freelistN(&ob->defbase); | BLI_freelistN(&ob->defbase); | ||||
| BLI_freelistN(&ob->fmaps); | BLI_freelistN(&ob->fmaps); | ||||
| ▲ Show 20 Lines • Show All 753 Lines • ▼ Show 20 Lines | |||||
| * WARNING! This function will not handle ID user count! | * WARNING! This function will not handle ID user count! | ||||
| * | * | ||||
| * \param flag Copying options (see BKE_library.h's LIB_ID_COPY_... flags for more). | * \param flag Copying options (see BKE_library.h's LIB_ID_COPY_... flags for more). | ||||
| */ | */ | ||||
| void BKE_object_copy_data(Main *UNUSED(bmain), Object *ob_dst, const Object *ob_src, const int flag) | void BKE_object_copy_data(Main *UNUSED(bmain), Object *ob_dst, const Object *ob_src, const int flag) | ||||
| { | { | ||||
| ModifierData *md; | ModifierData *md; | ||||
| GpencilModifierData *gmd; | GpencilModifierData *gmd; | ||||
| ShaderFxData *fx; | |||||
| /* We never handle usercount here for own data. */ | /* We never handle usercount here for own data. */ | ||||
| const int flag_subdata = flag | LIB_ID_CREATE_NO_USER_REFCOUNT; | const int flag_subdata = flag | LIB_ID_CREATE_NO_USER_REFCOUNT; | ||||
| if (ob_src->totcol) { | if (ob_src->totcol) { | ||||
| ob_dst->mat = MEM_dupallocN(ob_src->mat); | ob_dst->mat = MEM_dupallocN(ob_src->mat); | ||||
| ob_dst->matbits = MEM_dupallocN(ob_src->matbits); | ob_dst->matbits = MEM_dupallocN(ob_src->matbits); | ||||
| ob_dst->totcol = ob_src->totcol; | ob_dst->totcol = ob_src->totcol; | ||||
| Show All 16 Lines | void BKE_object_copy_data(Main *UNUSED(bmain), Object *ob_dst, const Object *ob_src, const int flag) | ||||
| for (gmd = ob_src->greasepencil_modifiers.first; gmd; gmd = gmd->next) { | for (gmd = ob_src->greasepencil_modifiers.first; gmd; gmd = gmd->next) { | ||||
| GpencilModifierData *nmd = BKE_gpencil_modifier_new(gmd->type); | GpencilModifierData *nmd = BKE_gpencil_modifier_new(gmd->type); | ||||
| BLI_strncpy(nmd->name, gmd->name, sizeof(nmd->name)); | BLI_strncpy(nmd->name, gmd->name, sizeof(nmd->name)); | ||||
| BKE_gpencil_modifier_copyData_ex(gmd, nmd, flag_subdata); | BKE_gpencil_modifier_copyData_ex(gmd, nmd, flag_subdata); | ||||
| BLI_addtail(&ob_dst->greasepencil_modifiers, nmd); | BLI_addtail(&ob_dst->greasepencil_modifiers, nmd); | ||||
| } | } | ||||
| BLI_listbase_clear(&ob_dst->shader_fx); | |||||
| for (fx = ob_src->shader_fx.first; fx; fx = fx->next) { | |||||
| ShaderFxData *nfx = BKE_shaderfx_new(fx->type); | |||||
| BLI_strncpy(nfx->name, fx->name, sizeof(nfx->name)); | |||||
| BKE_shaderfx_copyData_ex(fx, nfx, flag_subdata); | |||||
| BLI_addtail(&ob_dst->shader_fx, nfx); | |||||
| } | |||||
| if (ob_src->pose) { | if (ob_src->pose) { | ||||
| copy_object_pose(ob_dst, ob_src, flag_subdata); | copy_object_pose(ob_dst, ob_src, flag_subdata); | ||||
| /* backwards compat... non-armatures can get poses in older files? */ | /* backwards compat... non-armatures can get poses in older files? */ | ||||
| if (ob_src->type == OB_ARMATURE) | if (ob_src->type == OB_ARMATURE) | ||||
| BKE_pose_rebuild(ob_dst, ob_dst->data); | BKE_pose_rebuild(ob_dst, ob_dst->data); | ||||
| } | } | ||||
| defgroup_copy_list(&ob_dst->defbase, &ob_src->defbase); | defgroup_copy_list(&ob_dst->defbase, &ob_src->defbase); | ||||
| BKE_object_facemap_copy_list(&ob_dst->fmaps, &ob_src->fmaps); | BKE_object_facemap_copy_list(&ob_dst->fmaps, &ob_src->fmaps); | ||||
| ▲ Show 20 Lines • Show All 2,552 Lines • ▼ Show 20 Lines | for (fcu = (FCurve *)adt->drivers.first; | ||||
| if (fcu->rna_path && strstr(fcu->rna_path, pattern)) | if (fcu->rna_path && strstr(fcu->rna_path, pattern)) | ||||
| return true; | return true; | ||||
| } | } | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| bool BKE_object_shaderfx_use_time(Object *ob, ShaderFxData *fx) | |||||
| { | |||||
| if (BKE_shaderfx_dependsOnTime(fx)) { | |||||
| return true; | |||||
| } | |||||
| /* Check whether effect is animated. */ | |||||
| /* TODO (Aligorith): this should be handled as part of build_animdata() */ | |||||
| if (ob->adt) { | |||||
| AnimData *adt = ob->adt; | |||||
| FCurve *fcu; | |||||
| char pattern[MAX_NAME + 32]; | |||||
| BLI_snprintf(pattern, sizeof(pattern), "shader_effects[\"%s\"]", fx->name); | |||||
| /* action - check for F-Curves with paths containing string[' */ | |||||
| if (adt->action) { | |||||
| for (fcu = (FCurve *)adt->action->curves.first; | |||||
| fcu != NULL; | |||||
| fcu = (FCurve *)fcu->next) | |||||
| { | |||||
| if (fcu->rna_path && strstr(fcu->rna_path, pattern)) | |||||
| return true; | |||||
| } | |||||
| } | |||||
| /* This here allows properties to get driven and still update properly | |||||
| * | |||||
| */ | |||||
| for (fcu = (FCurve *)adt->drivers.first; | |||||
| fcu != NULL; | |||||
| fcu = (FCurve *)fcu->next) | |||||
| { | |||||
| if (fcu->rna_path && strstr(fcu->rna_path, pattern)) | |||||
| return true; | |||||
| } | |||||
| } | |||||
| return false; | |||||
| } | |||||
| /* set "ignore cache" flag for all caches on this object */ | /* set "ignore cache" flag for all caches on this object */ | ||||
| static void object_cacheIgnoreClear(Object *ob, int state) | static void object_cacheIgnoreClear(Object *ob, int state) | ||||
| { | { | ||||
| ListBase pidlist; | ListBase pidlist; | ||||
| PTCacheID *pid; | PTCacheID *pid; | ||||
| BKE_ptcache_ids_from_object(&pidlist, ob, NULL, 0); | BKE_ptcache_ids_from_object(&pidlist, ob, NULL, 0); | ||||
| for (pid = pidlist.first; pid; pid = pid->next) { | for (pid = pidlist.first; pid; pid = pid->next) { | ||||
| ▲ Show 20 Lines • Show All 94 Lines • Show Last 20 Lines | |||||