From 8975108fccd082fd13dfe0cc41e5e99d121eb1a1 Mon Sep 17 00:00:00 2001 From: Kevin Ngo Date: Thu, 12 May 2016 17:01:07 -0700 Subject: [PATCH] dist --- dist/aframe-interpolate-component.js | 203 +++++++++++++++++++++++ dist/aframe-interpolate-component.min.js | 1 + 2 files changed, 204 insertions(+) create mode 100644 dist/aframe-interpolate-component.js create mode 100644 dist/aframe-interpolate-component.min.js diff --git a/dist/aframe-interpolate-component.js b/dist/aframe-interpolate-component.js new file mode 100644 index 0000000..46b5647 --- /dev/null +++ b/dist/aframe-interpolate-component.js @@ -0,0 +1,203 @@ +/******/ (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) { + + /* globals AFRAME, performance, THREE */ + + if (typeof AFRAME === 'undefined') { + throw new Error('Component attempted to register before AFRAME was available.'); + } + + function getMillis () { + return new Date().getTime(); + } + + function PositionInterpolator (timestep, entity) { + var time = getMillis(); + var previous; + var next; + + entity.el.addEventListener('componentchanged', function (event) { + if (getTime() < 0.5) { + // fixme - ignore multiple calls + return; + } + + if (event.detail.name === 'position') { + if (!previous) { + previous = new THREE.Vector3(); + next = new THREE.Vector3(); + } + + time = getMillis(); + previous.copy(next); + next.copy(event.detail.newData); + } + }); + + function getTime () { + return (getMillis() - time) / timestep; + } + + this.active = function () { + return previous && next && (getTime() < 1.0); + }; + + var v = new THREE.Vector3(); + + this.get = function () { + return v.lerpVectors(previous, next, getTime()); + }; + } + + function radians(degrees) { + return degrees * Math.PI / 180.0; + } + + function RotationInterpolator (timestep, entity) { + var time = getMillis(); + var previous; + var next; + + entity.el.addEventListener('componentchanged', function (event) { + if (getTime() < 0.5) { + // fixme - ignore multiple calls + return; + } + + if (event.detail.name === 'rotation') { + if (!previous) { + previous = new THREE.Quaternion(); + next = new THREE.Quaternion(); + } + + time = getMillis(); + previous.copy(next); + next.setFromEuler(new THREE.Euler( + radians(event.detail.newData.x), + radians(event.detail.newData.y), + radians(event.detail.newData.z) + )); + } + }); + + function getTime () { + return (getMillis() - time) / timestep; + } + + this.active = function () { + return previous && next && (getTime() < 1.0); + }; + + var e = new THREE.Euler(); + var q = new THREE.Quaternion(); + this.get = function () { + THREE.Quaternion.slerp(previous, next, q, getTime()); + return e.setFromQuaternion(q); + }; + } + + /** + * Interpolate component for A-Frame. + */ + AFRAME.registerComponent('interpolation', { + schema: { + duration: { default: 200 } + }, + + /** + * Called once when component is attached. Generally for initial setup. + */ + init: function () { + }, + + /** + * Called when component is attached and when component data changes. + * Generally modifies the entity based on the data. + */ + update: function (oldData) { + if (!this.interpolation) { + var timestep = parseInt(this.data.duration, 10); + + this.positionInterpolator = new PositionInterpolator(timestep, this); + this.rotationInterpolator = new RotationInterpolator(timestep, this); + } + }, + + /** + * Called when a component is removed (e.g., via removeAttribute). + * Generally undoes all modifications to the entity. + */ + remove: function () { }, + + /** + * Called on each scene tick. + */ + tick: function (t) { + if (this.positionInterpolator && this.positionInterpolator.active()) { + this.el.object3D.position.copy(this.positionInterpolator.get()); + } + + if (this.rotationInterpolator && this.rotationInterpolator.active()) { + this.el.object3D.rotation.copy(this.rotationInterpolator.get()); + } + }, + + /** + * Called when entity pauses. + * Use to stop or remove any dynamic or background behavior such as events. + */ + pause: function () { }, + + /** + * Called when entity resumes. + * Use to continue or add any dynamic or background behavior such as events. + */ + play: function () { }, + }); + + +/***/ } +/******/ ]); \ No newline at end of file diff --git a/dist/aframe-interpolate-component.min.js b/dist/aframe-interpolate-component.min.js new file mode 100644 index 0000000..22f4641 --- /dev/null +++ b/dist/aframe-interpolate-component.min.js @@ -0,0 +1 @@ +!function(t){function n(o){if(e[o])return e[o].exports;var i=e[o]={exports:{},id:o,loaded:!1};return t[o].call(i.exports,i,i.exports,n),i.loaded=!0,i.exports}var e={};return n.m=t,n.c=e,n.p="",n(0)}([function(t,n){function e(){return(new Date).getTime()}function o(t,n){function o(){return(e()-a)/t}var i,r,a=e();n.el.addEventListener("componentchanged",function(t){o()<.5||"position"===t.detail.name&&(i||(i=new THREE.Vector3,r=new THREE.Vector3),a=e(),i.copy(r),r.copy(t.detail.newData))}),this.active=function(){return i&&r&&o()<1};var u=new THREE.Vector3;this.get=function(){return u.lerpVectors(i,r,o())}}function i(t){return t*Math.PI/180}function r(t,n){function o(){return(e()-u)/t}var r,a,u=e();n.el.addEventListener("componentchanged",function(t){o()<.5||"rotation"===t.detail.name&&(r||(r=new THREE.Quaternion,a=new THREE.Quaternion),u=e(),r.copy(a),a.setFromEuler(new THREE.Euler(i(t.detail.newData.x),i(t.detail.newData.y),i(t.detail.newData.z))))}),this.active=function(){return r&&a&&o()<1};var c=new THREE.Euler,s=new THREE.Quaternion;this.get=function(){return THREE.Quaternion.slerp(r,a,s,o()),c.setFromQuaternion(s)}}if("undefined"==typeof AFRAME)throw new Error("Component attempted to register before AFRAME was available.");AFRAME.registerComponent("interpolation",{schema:{duration:{"default":200}},init:function(){},update:function(t){if(!this.interpolation){var n=parseInt(this.data.duration,10);this.positionInterpolator=new o(n,this),this.rotationInterpolator=new r(n,this)}},remove:function(){},tick:function(t){this.positionInterpolator&&this.positionInterpolator.active()&&this.el.object3D.position.copy(this.positionInterpolator.get()),this.rotationInterpolator&&this.rotationInterpolator.active()&&this.el.object3D.rotation.copy(this.rotationInterpolator.get())},pause:function(){},play:function(){}})}]); \ No newline at end of file