UNPKG

awv3

Version:
75 lines (70 loc) 2.83 kB
import * as THREE from 'three'; /** A heads up display that renders a separate scene. */ export default class Hud { constructor(view) { this.enabled = true; this.view = view; this.renderer = view.renderer; this.scene = new THREE.Scene(); this.scene.canvas = view.canvas; this.scene.view = view; this.camera = undefined; this.controls = undefined; this.ambient = new THREE.AmbientLight(view.options.ambientColor ? view.options.ambientColor : 0xffffff); this.ambient.intensity = typeof view.options.ambientIntensity !== 'undefined' ? view.options.ambientIntensity : 1.0; this.ambient.keep = true; this.ambient.view = this; this.scene.add(this.ambient); } onMouseWheel(state) { this.enabled && this.controls && this.controls != this.view.controls && this.controls.onMouseWheel(state); } onMouseMove(state) { this.enabled && this.controls && this.controls != this.view.controls && this.controls.onMouseMove(state); } onMouseDown(state) { this.enabled && this.controls && this.controls != this.view.controls && this.controls.onMouseDown(state); } onMouseUp(state) { this.enabled && this.controls && this.controls != this.view.controls && this.controls.onMouseUp(state); } onTouchStart(state) { this.enabled && this.controls && this.controls != this.view.controls && this.controls.onTouchStart(state); } onTouchMove(state) { this.enabled && this.controls && this.controls != this.view.controls && this.controls.onTouchMove(state); } onTouchEnd(state) { this.enabled && this.controls && this.controls != this.view.controls && this.controls.onTouchEnd(state); } update(time) { this.enabled && this.controls && this.controls != this.view.controls && this.controls.update(time); } calibrate(width, height) { if (this.enabled && this.camera && this.camera != this.view.camera) { this.camera.aspect = this.view.camera.aspect; this.camera.updateProjectionMatrix(); this.camera.radius = (width + height) / 4; } } render() { this.enabled && this.renderer.gl.render(this.scene, (this.camera && this.camera.display) || this.view.camera.display); } destroy() { this.view = undefined; this.renderer = undefined; this.scene.destroy({ keep: false }); this.scene.canvas = undefined; this.scene.view = undefined; this.scene = undefined; this.camera = undefined; this.controls = undefined; this.ambient = undefined; } get inMotion() { return this.enabled && this.controls && this.controls.inMotion; } }