From 32d5d127cb49743578e8e1e9882d8a707a4e848e Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Thu, 16 May 2019 13:49:21 +0200 Subject: 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 --- source/blender/blenkernel/BKE_object.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'source/blender/blenkernel/BKE_object.h') diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h index c373fbfe478..aa4d9696527 100644 --- a/source/blender/blenkernel/BKE_object.h +++ b/source/blender/blenkernel/BKE_object.h @@ -396,6 +396,15 @@ bool BKE_object_empty_image_frame_is_visible_in_view3d(const struct Object *ob, bool BKE_object_empty_image_data_is_visible_in_view3d(const struct Object *ob, const struct RegionView3D *rv3d); +/* This is an utility function for Python's object.to_mesh() (the naming is not very clear though). + * The result is owned by the object. + * + * The mesh will be freed when object is re-evaluated or is destroyed. It is possible to force to + * clear memory sued by this mesh by calling BKE_object_to_mesh_clear(). */ +struct Mesh *BKE_object_to_mesh(struct Object *object); + +void BKE_object_to_mesh_clear(struct Object *object); + #ifdef __cplusplus } #endif -- cgit v1.2.3