[Bf-blender-cvs] [e791aeb] soc-2014-nurbs: New mesher (proper ngon, orco, etc).

Jonathan deWerd noreply at git.blender.org
Thu Aug 7 22:42:59 CEST 2014


Commit: e791aeb41b0628e7dd1522e5f518604d52270c8e
Author: Jonathan deWerd
Date:   Tue Aug 5 13:23:43 2014 -0400
Branches: soc-2014-nurbs
https://developer.blender.org/rBe791aeb41b0628e7dd1522e5f518604d52270c8e

New mesher (proper ngon, orco, etc).

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

M	source/blender/blenkernel/BKE_curve.h
M	source/blender/blenkernel/BKE_mesh.h
M	source/blender/blenkernel/intern/curve.cpp
M	source/blender/blenkernel/intern/mesh.c
M	source/blender/blenkernel/intern/surf_gridmesh.cpp
M	source/blender/blenkernel/intern/surf_gridmesh.h
M	source/blender/blenloader/intern/readfile.c
M	source/blender/editors/io/io_rhino_import.cpp
M	source/blender/editors/object/object_add.c

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

diff --git a/source/blender/blenkernel/BKE_curve.h b/source/blender/blenkernel/BKE_curve.h
index c0766dd..a044c31 100644
--- a/source/blender/blenkernel/BKE_curve.h
+++ b/source/blender/blenkernel/BKE_curve.h
@@ -49,6 +49,7 @@ struct rctf;
 struct DispList;
 struct BPoint;
 struct NurbTrim;
