-
Notifications
You must be signed in to change notification settings - Fork 265
/
TilesGroup.js
91 lines (55 loc) · 1.71 KB
/
TilesGroup.js
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
import { Group, Matrix4 } from 'three';
// Specialization of "Group" that only updates world matrices of children if
// the transform has changed since the last update and ignores the "force"
// parameter under the assumption that the children tiles will not move.
const tempMat = new Matrix4();
export class TilesGroup extends Group {
constructor( tilesRenderer ) {
super();
this.name = 'TilesRenderer.TilesGroup';
this.tilesRenderer = tilesRenderer;
}
raycast( raycaster, intersects ) {
// returning "false" ends raycast traversal
if ( this.tilesRenderer.optimizeRaycast ) {
this.tilesRenderer.raycast( raycaster, intersects );
return false;
}
return true;
}
updateMatrixWorld( force ) {
if ( this.matrixAutoUpdate ) {
this.updateMatrix();
}
if ( this.matrixWorldNeedsUpdate || force ) {
if ( this.parent === null ) {
tempMat.copy( this.matrix );
} else {
tempMat.multiplyMatrices( this.parent.matrixWorld, this.matrix );
}
this.matrixWorldNeedsUpdate = false;
// check if the matrix changed relative to what it was.
const elA = tempMat.elements;
const elB = this.matrixWorld.elements;
let isDifferent = false;
for ( let i = 0; i < 16; i ++ ) {
const itemA = elA[ i ];
const itemB = elB[ i ];
const diff = Math.abs( itemA - itemB );
if ( diff > Number.EPSILON ) {
isDifferent = true;
break;
}
}
if ( isDifferent ) {
this.matrixWorld.copy( tempMat );
// update children
// the children will not have to change unless the parent group has updated
const children = this.children;
for ( let i = 0, l = children.length; i < l; i ++ ) {
children[ i ].updateMatrixWorld();
}
}
}
}
}