Revision: 15311
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15311
Author: nicholasbishop
Date: 2008-06-22 21:43:52 +0200 (Sun, 22 Jun 2008)
Log Message:
-----------
Fixed saving/loading of MDisps. This took longer than it should have because of
a bug in SDNA, noted in the MDisps struct.
Undo/Redo should work correctly as well.
Modified Paths:
--------------
branches/soc-2008-nicholasbishop/source/blender/blenkernel/BKE_multires.h
branches/soc-2008-nicholasbishop/source/blender/blenkernel/intern/customdata.c
branches/soc-2008-nicholasbishop/source/blender/blenkernel/intern/multires.c
branches/soc-2008-nicholasbishop/source/blender/blenloader/intern/readfile.c
branches/soc-2008-nicholasbishop/source/blender/blenloader/intern/writefile.c
branches/soc-2008-nicholasbishop/source/blender/makesdna/DNA_meshdata_types.h
branches/soc-2008-nicholasbishop/source/blender/src/buttons_editing.c
Modified:
branches/soc-2008-nicholasbishop/source/blender/blenkernel/BKE_multires.h
===================================================================
--- branches/soc-2008-nicholasbishop/source/blender/blenkernel/BKE_multires.h
2008-06-22 19:34:18 UTC (rev 15310)
+++ branches/soc-2008-nicholasbishop/source/blender/blenkernel/BKE_multires.h
2008-06-22 19:43:52 UTC (rev 15311)
@@ -117,7 +117,7 @@
struct DerivedMesh *multires_dm_create_from_derived(struct
MultiresModifierData*, struct DerivedMesh*, int, int);
-void multiresModifier_subdivide(void *mmd_v, void *ob_v);
+void multiresModifier_subdivide(struct MultiresModifierData *mmd, struct Mesh
*me);
void multiresModifier_setLevel(void *mmd_v, void *ob_v);
void multires_displacer_init(MultiresDisplacer *d, struct DerivedMesh *dm,
Modified:
branches/soc-2008-nicholasbishop/source/blender/blenkernel/intern/customdata.c
===================================================================
---
branches/soc-2008-nicholasbishop/source/blender/blenkernel/intern/customdata.c
2008-06-22 19:34:18 UTC (rev 15310)
+++
branches/soc-2008-nicholasbishop/source/blender/blenkernel/intern/customdata.c
2008-06-22 19:43:52 UTC (rev 15311)
@@ -365,8 +365,15 @@
MDisps *d = dest;
for(i = 0; i < count; ++i) {
- if(s[i].disps)
+ if(s[i].disps) {
d[i].disps = MEM_dupallocN(s[i].disps);
+ d[i].totdisp = s[i].totdisp;
+ }
+ else {
+ d[i].disps = NULL;
+ d[i].totdisp = 0;
+ }
+
}
}
@@ -379,6 +386,7 @@
if(d[i].disps)
MEM_freeN(d[i].disps);
d[i].disps = NULL;
+ d[i].totdisp = 0;
}
}
Modified:
branches/soc-2008-nicholasbishop/source/blender/blenkernel/intern/multires.c
===================================================================
---
branches/soc-2008-nicholasbishop/source/blender/blenkernel/intern/multires.c
2008-06-22 19:34:18 UTC (rev 15310)
+++
branches/soc-2008-nicholasbishop/source/blender/blenkernel/intern/multires.c
2008-06-22 19:43:52 UTC (rev 15311)
@@ -1384,39 +1384,34 @@
calc_face_ts_mat(out, orco[f->v1], orco[f->v2], orco[f->v3], (f->v4 ?
orco[f->v4] : NULL));
}
-void multiresModifier_subdivide(void *mmd_v, void *ob_v)
+void multiresModifier_subdivide(MultiresModifierData *mmd, Mesh *me)
{
- MultiresModifierData *mmd = mmd_v;
- Object *ob = ob_v;
- Mesh *me = get_mesh(ob);
+ MDisps *mdisps;
+ int i;
- if(me && mmd) {
- MDisps *mdisps;
- int i;
+ if(mmd->totlvl == multires_max_levels) {
+ // TODO
+ return;
+ }
- if(mmd->totlvl == multires_max_levels) {
- // TODO
- return;
- }
+ ++mmd->lvl;
+ ++mmd->totlvl;
- ++mmd->lvl;
- ++mmd->totlvl;
+ mdisps = CustomData_get_layer(&me->fdata, CD_MDISPS);
+ if(!mdisps)
+ mdisps = CustomData_add_layer(&me->fdata, CD_MDISPS,
CD_DEFAULT, NULL, me->totface);
- mdisps = CustomData_get_layer(&me->fdata, CD_MDISPS);
- if(!mdisps)
- mdisps = CustomData_add_layer(&me->fdata, CD_MDISPS,
CD_DEFAULT, NULL, me->totface);
+ for(i = 0; i < me->totface; ++i) {
+ //const int totdisp = (me->mface[i].v4 ?
multires_quad_tot[totlvl] : multires_tri_tot[totlvl]);
+ const int totdisp = multires_quad_tot[mmd->totlvl - 1];
+ float (*disps)[3] = MEM_callocN(sizeof(float) * 3 * totdisp,
"multires disps");
- for(i = 0; i < me->totface; ++i) {
- //const int totdisp = (me->mface[i].v4 ?
multires_quad_tot[totlvl] : multires_tri_tot[totlvl]);
- const int totdisp = multires_quad_tot[mmd->totlvl - 1];
- float (*disps)[3] = MEM_callocN(sizeof(float) * 3 *
totdisp, "multires disps");
-
- if(mdisps[i].disps) {
- /* TODO: Transfer old disps over to the new */
- MEM_freeN(mdisps[i].disps);
- }
- mdisps[i].disps = disps;
+ if(mdisps[i].disps) {
+ /* TODO: Transfer old disps over to the new */
+ MEM_freeN(mdisps[i].disps);
}
+ mdisps[i].disps = disps;
+ mdisps[i].totdisp = totdisp;
}
}
@@ -1629,13 +1624,10 @@
mdisps = dm->getFaceDataArray(dm, CD_MDISPS);
- if(MultiresDM_get_lvl(dm) != MultiresDM_get_totlvl(dm))
- return;
-
if(mdisps) {
MultiresDisplacer d;
- const int gridFaces =
multires_side_tot[MultiresDM_get_totlvl(dm) - 2] - 1;
- const int edgeSize =
multires_side_tot[MultiresDM_get_totlvl(dm) - 1] - 1;
+ const int gridFaces = multires_side_tot[MultiresDM_get_lvl(dm)
- 2] - 1;
+ const int edgeSize = multires_side_tot[MultiresDM_get_lvl(dm) -
1] - 1;
ListBase *map = MultiresDM_get_vert_face_map(dm);
int S, x, y;
Modified:
branches/soc-2008-nicholasbishop/source/blender/blenloader/intern/readfile.c
===================================================================
---
branches/soc-2008-nicholasbishop/source/blender/blenloader/intern/readfile.c
2008-06-22 19:34:18 UTC (rev 15310)
+++
branches/soc-2008-nicholasbishop/source/blender/blenloader/intern/readfile.c
2008-06-22 19:43:52 UTC (rev 15311)
@@ -2702,6 +2702,19 @@
}
}
+static void direct_link_mdisps(FileData *fd, int count, MDisps *mdisps)
+{
+ if(mdisps) {
+ int i;
+
+ for(i = 0; i < count; ++i) {
+ mdisps[i].disps = newdataadr(fd, mdisps[i].disps);
+ if(!mdisps[i].disps)
+ mdisps[i].totdisp = 0;
+ }
+ }
+}
+
static void direct_link_customdata(FileData *fd, CustomData *data, int count)
{
int i = 0;
@@ -2713,6 +2726,8 @@
if (CustomData_verify_versions(data, i)) {
layer->data = newdataadr(fd, layer->data);
+ if(layer->type == CD_MDISPS)
+ direct_link_mdisps(fd, count, layer->data);
i++;
}
}
Modified:
branches/soc-2008-nicholasbishop/source/blender/blenloader/intern/writefile.c
===================================================================
---
branches/soc-2008-nicholasbishop/source/blender/blenloader/intern/writefile.c
2008-06-22 19:34:18 UTC (rev 15310)
+++
branches/soc-2008-nicholasbishop/source/blender/blenloader/intern/writefile.c
2008-06-22 19:43:52 UTC (rev 15311)
@@ -1105,7 +1105,7 @@
static void write_dverts(WriteData *wd, int count, MDeformVert *dvlist)
{
if (dvlist) {
- int i;
+ int i;
/* Write the dvert list */
writestruct(wd, DATA, "MDeformVert", count, dvlist);
@@ -1118,6 +1118,19 @@
}
}
+static void write_mdisps(WriteData *wd, int count, MDisps *mdlist)
+{
+ if(mdlist) {
+ int i;
+
+ writestruct(wd, DATA, "MDisps", count, mdlist);
+ for(i = 0; i < count; ++i) {
+ if(mdlist[i].disps)
+ writedata(wd, DATA,
sizeof(float)*3*mdlist[i].totdisp, mdlist[i].disps);
+ }
+ }
+}
+
static void write_customdata(WriteData *wd, int count, CustomData *data, int
partial_type, int partial_count)
{
int i;
@@ -1133,6 +1146,9 @@
/* layer types that allocate own memory need special
handling */
write_dverts(wd, count, layer->data);
}
+ else if (layer->type == CD_MDISPS) {
+ write_mdisps(wd, count, layer->data);
+ }
else {
CustomData_file_write_info(layer->type, &structname,
&structnum);
if (structnum) {
Modified:
branches/soc-2008-nicholasbishop/source/blender/makesdna/DNA_meshdata_types.h
===================================================================
---
branches/soc-2008-nicholasbishop/source/blender/makesdna/DNA_meshdata_types.h
2008-06-22 19:34:18 UTC (rev 15310)
+++
branches/soc-2008-nicholasbishop/source/blender/makesdna/DNA_meshdata_types.h
2008-06-22 19:43:52 UTC (rev 15311)
@@ -101,6 +101,9 @@
} OrigSpaceFace;
typedef struct MDisps {
+ /* Strange bug in SDNA: if disps pointer comes first, it fails to see
totdisp */
+ int totdisp;
+ char pad[4];
float (*disps)[3];
} MDisps;
Modified: branches/soc-2008-nicholasbishop/source/blender/src/buttons_editing.c
===================================================================
--- branches/soc-2008-nicholasbishop/source/blender/src/buttons_editing.c
2008-06-22 19:34:18 UTC (rev 15310)
+++ branches/soc-2008-nicholasbishop/source/blender/src/buttons_editing.c
2008-06-22 19:43:52 UTC (rev 15311)
@@ -1657,6 +1657,17 @@
emd->vgroup = 0;
}
+static void multiresModifier_subdivide_button(void *mmd_v, void *ob_v)
+{
+ MultiresModifierData *mmd = mmd_v;
+ Mesh *me = get_mesh(ob_v);
+
+ if(mmd && me) {
+ multiresModifier_subdivide(mmd, me);
+ BIF_undo_push("Multires subdivide");
+ }
+}
+
static int modifier_is_fluid_particles(ModifierData *md) {
if(md->type == eModifierType_ParticleSystem) {
if(((ParticleSystemModifierData *)md)->psys->part->type ==
PART_FLUID)
@@ -2450,7 +2461,7 @@
uiBut *but;
but = uiDefBut(block,BUT,B_MODIFIER_RECALC,"Subdivide",
lx,(cy-=19),buttonWidth,19,0,0,0,0,0,"Increase the resolution of
displacements");
- uiButSetFunc(but, multiresModifier_subdivide, mmd, ob);
+ uiButSetFunc(but, multiresModifier_subdivide_button,
mmd, ob);
but = uiDefButC(block,NUM,B_MODIFIER_RECALC,"Level:
",lx,(cy-=19),buttonWidth,19, &mmd->lvl, 1.0, mmd->totlvl, 0,0,"");
uiButSetFunc(but, multiresModifier_setLevel, mmd, ob);
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs