[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [42931] trunk/blender/source/blender: WIP loading bmesh in trunk, some conversion functions for this purpose.

Campbell Barton ideasman42 at gmail.com
Wed Dec 28 14:50:41 CET 2011


Revision: 42931
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=42931
Author:   campbellbarton
Date:     2011-12-28 13:50:33 +0000 (Wed, 28 Dec 2011)
Log Message:
-----------
WIP loading bmesh in trunk, some conversion functions for this purpose.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/mesh.c
    trunk/blender/source/blender/blenlib/CMakeLists.txt
    trunk/blender/source/blender/blenloader/intern/writefile.c
    trunk/blender/source/blender/makesdna/DNA_mesh_types.h
    trunk/blender/source/blender/python/intern/bpy_app_ffmpeg.c
    trunk/blender/source/blender/windowmanager/intern/wm_operators.c

Modified: trunk/blender/source/blender/blenkernel/intern/mesh.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/mesh.c	2011-12-28 13:40:14 UTC (rev 42930)
+++ trunk/blender/source/blender/blenkernel/intern/mesh.c	2011-12-28 13:50:33 UTC (rev 42931)
@@ -65,7 +65,11 @@
 /* -- */
 #include "BKE_object.h"
 
+#ifdef USE_BMESH_FORWARD_COMPAT
+#include "BLI_array.h"
+#endif
 
+
 EditMesh *BKE_mesh_get_editmesh(Mesh *me)
 {
 	return me->edit_mesh;
@@ -726,7 +730,7 @@
 		nors= dl->nors;
 		verts= dl->verts;
 		while(a--) {
-			VECCOPY(mvert->co, verts);
+			copy_v3_v3(mvert->co, verts);
 			normal_float_to_short_v3(mvert->no, nors);
 			mvert++;
 			nors+= 3;
@@ -1445,6 +1449,175 @@
 	}
 }
 
+#ifdef USE_BMESH_FORWARD_COMPAT
+
+void mesh_loops_to_mface_corners(CustomData *fdata, CustomData *ldata,
+			   CustomData *pdata, int lindex[4], int findex,
+			   const int polyindex,
+			   const int mf_len /* 3 or 4 */
+			   )
+{
+	MTFace *texface;
+	MTexPoly *texpoly;
+	MCol *mcol;
+	MLoopCol *mloopcol;
+	MLoopUV *mloopuv;
+	int i, j, hasWCol = CustomData_has_layer(ldata, CD_WEIGHT_MLOOPCOL);
+	int numTex = CustomData_number_of_layers(pdata, CD_MTEXPOLY);
+	int numCol = CustomData_number_of_layers(ldata, CD_MLOOPCOL);
+	
+	for(i=0; i < numTex; i++){
+		texface = CustomData_get_n(fdata, CD_MTFACE, findex, i);
+		texpoly = CustomData_get_n(pdata, CD_MTEXPOLY, polyindex, i);
+		
+		texface->tpage = texpoly->tpage;
+		texface->flag = texpoly->flag;
+		texface->transp = texpoly->transp;
+		texface->mode = texpoly->mode;
+		texface->tile = texpoly->tile;
+		texface->unwrap = texpoly->unwrap;
+
+		for (j=0; j < mf_len; j++) {
+			mloopuv = CustomData_get_n(ldata, CD_MLOOPUV, lindex[j], i);
+			texface->uv[j][0] = mloopuv->uv[0];
+			texface->uv[j][1] = mloopuv->uv[1];
+		}
+	}
+
+	for(i=0; i < numCol; i++){
+		mcol = CustomData_get_n(fdata, CD_MCOL, findex, i);
+
+		for (j=0; j < mf_len; j++) {
+			mloopcol = CustomData_get_n(ldata, CD_MLOOPCOL, lindex[j], i);
+			mcol[j].r = mloopcol->r;
+			mcol[j].g = mloopcol->g;
+			mcol[j].b = mloopcol->b;
+			mcol[j].a = mloopcol->a;
+		}
+	}
+
+	if (hasWCol) {
+		mcol = CustomData_get(fdata,  findex, CD_WEIGHT_MCOL);
+
+		for (j=0; j < mf_len; j++) {
+			mloopcol = CustomData_get(ldata, lindex[j], CD_WEIGHT_MLOOPCOL);
+			mcol[j].r = mloopcol->r;
+			mcol[j].g = mloopcol->g;
+			mcol[j].b = mloopcol->b;
+			mcol[j].a = mloopcol->a;
+		}
+	}
+}
+
+
+/*
+ * this function recreates a tesselation.
+ * returns number of tesselation faces.
+ */
+int mesh_mpoly_to_mface(struct CustomData *fdata, struct CustomData *ldata,
+	struct CustomData *pdata, int totface, int UNUSED(totloop), int totpoly)
+{
+	MLoop *mloop;
+
+	int lindex[4];
+	int i;
+	int k;
+
+	MPoly *mp, *mpoly;
+	MFace *mface = NULL, *mf;
+	BLI_array_declare(mface);
+
+	mpoly = CustomData_get_layer(pdata, CD_MPOLY);
+	mloop = CustomData_get_layer(ldata, CD_MLOOP);
+
+	mp = mpoly;
+	k = 0;
+	for (i = 0; i<totpoly; i++, mp++) {
+		if (ELEM(mp->totloop, 3, 4)) {
+			BLI_array_growone(mface);
+			mf = &mface[k];
+
+			mf->mat_nr = mp->mat_nr;
+			mf->flag = mp->flag;
+
+			mf->v1 = mp->loopstart + 0;
+			mf->v2 = mp->loopstart + 1;
+			mf->v3 = mp->loopstart + 2;
+			mf->v4 = (mp->totloop == 4) ? (mp->loopstart + 3) : 0;
+
+			/* abuse edcode for temp storage and clear next loop */
+			mf->edcode = (char)mp->totloop; /* only ever 3 or 4 */
+
+			k++;
+		}
+	}
+
+	CustomData_free(fdata, totface);
+	memset(fdata, 0, sizeof(CustomData));
+
+	totface= k;
+
+	CustomData_add_layer(fdata, CD_MFACE, CD_ASSIGN, mface, totface);
+
+	CustomData_from_bmeshpoly(fdata, pdata, ldata, totface);
+
+	mp = mpoly;
+	k = 0;
+	for (i = 0; i<totpoly; i++, mp++) {
+		if (ELEM(mp->totloop, 3, 4)) {
+			mf = &mface[k];
+
+			if (mf->edcode == 3) {
+				/*sort loop indices to ensure winding is correct*/
+				/* NO SORT - looks like we can skip this */
+
+				lindex[0] = mf->v1;
+				lindex[1] = mf->v2;
+				lindex[2] = mf->v3;
+				lindex[3] = 0; /* unused */
+
+				/*transform loop indices to vert indices*/
+				mf->v1 = mloop[mf->v1].v;
+				mf->v2 = mloop[mf->v2].v;
+				mf->v3 = mloop[mf->v3].v;
+
+				mesh_loops_to_mface_corners(fdata, ldata, pdata,
+				                            lindex, k, i, 3);
+				test_index_face(mf, fdata, totface, 3);
+			}
+			else {
+				/*sort loop indices to ensure winding is correct*/
+				/* NO SORT - looks like we can skip this */
+
+				lindex[0] = mf->v1;
+				lindex[1] = mf->v2;
+				lindex[2] = mf->v3;
+				lindex[3] = mf->v4;
+
+				/*transform loop indices to vert indices*/
+				mf->v1 = mloop[mf->v1].v;
+				mf->v2 = mloop[mf->v2].v;
+				mf->v3 = mloop[mf->v3].v;
+				mf->v4 = mloop[mf->v4].v;
+
+				mesh_loops_to_mface_corners(fdata, ldata, pdata,
+				                            lindex, k, i, 4);
+				test_index_face(mf, fdata, totface, 4);
+			}
+
+			mf->edcode= 0;
+
+			k++;
+		}
+	}
+
+	return k;
+}
+
+#endif /* USE_BMESH_FORWARD_COMPAT */
+
+
+
 /* basic vertex data functions */
 int minmax_mesh(Mesh *me, float min[3], float max[3])
 {

Modified: trunk/blender/source/blender/blenlib/CMakeLists.txt
===================================================================
--- trunk/blender/source/blender/blenlib/CMakeLists.txt	2011-12-28 13:40:14 UTC (rev 42930)
+++ trunk/blender/source/blender/blenlib/CMakeLists.txt	2011-12-28 13:50:33 UTC (rev 42931)
@@ -87,6 +87,7 @@
 	intern/voxel.c
 	intern/winstuff.c
 
+	BLI_array.h
 	BLI_args.h
 	BLI_blenlib.h
 	BLI_boxpack2d.h

Modified: trunk/blender/source/blender/blenloader/intern/writefile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/writefile.c	2011-12-28 13:40:14 UTC (rev 42930)
+++ trunk/blender/source/blender/blenloader/intern/writefile.c	2011-12-28 13:50:33 UTC (rev 42931)
@@ -175,7 +175,7 @@
 	
 	int tot, count, error, memsize;
 
-#ifdef USE_MESH_FORWARDS_COMAT
+#ifdef USE_BMESH_SAVE_AS_COMPAT
 	char use_mesh_compat; /* option to save with older mesh format */
 #endif
 } WriteData;
@@ -2625,7 +2625,7 @@
 
 	wd= bgnwrite(handle, compare, current);
 
-#ifdef USE_MESH_FORWARDS_COMAT
+#ifdef USE_BMESH_SAVE_AS_COMPAT
 	wd->use_mesh_compat = (write_flags & G_FILE_MESH_COMPAT) != 0;
 #endif
 

Modified: trunk/blender/source/blender/makesdna/DNA_mesh_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_mesh_types.h	2011-12-28 13:40:14 UTC (rev 42930)
+++ trunk/blender/source/blender/makesdna/DNA_mesh_types.h	2011-12-28 13:50:33 UTC (rev 42931)
@@ -198,7 +198,7 @@
  * will eventually be removed */
 
 #if 0 /* enable in bmesh branch only for now */
-#define USE_MESH_FORWARDS_COMAT
+#define USE_BMESH_SAVE_AS_COMPAT
 #endif
 
 

Modified: trunk/blender/source/blender/python/intern/bpy_app_ffmpeg.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_app_ffmpeg.c	2011-12-28 13:40:14 UTC (rev 42930)
+++ trunk/blender/source/blender/python/intern/bpy_app_ffmpeg.c	2011-12-28 13:50:33 UTC (rev 42931)
@@ -69,8 +69,12 @@
 static PyObject *make_ffmpeg_info(void)
 {
 	PyObject *ffmpeg_info;
-	int pos = 0, curversion;
+	int pos = 0;
 
+#ifdef WITH_FFMPEG
+	int curversion;
+#endif
+
 	ffmpeg_info = PyStructSequence_New(&BlenderAppFFmpegType);
 	if (ffmpeg_info == NULL) {
 		return NULL;

Modified: trunk/blender/source/blender/windowmanager/intern/wm_operators.c
===================================================================
--- trunk/blender/source/blender/windowmanager/intern/wm_operators.c	2011-12-28 13:40:14 UTC (rev 42930)
+++ trunk/blender/source/blender/windowmanager/intern/wm_operators.c	2011-12-28 13:50:33 UTC (rev 42931)
@@ -46,7 +46,7 @@
 #include "DNA_scene_types.h"
 #include "DNA_userdef_types.h"
 #include "DNA_windowmanager_types.h"
-#include "DNA_mesh_types.h" /* only for USE_MESH_FORWARDS_COMAT */
+#include "DNA_mesh_types.h" /* only for USE_BMESH_SAVE_AS_COMPAT */
 
 #include "BLF_translation.h"
 
@@ -2012,7 +2012,7 @@
 	RNA_def_boolean(ot->srna, "compress", 0, "Compress", "Write compressed .blend file");
 	RNA_def_boolean(ot->srna, "relative_remap", 1, "Remap Relative", "Remap relative paths when saving in a different directory");
 	RNA_def_boolean(ot->srna, "copy", 0, "Save Copy", "Save a copy of the actual working state but does not make saved file active");
-#ifdef USE_MESH_FORWARDS_COMAT
+#ifdef USE_BMESH_SAVE_AS_COMPAT
 	RNA_def_boolean(ot->srna, "use_mesh_compat", 0, "Legacy Mesh Format", "Save using legacy mesh format (no ngons)");
 #endif
 }




More information about the Bf-blender-cvs mailing list