Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2011-12-28 17:50:33 +0400
committerCampbell Barton <ideasman42@gmail.com>2011-12-28 17:50:33 +0400
commit5b88e16306711408825d9291bfeb7023bd7fd69c (patch)
tree75e0d8aa861280745308d9667125bf949f571567 /source/blender
parentca94cb123745f207ec837b091ab271ad3a5aacbe (diff)
WIP loading bmesh in trunk, some conversion functions for this purpose.
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/blenkernel/intern/mesh.c175
-rw-r--r--source/blender/blenlib/CMakeLists.txt1
-rw-r--r--source/blender/blenloader/intern/writefile.c4
-rw-r--r--source/blender/makesdna/DNA_mesh_types.h2
-rw-r--r--source/blender/python/intern/bpy_app_ffmpeg.c6
-rw-r--r--source/blender/windowmanager/intern/wm_operators.c4
6 files changed, 185 insertions, 7 deletions
diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c
index 4b4875213b1..61604bf1432 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -65,6 +65,10 @@
/* -- */
#include "BKE_object.h"
+#ifdef USE_BMESH_FORWARD_COMPAT
+#include "BLI_array.h"
+#endif
+
EditMesh *BKE_mesh_get_editmesh(Mesh *me)
{
@@ -726,7 +730,7 @@ void mball_to_mesh(ListBase *lb, Mesh *me)
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 @@ void create_vert_edge_map(ListBase **map, IndexNode **mem, const MEdge *medge, c
}
}
+#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])
{
diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt
index fb9b8021b8e..a03aee7cb7c 100644
--- a/source/blender/blenlib/CMakeLists.txt
+++ b/source/blender/blenlib/CMakeLists.txt
@@ -87,6 +87,7 @@ set(SRC
intern/voxel.c
intern/winstuff.c
+ BLI_array.h
BLI_args.h
BLI_blenlib.h
BLI_boxpack2d.h
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index f4575c3b1e3..e9c14404057 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -175,7 +175,7 @@ typedef struct {
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 @@ static int write_file_handle(Main *mainvar, int handle, MemFile *compare, MemFil
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
diff --git a/source/blender/makesdna/DNA_mesh_types.h b/source/blender/makesdna/DNA_mesh_types.h
index 8e8c3b8743a..ca471bbabcd 100644
--- a/source/blender/makesdna/DNA_mesh_types.h
+++ b/source/blender/makesdna/DNA_mesh_types.h
@@ -198,7 +198,7 @@ typedef struct TFace {
* 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
diff --git a/source/blender/python/intern/bpy_app_ffmpeg.c b/source/blender/python/intern/bpy_app_ffmpeg.c
index 9c4428919ec..778334c9600 100644
--- a/source/blender/python/intern/bpy_app_ffmpeg.c
+++ b/source/blender/python/intern/bpy_app_ffmpeg.c
@@ -69,7 +69,11 @@ static PyStructSequence_Desc app_ffmpeg_info_desc = {
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) {
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index db8f9794c88..29d2f9392b2 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -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 @@ static void WM_OT_save_as_mainfile(wmOperatorType *ot)
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
}