diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2018-05-30 12:49:45 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2018-05-30 12:49:45 +0300 |
commit | edc1e65809d1c622a15dbe60330947149db4776f (patch) | |
tree | aa17ba7f970f25d1ebf4378a85993dae90af39f3 /source/blender/depsgraph/intern/eval | |
parent | 6afa0a7a50fdd579c4545a8b7718e79d4a6a78be (diff) |
Add deformed evaluated mesh to object
This is a first step to have correspondence of legacy derivedDeform
within a new formulation. Only base ground for now to support file
reading, copy-on-write remapping and such.
Diffstat (limited to 'source/blender/depsgraph/intern/eval')
-rw-r--r-- | source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc | 106 |
1 files changed, 62 insertions, 44 deletions
diff --git a/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc b/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc index 4d9f1f6b977..ad7467ffbdc 100644 --- a/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc +++ b/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc @@ -693,6 +693,64 @@ static void deg_update_copy_on_write_animation(const Depsgraph *depsgraph, IDWALK_NOP); } +typedef struct ObjectRuntimeBackup { + CurveCache *curve_cache; + Object_Runtime runtime; + short base_flag; +} ObjectRuntimeBackup; + +/* Make a backup of object's evaluation runtime data, additionally + * male object to be safe for free without invalidating backed up + * pointers. + */ +static void deg_backup_object_runtime( + Object *object, + ObjectRuntimeBackup *object_runtime_backup) +{ + /* Store evaluated mesh, and make sure we don't free it. */ + Mesh *mesh_eval = object->runtime.mesh_eval; + object_runtime_backup->runtime = object->runtime; + BKE_object_runtime_reset(object); + /* Currently 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 anything. + */ + if (mesh_eval != NULL && object->data == mesh_eval) { + object->data = mesh_eval->id.orig_id; + } + /* Store curve cache and make sure we don't free it. */ + object_runtime_backup->curve_cache = object->curve_cache; + object->curve_cache = NULL; + /* Make a backup of base flags. */ + object_runtime_backup->base_flag = object->base_flag; +} + +static void deg_restore_object_runtime( + Object *object, + const ObjectRuntimeBackup *object_runtime_backup) +{ + object->runtime = object_runtime_backup->runtime; + if (object->runtime.mesh_eval != NULL) { + Mesh *mesh_eval = object->runtime.mesh_eval; + /* Do same thing as object update: override actual object data + * pointer with evaluated datablock. + */ + if (object->type == OB_MESH) { + object->data = mesh_eval; + /* Evaluated mesh simply copied edit_btmesh pointer from + * original mesh during update, need to make sure no dead + * pointers are left behind. + */ + Mesh *mesh = ((Mesh *)mesh_eval->id.orig_id); + mesh_eval->edit_btmesh = mesh->edit_btmesh; + } + } + if (object_runtime_backup->curve_cache != NULL) { + object->curve_cache = object_runtime_backup->curve_cache; + } + object->base_flag = object_runtime_backup->base_flag; +} + ID *deg_update_copy_on_write_datablock(const Depsgraph *depsgraph, const IDDepsNode *id_node) { @@ -716,9 +774,7 @@ ID *deg_update_copy_on_write_datablock(const Depsgraph *depsgraph, */ ListBase gpumaterial_backup; ListBase *gpumaterial_ptr = NULL; - Mesh *mesh_eval = NULL; - CurveCache *curve_cache = NULL; - short base_flag = 0; + ObjectRuntimeBackup object_runtime_backup = {NULL}; if (check_datablock_expanded(id_cow)) { switch (id_type) { case ID_MA: @@ -753,28 +809,9 @@ ID *deg_update_copy_on_write_datablock(const Depsgraph *depsgraph, break; } case ID_OB: - { - Object *object = (Object *)id_cow; - /* Store evaluated mesh, make sure we don't free it. */ - mesh_eval = object->runtime.mesh_eval; - object->runtime.mesh_eval = NULL; - /* Currently 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 anything. - */ - if (mesh_eval != NULL) { - if (object->data == mesh_eval) { - object->data = mesh_eval->id.orig_id; - } - } - /* Store curve cache and make sure we don't free it. */ - curve_cache = object->curve_cache; - object->curve_cache = NULL; - - /* Make a backup of base flags. */ - base_flag = object->base_flag; + deg_backup_object_runtime((Object *)id_cow, + &object_runtime_backup); break; - } default: break; } @@ -790,26 +827,7 @@ ID *deg_update_copy_on_write_datablock(const Depsgraph *depsgraph, *gpumaterial_ptr = gpumaterial_backup; } if (id_type == ID_OB) { - Object *object = (Object *)id_cow; - if (mesh_eval != NULL) { - object->runtime.mesh_eval = mesh_eval; - /* Do same thing as object update: override actual object data - * pointer with evaluated datablock. - */ - if (object->type == OB_MESH) { - object->data = mesh_eval; - /* Evaluated mesh simply copied edit_btmesh pointer from - * original mesh during update, need to make sure no dead - * pointers are left behind. - */ - mesh_eval->edit_btmesh = - ((Mesh *)mesh_eval->id.orig_id)->edit_btmesh; - } - } - if (curve_cache != NULL) { - object->curve_cache = curve_cache; - } - object->base_flag = base_flag; + deg_restore_object_runtime((Object *)id_cow, &object_runtime_backup); } return id_cow; } |