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:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2009-12-11 19:59:09 +0300
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2009-12-11 19:59:09 +0300
commitcb4d9a7427e28f360dc168fab225e24c343dc10e (patch)
treef41ecc32910e23f6caf64d65d97772f16d45dc7e /source/blender/blenlib
parent026364dcca6539c4e3ad6a5010cba81e61638ef2 (diff)
Sculpt:
* 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.
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r--source/blender/blenlib/BLI_math_geom.h2
-rw-r--r--source/blender/blenlib/BLI_pbvh.h29
-rw-r--r--source/blender/blenlib/intern/math_geom.c33
-rw-r--r--source/blender/blenlib/intern/pbvh.c24
4 files changed, 64 insertions, 24 deletions
diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h
index c50d9caade0..49d335f6c5c 100644
--- a/source/blender/blenlib/BLI_math_geom.h
+++ b/source/blender/blenlib/BLI_math_geom.h
@@ -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]);
diff --git a/source/blender/blenlib/BLI_pbvh.h b/source/blender/blenlib/BLI_pbvh.h
index 12c13de183c..148d9507c14 100644
--- a/source/blender/blenlib/BLI_pbvh.h
+++ b/source/blender/blenlib/BLI_pbvh.h
@@ -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) { \
diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c
index efa5876e1b0..75c32c5b45b 100644
--- a/source/blender/blenlib/intern/math_geom.c
+++ b/source/blender/blenlib/intern/math_geom.c
@@ -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];
diff --git a/source/blender/blenlib/intern/pbvh.c b/source/blender/blenlib/intern/pbvh.c
index f0464438b68..d8e3fe4b0be 100644
--- a/source/blender/blenlib/intern/pbvh.c
+++ b/source/blender/blenlib/intern/pbvh.c
@@ -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;
-}
-