awv3
Version:
⚡ AWV3 embedded CAD
121 lines (107 loc) • 4.51 kB
JavaScript
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = undefined;
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _three = require('three');
var THREE = _interopRequireWildcard(_three);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/** A heads up display that renders a separate scene. */
var Hud = function () {
function Hud(view) {
(0, _classCallCheck3.default)(this, Hud);
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);
}
(0, _createClass3.default)(Hud, [{
key: 'onMouseWheel',
value: function onMouseWheel(state) {
this.enabled && this.controls && this.controls != this.view.controls && this.controls.onMouseWheel(state);
}
}, {
key: 'onMouseMove',
value: function onMouseMove(state) {
this.enabled && this.controls && this.controls != this.view.controls && this.controls.onMouseMove(state);
}
}, {
key: 'onMouseDown',
value: function onMouseDown(state) {
this.enabled && this.controls && this.controls != this.view.controls && this.controls.onMouseDown(state);
}
}, {
key: 'onMouseUp',
value: function onMouseUp(state) {
this.enabled && this.controls && this.controls != this.view.controls && this.controls.onMouseUp(state);
}
}, {
key: 'onTouchStart',
value: function onTouchStart(state) {
this.enabled && this.controls && this.controls != this.view.controls && this.controls.onTouchStart(state);
}
}, {
key: 'onTouchMove',
value: function onTouchMove(state) {
this.enabled && this.controls && this.controls != this.view.controls && this.controls.onTouchMove(state);
}
}, {
key: 'onTouchEnd',
value: function onTouchEnd(state) {
this.enabled && this.controls && this.controls != this.view.controls && this.controls.onTouchEnd(state);
}
}, {
key: 'update',
value: function update(time) {
this.enabled && this.controls && this.controls != this.view.controls && this.controls.update(time);
}
}, {
key: 'calibrate',
value: function 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;
}
}
}, {
key: 'render',
value: function render() {
this.enabled && this.renderer.gl.render(this.scene, this.camera && this.camera.display || this.view.camera.display);
}
}, {
key: 'destroy',
value: function 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;
}
}, {
key: 'inMotion',
get: function get() {
return this.enabled && this.controls && this.controls.inMotion;
}
}]);
return Hud;
}();
exports.default = Hud;