Differential D6695 Diff 22100 source/blender/depsgraph/intern/eval/deg_eval_runtime_backup_object.cc
Changeset View
Changeset View
Standalone View
Standalone View
source/blender/depsgraph/intern/eval/deg_eval_runtime_backup_object.cc
| Show All 38 Lines | |||||
| { | { | ||||
| /* TODO(sergey): Use something like BKE_object_runtime_reset(). */ | /* TODO(sergey): Use something like BKE_object_runtime_reset(). */ | ||||
| memset(&runtime, 0, sizeof(runtime)); | memset(&runtime, 0, sizeof(runtime)); | ||||
| } | } | ||||
| void ObjectRuntimeBackup::init_from_object(Object *object) | void ObjectRuntimeBackup::init_from_object(Object *object) | ||||
| { | { | ||||
| /* Store evaluated mesh and curve_cache, and make sure we don't free it. */ | /* Store evaluated mesh and curve_cache, and make sure we don't free it. */ | ||||
| Mesh *mesh_eval = object->runtime.mesh_eval; | |||||
| runtime = object->runtime; | runtime = object->runtime; | ||||
| BKE_object_runtime_reset(object); | BKE_object_runtime_reset(object); | ||||
| /* Keep bbox (for now at least). */ | /* Keep bbox (for now at least). */ | ||||
| object->runtime.bb = runtime.bb; | object->runtime.bb = runtime.bb; | ||||
| /* Object update will override actual object->data to an evaluated version. | /* Object update will override actual object->data to an evaluated version. | ||||
| * Need to make sure we don't have data set to evaluated one before free | * Need to make sure we don't have data set to evaluated one before free | ||||
| * anything. */ | * anything. */ | ||||
| if (mesh_eval != nullptr && object->data == mesh_eval) { | object->data = runtime.data_orig; | ||||
| object->data = runtime.mesh_orig; | |||||
| } | |||||
| /* Make a backup of base flags. */ | /* Make a backup of base flags. */ | ||||
| base_flag = object->base_flag; | base_flag = object->base_flag; | ||||
| base_local_view_bits = object->base_local_view_bits; | base_local_view_bits = object->base_local_view_bits; | ||||
| /* Backup tuntime data of all modifiers. */ | /* Backup tuntime data of all modifiers. */ | ||||
| backup_modifier_runtime_data(object); | backup_modifier_runtime_data(object); | ||||
| /* Backup runtime data of all pose channels. */ | /* Backup runtime data of all pose channels. */ | ||||
| backup_pose_channel_runtime_data(object); | backup_pose_channel_runtime_data(object); | ||||
| } | } | ||||
| Show All 27 Lines | LISTBASE_FOREACH (bPoseChannel *, pchan, &object->pose->chanbase) { | ||||
| BKE_pose_channel_runtime_reset(&pchan->runtime); | BKE_pose_channel_runtime_reset(&pchan->runtime); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| void ObjectRuntimeBackup::restore_to_object(Object *object) | void ObjectRuntimeBackup::restore_to_object(Object *object) | ||||
| { | { | ||||
| Mesh *mesh_orig = object->runtime.mesh_orig; | ID *data_orig = object->runtime.data_orig; | ||||
| ID *data_eval = object->runtime.data_eval; | |||||
| BoundBox *bb = object->runtime.bb; | BoundBox *bb = object->runtime.bb; | ||||
| object->runtime = runtime; | object->runtime = runtime; | ||||
| object->runtime.mesh_orig = mesh_orig; | object->runtime.data_orig = data_orig; | ||||
| object->runtime.bb = bb; | object->runtime.bb = bb; | ||||
| if (object->type == OB_MESH && object->runtime.mesh_eval != nullptr) { | if (object->type == OB_MESH && data_eval != nullptr) { | ||||
| if (object->id.recalc & ID_RECALC_GEOMETRY) { | if (object->id.recalc & ID_RECALC_GEOMETRY) { | ||||
| /* If geometry is tagged for update it means, that part of | /* If geometry is tagged for update it means, that part of | ||||
| * evaluated mesh are not valid anymore. In this case we can not | * evaluated mesh are not valid anymore. In this case we can not | ||||
| * have any "persistent" pointers to point to an invalid data. | * have any "persistent" pointers to point to an invalid data. | ||||
| * | * | ||||
| * We restore object's data datablock to an original copy of | * We restore object's data datablock to an original copy of | ||||
| * that datablock. */ | * that datablock. */ | ||||
| object->data = mesh_orig; | object->data = data_orig; | ||||
| /* After that, immediately free the invalidated caches. */ | /* After that, immediately free the invalidated caches. */ | ||||
| BKE_object_free_derived_caches(object); | BKE_object_free_derived_caches(object); | ||||
| } | } | ||||
| else { | else { | ||||
| Mesh *mesh_eval = object->runtime.mesh_eval; | |||||
| /* Do same thing as object update: override actual object data | /* Do same thing as object update: override actual object data | ||||
| * pointer with evaluated datablock. */ | * pointer with evaluated datablock. */ | ||||
| object->data = mesh_eval; | object->data = data_eval; | ||||
| /* Evaluated mesh simply copied edit_mesh pointer from | /* Evaluated mesh simply copied edit_mesh pointer from | ||||
| * original mesh during update, need to make sure no dead | * original mesh during update, need to make sure no dead | ||||
| * pointers are left behind. */ | * pointers are left behind. */ | ||||
| if (object->type == OB_MESH) { | |||||
| Mesh *mesh_eval = (Mesh *)data_eval; | |||||
| Mesh *mesh_orig = (Mesh *)data_orig; | |||||
| mesh_eval->edit_mesh = mesh_orig->edit_mesh; | mesh_eval->edit_mesh = mesh_orig->edit_mesh; | ||||
| } | } | ||||
| } | } | ||||
| } | |||||
| object->base_flag = base_flag; | object->base_flag = base_flag; | ||||
| object->base_local_view_bits = base_local_view_bits; | object->base_local_view_bits = base_local_view_bits; | ||||
| /* Restore modifier's runtime data. | /* Restore modifier's runtime data. | ||||
| * NOTE: Data of unused modifiers will be freed there. */ | * NOTE: Data of unused modifiers will be freed there. */ | ||||
| restore_modifier_runtime_data(object); | restore_modifier_runtime_data(object); | ||||
| restore_pose_channel_runtime_data(object); | restore_pose_channel_runtime_data(object); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 45 Lines • Show Last 20 Lines | |||||