Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
b6861b3e
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,发现更多精彩内容 >>
提交
b6861b3e
编写于
8月 19, 2012
作者:
M
Mr.doob
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Yet more Ray clean up.
上级
92fa4b68
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
424 addition
and
415 deletion
+424
-415
build/three.js
build/three.js
+46
-26
build/three.min.js
build/three.min.js
+222
-221
examples/webgl_interactive_cubes.html
examples/webgl_interactive_cubes.html
+8
-8
src/core/Ray.js
src/core/Ray.js
+148
-160
未找到文件。
build/three.js
浏览文件 @
b6861b3e
...
...
@@ -2761,27 +2761,13 @@ THREE.Frustum.__v1 = new THREE.Vector3();
};
//
THREE.Ray.prototype.precision = 0.0001;
THREE.Ray.prototype.intersectObject = function ( object, recursive ) {
var intersect, intersects = [], distance;
if ( recursive === true ) {
for ( var i = 0, l = object.children.length; i < l; i ++ ) {
Array.prototype.push.apply( intersects, this.intersectObject( object.children[ i ], recursive ) );
var intersectObject = function ( object, ray, intersects ) {
}
}
var distance,intersect;
if ( object instanceof THREE.Particle ) {
distance = distanceFromIntersection(
this.origin, this
.direction, object.matrixWorld.getPosition() );
distance = distanceFromIntersection(
ray.origin, ray
.direction, object.matrixWorld.getPosition() );
if ( distance > object.scale.x ) {
...
...
@@ -2808,9 +2794,9 @@ THREE.Frustum.__v1 = new THREE.Vector3();
// Checking distance to ray
distance = distanceFromIntersection(
this.origin, this
.direction, object.matrixWorld.getPosition() );
distance = distanceFromIntersection(
ray.origin, ray
.direction, object.matrixWorld.getPosition() );
if ( distance > scaledRadius
) {
if ( distance > scaledRadius) {
return intersects;
...
...
@@ -2827,13 +2813,13 @@ THREE.Frustum.__v1 = new THREE.Vector3();
geometryMaterials = object.geometry.materials;
isFaceMaterial = object.material instanceof THREE.MeshFaceMaterial;
side = object.material.side;
var a, b, c, d;
var precision =
this
.precision;
var precision =
ray
.precision;
object.matrixRotationWorld.extractRotation( object.matrixWorld );
originCopy.copy( this.origin );
//directionCopy.copy( this.direction );
originCopy.copy( ray.origin );
objMatrix = object.matrixWorld;
inverseMatrix.getInverse( objMatrix );
...
...
@@ -2841,7 +2827,7 @@ THREE.Frustum.__v1 = new THREE.Vector3();
localOriginCopy.copy( originCopy );
inverseMatrix.multiplyVector3( localOriginCopy );
localDirectionCopy.copy(
this
.direction );
localDirectionCopy.copy(
ray
.direction );
inverseMatrix.rotateAxis( localDirectionCopy ).normalize();
for ( f = 0, fl = geometry.faces.length; f < fl; f ++ ) {
...
...
@@ -2883,7 +2869,7 @@ THREE.Frustum.__v1 = new THREE.Vector3();
point = object.matrixWorld.multiplyVector3( intersectPoint.clone() );
distance = originCopy.distanceTo( point );
if ( distance <
this.near || distance > this
.far ) continue;
if ( distance <
ray.near || distance > ray
.far ) continue;
intersect = {
...
...
@@ -2911,7 +2897,7 @@ THREE.Frustum.__v1 = new THREE.Vector3();
point = object.matrixWorld.multiplyVector3( intersectPoint.clone() );
distance = originCopy.distanceTo( point );
if ( distance <
this.near || distance > this
.far ) continue;
if ( distance <
ray.near || distance > ray
.far ) continue;
intersect = {
...
...
@@ -2935,6 +2921,35 @@ THREE.Frustum.__v1 = new THREE.Vector3();
}
};
var intersectDescendants= function ( object, ray, intersects ) {
var descendants = object.getDescendants();
for ( var i = 0, l = descendants.length; i < l; i ++ ) {
intersectObject( descendants[ i ], this, intersects );
}
};
//
THREE.Ray.prototype.precision = 0.0001;
THREE.Ray.prototype.intersectObject = function ( object, recursive ) {
var intersects = [];
if ( recursive === true ) {
intersectDescendants( object, this, intersects );
}
intersectObject(object,this,intersects);
intersects.sort( descSort );
return intersects;
...
...
@@ -2947,8 +2962,13 @@ THREE.Frustum.__v1 = new THREE.Vector3();
for ( var i = 0, l = objects.length; i < l; i ++ ) {
Array.prototype.push.apply( intersects, this.intersectObject( objects[ i ], recursive ) );
intersectObject( objects[ i ], this, intersects );
if ( recursive === true ) {
intersectDescendants( objects[ i ], this, intersects );
}
}
intersects.sort( descSort );
...
...
build/three.min.js
浏览文件 @
b6861b3e
因为 它太大了无法显示 source diff 。你可以改为
查看blob
。
examples/webgl_interactive_cubes.html
浏览文件 @
b6861b3e
...
...
@@ -57,7 +57,7 @@
var
geometry
=
new
THREE
.
CubeGeometry
(
20
,
20
,
20
);
for
(
var
i
=
0
;
i
<
5
00
;
i
++
)
{
for
(
var
i
=
0
;
i
<
20
00
;
i
++
)
{
var
object
=
new
THREE
.
Mesh
(
geometry
,
new
THREE
.
MeshLambertMaterial
(
{
color
:
Math
.
random
()
*
0xffffff
}
)
);
...
...
@@ -69,9 +69,9 @@
object
.
rotation
.
y
=
(
Math
.
random
()
*
360
)
*
Math
.
PI
/
180
;
object
.
rotation
.
z
=
(
Math
.
random
()
*
360
)
*
Math
.
PI
/
180
;
object
.
scale
.
x
=
Math
.
random
()
*
2
+
1
;
object
.
scale
.
y
=
Math
.
random
()
*
2
+
1
;
object
.
scale
.
z
=
Math
.
random
()
*
2
+
1
;
object
.
scale
.
x
=
Math
.
random
()
+
0.5
;
object
.
scale
.
y
=
Math
.
random
()
+
0.5
;
object
.
scale
.
z
=
Math
.
random
()
+
0.5
;
scene
.
add
(
object
);
...
...
@@ -153,17 +153,17 @@
if
(
INTERSECTED
!=
intersects
[
0
].
object
)
{
if
(
INTERSECTED
)
INTERSECTED
.
material
.
color
.
setHex
(
INTERSECTED
.
currentHex
);
if
(
INTERSECTED
)
INTERSECTED
.
material
.
emissive
.
setHex
(
INTERSECTED
.
currentHex
);
INTERSECTED
=
intersects
[
0
].
object
;
INTERSECTED
.
currentHex
=
INTERSECTED
.
material
.
color
.
getHex
();
INTERSECTED
.
material
.
color
.
setHex
(
0xff0000
);
INTERSECTED
.
currentHex
=
INTERSECTED
.
material
.
emissive
.
getHex
();
INTERSECTED
.
material
.
emissive
.
setHex
(
0xff0000
);
}
}
else
{
if
(
INTERSECTED
)
INTERSECTED
.
material
.
color
.
setHex
(
INTERSECTED
.
currentHex
);
if
(
INTERSECTED
)
INTERSECTED
.
material
.
emissive
.
setHex
(
INTERSECTED
.
currentHex
);
INTERSECTED
=
null
;
...
...
src/core/Ray.js
浏览文件 @
b6861b3e
/**
* @author mrdoob / http://mrdoob.com/
*/
(
function
(
THREE
){
(
function
(
THREE
)
{
THREE
.
Ray
=
function
(
origin
,
direction
,
near
,
far
)
{
this
.
origin
=
origin
||
new
THREE
.
Vector3
();
this
.
direction
=
direction
||
new
THREE
.
Vector3
();
this
.
near
=
near
||
0
;
this
.
far
=
far
||
Infinity
;
};
var
originCopy
=
new
THREE
.
Vector3
();
var
localOriginCopy
=
new
THREE
.
Vector3
();
var
localDirectionCopy
=
new
THREE
.
Vector3
();
var
vector
=
new
THREE
.
Vector3
();
var
normal
=
new
THREE
.
Vector3
();
var
intersectPoint
=
new
THREE
.
Vector3
();
var
inverseMatrix
=
new
THREE
.
Matrix4
();
var
descSort
=
function
(
a
,
b
)
{
return
a
.
distance
-
b
.
distance
;
};
var
v0
=
new
THREE
.
Vector3
(),
v1
=
new
THREE
.
Vector3
(),
v2
=
new
THREE
.
Vector3
();
var
distanceFromIntersection
=
function
(
origin
,
direction
,
position
)
{
var
dot
,
intersect
,
distance
;
v0
.
sub
(
position
,
origin
);
dot
=
v0
.
dot
(
direction
);
intersect
=
v1
.
add
(
origin
,
v2
.
copy
(
direction
).
multiplyScalar
(
dot
)
);
distance
=
position
.
distanceTo
(
intersect
);
var
dot
=
v0
.
dot
(
direction
);
var
intersect
=
v1
.
add
(
origin
,
v2
.
copy
(
direction
).
multiplyScalar
(
dot
)
);
var
distance
=
position
.
distanceTo
(
intersect
);
return
distance
;
};
// http://www.blackpawn.com/texts/pointinpoly/default.html
var
pointInFace3
=
function
(
p
,
a
,
b
,
c
)
{
var
dot00
,
dot01
,
dot02
,
dot11
,
dot12
,
invDenom
,
u
,
v
;
v0
.
sub
(
c
,
a
);
v1
.
sub
(
b
,
a
);
v2
.
sub
(
p
,
a
);
dot00
=
v0
.
dot
(
v0
);
dot01
=
v0
.
dot
(
v1
);
dot02
=
v0
.
dot
(
v2
);
dot11
=
v1
.
dot
(
v1
);
dot12
=
v1
.
dot
(
v2
);
invDenom
=
1
/
(
dot00
*
dot11
-
dot01
*
dot01
);
u
=
(
dot11
*
dot02
-
dot01
*
dot12
)
*
invDenom
;
v
=
(
dot00
*
dot12
-
dot01
*
dot02
)
*
invDenom
;
var
dot00
=
v0
.
dot
(
v0
);
var
dot01
=
v0
.
dot
(
v1
);
var
dot02
=
v0
.
dot
(
v2
);
var
dot11
=
v1
.
dot
(
v1
);
var
dot12
=
v1
.
dot
(
v2
);
var
invDenom
=
1
/
(
dot00
*
dot11
-
dot01
*
dot01
);
var
u
=
(
dot11
*
dot02
-
dot01
*
dot12
)
*
invDenom
;
v
ar
v
=
(
dot00
*
dot12
-
dot01
*
dot02
)
*
invDenom
;
return
(
u
>=
0
)
&&
(
v
>=
0
)
&&
(
u
+
v
<
1
);
};
var
intersectObject
=
function
(
object
,
ray
,
intersects
){
var
intersectObject
=
function
(
object
,
ray
,
intersects
)
{
var
distance
,
intersect
;
if
(
object
instanceof
THREE
.
Particle
)
{
distance
=
distanceFromIntersection
(
ray
.
origin
,
ray
.
direction
,
object
.
matrixWorld
.
getPosition
()
);
if
(
distance
>
object
.
scale
.
x
)
{
return
[]
;
return
intersects
;
}
intersect
=
{
distance
:
distance
,
point
:
object
.
position
,
face
:
null
,
object
:
object
};
intersects
.
push
(
intersect
);
}
else
if
(
object
instanceof
THREE
.
Mesh
)
{
// Checking boundingSphere
//var scale = THREE.Frustum.__v1.set( object.matrixWorld.getColumnX().length(), object.matrixWorld.getColumnY().length(), object.matrixWorld.getColumnZ().length() );
var
scaledRadius
=
object
.
geometry
.
boundingSphere
.
radius
*
object
.
matrixWorld
.
getMaxScaleOnAxis
();
// Checking distance to ray
distance
=
distanceFromIntersection
(
ray
.
origin
,
ray
.
direction
,
object
.
matrixWorld
.
getPosition
()
);
if
(
distance
>
scaledRadius
)
{
return
intersects
;
}
// Checking faces
var
f
,
fl
,
face
,
dot
,
scalar
,
geometry
=
object
.
geometry
,
vertices
=
geometry
.
vertices
,
objMatrix
,
geometryMaterials
,
isFaceMaterial
,
material
,
side
,
point
;
geometryMaterials
=
object
.
geometry
.
materials
;
isFaceMaterial
=
object
.
material
instanceof
THREE
.
MeshFaceMaterial
;
side
=
object
.
material
.
side
;
var
a
,
b
,
c
,
d
;
var
precision
=
ray
.
precision
;
object
.
matrixRotationWorld
.
extractRotation
(
object
.
matrixWorld
);
originCopy
.
copy
(
ray
.
origin
);
objMatrix
=
object
.
matrixWorld
;
inverseMatrix
.
getInverse
(
objMatrix
);
localOriginCopy
.
copy
(
originCopy
);
inverseMatrix
.
multiplyVector3
(
localOriginCopy
);
localDirectionCopy
.
copy
(
ray
.
direction
);
inverseMatrix
.
rotateAxis
(
localDirectionCopy
).
normalize
();
inverseMatrix
.
getInverse
(
objMatrix
);
localOriginCopy
.
copy
(
originCopy
);
inverseMatrix
.
multiplyVector3
(
localOriginCopy
);
localDirectionCopy
.
copy
(
ray
.
direction
);
inverseMatrix
.
rotateAxis
(
localDirectionCopy
).
normalize
();
for
(
f
=
0
,
fl
=
geometry
.
faces
.
length
;
f
<
fl
;
f
++
)
{
face
=
geometry
.
faces
[
f
];
material
=
isFaceMaterial
===
true
?
geometryMaterials
[
face
.
materialIndex
]
:
object
.
material
;
if
(
material
===
undefined
)
continue
;
side
=
material
.
side
;
vector
.
sub
(
face
.
centroid
,
localOriginCopy
);
normal
=
face
.
normal
;
dot
=
localDirectionCopy
.
dot
(
normal
);
// bail if ray and plane are parallel
if
(
Math
.
abs
(
dot
)
<
precision
)
continue
;
// calc distance to plane
scalar
=
normal
.
dot
(
vector
)
/
dot
;
// if negative distance, then plane is behind ray
if
(
scalar
<
0
)
continue
;
if
(
side
===
THREE
.
DoubleSide
||
(
side
===
THREE
.
FrontSide
?
dot
<
0
:
dot
>
0
)
)
{
intersectPoint
.
add
(
localOriginCopy
,
localDirectionCopy
.
multiplyScalar
(
scalar
)
);
if
(
face
instanceof
THREE
.
Face3
)
{
a
=
vertices
[
face
.
a
];
b
=
vertices
[
face
.
b
];
c
=
vertices
[
face
.
c
];
if
(
pointInFace3
(
intersectPoint
,
a
,
b
,
c
)
)
{
point
=
object
.
matrixWorld
.
multiplyVector3
(
intersectPoint
.
clone
());
distance
=
originCopy
.
distanceTo
(
point
);
if
(
distance
<
ray
.
near
)
continue
;
if
(
distance
>
ray
.
far
)
continue
;
point
=
object
.
matrixWorld
.
multiplyVector3
(
intersectPoint
.
clone
()
);
distance
=
originCopy
.
distanceTo
(
point
);
if
(
distance
<
ray
.
near
||
distance
>
ray
.
far
)
continue
;
intersect
=
{
distance
:
distance
,
point
:
point
,
face
:
face
,
faceIndex
:
f
,
object
:
object
};
intersects
.
push
(
intersect
);
}
}
else
if
(
face
instanceof
THREE
.
Face4
)
{
a
=
vertices
[
face
.
a
];
b
=
vertices
[
face
.
b
];
c
=
vertices
[
face
.
c
];
d
=
vertices
[
face
.
d
];
if
(
pointInFace3
(
intersectPoint
,
a
,
b
,
d
)
||
pointInFace3
(
intersectPoint
,
b
,
c
,
d
)
)
{
point
=
object
.
matrixWorld
.
multiplyVector3
(
intersectPoint
.
clone
());
distance
=
originCopy
.
distanceTo
(
point
);
if
(
distance
<
ray
.
near
)
continue
;
if
(
distance
>
ray
.
far
)
continue
;
point
=
object
.
matrixWorld
.
multiplyVector3
(
intersectPoint
.
clone
()
);
distance
=
originCopy
.
distanceTo
(
point
);
if
(
distance
<
ray
.
near
||
distance
>
ray
.
far
)
continue
;
intersect
=
{
distance
:
distance
,
point
:
point
,
face
:
face
,
faceIndex
:
f
,
object
:
object
};
intersects
.
push
(
intersect
);
}
}
}
}
}
};
var
intersectDescendants
=
function
(
object
,
ray
,
intersects
){
var
intersectDescendants
=
function
(
object
,
ray
,
intersects
)
{
var
descendants
=
object
.
getDescendants
();
var
length
=
descendants
.
length
;
for
(
var
i
=
0
;
i
<
length
;
i
++
)
{
intersectObject
(
descendants
[
i
],
this
,
intersects
);
for
(
var
i
=
0
,
l
=
descendants
.
length
;
i
<
l
;
i
++
)
{
intersectObject
(
descendants
[
i
],
this
,
intersects
);
}
};
//
THREE
.
Ray
.
prototype
.
precision
=
0.0001
;
/*
This has deemed to be unnessecary
THREE.Ray.prototype.setPrecision = function ( value ) {
this.precision = value;
};*/
THREE
.
Ray
.
prototype
.
intersectObject
=
function
(
object
,
recursive
)
{
var
intersects
=
[];
if
(
recursive
===
true
)
{
intersectDescendants
(
object
,
this
,
intersects
);
intersectDescendants
(
object
,
this
,
intersects
);
}
intersectObject
(
object
,
this
,
intersects
);
intersects
.
sort
(
descSort
);
return
intersects
;
};
THREE
.
Ray
.
prototype
.
intersectObjects
=
function
(
objects
,
recursive
)
{
var
intersects
=
[];
for
(
var
i
=
0
,
l
=
objects
.
length
;
i
<
l
;
i
++
)
{
intersectObject
(
objects
[
i
],
this
,
intersects
);
if
(
recursive
===
true
)
{
intersectDescendants
(
objects
[
i
],
this
,
intersects
);
intersectObject
(
objects
[
i
],
this
,
intersects
);
if
(
recursive
===
true
)
{
intersectDescendants
(
objects
[
i
],
this
,
intersects
);
}
}
intersects
.
sort
(
descSort
);
return
intersects
;
};
}(
THREE
)
);
}(
THREE
)
);
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录