123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- /******/ (function(modules) { // webpackBootstrap
- /******/ // The module cache
- /******/ var installedModules = {};
- /******/ // The require function
- /******/ function __webpack_require__(moduleId) {
- /******/ // Check if module is in cache
- /******/ if(installedModules[moduleId])
- /******/ return installedModules[moduleId].exports;
- /******/ // Create a new module (and put it into the cache)
- /******/ var module = installedModules[moduleId] = {
- /******/ exports: {},
- /******/ id: moduleId,
- /******/ loaded: false
- /******/ };
- /******/ // Execute the module function
- /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
- /******/ // Flag the module as loaded
- /******/ module.loaded = true;
- /******/ // Return the exports of the module
- /******/ return module.exports;
- /******/ }
- /******/ // expose the modules object (__webpack_modules__)
- /******/ __webpack_require__.m = modules;
- /******/ // expose the module cache
- /******/ __webpack_require__.c = installedModules;
- /******/ // __webpack_public_path__
- /******/ __webpack_require__.p = "";
- /******/ // Load entry module and return exports
- /******/ return __webpack_require__(0);
- /******/ })
- /************************************************************************/
- /******/ ([
- /* 0 */
- /***/ (function(module, exports, __webpack_require__) {
- /* global AFRAME THREE */
- if (typeof AFRAME === 'undefined') {
- throw new Error('Component attempted to register before AFRAME was available.');
- }
- var degToRad = THREE.Math.degToRad;
- var almostEqual = __webpack_require__(1);
- /**
- * Linear Interpolation component for A-Frame.
- */
- AFRAME.registerComponent('lerp', {
- schema: {
- properties: { default: ['position', 'rotation', 'scale']},
- },
- /**
- * Called once when component is attached. Generally for initial setup.
- */
- init: function () {
- var el = this.el;
- this.lastPosition = el.getAttribute('position');
- this.lastRotation = el.getAttribute('rotation');
- this.lastScale = el.getAttribute('scale');
- this.lerpingPosition = false;
- this.lerpingRotation = false;
- this.lerpingScale = false;
- this.timeOfLastUpdate = 0;
- },
- /**
- * Called on each scene tick.
- */
- tick: function (time, deltaTime) {
- var progress;
- var now = this.now();
- var obj3d = this.el.object3D;
- this.checkForComponentChanged();
- // Lerp position
- if (this.lerpingPosition) {
- progress = (now - this.startLerpTimePosition) / this.duration;
- obj3d.position.lerpVectors(this.startPosition, this.targetPosition, progress);
- // console.log("new position", obj3d.position);
- if (progress >= 1) {
- this.lerpingPosition = false;
- }
- }
- // Slerp rotation
- if (this.lerpingRotation) {
- progress = (now - this.startLerpTimeRotation) / this.duration;
- THREE.Quaternion.slerp(this.startRotation, this.targetRotation, obj3d.quaternion, progress);
- if (progress >= 1) {
- this.lerpingRotation = false;
- }
- }
- // Lerp scale
- if (this.lerpingScale) {
- progress = (now - this.startLerpTimeScale) / this.duration;
- obj3d.scale.lerpVectors(this.startScale, this.targetScale, progress);
- if (progress >= 1) {
- this.lerpingScale = false;
- }
- }
- },
- checkForComponentChanged: function() {
- var el = this.el;
- var hasChanged = false;
- var newPosition = el.getAttribute('position');
- if (this.isLerpable('position') && !this.almostEqualVec3(this.lastPosition, newPosition)) {
- this.toPosition(this.lastPosition, newPosition);
- this.lastPosition = newPosition;
- hasChanged = true;
- }
- var newRotation = el.getAttribute('rotation');
- if (this.isLerpable('rotation') && !this.almostEqualVec3(this.lastRotation, newRotation)) {
- this.toRotation(this.lastRotation, newRotation);
- this.lastRotation = newRotation;
- hasChanged = true;
- }
- var newScale = el.getAttribute('scale');
- if (this.isLerpable('scale') && !this.almostEqualVec3(this.lastScale, newScale)) {
- this.toScale(this.lastScale, newScale);
- this.lastScale = newScale;
- hasChanged = true;
- }
- if (hasChanged) {
- this.updateDuration();
- }
- },
- isLerpable: function(name) {
- return this.data.properties.indexOf(name) != -1
- },
- updateDuration: function() {
- var now = this.now();
- this.duration = now - this.timeOfLastUpdate;
- this.timeOfLastUpdate = now;
- },
- /**
- * Start lerp to position (vec3)
- */
- toPosition: function (from, to) {
- this.lerpingPosition = true;
- this.startLerpTimePosition = this.now();
- this.startPosition = new THREE.Vector3(from.x, from.y, from.z);
- this.targetPosition = new THREE.Vector3(to.x, to.y, to.z);
- },
- /**
- * Start lerp to euler rotation (vec3,'YXZ')
- */
- toRotation: function (from, to) {
- this.lerpingRotation = true;
- this.startLerpTimeRotation = this.now();
- this.startRotation = new THREE.Quaternion();
- this.startRotation.setFromEuler(
- new THREE.Euler(degToRad(from.x), degToRad(from.y), degToRad(from.z), 'YXZ'));
- this.targetRotation = new THREE.Quaternion();
- this.targetRotation.setFromEuler(
- new THREE.Euler(degToRad(to.x), degToRad(to.y), degToRad(to.z), 'YXZ'));
- },
- /**
- * Start lerp to scale (vec3)
- */
- toScale: function (from, to) {
- this.lerpingScale = true;
- this.startLerpTimeScale = this.now();
- this.startScale = new THREE.Vector3(from.x, from.y, from.z);
- this.targetScale = new THREE.Vector3(to.x, to.y, to.z);
- },
- almostEqualVec3: function(a, b) {
- return almostEqual(a.x, b.x) && almostEqual(a.y, b.y) && almostEqual(a.z, b.z);
- },
- /**
- * Returns the current time in milliseconds (ms)
- */
- now: function() {
- return Date.now();
- }
- });
- /***/ }),
- /* 1 */
- /***/ (function(module, exports) {
- "use strict"
- var abs = Math.abs
- , min = Math.min
- function almostEqual(a, b, absoluteError, relativeError) {
- var d = abs(a - b)
-
- if (absoluteError == null) absoluteError = almostEqual.DBL_EPSILON;
- if (relativeError == null) relativeError = absoluteError;
-
- if(d <= absoluteError) {
- return true
- }
- if(d <= relativeError * min(abs(a), abs(b))) {
- return true
- }
- return a === b
- }
- almostEqual.FLT_EPSILON = 1.19209290e-7
- almostEqual.DBL_EPSILON = 2.2204460492503131e-16
- module.exports = almostEqual
- /***/ })
- /******/ ]);
|