[Bf-blender-cvs] [717046a] master: Use looptri for volume snapping
Campbell Barton
noreply at git.blender.org
Thu Jul 23 06:46:09 CEST 2015
Commit: 717046ad2a41c5b7d23313c77eca6ffc9f7b8762
Author: Campbell Barton
Date: Thu Jul 23 12:56:44 2015 +1000
Branches: master
https://developer.blender.org/rB717046ad2a41c5b7d23313c77eca6ffc9f7b8762
Use looptri for volume snapping
===================================================================
M source/blender/editors/transform/transform_snap.c
===================================================================
diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c
index 99d9836..d1cd33b 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);
- }
- }
}
}
}
More information about the Bf-blender-cvs
mailing list