[Bf-blender-cvs] [4f55a3a] temp-derivedmesh-looptri: Re-Branch temp-derivedmesh-looptri against master

Campbell Barton noreply at git.blender.org
Wed Jul 15 08:37:40 CEST 2015


Commit: 4f55a3aec7ca266fcb0967434043544d188b20f8
Author: Campbell Barton
Date:   Wed Jul 15 16:32:50 2015 +1000
Branches: temp-derivedmesh-looptri
https://developer.blender.org/rB4f55a3aec7ca266fcb0967434043544d188b20f8

Re-Branch temp-derivedmesh-looptri against master

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

M	source/blender/blenkernel/BKE_DerivedMesh.h
M	source/blender/blenkernel/BKE_cdderivedmesh.h
M	source/blender/blenkernel/BKE_mesh.h
M	source/blender/blenkernel/BKE_paint.h
M	source/blender/blenkernel/BKE_pbvh.h
M	source/blender/blenkernel/intern/DerivedMesh.c
M	source/blender/blenkernel/intern/cdderivedmesh.c
M	source/blender/blenkernel/intern/mesh_evaluate.c
M	source/blender/blenkernel/intern/paint.c
M	source/blender/blenkernel/intern/pbvh.c
M	source/blender/blenkernel/intern/pbvh_intern.h
M	source/blender/blenkernel/intern/subsurf_ccg.c
M	source/blender/blenlib/BLI_math_geom.h
M	source/blender/blenlib/intern/math_geom.c
M	source/blender/editors/mesh/editface.c
M	source/blender/editors/sculpt_paint/paint_vertex.c
M	source/blender/editors/space_view3d/drawmesh.c
M	source/blender/gpu/GPU_buffers.h
M	source/blender/gpu/intern/gpu_buffers.c
M	source/blender/makesdna/DNA_customdata_types.h
M	source/blender/makesdna/DNA_meshdata_types.h

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

