UNPKG

@onirix/camera-controls-module

Version:

Onirix helper library for camera controls.

2 lines (1 loc) 33.9 kB
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(t||self).OnirixCameraControlsModule=n()}(this,function(){function t(t){return t}var n=h(3),e=u(3),i=a(n,e),o=c(.25),r=l(.25),s=a(c(.5),l(.5));function a(t,n){return function(e){return e<.5?t(2*e)/2:(1+n(2*e-1))/2}}function h(t){return function(n){return Math.pow(n,t)}}function u(t){return function(n){return 1-Math.pow(1-n,t)}}function c(t){var n=1/(2*t-t*t-1),e=-2*n,i=n+1;return function(t){var o=t*t;return n*(o*t)+e*o+i*t}}function l(t){var n=1/(2*t-t*t-1),e=-n;return function(t){var i=t*t;return n*(i*t)+e*i+t}}function f(t,n){for(var e=0;e<n.length;e++){var i=n[e];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,"symbol"==typeof(o=function(t,n){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var i=e.call(t,"string");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(i.key))?o:String(o),i)}var o}function d(t,n,e){return n&&f(t.prototype,n),e&&f(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t}function _(t,n){(null==n||n>t.length)&&(n=t.length);for(var e=0,i=new Array(n);e<n;e++)i[e]=t[e];return i}var v,m,p=1e-8,y=function(){function t(t,n,e){this._x=0,this._y=0,this._z=0,this._x=null==t?this._x:t,this._y=null==n?this._y:n,this._z=null==e?this._z:e}var n=t.prototype;return n.add=function(n){return"number"==typeof n?new t(this.x+n,this.y+n,this.z+n):new t(this.x+n.x,this.y+n.y,this.z+n.z)},n.sub=function(n){return"number"==typeof n?new t(this.x-n,this.y-n,this.z-n):new t(this.x-n.x,this.y-n.y,this.z-n.z)},n.prod=function(n){return"number"==typeof n?new t(this.x*n,this.y*n,this.z*n):new t(this.x*n.x,this.y*n.y,this.z*n.z)},n.div=function(n){return"number"==typeof n?new t(this.x/n,this.y/n,this.z/n):new t(this.x/n.x,this.y/n.y,this.z/n.z)},n.dot=function(t){return this.x*t.x+this.y*t.y+this.z*t.z},n.cross=function(n){return new t(this.y*n.z-this.z*n.y,this.z*n.x-this.x*n.z,this.x*n.y-this.y*n.x)},n.abs=function(){return Math.sqrt(this.dot(this))},n.normalized=function(){return 0===this.abs()?new t(0,0,0):this.div(this.abs())},n.angle=function(t){return Math.acos(this.dot(t)/(this.abs()*t.abs()))},n.projectAbs=function(t){return this.dot(t)/this.abs()},n.project=function(t){var n=this.normalized(),e=n.dot(t);return n.prod(e)},n.negate=function(){return new t(-this.x,-this.y,-this.z)},n.equals=function(t){return this===t||Math.abs(this.x-t.x)<p&&Math.abs(this.y-t.y)<p&&Math.abs(this.z-t.z)<p},n.orthonormal=function(){return Math.abs(this.x)>=p?[new t(-this.z,0,this.x),new t(this.y,-this.x,0)]:Math.abs(this.y)>=p?[new t(0,this.z,-this.y),new t(this.y,-this.x,0)]:Math.abs(this.z)>=p?[new t(0,this.z,-this.y),new t(-this.z,0,this.x)]:void 0},n.max=function(n){return new t(Math.max(this.x,n.x),Math.max(this.y,n.y),Math.max(this.z,n.z))},n.min=function(n){return new t(Math.min(this.x,n.x),Math.min(this.y,n.y),Math.min(this.z,n.z))},n.clamp=function(t,n){return this.min(n).max(t)},n.distance=function(t){return this.sub(t).abs()},d(t,[{key:"x",get:function(){return this._x}},{key:"y",get:function(){return this._y}},{key:"z",get:function(){return this._z}}]),t}();y.ZERO=new(v=y)(0,0,0),y.X=new v(1,0,0),y.Y=new v(0,1,0),y.Z=new v(0,0,1),y.UP=v.Y,y.DOWN=v.Y.negate(),y.LEFT=v.X.negate(),y.RIGHT=v.X,y.FRONT=v.Z.negate(),y.BACK=v.Z;var w=function(){function t(t,n,e,i){this._x=0,this._y=0,this._z=0,this._w=0,this._x=null==t?this._x:t,this._y=null==n?this._y:n,this._z=null==e?this._z:e,this._w=null==i?this._w:i}t.betweenVectors=function(n,e,i){return void 0===i&&(i=y.UP),t.forDirection(e,n,i)},t.forDirection=function(n,e,i){if(void 0===e&&(e=y.FRONT),void 0===i&&(i=y.UP),n.equals(y.ZERO)||e.equals(y.ZERO)||i.equals(y.ZERO))return t.IDENTITY;n=n.normalized(),e=e.normalized(),i=i.normalized();var o=e.cross(n);Math.abs(o.abs())<p&&(o=e.orthonormal()[0].normalized());var r=e.angle(n),s=t.forRotationAroundAxis(o,r),a=s.apply(i),h=a.sub(e.project(a)),u=i.sub(e.project(i));if(h.equals(y.ZERO)||u.equals(y.ZERO))return s;var c=u.angle(h),l=u.cross(h).normalized();return s.append(t.forRotationAroundAxis(l,c))},t.forRotationAroundAxis=function(n,e){n=n.normalized();var i=Math.sin(e/2);return new t(i*n.x,i*n.y,i*n.z,Math.cos(e/2))},t.forXRotation=function(n){return new t(Math.sin(n/2),0,0,Math.cos(n/2))},t.forYRotation=function(n){return new t(0,Math.sin(n/2),0,Math.cos(n/2))},t.forZRotation=function(n){return new t(0,0,Math.sin(n/2),Math.cos(n/2))},t.forEuler=function(n,e,i){var o=Math.cos(n/2),r=Math.sin(n/2),s=Math.cos(e/2),a=Math.sin(e/2),h=Math.cos(i/2),u=Math.sin(i/2);return new t(r*s*h+o*a*u,o*a*h-r*s*u,o*s*u+r*a*h,o*s*h-r*a*u)},t.sequence=function(){for(var t=[].slice.call(arguments),n=t[0],e=1;e<t.length;e++)n=n.append(t[e]);return n},t.extractYaw=function(t){return Math.atan2(2*(t.w*t.y+t.x*t.z),1-2*(t.y*t.y+t.z*t.z))};var n=t.prototype;return n.conjugate=function(){return new t(-this.x,-this.y,-this.z,this.w)},n.inverse=function(){return this.conjugate().div(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},n.add=function(n){return"number"==typeof n?new t(this.x+n,this.y+n,this.z+n,this.w+n):new t(this.x+n.x,this.y+n.y,this.z+n.z,this.w+n.w)},n.sub=function(n){return"number"==typeof n?new t(this.x-n,this.y-n,this.z-n,this.w-n):new t(this.x-n.x,this.y-n.y,this.z-n.z,this.w-n.w)},n.prod=function(n){return"number"==typeof n?new t(this.x*n,this.y*n,this.z*n,this.w*n):new t(this.w*n.x+this.x*n.w+this.y*n.z-this.z*n.y,this.w*n.y+this.y*n.w+this.z*n.x-this.x*n.z,this.w*n.z+this.z*n.w+this.x*n.y-this.y*n.x,this.w*n.w-this.x*n.x-this.y*n.y-this.z*n.z)},n.div=function(n){return"number"==typeof n?new t(this.x/n,this.y/n,this.z/n,this.w/n):this.prod(n.inverse())},n.negate=function(){return new t(-this.x,-this.y,-this.z,-this.w)},n.equals=function(t){return this===t||Math.abs(this.x-t.x)<p&&Math.abs(this.y-t.y)<p&&Math.abs(this.z-t.z)<p&&Math.abs(this.w-t.w)<p},n.prepend=function(t){return t.prod(this)},n.append=function(t){return this.prod(t)},n.axis=function(){var t=this.normalized(),n=Math.sqrt(1-t.w*t.w);return this.vector().div(n)},n.angle=function(){return 2*Math.atan2(this.vector().abs(),this.w)},n.vector=function(){return new y(this.x,this.y,this.z)},n.scalar=function(){return this.w},n.exp=function(){if(this.abs()<p)return t.IDENTITY;var n=this.scalar(),e=this.vector(),i=e.abs(),o=Math.exp(n),r=e.prod(o*Math.sin(i)/i),s=o*Math.cos(i);return new t(r.x,r.y,r.z,s)},n.log=function(){var n=this.scalar(),e=this.vector(),i=this.abs(),o=Math.log(i),r=e.normalized().prod(Math.acos(n/i));return new t(r.x,r.y,r.z,o)},n.pow=function(t){return this.log().prod(t).exp()},n.apply=function(n){n=new t(n.x,n.y,n.z,0);var e=this.normalized(),i=e.conjugate(),o=e.prod(n).prod(i);return new y(o.x,o.y,o.z)},n.abs=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},n.normalized=function(){var n=this.abs();return new t(this.x/n,this.y/n,this.z/n,this.w/n)},n.distance=function(t){return this.inverse().prod(t).angle()},d(t,[{key:"x",get:function(){return this._x}},{key:"y",get:function(){return this._y}},{key:"z",get:function(){return this._z}},{key:"w",get:function(){return this._w}}]),t}();function g(t,n){if(t instanceof y||t instanceof w){var e=n.sub(t);return function(n){return t.add(e.prod(n))}}if("number"==typeof t){var i=n-t;return function(n){return t+i*n}}throw new TypeError("Linear interpolation is not defined for type '"+typeof t+"'")}function b(t,n,e){function i(t,n){if(t instanceof y){var i=b(w.IDENTITY,w.betweenVectors(t.negate(),n.negate(),e)),o=t.abs(),r=g(o,n.abs());return t=o<p?n.normalized():t.normalized(),function(n){var e=i(n),o=r(n);return e.apply(t).prod(o)}}if(t instanceof w){var s=t.inverse().prod(n);return function(n){return t.prod(s.pow(n))}}throw new TypeError("Spherical interpolation is not defined for type '"+typeof t+"'")}if(void 0===n&&(n=void 0),void 0===e&&(e=y.UP),null==n){var o=t;return function(t,n){var e=i(t.sub(o),n.sub(o));return function(t){return e(t).add(o)}}}return i(t,n)}function x(t,n,e){return void 0===e&&(e=null),0===n?z(function(){return t(1)})():z(function(i){var o=z(function(r){var s,a=Math.min((r-i)/n,1);if(t(a),r<i+n&&(null==(s=e)||!s.aborted))return o()});return o()})()}function E(t){var n=!1,e=null,i=z(function(){return n=!1,t.apply(void 0,[].slice.call(arguments))});return function(){return n||(e=i([].slice.call(arguments)),n=!0),e}}function z(t){return function(){var n=arguments;return new Promise(function(e){return window.requestAnimationFrame(function(i){return e(t.apply(void 0,[i].concat([].slice.call(n))))})})}}w.ZERO=new(m=w)(0,0,0,0),w.IDENTITY=new m(0,0,0,1);var T={__proto__:null,linear:t,cubicEaseIn:n,cubicEaseOut:e,cubicEaseInOut:i,bounceIn:o,bounceOut:r,bounceInOut:s,easeInOutFactory:a,polynomialEaseInFactory:h,polynomialEaseOutFactory:u,bounceInFactory:c,bounceOutFactory:l,linearInterpolator:g,sphericalInterpolator:b,animate:x,debounced:E,deferred:z},P=function(){function t(t){this._array=void 0,null==t&&((t=Array(16).fill(0))[0]=1,t[5]=1,t[10]=1,t[15]=1),this._array=t}t.identity=function(){var n=Array(16).fill(0);return n[0]=1,n[5]=1,n[10]=1,n[15]=1,new t(n)},t.fromRotationTranslation=function(n,e){var i=n.x+n.x,o=n.y+n.y,r=n.z+n.z,s=n.x*i,a=n.x*o,h=n.x*r,u=n.y*o,c=n.y*r,l=n.z*r,f=n.w*i,d=n.w*o,_=n.w*r,v=Array(16).fill(0);return v[0]=1-(u+l),v[1]=a-_,v[2]=h+d,v[3]=e.x,v[4]=a-_,v[5]=1-(s+l),v[6]=c-f,v[7]=e.y,v[8]=h-d,v[9]=c+f,v[10]=1-(s+u),v[11]=e.z,v[12]=0,v[13]=0,v[14]=0,v[15]=1,new t(v)};var n=t.prototype;return n.getPosition=function(){var t=this._array;return new y(t[3],t[7],t[11])},n.getQuaternion=function(){var t,n,e,i,o,r=this._array,s=r[0],a=r[1],h=r[2],u=r[4],c=r[5],l=r[6],f=r[8],d=r[9],_=r[10],v=s+c+_;return v>0?(o=.25/(t=.5/Math.sqrt(v+1)),n=(d-l)*t,e=(h-f)*t,i=(u-a)*t):s>c&&s>_?(o=(d-l)/(t=2*Math.sqrt(1+s-c-_)),n=.25*t,e=(a+u)/t,i=(h+f)/t):c>_?(o=(h-f)/(t=2*Math.sqrt(1+c-s-_)),n=(a+u)/t,e=.25*t,i=(l+d)/t):(o=(u-a)/(t=2*Math.sqrt(1+_-s-c)),n=(h+f)/t,e=(l+d)/t,i=.25*t),new w(n,e,i,o)},t.translate=function(n){return new t([1,0,0,n.x,0,1,0,n.y,0,0,1,n.z,0,0,0,1])},t.rotate=function(n){var e=n.x,i=n.x*n.x,o=n.y,r=n.y*n.y,s=n.z,a=n.z*n.z,h=n.w;return new t([1-2*r-2*a,2*e*o-2*s*h,2*e*s+2*o*h,0,2*e*o+2*s*h,1-2*i-2*a,2*o*s-2*e*h,0,2*e*s-2*o*h,2*o*s+2*e*h,1-2*i-2*r,0,0,0,0,1])},t.invert=function(n){var e=Array(16).fill(0),i=n._array,o=i[0],r=i[1],s=i[2],a=i[3],h=i[4],u=i[5],c=i[6],l=i[7],f=i[8],d=i[9],_=i[10],v=i[11],m=i[12],p=i[13],y=i[14],w=i[15],g=o*u-r*h,b=o*c-s*h,x=o*l-a*h,E=r*c-s*u,z=r*l-a*u,T=s*l-a*c,P=f*p-d*m,M=f*y-_*m,O=f*w-v*m,R=d*y-_*p,A=d*w-v*p,I=_*w-v*y,N=g*I-b*A+x*R+E*O-z*M+T*P;return N?(e[0]=(u*I-c*A+l*R)*(N=1/N),e[1]=(s*A-r*I-a*R)*N,e[2]=(p*T-y*z+w*E)*N,e[3]=(_*z-d*T-v*E)*N,e[4]=(c*O-h*I-l*M)*N,e[5]=(o*I-s*O+a*M)*N,e[6]=(y*x-m*T-w*b)*N,e[7]=(f*T-_*x+v*b)*N,e[8]=(h*A-u*O+l*P)*N,e[9]=(r*O-o*A-a*P)*N,e[10]=(m*z-p*x+w*g)*N,e[11]=(d*x-f*z-v*g)*N,e[12]=(u*M-h*R-c*P)*N,e[13]=(o*R-r*M+s*P)*N,e[14]=(p*b-m*E-y*g)*N,e[15]=(f*E-d*b+_*g)*N,new t(e)):null},t.sequence=function(){var t=[].slice.call(arguments);if(0!==t.length){for(var n=t[0],e=1;e<t.length;e++)n=n.prepend(t[e]);return n}},n.prod=function(n){var e=this._array,i=n._array;return new t([e[0]*i[0]+e[1]*i[4]+e[2]*i[8]+e[3]*i[12],e[0]*i[1]+e[1]*i[5]+e[2]*i[9]+e[3]*i[13],e[0]*i[2]+e[1]*i[6]+e[2]*i[10]+e[3]*i[14],e[0]*i[3]+e[1]*i[7]+e[2]*i[11]+e[3]*i[15],e[4]*i[0]+e[5]*i[4]+e[6]*i[8]+e[7]*i[12],e[4]*i[1]+e[5]*i[5]+e[6]*i[9]+e[7]*i[13],e[4]*i[2]+e[5]*i[6]+e[6]*i[10]+e[7]*i[14],e[4]*i[3]+e[5]*i[7]+e[6]*i[11]+e[7]*i[15],e[8]*i[0]+e[9]*i[4]+e[10]*i[8]+e[11]*i[12],e[8]*i[1]+e[9]*i[5]+e[10]*i[9]+e[11]*i[13],e[8]*i[2]+e[9]*i[6]+e[10]*i[10]+e[11]*i[14],e[8]*i[3]+e[9]*i[7]+e[10]*i[11]+e[11]*i[15],e[12]*i[0]+e[13]*i[4]+e[14]*i[8]+e[15]*i[12],e[12]*i[1]+e[13]*i[5]+e[14]*i[9]+e[15]*i[13],e[12]*i[2]+e[13]*i[6]+e[14]*i[10]+e[15]*i[14],e[12]*i[3]+e[13]*i[7]+e[14]*i[11]+e[15]*i[15]])},n.prepend=function(t){return t.prod(this)},n.append=function(t){return this.prod(t)},n.apply=function(t){var n=this._array;return new y(n[0]*t.x+n[1]*t.y+n[2]*t.z+n[3],n[4]*t.x+n[5]*t.y+n[6]*t.z+n[7],n[8]*t.x+n[9]*t.y+n[10]*t.z+n[11])},d(t,[{key:"array",get:function(){return[].concat(this._array)}}]),t}(),M=function(){function n(t,n){var e=this;this.up=y.UP,this.front=y.FRONT,this.orientation="horizontal",this._abortController=new AbortController,this._animationsRunning=0,this.defaultPreviewHorizontalPosition=new y(0,1,2).normalized().prod(5),this.defaultPreviewVerticalPosition=new y(0,0,5),this._position=y.ZERO,this.defaultPreviewHorizontalRotation=w.forDirection(new y(0,-1,-2).normalized()),this.defaultPreviewVerticalRotation=w.forXRotation(-Math.PI/2),this._rotation=w.IDENTITY,this._sdk=null,this._platform=null,this._lookAt=null,this._eventListeners={},this.update=E(function(){e._update()}),this._sdk=t,this._platform=n,this._onSceneLoadEnd=this._onSceneLoadEnd.bind(this),this._registerSDKEvents(),this.reset()}var e=n.prototype;return e._registerSDKEvents=function(){this._sdk.subscribe("SCENE_LOAD_END",this._onSceneLoadEnd),"AR"===this._platform&&this._sdk.subscribe("ON_POSE",this._onPose.bind(this))},e._onSceneLoadEnd=function(t){if("AR"!==this._platform){if(this.orientation!==t.orientation){switch(this.orientation=t.orientation,this.orientation){case"horizontal":this.up=y.UP,this.front=y.FRONT;break;case"vertical":this.up=y.FRONT,this.front=y.DOWN}this._triggerEvent(n.events.ORIENTATION_CHANGE,[this.orientation])}}else{var e=t.transform.position,i=t.transform.quaternion,o=new y(e.x,e.y,e.z),r=new w(i.x,i.y,i.z,i.w);this._sceneTransformMatrix=P.fromRotationTranslation(r,o)}this.reset()},e._onPose=function(t){var n=new y(t.position.x,t.position.y,t.position.z),e=new w(t.quaternion.x,t.quaternion.y,t.quaternion.z,t.quaternion.w);this._poseTransformMatrix=P.fromRotationTranslation(e,n)},e.dispose=function(){this._triggerEvent(n.events.DISPOSE),this._unregisterSDKEvents()},e._unregisterSDKEvents=function(){this._sdk.unsubscribe("SCENE_LOAD_END",this._onSceneLoadEnd),"AR"===this._platform&&this._sdk.unsubscribe("ON_POSE",this._onPose)},e.reset=function(){if(this._sdk.disableCameraControls(),this.abortAnimations(),"AR"!==this._platform)switch(this.orientation){case"horizontal":this.position=this.defaultPreviewHorizontalPosition,this.rotation=this.defaultPreviewHorizontalRotation;break;case"vertical":this.position=this.defaultPreviewVerticalPosition,this.rotation=this.defaultPreviewVerticalRotation}else this.position=y.ZERO,this.rotation=w.IDENTITY;this.update(),this._triggerEvent(n.events.POSITION_CHANGE,[this.position]),this._triggerEvent(n.events.ROTATION_CHANGE,[this.rotation]),this._triggerEvent(n.events.RESET)},e._triggerEvent=function(t,n){if(void 0===n&&(n=[]),t in this._eventListeners)for(var e,i=function(t,n){var e="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(e)return(e=e.call(t)).next.bind(e);if(Array.isArray(t)||(e=function(t,n){if(t){if("string"==typeof t)return _(t,n);var e=Object.prototype.toString.call(t).slice(8,-1);return"Object"===e&&t.constructor&&(e=t.constructor.name),"Map"===e||"Set"===e?Array.from(t):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?_(t,n):void 0}}(t))){e&&(t=e);var i=0;return function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(this._eventListeners[t]);!(e=i()).done;)e.value.apply(void 0,n)},e.addEventListener=function(t,e){-1!==Object.values(n.events).indexOf(t)&&(t in this._eventListeners||(this._eventListeners[t]=[]),this._eventListeners[t].push(e))},e.removeEventListener=function(t,e){if(-1!==Object.values(n.events).indexOf(t)&&t in this._eventListeners){var i=this._eventListeners[t].indexOf(e);-1!==i&&this._eventListeners[t].splice(i,1)}},e._update=function(){var t=P.translate(this._position),n=P.rotate(this._rotation),e=P.sequence(n,t);this._sdk.setCameraRigTransform(e.array)},e.startAnimation=function(){this._animationsRunning=this._animationsRunning+1},e.stopAnimation=function(){this._animationsRunning=this._animationsRunning-1},e.abortAnimations=function(){this._abortController.abort(),this._abortController=new AbortController},e.translateTo=function(e,i,o,r){void 0===i&&(i=0),void 0===o&&(o=t),void 0===r&&(r=g);try{var s=this;if(s._position.equals(e))return Promise.resolve();var a=r(s._position,e,s.up);return s.startAnimation(),Promise.resolve(x(function(t){var e=o(t),i=a(e);s._position=i,s._update(),s._triggerEvent(n.events.POSITION_CHANGE,[i])},i,s.abortSignal)).then(function(){s.stopAnimation()})}catch(t){return Promise.reject(t)}},e.rotateTo=function(e,i,o,r){void 0===i&&(i=0),void 0===o&&(o=t),void 0===r&&(r=b);try{var s=this;if(s._rotation.equals(e))return Promise.resolve();var a=r(s._rotation,e,s.up);return s.startAnimation(),Promise.resolve(x(function(t){var e=o(t),i=a(e);s._rotation=i,s._update(),s._triggerEvent(n.events.ROTATION_CHANGE,[i])},i,s.abortSignal)).then(function(){s.stopAnimation()})}catch(t){return Promise.reject(t)}},e.lookAt=function(n,e,i,o){void 0===e&&(e=0),void 0===i&&(i=t),void 0===o&&(o=b);var r=n.sub(this._position);if(!r.equals(y.ZERO)){var s=w.forDirection(r,this.front,this.up);return this.rotateTo(s,e,i,o)}},e.animateTo=function(e,i,o,r,s,a,h){void 0===e&&(e=void 0),void 0===i&&(i=void 0),void 0===o&&(o=0),void 0===r&&(r=t),void 0===s&&(s=b),void 0===a&&(a=b),void 0===h&&(h="local");try{var u=this;if(void 0===e&&(e=u.position),void 0===i){var c=u._poseTransformMatrix?u._poseTransformMatrix.getPosition():u.position,l=e.sub(c).normalized();i=e.add(l),u._lookAt=i}var f=e,d=i;"local"===h&&u._sceneTransformMatrix&&(f=u._sceneTransformMatrix.apply(e),d=u._sceneTransformMatrix.apply(i));var _,v,m=d.sub(f),p=w.forDirection(m,u.front,u.up);if(u._poseTransformMatrix){var y=P.fromRotationTranslation(p,f),g=w.extractYaw(y.getQuaternion()),E=w.extractYaw(u._poseTransformMatrix.getQuaternion()),z=w.forYRotation(g-E),T=z.apply(u._poseTransformMatrix.getPosition()),M=y.getPosition().sub(T);_=s(u._position,M),v=a(u._rotation,z)}else _=s(u._position,f),v=a(u._rotation,p);return u.startAnimation(),Promise.resolve(x(function(t){var e=r(t),i=_(e);u._position=i,u._triggerEvent(n.events.POSITION_CHANGE,[i]);var o=v(e);u._rotation=o,u._triggerEvent(n.events.ROTATION_CHANGE,[o]),u._update()},o)).then(function(){u.stopAnimation()})}catch(t){return Promise.reject(t)}},d(n,[{key:"abortSignal",get:function(){return this._abortController.signal}},{key:"isAnimating",get:function(){return this._animationsRunning>0}},{key:"position",get:function(){return this._position},set:function(t){this._position=t,this._triggerEvent(n.events.POSITION_CHANGE,[t]),this.update()}},{key:"rotation",get:function(){return this._rotation},set:function(t){this._rotation=t,this._triggerEvent(n.events.ROTATION_CHANGE,[t]),this.update()}}]),n}();M.events={POSITION_CHANGE:"positionchange",ROTATION_CHANGE:"rotationchange",ORIENTATION_CHANGE:"orientationchange",RESET:"reset",DISPOSE:"dispose"};var O=function(){function n(t,n,e){var i=this;void 0===n&&(n=!1),void 0===e&&(e=document.querySelector("canvas")),this._camera=null,this._eventTarget=null,this._locked=!1,this.allowPan=!0,this.allowRotation=!0,this.allowZoom=!0,this.primaryAxis=y.UP,this.secondaryAxis=y.RIGHT,this._target=y.ZERO,this.defaultPan=y.ZERO,this._pan=this.defaultPan,this.panSpeed=new y(-2/Math.min(window.innerWidth,window.innerHeight),2/Math.min(window.innerWidth,window.innerHeight),0),this.minPan=new y(-Infinity,-Infinity,-Infinity),this.maxPan=new y(Infinity,Infinity,Infinity),this.defaultHorizontalRotation=w.forDirection(new y(0,-1,-2).normalized()),this.defaultVerticalRotation=w.forXRotation(-Math.PI/2),this._rotation=this.defaultHorizontalRotation,this.rotationSpeed=new y(Math.PI/(2*Math.min(window.innerWidth,window.innerHeight)),Math.PI/(2*Math.min(window.innerWidth,window.innerHeight)),0),this.minRotation=new y(-Infinity,-Infinity,-Infinity),this.maxRotation=new y(Infinity,Infinity,Infinity),this.defaultZoom=5,this._zoom=this.defaultZoom,this.zoomSpeed=.002,this.mouseWheelStep=10,this.minZoom=p,this.maxZoom=10,this._state=null,this._lastPointerPosition=null,this._lastTouchDistance=null,this.update=E(function(){i._update()}),this._camera=t,this._eventTarget=e,this._onOrientationChange=this._onOrientationChange.bind(this),this._onCameraUpdated=this._onCameraUpdated.bind(this),this.reset=this.reset.bind(this),this.dispose=this.dispose.bind(this),this._onTouchStart=this._onTouchStart.bind(this),this._onTouchMove=this._onTouchMove.bind(this),this._onTouchEnd=this._onTouchEnd.bind(this),this._onMouseDown=this._onMouseDown.bind(this),this._onMouseMove=this._onMouseMove.bind(this),this._onMouseUp=this._onMouseUp.bind(this),this._onMouseLeave=this._onMouseLeave.bind(this),this._onWheel=this._onWheel.bind(this),this._onContextMenu=this._onContextMenu.bind(this),this._registerCameraEvents(),this._registerDOMEvents(),this._onOrientationChange(this._camera.orientation),n?this.reset():this._onCameraUpdated()}var e=n.prototype;return e._registerCameraEvents=function(){this._camera.addEventListener(M.events.ORIENTATION_CHANGE,this._onOrientationChange),this._camera.addEventListener(M.events.POSITION_CHANGE,this._onCameraUpdated),this._camera.addEventListener(M.events.ROTATION_CHANGE,this._onCameraUpdated),this._camera.addEventListener(M.events.RESET,this.reset),this._camera.addEventListener(M.events.DISPOSE,this.dispose)},e._onOrientationChange=function(t){var n=this._camera.up.cross(this._camera.front.negate());switch(t){case"horizontal":this.primaryAxis=this._camera.up,this.secondaryAxis=n;break;case"vertical":this.primaryAxis=this._camera.front,this.secondaryAxis=n}},e._onCameraUpdated=function(){var t=this._camera.rotation,n=t.apply(this._camera.front).normalized(),e=new y(Math.abs(n.x)<p?0:n.x,Math.abs(n.y)<p?0:n.y,Math.abs(n.z)<p?0:n.z),i=this._camera.position.sub(this._target),o=i.div(e),r=Math.max(Number.isFinite(o.x)?-o.x:p,Number.isFinite(o.y)?-o.y:p,Number.isFinite(o.z)?-o.z:p);Number.isFinite(r)||(r=p);var s=i.sub(e.prod(-r));this._rotation=t,this._zoom=r,this._pan=s},e._registerDOMEvents=function(){this._eventTarget.addEventListener("touchstart",this._onTouchStart,{capture:!0,passive:!1}),this._eventTarget.addEventListener("touchmove",this._onTouchMove,{capture:!0,passive:!1}),this._eventTarget.addEventListener("touchend",this._onTouchEnd,{capture:!0,passive:!1}),this._eventTarget.addEventListener("mousedown",this._onMouseDown,{capture:!0,passive:!1}),this._eventTarget.addEventListener("mousemove",this._onMouseMove,{capture:!0,passive:!1}),this._eventTarget.addEventListener("mouseup",this._onMouseUp,{capture:!0,passive:!1}),this._eventTarget.addEventListener("mouseleave",this._onMouseLeave,{capture:!0,passive:!1}),this._eventTarget.addEventListener("wheel",this._onWheel,{capture:!0,passive:!1}),this._eventTarget.addEventListener("contextmenu",this._onContextMenu)},e._onContextMenu=function(t){t.preventDefault()},e.dispose=function(){this._unregisterCameraEvents(),this._unregisterDOMEvents()},e._unregisterCameraEvents=function(){this._camera.removeEventListener(M.events.ORIENTATION_CHANGE,this._onOrientationChange),this._camera.removeEventListener(M.events.POSITION_CHANGE,this._onCameraUpdated),this._camera.removeEventListener(M.events.ROTATION_CHANGE,this._onCameraUpdated),this._camera.removeEventListener(M.events.RESET,this.reset),this._camera.removeEventListener(M.events.DISPOSE,this.dispose)},e._unregisterDOMEvents=function(){this._eventTarget.removeEventListener("touchstart",this._onTouchStart,!0),this._eventTarget.removeEventListener("touchmove",this._onTouchMove,!0),this._eventTarget.removeEventListener("touchend",this._onTouchEnd,!0),this._eventTarget.removeEventListener("mousedown",this._onMouseDown,!0),this._eventTarget.removeEventListener("mousemove",this._onMouseMove,!0),this._eventTarget.removeEventListener("mouseup",this._onMouseUp,!0),this._eventTarget.removeEventListener("mouseleave",this._onMouseLeave,!0),this._eventTarget.removeEventListener("wheel",this._onWheel,!0),this._eventTarget.removeEventListener("contextmenu",this._onContextMenu)},e._onTouchStart=function(t){if(!this.locked)if(1===t.touches.length)this._state="rotate",this._lastPointerPosition=new y(t.touches[0].screenX,t.touches[0].screenY,0);else if(2===t.touches.length){this._state="pan + zoom";var n=new y(t.touches[0].screenX,t.touches[0].screenY,0),e=new y(t.touches[1].screenX,t.touches[1].screenY,0);this._lastPointerPosition=n.add(e).div(2),this._lastTouchDistance=n.distance(e)}},e._onTouchMove=function(t){if(t.preventDefault(),!this.locked)if("rotate"===this._state&&t.touches.length>=1){var n=new y(t.touches[0].screenX,t.touches[0].screenY,0),e=n.sub(this._lastPointerPosition);this._doRotate(e),this._lastPointerPosition=n}else if("pan + zoom"===this._state&&t.touches.length>=2){var i=new y(t.touches[0].screenX,t.touches[0].screenY,0),o=new y(t.touches[1].screenX,t.touches[1].screenY,0),r=i.add(o).div(2),s=r.sub(this._lastPointerPosition);this._doPan(s);var a=i.distance(o);this._doZoom(this._lastTouchDistance-a),this._lastPointerPosition=r,this._lastTouchDistance=a}},e._onTouchEnd=function(t){this.locked||1===t.touches.length&&(this._state=null,this._lastPointerPosition=null,this._lastTouchDistance=null)},e._onMouseDown=function(t){this.locked||(1&t.buttons?this._state="rotate":6&t.buttons&&(this._state="pan"),this._state&&(this._lastPointerPosition=new y(t.screenX,t.screenY,0)))},e._onMouseMove=function(t){if(t.preventDefault(),!this.locked){var n=new y(t.screenX,t.screenY,0);if(this._state){var e=n.sub(this._lastPointerPosition);"rotate"===this._state?this._doRotate(e):"pan"===this._state&&this._doPan(e)}this._state=1&t.buttons?"rotate":6&t.buttons?"pan":null,this._lastPointerPosition=this._state?n:null}},e._onMouseUp=function(t){if(!this.locked){if(this._state){var n=new y(t.screenX,t.screenY,0).sub(this._lastPointerPosition);"rotate"===this._state?this._doRotate(n):"pan"===this._state&&this._doPan(n)}this._state=null,this._lastPointerPosition=null}},e._onMouseLeave=function(){this.locked||(this._state=null,this._lastPointerPosition=null)},e._onWheel=function(t){if(t.preventDefault(),!this.locked)if(t.wheelDeltaY?t.wheelDeltaY===-3*t.deltaY:0===t.deltaMode)this._doZoom(t.deltaY);else{var n=Math.sign(t.deltaY);this._doZoom(n*this.mouseWheelStep)}},e._doRotate=function(t){if(this.allowRotation){var n=this.rotationSpeed.negate().prod(t),e=w.sequence(w.forRotationAroundAxis(this.primaryAxis,n.x),this._rotation,w.forRotationAroundAxis(this.secondaryAxis,n.y));this._isValidRotation(e)&&(this._rotation=e,this.update())}},e._isValidRotation=function(t){var n=this._camera.up.cross(this._camera.front.negate()),e=Math.abs(t.apply(y.X).angle(n)),i=Math.abs(t.apply(y.Y).angle(this._camera.up)),o=Math.abs(t.apply(y.Z).angle(this._camera.front.negate()));return!(e<this.minRotation.x||e>this.maxRotation.x||i<this.minRotation.y||i>this.maxRotation.y||o<this.minRotation.z||o>this.maxRotation.z)},e._doPan=function(t){if(this.allowPan){var n=this._rotation.apply(t.prod(this.panSpeed));this._pan=this._pan.add(n).clamp(this.minPan,this.maxPan),this.update()}},e._doZoom=function(t){this.allowZoom&&(this._zoom=Math.max(Math.min(this._zoom+this.zoomSpeed*t,this.maxZoom),this.minZoom),this.update())},e.reset=function(){switch(this._camera.abortAnimations(),this._pan=this.defaultPan,this._camera.orientation){case"horizontal":this._rotation=this.defaultHorizontalRotation;break;case"vertical":this._rotation=this.defaultVerticalRotation}this._zoom=this.defaultZoom,this.update()},e._update=function(){var t=this._rotation.apply(this._camera.front);this._camera._position=this._pan.add(this._target).add(t.prod(-this._zoom)),this._camera._rotation=this._rotation,this._camera._update()},e.zoomTo=function(n,e,i,o){void 0===e&&(e=0),void 0===i&&(i=t),void 0===o&&(o=g);try{var r=this;if(Math.abs(r._zoom-n)<p)return Promise.resolve();var s=o(r._zoom,n,r.up);return r._camera.startAnimation(),Promise.resolve(x(function(t){var n=i(t);r._zoom=s(n),r._update()},e,r._camera.abortSignal)).then(function(){r._camera.stopAnimation()})}catch(t){return Promise.reject(t)}},e.panTo=function(n,e,i,o){void 0===e&&(e=0),void 0===i&&(i=t),void 0===o&&(o=g);try{var r=this;if(r._pan.equals(n))return Promise.resolve();var s=o(r._pan,n,r.up);return r._camera.startAnimation(),Promise.resolve(x(function(t){var n=i(t);r._pan=s(n),r._update()},e,r._camera.abortSignal)).then(function(){r._camera.stopAnimation()})}catch(t){return Promise.reject(t)}},e.targetTo=function(n,e,i,o){void 0===e&&(e=0),void 0===i&&(i=t),void 0===o&&(o=g);try{var r=this;if(r._target.equals(n))return Promise.resolve();var s=o(r._target,n,r.up);return r._camera.startAnimation(),Promise.resolve(x(function(t){var n=i(t);r._target=s(n),r._update()},e,r._camera.abortSignal)).then(function(){r._camera.stopAnimation()})}catch(t){return Promise.reject(t)}},e.rotateTo=function(n,e,i,o){void 0===e&&(e=0),void 0===i&&(i=t),void 0===o&&(o=b);try{var r=this;if(r._rotation.equals(n))return Promise.resolve();var s=o(r._rotation,n,r.up);return r._camera.startAnimation(),Promise.resolve(x(function(t){var n=i(t);r._rotation=s(n),r._update()},e,r._camera.abortSignal)).then(function(){r._camera.stopAnimation()})}catch(t){return Promise.reject(t)}},d(n,[{key:"locked",get:function(){return this._camera.isAnimating||this._locked},set:function(t){this._locked=t}},{key:"target",get:function(){return this._target},set:function(t){this._target=t,this.update()}},{key:"pan",get:function(){return this._pan},set:function(t){this._pan=t,this.update()}},{key:"rotation",get:function(){return this._rotation},set:function(t){this._rotation=t,this.update()}},{key:"zoom",get:function(){return this._zoom},set:function(t){this._zoom=t,this.update()}}]),n}(),R={__proto__:null,Matrix4:P,Quaternion:w,EPSILON:p,Vector3:y},A=function(){function t(t,n){void 0===n&&(n=["PREVIEW"]),this._sdk=null,this._enabledPlatforms=["PREVIEW"],this._currentPlatform=null,this._enabled=!1,this.camera=null,this.controls=null,this._sdk=t,document.querySelector(".ox-webar-renderer--preview")&&(this._currentPlatform="PREVIEW"),document.querySelector(".ox-webar-renderer--ar")&&(this._currentPlatform="AR"),this._enabled=-1!==n.indexOf(this._currentPlatform),this._enabled&&(this.camera=new M(this._sdk,this._currentPlatform))}var n=t.prototype;return n.getEasingByName=function(n){if(n in t.easings)return t.easings[n];var e=JSON.stringify(Object.keys(t.easings));throw new Error("Invalid easing function. Expected one of "+e+", got '"+n+"'.")},n.getInterpolatorByName=function(n){if(n in t.interpolators)return t.interpolators[n];var e=JSON.stringify(Object.keys(t.interpoators));throw new Error("Invalid interpolator function. Expected one of "+e+", got '"+n+"'.")},n.parseMode=function(t){if(!t)return{};var n,e,i=t.split(" ");if(1===i.length)i[0].includes("-in")||i[0].includes("-out")?n=this.getEasingByName(i[0]):e=this.getInterpolatorByName(i[0]);else{if(2!==i.length)throw new Error("Invalid mode format. Expected '<transition> <easing>', '<easing>', or <transition>', got '"+mode+"'.");e=this.getInterpolatorByName(i[0]),n=this.getEasingByName(i[1])}return{interpolator:e,easing:n}},n.disableControls=function(){this._enabled&&this.controls&&(this.controls.dispose(),this.controls=null)},n.animateTo=function(t,n,e,i,o,r,s,a,h,u,c){void 0===s&&(s="linear linear-in-out"),void 0===a&&(a=0),void 0===h&&(h=void 0),void 0===u&&(u=void 0),void 0===c&&(c=void 0);try{var l=this;if(!l._enabled)return Promise.resolve();var f=void 0;null!=t&&null!=n&&null!=e&&(f=new y(t,n,e));var d=void 0;null!=i&&null!=o&&null!=r&&(d=new y(i,o,r));var _,v=l.parseMode(s),m=v.easing,w=v.interpolator,g=w,x=w;return g===b&&(null!=h&&null!=u&&null!=c?g=b(new y(h,u,c)):null!=(_=l.controls)&&_.target&&(g=b(l.controls.target))),Promise.resolve(l.camera.animateTo(f,d,1e3*a,m,g,x)).then(function(){var t,n;null!=l.controls&&(l.controls.target=null!=(t=d)?t:l.camera._lookAt,l.controls.pan=y.ZERO,l.controls.zoom=Math.max((null!=(n=d)?n:l.camera._lookAt).sub(f).abs(),p))})}catch(t){return Promise.reject(t)}},n.enableOrbitControls=function(){this._enabled&&"AR"!==this._currentPlatform&&(this.controls&&this.controls.dispose(),this.controls=new O(this.camera))},n.setOrbitControlsPanRange=function(t,n,e,i,o,r){if(this._enabled){if(!this.controls)throw new Error("The camera controls are currently disabled.");if(!(this.controls instanceof O))throw new Error("The camera controls are not orbit controls.");this.controls.minPan=new y(t,e,o),this.controls.maxPan=new y(n,i,r)}},n.setOrbitControlsRotateRange=function(t,n,e,i,o,r){if(this._enabled){if(!this.controls)throw new Error("The camera controls are currently disabled.");if(!(this.controls instanceof O))throw new Error("The camera controls are not orbit controls.");this.controls.minRotation=new y(t,e,o),this.controls.maxRotation=new y(n,i,r)}},n.setOrbitControlsZoomRange=function(t,n){if(this._enabled){if(!this.controls)throw new Error("The camera controls are currently disabled.");if(!(this.controls instanceof O))throw new Error("The camera controls are not orbit controls.");this.controls.minZoom=t,this.controls.maxZoom=n}},n.setOrbitControlsTarget=function(t,n,e){if(this._enabled){if(!this.controls)throw new Error("The camera controls are currently disabled.");if(!(this.controls instanceof O))throw new Error("The camera controls are not orbit controls.");this.controls.target=new y(t,n,e)}},t}();return A.animation=T,A.math=R,A.Camera=M,A.OrbitControls=O,A.easings={"linear-in-out":t,"ease-in":n,"ease-out":e,"ease-in-out":i,"bounce-in":o,"bounce-out":r,"bounce-in-out":s},A.interpolators={linear:g,spherical:b},A});