Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
d0adb01f
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,发现更多精彩内容 >>
提交
d0adb01f
编写于
12月 07, 2012
作者:
M
Mr.doob
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'bhouston/triangle' into dev
上级
cc40cec1
a48922b9
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
52 addition
and
76 deletion
+52
-76
src/math/Box2.js
src/math/Box2.js
+2
-15
src/math/Box3.js
src/math/Box3.js
+2
-21
src/math/Triangle.js
src/math/Triangle.js
+22
-14
test/core/Box2.js
test/core/Box2.js
+13
-13
test/core/Box3.js
test/core/Box3.js
+13
-13
未找到文件。
src/math/Box2.js
浏览文件 @
d0adb01f
...
...
@@ -4,21 +4,8 @@
THREE
.
Box2
=
function
(
min
,
max
)
{
if
(
min
===
undefined
&&
max
===
undefined
)
{
this
.
min
=
new
THREE
.
Vector2
();
this
.
max
=
new
THREE
.
Vector2
();
this
.
makeEmpty
();
}
else
{
this
.
min
=
min
.
clone
();
if
(
max
===
undefined
)
{
this
.
max
=
new
THREE
.
Vector2
().
copy
(
this
.
min
);
// This is done on purpose so you can make a box using a single point and then expand it.
}
else
{
this
.
max
=
max
.
clone
();
}
}
this
.
min
=
min
!==
undefined
?
min
.
clone
()
:
new
THREE
.
Vector2
(
Infinity
,
Infinity
);
this
.
max
=
max
!==
undefined
?
max
.
clone
()
:
new
THREE
.
Vector2
(
-
Infinity
,
-
Infinity
);
};
...
...
src/math/Box3.js
浏览文件 @
d0adb01f
...
...
@@ -4,27 +4,8 @@
THREE
.
Box3
=
function
(
min
,
max
)
{
if
(
min
===
undefined
&&
max
===
undefined
)
{
this
.
min
=
new
THREE
.
Vector3
();
this
.
max
=
new
THREE
.
Vector3
();
this
.
makeEmpty
();
}
else
{
this
.
min
=
min
.
clone
();
if
(
max
===
undefined
)
{
this
.
max
=
new
THREE
.
Vector3
().
copy
(
this
.
min
);
// This is done on purpose so you can make a box using a single point and then expand it.
}
else
{
this
.
max
=
max
.
clone
();
}
}
this
.
min
=
min
!==
undefined
?
min
.
clone
()
:
new
THREE
.
Vector3
(
Infinity
,
Infinity
,
Infinity
);
this
.
max
=
max
!==
undefined
?
max
.
clone
()
:
new
THREE
.
Vector3
(
-
Infinity
,
-
Infinity
,
-
Infinity
);
};
...
...
src/math/Triangle.js
浏览文件 @
d0adb01f
...
...
@@ -19,6 +19,25 @@ THREE.Triangle = function ( a, b, c ) {
};
THREE
.
Triangle
.
normal
=
function
(
a
,
b
,
c
,
optionalTarget
)
{
var
result
=
optionalTarget
||
new
THREE
.
Vector3
();
result
.
sub
(
c
,
b
);
THREE
.
Triangle
.
__v0
.
sub
(
a
,
b
);
result
.
crossSelf
(
THREE
.
Triangle
.
__v0
);
var
resultLengthSq
=
result
.
lengthSq
();
if
(
resultLengthSq
>
0
)
{
return
result
.
multiplyScalar
(
1
/
Math
.
sqrt
(
resultLengthSq
)
);
}
return
result
.
set
(
0
,
0
,
0
);
};
// static/instance method to calculate barycoordinates
THREE
.
Triangle
.
barycoordFromPoint
=
function
(
point
,
a
,
b
,
c
,
optionalTarget
)
{
...
...
@@ -49,6 +68,7 @@ THREE.Triangle.barycoordFromPoint = function ( point, a, b, c, optionalTarget )
// barycoordinates must always sum to 1
return
result
.
set
(
1
-
u
-
v
,
v
,
u
);
};
THREE
.
Triangle
.
containsPoint
=
function
(
point
,
a
,
b
,
c
)
{
...
...
@@ -57,6 +77,7 @@ THREE.Triangle.containsPoint = function ( point, a, b, c ) {
var
result
=
THREE
.
Triangle
.
barycoordFromPoint
(
point
,
a
,
b
,
c
,
THREE
.
Triangle
.
__v3
);
return
(
result
.
x
>=
0
)
&&
(
result
.
y
>=
0
)
&&
(
(
result
.
x
+
result
.
y
)
<=
1
);
};
THREE
.
Triangle
.
prototype
=
{
...
...
@@ -111,20 +132,7 @@ THREE.Triangle.prototype = {
normal
:
function
(
optionalTarget
)
{
var
result
=
optionalTarget
||
new
THREE
.
Vector3
();
result
.
sub
(
this
.
c
,
this
.
b
);
THREE
.
Triangle
.
__v0
.
sub
(
this
.
a
,
this
.
b
);
result
.
crossSelf
(
THREE
.
Triangle
.
__v0
);
var
resultLengthSq
=
result
.
lengthSq
();
if
(
resultLengthSq
>
0
)
{
return
result
.
multiplyScalar
(
1
/
Math
.
sqrt
(
resultLengthSq
)
);
}
return
result
.
set
(
0
,
0
,
0
);
return
THREE
.
Triangle
.
normal
(
this
.
a
,
this
.
b
,
this
.
c
,
optionalTarget
);
},
...
...
test/core/Box2.js
浏览文件 @
d0adb01f
...
...
@@ -9,7 +9,7 @@ test( "constructor", function() {
ok
(
a
.
min
.
equals
(
posInf2
),
"
Passed!
"
);
ok
(
a
.
max
.
equals
(
negInf2
),
"
Passed!
"
);
a
=
new
THREE
.
Box2
(
zero2
);
a
=
new
THREE
.
Box2
(
zero2
,
zero2
);
ok
(
a
.
min
.
equals
(
zero2
),
"
Passed!
"
);
ok
(
a
.
max
.
equals
(
zero2
),
"
Passed!
"
);
...
...
@@ -52,7 +52,7 @@ test( "empty/makeEmpty", function() {
});
test
(
"
center
"
,
function
()
{
var
a
=
new
THREE
.
Box2
(
zero2
);
var
a
=
new
THREE
.
Box2
(
zero2
,
zero2
);
ok
(
a
.
center
().
equals
(
zero2
),
"
Passed!
"
);
...
...
@@ -62,7 +62,7 @@ test( "center", function() {
});
test
(
"
size
"
,
function
()
{
var
a
=
new
THREE
.
Box2
(
zero2
);
var
a
=
new
THREE
.
Box2
(
zero2
,
zero2
);
ok
(
a
.
size
().
equals
(
zero2
),
"
Passed!
"
);
...
...
@@ -71,7 +71,7 @@ test( "size", function() {
});
test
(
"
expandByPoint
"
,
function
()
{
var
a
=
new
THREE
.
Box2
(
zero2
);
var
a
=
new
THREE
.
Box2
(
zero2
,
zero2
);
a
.
expandByPoint
(
zero2
);
ok
(
a
.
size
().
equals
(
zero2
),
"
Passed!
"
);
...
...
@@ -85,7 +85,7 @@ test( "expandByPoint", function() {
});
test
(
"
expandByVector
"
,
function
()
{
var
a
=
new
THREE
.
Box2
(
zero2
);
var
a
=
new
THREE
.
Box2
(
zero2
,
zero2
);
a
.
expandByVector
(
zero2
);
ok
(
a
.
size
().
equals
(
zero2
),
"
Passed!
"
);
...
...
@@ -96,7 +96,7 @@ test( "expandByVector", function() {
});
test
(
"
expandByScalar
"
,
function
()
{
var
a
=
new
THREE
.
Box2
(
zero2
);
var
a
=
new
THREE
.
Box2
(
zero2
,
zero2
);
a
.
expandByScalar
(
0
);
ok
(
a
.
size
().
equals
(
zero2
),
"
Passed!
"
);
...
...
@@ -107,7 +107,7 @@ test( "expandByScalar", function() {
});
test
(
"
containsPoint
"
,
function
()
{
var
a
=
new
THREE
.
Box2
(
zero2
);
var
a
=
new
THREE
.
Box2
(
zero2
,
zero2
);
ok
(
a
.
containsPoint
(
zero2
),
"
Passed!
"
);
ok
(
!
a
.
containsPoint
(
one2
),
"
Passed!
"
);
...
...
@@ -119,7 +119,7 @@ test( "containsPoint", function() {
});
test
(
"
containsBox
"
,
function
()
{
var
a
=
new
THREE
.
Box2
(
zero2
);
var
a
=
new
THREE
.
Box2
(
zero2
,
zero2
);
var
b
=
new
THREE
.
Box2
(
zero2
,
one2
);
var
c
=
new
THREE
.
Box2
(
one2
.
clone
().
negate
(),
one2
);
...
...
@@ -190,7 +190,7 @@ test( "distanceToPoint", function() {
});
test
(
"
isIntersectionBox
"
,
function
()
{
var
a
=
new
THREE
.
Box2
(
zero2
);
var
a
=
new
THREE
.
Box2
(
zero2
,
zero2
);
var
b
=
new
THREE
.
Box2
(
zero2
,
one2
);
var
c
=
new
THREE
.
Box2
(
one2
.
clone
().
negate
(),
one2
);
...
...
@@ -209,7 +209,7 @@ test( "isIntersectionBox", function() {
});
test
(
"
intersect
"
,
function
()
{
var
a
=
new
THREE
.
Box2
(
zero2
);
var
a
=
new
THREE
.
Box2
(
zero2
,
zero2
);
var
b
=
new
THREE
.
Box2
(
zero2
,
one2
);
var
c
=
new
THREE
.
Box2
(
one2
.
clone
().
negate
(),
one2
);
...
...
@@ -222,7 +222,7 @@ test( "intersect", function() {
});
test
(
"
union
"
,
function
()
{
var
a
=
new
THREE
.
Box2
(
zero2
);
var
a
=
new
THREE
.
Box2
(
zero2
,
zero2
);
var
b
=
new
THREE
.
Box2
(
zero2
,
one2
);
var
c
=
new
THREE
.
Box2
(
one2
.
clone
().
negate
(),
one2
);
...
...
@@ -233,7 +233,7 @@ test( "union", function() {
});
test
(
"
translate
"
,
function
()
{
var
a
=
new
THREE
.
Box2
(
zero2
);
var
a
=
new
THREE
.
Box2
(
zero2
,
zero2
);
var
b
=
new
THREE
.
Box2
(
zero2
,
one2
);
var
c
=
new
THREE
.
Box2
(
one2
.
clone
().
negate
(),
one2
);
var
d
=
new
THREE
.
Box2
(
one2
.
clone
().
negate
(),
zero2
);
...
...
@@ -245,7 +245,7 @@ test( "translate", function() {
});
test
(
"
scale
"
,
function
()
{
var
a
=
new
THREE
.
Box2
(
zero2
);
var
a
=
new
THREE
.
Box2
(
zero2
,
zero2
);
var
b
=
new
THREE
.
Box2
(
zero2
,
one2
);
var
c
=
new
THREE
.
Box2
(
one2
.
clone
().
negate
(),
one2
);
var
d
=
new
THREE
.
Box2
(
one2
.
clone
().
negate
(),
zero2
);
...
...
test/core/Box3.js
浏览文件 @
d0adb01f
...
...
@@ -9,7 +9,7 @@ test( "constructor", function() {
ok
(
a
.
min
.
equals
(
posInf3
),
"
Passed!
"
);
ok
(
a
.
max
.
equals
(
negInf3
),
"
Passed!
"
);
a
=
new
THREE
.
Box3
(
zero3
);
a
=
new
THREE
.
Box3
(
zero3
,
zero3
);
ok
(
a
.
min
.
equals
(
zero3
),
"
Passed!
"
);
ok
(
a
.
max
.
equals
(
zero3
),
"
Passed!
"
);
...
...
@@ -52,7 +52,7 @@ test( "empty/makeEmpty", function() {
});
test
(
"
center
"
,
function
()
{
var
a
=
new
THREE
.
Box3
(
zero3
);
var
a
=
new
THREE
.
Box3
(
zero3
,
zero3
);
ok
(
a
.
center
().
equals
(
zero3
),
"
Passed!
"
);
...
...
@@ -62,7 +62,7 @@ test( "center", function() {
});
test
(
"
size
"
,
function
()
{
var
a
=
new
THREE
.
Box3
(
zero3
);
var
a
=
new
THREE
.
Box3
(
zero3
,
zero3
);
ok
(
a
.
size
().
equals
(
zero3
),
"
Passed!
"
);
...
...
@@ -71,7 +71,7 @@ test( "size", function() {
});
test
(
"
expandByPoint
"
,
function
()
{
var
a
=
new
THREE
.
Box3
(
zero3
);
var
a
=
new
THREE
.
Box3
(
zero3
,
zero3
);
a
.
expandByPoint
(
zero3
);
ok
(
a
.
size
().
equals
(
zero3
),
"
Passed!
"
);
...
...
@@ -85,7 +85,7 @@ test( "expandByPoint", function() {
});
test
(
"
expandByVector
"
,
function
()
{
var
a
=
new
THREE
.
Box3
(
zero3
);
var
a
=
new
THREE
.
Box3
(
zero3
,
zero3
);
a
.
expandByVector
(
zero3
);
ok
(
a
.
size
().
equals
(
zero3
),
"
Passed!
"
);
...
...
@@ -96,7 +96,7 @@ test( "expandByVector", function() {
});
test
(
"
expandByScalar
"
,
function
()
{
var
a
=
new
THREE
.
Box3
(
zero3
);
var
a
=
new
THREE
.
Box3
(
zero3
,
zero3
);
a
.
expandByScalar
(
0
);
ok
(
a
.
size
().
equals
(
zero3
),
"
Passed!
"
);
...
...
@@ -107,7 +107,7 @@ test( "expandByScalar", function() {
});
test
(
"
containsPoint
"
,
function
()
{
var
a
=
new
THREE
.
Box3
(
zero3
);
var
a
=
new
THREE
.
Box3
(
zero3
,
zero3
);
ok
(
a
.
containsPoint
(
zero3
),
"
Passed!
"
);
ok
(
!
a
.
containsPoint
(
one3
),
"
Passed!
"
);
...
...
@@ -119,7 +119,7 @@ test( "containsPoint", function() {
});
test
(
"
containsBox
"
,
function
()
{
var
a
=
new
THREE
.
Box3
(
zero3
);
var
a
=
new
THREE
.
Box3
(
zero3
,
zero3
);
var
b
=
new
THREE
.
Box3
(
zero3
,
one3
);
var
c
=
new
THREE
.
Box3
(
one3
.
clone
().
negate
(),
one3
);
...
...
@@ -190,7 +190,7 @@ test( "distanceToPoint", function() {
});
test
(
"
isIntersectionBox
"
,
function
()
{
var
a
=
new
THREE
.
Box3
(
zero3
);
var
a
=
new
THREE
.
Box3
(
zero3
,
zero3
);
var
b
=
new
THREE
.
Box3
(
zero3
,
one3
);
var
c
=
new
THREE
.
Box3
(
one3
.
clone
().
negate
(),
one3
);
...
...
@@ -209,7 +209,7 @@ test( "isIntersectionBox", function() {
});
test
(
"
intersect
"
,
function
()
{
var
a
=
new
THREE
.
Box3
(
zero3
);
var
a
=
new
THREE
.
Box3
(
zero3
,
zero3
);
var
b
=
new
THREE
.
Box3
(
zero3
,
one3
);
var
c
=
new
THREE
.
Box3
(
one3
.
clone
().
negate
(),
one3
);
...
...
@@ -222,7 +222,7 @@ test( "intersect", function() {
});
test
(
"
union
"
,
function
()
{
var
a
=
new
THREE
.
Box3
(
zero3
);
var
a
=
new
THREE
.
Box3
(
zero3
,
zero3
);
var
b
=
new
THREE
.
Box3
(
zero3
,
one3
);
var
c
=
new
THREE
.
Box3
(
one3
.
clone
().
negate
(),
one3
);
...
...
@@ -233,7 +233,7 @@ test( "union", function() {
});
test
(
"
translate
"
,
function
()
{
var
a
=
new
THREE
.
Box3
(
zero3
);
var
a
=
new
THREE
.
Box3
(
zero3
,
zero3
);
var
b
=
new
THREE
.
Box3
(
zero3
,
one3
);
var
c
=
new
THREE
.
Box3
(
one3
.
clone
().
negate
(),
one3
);
var
d
=
new
THREE
.
Box3
(
one3
.
clone
().
negate
(),
zero3
);
...
...
@@ -245,7 +245,7 @@ test( "translate", function() {
});
test
(
"
scale
"
,
function
()
{
var
a
=
new
THREE
.
Box3
(
zero3
);
var
a
=
new
THREE
.
Box3
(
zero3
,
zero3
);
var
b
=
new
THREE
.
Box3
(
zero3
,
one3
);
var
c
=
new
THREE
.
Box3
(
one3
.
clone
().
negate
(),
one3
);
var
d
=
new
THREE
.
Box3
(
one3
.
clone
().
negate
(),
zero3
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录