+struct GridMesh;
 
 typedef struct CurveCache {
 	ListBase disp;
@@ -180,9 +181,11 @@ void BKE_nurb_domain(struct Nurb *nu, float *umin, float *umax, float *vmin, flo
 
 void BKE_nurb_makeFaces(struct Nurb *nu, float *coord_array, int rowstride, int resolu, int resolv);
 void BKE_nurb_makeCurve(struct Nurb *nu, float *coord_array, float *tilt_array, float *radius_array, float *weight_array, int resolu, int stride);
+struct GridMesh *BKE_nurb_compute_trimmed_GridMesh(struct Nurb* nu);
 void BKE_nurb_compute_trimmed_UV_mesh(struct Nurb* nu);
 void BKE_nurb_clear_cached_UV_mesh(struct Nurb* nu, bool free_mem);
 void BKE_nurb_make_displist(struct Nurb *nurb, struct DispList *dl);
+void BKE_surf_to_mesh(struct Object *surf);
 
 void BKE_nurb_knot_calc_u(struct Nurb *nu);
 void BKE_nurb_knot_calc_v(struct Nurb *nu);
diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h
index 587dea5..28a3ee0 100644
--- a/source/blender/blenkernel/BKE_mesh.h
+++ b/source/blender/blenkernel/BKE_mesh.h
@@ -101,9 +101,6 @@ int test_index_face(struct MFace *mface, struct CustomData *mfdata, int mfindex,
 struct Mesh *BKE_mesh_from_object(struct Object *ob);
 void BKE_mesh_assign_object(struct Object *ob, struct Mesh *me);
 void BKE_mesh_from_metaball(struct ListBase *lb, struct Mesh *me);
-int  BKE_mesh_nurbs_to_mdata(struct Object *ob, struct MVert **allvert, int *totvert,
-                             struct MEdge **alledge, int *totedge, struct MLoop **allloop, struct MPoly **allpoly,
-                             int *totloop, int *totpoly);
 int BKE_mesh_nurbs_displist_to_mdata(struct Object *ob, struct ListBase *dispbase, struct MVert **allvert, int *_totvert,
                                      struct MEdge **alledge, int *_totedge, struct MLoop **allloop, struct MPoly **allpoly,
                                      struct MLoopUV **alluv, int *_totloop, int *_totpoly);
diff --git a/source/blender/blenkernel/intern/curve.cpp b/source/blender/blenkernel/intern/curve.cpp
index a2a964d..4b8b6a2 100644
--- a/source/blender/blenkernel/intern/curve.cpp
+++ b/source/blender/blenkernel/intern/curve.cpp
@@ -51,9 +51,12 @@ extern "C" {
 #include "DNA_scene_types.h"
 #include "DNA_vfont_types.h"
 #include "DNA_object_types.h"
+#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
 
 #include "BKE_animsys.h"
 #include "BKE_curve.h"
+#include "BKE_mesh.h"
 #include "BKE_displist.h"
 #include "BKE_font.h"
 #include "BKE_global.h"
@@ -62,6 +65,7 @@ extern "C" {
 #include "BKE_main.h"
 #include "BKE_object.h"
 #include "BKE_material.h"
+#include "BKE_customdata.h"
 }
 
 #include "surf_gridmesh.h"
@@ -4060,10 +4064,7 @@ void BKE_nurb_domain(struct Nurb *nu, float *umin, float *umax, float *vmin, flo
 	}
 }
 
-float subj0[] = {0.512000,0.938000, 0.374000,0.950000, 0.248000,0.908000, 0.170000,0.866000, 0.092000,0.740000, 0.092000,0.602000, 0.092000,0.440000, 0.116000,0.260000, 0.254000,0.110000, 0.476000,0.074000, 0.746000,0.092000, 0.836000,0.206000, 0.848000,0.422000, 0.812000,0.644000, 0.716000,0.686000, 0.614000,0.734000, 0.488000,0.728000, 0.386000,0.710000, 0.260000,0.626000, 0.272000,0.476000, 0.350000,0.338000, 0.482000,0.278000, 0.632000,0.308000, 0.644000,0.404000, 0.638000,0.494000,  [...]
-void BKE_nurb_compute_trimmed_UV_mesh(struct Nurb* nu) {
-	bool remap_coords = true; // Remove trimmed verts (only useful for meshgen)
-
+GridMesh *BKE_nurb_compute_trimmed_GridMesh(struct Nurb* nu) {
 	// Figure out the domain
 	int totu=(nu->pntsu-nu->orderu+1)*nu->resolu, totv=(nu->pntsv-nu->orderv+1)*nu->resolv;
 	float ustart,uend,vstart,vend;
@@ -4071,14 +4072,6 @@ void BKE_nurb_compute_trimmed_UV_mesh(struct Nurb* nu) {
 	
 	// Trim the uniform grid in 2D UV space
 	GridMesh *gm = new GridMesh();
-	int coords_len = (totu+1)*(totv+1)*2;
-	GridMeshCoord *coords=NULL;
-	if (!remap_coords) {
-		coords = (GridMeshCoord*)MEM_mallocN(coords_len * sizeof(GridMeshCoord), "NURBS_tess_1");
-		gm->mallocN = MEM_mallocN;
-		gm->reallocN = MEM_reallocN_id;
-		gm->coords_import(coords, coords_len);
-	}
 	gm->set_ll_ur(ustart,vstart,uend,vend);
 	gm->init_grid(totu,totv);
 	
@@ -4102,28 +4095,30 @@ void BKE_nurb_compute_trimmed_UV_mesh(struct Nurb* nu) {
 		}
 		MEM_freeN(trim_uv_pts);
 	}
-//	static ThreadMutex *mutex = NULL;
-//	if (!mutex) {
-//		mutex = (ThreadMutex*)MEM_callocN(sizeof(ThreadMutex), "ThreadMutex");
-//		BLI_mutex_init(mutex);
-//	}
-//	BLI_mutex_lock(mutex);
-//	gm->dump_recording();
-//	BLI_mutex_unlock(mutex);
+	//	static ThreadMutex *mutex = NULL;
+	//	if (!mutex) {
+	//		mutex = (ThreadMutex*)MEM_callocN(sizeof(ThreadMutex), "ThreadMutex");
+	//		BLI_mutex_init(mutex);
+	//	}
+	//	BLI_mutex_lock(mutex);
+	//	gm->dump_recording();
+	//	BLI_mutex_unlock(mutex);
+	return gm;
+}
+
+void BKE_nurb_compute_trimmed_UV_mesh(struct Nurb* nu) {
+	GridMesh *gm = BKE_nurb_compute_trimmed_GridMesh(nu);
 	
 	// Extract the results
+	int totu=(nu->pntsu-nu->orderu+1)*nu->resolu, totv=(nu->pntsv-nu->orderv+1)*nu->resolv;
 	std::map<int,int> *used_idxs;
-	if (!remap_coords) {
-		coords = gm->coords_export(&coords_len);
-		used_idxs = NULL;
-	} else {
-		coords = gm->coords;
-		used_idxs = new std::map<int,int>();
-	}
+	GridMeshCoord *coords = gm->coords;
+	int coords_len = (totu+1)*(totv+1)*2;
+	used_idxs = new std::map<int,int>();
 	int idxs_len = 4 * 3*sizeof(int)*totu*totv;
 	int *idxs = (int*)MEM_mallocN(sizeof(int)*idxs_len, "NURBS_tess_2.0");
 	int ii=0; // Index index
-#define TESS_MAX_POLY_VERTS 1024
+#define TESS_MAX_POLY_VERTS 2048
 	float coords_tmp[TESS_MAX_POLY_VERTS][2];
 	int reindex_tmp[TESS_MAX_POLY_VERTS];
 	unsigned idx_tmp[TESS_MAX_POLY_VERTS][3];
@@ -4150,10 +4145,8 @@ void BKE_nurb_compute_trimmed_UV_mesh(struct Nurb* nu) {
 					int ll=ll_gp, lr=ll_gp+1, ur=ll_gp+(totu+1)+1, ul=ll_gp+(totu+1);
 					idxs[ii++]=ll; idxs[ii++]=lr; idxs[ii++]=ur;
 					idxs[ii++]=ur; idxs[ii++]=ul; idxs[ii++]=ll;
-					if (remap_coords) {
-						(*used_idxs)[ll]=0; (*used_idxs)[lr]=0;
-						(*used_idxs)[ul]=0; (*used_idxs)[ur]=0;
-					}
+					(*used_idxs)[ll]=0; (*used_idxs)[lr]=0;
+					(*used_idxs)[ul]=0; (*used_idxs)[ur]=0;
 				} else {
 					int num_verts=0; int vert=poly;
 					do {
@@ -4184,32 +4177,30 @@ void BKE_nurb_compute_trimmed_UV_mesh(struct Nurb* nu) {
 						int i2=reindex_tmp[idx_tmp[z][1]];
 						int i3=reindex_tmp[idx_tmp[z][2]];
 						idxs[ii++]=i1; idxs[ii++]=i2; idxs[ii++]=i3;
-						if (remap_coords) {
-							(*used_idxs)[i1]=0;
-							(*used_idxs)[i2]=0;
-							(*used_idxs)[i3]=0;
-						}
+						(*used_idxs)[i1]=0;
+						(*used_idxs)[i2]=0;
+						(*used_idxs)[i3]=0;
 					}
 				}
 			}
 		}
 	}
-	if (remap_coords) {
-		int num_used_idxs = int(used_idxs->size());
-		coords = (GridMeshCoord*)MEM_mallocN(3*sizeof(float)*num_used_idxs, "NURBS_tess_2.3");
-		coords_len = num_used_idxs;
-		int newidx=0;
-		std::map<int,int>::iterator it=used_idxs->begin(),end=used_idxs->end();
-		for (; it!=end; it++) {
-			int old_idx = it->first;
-			coords[newidx] = gm->coords[old_idx];
-			it->second = newidx++;
-		}
-		// ii, the index index, points to the end of idxs, the index array
-		for (int i=0; i<ii; i++) {
-			idxs[i] = (*used_idxs)[idxs[i]];
-		}
-	}
+	/* Remap Coords */
+	int num_used_idxs = int(used_idxs->size());
+	coords = (GridMeshCoord*)MEM_mallocN(3*sizeof(float)*num_used_idxs, "NURBS_tess_2.3");
+	coords_len = num_used_idxs;
+	int newidx=0;
+	std::map<int,int>::iterator it=used_idxs->begin(),end=used_idxs->end();
+	for (; it!=end; it++) {
+		int old_idx = it->first;
+		coords[newidx] = gm->coords[old_idx];
+		it->second = newidx++;
+	}
+	// ii, the index index, points to the end of idxs, the index array
+	for (int i=0; i<ii; i++) {
+		idxs[i] = (*used_idxs)[idxs[i]];
+	}
+	/* End remap coords */
 	
 	nu->UV_verts_count = coords_len;
 	nu->UV_tri_count = ii/3;
@@ -4265,3 +4256,213 @@ void BKE_nurb_make_displist(struct Nurb *nu, struct DispList *dl) {
 	if (nu->flag&CU_SMOOTH)
 		dl->rt |= CU_SMOOTH;
 }
+
+/* Helper for BKE_surf_to_mesh */
+struct NurbsMeshInfo {
+	/* Output from Pass 1 */
+	int num_vert, num_edge, num_loop, num_poly;
+	GridMesh *gm;
+	std::map<int,int> remap_vert;
+	std::map<std::pair<int,int>,int> remap_edge;
+	
+	/* Input to Pass 2 */
+	MVert *verts;
+	MEdge *edges;
+	MLoop *loops;
+	MLoopUV *uvs;
+	MPoly *polys;
+};
+
+/* Helper for BKE_surf_to_mesh */
+void nurbs_meshinfo_pass_1(Nurb *nu, NurbsMeshInfo &nmi) {
+	GridMesh *gm = BKE_nurb_compute_trimmed_GridMesh(nu);
+	nmi.gm = gm;
+	std::map<int,int> &remap_vert = nmi.remap_vert;
+	std::map<std::pair<int,int>,int> &remap_edge = nmi.remap_edge;
+	int vertid=0, edgeid=0, loopid=0, polyid=0;
+	for (GridMeshIterator gmi=gm->begin(); !gmi.done(); gmi.next()) {
+		int poly = gmi.poly;
+		int vert=poly; do {
+			int coordidx = gm->v[vert].coord_idx;
+			std::map<int,int>::iterator crd = remap_vert.find(coordidx);
+			if (crd==remap_vert.end()) {
+				remap_vert[coordidx] = vertid++;
+			}
+			int nextvert = gm->v[vert].next;
+			int c1=coordidx, c2=gm->v[nextvert].coord_idx;
+			std::pair<int,int> thisedge = (c1<c2)? std::make_pair(c1,c2) : std::make_pair(c2,c1);
+			std::map<std::pair<int,int>,int>::iterator edg = remap_edge.find(thisedge);
+			if (edg==remap_edge.end()) {
+				remap_edge[thisedge] = edgeid++;
+			}
+			loopid++;
+			vert = nextvert;
+		} while (vert!=poly);
+		polyid++;
+	}
+	nmi.num_vert = vertid;
+	nmi.num_edge = edgeid;
+	nmi.num_loop = loopid;
+	nmi.num_poly 

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list