-
Notifications
You must be signed in to change notification settings - Fork 105
/
LODRadial.ts
52 lines (44 loc) · 1.31 KB
/
LODRadial.ts
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
import {LODControl} from './LODControl';
import {Camera, Object3D, Vector3, WebGLRenderer} from 'three';
import {MapView} from '../MapView';
const pov = new Vector3();
const position = new Vector3();
/**
* Check the planar distance between the nodes center and the view position.
*
* Distance is adjusted with the node level, more consistent results since every node is considered.
*/
export class LODRadial implements LODControl
{
/**
* Minimum ditance to subdivide nodes.
*/
public subdivideDistance: number;
/**
* Minimum ditance to simplify far away nodes that are subdivided.
*/
public simplifyDistance: number;
public constructor(subdivideDistance: number = 50, simplifyDistance: number = 300)
{
this.subdivideDistance = subdivideDistance;
this.simplifyDistance = simplifyDistance;
}
public updateLOD(view: MapView, camera: Camera, renderer: WebGLRenderer, scene: Object3D): void
{
camera.getWorldPosition(pov);
view.children[0].traverse((node: any) =>
{
node.getWorldPosition(position);
let distance = pov.distanceTo(position);
distance /= Math.pow(2, view.provider.maxZoom - node.level);
if (distance < this.subdivideDistance)
{
node.subdivide();
}
else if (distance > this.simplifyDistance && node.parentNode)
{
node.parentNode.simplify();
}
});
}
}