[Bf-blender-cvs] [6320749] cycles_memory: Add an option to mesh.calc_tessface() to get rid of polygons and loops

Sergey Sharybin noreply at git.blender.org
Fri Feb 27 07:56:29 CET 2015


Commit: 6320749361f59ed9942d08e1a99db75c358b6ecd
Author: Sergey Sharybin
Date:   Wed Feb 18 22:47:23 2015 +0500
Branches: cycles_memory
https://developer.blender.org/rB6320749361f59ed9942d08e1a99db75c358b6ecd

Add an option to mesh.calc_tessface() to get rid of polygons and loops

The purpose of this change is to add extra possibility to render engines and
export scripts to reduce peak memory footprint during their operation.

This new argument should be used with care since it'll leave mesh in not really
compatible with blender format, but it's ok to be used on temp meshes.

Unfortunately, it's hard to get scene where it'll show huge benefit because
in my tests with cycles peak memory is reached in MEM_printmemlist_stats().

However, in the file with sintel dragon it gives around 1gig of memory benefit
after removing the polys which would allow other heavy to compute stuff such as
hair (or even pointiness calculation) to not be a peak memory usage.

In any case, this change is nice to have IMO, and only means more parts of
scene export code should be optimized memory-wise.

Reviewers: campbellbarton

Differential Revision: https://developer.blender.org/D1125

===================================================================

M	intern/cycles/blender/blender_util.h
M	source/blender/editors/include/ED_mesh.h
M	source/blender/editors/mesh/mesh_data.c
M	source/blender/makesrna/intern/rna_mesh_api.c

===================================================================

diff --git a/intern/cycles/blender/blender_util.h b/intern/cycles/blender/blender_util.h
index 64fc352..9f7181c 100644
--- a/intern/cycles/blender/blender_util.h
+++ b/intern/cycles/blender/blender_util.h
@@ -47,7 +47,7 @@ static inline BL::Mesh object_to_mesh(BL::BlendData data, BL::Object object, BL:
 		if (me.use_auto_smooth()) {
 			me.calc_normals_split();
 		}
-		me.calc_tessface();
+		me.calc_tessface(true);
 	}
 	return me;
 }
diff --git a/source/blender/editors/include/ED_mesh.h b/source/blender/editors/include/ED_mesh.h
index 8eb7fdf..ccf9722 100644
--- a/source/blender/editors/include/ED_mesh.h
+++ b/source/blender/editors/include/ED_mesh.h
@@ -256,7 +256,7 @@ void ED_mesh_faces_remove(struct Mesh *mesh, struct ReportList *reports, int cou
 void ED_mesh_edges_remove(struct Mesh *mesh, struct ReportList *reports, int count);
 void ED_mesh_vertices_remove(struct Mesh *mesh, struct ReportList *reports, int count);
 
-void ED_mesh_calc_tessface(struct Mesh *mesh);
+void ED_mesh_calc_tessface(struct Mesh *mesh, bool free_mpoly);
 void ED_mesh_update(struct Mesh *mesh, struct bContext *C, int calc_edges, int calc_tessface);
 
 void ED_mesh_uv_texture_ensure(struct Mesh *me, const char *name);
diff --git a/source/blender/editors/mesh/mesh_data.c b/source/blender/editors/mesh/mesh_data.c
index 30e9a85..86991d7 100644
--- a/source/blender/editors/mesh/mesh_data.c
+++ b/source/blender/editors/mesh/mesh_data.c
@@ -1235,7 +1235,7 @@ void ED_mesh_polys_add(Mesh *mesh, ReportList *reports, int count)
 	mesh_add_polys(mesh, count);
 }
 
-void ED_mesh_calc_tessface(Mesh *mesh)
+void ED_mesh_calc_tessface(Mesh *mesh, bool free_mpoly)
 {
 	if (mesh->edit_btmesh) {
 		BKE_editmesh_tessface_calc(mesh->edit_btmesh);
@@ -1243,6 +1243,17 @@ void ED_mesh_calc_tessface(Mesh *mesh)
 	else {
 		BKE_mesh_tessface_calc(mesh);
 	}
+	if (free_mpoly) {
+		CustomData_free(&mesh->ldata, mesh->totloop);
+		CustomData_free(&mesh->pdata, mesh->totpoly);
+		mesh->totloop = 0;
+		mesh->totpoly = 0;
+		mesh->mloop = NULL;
+		mesh->mloopcol = NULL;
+		mesh->mloopuv = NULL;
+		mesh->mpoly = NULL;
+		mesh->mtpoly = NULL;
+	}
 }
 
 void ED_mesh_report_mirror_ex(wmOperator *op, int totmirr, int totfail,
diff --git a/source/blender/makesrna/intern/rna_mesh_api.c b/source/blender/makesrna/intern/rna_mesh_api.c
index 53704e2..1b7d633 100644
--- a/source/blender/makesrna/intern/rna_mesh_api.c
+++ b/source/blender/makesrna/intern/rna_mesh_api.c
@@ -141,6 +141,11 @@ static void rna_Mesh_free_tangents(Mesh *mesh)
 	CustomData_free_layers(&mesh->ldata, CD_MLOOPTANGENT, mesh->totloop);
 }
 
+static void rna_Mesh_calc_tessface(Mesh *mesh, int free_mpoly)
+{
+	ED_mesh_calc_tessface(mesh, free_mpoly != 0);
+}
+
 static void rna_Mesh_calc_smooth_groups(Mesh *mesh, int use_bitflags, int *r_poly_group_len,
                                         int **r_poly_group, int *r_group_total)
 {
@@ -269,8 +274,12 @@ void RNA_api_mesh(StructRNA *srna)
 	func = RNA_def_function(srna, "free_tangents", "rna_Mesh_free_tangents");
 	RNA_def_function_ui_description(func, "Free tangents");
 
-	func = RNA_def_function(srna, "calc_tessface", "ED_mesh_calc_tessface");
+	func = RNA_def_function(srna, "calc_tessface", "rna_Mesh_calc_tessface");
 	RNA_def_function_ui_description(func, "Calculate face tessellation (supports editmode too)");
+	RNA_def_boolean(func, "free_mpoly", 0, "Free MPoly", "Free data used by polygons and loops. "
+	                "WARNING: This destructive operation removes regular faces, "
+	                "only used on temporary mesh data-blocks to reduce memory footprint of render "
+	                "engines and export scripts.");
 
 	func = RNA_def_function(srna, "calc_smooth_groups", "rna_Mesh_calc_smooth_groups");
 	RNA_def_function_ui_description(func, "Calculate smooth groups from sharp edges");




More information about the Bf-blender-cvs mailing list