diff --git a/source/blender/blenkernel/BKE_DerivedMesh.h b/source/blender/blenkernel/BKE_DerivedMesh.h
index c8bd7e9..c8068c2 100644
--- a/source/blender/blenkernel/BKE_DerivedMesh.h
+++ b/source/blender/blenkernel/BKE_DerivedMesh.h
@@ -184,6 +184,12 @@ struct DerivedMesh {
 	int totmat; /* total materials. Will be valid only before object drawing. */
 	struct Material **mat; /* material array. Will be valid only before object drawing */
 
+	struct {
+		struct MLoopTri *array;
+		int num;
+		int num_alloc;
+	} looptris;
+
 	/* use for converting to BMesh which doesn't store bevel weight and edge crease by default */
 	char cd_flag;
 
@@ -200,6 +206,8 @@ struct DerivedMesh {
 	/** Recalculates mesh tessellation */
 	void (*recalcTessellation)(DerivedMesh *dm);
 
+	void (*recalcLooptri)(DerivedMesh *dm);
+
 	/* Misc. Queries */
 
 	/* Also called in Editmode */
@@ -593,10 +601,14 @@ void DM_DupPolys(DerivedMesh *source, DerivedMesh *target);
 void DM_ensure_normals(DerivedMesh *dm);
 void DM_ensure_tessface(DerivedMesh *dm);
 
+void DM_ensure_looptri_data(DerivedMesh *dm);
+void DM_ensure_looptri(DerivedMesh *dm);
+
 void DM_update_tessface_data(DerivedMesh *dm);
 
 void DM_update_materials(DerivedMesh *dm, struct Object *ob);
 struct MTFace *DM_paint_uvlayer_active_get(DerivedMesh *dm, int mat_nr);
+struct MLoopUV *DM_paint_uvlayer_active_get_mloopuv(DerivedMesh *dm, int mat_nr);
 
 void DM_interp_vert_data(
         struct DerivedMesh *source, struct DerivedMesh *dest,
@@ -720,12 +732,12 @@ void DM_update_weight_mcol(
  * the DerivedMesh, with both a pointer for arrays and an offset for editmesh */
 typedef struct DMVertexAttribs {
 	struct {
-		struct MTFace *array;
+		struct MLoopUV *array;
 		int em_offset, gl_index, gl_texco;
 	} tface[MAX_MTFACE];
 
 	struct {
-		struct MCol *array;
+		struct MLoopCol *array;
 		int em_offset, gl_index;
 	} mcol[MAX_MCOL];
 
diff --git a/source/blender/blenkernel/BKE_cdderivedmesh.h b/source/blender/blenkernel/BKE_cdderivedmesh.h
index 59ec316..c7ad641 100644
--- a/source/blender/blenkernel/BKE_cdderivedmesh.h
+++ b/source/blender/blenkernel/BKE_cdderivedmesh.h
@@ -125,6 +125,8 @@ void CDDM_calc_edges(struct DerivedMesh *dm);
 void CDDM_recalc_tessellation(struct DerivedMesh *dm);
 void CDDM_recalc_tessellation_ex(struct DerivedMesh *dm, const bool do_face_nor_cpy);
 
+void CDDM_recalc_looptri(struct DerivedMesh *dm);
+
 /* lowers the number of vertices/edges/faces in a CDDerivedMesh
  * the layer data stays the same size
  */
diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h
index 1ff2c6b..afe6fda 100644
--- a/source/blender/blenkernel/BKE_mesh.h
+++ b/source/blender/blenkernel/BKE_mesh.h
@@ -39,6 +39,7 @@ struct LinkNode;
 struct BLI_Stack;
 struct MemArena;
 struct BMesh;
+struct MLoopTri;
 struct Main;
 struct Mesh;
 struct MPoly;
@@ -178,6 +179,11 @@ void BKE_mesh_calc_normals_tessface(
         struct MVert *mverts, int numVerts,
         const struct MFace *mfaces, int numFaces,
         float (*r_faceNors)[3]);
+void BKE_mesh_calc_normals_looptri(
+        struct MVert *mverts, int numVerts,
+        const struct MLoop *mloop,
+        const struct MLoopTri *looptri, int looptri_num,
+        float (*r_tri_nors)[3]);
 void BKE_mesh_loop_tangents_ex(
         const struct MVert *mverts, const int numVerts, const struct MLoop *mloops,
         float (*r_looptangent)[4], float (*loopnors)[3], const struct MLoopUV *loopuv,
@@ -285,6 +291,11 @@ int BKE_mesh_recalc_tessellation(
         struct MVert *mvert,
         int totface, int totloop, int totpoly,
         const bool do_face_nor_copy);
+void BKE_mesh_recalc_looptri(
+        const struct MLoop *mloop, const struct MPoly *mpoly,
+        const struct MVert *mvert,
+        int totloop, int totpoly,
+        struct MLoopTri *mlooptri);
 int BKE_mesh_mpoly_to_mface(
         struct CustomData *fdata, struct CustomData *ldata,
         struct CustomData *pdata, int totface, int totloop, int totpoly);
diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h
index 09ccc3d..c9192fd 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -40,6 +40,8 @@ struct CurveMapping;
 struct MeshElemMap;
 struct GridPaintMask;
 struct Main;
+struct MLoop;
+struct MLoopTri;
 struct MFace;
 struct MVert;
 struct Object;
@@ -133,7 +135,7 @@ bool BKE_paint_select_vert_test(struct Object *ob);
 bool BKE_paint_select_elem_test(struct Object *ob);
 
 /* partial visibility */
-bool paint_is_face_hidden(const struct MFace *f, const struct MVert *mvert);
+bool paint_is_face_hidden(const struct MLoopTri *lt, const struct MVert *mvert, const struct MLoop *mloop);
 bool paint_is_grid_face_hidden(const unsigned int *grid_hidden,
                                int gridsize, int x, int y);
 bool paint_is_bmesh_face_hidden(struct BMFace *f);
diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h
index fbaf91d..79b285f 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -34,7 +34,9 @@ struct CCGElem;
 struct CCGKey;
 struct CustomData;
 struct DMFlagMat;
-struct MFace;
+struct MPoly;
+struct MLoop;
+struct MLoopTri;
 struct MVert;
 struct PBVH;
 struct PBVHNode;
@@ -60,8 +62,10 @@ typedef void (*BKE_pbvh_HitOccludedCallback)(PBVHNode *node, void *data, float *
 
 PBVH *BKE_pbvh_new(void);
 void BKE_pbvh_build_mesh(
-        PBVH *bvh, const struct MFace *faces, struct MVert *verts,
-        int totface, int totvert, struct CustomData *vdata);
+        PBVH *bvh,
+        const struct MPoly *mpoly, const struct MLoop *mloop,
+        struct MVert *verts, int totvert, struct CustomData *vdata,
+        const struct MLoopTri *looptri, int looptri_num);
 void BKE_pbvh_build_grids(PBVH *bvh, struct CCGElem **grid_elems,
                           int totgrid,
                           struct CCGKey *key, void **gridfaces, struct DMFlagMat *flagmats,
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c
index 7ced227..a75442e 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -364,6 +364,10 @@ int DM_release(DerivedMesh *dm)
 			dm->totmat = 0;
 		}
 
+		MEM_SAFE_FREE(dm->looptris.array);
+		dm->looptris.num = 0;
+		dm->looptris.num_alloc = 0;
+
 		return 1;
 	}
 	else {
@@ -438,6 +442,46 @@ void DM_ensure_tessface(DerivedMesh *dm)
 	}
 
 	dm->dirty &= ~DM_DIRTY_TESS_CDLAYERS;
+
+	/* -------------------------------------------------------------------- */
+	/* ---------------------- WATCH IT! THIS IS ONLY HERE FOR TESTING ----- */
+	/* -------------------------------------------------------------------- */
+	DM_ensure_looptri(dm);
+}
+
+/* ensure the array is large enough */
+void DM_ensure_looptri_data(DerivedMesh *dm)
+{
+	const unsigned int totpoly = dm->numPolyData;
+	const unsigned int totloop = dm->numLoopData;
+	const int looptris_num = poly_to_tri_count(totpoly, totloop);
+
+	if ((looptris_num > dm->looptris.num_alloc) ||
+	    (looptris_num < dm->looptris.num_alloc * 2) ||
+	    (totpoly == 0))
+	{
+		MEM_SAFE_FREE(dm->looptris.array);
+		dm->looptris.num_alloc = 0;
+		dm->looptris.num = 0;
+	}
+
+	if (totpoly) {
+		if (dm->looptris.array == NULL) {
+			dm->looptris.array = MEM_mallocN(sizeof(*dm->looptris.array) * looptris_num, __func__);
+			dm->looptris.num_alloc = looptris_num;
+		}
+
+		dm->looptris.num = looptris_num;
+	}
+}
+
+void DM_ensure_looptri(DerivedMesh *dm)
+{
+	const int numPolys =  dm->getNumPolys(dm);
+
+	if ((dm->looptris.num == 0) && (numPolys != 0)) {
+		dm->recalcLooptri(dm);
+	}
 }
 
 /* Update tessface CD data from loop/poly ones. Needed when not retessellating after modstack evaluation. */
@@ -546,6 +590,29 @@ MTFace *DM_paint_uvlayer_active_get(DerivedMesh *dm, int mat_nr)
 	return tf_base;
 }
 
+MLoopUV *DM_paint_uvlayer_active_get_mloopuv(DerivedMesh *dm, int mat_nr)
+{
+	MLoopUV *uv_base;
+
+	BLI_assert(mat_nr < dm->totmat);
+
+	if (dm->mat[mat_nr] && dm->mat[mat_nr]->texpaintslot &&
+	    dm->mat[mat_nr]->texpaintslot[dm->mat[mat_nr]->paint_active_slot].uvname)
+	{
+		uv_base = CustomData_get_layer_named(&dm->loopData, CD_MLOOPUV,
+		                                     dm->mat[mat_nr]->texpaintslot[dm->mat[mat_nr]->paint_active_slot].uvname);
+		/* This can fail if we have changed the name in the UV layer list and have assigned the old name in the material
+		 * texture slot.*/
+		if (!uv_base)
+			uv_base = CustomData_get_layer(&dm->loopData, CD_MLOOPUV);
+	}
+	else {
+		uv_base = CustomData_get_layer(&dm->loopData, CD_MLOOPUV);
+	}
+
+	return uv_base;
+}
+
 void DM_to_mesh(DerivedMesh *dm, Mesh *me, Object *ob, CustomDataMask mask, bool take_ownership)
 {
 	/* dm might depend on me, so we need to do everything with a local copy */
@@ -3160,17 +3227,20 @@ void DM_vertex_attributes_from_gpu(DerivedMesh *dm, GPUVertexAttribs *gattribs,
 				attribs->tface[a].gl_texco = gattribs->layer[b].gltexco;
 			}
 			else {
+				/* exception .. */
+				CustomData *ldata = dm->getLoopDataLayout(dm);
+
 				if (gattribs->layer[b].name[0])
-					layer = CustomData_get_named_layer_index(tfdata, CD_MTFACE,
+					layer = CustomData_get_named_layer_index(ldata, CD_MLOOPUV,
 					                                         gattribs->layer[b].name);
 				else
-					layer = CustomData_get_active_layer_index(tfdata, CD_MTFACE);
+					layer = CustomData_get_active_layer_index(ldata, CD_MLOOPUV);
 
 				a = attribs->tottface++;
 
 				if (layer != -1) {
-					attribs->tface[a].array = tfdata->layers[layer].data;
-					attribs->tface[a].em_offset = tfdata->layers[layer].offset;
+					attribs->tface[a].array = ldata->layers[layer].data;
+					attribs->tface[a].em_offset = ldata->layers[layer].offset;
 				}
 				else {
 					attribs->tface[a].array = NULL;
@@ -3207,19 +3277,22 @@ void DM_vertex_attributes_from_gpu(DerivedMesh *dm, GPUVertexAttribs *gattribs,
 				attribs->mcol[a].gl_index = gattribs->layer[b].glindex;
 			}
 			else {
+				/* exception .. */
+				CustomData *ldata = dm->getLoopDataLayout(dm);
+
 				/* vertex colors */
 				if (gattribs->layer[b].name[0

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list