From 99f72dfbfcb004418ae3c701f3badfd36996e6e5 Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Wed, 14 Mar 2012 03:10:18 +0000 Subject: Add 'level' field to struct MDisps, companion to 'totdisp'. Gets initialized when loading old files and updated at the same places totdisp is updated. Saves having to do log+sqrt to extract level from totdisp. --- source/blender/blenkernel/intern/customdata.c | 3 +++ source/blender/blenkernel/intern/mesh.c | 1 + source/blender/blenkernel/intern/multires.c | 6 ++++++ source/blender/blenloader/intern/readfile.c | 9 +++++++++ source/blender/bmesh/intern/bmesh_interp.c | 1 + source/blender/bmesh/intern/bmesh_mesh.c | 1 + source/blender/makesdna/DNA_meshdata_types.h | 2 +- 7 files changed, 22 insertions(+), 1 deletion(-) (limited to 'source') diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c index 233d0202540..2520c9b666e 100644 --- a/source/blender/blenkernel/intern/customdata.c +++ b/source/blender/blenkernel/intern/customdata.c @@ -485,10 +485,12 @@ static void layerCopy_mdisps(const void *source, void *dest, int count) if(s[i].disps) { d[i].disps = MEM_dupallocN(s[i].disps); d[i].totdisp = s[i].totdisp; + d[i].level = s[i].level; } else { d[i].disps = NULL; d[i].totdisp = 0; + d[i].level = 0; } } @@ -504,6 +506,7 @@ static void layerFree_mdisps(void *data, int count, int UNUSED(size)) MEM_freeN(d[i].disps); d[i].disps = NULL; d[i].totdisp = 0; + d[i].level = 0; } } diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index 054cbe0021b..6600099fff7 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -1877,6 +1877,7 @@ static void bm_corners_to_loops(Mesh *me, int findex, int loopstart, int numTex, for (i=0; itotdisp = side*side; + ld->level = (int)(logf(side - 1.0f) / M_LN2) + 1; if (ld->disps) MEM_freeN(ld->disps); diff --git a/source/blender/blenkernel/intern/multires.c b/source/blender/blenkernel/intern/multires.c index 7d50ec6d13a..b708f33537f 100644 --- a/source/blender/blenkernel/intern/multires.c +++ b/source/blender/blenkernel/intern/multires.c @@ -320,6 +320,7 @@ static void multires_set_tot_mdisps(Mesh *me, int lvl) if (mdisps) { for (i = 0; i < me->totloop; i++, mdisps++) { mdisps->totdisp = multires_grid_tot[lvl]; + mdisps->level = lvl; } } } @@ -338,6 +339,7 @@ static void multires_reallocate_mdisps(int totloop, MDisps *mdisps, int lvl) mdisps[i].disps = disps; mdisps[i].totdisp = totdisp; + mdisps[i].level = lvl; } } @@ -426,6 +428,7 @@ static void multires_del_higher(MultiresModifierData *mmd, Object *ob, int lvl) MEM_freeN(mdisp->disps); mdisp->disps = disps; mdisp->totdisp = totdisp; + mdisp->level = lvl; } } } @@ -999,6 +1002,7 @@ void multires_set_space(DerivedMesh *dm, Object *ob, int from, int to) /* when adding new faces in edit mode, need to allocate disps */ if (!mdisp->disps) { mdisp->totdisp = gridSize*gridSize; + mdisp->level = totlvl; mdisp->disps = MEM_callocN(sizeof(float)*3*mdisp->totdisp, "disp in multires_set_space"); } @@ -1224,6 +1228,7 @@ static void old_mdisps_convert(MFace *mface, MDisps *mdisp) MEM_freeN(mdisp->disps); mdisp->totdisp= newtotdisp; + mdisp->level= newlvl; mdisp->disps= disps; } @@ -1252,6 +1257,7 @@ void multires_load_old_250(Mesh *me) for (j=0; j < mf->v4 ? 4 : 3; j++, k++) { mdisps2[k].disps = MEM_callocN(sizeof(float)*3*totdisp, "multires disp in conversion"); mdisps2[k].totdisp = totdisp; + mdisps2[k].level = mdisps[i].level; memcpy(mdisps2[k].disps, mdisps[i].disps + totdisp*j, totdisp); } diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 50b8e0997ee..2cbb8a300ed 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -3751,6 +3751,15 @@ static void direct_link_mdisps(FileData *fd, int count, MDisps *mdisps, int exte for(i = 0; i < count; ++i) { mdisps[i].disps = newdataadr(fd, mdisps[i].disps); + if (mdisps[i].totdisp && !mdisps[i].level) { + /* this calculation is only correct for loop mdisps; + if loading pre-BMesh face mdisps this will be + overwritten with the correct value in + bm_corners_to_loops() */ + float gridsize = sqrtf(mdisps[i].totdisp); + mdisps[i].level = (int)(logf(gridsize - 1.0f) / M_LN2) + 1; + } + if( (fd->flags & FD_FLAGS_SWITCH_ENDIAN) && (mdisps[i].disps) ) { /* DNA_struct_switch_endian doesn't do endian swap for (*disps)[] */ /* this does swap for data written at write_mdisps() - readfile.c */ diff --git a/source/blender/bmesh/intern/bmesh_interp.c b/source/blender/bmesh/intern/bmesh_interp.c index 7074adc324f..5b8b537c669 100644 --- a/source/blender/bmesh/intern/bmesh_interp.c +++ b/source/blender/bmesh/intern/bmesh_interp.c @@ -426,6 +426,7 @@ static void bm_loop_interp_mdisps(BMesh *bm, BMLoop *target, BMFace *source) MDisps *md2 = CustomData_bmesh_get(&bm->ldata, BM_FACE_FIRST_LOOP(source)->head.data, CD_MDISPS); mdisps->totdisp = md2->totdisp; + mdisps->level = md2->level; if (mdisps->totdisp) { mdisps->disps = MEM_callocN(sizeof(float) * 3 * mdisps->totdisp, "mdisp->disps in bmesh_loop_intern_mdisps"); diff --git a/source/blender/bmesh/intern/bmesh_mesh.c b/source/blender/bmesh/intern/bmesh_mesh.c index 04279d30e61..096c1fabc5e 100644 --- a/source/blender/bmesh/intern/bmesh_mesh.c +++ b/source/blender/bmesh/intern/bmesh_mesh.c @@ -371,6 +371,7 @@ static void UNUSED_FUNCTION(bm_mdisps_space_set)(Object *ob, BMesh *bm, int from lmd->disps = MEM_dupallocN(mdisps->disps); lmd->totdisp = mdisps->totdisp; + lmd->level = mdisps->level; } mdisps++; diff --git a/source/blender/makesdna/DNA_meshdata_types.h b/source/blender/makesdna/DNA_meshdata_types.h index 4367d259b1f..f5a8a185556 100644 --- a/source/blender/makesdna/DNA_meshdata_types.h +++ b/source/blender/makesdna/DNA_meshdata_types.h @@ -164,7 +164,7 @@ typedef struct OrigSpaceLoop { typedef struct MDisps { /* Strange bug in SDNA: if disps pointer comes first, it fails to see totdisp */ int totdisp; - char pad[4]; + int level; float (*disps)[3]; } MDisps; -- cgit v1.2.3