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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/* global QUnit */
import { Object3D } from '../../../../src/core/Object3D.js';
import { Mesh } from '../../../../src/objects/Mesh.js';
import { Raycaster } from '../../../../src/core/Raycaster.js';
import { PlaneGeometry } from '../../../../src/geometries/PlaneGeometry.js';
import { BoxGeometry } from '../../../../src/geometries/BoxGeometry.js';
import { MeshBasicMaterial } from '../../../../src/materials/MeshBasicMaterial.js';
import { Vector2 } from '../../../../src/math/Vector2.js';
import { Vector3 } from '../../../../src/math/Vector3.js';
import { DoubleSide } from '../../../../src/constants.js';
import { Material } from '../../../../src/materials/Material.js';
export default QUnit.module( 'Objects', () => {
QUnit.module( 'Mesh', () => {
// INHERITANCE
QUnit.test( 'Extending', ( assert ) => {
const mesh = new Mesh();
assert.strictEqual(
mesh instanceof Object3D, true,
'Mesh extends from Object3D'
);
} );
// INSTANCING
QUnit.test( 'Instancing', ( assert ) => {
const object = new Mesh();
assert.ok( object, 'Can instantiate a Mesh.' );
} );
// PROPERTIES
QUnit.test( 'type', ( assert ) => {
const object = new Mesh();
assert.ok(
object.type === 'Mesh',
'Mesh.type should be Mesh'
);
} );
QUnit.todo( 'geometry', ( assert ) => {
assert.ok( false, 'everything\'s gonna be alright' );
} );
QUnit.todo( 'material', ( assert ) => {
assert.ok( false, 'everything\'s gonna be alright' );
} );
// PUBLIC
QUnit.test( 'isMesh', ( assert ) => {
const object = new Mesh();
assert.ok(
object.isMesh,
'Mesh.isMesh should be true'
);
} );
QUnit.todo( 'copy', ( assert ) => {
assert.ok( false, 'everything\'s gonna be alright' );
} );
QUnit.test( 'copy/material', ( assert ) => {
// Material arrays are cloned
const mesh1 = new Mesh();
mesh1.material = [ new Material() ];
const copy1 = mesh1.clone();
assert.notStrictEqual( mesh1.material, copy1.material );
// Non arrays are not cloned
const mesh2 = new Mesh();
mesh1.material = new Material();
const copy2 = mesh2.clone();
assert.strictEqual( mesh2.material, copy2.material );
} );
QUnit.todo( 'updateMorphTargets', ( assert ) => {
assert.ok( false, 'everything\'s gonna be alright' );
} );
QUnit.todo( 'getVertexPosition', ( assert ) => {
assert.ok( false, 'everything\'s gonna be alright' );
} );
QUnit.todo( 'raycast', ( assert ) => {
const geometry = new PlaneGeometry();
const material = new MeshBasicMaterial();
const mesh = new Mesh( geometry, material );
const raycaster = new Raycaster();
raycaster.ray.origin.set( 0.25, 0.25, 1 );
raycaster.ray.direction.set( 0, 0, - 1 );
const intersections = [];
mesh.raycast( raycaster, intersections );
const intersection = intersections[ 0 ];
assert.equal( intersection.object, mesh, 'intersction object' );
assert.equal( intersection.distance, 1, 'intersction distance' );
assert.equal( intersection.faceIndex, 1, 'intersction face index' );
assert.deepEqual( intersection.face, { a: 0, b: 2, c: 1 }, 'intersction vertex indices' );
assert.deepEqual( intersection.point, new Vector3( 0.25, 0.25, 0 ), 'intersction point' );
assert.deepEqual( intersection.uv, new Vector2( 0.75, 0.75 ), 'intersction uv' );
} );
QUnit.test( 'raycast/range', ( assert ) => {
const geometry = new BoxGeometry( 1, 1, 1 );
const material = new MeshBasicMaterial( { side: DoubleSide } );
const mesh = new Mesh( geometry, material );
const raycaster = new Raycaster();
const intersections = [];
raycaster.ray.origin.set( 0, 0, 0 );
raycaster.ray.direction.set( 1, 0, 0 );
raycaster.near = 100;
raycaster.far = 200;
mesh.matrixWorld.identity();
mesh.position.setX( 150 );
mesh.updateMatrixWorld( true );
intersections.length = 0;
mesh.raycast( raycaster, intersections );
assert.ok( intersections.length > 0, 'bounding sphere between near and far' );
mesh.matrixWorld.identity();
mesh.position.setX( raycaster.near );
mesh.updateMatrixWorld( true );
intersections.length = 0;
mesh.raycast( raycaster, intersections );
assert.ok( intersections.length > 0, 'bounding sphere across near' );
mesh.matrixWorld.identity();
mesh.position.setX( raycaster.far );
mesh.updateMatrixWorld( true );
intersections.length = 0;
mesh.raycast( raycaster, intersections );
assert.ok( intersections.length > 0, 'bounding sphere across far' );
mesh.matrixWorld.identity();
mesh.position.setX( 150 );
mesh.scale.setY( 9999 );
mesh.updateMatrixWorld( true );
intersections.length = 0;
mesh.raycast( raycaster, intersections );
assert.ok( intersections.length > 0, 'bounding sphere across near and far' );
mesh.matrixWorld.identity();
mesh.position.setX( - 9999 );
mesh.updateMatrixWorld( true );
intersections.length = 0;
mesh.raycast( raycaster, intersections );
assert.ok( intersections.length === 0, 'bounding sphere behind near' );
mesh.matrixWorld.identity();
mesh.position.setX( 9999 );
mesh.updateMatrixWorld( true );
intersections.length = 0;
mesh.raycast( raycaster, intersections );
assert.ok( intersections.length === 0, 'bounding sphere beyond far' );
} );
} );
} );