Sculpt Branch:

* Don't allow adding/removing multires levels in editmode.
* Customdata code for swapping mdisps restored.
* Fix inflate brush crashing with multires.
* Smooth and layer brush don't work yet with multires, but at
  least avoids crashing now.
* Fix threading issue with flatten brush.
This commit is contained in:
Brecht Van Lommel 2009-12-07 19:11:37 +00:00
parent 010c99deb2
commit 4ca2581b77
4 changed files with 41 additions and 31 deletions

@ -440,6 +440,7 @@ class DATA_PT_modifiers(DataButtonsPanel):
if wide_ui:
col = split.column()
col.enabled = ob.mode != 'EDIT'
col.operator("object.multires_subdivide", text="Subdivide")
col.operator("object.multires_higher_levels_delete", text="Delete Higher")
row = col.row()

@ -440,29 +440,30 @@ static void mdisps_bilinear(float out[3], float (*disps)[3], int st, float u, fl
}
#endif
static int mdisp_corners(MDisps *s)
{
/* silly trick because we don't get it from callback */
return (s->totdisp % (3*3) == 0)? 3: 4;
}
static void layerSwap_mdisps(void *data, int *ci)
{
// XXX
#if 0
MDisps *s = data;
float (*d)[3] = NULL;
int x, y, st;
int corners, cornersize, S;
if(!(ci[0] == 2 && ci[1] == 3 && ci[2] == 0 && ci[3] == 1)) return;
/* this function is untested .. */
corners = mdisp_corners(s);
cornersize = s->totdisp/corners;
d = MEM_callocN(sizeof(float) * 3 * s->totdisp, "mdisps swap");
st = sqrt(s->totdisp);
for(y = 0; y < st; ++y) {
for(x = 0; x < st; ++x) {
copy_v3_v3(d[(st - y - 1) * st + (st - x - 1)], s->disps[y * st + x]);
}
}
for(S = 0; S < corners; S++)
memcpy(d + cornersize*S, s->disps + cornersize*ci[S], cornersize*3*sizeof(float));
if(s->disps)
MEM_freeN(s->disps);
s->disps = d;
#endif
}
static void layerInterp_mdisps(void **sources, float *weights, float *sub_weights,

@ -1012,12 +1012,12 @@ void BLI_pbvh_node_get_verts(PBVHNode *node, int **vert_indices, int *totvert, i
void BLI_pbvh_node_num_verts(PBVH *bvh, PBVHNode *node, int *uniquevert, int *totvert)
{
if(bvh->grids) {
*totvert= node->totprim*bvh->gridsize*bvh->gridsize;
*uniquevert= *totvert;
if(totvert) *totvert= node->totprim*bvh->gridsize*bvh->gridsize;
if(uniquevert) *uniquevert= *totvert;
}
else {
*uniquevert= node->uniq_verts;
*totvert= node->uniq_verts + node->face_verts;
if(totvert) *totvert= node->uniq_verts + node->face_verts;
if(uniquevert) *uniquevert= node->uniq_verts;
}
}
@ -1030,10 +1030,10 @@ void BLI_pbvh_node_get_grids(PBVH *bvh, PBVHNode *node, int **grid_indices, int
if(gridsize) *gridsize= bvh->gridsize;
}
else {
*grid_indices= NULL;
*totgrid= 0;
*maxgrid= 0;
*gridsize= 0;
if(grid_indices) *grid_indices= NULL;
if(totgrid) *totgrid= 0;
if(maxgrid) *maxgrid= 0;
if(gridsize) *gridsize= 0;
}
}

@ -905,6 +905,10 @@ static void do_smooth_brush(Sculpt *sd, SculptSession *ss, PBVHNode **nodes, int
float bstrength= ss->cache->bstrength;
int iteration, n;
/* XXX not working for multires yet */
if(!ss->fmap)
return;
for(iteration = 0; iteration < 2; ++iteration) {
#pragma omp parallel for private(n) schedule(static)
for(n=0; n<totnode; n++) {
@ -999,7 +1003,6 @@ static void do_grab_brush(Sculpt *sd, SculptSession *ss, PBVHNode **nodes, int t
BLI_pbvh_node_mark_update(nodes[n]);
}
}
static void do_layer_brush(Sculpt *sd, SculptSession *ss, PBVHNode **nodes, int totnode)
@ -1010,6 +1013,10 @@ static void do_layer_brush(Sculpt *sd, SculptSession *ss, PBVHNode **nodes, int
float lim= ss->cache->radius / 4;
int n;
/* XXX not working yet for multires */
if(!ss->mvert)
return;
if(ss->cache->flip)
lim = -lim;
@ -1081,10 +1088,10 @@ static void do_inflate_brush(Sculpt *sd, SculptSession *ss, PBVHNode **nodes, in
if(sculpt_brush_test(&test, vd.co)) {
float fade = tex_strength(ss, brush, vd.co, test.dist)*bstrength;
float add[3];
if(vd.fno) copy_v3_v3(add, vd.fno);
else normal_short_to_float_v3(add, vd.no);
add[0]= vd.no[0]/32767.0f;
add[1]= vd.no[1]/32767.0f;
add[2]= vd.no[2]/32767.0f;
mul_v3_fl(add, fade * ss->cache->radius);
add[0]*= ss->cache->scale[0];
add[1]*= ss->cache->scale[1];
@ -1116,16 +1123,17 @@ static void calc_flatten_center(Sculpt *sd, SculptSession *ss, PBVHNode **nodes,
for(n=0; n<totnode; n++) {
PBVHVertexIter vd;
SculptBrushTest test;
int j;
sculpt_undo_push_node(ss, nodes[n]);
sculpt_brush_test_init(ss, &test);
BLI_pbvh_vertex_iter_begin(ss->tree, nodes[n], vd, PBVH_ITER_UNIQUE) {
if(sculpt_brush_test(&test, vd.co)) {
for(i = 0; i < FLATTEN_SAMPLE_SIZE; ++i) {
if(test.dist > outer_dist[i]) {
copy_v3_v3(outer_co[i], vd.co);
outer_dist[i] = test.dist;
for(j = 0; j < FLATTEN_SAMPLE_SIZE; ++j) {
if(test.dist > outer_dist[j]) {
copy_v3_v3(outer_co[j], vd.co);
outer_dist[j] = test.dist;
break;
}
}
@ -1424,9 +1432,9 @@ void sculpt_update_mesh_elements(bContext *C, int need_fmap)
if((ss->multires = sculpt_multires_active(ob))) {
ss->totvert = dm->getNumVerts(dm);
ss->totface = dm->getNumFaces(dm);
ss->mvert = dm->getVertDataArray(dm, CD_MVERT);
ss->mface = dm->getFaceDataArray(dm, CD_MFACE);
ss->face_normals = dm->getFaceDataArray(dm, CD_NORMAL);
ss->mvert= NULL;
ss->mface= NULL;
ss->face_normals= NULL;
}
else {
Mesh *me = get_mesh(ob);
@ -1439,7 +1447,7 @@ void sculpt_update_mesh_elements(bContext *C, int need_fmap)
ss->ob = ob;
ss->tree = dm->getPBVH(ob, dm);
ss->fmap = (need_fmap)? dm->getFaceMap(dm): NULL;
ss->fmap = (need_fmap && dm->getFaceMap)? dm->getFaceMap(dm): NULL;
if((ob->shapeflag & OB_SHAPE_LOCK) && !sculpt_multires_active(ob)) {
ss->kb= ob_get_keyblock(ob);