-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathaframe-interpolate-component.min.js
More file actions
1 lines (1 loc) · 1.79 KB
/
aframe-interpolate-component.min.js
File metadata and controls
1 lines (1 loc) · 1.79 KB
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(){}})}]);