[Bf-blender-cvs] [0c4b2cddf8e] temp-modifier-rm-cddm: Ported Array modifier

Sybren A. Stüvel noreply at git.blender.org
Wed Apr 25 16:57:44 CEST 2018


Commit: 0c4b2cddf8e0456046c17bf45bff79649db69995
Author: Sybren A. Stüvel
Date:   Wed Apr 25 16:47:52 2018 +0200
Branches: temp-modifier-rm-cddm
https://developer.blender.org/rB0c4b2cddf8e0456046c17bf45bff79649db69995

Ported Array modifier

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

M	source/blender/modifiers/intern/MOD_array.c
M	source/blender/modifiers/intern/MOD_util.c
M	source/blender/modifiers/intern/MOD_util.h

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

diff --git a/source/blender/modifiers/intern/MOD_array.c b/source/blender/modifiers/intern/MOD_array.c
index b5ebe7b885f..0e872d3f145 100644
--- a/source/blender/modifiers/intern/MOD_array.c
+++ b/source/blender/modifiers/intern/MOD_array.c
@@ -41,6 +41,7 @@
 #include "BLI_utildefines.h"
 
 #include "DNA_curve_types.h"
+#include "DNA_mesh_types.h"
 #include "DNA_meshdata_types.h"
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
@@ -273,8 +274,8 @@ static void dm_mvert_map_doubles(
 }
 
 
