1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/* global QUnit */
import { Object3D } from '../../../../src/core/Object3D.js';
import { Raycaster } from '../../../../src/core/Raycaster.js';
import { LOD } from '../../../../src/objects/LOD.js';
export default QUnit.module( 'Objects', () => {
QUnit.module( 'LOD', () => {
// INHERITANCE
QUnit.test( 'Extending', ( assert ) => {
const lod = new LOD();
assert.strictEqual( ( lod instanceof Object3D ), true, 'LOD extends from Object3D' );
} );
// PROPERTIES
QUnit.test( 'type', ( assert ) => {
const object = new LOD();
assert.ok(
object.type === 'LOD',
'LOD.type should be LOD'
);
} );
QUnit.test( 'levels', ( assert ) => {
const lod = new LOD();
const 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.' );
} );
QUnit.test( 'autoUpdate', ( assert ) => {
const lod = new LOD();
assert.strictEqual( lod.autoUpdate, true, 'LOD.autoUpdate is of type boolean and true by default.' );
} );
// PUBLIC
QUnit.test( 'isLOD', ( assert ) => {
const lod = new LOD();
assert.strictEqual( lod.isLOD, true, '.isLOD property is defined.' );
} );
QUnit.test( 'copy', ( assert ) => {
const lod1 = new LOD();
const lod2 = new LOD();
const high = new Object3D();
const mid = new Object3D();
const 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.test( 'addLevel', ( assert ) => {
const lod = new LOD();
const high = new Object3D();
const mid = new Object3D();
const low = new Object3D();
lod.addLevel( high, 5, 0.00 );
lod.addLevel( mid, 25, 0.05 );
lod.addLevel( low, 50, 0.10 );
assert.strictEqual( lod.levels.length, 3, 'LOD.levels has the correct length.' );
assert.deepEqual( lod.levels[ 0 ], { distance: 5, object: high, hysteresis: 0.00 }, 'First entry correct.' );
assert.deepEqual( lod.levels[ 1 ], { distance: 25, object: mid, hysteresis: 0.05 }, 'Second entry correct.' );
assert.deepEqual( lod.levels[ 2 ], { distance: 50, object: low, hysteresis: 0.10 }, 'Third entry correct.' );
} );
QUnit.todo( 'getCurrentLevel', ( assert ) => {
assert.ok( false, 'everything\'s gonna be alright' );
} );
QUnit.test( 'getObjectForDistance', ( assert ) => {
const lod = new LOD();
const high = new Object3D();
const mid = new Object3D();
const 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.test( 'raycast', ( assert ) => {
const lod = new LOD();
const raycaster = new Raycaster();
const 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 ) => {
assert.ok( false, 'everything\'s gonna be alright' );
} );
QUnit.todo( 'toJSON', ( assert ) => {
assert.ok( false, 'everything\'s gonna be alright' );
} );
} );
} );