[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [29388] branches/soc-2010-nicolasbishop/ source/blender: * Initial support for dynamically-sized Griddata from subsurf.
Nicholas Bishop
nicholasbishop at gmail.com
Thu Jun 10 20:20:55 CEST 2010
Revision: 29388
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29388
Author: nicholasbishop
Date: 2010-06-10 20:20:55 +0200 (Thu, 10 Jun 2010)
Log Message:
-----------
* Initial support for dynamically-sized Griddata from subsurf.
CCGSubsurf internally already fully supports vertdata of any size. This commit basically extends that support to all the code using the output of subsurf (with dm->getGridData).
For now, two types of grid data are set up: coords+normals with masks, and coords+normals without masks. More types to come.
For future reference, emacs find/replace regexps used to make some of the changes:
\(data\|subgrid\|grid\|edgeData\|faceGridData\)\[\(.*?\)\].\(co\|no\|mask\)
GRIDELEM_\,(upcase \3)_AT(\1, \2, gridkey)
&\(diffGrid\|gridA\|gridB\|faceGridData\|gridData\[i\]\|lowGridData\[i\]\)\[\(.*?\)\]
GRIDELEM_AT(\1, \2, gridkey)
\(vi\.grid\|vd\|a\|b\|vda\|vdb\)->\(co\|no\|mask\)
GRIDELEM_\,(upcase \2)(\1, gridkey)
Modified Paths:
--------------
branches/soc-2010-nicolasbishop/source/blender/blenkernel/BKE_DerivedMesh.h
branches/soc-2010-nicolasbishop/source/blender/blenkernel/BKE_subsurf.h
branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/CCGSubSurf.c
branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/CCGSubSurf.h
branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/multires.c
branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/subsurf_ccg.c
branches/soc-2010-nicolasbishop/source/blender/blenlib/BLI_pbvh.h
branches/soc-2010-nicolasbishop/source/blender/blenlib/intern/pbvh.c
branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_mask.c
branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/sculpt.c
branches/soc-2010-nicolasbishop/source/blender/gpu/gpu_buffers.h
branches/soc-2010-nicolasbishop/source/blender/gpu/intern/gpu_buffers.c
Modified: branches/soc-2010-nicolasbishop/source/blender/blenkernel/BKE_DerivedMesh.h
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/blenkernel/BKE_DerivedMesh.h 2010-06-10 16:06:54 UTC (rev 29387)
+++ branches/soc-2010-nicolasbishop/source/blender/blenkernel/BKE_DerivedMesh.h 2010-06-10 18:20:55 UTC (rev 29388)
@@ -68,11 +68,7 @@
#define SUB_ELEMS_EDGE 2
#define SUB_ELEMS_FACE 4
-typedef struct DMGridData {
- float co[3];
- float mask;
- float no[3];
-} DMGridData;
+typedef struct DMGridData DMGridData;
typedef struct DMGridAdjacency {
int index[4];
@@ -159,6 +155,7 @@
DMGridData **(*getGridData)(DerivedMesh *dm);
DMGridAdjacency *(*getGridAdjacency)(DerivedMesh *dm);
int *(*getGridOffset)(DerivedMesh *dm);
+ int (*getGridKey)(DerivedMesh *dm);
/* Iterate over each mapped vertex in the derived mesh, calling the
* given function with the original vert and the mapped vert's new
Modified: branches/soc-2010-nicolasbishop/source/blender/blenkernel/BKE_subsurf.h
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/blenkernel/BKE_subsurf.h 2010-06-10 16:06:54 UTC (rev 29387)
+++ branches/soc-2010-nicolasbishop/source/blender/blenkernel/BKE_subsurf.h 2010-06-10 18:20:55 UTC (rev 29388)
@@ -46,6 +46,43 @@
/**************************** External *****************************/
+/* Grids */
+
+/* Format of the data in a grid element */
+typedef enum {
+ GRID_ELEM_KEY_CO_NO = 0,
+ GRID_ELEM_KEY_CO_MASK_NO,
+ GRID_ELEM_KEY_TOTAL
+} DMGridElemKey;
+
+/* Information about the data stored by each type of key */
+typedef struct {
+ int size;
+ int has_mask;
+ int no_offset;
+ int mask_offset;
+ int interp_count;
+} DMGridElemKeyInfo;
+
+extern DMGridElemKeyInfo GridElemKeyInfo[GRID_ELEM_KEY_TOTAL];
+
+#define GRIDELEM_SIZE(_key) GridElemKeyInfo[_key].size
+#define GRIDELEM_HAS_MASK(_key) GridElemKeyInfo[_key].has_mask
+#define GRIDELEM_NO_OFFSET(_key) GridElemKeyInfo[_key].no_offset
+#define GRIDELEM_MASK_OFFSET(_key) GridElemKeyInfo[_key].mask_offset
+#define GRIDELEM_INTERP_COUNT(_key) GridElemKeyInfo[_key].interp_count
+
+#define GRIDELEM_AT(_grid, _elem, _key) (struct DMGridData*)(((char*)(_grid)) + (_elem) * GRIDELEM_SIZE(_key))
+#define GRIDELEM_INC(_grid, _inc, _key) ((_grid) = GRIDELEM_AT(_grid, _inc, _key))
+
+#define GRIDELEM_CO(_grid, _key) (float*)(_grid)
+#define GRIDELEM_NO(_grid, _key) (float*)((char*)(_grid) + GRIDELEM_NO_OFFSET(_key))
+#define GRIDELEM_MASK(_grid, _key) (float*)((char*)(_grid) + GRIDELEM_MASK_OFFSET(_key))
+
+#define GRIDELEM_CO_AT(_grid, _elem, _key) GRIDELEM_CO(GRIDELEM_AT(_grid, _elem, _key), _key)
+#define GRIDELEM_NO_AT(_grid, _elem, _key) GRIDELEM_NO(GRIDELEM_AT(_grid, _elem, _key), _key)
+#define GRIDELEM_MASK_AT(_grid, _elem, _key) GRIDELEM_MASK(GRIDELEM_AT(_grid, _elem, _key), _key)
+
struct DerivedMesh *subsurf_make_derived_from_derived(
struct DerivedMesh *dm,
struct SubsurfModifierData *smd,
Modified: branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/CCGSubSurf.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/CCGSubSurf.c 2010-06-10 16:06:54 UTC (rev 29387)
+++ branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/CCGSubSurf.c 2010-06-10 18:20:55 UTC (rev 29388)
@@ -2555,6 +2555,10 @@
}
}
+int ccgSubSurf_getGridKey(CCGSubSurf *ss) {
+ return ss->meshIFC.gridkey;
+}
+
/* Vert accessors */
CCGVertHDL ccgSubSurf_getVertVertHandle(CCGVert *v) {
Modified: branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/CCGSubSurf.h
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/CCGSubSurf.h 2010-06-10 16:06:54 UTC (rev 29387)
+++ branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/CCGSubSurf.h 2010-06-10 18:20:55 UTC (rev 29388)
@@ -18,6 +18,8 @@
example: if interpolating coordinates and paint masks,
that would be (3+1) floats, so finterpCount would be 4. */
int finterpCount;
+
+ int gridkey;
};
/***/
@@ -90,6 +92,7 @@
int ccgSubSurf_getEdgeLevelSize (CCGSubSurf *ss, int level);
int ccgSubSurf_getGridSize (CCGSubSurf *ss);
int ccgSubSurf_getGridLevelSize (CCGSubSurf *ss, int level);
+int ccgSubSurf_getGridKey (CCGSubSurf *ss);
CCGVert* ccgSubSurf_getVert (CCGSubSurf *ss, CCGVertHDL v);
CCGVertHDL ccgSubSurf_getVertVertHandle (CCGVert *v);
Modified: branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/multires.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/multires.c 2010-06-10 16:06:54 UTC (rev 29387)
+++ branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/multires.c 2010-06-10 18:20:55 UTC (rev 29388)
@@ -358,23 +358,24 @@
}
}
-static void multires_copy_dm_grid(DMGridData *gridA, DMGridData *gridB, int finterpCount, int sizeA, int sizeB)
+static void multires_copy_dm_grid(DMGridData *gridA, DMGridData *gridB, int gridkey, int sizeA, int sizeB)
{
int x, y, j, skip;
+ int size = sizeof(float)*GRIDELEM_INTERP_COUNT(gridkey);
if(sizeA > sizeB) {
skip = (sizeA-1)/(sizeB-1);
for(j = 0, y = 0; y < sizeB; y++)
for(x = 0; x < sizeB; x++, j++)
- memcpy(&gridA[y*skip*sizeA + x*skip], &gridB[j], sizeof(float) * finterpCount);
+ memcpy(GRIDELEM_AT(gridA, y*skip*sizeA + x*skip, gridkey), GRIDELEM_AT(gridB, j, gridkey), size);
}
else {
skip = (sizeB-1)/(sizeA-1);
for(j = 0, y = 0; y < sizeA; y++)
for(x = 0; x < sizeA; x++, j++)
- memcpy(&gridA[j], &gridB[y*skip*sizeB + x*skip], sizeof(float) * finterpCount);
+ memcpy(GRIDELEM_AT(gridA, j, gridkey), GRIDELEM_AT(gridB, y*skip*sizeB + x*skip, gridkey), size);
}
}
@@ -460,14 +461,14 @@
return subsurf_make_derived_from_derived(dm, &smd, 0, NULL, 0, 0);
}
-static DMGridData **copy_grids(DMGridData **grids, int totgrid, int gridsize)
+static DMGridData **copy_grids(DMGridData **grids, int totgrid, int gridsize, int gridkey)
{
DMGridData **grids_copy = MEM_callocN(sizeof(DMGridData*) * totgrid, "subgrids");
int i;
for(i = 0; i < totgrid; ++i) {
- grids_copy[i] = MEM_callocN(sizeof(DMGridData)*gridsize*gridsize, "subgrid");
- memcpy(grids_copy[i], grids[i], sizeof(DMGridData)*gridsize*gridsize);
+ grids_copy[i] = MEM_callocN(GRIDELEM_SIZE(gridkey)*gridsize*gridsize, "subgrid");
+ memcpy(grids_copy[i], grids[i], GRIDELEM_SIZE(gridkey)*gridsize*gridsize);
}
return grids_copy;
@@ -494,11 +495,12 @@
DerivedMesh *lowdm, *cddm, *highdm;
DMGridData **highGridData, **lowGridData, **subGridData;
CCGSubSurf *ss;
- int i, numGrids, highGridSize, lowGridSize;
+ int i, numGrids, highGridSize, lowGridSize, gridkey;
/* create subsurf DM from original mesh at high level */
cddm = CDDM_from_mesh(me, NULL);
highdm = subsurf_dm_create_local(ob, cddm, totlvl, simple, 0);
+ gridkey = highdm->getGridKey(highdm);
/* create multires DM from original mesh at low level */
lowdm = multires_dm_create_local(ob, cddm, lvl, lvl, simple);
@@ -512,11 +514,11 @@
lowGridData = lowdm->getGridData(lowdm);
/* backup subsurf grids */
- subGridData = copy_grids(highGridData, numGrids, highGridSize);
+ subGridData = copy_grids(highGridData, numGrids, highGridSize, gridkey);
/* overwrite with current displaced grids */
for(i = 0; i < numGrids; ++i)
- multires_copy_dm_grid(highGridData[i], lowGridData[i], 4 /* TODO */, highGridSize, lowGridSize);
+ multires_copy_dm_grid(highGridData[i], lowGridData[i], gridkey, highGridSize, lowGridSize);
/* low lower level dm no longer needed at this point */
lowdm->release(lowdm);
@@ -546,27 +548,29 @@
multires_set_tot_level(ob, mmd, totlvl);
}
-static void grid_tangent(int gridSize, int index, int x, int y, int axis, DMGridData **gridData, float t[3])
+static void grid_tangent(int gridSize, int index, int x, int y, int axis, DMGridData **gridData, int gridkey, float t[3])
{
+ DMGridData *grid = gridData[index];
+
if(axis == 0) {
if(x == gridSize - 1) {
if(y == gridSize - 1)
- sub_v3_v3v3(t, gridData[index][x + gridSize*(y - 1)].co, gridData[index][x - 1 + gridSize*(y - 1)].co);
+ sub_v3_v3v3(t, GRIDELEM_CO_AT(grid, x + gridSize*(y - 1), gridkey), GRIDELEM_CO_AT(grid, x - 1 + gridSize*(y - 1), gridkey));
else
- sub_v3_v3v3(t, gridData[index][x + gridSize*y].co, gridData[index][x - 1 + gridSize*y].co);
+ sub_v3_v3v3(t, GRIDELEM_CO_AT(grid, x + gridSize*y, gridkey), GRIDELEM_CO_AT(grid, x - 1 + gridSize*y, gridkey));
}
else
- sub_v3_v3v3(t, gridData[index][x + 1 + gridSize*y].co, gridData[index][x + gridSize*y].co);
+ sub_v3_v3v3(t, GRIDELEM_CO_AT(grid, x + 1 + gridSize*y, gridkey), GRIDELEM_CO_AT(grid, x + gridSize*y, gridkey));
}
else if(axis == 1) {
if(y == gridSize - 1) {
if(x == gridSize - 1)
- sub_v3_v3v3(t, gridData[index][x - 1 + gridSize*y].co, gridData[index][x - 1 + gridSize*(y - 1)].co);
+ sub_v3_v3v3(t, GRIDELEM_CO_AT(grid, x - 1 + gridSize*y, gridkey), GRIDELEM_CO_AT(grid, x - 1 + gridSize*(y - 1), gridkey));
else
- sub_v3_v3v3(t, gridData[index][x + gridSize*y].co, gridData[index][x + gridSize*(y - 1)].co);
+ sub_v3_v3v3(t, GRIDELEM_CO_AT(grid, x + gridSize*y, gridkey), GRIDELEM_CO_AT(grid, x + gridSize*(y - 1), gridkey));
}
else
- sub_v3_v3v3(t, gridData[index][x + gridSize*(y + 1)].co, gridData[index][x + gridSize*y].co);
+ sub_v3_v3v3(t, GRIDELEM_CO_AT(grid, x + gridSize*(y + 1), gridkey), GRIDELEM_CO_AT(grid, x + gridSize*y, gridkey));
}
}
@@ -596,7 +600,7 @@
MFace *mface = me->mface;
MDisps *mdisps = CustomData_get_layer(&me->fdata, CD_MDISPS);
CustomData *stored_grids;
- int *gridOffset;
+ int *gridOffset, gridkey;
int i, numGrids, gridSize, dGridSize, dSkip;
if(!mdisps) {
@@ -611,6 +615,7 @@
gridData = dm->getGridData(dm);
gridOffset = dm->getGridOffset(dm);
subGridData = (oldGridData)? oldGridData: gridData;
+ gridkey = dm->getGridKey(dm);
dGridSize = multires_side_tot[totlvl];
dSkip = (dGridSize-1)/(gridSize-1);
@@ -653,21 +658,21 @@
int ccgdm_offset = x + y*gridSize;
int stored_offset = dGridSize*y*dSkip + x*dSkip;
- float *co = grid[ccgdm_offset].co;
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list