* Temporary workaround for sculpt not working well with small polygons,
  still seems to be some issues, but can at least paint now.
* Small optimization avoiding local function variable aliasing.
This commit is contained in:
2009-12-11 16:59:09 +00:00
parent 026364dcca
commit cb4d9a7427
4 changed files with 64 additions and 24 deletions

View File

@@ -85,6 +85,8 @@ int isect_ray_tri_v3(float p1[3], float d[3],
float v0[3], float v1[3], float v2[3], float *lambda, float *uv);
int isect_ray_tri_threshold_v3(float p1[3], float d[3],
float v0[3], float v1[3], float v2[3], float *lambda, float *uv, float threshold);
int isect_ray_tri_epsilon_v3(float p1[3], float d[3],
float v0[3], float v1[3], float v2[3], float *lambda, float *uv, float epsilon);
/* point in polygon */
int isect_point_tri_v2(float p[2], float a[2], float b[2], float c[2]);

View File

@@ -100,6 +100,8 @@ void BLI_pbvh_node_get_grids(PBVH *bvh, PBVHNode *node,
struct DMGridData ***griddata, struct DMGridAdjacency **gridadj);
void BLI_pbvh_node_num_verts(PBVH *bvh, PBVHNode *node,
int *uniquevert, int *totvert);
void BLI_pbvh_node_get_verts(PBVH *bvh, PBVHNode *node,
int **vert_indices, struct MVert **verts);
void BLI_pbvh_node_get_BB(PBVHNode *node, float bb_min[3], float bb_max[3]);
void BLI_pbvh_node_get_original_BB(PBVHNode *node, float bb_min[3], float bb_max[3]);
@@ -149,11 +151,30 @@ typedef struct PBVHVertexIter {
float *fno;
} PBVHVertexIter;
void BLI_pbvh_node_verts_iter_init(PBVH *bvh, PBVHNode *node, PBVHVertexIter *vi, int mode);
#define BLI_pbvh_vertex_iter_begin(bvh, node, vi, mode) \
/* XXX breaks aliasing! */ \
BLI_pbvh_node_verts_iter_init(bvh, node, &vi, mode); \
{ \
struct DMGridData **grids; \
struct MVert *verts; \
int *grid_indices, totgrid, gridsize, *vert_indices, uniq_verts, totvert; \
\
memset(&vi, 0, sizeof(PBVHVertexIter)); \
\
BLI_pbvh_node_get_grids(bvh, node, &grid_indices, &totgrid, NULL, &gridsize, &grids, NULL); \
BLI_pbvh_node_num_verts(bvh, node, &uniq_verts, &totvert); \
BLI_pbvh_node_get_verts(bvh, node, &vert_indices, &verts); \
\
vi.grids= grids; \
vi.grid_indices= grid_indices; \
vi.totgrid= (grids)? totgrid: 1; \
vi.gridsize= gridsize; \
\
if(mode == PBVH_ITER_ALL) \
vi.totvert = totvert; \
else \
vi.totvert= uniq_verts; \
vi.vert_indices= vert_indices; \
vi.mverts= verts; \
}\
\
for(vi.i=0, vi.g=0; vi.g<vi.totgrid; vi.g++) { \
if(vi.grids) { \

View File

@@ -458,6 +458,39 @@ int isect_ray_tri_v3(float p1[3], float d[3], float v0[3], float v1[3], float v2
return 1;
}
int isect_ray_tri_epsilon_v3(float p1[3], float d[3], float v0[3], float v1[3], float v2[3], float *lambda, float *uv, float epsilon)
{
float p[3], s[3], e1[3], e2[3], q[3];
float a, f, u, v;
sub_v3_v3v3(e1, v1, v0);
sub_v3_v3v3(e2, v2, v0);
cross_v3_v3v3(p, d, e2);
a = dot_v3v3(e1, p);
if (a == 0.0f) return 0;
f = 1.0f/a;
sub_v3_v3v3(s, p1, v0);
cross_v3_v3v3(q, s, e1);
*lambda = f * dot_v3v3(e2, q);
if ((*lambda < 0.0)) return 0;
u = f * dot_v3v3(s, p);
if ((u < -epsilon)||(u > 1.0+epsilon)) return 0;
v = f * dot_v3v3(d, q);
if ((v < -epsilon)||((u + v) > 1.0+epsilon)) return 0;
if(uv) {
uv[0]= u;
uv[1]= v;
}
return 1;
}
int isect_ray_tri_threshold_v3(float p1[3], float d[3], float v0[3], float v1[3], float v2[3], float *lambda, float *uv, float threshold)
{
float p[3], s[3], e1[3], e2[3], q[3];

View File

@@ -1006,11 +1006,10 @@ void BLI_pbvh_node_mark_update(PBVHNode *node)
node->flag |= PBVH_UpdateNormals|PBVH_UpdateBB|PBVH_UpdateOriginalBB|PBVH_UpdateDrawBuffers|PBVH_UpdateRedraw;
}
void BLI_pbvh_node_get_verts(PBVHNode *node, int **vert_indices, int *totvert, int *allvert)
void BLI_pbvh_node_get_verts(PBVH *bvh, PBVHNode *node, int **vert_indices, MVert **verts)
{
if(vert_indices) *vert_indices= node->vert_indices;
if(totvert) *totvert= node->uniq_verts;
if(allvert) *allvert= node->uniq_verts + node->face_verts;
if(verts) *verts= bvh->verts;
}
void BLI_pbvh_node_num_verts(PBVH *bvh, PBVHNode *node, int *uniquevert, int *totvert)
@@ -1100,7 +1099,7 @@ static int ray_aabb_intersect(PBVHNode *node, void *data_v)
if((tmin > tzmax) || (tzmin > tmax))
return 0;
return 1;
/* XXX: Not sure about this?
@@ -1142,7 +1141,7 @@ static int ray_face_intersection(float ray_start[3], float ray_normal[3],
{
float dist = FLT_MAX;
if(!isect_ray_tri_threshold_v3(ray_start, ray_normal, t0, t1, t2,
if(!isect_ray_tri_epsilon_v3(ray_start, ray_normal, t0, t1, t2,
&dist, NULL, 0.001f))
dist = FLT_MAX;
@@ -1300,18 +1299,3 @@ void BLI_pbvh_draw(PBVH *bvh, float (*planes)[4], float (*face_nors)[3])
}
}
void BLI_pbvh_node_verts_iter_init(PBVH *bvh, PBVHNode *node, PBVHVertexIter *vi, int mode)
{
memset(vi, 0, sizeof(PBVHVertexIter));
vi->grids= bvh->grids;
vi->grid_indices= node->prim_indices;
vi->totgrid= (bvh->grids)? node->totprim: 1;
vi->gridsize= bvh->gridsize;
vi->totvert= node->uniq_verts;
if(mode == PBVH_ITER_ALL)
vi->totvert += node->face_verts;
vi->vert_indices= node->vert_indices;
vi->mverts= bvh->verts;
}