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:
authorCampbell Barton <ideasman42@gmail.com>2015-07-23 05:56:44 +0300
committerCampbell Barton <ideasman42@gmail.com>2015-07-23 07:41:09 +0300
commit717046ad2a41c5b7d23313c77eca6ffc9f7b8762 (patch)
tree0593f505fad58b34c64a9ff08146eec619574bbf /source/blender/editors/transform/transform_snap.c
parent748899a50a0c1d83495db30a6161060cfbf420f1 (diff)
Use looptri for volume snapping
Diffstat (limited to 'source/blender/editors/transform/transform_snap.c')
-rw-r--r--source/blender/editors/transform/transform_snap.c60
1 files changed, 19 insertions, 41 deletions
diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c
index 99d9836014c..d1cd33b5949 100644
--- a/source/blender/editors/transform/transform_snap.c
+++ b/source/blender/editors/transform/transform_snap.c
@@ -2062,9 +2062,11 @@ static bool peelDerivedMesh(Object *ob, DerivedMesh *dm, float obmat[4][4],
{
bool retval = false;
int totvert = dm->getNumVerts(dm);
- int totface = dm->getNumTessFaces(dm);
if (totvert > 0) {
+ const MLoopTri *looptri = dm->getLoopTriArray(dm);
+ const MLoop *mloop = dm->getLoopArray(dm);
+ int looptri_num = dm->getNumLoopTri(dm);
float imat[4][4];
float timat[3][3]; /* transpose inverse matrix for normals */
float ray_start_local[3], ray_normal_local[3];
@@ -2080,23 +2082,27 @@ static bool peelDerivedMesh(Object *ob, DerivedMesh *dm, float obmat[4][4],
/* If number of vert is more than an arbitrary limit,
* test against boundbox first
* */
- if (totface > 16) {
+ if (looptri_num > 16) {
struct BoundBox *bb = BKE_object_boundbox_get(ob);
test = BKE_boundbox_ray_hit_check(bb, ray_start_local, ray_normal_local, NULL);
}
if (test == 1) {
+ const MLoopTri *lt;
MVert *verts = dm->getVertArray(dm);
- MFace *faces = dm->getTessFaceArray(dm);
+ float (*polynors)[3] = dm->getPolyDataArray(dm, CD_NORMAL);
int i;
- for (i = 0; i < totface; i++) {
- MFace *f = faces + i;
+ for (i = 0, lt = looptri; i < looptri_num; i++, lt++) {
+ const unsigned int vtri[3] = {mloop[lt->tri[0]].v, mloop[lt->tri[1]].v, mloop[lt->tri[2]].v};
float lambda;
int result;
- result = isect_ray_tri_threshold_v3(ray_start_local, ray_normal_local, verts[f->v1].co, verts[f->v2].co, verts[f->v3].co, &lambda, NULL, 0.001);
+ result = isect_ray_tri_threshold_v3(
+ ray_start_local, ray_normal_local,
+ verts[vtri[0]].co, verts[vtri[1]].co, verts[vtri[2]].co,
+ &lambda, NULL, 0.001);
if (result) {
float location[3], normal[3];
@@ -2108,11 +2114,13 @@ static bool peelDerivedMesh(Object *ob, DerivedMesh *dm, float obmat[4][4],
add_v3_v3(intersect, ray_start_local);
copy_v3_v3(location, intersect);
-
- if (f->v4)
- normal_quad_v3(normal, verts[f->v1].co, verts[f->v2].co, verts[f->v3].co, verts[f->v4].co);
- else
- normal_tri_v3(normal, verts[f->v1].co, verts[f->v2].co, verts[f->v3].co);
+
+ if (polynors) {
+ copy_v3_v3(normal, polynors[lt->poly]);
+ }
+ else {
+ normal_tri_v3(normal, verts[vtri[0]].co, verts[vtri[1]].co, verts[vtri[2]].co);
+ }
mul_m4_v3(obmat, location);
@@ -2123,36 +2131,6 @@ static bool peelDerivedMesh(Object *ob, DerivedMesh *dm, float obmat[4][4],
addDepthPeel(depth_peels, new_depth, location, normal, ob);
}
-
- if (f->v4 && result == 0) {
- result = isect_ray_tri_threshold_v3(ray_start_local, ray_normal_local, verts[f->v3].co, verts[f->v4].co, verts[f->v1].co, &lambda, NULL, 0.001);
-
- if (result) {
- float location[3], normal[3];
- float intersect[3];
- float new_depth;
-
- copy_v3_v3(intersect, ray_normal_local);
- mul_v3_fl(intersect, lambda);
- add_v3_v3(intersect, ray_start_local);
-
- copy_v3_v3(location, intersect);
-
- if (f->v4)
- normal_quad_v3(normal, verts[f->v1].co, verts[f->v2].co, verts[f->v3].co, verts[f->v4].co);
- else
- normal_tri_v3(normal, verts[f->v1].co, verts[f->v2].co, verts[f->v3].co);
-
- mul_m4_v3(obmat, location);
-
- new_depth = len_v3v3(location, ray_start);
-
- mul_m3_v3(timat, normal);
- normalize_v3(normal);
-
- addDepthPeel(depth_peels, new_depth, location, normal, ob);
- }
- }
}
}
}