-static void dm_merge_transform(
-        DerivedMesh *result, DerivedMesh *cap_dm, float cap_offset[4][4],
+static void mesh_merge_transform(
+        Mesh *result, Mesh *cap_mesh, float cap_offset[4][4],
         unsigned int cap_verts_index, unsigned int cap_edges_index, int cap_loops_index, int cap_polys_index,
         int cap_nverts, int cap_nedges, int cap_nloops, int cap_npolys, int *remap, int remap_len)
 {
@@ -286,18 +287,12 @@ static void dm_merge_transform(
 	MPoly *mp;
 	MDeformVert *dvert;
 
-	/* needed for subsurf so arrays are allocated */
-	cap_dm->getVertArray(cap_dm);
-	cap_dm->getEdgeArray(cap_dm);
-	cap_dm->getLoopArray(cap_dm);
-	cap_dm->getPolyArray(cap_dm);
+	CustomData_copy_data(&cap_mesh->vdata, &result->vdata, 0, cap_verts_index, cap_nverts);
+	CustomData_copy_data(&cap_mesh->edata, &result->edata, 0, cap_edges_index, cap_nedges);
+	CustomData_copy_data(&cap_mesh->ldata, &result->ldata, 0, cap_loops_index, cap_nloops);
+	CustomData_copy_data(&cap_mesh->pdata, &result->pdata, 0, cap_polys_index, cap_npolys);
 
-	DM_copy_vert_data(cap_dm, result, 0, cap_verts_index, cap_nverts);
-	DM_copy_edge_data(cap_dm, result, 0, cap_edges_index, cap_nedges);
-	DM_copy_loop_data(cap_dm, result, 0, cap_loops_index, cap_nloops);
-	DM_copy_poly_data(cap_dm, result, 0, cap_polys_index, cap_npolys);
-
-	mv = CDDM_get_verts(result) + cap_verts_index;
+	mv = result->mvert + cap_verts_index;
 
 	for (i = 0; i < cap_nverts; i++, mv++) {
 		mul_m4_v3(cap_offset, mv->co);
@@ -306,55 +301,55 @@ static void dm_merge_transform(
 	}
 
 	/* remap the vertex groups if necessary */
-	dvert = DM_get_vert_data(result, cap_verts_index, CD_MDEFORMVERT);
+	dvert = result->dvert + cap_verts_index;
 	if (dvert != NULL) {
 		BKE_object_defgroup_index_map_apply(dvert, cap_nverts, remap, remap_len);
 	}
 
 	/* adjust cap edge vertex indices */
-	me = CDDM_get_edges(result) + cap_edges_index;
+	me = result->medge + cap_edges_index;
 	for (i = 0; i < cap_nedges; i++, me++) {
 		me->v1 += cap_verts_index;
 		me->v2 += cap_verts_index;
 	}
 
 	/* adjust cap poly loopstart indices */
-	mp = CDDM_get_polys(result) + cap_polys_index;
+	mp = result->mpoly + cap_polys_index;
 	for (i = 0; i < cap_npolys; i++, mp++) {
 		mp->loopstart += cap_loops_index;
 	}
 
 	/* adjust cap loop vertex and edge indices */
-	ml = CDDM_get_loops(result) + cap_loops_index;
+	ml = result->mloop + cap_loops_index;
 	for (i = 0; i < cap_nloops; i++, ml++) {
 		ml->v += cap_verts_index;
 		ml->e += cap_edges_index;
 	}
 
 	/* set origindex */
-	index_orig = result->getVertDataArray(result, CD_ORIGINDEX);
+	index_orig = CustomData_get_layer(&result->vdata, CD_ORIGINDEX);
 	if (index_orig) {
 		copy_vn_i(index_orig + cap_verts_index, cap_nverts, ORIGINDEX_NONE);
 	}
 
-	index_orig = result->getEdgeDataArray(result, CD_ORIGINDEX);
+	index_orig = CustomData_get_layer(&result->edata, CD_ORIGINDEX);
 	if (index_orig) {
 		copy_vn_i(index_orig + cap_edges_index, cap_nedges, ORIGINDEX_NONE);
 	}
 
-	index_orig = result->getPolyDataArray(result, CD_ORIGINDEX);
+	index_orig = CustomData_get_layer(&result->pdata, CD_ORIGINDEX);
 	if (index_orig) {
 		copy_vn_i(index_orig + cap_polys_index, cap_npolys, ORIGINDEX_NONE);
 	}
 
-	index_orig = result->getLoopDataArray(result, CD_ORIGINDEX);
+	index_orig = CustomData_get_layer(&result->ldata, CD_ORIGINDEX);
 	if (index_orig) {
 		copy_vn_i(index_orig + cap_loops_index, cap_nloops, ORIGINDEX_NONE);
 	}
 }
 
-static DerivedMesh *arrayModifier_doArray(
-        ArrayModifierData *amd, Object *ob, DerivedMesh *dm,
+static Mesh *arrayModifier_doArray(
+        ArrayModifierData *amd, Object *ob, Mesh *mesh,
         ModifierApplyFlag flag)
 {
 	const float eps = 1e-6f;
@@ -376,7 +371,7 @@ static DerivedMesh *arrayModifier_doArray(
 	int tot_doubles;
 
 	const bool use_merge = (amd->flags & MOD_ARR_MERGE) != 0;
-	const bool use_recalc_normals = (dm->dirty & DM_DIRTY_NORMALS) || use_merge;
+	const bool use_recalc_normals = /* (dm->dirty & DM_DIRTY_NORMALS) || */ use_merge;
 	const bool use_offset_ob = ((amd->offset_type & MOD_ARR_OFF_OBJ) && amd->offset_ob);
 
 	int start_cap_nverts = 0, start_cap_nedges = 0, start_cap_npolys = 0, start_cap_nloops = 0;
@@ -385,47 +380,47 @@ static DerivedMesh *arrayModifier_doArray(
 	int chunk_nverts, chunk_nedges, chunk_nloops, chunk_npolys;
 	int first_chunk_start, first_chunk_nverts, last_chunk_start, last_chunk_nverts;
 
-	DerivedMesh *result, *start_cap_dm = NULL, *end_cap_dm = NULL;
+	Mesh *result, *start_cap_mesh = NULL, *end_cap_mesh = NULL;
 
 	int *vgroup_start_cap_remap = NULL;
 	int vgroup_start_cap_remap_len = 0;
 	int *vgroup_end_cap_remap = NULL;
 	int vgroup_end_cap_remap_len = 0;
 
-	chunk_nverts = dm->getNumVerts(dm);
-	chunk_nedges = dm->getNumEdges(dm);
-	chunk_nloops = dm->getNumLoops(dm);
-	chunk_npolys = dm->getNumPolys(dm);
+	chunk_nverts = mesh->totvert;
+	chunk_nedges = mesh->totedge;
+	chunk_nloops = mesh->totloop;
+	chunk_npolys = mesh->totpoly;
 
 	count = amd->count;
 
 	if (amd->start_cap && amd->start_cap != ob && amd->start_cap->type == OB_MESH) {
 		vgroup_start_cap_remap = BKE_object_defgroup_index_map_create(amd->start_cap, ob, &vgroup_start_cap_remap_len);
 
-		start_cap_dm = get_dm_for_modifier(amd->start_cap, flag);
-		if (start_cap_dm) {
-			start_cap_nverts = start_cap_dm->getNumVerts(start_cap_dm);
-			start_cap_nedges = start_cap_dm->getNumEdges(start_cap_dm);
-			start_cap_nloops = start_cap_dm->getNumLoops(start_cap_dm);
-			start_cap_npolys = start_cap_dm->getNumPolys(start_cap_dm);
+		start_cap_mesh = get_mesh_eval_for_modifier(amd->start_cap, flag);
+		if (start_cap_mesh) {
+			start_cap_nverts = start_cap_mesh->totvert;
+			start_cap_nedges = start_cap_mesh->totedge;
+			start_cap_nloops = start_cap_mesh->totloop;
+			start_cap_npolys = start_cap_mesh->totpoly;
 		}
 	}
 	if (amd->end_cap && amd->end_cap != ob && amd->end_cap->type == OB_MESH) {
 		vgroup_end_cap_remap = BKE_object_defgroup_index_map_create(amd->end_cap, ob, &vgroup_end_cap_remap_len);
 
-		end_cap_dm = get_dm_for_modifier(amd->end_cap, flag);
-		if (end_cap_dm) {
-			end_cap_nverts = end_cap_dm->getNumVerts(end_cap_dm);
-			end_cap_nedges = end_cap_dm->getNumEdges(end_cap_dm);
-			end_cap_nloops = end_cap_dm->getNumLoops(end_cap_dm);
-			end_cap_npolys = end_cap_dm->getNumPolys(end_cap_dm);
+		end_cap_mesh = get_mesh_eval_for_modifier(amd->end_cap, flag);
+		if (end_cap_mesh) {
+			end_cap_nverts = end_cap_mesh->totvert;
+			end_cap_nedges = end_cap_mesh->totedge;
+			end_cap_nloops = end_cap_mesh->totloop;
+			end_cap_npolys = end_cap_mesh->totpoly;
 		}
 	}
 
 	/* Build up offset array, cumulating all settings options */
 
 	unit_m4(offset);
-	src_mvert = dm->getVertArray(dm);
+	src_mvert = mesh->mvert;
 
 	if (amd->offset_type & MOD_ARR_OFF_CONST) {
 		add_v3_v3(offset[3], amd->offset);
@@ -499,8 +494,8 @@ static DerivedMesh *arrayModifier_doArray(
 	result_npolys = chunk_npolys * count + start_cap_npolys + end_cap_npolys;
 
 	/* Initialize a result dm */
-	result = CDDM_from_template(dm, result_nverts, result_nedges, 0, result_nloops, result_npolys);
-	result_dm_verts = CDDM_get_verts(result);
+	result = BKE_mesh_from_template(mesh, result_nverts, result_nedges, 0, result_nloops, result_npolys);
+	result_dm_verts = result->mvert;
 
 	if (use_merge) {
 		/* Will need full_doubles_map for handling merge */
@@ -509,23 +504,22 @@ static DerivedMesh *arrayModifier_doArray(
 	}
 
 	/* copy customdata to original geometry */
-	DM_copy_vert_data(dm, result, 0, 0, chunk_nverts);
-	DM_copy_edge_data(dm, result, 0, 0, chunk_nedges);
-	DM_copy_loop_data(dm, result, 0, 0, chunk_nloops);
-	DM_copy_poly_data(dm, result, 0, 0, chunk_npolys);
+	CustomData_copy_data(&mesh->vdata, &result->vdata, 0, 0, chunk_nverts);
+	CustomData_copy_data(&mesh->edata, &result->edata, 0, 0, chunk_nedges);
+	CustomData_copy_data(&mesh->ldata, &result->ldata, 0, 0, chunk_nloops);
+	CustomData_copy_data(&mesh->pdata, &result->pdata, 0, 0, chunk_npolys);
 
 	/* Subsurf for eg wont have mesh data in the custom data arrays.
 	 * now add mvert/medge/mpoly layers. */
-
-	if (!CustomData_has_layer(&dm->vertData, CD_MVERT)) {
-		dm->copyVertArray(dm, result_dm_verts);
+	if (!CustomData_has_layer(&mesh->vdata, CD_MVERT)) {
+		memcpy(result->mvert, mesh->mvert, sizeof(*result->mvert) * mesh->totvert);
 	}
-	if (!CustomData_has_layer(&dm->edgeData, CD_MEDGE)) {
-		dm->copyEdgeArray(dm, CDDM_get_edges(result));
+	if (!CustomData_has_layer(&mesh->edata, CD_MEDGE)) {
+		memcpy(result->medge, mesh->medge, sizeof(*result->medge) * mesh->totedge);
 	}
-	if (!CustomData_has_layer(&dm->polyData, CD_MPOLY)) {
-		dm->copyLoopArray(dm, CDDM_get_loops(result));
-		dm->copyPolyArray(dm, CDDM_get_polys(result));
+	if (!CustomData_has_layer(&mesh->pdata, CD_MPOLY)) {
+		memcpy(result->mloop, mesh->mloop, sizeof(*result->mloop) * mesh->totloop);
+		memcpy(result->mpoly, mesh->mpoly, sizeof(*result->mpoly) * mesh->totpoly);
 	}
 
 	/* Remember first chunk, in case of cap merge */
@@ -535,10 +529,10 @@ static DerivedMesh *arrayModifier_doArray(
 	unit_m4(current_offset);
 	for (c = 1; c < count; c++) {
 		/* copy customdata to new geometry */
-		DM_copy_vert_data(result, result, 0, c * chunk_nverts, chunk_nverts);
-		DM_copy_edge_data(result, result, 0, c * chunk_nedges, chunk_nedges);
-		DM_copy_loop_data(result, result, 0, c * chunk_nloops, chunk_nloops);
-		DM_copy_poly_data(result, result, 0, c * chunk_npolys, chunk_npolys);
+		CustomData_copy_data(&mesh->vdata, &result->vdata, 0, c * chunk_nverts, chunk_nverts);
+		CustomData_copy_data(&mesh->edata, &result->edata, 0, c * chunk_nedges, chunk_nedges);
+		CustomData_copy_data(&mesh->ldata, &result->ldata, 0, c * chunk_nloops, c

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list