@galacean/effects-plugin-orientation-transformer 2.0.0-alpha.13 → 2.0.0-alpha.14

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
@@ -828,7 +828,7 @@ exports.OrientationComponent = __decorate([
828
828
  ], exports.OrientationComponent);
829
829
 
830
830
  effects.registerPlugin("orientation-transformer", OrientationPluginLoader, effects.VFXItem);
831
- var version = "2.0.0-alpha.13";
831
+ var version = "2.0.0-alpha.14";
832
832
  effects.logger.info("plugin orientation transformer version: " + version);
833
833
  if (version !== effects.version) {
834
834
  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
@@ -824,7 +824,7 @@ OrientationComponent = __decorate([
824
824
  ], OrientationComponent);
825
825
 
826
826
  registerPlugin("orientation-transformer", OrientationPluginLoader, VFXItem);
827
- var version = "2.0.0-alpha.13";
827
+ var version = "2.0.0-alpha.14";
828
828
  logger.info("plugin orientation transformer version: " + version);
829
829
  if (version !== version$1) {
830
830
  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.0.0-alpha.13
6
+ * Version: v2.0.0-alpha.14
7
7
  */
8
8
 
9
9
  'use strict';
@@ -835,7 +835,7 @@ exports.OrientationComponent = __decorate([
835
835
  ], exports.OrientationComponent);
836
836
 
837
837
  effects.registerPlugin("orientation-transformer", OrientationPluginLoader, effects.VFXItem);
838
- var version = "2.0.0-alpha.13";
838
+ var version = "2.0.0-alpha.14";
839
839
  effects.logger.info("plugin orientation transformer version: " + version);
840
840
  if (version !== effects.version) {
841
841
  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.0.0-alpha.13
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";function n(t,e){return(n=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function a(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&&n(t,e)}var i,r,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==(A=this.records[t])?void 0:A.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,p,d,v,g,y,b,w,M,R,x,O,A,L,E,P=[c[0]+1.2*(p=(h-(m=this.gammaRange[0]))/(this.gammaRange[1]-m),(d=u.xMin)+(u.xMax-d)*p),c[1]+1.2*(g=(f-(v=this.betaRange[0]))/(this.betaRange[1]-v),(y=u.yMin)+(u.yMax-y)*g),c[2]],D=(b=s(.8*r,this.gammaRange),(b-(w=this.gammaRange[0]))/(this.gammaRange[1]-w)),j=(M=s(.8*i,this.betaRange),(M-(R=this.betaRange[0]))/(this.betaRange[1]-R)),T=[l[0]+((x=u.hMin)+(u.hMax-x)*j),l[1]+((O=u.vMin)+(u.vMax-O)*D),l[2]];(L=o.transform).setPosition.apply(L,[].concat(P)),(E=o.transform).setRotation.apply(E,[].concat(T)),this.currentPos[t]=P.slice(),this.currentRot[t]=T.slice()}}},t}();function s(t,e){return t<e[0]?e[0]:t>e[1]?e[1]:t}function c(t){return Object.prototype.toString.call(t)}function l(t,e){var n=!0,a=!0,i=!0;if("[object Array]"===c(e.alpha)&&e.alpha.length>=2){var r=t.alpha+e.alpha[0],o=t.alpha+e.alpha[1];n=(r=r<0?r+360:r)<(o=o>360?o-360:o)?t.alpha>r&&t.alpha<o:t.alpha>r||t.alpha<o}return"[object Array]"===c(e.beta)&&e.beta.length>=2&&(a=t.beta>=e.beta[0]&&t.beta<=e.beta[1]),"[object Array]"===c(e.gamma)&&e.gamma.length>=2&&(i=t.gamma>=e.gamma[0]&&t.gamma<=e.gamma[1]),n&&a&&i}function u(){return(u=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)}var h=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}(),f=((i=navigator.userAgent.toLowerCase().match(/cpu (iphone )?os (.*?) like mac os/))?parseInt(i[2],10):0)&&void 0!==window.AlipayJSBridge,m=void 0!==window.WindVane,p={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,this.options=function t(n,a){if(!e.isObject(n)&&!e.isArray(n))return n;for(var i=e.isArray(n)?[].concat(n):u({},n),r=arguments.length,o=1;o<r;o++){var s=arguments[o]||{};if(e.isObject(s)){var c=void 0;for(c in s)s.hasOwnProperty(c)&&(e.isObject(i[c])&&e.isObject(s[c])?i[c]=t(i[c],s[c]):e.isObject(s[c])?i[c]=t(s[c]):e.isArray(s[c])?i[c]=t(s[c]):i[c]=s[c]);for(c in i)e.isObject(i[c])&&i.hasOwnProperty(c)&&!s.hasOwnProperty(c)&&(i[c]=t(i[c]))}}if(1===r)for(var l in i)e.isObject(i[l])&&i.hasOwnProperty(l)&&(i[l]=t(i[l]));return i}(p,t);var n=this.options.stableRange;this.filterX=new h({stableRange:n}),this.filterY=new h({stableRange:n})}var n=t.prototype;return n.watch=function(t){var e,n,a,i,r,o,s=this;if("function"==typeof t&&!this.watchListener){var c,u=0,h=0,p=NaN,d=NaN,y=function(c){!s.stoped&&(e=c.alpha,n=c.beta,a=c.gamma,i=l.call(s,{alpha:e,beta:n,gamma:a},s.options.validRange),isNaN(p)&&(p=a,s.filterX.lastValue=a),isNaN(d)&&(d=n,s.filterY.lastValue=n),i&&(s.options.X?(r=s.options.relativeGamma?a-p:a,r=s.filterX.stableFix(r),r=s.filterX.changeLimit(r),r=s.filterX.linearRegressionMedian(+r)):r=0,s.options.Y?(o=s.options.relativeBeta?n-d:n,o=s.filterY.stableFix(o),o=s.filterY.changeLimit(o),o=s.filterY.linearRegressionMedian(+o)):o=0,s.isValid(r,o)&&(s.options.useRequestAnimationFrame?window.requestAnimationFrame(function(){t(r,o,{alpha:e,beta:o-d,gamma:r-p})}):t(r,o,{alpha:e,beta:o-d,gamma:r-p}),s.lastX=r,s.lastY=o)))};this.stoped=!1,m?(g(!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!==s.prevAcceler.x||a!==s.prevAcceler.y||i!==s.prevAcceler.z)&&(s.prevAcceler={x:n,y:a,z:i},y({alpha:180*+i,beta:-90*+a,gamma:90*+n}))}},document.addEventListener("motion.gyro",this.watchListener,!1)):f&&!("undefined"!=typeof my&&(null==(c=my)?void 0:c.renderTarget)==="web"||"miniprogram"===window.__wxjs_environment)?(v(!0,this.options.interval/1e3),this.watchListener=function(t){if(t&&"data"in t){var e=t.data,n=e.x,a=e.y;y({alpha:180*e.z,beta:-90*a,gamma:90*n})}},document.addEventListener("accelerometerChange",this.watchListener,!1)):(this.watchListener=function(t){(h=new Date().getTime())-u>=s.options.interval&&(u=h,y(t))},window.addEventListener("deviceorientation",this.watchListener,!1))}},n.unWatch=function(){e.assertExist(this.watchListener),m?(g(!1),document.removeEventListener("motion.gyro",this.watchListener)):f?(v(!1),document.removeEventListener("accelerometerChange",this.watchListener)):window.removeEventListener("deviceorientation",this.watchListener),this.stoped=!0,this.watchListener=void 0},n.pause=function(){this.stoped=!0,f&&v(!1)},n.continue=function(){this.stoped=!1,f&&v(!0,this.options.interval/1e3)},n.isValid=function(t,e){return this.lastX!==t||this.lastY!==e},t}();function v(t,e){window.AlipayJSBridge.call("watchShake",{monitorGyroscope:!1,monitorAccelerometer:!!t,interval:t?parseFloat(e.toFixed(3)):10},function(){})}function g(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 y=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(!w){var t;null==(t=e.adapter)||t.connect()}},e.handleDisconnect=function(){var t;null==(t=e.adapter)||t.disconnect()},e}a(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),w=!1;function M(){return r||(r=new y),r}"function"==typeof SuppressedError&&SuppressedError,t.OrientationComponent=function(t){function e(){return t.apply(this,arguments)}a(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.start=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.update=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.ItemBehaviour),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 R="2.0.0-alpha.13";e.logger.info("plugin orientation transformer version: "+R),R!==e.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=y,t.OrientationPluginLoader=b,t.closeDeviceMotion=function(){w=!0,M().disconnect()},t.getAdapter=M,t.openDeviceMotion=function(){w=!1,M().connect()},t.version=R,Object.defineProperty(t,"__esModule",{value:!0})});
6
+ * Version: v2.0.0-alpha.14
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";function n(t,e){return(n=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function a(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&&n(t,e)}var i,r,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==(A=this.records[t])?void 0:A.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,p,d,v,g,y,b,w,M,R,x,O,A,L,E,P=[c[0]+1.2*(p=(h-(m=this.gammaRange[0]))/(this.gammaRange[1]-m),(d=u.xMin)+(u.xMax-d)*p),c[1]+1.2*(g=(f-(v=this.betaRange[0]))/(this.betaRange[1]-v),(y=u.yMin)+(u.yMax-y)*g),c[2]],D=(b=s(.8*r,this.gammaRange),(b-(w=this.gammaRange[0]))/(this.gammaRange[1]-w)),j=(M=s(.8*i,this.betaRange),(M-(R=this.betaRange[0]))/(this.betaRange[1]-R)),T=[l[0]+((x=u.hMin)+(u.hMax-x)*j),l[1]+((O=u.vMin)+(u.vMax-O)*D),l[2]];(L=o.transform).setPosition.apply(L,[].concat(P)),(E=o.transform).setRotation.apply(E,[].concat(T)),this.currentPos[t]=P.slice(),this.currentRot[t]=T.slice()}}},t}();function s(t,e){return t<e[0]?e[0]:t>e[1]?e[1]:t}function c(t){return Object.prototype.toString.call(t)}function l(t,e){var n=!0,a=!0,i=!0;if("[object Array]"===c(e.alpha)&&e.alpha.length>=2){var r=t.alpha+e.alpha[0],o=t.alpha+e.alpha[1];n=(r=r<0?r+360:r)<(o=o>360?o-360:o)?t.alpha>r&&t.alpha<o:t.alpha>r||t.alpha<o}return"[object Array]"===c(e.beta)&&e.beta.length>=2&&(a=t.beta>=e.beta[0]&&t.beta<=e.beta[1]),"[object Array]"===c(e.gamma)&&e.gamma.length>=2&&(i=t.gamma>=e.gamma[0]&&t.gamma<=e.gamma[1]),n&&a&&i}function u(){return(u=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)}var h=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}(),f=((i=navigator.userAgent.toLowerCase().match(/cpu (iphone )?os (.*?) like mac os/))?parseInt(i[2],10):0)&&void 0!==window.AlipayJSBridge,m=void 0!==window.WindVane,p={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,this.options=function t(n,a){if(!e.isObject(n)&&!e.isArray(n))return n;for(var i=e.isArray(n)?[].concat(n):u({},n),r=arguments.length,o=1;o<r;o++){var s=arguments[o]||{};if(e.isObject(s)){var c=void 0;for(c in s)s.hasOwnProperty(c)&&(e.isObject(i[c])&&e.isObject(s[c])?i[c]=t(i[c],s[c]):e.isObject(s[c])?i[c]=t(s[c]):e.isArray(s[c])?i[c]=t(s[c]):i[c]=s[c]);for(c in i)e.isObject(i[c])&&i.hasOwnProperty(c)&&!s.hasOwnProperty(c)&&(i[c]=t(i[c]))}}if(1===r)for(var l in i)e.isObject(i[l])&&i.hasOwnProperty(l)&&(i[l]=t(i[l]));return i}(p,t);var n=this.options.stableRange;this.filterX=new h({stableRange:n}),this.filterY=new h({stableRange:n})}var n=t.prototype;return n.watch=function(t){var e,n,a,i,r,o,s=this;if("function"==typeof t&&!this.watchListener){var c,u=0,h=0,p=NaN,d=NaN,y=function(c){!s.stoped&&(e=c.alpha,n=c.beta,a=c.gamma,i=l.call(s,{alpha:e,beta:n,gamma:a},s.options.validRange),isNaN(p)&&(p=a,s.filterX.lastValue=a),isNaN(d)&&(d=n,s.filterY.lastValue=n),i&&(s.options.X?(r=s.options.relativeGamma?a-p:a,r=s.filterX.stableFix(r),r=s.filterX.changeLimit(r),r=s.filterX.linearRegressionMedian(+r)):r=0,s.options.Y?(o=s.options.relativeBeta?n-d:n,o=s.filterY.stableFix(o),o=s.filterY.changeLimit(o),o=s.filterY.linearRegressionMedian(+o)):o=0,s.isValid(r,o)&&(s.options.useRequestAnimationFrame?window.requestAnimationFrame(function(){t(r,o,{alpha:e,beta:o-d,gamma:r-p})}):t(r,o,{alpha:e,beta:o-d,gamma:r-p}),s.lastX=r,s.lastY=o)))};this.stoped=!1,m?(g(!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!==s.prevAcceler.x||a!==s.prevAcceler.y||i!==s.prevAcceler.z)&&(s.prevAcceler={x:n,y:a,z:i},y({alpha:180*+i,beta:-90*+a,gamma:90*+n}))}},document.addEventListener("motion.gyro",this.watchListener,!1)):f&&!("undefined"!=typeof my&&(null==(c=my)?void 0:c.renderTarget)==="web"||"miniprogram"===window.__wxjs_environment)?(v(!0,this.options.interval/1e3),this.watchListener=function(t){if(t&&"data"in t){var e=t.data,n=e.x,a=e.y;y({alpha:180*e.z,beta:-90*a,gamma:90*n})}},document.addEventListener("accelerometerChange",this.watchListener,!1)):(this.watchListener=function(t){(h=new Date().getTime())-u>=s.options.interval&&(u=h,y(t))},window.addEventListener("deviceorientation",this.watchListener,!1))}},n.unWatch=function(){e.assertExist(this.watchListener),m?(g(!1),document.removeEventListener("motion.gyro",this.watchListener)):f?(v(!1),document.removeEventListener("accelerometerChange",this.watchListener)):window.removeEventListener("deviceorientation",this.watchListener),this.stoped=!0,this.watchListener=void 0},n.pause=function(){this.stoped=!0,f&&v(!1)},n.continue=function(){this.stoped=!1,f&&v(!0,this.options.interval/1e3)},n.isValid=function(t,e){return this.lastX!==t||this.lastY!==e},t}();function v(t,e){window.AlipayJSBridge.call("watchShake",{monitorGyroscope:!1,monitorAccelerometer:!!t,interval:t?parseFloat(e.toFixed(3)):10},function(){})}function g(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 y=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(!w){var t;null==(t=e.adapter)||t.connect()}},e.handleDisconnect=function(){var t;null==(t=e.adapter)||t.disconnect()},e}a(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),w=!1;function M(){return r||(r=new y),r}"function"==typeof SuppressedError&&SuppressedError,t.OrientationComponent=function(t){function e(){return t.apply(this,arguments)}a(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.start=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.update=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.ItemBehaviour),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 R="2.0.0-alpha.14";e.logger.info("plugin orientation transformer version: "+R),R!==e.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=y,t.OrientationPluginLoader=b,t.closeDeviceMotion=function(){w=!0,M().disconnect()},t.getAdapter=M,t.openDeviceMotion=function(){w=!1,M().connect()},t.version=R,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.0.0-alpha.13
6
+ * Version: v2.0.0-alpha.14
7
7
  */
8
8
 
9
9
  import { isObject, isArray, assertExist, AbstractPlugin, effectsClass, ItemBehaviour, registerPlugin, VFXItem, logger, version as version$1 } from '@galacean/effects';
@@ -831,7 +831,7 @@ OrientationComponent = __decorate([
831
831
  ], OrientationComponent);
832
832
 
833
833
  registerPlugin("orientation-transformer", OrientationPluginLoader, VFXItem);
834
- var version = "2.0.0-alpha.13";
834
+ var version = "2.0.0-alpha.14";
835
835
  logger.info("plugin orientation transformer version: " + version);
836
836
  if (version !== version$1) {
837
837
  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.0.0-alpha.13",
3
+ "version": "2.0.0-alpha.14",
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.0.0-alpha.13"
46
+ "@galacean/effects": "2.0.0-alpha.14"
47
47
  },
48
48
  "scripts": {
49
49
  "dev": "vite",