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/makesrna/intern/rna_object_api.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/makesrna/intern/rna_object_api.c')
-rw-r--r--source/blender/makesrna/intern/rna_object_api.c40
1 files changed, 29 insertions, 11 deletions
diff --git a/source/blender/makesrna/intern/rna_object_api.c b/source/blender/makesrna/intern/rna_object_api.c
index d94abd4066a..da00e1f155d 100644
--- a/source/blender/makesrna/intern/rna_object_api.c
+++ b/source/blender/makesrna/intern/rna_object_api.c
@@ -375,11 +375,28 @@ static void rna_Object_camera_fit_coords(
}
/* copied from Mesh_getFromObject and adapted to RNA interface */
-static Mesh *rna_Object_to_mesh(Object *object, bContext *C, ReportList *reports)
+static Mesh *rna_Object_to_mesh(Object *object, ReportList *reports)
{
- Main *bmain = CTX_data_main(C);
+ /* TODO(sergey): Make it more re-usable function, de-duplicate with
+ * rna_Main_meshes_new_from_object. */
+ switch (object->type) {
+ case OB_FONT:
+ case OB_CURVE:
+ case OB_SURF:
+ case OB_MBALL:
+ case OB_MESH:
+ break;
+ default:
+ BKE_report(reports, RPT_ERROR, "Object does not have geometry data");
+ return NULL;
+ }
+
+ return BKE_object_to_mesh(object);
+}
- return rna_Main_meshes_new_from_object(bmain, reports, object);
+static void rna_Object_to_mesh_clear(Object *object)
+{
+ BKE_object_to_mesh_clear(object);
}
static PointerRNA rna_Object_shape_key_add(
@@ -875,16 +892,17 @@ void RNA_api_object(StructRNA *srna)
/* mesh */
func = RNA_def_function(srna, "to_mesh", "rna_Object_to_mesh");
- RNA_def_function_ui_description(func,
- "Create a Mesh data-block from the current state of the object");
- RNA_def_function_flag(func, FUNC_USE_REPORTS | FUNC_USE_CONTEXT);
- parm = RNA_def_pointer(func,
- "mesh",
- "Mesh",
- "",
- "Mesh created from object, remove it if it is only used for export");
+ RNA_def_function_ui_description(
+ func,
+ "Create a Mesh data-block from the current state of the object. The object owns the "
+ "data-block. To force free it use to_mesh_clear()");
+ RNA_def_function_flag(func, FUNC_USE_REPORTS);
+ parm = RNA_def_pointer(func, "mesh", "Mesh", "", "Mesh created from object");
RNA_def_function_return(func, parm);
+ func = RNA_def_function(srna, "to_mesh_clear", "rna_Object_to_mesh_clear");
+ RNA_def_function_ui_description(func, "Clears mesh data-block created by to_mesh()");
+
/* Armature */
func = RNA_def_function(srna, "find_armature", "modifiers_isDeformedByArmature");
RNA_def_function_ui_description(