Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Sharybin <sergey.vfx@gmail.com>2019-05-16 14:49:21 +0300
committerSergey Sharybin <sergey.vfx@gmail.com>2019-05-16 17:42:16 +0300
commit32d5d127cb49743578e8e1e9882d8a707a4e848e (patch)
tree72c18410ca6f3d503d8790bd936bc73273efb658 /source/blender/blenkernel/intern/object.c
parent22a91bb0bd6ac76142f832e0e07df0b5f9e8ead2 (diff)
Tweak API to support adding evaluated meshes to main database
One of the usecases is to create mesh from an object is a manner similar to how Apply Modifiers does it, and have it in the bmain so it can be referenced by other objects. This usecase is something what went unnoticed in the previous API changes, so here is a followup. Summary of changes: * bpy.meshes.new_from_object() behaves almost the same as before this change. The difference now is that it now ensures all referenced data-blocks are original (for example, materials referenced by the mesh). * object.to_mesh() now creates free-standing Mesh data-block which is outside of any bmain. The object owns it, which guarantees the memory never leaks. It is possible to force free memory by calling object.to_mesh_clear(). Reviewers: brecht Reviewed By: brecht Differential Revision: https://developer.blender.org/D4875
Diffstat (limited to 'source/blender/blenkernel/intern/object.c')
-rw-r--r--source/blender/blenkernel/intern/object.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index 78f2b10305e..95be7f8f51f 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -469,6 +469,7 @@ void BKE_object_free_derived_caches(Object *ob)
ob->runtime.mesh_deform_eval = NULL;
}
+ BKE_object_to_mesh_clear(ob);
BKE_object_free_curve_cache(ob);
/* clear grease pencil data */
@@ -4497,3 +4498,21 @@ void BKE_object_update_select_id(struct Main *bmain)
ob = ob->id.next;
}
}
+
+Mesh *BKE_object_to_mesh(Object *object)
+{
+ BKE_object_to_mesh_clear(object);
+
+ Mesh *mesh = BKE_mesh_new_from_object(object);
+ object->runtime.object_as_temp_mesh = mesh;
+ return mesh;
+}
+
+void BKE_object_to_mesh_clear(Object *object)
+{
+ if (object->runtime.object_as_temp_mesh == NULL) {
+ return;
+ }
+ BKE_id_free(NULL, object->runtime.object_as_temp_mesh);
+ object->runtime.object_as_temp_mesh = NULL;
+}