Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
847c86fb
T
three.js
项目概览
Ablesons
/
three.js
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
three.js
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
847c86fb
编写于
8月 11, 2013
作者:
M
Mr.doob
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Updated builds.
上级
2e7e660c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
335 addition
and
251 deletion
+335
-251
build/three.js
build/three.js
+161
-79
build/three.min.js
build/three.min.js
+174
-172
未找到文件。
build/three.js
浏览文件 @
847c86fb
...
...
@@ -5291,6 +5291,150 @@ THREE.Ray.prototype = {
},
isIntersectionBox: function () {
var v = new THREE.Vector3();
return function ( box ) {
return this.intersectBox( box, v ) !== null;
}
}(),
intersectBox: function ( box , optionalTarget ) {
// http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-7-intersecting-simple-shapes/ray-box-intersection/
var tmin,tmax,tymin,tymax,tzmin,tzmax;
var invdirx = 1/this.direction.x,
invdiry = 1/this.direction.y,
invdirz = 1/this.direction.z;
var origin = this.origin;
if (invdirx >= 0) {
tmin = (box.min.x - origin.x) * invdirx;
tmax = (box.max.x - origin.x) * invdirx;
} else {
tmin = (box.max.x - origin.x) * invdirx;
tmax = (box.min.x - origin.x) * invdirx;
}
if (invdiry >= 0) {
tymin = (box.min.y - origin.y) * invdiry;
tymax = (box.max.y - origin.y) * invdiry;
} else {
tymin = (box.max.y - origin.y) * invdiry;
tymax = (box.min.y - origin.y) * invdiry;
}
if ((tmin > tymax) || (tymin > tmax)) return null;
// These lines also handle the case where tmin or tmax is NaN
// (result of 0 * Infinity). x !== x returns true if x is NaN
if (tymin > tmin || tmin !== tmin ) tmin = tymin;
if (tymax < tmax || tmax !== tmax ) tmax = tymax;
if (invdirz >= 0) {
tzmin = (box.min.z - origin.z) * invdirz;
tzmax = (box.max.z - origin.z) * invdirz;
} else {
tzmin = (box.max.z - origin.z) * invdirz;
tzmax = (box.min.z - origin.z) * invdirz;
}
if ((tmin > tzmax) || (tzmin > tmax)) return null;
if (tzmin > tmin || tmin !== tmin ) tmin = tzmin;
if (tzmax < tmax || tmax !== tmax ) tmax = tzmax;
//return point closest to the ray (positive side)
if ( tmax < 0 ) return null;
return this.at( tmin >= 0 ? tmin : tmax, optionalTarget );
},
intersectTriangle: function() {
// Compute the offset origin, edges, and normal.
var diff = new THREE.Vector3();
var edge1 = new THREE.Vector3();
var edge2 = new THREE.Vector3();
var normal = new THREE.Vector3();
return function ( a, b, c, backfaceCulling, optionalTarget ) {
//from http://www.geometrictools.com/LibMathematics/Intersection/Wm5IntrRay3Triangle3.cpp
edge1.subVectors( b, a );
edge2.subVectors( c, a );
normal.crossVectors( edge1, edge2 );
// Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
// E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
// |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
// |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
// |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
var DdN = this.direction.dot(normal);
var sign;
if ( DdN > 0 ) {
if ( backfaceCulling ) return null;
sign = 1;
} else if ( DdN < 0 ) {
sign = - 1;
DdN = - DdN;
} else return null;
diff.subVectors( this.origin, a );
var DdQxE2 = sign * this.direction.dot( edge2.crossVectors( diff, edge2 ) );
// b1 < 0, no intersection
if ( DdQxE2 < 0 )
return null;
var DdE1xQ = sign * this.direction.dot( edge1.cross( diff ) );
// b2 < 0, no intersection
if ( DdE1xQ < 0 )
return null;
// b1+b2 > 1, no intersection
if ( DdQxE2 + DdE1xQ > DdN )
return null
// Line intersects triangle, check if ray does.
var QdN = - sign * diff.dot( normal );
// t < 0, no intersection
if ( QdN < 0 )
return null
// Ray intersects triangle.
return this.at( QdN / DdN, optionalTarget );
}
}(),
applyMatrix4: function ( matrix4 ) {
this.direction.add( this.origin ).applyMatrix4( matrix4 );
...
...
@@ -6301,69 +6445,6 @@ THREE.Triangle.containsPoint = function() {
}();
THREE.Triangle.intersectionRay = function () {
// Compute the offset origin, edges, and normal.
var diff = new THREE.Vector3();
var edge1 = new THREE.Vector3();
var edge2 = new THREE.Vector3();
var normal = new THREE.Vector3();
return function ( ray, a, b, c, backfaceCulling ) {
//from http://www.geometrictools.com/LibMathematics/Intersection/Wm5IntrRay3Triangle3.cpp
edge1.subVectors( b, a );
edge2.subVectors( c, a );
normal.crossVectors( edge1, edge2 );
// Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
// E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
// |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
// |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
// |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
var DdN = ray.direction.dot(normal);
var sign;
if ( DdN > 0 ) {
if ( backfaceCulling ) return null;
sign = 1;
} else if ( DdN < 0 ) {
sign = - 1;
DdN = - DdN;
} else return null;
diff.subVectors( ray.origin, a );
var DdQxE2 = sign * ray.direction.dot( edge2.crossVectors( diff, edge2 ) );
// b1 < 0, no intersection
if ( DdQxE2 < 0 )
return null;
var DdE1xQ = sign * ray.direction.dot( edge1.cross( diff ) );
// b2 < 0, no intersection
if ( DdE1xQ < 0 )
return null;
// b1+b2 > 1, no intersection
if ( DdQxE2 + DdE1xQ > DdN )
return null
// Line intersects triangle, check if ray does.
var QdN = - sign * diff.dot( normal );
// t < 0, no intersection
if ( QdN < 0 )
return null
// Ray intersects triangle.
return ray.at( QdN / DdN );
}
}();
THREE.Triangle.prototype = {
constructor: THREE.Triangle,
...
...
@@ -6447,12 +6528,6 @@ THREE.Triangle.prototype = {
},
intersectionRay: function ( ray, backfaceCulling ) {
return THREE.Triangle.intersectionRay( ray, this.a, this.b, this.c, backfaceCulling );
},
equals: function ( triangle ) {
return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
...
...
@@ -6737,6 +6812,21 @@ THREE.EventDispatcher.prototype = {
}
//Check boundingBox before continuing
inverseMatrix.getInverse( object.matrixWorld );
localRay.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
if ( geometry.boundingBox !== null) {
if ( localRay.isIntersectionBox(geometry.boundingBox) === false ) {
return intersects;
}
}
var vertices = geometry.vertices;
if ( geometry instanceof THREE.BufferGeometry ) {
...
...
@@ -6749,10 +6839,6 @@ THREE.EventDispatcher.prototype = {
var a, b, c;
var precision = raycaster.precision;
inverseMatrix.getInverse( object.matrixWorld );
localRay.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
var fl;
var indexed = false;
...
...
@@ -6810,7 +6896,7 @@ THREE.EventDispatcher.prototype = {
positions[ c * 3 + 2 ]
);
var interPoint =
THREE.Triangle.intersectionRay( localRay,
vA, vB, vC, material.side !== THREE.DoubleSide );
var interPoint =
localRay.intersectTriangle(
vA, vB, vC, material.side !== THREE.DoubleSide );
if ( !interPoint ) continue;
...
...
@@ -6843,10 +6929,6 @@ THREE.EventDispatcher.prototype = {
var a, b, c, d;
var precision = raycaster.precision;
inverseMatrix.getInverse( object.matrixWorld );
localRay.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
for ( var f = 0, fl = geometry.faces.length; f < fl; f ++ ) {
var face = geometry.faces[ f ];
...
...
@@ -6859,7 +6941,7 @@ THREE.EventDispatcher.prototype = {
b = vertices[ face.b ];
c = vertices[ face.c ];
var interPoint =
THREE.Triangle.intersectionRay( localRay,
a, b, c, material.side !== THREE.DoubleSide );
var interPoint =
localRay.intersectTriangle(
a, b, c, material.side !== THREE.DoubleSide );
if ( !interPoint ) {
...
...
build/three.min.js
浏览文件 @
847c86fb
因为 它太大了无法显示 source diff 。你可以改为
查看blob
。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录