UNPKG

awv3

Version:
239 lines (187 loc) 9.03 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _extends2 = require('babel-runtime/helpers/extends'); var _extends3 = _interopRequireDefault(_extends2); var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of'); var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf); var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); var _createClass2 = require('babel-runtime/helpers/createClass'); var _createClass3 = _interopRequireDefault(_createClass2); var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn'); var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2); var _inherits2 = require('babel-runtime/helpers/inherits'); var _inherits3 = _interopRequireDefault(_inherits2); var _get2 = require('babel-runtime/helpers/get'); var _get3 = _interopRequireDefault(_get2); var _three = require('three'); var THREE = _interopRequireWildcard(_three); var _object = require('../three/object3'); var _object2 = _interopRequireDefault(_object); var _helpers = require('../session/helpers'); var _easing = require('../animation/easing'); 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 }; } var Presentation = function (_Pool) { (0, _inherits3.default)(Presentation, _Pool); function Presentation(args) { (0, _classCallCheck3.default)(this, Presentation); var _this = (0, _possibleConstructorReturn3.default)(this, (Presentation.__proto__ || (0, _getPrototypeOf2.default)(Presentation)).call(this, args)); _this.options = (0, _extends3.default)({ shadow: true, lights: true, edges: 0.25, ambient: 0, light: 0.9 }, args); _this._objects = new Objects({ pool: _this }); (0, _get3.default)(Presentation.prototype.__proto__ || (0, _getPrototypeOf2.default)(Presentation.prototype), 'add', _this).call(_this, _this._objects); _this._stage = new Stage({ pool: _this }); (0, _get3.default)(Presentation.prototype.__proto__ || (0, _getPrototypeOf2.default)(Presentation.prototype), 'add', _this).call(_this, _this._stage); _this._lights = new Lights({ pool: _this }); (0, _get3.default)(Presentation.prototype.__proto__ || (0, _getPrototypeOf2.default)(Presentation.prototype), 'add', _this).call(_this, _this._lights); return _this; } (0, _createClass3.default)(Presentation, [{ key: 'add', value: function add(args) { this._objects.add(args); } }, { key: 'addAsync', value: function addAsync(args) { return this._objects.addAsync(args); } }, { key: 'remove', value: function remove(args) { this._objects.remove(args); } }, { key: 'removeAsync', value: function removeAsync(args) { return this._objects.removeAsync(args); } }, { key: 'update', value: function update() { var _this2 = this; this.viewFound().then(function () { _this2._objects.update(); _this2._lights.update(); _this2._stage.update(); _this2.view.scene.updateBounds(); _this2.view.controls.focus().zoom(); }); } }]); return Presentation; }(_helpers.Pool); exports.default = Presentation; var Lights = function (_Object) { (0, _inherits3.default)(Lights, _Object); function Lights(_ref) { var pool = _ref.pool; (0, _classCallCheck3.default)(this, Lights); var _this3 = (0, _possibleConstructorReturn3.default)(this, (Lights.__proto__ || (0, _getPrototypeOf2.default)(Lights)).call(this)); _this3.pool = pool; _this3.interactive = false; _this3.tweens = false; _this3.measurable = false; return _this3; } (0, _createClass3.default)(Lights, [{ key: 'update', value: function update() { this.destroy(); if (this.pool.parent) { if (this.pool.options.ambient) { var ambient = new THREE.AmbientLight(0xffffff); ambient.intensity = this.pool.options.ambient; this.add(ambient); } var radius = this.pool._objects.radius; this.add(new THREE.PointLight(0xffffff, this.pool.options.light / 2).setPosition(-radius, 0, 0)); this.add(new THREE.SpotLight(0xffffff, this.pool.options.light / 2).setPosition(0, -radius, -radius * 2)); this.add(new THREE.PointLight(0xffffff, this.pool.options.light / 2).setPosition(radius, 0, 0)); this.add(new THREE.PointLight(0xffffff, this.pool.options.light / 2).setPosition(0, radius, 0)); this.add(new THREE.PointLight(0xffffff, this.pool.options.light / 2).setPosition(0, 0, radius)); var vec = this.pool.parent.worldToLocal(new THREE.Vector3(-radius / 2, radius, radius / 2)); var spotLight = new THREE.SpotLight(0xffffff, this.pool.options.light, radius * 1.5, Math.PI / 6); spotLight.position.copy(vec); spotLight.target = this.pool._objects; spotLight.castShadow = true; spotLight.penumbra = 1; spotLight.shadow = new THREE.LightShadow(new THREE.PerspectiveCamera(10, 1, 100, radius * 1.5)); spotLight.shadow.mapSize.width = 2048; spotLight.shadow.mapSize.height = 2048; this.add(spotLight); } } }]); return Lights; }(_object2.default); var Stage = function (_Object2) { (0, _inherits3.default)(Stage, _Object2); function Stage(_ref2) { var pool = _ref2.pool; (0, _classCallCheck3.default)(this, Stage); var _this4 = (0, _possibleConstructorReturn3.default)(this, (Stage.__proto__ || (0, _getPrototypeOf2.default)(Stage)).call(this)); _this4.pool = pool; _this4.interactive = false; _this4.tweens = false; _this4.measurable = false; return _this4; } (0, _createClass3.default)(Stage, [{ key: 'update', value: function update() { this.destroy(); if (!isNaN(this.pool._objects.width) && !isNaN(this.pool._objects.depth)) { this.position.copy(this.pool._objects.getCenter()); this.position.y -= this.pool._objects.height * 0.9; this.rotation.x = -Math.PI / 2; var shadowGeo = new THREE.PlaneBufferGeometry(this.pool._objects.width * 1.2, this.pool._objects.depth * 1.2, 1, 1); var mesh = new THREE.Mesh(shadowGeo, shadowMaterial); this.add(mesh); } } }]); return Stage; }(_object2.default); var Objects = function (_Object3) { (0, _inherits3.default)(Objects, _Object3); function Objects() { (0, _classCallCheck3.default)(this, Objects); return (0, _possibleConstructorReturn3.default)(this, (Objects.__proto__ || (0, _getPrototypeOf2.default)(Objects)).apply(this, arguments)); } (0, _createClass3.default)(Objects, [{ key: 'update', value: function update() { this.updateBounds(); this.min = this.bounds.box.min; this.max = this.bounds.box.max; this.width = this.max.distanceTo(new THREE.Vector3(this.min.x, this.max.y, this.max.z)); this.height = this.max.distanceTo(new THREE.Vector3(this.max.x, this.min.y, this.max.z)); this.depth = this.max.distanceTo(new THREE.Vector3(this.max.x, this.max.y, this.min.z)); this.radius = this.getRadius() * 6; } }]); return Objects; }(_object2.default); function createShadowMaterial() { var canvas2d = document.createElement('canvas'); canvas2d.width = 128; canvas2d.height = 128; var context = canvas2d.getContext('2d'); var gradient = context.createRadialGradient(canvas2d.width / 2, canvas2d.height / 2, 0, canvas2d.width / 2, canvas2d.height / 2, canvas2d.width / 2); gradient.addColorStop(0.1, 'rgba(0,0,0,0.15)'); gradient.addColorStop(1, 'rgba(0,0,0,0)'); context.fillStyle = gradient; context.fillRect(0, 0, canvas2d.width, canvas2d.height); var shadowTexture = new THREE.CanvasTexture(canvas2d); return new THREE.MeshBasicMaterial({ map: shadowTexture, transparent: true }); } var shadowMaterial = createShadowMaterial();