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:
authorNicholas Bishop <nicholasbishop@gmail.com>2012-05-11 00:33:09 +0400
committerNicholas Bishop <nicholasbishop@gmail.com>2012-05-11 00:33:09 +0400
commitf751d0f6ae7de155343e24e36965956bd7a061e3 (patch)
treed963bb17c3fb79066e9de499b20317626d60fe92 /source/blender/editors
parent2ca64189b734dbd289d1a07e1ce9d332eadebe19 (diff)
Replace hardcoded DMGridData structure with CCGElem/CCGKey.
* Changes to DerivedMesh interface: DMGridData has been removed, getGridData() now returns an array of CCGElem pointers. Also added getGridKey() to initialize a CCGKey (implemented only by CCGDerivedMesh.) * PBVH: added BLI_pbvh_get_grid_key(). * A lot of code is affected, but mainly is just replacing DMGridData.co, DMGridData.no, and sizeof(DMGridData) with the CCG_*_elem functions, removing the reliance on grid elements of exactly six floats.
Diffstat (limited to 'source/blender/editors')
-rw-r--r--source/blender/editors/object/object_bake.c31
-rw-r--r--source/blender/editors/sculpt_paint/paint_hide.c27
-rw-r--r--source/blender/editors/sculpt_paint/sculpt.c21
-rw-r--r--source/blender/editors/sculpt_paint/sculpt_undo.c9
4 files changed, 52 insertions, 36 deletions
diff --git a/source/blender/editors/object/object_bake.c b/source/blender/editors/object/object_bake.c
index 91acb18dfda..c6155b54aec 100644
--- a/source/blender/editors/object/object_bake.c
+++ b/source/blender/editors/object/object_bake.c
@@ -49,6 +49,7 @@
#include "BLI_math_geom.h"
#include "BKE_blender.h"
+#include "BKE_ccg.h"
#include "BKE_screen.h"
#include "BKE_context.h"
#include "BKE_global.h"
@@ -475,32 +476,32 @@ static void interp_barycentric_tri_data(float data[3][3], float u, float v, floa
/* mode = 0: interpolate normals,
* mode = 1: interpolate coord */
-static void interp_bilinear_grid(DMGridData *grid, int grid_size, float crn_x, float crn_y, int mode, float res[3])
+static void interp_bilinear_grid(CCGKey *key, CCGElem *grid, float crn_x, float crn_y, int mode, float res[3])
{
int x0, x1, y0, y1;
float u, v;
float data[4][3];
x0 = (int) crn_x;
- x1 = x0 >= (grid_size - 1) ? (grid_size - 1) : (x0 + 1);
+ x1 = x0 >= (key->grid_size - 1) ? (key->grid_size - 1) : (x0 + 1);
y0 = (int) crn_y;
- y1 = y0 >= (grid_size - 1) ? (grid_size - 1) : (y0 + 1);
+ y1 = y0 >= (key->grid_size - 1 ) ? (key->grid_size - 1) : (y0 + 1);
u = crn_x - x0;
v = crn_y - y0;
if (mode == 0) {
- copy_v3_v3(data[0], grid[y0 * grid_size + x0].no);
- copy_v3_v3(data[1], grid[y0 * grid_size + x1].no);
- copy_v3_v3(data[2], grid[y1 * grid_size + x1].no);
- copy_v3_v3(data[3], grid[y1 * grid_size + x0].no);
+ copy_v3_v3(data[0], CCG_grid_elem_no(key, grid, x0, y0));
+ copy_v3_v3(data[1], CCG_grid_elem_no(key, grid, x1, y0));
+ copy_v3_v3(data[2], CCG_grid_elem_no(key, grid, x1, y1));
+ copy_v3_v3(data[3], CCG_grid_elem_no(key, grid, x0, y1));
}
else {
- copy_v3_v3(data[0], grid[y0 * grid_size + x0].co);
- copy_v3_v3(data[1], grid[y0 * grid_size + x1].co);
- copy_v3_v3(data[2], grid[y1 * grid_size + x1].co);
- copy_v3_v3(data[3], grid[y1 * grid_size + x0].co);
+ copy_v3_v3(data[0], CCG_grid_elem_co(key, grid, x0, y0));
+ copy_v3_v3(data[1], CCG_grid_elem_co(key, grid, x1, y0));
+ copy_v3_v3(data[2], CCG_grid_elem_co(key, grid, x1, y1));
+ copy_v3_v3(data[3], CCG_grid_elem_co(key, grid, x0, y1));
}
interp_bilinear_quad_data(data, u, v, res);
@@ -509,7 +510,8 @@ static void interp_bilinear_grid(DMGridData *grid, int grid_size, float crn_x, f
static void get_ccgdm_data(DerivedMesh *lodm, DerivedMesh *hidm, const int *origindex, const int lvl, const int face_index, const float u, const float v, float co[3], float n[3])
{
MFace mface;
- DMGridData **grid_data;
+ CCGElem **grid_data;
+ CCGKey key;
float crn_x, crn_y;
int grid_size, S, face_side;
int *grid_offset, g_index;
@@ -519,6 +521,7 @@ static void get_ccgdm_data(DerivedMesh *lodm, DerivedMesh *hidm, const int *orig
grid_size = hidm->getGridSize(hidm);
grid_data = hidm->getGridData(hidm);
grid_offset = hidm->getGridOffset(hidm);
+ hidm->getGridKey(hidm, &key);
face_side = (grid_size << 1) - 1;
@@ -546,10 +549,10 @@ static void get_ccgdm_data(DerivedMesh *lodm, DerivedMesh *hidm, const int *orig
CLAMP(crn_y, 0.0f, grid_size);
if (n != NULL)
- interp_bilinear_grid(grid_data[g_index + S], grid_size, crn_x, crn_y, 0, n);
+ interp_bilinear_grid(&key, grid_data[g_index + S], crn_x, crn_y, 0, n);
if (co != NULL)
- interp_bilinear_grid(grid_data[g_index + S], grid_size, crn_x, crn_y, 1, co);
+ interp_bilinear_grid(&key, grid_data[g_index + S], crn_x, crn_y, 1, co);
}
/* mode = 0: interpolate normals,
diff --git a/source/blender/editors/sculpt_paint/paint_hide.c b/source/blender/editors/sculpt_paint/paint_hide.c
index a3c74b33f9e..ca70a81055c 100644
--- a/source/blender/editors/sculpt_paint/paint_hide.c
+++ b/source/blender/editors/sculpt_paint/paint_hide.c
@@ -45,6 +45,7 @@
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
+#include "BKE_ccg.h"
#include "BKE_context.h"
#include "BKE_DerivedMesh.h"
#include "BKE_mesh.h"
@@ -141,16 +142,18 @@ static void partialvis_update_grids(Object *ob,
PartialVisArea area,
float planes[4][4])
{
- DMGridData **grids;
+ CCGElem **grids;
+ CCGKey key;
BLI_bitmap *grid_hidden;
int any_visible = 0;
- int *grid_indices, gridsize, totgrid, any_changed, i;
+ int *grid_indices, totgrid, any_changed, i;
/* get PBVH data */
BLI_pbvh_node_get_grids(pbvh, node,
- &grid_indices, &totgrid, NULL, &gridsize,
- &grids, NULL);
+ &grid_indices, &totgrid, NULL, NULL,
+ &grids, NULL);
grid_hidden = BLI_pbvh_grid_hidden(pbvh);
+ BLI_pbvh_get_grid_key(pbvh, &key);
sculpt_undo_push_node(ob, node, SCULPT_UNDO_HIDDEN);
@@ -164,8 +167,8 @@ static void partialvis_update_grids(Object *ob,
switch (action) {
case PARTIALVIS_HIDE:
/* create grid flags data */
- gh = grid_hidden[g] = BLI_BITMAP_NEW(gridsize * gridsize,
- "partialvis_update_grids");
+ gh = grid_hidden[g] = BLI_BITMAP_NEW(key.grid_area,
+ "partialvis_update_grids");
break;
case PARTIALVIS_SHOW:
/* entire grid is visible, nothing to show */
@@ -182,21 +185,21 @@ static void partialvis_update_grids(Object *ob,
continue;
}
- for (y = 0; y < gridsize; y++) {
- for (x = 0; x < gridsize; x++) {
- const float *co = grids[g][y * gridsize + x].co;
+ for (y = 0; y < key.grid_size; y++) {
+ for (x = 0; x < key.grid_size; x++) {
+ const float *co = CCG_grid_elem_co(&key, grids[g], x, y);
/* skip grid element if not in the effected area */
if (is_effected(area, planes, co)) {
/* set or clear the hide flag */
- BLI_BITMAP_MODIFY(gh, y * gridsize + x,
- action == PARTIALVIS_HIDE);
+ BLI_BITMAP_MODIFY(gh, y * key.grid_size + x,
+ action == PARTIALVIS_HIDE);
any_changed = 1;
}
/* keep track of whether any elements are still hidden */
- if (BLI_BITMAP_GET(gh, y * gridsize + x))
+ if (BLI_BITMAP_GET(gh, y * key.grid_size + x))
any_hidden = 1;
else
any_visible = 1;
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index 3edda91e4e4..77f9a444153 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -52,6 +52,7 @@
#include "DNA_brush_types.h"
#include "BKE_brush.h"
+#include "BKE_ccg.h"
#include "BKE_cdderivedmesh.h"
#include "BKE_context.h"
#include "BKE_depsgraph.h"
@@ -1049,7 +1050,8 @@ static void do_multires_smooth_brush(Sculpt *sd, SculptSession *ss, PBVHNode *no
{
Brush *brush = paint_brush(&sd->paint);
SculptBrushTest test;
- DMGridData **griddata, *data;
+ CCGElem **griddata, *data;
+ CCGKey key;
DMGridAdjacency *gridadj, *adj;
float (*tmpgrid)[3], (*tmprow)[3];
int v1, v2, v3, v4;
@@ -1060,7 +1062,8 @@ static void do_multires_smooth_brush(Sculpt *sd, SculptSession *ss, PBVHNode *no
CLAMP(bstrength, 0.0f, 1.0f);
BLI_pbvh_node_get_grids(ss->pbvh, node, &grid_indices, &totgrid,
- NULL, &gridsize, &griddata, &gridadj);
+ NULL, &gridsize, &griddata, &gridadj);
+ BLI_pbvh_get_grid_key(ss->pbvh, &key);
#pragma omp critical
{
@@ -1078,7 +1081,9 @@ static void do_multires_smooth_brush(Sculpt *sd, SculptSession *ss, PBVHNode *no
float tmp[3];
v1 = y * gridsize;
- add_v3_v3v3(tmprow[0], data[v1].co, data[v1 + gridsize].co);
+ add_v3_v3v3(tmprow[0],
+ CCG_elem_offset_co(&key, data, v1),
+ CCG_elem_offset_co(&key, data, v1 + gridsize));
for (x = 0; x < gridsize - 1; x++) {
v1 = x + y * gridsize;
@@ -1086,7 +1091,9 @@ static void do_multires_smooth_brush(Sculpt *sd, SculptSession *ss, PBVHNode *no
v3 = v1 + gridsize;
v4 = v3 + 1;
- add_v3_v3v3(tmprow[x + 1], data[v2].co, data[v4].co);
+ add_v3_v3v3(tmprow[x + 1],
+ CCG_elem_offset_co(&key, data, v2),
+ CCG_elem_offset_co(&key, data, v4));
add_v3_v3v3(tmp, tmprow[x + 1], tmprow[x]);
add_v3_v3(tmpgrid[v1], tmp);
@@ -1115,9 +1122,9 @@ static void do_multires_smooth_brush(Sculpt *sd, SculptSession *ss, PBVHNode *no
if (y == gridsize - 1 && adj->index[1] == -1)
continue;
- index = x + y * gridsize;
- co = data[index].co;
- fno = data[index].no;
+ index = x + y*gridsize;
+ co = CCG_elem_offset_co(&key, data, index);
+ fno = CCG_elem_offset_no(&key, data, index);
if (sculpt_brush_test(&test, co)) {
const float fade = bstrength * tex_strength(ss, brush, co, test.dist,
diff --git a/source/blender/editors/sculpt_paint/sculpt_undo.c b/source/blender/editors/sculpt_paint/sculpt_undo.c
index 801bfabc748..ea5c173e410 100644
--- a/source/blender/editors/sculpt_paint/sculpt_undo.c
+++ b/source/blender/editors/sculpt_paint/sculpt_undo.c
@@ -47,6 +47,7 @@
#include "DNA_scene_types.h"
#include "DNA_mesh_types.h"
+#include "BKE_ccg.h"
#include "BKE_cdderivedmesh.h"
#include "BKE_context.h"
#include "BKE_depsgraph.h"
@@ -157,19 +158,21 @@ static int sculpt_undo_restore_coords(bContext *C, DerivedMesh *dm, SculptUndoNo
}
else if (unode->maxgrid && dm->getGridData) {
/* multires restore */
- DMGridData **grids, *grid;
+ CCGElem **grids, *grid;
+ CCGKey key;
float (*co)[3];
int gridsize;
grids = dm->getGridData(dm);
gridsize = dm->getGridSize(dm);
+ dm->getGridKey(dm, &key);
co = unode->co;
for (j = 0; j < unode->totgrid; j++) {
grid = grids[unode->grids[j]];
- for (i = 0; i < gridsize * gridsize; i++, co++)
- swap_v3_v3(grid[i].co, co[0]);
+ for (i = 0; i < gridsize*gridsize; i++, co++)
+ swap_v3_v3(CCG_elem_offset_co(&key, grid, i), co[0]);
}
}