Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/object.c
| Show First 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | |||||
| #include "BKE_DerivedMesh.h" | #include "BKE_DerivedMesh.h" | ||||
| #include "BKE_action.h" | #include "BKE_action.h" | ||||
| #include "BKE_anim_data.h" | #include "BKE_anim_data.h" | ||||
| #include "BKE_anim_path.h" | #include "BKE_anim_path.h" | ||||
| #include "BKE_anim_visualization.h" | #include "BKE_anim_visualization.h" | ||||
| #include "BKE_animsys.h" | #include "BKE_animsys.h" | ||||
| #include "BKE_armature.h" | #include "BKE_armature.h" | ||||
| #include "BKE_asset.h" | |||||
| #include "BKE_camera.h" | #include "BKE_camera.h" | ||||
| #include "BKE_collection.h" | #include "BKE_collection.h" | ||||
| #include "BKE_constraint.h" | #include "BKE_constraint.h" | ||||
| #include "BKE_curve.h" | #include "BKE_curve.h" | ||||
| #include "BKE_deform.h" | #include "BKE_deform.h" | ||||
| #include "BKE_displist.h" | #include "BKE_displist.h" | ||||
| #include "BKE_duplilist.h" | #include "BKE_duplilist.h" | ||||
| #include "BKE_editmesh.h" | #include "BKE_editmesh.h" | ||||
| ▲ Show 20 Lines • Show All 1,047 Lines • ▼ Show 20 Lines | static void object_lib_override_apply_post(ID *id_dst, ID *UNUSED(id_src)) | ||||
| LISTBASE_FOREACH (PTCacheID *, pid, &pidlist) { | LISTBASE_FOREACH (PTCacheID *, pid, &pidlist) { | ||||
| LISTBASE_FOREACH (PointCache *, point_cache, pid->ptcaches) { | LISTBASE_FOREACH (PointCache *, point_cache, pid->ptcaches) { | ||||
| point_cache->flag |= PTCACHE_FLAG_INFO_DIRTY; | point_cache->flag |= PTCACHE_FLAG_INFO_DIRTY; | ||||
| } | } | ||||
| } | } | ||||
| BLI_freelistN(&pidlist); | BLI_freelistN(&pidlist); | ||||
| } | } | ||||
| static IDProperty *object_asset_boundbox_hint_property(Object *ob) | |||||
| { | |||||
| BoundBox *boundbox = BKE_object_boundbox_get(ob); | |||||
Severin: Calculating the bounding box can be a bit expensive, I'd rather not do it on file save. But I… | |||||
| if (!boundbox) { | |||||
| return NULL; | |||||
| } | |||||
| IDPropertyTemplate idprop = {0}; | |||||
| idprop.array.len = sizeof(boundbox->vec) / sizeof(**boundbox->vec); | |||||
| idprop.array.type = IDP_FLOAT; | |||||
| IDProperty *property = IDP_New(IDP_ARRAY, &idprop, "boundbox_hint"); | |||||
| memcpy(IDP_Array(property), boundbox->vec, sizeof(boundbox->vec)); | |||||
| return property; | |||||
| } | |||||
| static IDProperty *object_asset_matrix_basis_property(Object *ob) | |||||
| { | |||||
| float mat[4][4]; | |||||
| IDPropertyTemplate idprop = {0}; | |||||
| idprop.array.len = sizeof(mat) / sizeof(**mat); | |||||
| idprop.array.type = IDP_FLOAT; | |||||
| IDProperty *property = IDP_New(IDP_ARRAY, &idprop, "matrix_basis"); | |||||
| BKE_object_to_mat4(ob, (float(*)[])IDP_Array(property)); | |||||
| return property; | |||||
| } | |||||
| static void object_asset_pre_save(void *asset_ptr, struct AssetMetaData *asset_data) | |||||
| { | |||||
| Object *ob = asset_ptr; | |||||
| BLI_assert(GS(ob->id.name) == ID_OB); | |||||
| /* Update bounding-box hint for the asset. */ | |||||
| IDProperty *boundbox_prop = object_asset_boundbox_hint_property(ob); | |||||
| if (boundbox_prop) { | |||||
| BKE_asset_metadata_idprop_ensure(asset_data, boundbox_prop); | |||||
| } | |||||
| /* Base matrix (object matrix without parent or constraint transforms). */ | |||||
| IDProperty *base_matrix_prop = object_asset_matrix_basis_property(ob); | |||||
| if (base_matrix_prop) { | |||||
| BKE_asset_metadata_idprop_ensure(asset_data, base_matrix_prop); | |||||
| } | |||||
| } | |||||
| AssetTypeInfo AssetType_OB = { | |||||
| .pre_save_fn = object_asset_pre_save, | |||||
| }; | |||||
| IDTypeInfo IDType_ID_OB = { | IDTypeInfo IDType_ID_OB = { | ||||
| .id_code = ID_OB, | .id_code = ID_OB, | ||||
| .id_filter = FILTER_ID_OB, | .id_filter = FILTER_ID_OB, | ||||
| .main_listbase_index = INDEX_ID_OB, | .main_listbase_index = INDEX_ID_OB, | ||||
| .struct_size = sizeof(Object), | .struct_size = sizeof(Object), | ||||
| .name = "Object", | .name = "Object", | ||||
| .name_plural = "objects", | .name_plural = "objects", | ||||
| .translation_context = BLT_I18NCONTEXT_ID_OBJECT, | .translation_context = BLT_I18NCONTEXT_ID_OBJECT, | ||||
| Show All 10 Lines | IDTypeInfo IDType_ID_OB = { | ||||
| .blend_write = object_blend_write, | .blend_write = object_blend_write, | ||||
| .blend_read_data = object_blend_read_data, | .blend_read_data = object_blend_read_data, | ||||
| .blend_read_lib = object_blend_read_lib, | .blend_read_lib = object_blend_read_lib, | ||||
| .blend_read_expand = object_blend_read_expand, | .blend_read_expand = object_blend_read_expand, | ||||
| .blend_read_undo_preserve = NULL, | .blend_read_undo_preserve = NULL, | ||||
| .lib_override_apply_post = object_lib_override_apply_post, | .lib_override_apply_post = object_lib_override_apply_post, | ||||
| .asset_type_info = &AssetType_OB, | |||||
| }; | }; | ||||
| void BKE_object_workob_clear(Object *workob) | void BKE_object_workob_clear(Object *workob) | ||||
| { | { | ||||
| memset(workob, 0, sizeof(Object)); | memset(workob, 0, sizeof(Object)); | ||||
| workob->scale[0] = workob->scale[1] = workob->scale[2] = 1.0f; | workob->scale[0] = workob->scale[1] = workob->scale[2] = 1.0f; | ||||
| workob->dscale[0] = workob->dscale[1] = workob->dscale[2] = 1.0f; | workob->dscale[0] = workob->dscale[1] = workob->dscale[2] = 1.0f; | ||||
| ▲ Show 20 Lines • Show All 1,846 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Object Matrix Get/Set API | /** \name Object Matrix Get/Set API | ||||
| * \{ */ | * \{ */ | ||||
| void BKE_object_scale_to_vec3(const Object *ob, float r_scale[3]) | |||||
| { | |||||
| mul_v3_v3v3(r_scale, ob->scale, ob->dscale); | |||||
| } | |||||
| void BKE_object_scale_to_mat3(Object *ob, float mat[3][3]) | void BKE_object_scale_to_mat3(Object *ob, float mat[3][3]) | ||||
| { | { | ||||
| float vec[3]; | float vec[3]; | ||||
| mul_v3_v3v3(vec, ob->scale, ob->dscale); | BKE_object_scale_to_vec3(ob, vec); | ||||
| size_to_mat3(mat, vec); | size_to_mat3(mat, vec); | ||||
| } | } | ||||
| void BKE_object_rot_to_mat3(const Object *ob, float mat[3][3], bool use_drot) | void BKE_object_rot_to_mat3(const Object *ob, float mat[3][3], bool use_drot) | ||||
| { | { | ||||
| float rmat[3][3], dmat[3][3]; | float rmat[3][3], dmat[3][3]; | ||||
| /* 'dmat' is the delta-rotation matrix, which will get (pre)multiplied | /* 'dmat' is the delta-rotation matrix, which will get (pre)multiplied | ||||
| ▲ Show 20 Lines • Show All 2,738 Lines • Show Last 20 Lines | |||||
Calculating the bounding box can be a bit expensive, I'd rather not do it on file save. But I think at this point it's usually already calculated, so think this is nothing to worry about.
This should be double-checked though.