@galacean/effects-plugin-orientation-transformer 2.1.0-alpha.5 → 2.1.0-alpha.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/alipay.js CHANGED
@@ -790,7 +790,7 @@ exports.OrientationComponent = __decorate([
790
790
  ], exports.OrientationComponent);
791
791
 
792
792
  EFFECTS.registerPlugin("orientation-transformer", OrientationPluginLoader, EFFECTS.VFXItem);
793
- var version = "2.1.0-alpha.5";
793
+ var version = "2.1.0-alpha.7";
794
794
  EFFECTS.logger.info("Plugin orientation transformer version: " + version + ".");
795
795
  if (version !== EFFECTS__namespace.version) {
796
796
  console.error("注意:请统一 Orientation Transformer 插件与 Player 版本,不统一的版本混用会有不可预知的后果!", "\nAttention: Please ensure the Orientation Transformer plugin is synchronized with the Player version. Mixing and matching incompatible versions may result in unpredictable consequences!");
package/dist/alipay.mjs CHANGED
@@ -767,7 +767,7 @@ OrientationComponent = __decorate([
767
767
  ], OrientationComponent);
768
768
 
769
769
  registerPlugin("orientation-transformer", OrientationPluginLoader, VFXItem);
770
- var version = "2.1.0-alpha.5";
770
+ var version = "2.1.0-alpha.7";
771
771
  logger.info("Plugin orientation transformer version: " + version + ".");
772
772
  if (version !== EFFECTS.version) {
773
773
  console.error("注意:请统一 Orientation Transformer 插件与 Player 版本,不统一的版本混用会有不可预知的后果!", "\nAttention: Please ensure the Orientation Transformer plugin is synchronized with the Player version. Mixing and matching incompatible versions may result in unpredictable consequences!");
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  * Description: Galacean Effects player orientation transformer plugin
4
4
  * Author: Ant Group CO., Ltd.
5
5
  * Contributors: 燃然,意绮
6
- * Version: v2.1.0-alpha.5
6
+ * Version: v2.1.0-alpha.7
7
7
  */
8
8
 
9
9
  'use strict';
@@ -797,7 +797,7 @@ exports.OrientationComponent = __decorate([
797
797
  ], exports.OrientationComponent);
798
798
 
799
799
  EFFECTS.registerPlugin("orientation-transformer", OrientationPluginLoader, EFFECTS.VFXItem);
800
- var version = "2.1.0-alpha.5";
800
+ var version = "2.1.0-alpha.7";
801
801
  EFFECTS.logger.info("Plugin orientation transformer version: " + version + ".");
802
802
  if (version !== EFFECTS__namespace.version) {
803
803
  console.error("注意:请统一 Orientation Transformer 插件与 Player 版本,不统一的版本混用会有不可预知的后果!", "\nAttention: Please ensure the Orientation Transformer plugin is synchronized with the Player version. Mixing and matching incompatible versions may result in unpredictable consequences!");
package/dist/index.min.js CHANGED
@@ -3,6 +3,6 @@
3
3
  * Description: Galacean Effects player orientation transformer plugin
4
4
  * Author: Ant Group CO., Ltd.
5
5
  * Contributors: 燃然,意绮
6
- * Version: v2.1.0-alpha.5
7
- */function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@galacean/effects")):"function"==typeof define&&define.amd?define(["exports","@galacean/effects"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).ge=t.ge||{},t.ge.orientationTransformerPlugin={}),t.ge)}(this,function(t,e){"use strict";var n,a=function(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach(function(n){if("default"!==n){var a=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,a.get?a:{enumerable:!0,get:function(){return t[n]}})}}),e.default=t,Object.freeze(e)}(e);function i(t,e){return(i=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function r(t,e){if("function"!=typeof e&&null!==e)throw TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&i(t,e)}var o=function(){function t(t){this.composition=t,this.targets={},this.records={},this.currentPos={},this.currentRot={},this.gammaRange=[-89,89],this.betaRange=[-89,89]}var e=t.prototype;return e.update=function(t){var e=t.x,n=t.y,a=t.beta,i=t.gamma;this.currentEvent={x:e,y:n,beta:a,gamma:i}},e.updateOrientation=function(){var t=this,e=this.currentEvent;e&&Object.getOwnPropertyNames(this.targets).forEach(function(n){t.moveLayer(n,e)})},e.initComposition=function(){for(var t=this.composition.items,e=0;e<t.length;e++){var n=t[e];if(this.targets[n.name]){var a=n.transform.position.toArray(),i=n.transform.rotation.toArray(),r=this.currentPos[n.name],o=this.currentRot[n.name];this.records[n.name]={item:n,position:a,rotation:i},r&&n.transform.setPosition(r[0],r[1],r[2]),o&&n.transform.setRotation(o[0],o[1],o[2])}}},e.addTarget=function(t){this.targets[t.name]=t},e.removeTarget=function(t){delete this.targets[t],delete this.records[t]},e.moveLayer=function(t,e){var n=e.x,a=e.y,i=e.beta,r=e.gamma,o=null==(L=this.records[t])?void 0:L.item;if(o){var c=this.records[t].position,l=this.records[t].rotation,u=this.targets[t],h=s(n,this.betaRange),f=s(a,this.gammaRange);if(u){var m,d,p,v,g,b,y,M,w,R,x,O,L,E,A,P=[c[0]+1.2*(d=(h-(m=this.gammaRange[0]))/(this.gammaRange[1]-m),(p=u.xMin)+(u.xMax-p)*d),c[1]+1.2*(g=(f-(v=this.betaRange[0]))/(this.betaRange[1]-v),(b=u.yMin)+(u.yMax-b)*g),c[2]],D=(y=s(.8*r,this.gammaRange),(y-(M=this.gammaRange[0]))/(this.gammaRange[1]-M)),T=(w=s(.8*i,this.betaRange),(w-(R=this.betaRange[0]))/(this.betaRange[1]-R)),C=[l[0]+((x=u.hMin)+(u.hMax-x)*T),l[1]+((O=u.vMin)+(u.vMax-O)*D),l[2]];(E=o.transform).setPosition.apply(E,[].concat(P)),(A=o.transform).setRotation.apply(A,[].concat(C)),this.currentPos[t]=P.slice(),this.currentRot[t]=C.slice()}}},t}();function s(t,e){return t<e[0]?e[0]:t>e[1]?e[1]:t}function c(){return(c=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(t[a]=n[a])}return t}).apply(this,arguments)}function l(t,n){var a=!0,i=!0,r=!0;if(e.isArray(n.alpha)&&n.alpha.length>=2){var o=t.alpha+n.alpha[0],s=t.alpha+n.alpha[1];a=(o=o<0?o+360:o)<(s=s>360?s-360:s)?t.alpha>o&&t.alpha<s:t.alpha>o||t.alpha<s}return e.isArray(n.beta)&&n.beta.length>=2&&(i=t.beta>=n.beta[0]&&t.beta<=n.beta[1]),e.isArray(n.gamma)&&n.gamma.length>=2&&(r=t.gamma>=n.gamma[0]&&t.gamma<=n.gamma[1]),a&&i&&r}var u=function(){function t(t){void 0===t&&(t={}),this.options=t,this.lastValue=0,this.valuePool=[]}var e=t.prototype;return e.stableFix=function(t){var e=this.options.stableRange||3;return Math.abs(t)<e?0:t>e?t-e:t+e},e.changeLimit=function(t){var e=this.lastValue,n=t;return Math.abs(t-e)>5&&(n=e<t?e+5:e-5),1>Math.abs(t-e)&&(n=e),this.lastValue=n,n},e.linearRegressionMedian=function(t){var e,n,a;return this.valuePool.push(t),this.valuePool.length>=5?(a=function(t){var e=[],n=[];t.forEach(function(t,a){e.push(a),n.push(t)});var a=function(t,e){for(var n={},a=e.length,i=0,r=0,o=0,s=0,c=0,l=0;l<e.length;l++)i+=t[l],r+=e[l],o+=t[l]*e[l],s+=t[l]*t[l],c+=e[l]*e[l];var u=i/a,h=r/a;return n.a=(o-a*u*h)/(s-a*u*u),n.b=h-n.a*u,n.miss=Math.pow((a*o-i*r)/Math.sqrt((a*s-i*i)*(a*c-r*r)),2),n}(e,n);return function(t){return a.a*t+a.b}}(n=this.valuePool),n=n.map(function(t,e){return a(e)}),e=a(n.length/2),this.valuePool.shift()):e=this.lastValue,e},t}(),h=e.isIOSByUA()&&void 0!==window.AlipayJSBridge,f=void 0!==window.WindVane,m={X:!0,Y:!0,interval:Math.floor(1e3/30),useRequestAnimationFrame:!0,relativeBeta:!1,relativeGamma:!1,validRange:{alpha:[-60,60],beta:[-60,180],gamma:[-89,89]},stableRange:3},d=function(){function t(t){void 0===t&&(t={}),this.lastX=0,this.lastY=0,this.prevAcceler={x:0,y:0,z:0},this.stoped=!1;var e=c({},m.validRange,t.validRange),n=c({},m,t);n.validRange=e,this.options=n;var a=this.options.stableRange;this.filterX=new u({stableRange:a}),this.filterY=new u({stableRange:a})}var n=t.prototype;return n.watch=function(t){var n,a,i,r,o,s,c=this;if("function"==typeof t&&!this.watchListener){var u=0,m=0,d=NaN,g=NaN,b=function(e){!c.stoped&&(n=e.alpha||0,a=e.beta||0,i=e.gamma||0,r=l.call(c,{alpha:n,beta:a,gamma:i},c.options.validRange),isNaN(d)&&(d=i,c.filterX.lastValue=i),isNaN(g)&&(g=a,c.filterY.lastValue=a),r&&(c.options.X?(o=c.options.relativeGamma?i-d:i,o=c.filterX.stableFix(o),o=c.filterX.changeLimit(o),o=c.filterX.linearRegressionMedian(+o)):o=0,c.options.Y?(s=c.options.relativeBeta?a-g:a,s=c.filterY.stableFix(s),s=c.filterY.changeLimit(s),s=c.filterY.linearRegressionMedian(+s)):s=0,c.isValid(o,s)&&(c.options.useRequestAnimationFrame?window.requestAnimationFrame(function(){t(o,s,{alpha:n,beta:s-g,gamma:o-d})}):t(o,s,{alpha:n,beta:s-g,gamma:o-d}),c.lastX=o,c.lastY=s)))};this.stoped=!1,f?(v(!0,this.options.interval),this.watchListener=function(t){if("param"in t){var e=t.param,n=e.x,a=e.y,i=e.z;(n!==c.prevAcceler.x||a!==c.prevAcceler.y||i!==c.prevAcceler.z)&&(c.prevAcceler={x:n,y:a,z:i},b({alpha:180*+i,beta:-90*+a,gamma:90*+n}))}},document.addEventListener("motion.gyro",this.watchListener,!1)):h&&!e.isMiniProgram()?(p(!0,this.options.interval/1e3),this.watchListener=function(t){if(t&&"data"in t){var e=t.data,n=e.x,a=e.y;b({alpha:180*e.z,beta:-90*a,gamma:90*n})}},document.addEventListener("accelerometerChange",this.watchListener,!1)):(this.watchListener=function(t){(m=new Date().getTime())-u>=c.options.interval&&(u=m,b(t))},window.addEventListener("deviceorientation",this.watchListener,!1))}},n.unWatch=function(){e.assertExist(this.watchListener),f?(v(!1),document.removeEventListener("motion.gyro",this.watchListener)):h?(p(!1),document.removeEventListener("accelerometerChange",this.watchListener)):window.removeEventListener("deviceorientation",this.watchListener),this.stoped=!0,this.watchListener=void 0},n.pause=function(){this.stoped=!0,h&&p(!1)},n.continue=function(){this.stoped=!1,h&&p(!0,this.options.interval/1e3)},n.isValid=function(t,e){return this.lastX!==t||this.lastY!==e},t}();function p(t,e){window.AlipayJSBridge.call("watchShake",{monitorGyroscope:!1,monitorAccelerometer:!!t,interval:t?parseFloat(e.toFixed(3)):10},function(){})}function v(t,e){window.WindVane.call("WVMotion","listenGyro",{on:t,frequency:e},function(t){console.info("Call WVMotion success.")},function(t){console.error("Call WVMotion failed: "+JSON.stringify(t)+".")})}var g=function(){function t(){this.transformers=[],this.connected=!1,this.accelerMotion=null,this.validRange={alpha:[-60,60],beta:[-80,80],gamma:[-89,89]}}var e=t.prototype;return e.connect=function(){var t=this;this.connected||(this.accelerMotion=new d({X:!0,Y:!0,interval:Math.floor(1e3/60),useRequestAnimationFrame:!0,relativeBeta:!1,relativeGamma:!1,validRange:this.validRange,stableRange:3}),this.accelerMotion.watch(function(e,n,a){var i=a.beta,r=a.gamma;t.dispatchMotion({x:e,y:n,beta:i,gamma:r})})),this.connected=!0},e.disconnect=function(){this.accelerMotion&&this.accelerMotion.unWatch(),this.connected=!1},e.dispatchMotion=function(t){this.transformers.forEach(function(e){return e.update(t)})},e.addTransformer=function(t){this.transformers.includes(t)||this.transformers.push(t)},e.removeTransformer=function(t){var e=this.transformers.indexOf(t);return e>-1&&this.transformers.splice(e,1),0===this.transformers.length},t}(),b=function(t){function e(){var e;return e=t.apply(this,arguments)||this,e.order=90,e.adapter=null,e.handleConnect=function(){if(!y){var t;null==(t=e.adapter)||t.connect()}},e.handleDisconnect=function(){var t;null==(t=e.adapter)||t.disconnect()},e}r(e,t);var n=e.prototype;return n.onCompositionConstructed=function(){var t;this.adapter=M(),null==(t=this.adapter)||t.connect(),this.bindAccelerDocumentEvent()},n.onCompositionReset=function(t){var e,n=t.loaderData.deviceTransformer=new o(t);null==(e=this.adapter)||e.addTransformer(n)},n.onCompositionUpdate=function(t){var e=t.loaderData.deviceTransformer;e&&e.updateOrientation()},n.onCompositionDestroyed=function(t){var e,n;(null==(e=this.adapter)?void 0:e.removeTransformer(t.loaderData.deviceTransformer))&&(null==(n=this.adapter)||n.disconnect())},n.bindAccelerDocumentEvent=function(){this.unbindAccelerDocumentEvent(),document.addEventListener("resume",this.handleConnect,!1),document.addEventListener("pause",this.handleDisconnect,!1),document.addEventListener("back",this.handleDisconnect,!1)},n.unbindAccelerDocumentEvent=function(){document.removeEventListener("resume",this.handleConnect),document.removeEventListener("pause",this.handleDisconnect),document.removeEventListener("back",this.handleDisconnect)},n.dispose=function(){M().disconnect(),this.unbindAccelerDocumentEvent()},e}(e.AbstractPlugin),y=!1;function M(){return n||(n=new g),n}"function"==typeof SuppressedError&&SuppressedError,t.OrientationComponent=function(t){function e(){return t.apply(this,arguments)}r(e,t);var n=e.prototype;return n.fromData=function(e){t.prototype.fromData.call(this,e);var n=e.options.targets;n&&(this.targets=n.map(function(t){return{name:t.name,xMin:+t.xMin||0,yMin:+t.yMin||0,xMax:+t.xMax||0,yMax:+t.yMax||0,vMin:+t.vMin||0,hMin:+t.hMin||0,vMax:+t.vMax||0,hMax:+t.hMax||0}}))},n.onStart=function(){var t,e,n=null==(t=this.item.composition)?void 0:t.loaderData.deviceTransformer;n&&(null==(e=this.targets)||e.forEach(function(t){return n.addTarget(t)}),n.initComposition())},n.onUpdate=function(t){var e,n=null==(e=this.item.composition)?void 0:e.loaderData.deviceTransformer;n&&n.updateOrientation()},n.onDestroy=function(){var t,e=this;null==(t=this.targets)||t.forEach(function(t){var n,a;return null==(a=e.item.composition)?void 0:null==(n=a.loaderData.deviceTransformer)?void 0:n.removeTarget(t.name)})},e}(e.Behaviour),t.OrientationComponent=function(t,e,n,a){var i,r=arguments.length,o=r<3?e:null===a?a=Object.getOwnPropertyDescriptor(e,n):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,n,a);else for(var s=t.length-1;s>=0;s--)(i=t[s])&&(o=(r<3?i(o):r>3?i(e,n,o):i(e,n))||o);return r>3&&o&&Object.defineProperty(e,n,o),o}([e.effectsClass("OrientationComponent")],t.OrientationComponent),e.registerPlugin("orientation-transformer",b,e.VFXItem);var w="2.1.0-alpha.5";e.logger.info("Plugin orientation transformer version: "+w+"."),w!==a.version&&console.error("注意:请统一 Orientation Transformer 插件与 Player 版本,不统一的版本混用会有不可预知的后果!","\nAttention: Please ensure the Orientation Transformer plugin is synchronized with the Player version. Mixing and matching incompatible versions may result in unpredictable consequences!"),t.OrientationAdapterAcceler=g,t.OrientationPluginLoader=b,t.closeDeviceMotion=function(){y=!0,M().disconnect()},t.getAdapter=M,t.openDeviceMotion=function(){y=!1,M().connect()},t.version=w,Object.defineProperty(t,"__esModule",{value:!0})});
6
+ * Version: v2.1.0-alpha.7
7
+ */function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@galacean/effects")):"function"==typeof define&&define.amd?define(["exports","@galacean/effects"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).ge=t.ge||{},t.ge.orientationTransformerPlugin={}),t.ge)}(this,function(t,e){"use strict";var n,a=function(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach(function(n){if("default"!==n){var a=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,a.get?a:{enumerable:!0,get:function(){return t[n]}})}}),e.default=t,Object.freeze(e)}(e);function i(t,e){return(i=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function r(t,e){if("function"!=typeof e&&null!==e)throw TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&i(t,e)}var o=function(){function t(t){this.composition=t,this.targets={},this.records={},this.currentPos={},this.currentRot={},this.gammaRange=[-89,89],this.betaRange=[-89,89]}var e=t.prototype;return e.update=function(t){var e=t.x,n=t.y,a=t.beta,i=t.gamma;this.currentEvent={x:e,y:n,beta:a,gamma:i}},e.updateOrientation=function(){var t=this,e=this.currentEvent;e&&Object.getOwnPropertyNames(this.targets).forEach(function(n){t.moveLayer(n,e)})},e.initComposition=function(){for(var t=this.composition.items,e=0;e<t.length;e++){var n=t[e];if(this.targets[n.name]){var a=n.transform.position.toArray(),i=n.transform.rotation.toArray(),r=this.currentPos[n.name],o=this.currentRot[n.name];this.records[n.name]={item:n,position:a,rotation:i},r&&n.transform.setPosition(r[0],r[1],r[2]),o&&n.transform.setRotation(o[0],o[1],o[2])}}},e.addTarget=function(t){this.targets[t.name]=t},e.removeTarget=function(t){delete this.targets[t],delete this.records[t]},e.moveLayer=function(t,e){var n=e.x,a=e.y,i=e.beta,r=e.gamma,o=null==(L=this.records[t])?void 0:L.item;if(o){var c=this.records[t].position,l=this.records[t].rotation,u=this.targets[t],h=s(n,this.betaRange),f=s(a,this.gammaRange);if(u){var m,d,p,v,g,b,y,M,w,R,x,O,L,E,A,P=[c[0]+1.2*(d=(h-(m=this.gammaRange[0]))/(this.gammaRange[1]-m),(p=u.xMin)+(u.xMax-p)*d),c[1]+1.2*(g=(f-(v=this.betaRange[0]))/(this.betaRange[1]-v),(b=u.yMin)+(u.yMax-b)*g),c[2]],D=(y=s(.8*r,this.gammaRange),(y-(M=this.gammaRange[0]))/(this.gammaRange[1]-M)),T=(w=s(.8*i,this.betaRange),(w-(R=this.betaRange[0]))/(this.betaRange[1]-R)),C=[l[0]+((x=u.hMin)+(u.hMax-x)*T),l[1]+((O=u.vMin)+(u.vMax-O)*D),l[2]];(E=o.transform).setPosition.apply(E,[].concat(P)),(A=o.transform).setRotation.apply(A,[].concat(C)),this.currentPos[t]=P.slice(),this.currentRot[t]=C.slice()}}},t}();function s(t,e){return t<e[0]?e[0]:t>e[1]?e[1]:t}function c(){return(c=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(t[a]=n[a])}return t}).apply(this,arguments)}function l(t,n){var a=!0,i=!0,r=!0;if(e.isArray(n.alpha)&&n.alpha.length>=2){var o=t.alpha+n.alpha[0],s=t.alpha+n.alpha[1];a=(o=o<0?o+360:o)<(s=s>360?s-360:s)?t.alpha>o&&t.alpha<s:t.alpha>o||t.alpha<s}return e.isArray(n.beta)&&n.beta.length>=2&&(i=t.beta>=n.beta[0]&&t.beta<=n.beta[1]),e.isArray(n.gamma)&&n.gamma.length>=2&&(r=t.gamma>=n.gamma[0]&&t.gamma<=n.gamma[1]),a&&i&&r}var u=function(){function t(t){void 0===t&&(t={}),this.options=t,this.lastValue=0,this.valuePool=[]}var e=t.prototype;return e.stableFix=function(t){var e=this.options.stableRange||3;return Math.abs(t)<e?0:t>e?t-e:t+e},e.changeLimit=function(t){var e=this.lastValue,n=t;return Math.abs(t-e)>5&&(n=e<t?e+5:e-5),1>Math.abs(t-e)&&(n=e),this.lastValue=n,n},e.linearRegressionMedian=function(t){var e,n,a;return this.valuePool.push(t),this.valuePool.length>=5?(a=function(t){var e=[],n=[];t.forEach(function(t,a){e.push(a),n.push(t)});var a=function(t,e){for(var n={},a=e.length,i=0,r=0,o=0,s=0,c=0,l=0;l<e.length;l++)i+=t[l],r+=e[l],o+=t[l]*e[l],s+=t[l]*t[l],c+=e[l]*e[l];var u=i/a,h=r/a;return n.a=(o-a*u*h)/(s-a*u*u),n.b=h-n.a*u,n.miss=Math.pow((a*o-i*r)/Math.sqrt((a*s-i*i)*(a*c-r*r)),2),n}(e,n);return function(t){return a.a*t+a.b}}(n=this.valuePool),n=n.map(function(t,e){return a(e)}),e=a(n.length/2),this.valuePool.shift()):e=this.lastValue,e},t}(),h=e.isIOSByUA()&&void 0!==window.AlipayJSBridge,f=void 0!==window.WindVane,m={X:!0,Y:!0,interval:Math.floor(1e3/30),useRequestAnimationFrame:!0,relativeBeta:!1,relativeGamma:!1,validRange:{alpha:[-60,60],beta:[-60,180],gamma:[-89,89]},stableRange:3},d=function(){function t(t){void 0===t&&(t={}),this.lastX=0,this.lastY=0,this.prevAcceler={x:0,y:0,z:0},this.stoped=!1;var e=c({},m.validRange,t.validRange),n=c({},m,t);n.validRange=e,this.options=n;var a=this.options.stableRange;this.filterX=new u({stableRange:a}),this.filterY=new u({stableRange:a})}var n=t.prototype;return n.watch=function(t){var n,a,i,r,o,s,c=this;if("function"==typeof t&&!this.watchListener){var u=0,m=0,d=NaN,g=NaN,b=function(e){!c.stoped&&(n=e.alpha||0,a=e.beta||0,i=e.gamma||0,r=l.call(c,{alpha:n,beta:a,gamma:i},c.options.validRange),isNaN(d)&&(d=i,c.filterX.lastValue=i),isNaN(g)&&(g=a,c.filterY.lastValue=a),r&&(c.options.X?(o=c.options.relativeGamma?i-d:i,o=c.filterX.stableFix(o),o=c.filterX.changeLimit(o),o=c.filterX.linearRegressionMedian(+o)):o=0,c.options.Y?(s=c.options.relativeBeta?a-g:a,s=c.filterY.stableFix(s),s=c.filterY.changeLimit(s),s=c.filterY.linearRegressionMedian(+s)):s=0,c.isValid(o,s)&&(c.options.useRequestAnimationFrame?window.requestAnimationFrame(function(){t(o,s,{alpha:n,beta:s-g,gamma:o-d})}):t(o,s,{alpha:n,beta:s-g,gamma:o-d}),c.lastX=o,c.lastY=s)))};this.stoped=!1,f?(v(!0,this.options.interval),this.watchListener=function(t){if("param"in t){var e=t.param,n=e.x,a=e.y,i=e.z;(n!==c.prevAcceler.x||a!==c.prevAcceler.y||i!==c.prevAcceler.z)&&(c.prevAcceler={x:n,y:a,z:i},b({alpha:180*+i,beta:-90*+a,gamma:90*+n}))}},document.addEventListener("motion.gyro",this.watchListener,!1)):h&&!e.isMiniProgram()?(p(!0,this.options.interval/1e3),this.watchListener=function(t){if(t&&"data"in t){var e=t.data,n=e.x,a=e.y;b({alpha:180*e.z,beta:-90*a,gamma:90*n})}},document.addEventListener("accelerometerChange",this.watchListener,!1)):(this.watchListener=function(t){(m=new Date().getTime())-u>=c.options.interval&&(u=m,b(t))},window.addEventListener("deviceorientation",this.watchListener,!1))}},n.unWatch=function(){e.assertExist(this.watchListener),f?(v(!1),document.removeEventListener("motion.gyro",this.watchListener)):h?(p(!1),document.removeEventListener("accelerometerChange",this.watchListener)):window.removeEventListener("deviceorientation",this.watchListener),this.stoped=!0,this.watchListener=void 0},n.pause=function(){this.stoped=!0,h&&p(!1)},n.continue=function(){this.stoped=!1,h&&p(!0,this.options.interval/1e3)},n.isValid=function(t,e){return this.lastX!==t||this.lastY!==e},t}();function p(t,e){window.AlipayJSBridge.call("watchShake",{monitorGyroscope:!1,monitorAccelerometer:!!t,interval:t?parseFloat(e.toFixed(3)):10},function(){})}function v(t,e){window.WindVane.call("WVMotion","listenGyro",{on:t,frequency:e},function(t){console.info("Call WVMotion success.")},function(t){console.error("Call WVMotion failed: "+JSON.stringify(t)+".")})}var g=function(){function t(){this.transformers=[],this.connected=!1,this.accelerMotion=null,this.validRange={alpha:[-60,60],beta:[-80,80],gamma:[-89,89]}}var e=t.prototype;return e.connect=function(){var t=this;this.connected||(this.accelerMotion=new d({X:!0,Y:!0,interval:Math.floor(1e3/60),useRequestAnimationFrame:!0,relativeBeta:!1,relativeGamma:!1,validRange:this.validRange,stableRange:3}),this.accelerMotion.watch(function(e,n,a){var i=a.beta,r=a.gamma;t.dispatchMotion({x:e,y:n,beta:i,gamma:r})})),this.connected=!0},e.disconnect=function(){this.accelerMotion&&this.accelerMotion.unWatch(),this.connected=!1},e.dispatchMotion=function(t){this.transformers.forEach(function(e){return e.update(t)})},e.addTransformer=function(t){this.transformers.includes(t)||this.transformers.push(t)},e.removeTransformer=function(t){var e=this.transformers.indexOf(t);return e>-1&&this.transformers.splice(e,1),0===this.transformers.length},t}(),b=function(t){function e(){var e;return e=t.apply(this,arguments)||this,e.order=90,e.adapter=null,e.handleConnect=function(){if(!y){var t;null==(t=e.adapter)||t.connect()}},e.handleDisconnect=function(){var t;null==(t=e.adapter)||t.disconnect()},e}r(e,t);var n=e.prototype;return n.onCompositionConstructed=function(){var t;this.adapter=M(),null==(t=this.adapter)||t.connect(),this.bindAccelerDocumentEvent()},n.onCompositionReset=function(t){var e,n=t.loaderData.deviceTransformer=new o(t);null==(e=this.adapter)||e.addTransformer(n)},n.onCompositionUpdate=function(t){var e=t.loaderData.deviceTransformer;e&&e.updateOrientation()},n.onCompositionDestroyed=function(t){var e,n;(null==(e=this.adapter)?void 0:e.removeTransformer(t.loaderData.deviceTransformer))&&(null==(n=this.adapter)||n.disconnect())},n.bindAccelerDocumentEvent=function(){this.unbindAccelerDocumentEvent(),document.addEventListener("resume",this.handleConnect,!1),document.addEventListener("pause",this.handleDisconnect,!1),document.addEventListener("back",this.handleDisconnect,!1)},n.unbindAccelerDocumentEvent=function(){document.removeEventListener("resume",this.handleConnect),document.removeEventListener("pause",this.handleDisconnect),document.removeEventListener("back",this.handleDisconnect)},n.dispose=function(){M().disconnect(),this.unbindAccelerDocumentEvent()},e}(e.AbstractPlugin),y=!1;function M(){return n||(n=new g),n}"function"==typeof SuppressedError&&SuppressedError,t.OrientationComponent=function(t){function e(){return t.apply(this,arguments)}r(e,t);var n=e.prototype;return n.fromData=function(e){t.prototype.fromData.call(this,e);var n=e.options.targets;n&&(this.targets=n.map(function(t){return{name:t.name,xMin:+t.xMin||0,yMin:+t.yMin||0,xMax:+t.xMax||0,yMax:+t.yMax||0,vMin:+t.vMin||0,hMin:+t.hMin||0,vMax:+t.vMax||0,hMax:+t.hMax||0}}))},n.onStart=function(){var t,e,n=null==(t=this.item.composition)?void 0:t.loaderData.deviceTransformer;n&&(null==(e=this.targets)||e.forEach(function(t){return n.addTarget(t)}),n.initComposition())},n.onUpdate=function(t){var e,n=null==(e=this.item.composition)?void 0:e.loaderData.deviceTransformer;n&&n.updateOrientation()},n.onDestroy=function(){var t,e=this;null==(t=this.targets)||t.forEach(function(t){var n,a;return null==(a=e.item.composition)?void 0:null==(n=a.loaderData.deviceTransformer)?void 0:n.removeTarget(t.name)})},e}(e.Behaviour),t.OrientationComponent=function(t,e,n,a){var i,r=arguments.length,o=r<3?e:null===a?a=Object.getOwnPropertyDescriptor(e,n):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,n,a);else for(var s=t.length-1;s>=0;s--)(i=t[s])&&(o=(r<3?i(o):r>3?i(e,n,o):i(e,n))||o);return r>3&&o&&Object.defineProperty(e,n,o),o}([e.effectsClass("OrientationComponent")],t.OrientationComponent),e.registerPlugin("orientation-transformer",b,e.VFXItem);var w="2.1.0-alpha.7";e.logger.info("Plugin orientation transformer version: "+w+"."),w!==a.version&&console.error("注意:请统一 Orientation Transformer 插件与 Player 版本,不统一的版本混用会有不可预知的后果!","\nAttention: Please ensure the Orientation Transformer plugin is synchronized with the Player version. Mixing and matching incompatible versions may result in unpredictable consequences!"),t.OrientationAdapterAcceler=g,t.OrientationPluginLoader=b,t.closeDeviceMotion=function(){y=!0,M().disconnect()},t.getAdapter=M,t.openDeviceMotion=function(){y=!1,M().connect()},t.version=w,Object.defineProperty(t,"__esModule",{value:!0})});
8
8
  //# sourceMappingURL=index.min.js.map
package/dist/index.mjs CHANGED
@@ -3,7 +3,7 @@
3
3
  * Description: Galacean Effects player orientation transformer plugin
4
4
  * Author: Ant Group CO., Ltd.
5
5
  * Contributors: 燃然,意绮
6
- * Version: v2.1.0-alpha.5
6
+ * Version: v2.1.0-alpha.7
7
7
  */
8
8
 
9
9
  import * as EFFECTS from '@galacean/effects';
@@ -774,7 +774,7 @@ OrientationComponent = __decorate([
774
774
  ], OrientationComponent);
775
775
 
776
776
  registerPlugin("orientation-transformer", OrientationPluginLoader, VFXItem);
777
- var version = "2.1.0-alpha.5";
777
+ var version = "2.1.0-alpha.7";
778
778
  logger.info("Plugin orientation transformer version: " + version + ".");
779
779
  if (version !== EFFECTS.version) {
780
780
  console.error("注意:请统一 Orientation Transformer 插件与 Player 版本,不统一的版本混用会有不可预知的后果!", "\nAttention: Please ensure the Orientation Transformer plugin is synchronized with the Player version. Mixing and matching incompatible versions may result in unpredictable consequences!");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@galacean/effects-plugin-orientation-transformer",
3
- "version": "2.1.0-alpha.5",
3
+ "version": "2.1.0-alpha.7",
4
4
  "description": "Galacean Effects player orientation transformer plugin",
5
5
  "module": "./dist/index.mjs",
6
6
  "main": "./dist/index.js",
@@ -43,7 +43,7 @@
43
43
  "registry": "https://registry.npmjs.org"
44
44
  },
45
45
  "devDependencies": {
46
- "@galacean/effects": "2.1.0-alpha.5"
46
+ "@galacean/effects": "2.1.0-alpha.7"
47
47
  },
48
48
  "scripts": {
49
49
  "dev": "vite",