[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [37145] branches/soc-2011-onion: Revision: 29388
Jason Wilkins
Jason.A.Wilkins at gmail.com
Fri Jun 3 22:49:55 CEST 2011
Revision: 37145
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37145
Author: jwilkins
Date: 2011-06-03 20:49:55 +0000 (Fri, 03 Jun 2011)
Log Message:
-----------
Revision: 29388
Author: nicholasbishop
Date: 1:20:55 PM, Thursday, June 10, 2010
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)
** jwilkins:
** this one was a little tricky
** I had to split the changes to sculpt.c between sculpt.c and sculpt_undo.c
** there seem to be some dependencies between BKE_subsurf.h, BKE_DerivedMesh.h, and BLI_pbvh.h that should be resolved
** had to change some more recent code to use the new grid macros (multires_apply_smat)
** XXX: is it really ok for the 'subgrid' in multires_apply_smat to assume the same gridsize and gridoffset? If so it can probably share a gridkey as well.
Modified Paths:
--------------
branches/soc-2011-onion/source/blender/blenkernel/BKE_DerivedMesh.h
branches/soc-2011-onion/source/blender/blenkernel/BKE_subsurf.h
branches/soc-2011-onion/source/blender/blenkernel/intern/CCGSubSurf.c
branches/soc-2011-onion/source/blender/blenkernel/intern/CCGSubSurf.h
branches/soc-2011-onion/source/blender/blenkernel/intern/multires.c
branches/soc-2011-onion/source/blender/blenkernel/intern/subsurf_ccg.c
branches/soc-2011-onion/source/blender/blenlib/BLI_pbvh.h
branches/soc-2011-onion/source/blender/blenlib/intern/pbvh.c
branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_mask.c
branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_stroke.c
branches/soc-2011-onion/source/blender/editors/sculpt_paint/sculpt.c
branches/soc-2011-onion/source/blender/editors/sculpt_paint/sculpt_undo.c
branches/soc-2011-onion/source/blender/gpu/GPU_buffers.h
branches/soc-2011-onion/source/blender/gpu/intern/gpu_buffers.c
Property Changed:
----------------
branches/soc-2011-onion/
Property changes on: branches/soc-2011-onion
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/soc-2010-jwilkins:28499-37009
/branches/soc-2010-nicolasbishop:28448-29352
/trunk/blender:36833-37054
+ /branches/soc-2010-jwilkins:28499-37009
/branches/soc-2010-nicolasbishop:28448-29352,29388
/trunk/blender:36833-37054
Modified: branches/soc-2011-onion/source/blender/blenkernel/BKE_DerivedMesh.h
===================================================================
--- branches/soc-2011-onion/source/blender/blenkernel/BKE_DerivedMesh.h 2011-06-03 20:44:23 UTC (rev 37144)
+++ branches/soc-2011-onion/source/blender/blenkernel/BKE_DerivedMesh.h 2011-06-03 20:49:55 UTC (rev 37145)
@@ -70,11 +70,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];
@@ -161,6 +157,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-2011-onion/source/blender/blenkernel/BKE_subsurf.h
===================================================================
--- branches/soc-2011-onion/source/blender/blenkernel/BKE_subsurf.h 2011-06-03 20:44:23 UTC (rev 37144)
+++ branches/soc-2011-onion/source/blender/blenkernel/BKE_subsurf.h 2011-06-03 20:49:55 UTC (rev 37145)
@@ -50,6 +50,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-2011-onion/source/blender/blenkernel/intern/CCGSubSurf.c
===================================================================
--- branches/soc-2011-onion/source/blender/blenkernel/intern/CCGSubSurf.c 2011-06-03 20:44:23 UTC (rev 37144)
+++ branches/soc-2011-onion/source/blender/blenkernel/intern/CCGSubSurf.c 2011-06-03 20:49:55 UTC (rev 37145)
@@ -2576,6 +2576,10 @@
}
}
+int ccgSubSurf_getGridKey(CCGSubSurf *ss) {
+ return ss->meshIFC.gridkey;
+}
+
/* Vert accessors */
CCGVertHDL ccgSubSurf_getVertVertHandle(CCGVert *v) {
Modified: branches/soc-2011-onion/source/blender/blenkernel/intern/CCGSubSurf.h
===================================================================
--- branches/soc-2011-onion/source/blender/blenkernel/intern/CCGSubSurf.h 2011-06-03 20:44:23 UTC (rev 37144)
+++ branches/soc-2011-onion/source/blender/blenkernel/intern/CCGSubSurf.h 2011-06-03 20:49:55 UTC (rev 37145)
@@ -21,6 +21,8 @@
example: if interpolating coordinates and paint masks,
that would be (3+1) floats, so finterpCount would be 4. */
int finterpCount;
+
+ int gridkey;
};
/***/
@@ -97,6 +99,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-2011-onion/source/blender/blenkernel/intern/multires.c
===================================================================
--- branches/soc-2011-onion/source/blender/blenkernel/intern/multires.c 2011-06-03 20:44:23 UTC (rev 37144)
+++ branches/soc-2011-onion/source/blender/blenkernel/intern/multires.c 2011-06-03 20:49:55 UTC (rev 37145)
@@ -386,23 +386,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);
}
}
@@ -627,14 +628,14 @@
dispdm->release(dispdm);
}
-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;
@@ -660,12 +661,13 @@
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);
DM_set_only_copy(cddm, CD_MASK_BAREMESH);
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);
@@ -679,11 +681,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);
@@ -718,27 +720,29 @@
multires_subdivide(mmd, ob, mmd->totlvl+1, updateblock, simple);
}
-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));
}
}
@@ -768,7 +772,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) {
@@ -783,6 +787,7 @@
gridData = dm->getGridData(dm);
gridOffset = dm->getGridOffset(dm);
subGridData = (oldGridData)? oldGridData: gridData;
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list