Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
f994a92b
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,发现更多精彩内容 >>
未验证
提交
f994a92b
编写于
4月 02, 2021
作者:
M
Michael Herzog
提交者:
GitHub
4月 02, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
OBB: Use ES6 syntax. (#21563)
上级
e9b90563
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
73 addition
and
73 deletion
+73
-73
examples/jsm/math/OBB.js
examples/jsm/math/OBB.js
+73
-73
未找到文件。
examples/jsm/math/OBB.js
浏览文件 @
f994a92b
...
...
@@ -9,47 +9,47 @@ import {
// module scope helper variables
var
a
=
{
const
a
=
{
c
:
null
,
// center
u
:
[
new
Vector3
(),
new
Vector3
(),
new
Vector3
()
],
// basis vectors
e
:
[]
// half width
};
var
b
=
{
const
b
=
{
c
:
null
,
// center
u
:
[
new
Vector3
(),
new
Vector3
(),
new
Vector3
()
],
// basis vectors
e
:
[]
// half width
};
var
R
=
[[],
[],
[]];
var
AbsR
=
[[],
[],
[]];
var
t
=
[];
var
xAxis
=
new
Vector3
();
var
yAxis
=
new
Vector3
();
var
zAxis
=
new
Vector3
();
var
v1
=
new
Vector3
();
var
size
=
new
Vector3
();
var
closestPoint
=
new
Vector3
();
var
rotationMatrix
=
new
Matrix3
();
var
aabb
=
new
Box3
();
var
matrix
=
new
Matrix4
();
var
inverse
=
new
Matrix4
();
var
localRay
=
new
Ray
();
const
R
=
[[],
[],
[]];
const
AbsR
=
[[],
[],
[]];
const
t
=
[];
const
xAxis
=
new
Vector3
();
const
yAxis
=
new
Vector3
();
const
zAxis
=
new
Vector3
();
const
v1
=
new
Vector3
();
const
size
=
new
Vector3
();
const
closestPoint
=
new
Vector3
();
const
rotationMatrix
=
new
Matrix3
();
const
aabb
=
new
Box3
();
const
matrix
=
new
Matrix4
();
const
inverse
=
new
Matrix4
();
const
localRay
=
new
Ray
();
// OBB
function
OBB
(
center
=
new
Vector3
(),
halfSize
=
new
Vector3
(),
rotation
=
new
Matrix3
()
)
{
class
OBB
{
this
.
center
=
center
;
this
.
halfSize
=
halfSize
;
this
.
rotation
=
rotation
;
constructor
(
center
=
new
Vector3
(),
halfSize
=
new
Vector3
(),
rotation
=
new
Matrix3
()
)
{
}
this
.
center
=
center
;
this
.
halfSize
=
halfSize
;
this
.
rotation
=
rotation
;
Object
.
assign
(
OBB
.
prototype
,
{
}
set
:
function
(
center
,
halfSize
,
rotation
)
{
set
(
center
,
halfSize
,
rotation
)
{
this
.
center
=
center
;
this
.
halfSize
=
halfSize
;
...
...
@@ -57,9 +57,9 @@ Object.assign( OBB.prototype, {
return
this
;
}
,
}
copy
:
function
(
obb
)
{
copy
(
obb
)
{
this
.
center
.
copy
(
obb
.
center
);
this
.
halfSize
.
copy
(
obb
.
halfSize
);
...
...
@@ -67,27 +67,27 @@ Object.assign( OBB.prototype, {
return
this
;
}
,
}
clone
:
function
()
{
clone
()
{
return
new
this
.
constructor
().
copy
(
this
);
}
,
}
getSize
:
function
(
result
)
{
getSize
(
result
)
{
return
result
.
copy
(
this
.
halfSize
).
multiplyScalar
(
2
);
}
,
}
/**
* Reference: Closest Point on OBB to Point in Real-Time Collision Detection
* by Christer Ericson (chapter 5.1.4)
*/
clampPoint
:
function
(
point
,
result
)
{
clampPoint
(
point
,
result
)
{
var
halfSize
=
this
.
halfSize
;
const
halfSize
=
this
.
halfSize
;
v1
.
subVectors
(
point
,
this
.
center
);
this
.
rotation
.
extractBasis
(
xAxis
,
yAxis
,
zAxis
);
...
...
@@ -98,20 +98,20 @@ Object.assign( OBB.prototype, {
// project the target onto the OBB axes and walk towards that point
var
x
=
MathUtils
.
clamp
(
v1
.
dot
(
xAxis
),
-
halfSize
.
x
,
halfSize
.
x
);
const
x
=
MathUtils
.
clamp
(
v1
.
dot
(
xAxis
),
-
halfSize
.
x
,
halfSize
.
x
);
result
.
add
(
xAxis
.
multiplyScalar
(
x
)
);
var
y
=
MathUtils
.
clamp
(
v1
.
dot
(
yAxis
),
-
halfSize
.
y
,
halfSize
.
y
);
const
y
=
MathUtils
.
clamp
(
v1
.
dot
(
yAxis
),
-
halfSize
.
y
,
halfSize
.
y
);
result
.
add
(
yAxis
.
multiplyScalar
(
y
)
);
var
z
=
MathUtils
.
clamp
(
v1
.
dot
(
zAxis
),
-
halfSize
.
z
,
halfSize
.
z
);
const
z
=
MathUtils
.
clamp
(
v1
.
dot
(
zAxis
),
-
halfSize
.
z
,
halfSize
.
z
);
result
.
add
(
zAxis
.
multiplyScalar
(
z
)
);
return
result
;
}
,
}
containsPoint
:
function
(
point
)
{
containsPoint
(
point
)
{
v1
.
subVectors
(
point
,
this
.
center
);
this
.
rotation
.
extractBasis
(
xAxis
,
yAxis
,
zAxis
);
...
...
@@ -122,15 +122,15 @@ Object.assign( OBB.prototype, {
Math
.
abs
(
v1
.
dot
(
yAxis
)
)
<=
this
.
halfSize
.
y
&&
Math
.
abs
(
v1
.
dot
(
zAxis
)
)
<=
this
.
halfSize
.
z
;
}
,
}
intersectsBox3
:
function
(
box3
)
{
intersectsBox3
(
box3
)
{
return
this
.
intersectsOBB
(
obb
.
fromBox3
(
box3
)
);
}
,
}
intersectsSphere
:
function
(
sphere
)
{
intersectsSphere
(
sphere
)
{
// find the point on the OBB closest to the sphere center
...
...
@@ -140,14 +140,14 @@ Object.assign( OBB.prototype, {
return
closestPoint
.
distanceToSquared
(
sphere
.
center
)
<=
(
sphere
.
radius
*
sphere
.
radius
);
}
,
}
/**
* Reference: OBB-OBB Intersection in Real-Time Collision Detection
* by Christer Ericson (chapter 4.4.1)
*
*/
intersectsOBB
:
function
(
obb
,
epsilon
=
Number
.
EPSILON
)
{
intersectsOBB
(
obb
,
epsilon
=
Number
.
EPSILON
)
{
// prepare data structures (the code uses the same nomenclature like the reference)
...
...
@@ -165,9 +165,9 @@ Object.assign( OBB.prototype, {
// compute rotation matrix expressing b in a's coordinate frame
for
(
var
i
=
0
;
i
<
3
;
i
++
)
{
for
(
let
i
=
0
;
i
<
3
;
i
++
)
{
for
(
var
j
=
0
;
j
<
3
;
j
++
)
{
for
(
let
j
=
0
;
j
<
3
;
j
++
)
{
R
[
i
][
j
]
=
a
.
u
[
i
].
dot
(
b
.
u
[
j
]
);
...
...
@@ -189,9 +189,9 @@ Object.assign( OBB.prototype, {
// counteract arithmetic errors when two edges are parallel and
// their cross product is (near) null
for
(
var
i
=
0
;
i
<
3
;
i
++
)
{
for
(
let
i
=
0
;
i
<
3
;
i
++
)
{
for
(
var
j
=
0
;
j
<
3
;
j
++
)
{
for
(
let
j
=
0
;
j
<
3
;
j
++
)
{
AbsR
[
i
][
j
]
=
Math
.
abs
(
R
[
i
][
j
]
)
+
epsilon
;
...
...
@@ -199,11 +199,11 @@ Object.assign( OBB.prototype, {
}
var
ra
,
rb
;
let
ra
,
rb
;
// test axes L = A0, L = A1, L = A2
for
(
var
i
=
0
;
i
<
3
;
i
++
)
{
for
(
let
i
=
0
;
i
<
3
;
i
++
)
{
ra
=
a
.
e
[
i
];
rb
=
b
.
e
[
0
]
*
AbsR
[
i
][
0
]
+
b
.
e
[
1
]
*
AbsR
[
i
][
1
]
+
b
.
e
[
2
]
*
AbsR
[
i
][
2
];
...
...
@@ -214,7 +214,7 @@ Object.assign( OBB.prototype, {
// test axes L = B0, L = B1, L = B2
for
(
var
i
=
0
;
i
<
3
;
i
++
)
{
for
(
let
i
=
0
;
i
<
3
;
i
++
)
{
ra
=
a
.
e
[
0
]
*
AbsR
[
0
][
i
]
+
a
.
e
[
1
]
*
AbsR
[
1
][
i
]
+
a
.
e
[
2
]
*
AbsR
[
2
][
i
];
rb
=
b
.
e
[
i
];
...
...
@@ -280,13 +280,13 @@ Object.assign( OBB.prototype, {
return
true
;
}
,
}
/**
* Reference: Testing Box Against Plane in Real-Time Collision Detection
* by Christer Ericson (chapter 5.2.3)
*/
intersectsPlane
:
function
(
plane
)
{
intersectsPlane
(
plane
)
{
this
.
rotation
.
extractBasis
(
xAxis
,
yAxis
,
zAxis
);
...
...
@@ -304,13 +304,13 @@ Object.assign( OBB.prototype, {
return
Math
.
abs
(
d
)
<=
r
;
}
,
}
/**
* Performs a ray/OBB intersection test and stores the intersection point
* to the given 3D vector. If no intersection is detected, *null* is returned.
*/
intersectRay
:
function
(
ray
,
result
)
{
intersectRay
(
ray
,
result
)
{
// the idea is to perform the intersection test in the local space
// of the OBB.
...
...
@@ -342,19 +342,19 @@ Object.assign( OBB.prototype, {
}
}
,
}
/**
* Performs a ray/OBB intersection test. Returns either true or false if
* there is a intersection or not.
*/
intersectsRay
:
function
(
ray
)
{
intersectsRay
(
ray
)
{
return
this
.
intersectRay
(
ray
,
v1
)
!==
null
;
}
,
}
fromBox3
:
function
(
box3
)
{
fromBox3
(
box3
)
{
box3
.
getCenter
(
this
.
center
);
...
...
@@ -364,32 +364,32 @@ Object.assign( OBB.prototype, {
return
this
;
}
,
}
equals
:
function
(
obb
)
{
equals
(
obb
)
{
return
obb
.
center
.
equals
(
this
.
center
)
&&
obb
.
halfSize
.
equals
(
this
.
halfSize
)
&&
obb
.
rotation
.
equals
(
this
.
rotation
);
}
,
}
applyMatrix4
:
function
(
matrix
)
{
applyMatrix4
(
matrix
)
{
var
e
=
matrix
.
elements
;
const
e
=
matrix
.
elements
;
var
sx
=
v1
.
set
(
e
[
0
],
e
[
1
],
e
[
2
]
).
length
();
var
sy
=
v1
.
set
(
e
[
4
],
e
[
5
],
e
[
6
]
).
length
();
var
sz
=
v1
.
set
(
e
[
8
],
e
[
9
],
e
[
10
]
).
length
();
const
sx
=
v1
.
set
(
e
[
0
],
e
[
1
],
e
[
2
]
).
length
();
const
sy
=
v1
.
set
(
e
[
4
],
e
[
5
],
e
[
6
]
).
length
();
const
sz
=
v1
.
set
(
e
[
8
],
e
[
9
],
e
[
10
]
).
length
();
var
det
=
matrix
.
determinant
();
const
det
=
matrix
.
determinant
();
if
(
det
<
0
)
sx
=
-
sx
;
rotationMatrix
.
setFromMatrix4
(
matrix
);
var
invSX
=
1
/
sx
;
var
invSY
=
1
/
sy
;
var
invSZ
=
1
/
sz
;
const
invSX
=
1
/
sx
;
const
invSY
=
1
/
sy
;
const
invSZ
=
1
/
sz
;
rotationMatrix
.
elements
[
0
]
*=
invSX
;
rotationMatrix
.
elements
[
1
]
*=
invSX
;
...
...
@@ -416,8 +416,8 @@ Object.assign( OBB.prototype, {
}
}
);
}
var
obb
=
new
OBB
();
const
obb
=
new
OBB
();
export
{
OBB
};
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录