Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
9f7bc7e3
T
three.js
项目概览
车家大少爷
/
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,发现更多精彩内容 >>
未验证
提交
9f7bc7e3
编写于
11月 11, 2019
作者:
M
Michael Herzog
提交者:
GitHub
11月 11, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #17894 from Mugen87/dev33
LOD: Make methods more robust.
上级
a1282abd
83d339a9
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
107 addition
and
26 deletion
+107
-26
src/objects/LOD.d.ts
src/objects/LOD.d.ts
+2
-1
src/objects/LOD.js
src/objects/LOD.js
+21
-7
test/unit/src/objects/LOD.tests.js
test/unit/src/objects/LOD.tests.js
+84
-18
未找到文件。
src/objects/LOD.d.ts
浏览文件 @
9f7bc7e3
...
...
@@ -10,9 +10,10 @@ export class LOD extends Object3D {
type
:
'
LOD
'
;
levels
:
{
distance
:
number
;
object
:
Object3D
}[];
autoUpdate
:
boolean
;
addLevel
(
object
:
Object3D
,
distance
?:
number
):
this
;
getObjectForDistance
(
distance
:
number
):
Object3D
;
getObjectForDistance
(
distance
:
number
):
Object3D
|
null
;
raycast
(
raycaster
:
Raycaster
,
intersects
:
Intersection
[]
):
void
;
update
(
camera
:
Camera
):
void
;
toJSON
(
meta
:
any
):
any
;
...
...
src/objects/LOD.js
浏览文件 @
9f7bc7e3
...
...
@@ -47,6 +47,8 @@ LOD.prototype = Object.assign( Object.create( Object3D.prototype ), {
}
this
.
autoUpdate
=
source
.
autoUpdate
;
return
this
;
},
...
...
@@ -81,27 +83,39 @@ LOD.prototype = Object.assign( Object.create( Object3D.prototype ), {
var
levels
=
this
.
levels
;
for
(
var
i
=
1
,
l
=
levels
.
length
;
i
<
l
;
i
++
)
{
if
(
levels
.
length
>
0
)
{
for
(
var
i
=
1
,
l
=
levels
.
length
;
i
<
l
;
i
++
)
{
if
(
distance
<
levels
[
i
].
distance
)
{
if
(
distance
<
levels
[
i
].
distance
)
{
break
;
break
;
}
}
return
levels
[
i
-
1
].
object
;
}
return
levels
[
i
-
1
].
object
;
return
null
;
},
raycast
:
function
(
raycaster
,
intersects
)
{
_v1
.
setFromMatrixPosition
(
this
.
matrixWorld
);
var
levels
=
this
.
levels
;
if
(
levels
.
length
>
0
)
{
var
distance
=
raycaster
.
ray
.
origin
.
distanceTo
(
_v1
);
_v1
.
setFromMatrixPosition
(
this
.
matrixWorld
);
this
.
getObjectForDistance
(
distance
).
raycast
(
raycaster
,
intersects
);
var
distance
=
raycaster
.
ray
.
origin
.
distanceTo
(
_v1
);
this
.
getObjectForDistance
(
distance
).
raycast
(
raycaster
,
intersects
);
}
},
...
...
test/unit/src/objects/LOD.tests.js
浏览文件 @
9f7bc7e3
...
...
@@ -3,6 +3,8 @@
*/
/* global QUnit */
import
{
Object3D
}
from
'
../../../../src/core/Object3D
'
;
import
{
Raycaster
}
from
'
../../../../src/core/Raycaster
'
;
import
{
LOD
}
from
'
../../../../src/objects/LOD
'
;
export
default
QUnit
.
module
(
'
Objects
'
,
()
=>
{
...
...
@@ -10,50 +12,114 @@ export default QUnit.module( 'Objects', () => {
QUnit
.
module
(
'
LOD
'
,
()
=>
{
// INHERITANCE
QUnit
.
t
odo
(
"
Extending
"
,
(
assert
)
=>
{
QUnit
.
t
est
(
"
Extending
"
,
(
assert
)
=>
{
assert
.
ok
(
false
,
"
everything's gonna be alright
"
);
var
lod
=
new
LOD
();
assert
.
strictEqual
(
(
lod
instanceof
Object3D
),
true
,
"
LOD extends from Object3D
"
);
}
);
//
INSTANCING
QUnit
.
t
odo
(
"
Instancing
"
,
(
assert
)
=>
{
//
PROPERTIES
QUnit
.
t
est
(
"
levels
"
,
(
assert
)
=>
{
assert
.
ok
(
false
,
"
everything's gonna be alright
"
);
var
lod
=
new
LOD
();
var
levels
=
lod
.
levels
;
assert
.
strictEqual
(
Array
.
isArray
(
levels
),
true
,
"
LOD.levels is of type array.
"
);
assert
.
strictEqual
(
levels
.
length
,
0
,
"
LOD.levels is empty by default.
"
);
}
);
// PROPERTIES
QUnit
.
todo
(
"
levels
"
,
(
assert
)
=>
{
QUnit
.
test
(
"
autoUpdate
"
,
(
assert
)
=>
{
assert
.
ok
(
false
,
"
everything's gonna be alright
"
);
var
lod
=
new
LOD
();
assert
.
strictEqual
(
lod
.
autoUpdate
,
true
,
"
LOD.autoUpdate is of type boolean and true by default.
"
);
}
);
// PUBLIC STUFF
QUnit
.
t
odo
(
"
isLOD
"
,
(
assert
)
=>
{
QUnit
.
t
est
(
"
isLOD
"
,
(
assert
)
=>
{
assert
.
ok
(
false
,
"
everything's gonna be alright
"
);
var
lod
=
new
LOD
();
assert
.
strictEqual
(
lod
.
isLOD
,
true
,
"
.isLOD property is defined.
"
);
}
);
QUnit
.
t
odo
(
"
copy
"
,
(
assert
)
=>
{
QUnit
.
t
est
(
"
copy
"
,
(
assert
)
=>
{
assert
.
ok
(
false
,
"
everything's gonna be alright
"
);
var
lod1
=
new
LOD
();
var
lod2
=
new
LOD
();
var
high
=
new
Object3D
();
var
mid
=
new
Object3D
();
var
low
=
new
Object3D
();
lod1
.
addLevel
(
high
,
5
);
lod1
.
addLevel
(
mid
,
25
);
lod1
.
addLevel
(
low
,
50
);
lod1
.
autoUpdate
=
false
;
lod2
.
copy
(
lod1
);
assert
.
strictEqual
(
lod2
.
autoUpdate
,
false
,
"
LOD.autoUpdate is correctly copied.
"
);
assert
.
strictEqual
(
lod2
.
levels
.
length
,
3
,
"
LOD.levels has the correct length after the copy.
"
);
}
);
QUnit
.
t
odo
(
"
addLevel
"
,
(
assert
)
=>
{
QUnit
.
t
est
(
"
addLevel
"
,
(
assert
)
=>
{
assert
.
ok
(
false
,
"
everything's gonna be alright
"
);
var
lod
=
new
LOD
();
var
high
=
new
Object3D
();
var
mid
=
new
Object3D
();
var
low
=
new
Object3D
();
lod
.
addLevel
(
high
,
5
);
lod
.
addLevel
(
mid
,
25
);
lod
.
addLevel
(
low
,
50
);
assert
.
strictEqual
(
lod
.
levels
.
length
,
3
,
"
LOD.levels has the correct length.
"
);
assert
.
deepEqual
(
lod
.
levels
[
0
],
{
distance
:
5
,
object
:
high
},
"
First entry correct.
"
);
assert
.
deepEqual
(
lod
.
levels
[
1
],
{
distance
:
25
,
object
:
mid
},
"
Second entry correct.
"
);
assert
.
deepEqual
(
lod
.
levels
[
2
],
{
distance
:
50
,
object
:
low
},
"
Third entry correct.
"
);
}
);
QUnit
.
t
odo
(
"
getObjectForDistance
"
,
(
assert
)
=>
{
QUnit
.
t
est
(
"
getObjectForDistance
"
,
(
assert
)
=>
{
assert
.
ok
(
false
,
"
everything's gonna be alright
"
);
var
lod
=
new
LOD
();
var
high
=
new
Object3D
();
var
mid
=
new
Object3D
();
var
low
=
new
Object3D
();
assert
.
strictEqual
(
lod
.
getObjectForDistance
(
5
),
null
,
"
Returns null if no LOD levels are defined.
"
);
lod
.
addLevel
(
high
,
5
);
assert
.
strictEqual
(
lod
.
getObjectForDistance
(
0
),
high
,
"
Returns always the same object if only one LOD level is defined.
"
);
assert
.
strictEqual
(
lod
.
getObjectForDistance
(
10
),
high
,
"
Returns always the same object if only one LOD level is defined.
"
);
lod
.
addLevel
(
mid
,
25
);
lod
.
addLevel
(
low
,
50
);
assert
.
strictEqual
(
lod
.
getObjectForDistance
(
0
),
high
,
"
Returns the high resolution object.
"
);
assert
.
strictEqual
(
lod
.
getObjectForDistance
(
10
),
high
,
"
Returns the high resolution object.
"
);
assert
.
strictEqual
(
lod
.
getObjectForDistance
(
25
),
mid
,
"
Returns the mid resolution object.
"
);
assert
.
strictEqual
(
lod
.
getObjectForDistance
(
50
),
low
,
"
Returns the low resolution object.
"
);
assert
.
strictEqual
(
lod
.
getObjectForDistance
(
60
),
low
,
"
Returns the low resolution object.
"
);
}
);
QUnit
.
t
odo
(
"
raycast
"
,
(
assert
)
=>
{
QUnit
.
t
est
(
"
raycast
"
,
(
assert
)
=>
{
assert
.
ok
(
false
,
"
everything's gonna be alright
"
);
var
lod
=
new
LOD
();
var
raycaster
=
new
Raycaster
();
var
intersections
=
[];
lod
.
raycast
(
raycaster
,
intersections
);
assert
.
strictEqual
(
intersections
.
length
,
0
,
"
Does not fail if raycasting is used with a LOD object without levels.
"
);
}
);
QUnit
.
todo
(
"
update
"
,
(
assert
)
=>
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录