@galacean/effects-plugin-orientation-transformer 2.7.2 → 2.7.4
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 +1 -1
- package/dist/alipay.mjs +1 -1
- package/dist/index.js +2 -2
- package/dist/index.min.js +2 -2
- package/dist/index.mjs +2 -2
- package/package.json +3 -3
package/dist/alipay.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@galacean/effects/alipay"),e=require("@galacean/appx-adapter/alipay");function n(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)}var a=n(t);function i(t,e){return i=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},i(t,e)}function r(t,e){if("function"!=typeof e&&null!==e)throw new 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,a=e.x,i=e.y,r=e.beta,o=e.gamma,u=null==(n=this.records[t])?void 0:n.item;if(u){var h=this.records[t].position,f=this.records[t].rotation,m=this.targets[t],p=s(a,this.betaRange),d=s(i,this.gammaRange);if(m){var v,g,y=[h[0]+1.2*c(l(p,this.gammaRange[0],this.gammaRange[1]),m.xMin,m.xMax),h[1]+1.2*c(l(d,this.betaRange[0],this.betaRange[1]),m.yMin,m.yMax),h[2]],b=l(s(.8*o,this.gammaRange),this.gammaRange[0],this.gammaRange[1]),M=l(s(.8*r,this.betaRange),this.betaRange[0],this.betaRange[1]),x=[f[0]+c(M,m.hMin,m.hMax),f[1]+c(b,m.vMin,m.vMax),f[2]];(v=u.transform).setPosition.apply(v,[].concat(y)),(g=u.transform).setRotation.apply(g,[].concat(x)),this.currentPos[t]=y.slice(),this.currentRot[t]=x.slice()}}},t}();function s(t,e){return t<e[0]?e[0]:t>e[1]?e[1]:t}function c(t,e,n){return e+(n-e)*t}function l(t,e,n){return(t-e)/(n-e)}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},u.apply(this,arguments)}function h(e,n){var a=!0,i=!0,r=!0;if(t.isArray(n.alpha)&&n.alpha.length>=2){var o=e.alpha+n.alpha[0],s=e.alpha+n.alpha[1];a=(o=o<0?o+360:o)<(s=s>360?s-360:s)?e.alpha>o&&e.alpha<s:e.alpha>o||e.alpha<s}return t.isArray(n.beta)&&n.beta.length>=2&&(i=e.beta>=n.beta[0]&&e.beta<=n.beta[1]),t.isArray(n.gamma)&&n.gamma.length>=2&&(r=e.gamma>=n.gamma[0]&&e.gamma<=n.gamma[1]),a&&i&&r}var f=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),Math.abs(t-e)<1&&(n=e),this.lastValue=n,n},e.linearRegressionMedian=function(t){var e,n,a;return this.valuePool.push(t),this.valuePool.length>=5?(n=this.valuePool,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),n=n.map((function(t,e){return a(e)})),e=a(n.length/2),this.valuePool.shift()):e=this.lastValue,e},t}();var m=t.isIOSByUA()&&void 0!==e.window.AlipayJSBridge,p=void 0!==e.window.WindVane,d={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},v=function(){function n(t){void 0===t&&(t={}),this.lastX=0,this.lastY=0,this.prevAcceler={x:0,y:0,z:0},this.stoped=!1;var e=u({},d.validRange,t.validRange),n=u({},d,t);n.validRange=e,this.options=n;var a=this.options.stableRange;this.filterX=new f({stableRange:a}),this.filterY=new f({stableRange:a})}var a=n.prototype;return a.watch=function(n){var a=this;if("function"==typeof n&&!this.watchListener){var i,r,o,s,c,l,u=0,f=0,d=NaN,v=NaN,b=function(t){a.stoped||(i=t.alpha||0,r=t.beta||0,o=t.gamma||0,s=h.call(a,{alpha:i,beta:r,gamma:o},a.options.validRange),isNaN(d)&&(d=o,a.filterX.lastValue=o),isNaN(v)&&(v=r,a.filterY.lastValue=r),s&&(a.options.X?(c=a.options.relativeGamma?o-d:o,c=a.filterX.stableFix(c),c=a.filterX.changeLimit(c),c=a.filterX.linearRegressionMedian(+c)):c=0,a.options.Y?(l=a.options.relativeBeta?r-v:r,l=a.filterY.stableFix(l),l=a.filterY.changeLimit(l),l=a.filterY.linearRegressionMedian(+l)):l=0,a.isValid(c,l)&&(a.options.useRequestAnimationFrame?e.window.requestAnimationFrame((function(){n(c,l,{alpha:i,beta:l-v,gamma:c-d})})):n(c,l,{alpha:i,beta:l-v,gamma:c-d}),a.lastX=c,a.lastY=l)))};this.stoped=!1,p?(y(!0,this.options.interval),this.watchListener=function(t){if("param"in t){var e=t.param,n=e.x,i=e.y,r=e.z;if(n===a.prevAcceler.x&&i===a.prevAcceler.y&&r===a.prevAcceler.z)return;a.prevAcceler={x:n,y:i,z:r},b({alpha:180*+r,beta:-90*+i,gamma:90*+n})}},e.document.addEventListener("motion.gyro",this.watchListener,!1)):m&&!t.isMiniProgram()?(g(!0,this.options.interval/1e3),this.watchListener=function(t){if(t&&"data"in t){var e=t.data,n=e.x,a=e.y,i=e.z;b({alpha:180*i,beta:-90*a,gamma:90*n})}},e.document.addEventListener("accelerometerChange",this.watchListener,!1)):(this.watchListener=function(t){(f=(new Date).getTime())-u>=a.options.interval&&(u=f,b(t))},e.window.addEventListener("deviceorientation",this.watchListener,!1))}},a.unWatch=function(){t.assertExist(this.watchListener),p?(y(!1),e.document.removeEventListener("motion.gyro",this.watchListener)):m?(g(!1),e.document.removeEventListener("accelerometerChange",this.watchListener)):e.window.removeEventListener("deviceorientation",this.watchListener),this.stoped=!0,this.watchListener=void 0},a.pause=function(){this.stoped=!0,m&&g(!1)},a.continue=function(){this.stoped=!1,m&&g(!0,this.options.interval/1e3)},a.isValid=function(t,e){return this.lastX!==t||this.lastY!==e},n}();function g(t,n){e.window.AlipayJSBridge.call("watchShake",{monitorGyroscope:!1,monitorAccelerometer:!!t,interval:t?parseFloat(n.toFixed(3)):10},(function(){}))}function y(t,n){var a={on:t,frequency:n};e.window.WindVane.call("WVMotion","listenGyro",a,(function(t){console.info("Call WVMotion success.")}),(function(t){console.error("Call WVMotion failed: "+JSON.stringify(t)+".")}))}var b,M=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 v({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={x:e,y:n,beta:a.beta,gamma:a.gamma};t.dispatchMotion(i)}))),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}();var x=function(t){function n(){var e;return(e=t.apply(this,arguments)||this).order=90,e.adapter=null,e.handleConnect=function(){var t;w||(null==(t=e.adapter)||t.connect())},e.handleDisconnect=function(){var t;null==(t=e.adapter)||t.disconnect()},e}r(n,t);var a=n.prototype;return a.onCompositionConstructed=function(){var t;this.adapter=R(),null==(t=this.adapter)||t.connect(),this.bindAccelerDocumentEvent()},a.onCompositionReset=function(t){var e,n=t.loaderData.deviceTransformer=new o(t);null==(e=this.adapter)||e.addTransformer(n)},a.onCompositionUpdate=function(t){var e=t.loaderData.deviceTransformer;e&&e.updateOrientation()},a.onCompositionDestroyed=function(t){var e,n;(null==(e=this.adapter)?void 0:e.removeTransformer(t.loaderData.deviceTransformer))&&(null==(n=this.adapter)||n.disconnect())},a.bindAccelerDocumentEvent=function(){this.unbindAccelerDocumentEvent(),e.document.addEventListener("resume",this.handleConnect,!1),e.document.addEventListener("pause",this.handleDisconnect,!1),e.document.addEventListener("back",this.handleDisconnect,!1)},a.unbindAccelerDocumentEvent=function(){e.document.removeEventListener("resume",this.handleConnect),e.document.removeEventListener("pause",this.handleDisconnect),e.document.removeEventListener("back",this.handleDisconnect)},a.dispose=function(){R().disconnect(),this.unbindAccelerDocumentEvent()},n}(t.AbstractPlugin),w=!1;function R(){return b||(b=new M),b}"function"==typeof SuppressedError&&SuppressedError,exports.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)||null==(n=a.loaderData.deviceTransformer)?void 0:n.removeTarget(t.name)}))},e}(t.Behaviour),exports.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}([t.effectsClass("OrientationComponent")],exports.OrientationComponent),t.registerPlugin("orientation-transformer",x,t.VFXItem);var O="2.7.2";t.logger.info("Plugin orientation transformer version: 2.7.2."),O!==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!"),exports.OrientationAdapterAcceler=M,exports.OrientationPluginLoader=x,exports.closeDeviceMotion=function(){w=!0,R().disconnect()},exports.getAdapter=R,exports.openDeviceMotion=function(){w=!1,R().connect()},exports.version=O;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@galacean/effects/alipay"),e=require("@galacean/appx-adapter/alipay");function n(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)}var a=n(t);function i(t,e){return i=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},i(t,e)}function r(t,e){if("function"!=typeof e&&null!==e)throw new 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,a=e.x,i=e.y,r=e.beta,o=e.gamma,u=null==(n=this.records[t])?void 0:n.item;if(u){var h=this.records[t].position,f=this.records[t].rotation,m=this.targets[t],p=s(a,this.betaRange),d=s(i,this.gammaRange);if(m){var v,g,y=[h[0]+1.2*c(l(p,this.gammaRange[0],this.gammaRange[1]),m.xMin,m.xMax),h[1]+1.2*c(l(d,this.betaRange[0],this.betaRange[1]),m.yMin,m.yMax),h[2]],b=l(s(.8*o,this.gammaRange),this.gammaRange[0],this.gammaRange[1]),M=l(s(.8*r,this.betaRange),this.betaRange[0],this.betaRange[1]),x=[f[0]+c(M,m.hMin,m.hMax),f[1]+c(b,m.vMin,m.vMax),f[2]];(v=u.transform).setPosition.apply(v,[].concat(y)),(g=u.transform).setRotation.apply(g,[].concat(x)),this.currentPos[t]=y.slice(),this.currentRot[t]=x.slice()}}},t}();function s(t,e){return t<e[0]?e[0]:t>e[1]?e[1]:t}function c(t,e,n){return e+(n-e)*t}function l(t,e,n){return(t-e)/(n-e)}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},u.apply(this,arguments)}function h(e,n){var a=!0,i=!0,r=!0;if(t.isArray(n.alpha)&&n.alpha.length>=2){var o=e.alpha+n.alpha[0],s=e.alpha+n.alpha[1];a=(o=o<0?o+360:o)<(s=s>360?s-360:s)?e.alpha>o&&e.alpha<s:e.alpha>o||e.alpha<s}return t.isArray(n.beta)&&n.beta.length>=2&&(i=e.beta>=n.beta[0]&&e.beta<=n.beta[1]),t.isArray(n.gamma)&&n.gamma.length>=2&&(r=e.gamma>=n.gamma[0]&&e.gamma<=n.gamma[1]),a&&i&&r}var f=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),Math.abs(t-e)<1&&(n=e),this.lastValue=n,n},e.linearRegressionMedian=function(t){var e,n,a;return this.valuePool.push(t),this.valuePool.length>=5?(n=this.valuePool,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),n=n.map((function(t,e){return a(e)})),e=a(n.length/2),this.valuePool.shift()):e=this.lastValue,e},t}();var m=t.isIOSByUA()&&void 0!==e.window.AlipayJSBridge,p=void 0!==e.window.WindVane,d={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},v=function(){function n(t){void 0===t&&(t={}),this.lastX=0,this.lastY=0,this.prevAcceler={x:0,y:0,z:0},this.stoped=!1;var e=u({},d.validRange,t.validRange),n=u({},d,t);n.validRange=e,this.options=n;var a=this.options.stableRange;this.filterX=new f({stableRange:a}),this.filterY=new f({stableRange:a})}var a=n.prototype;return a.watch=function(n){var a=this;if("function"==typeof n&&!this.watchListener){var i,r,o,s,c,l,u=0,f=0,d=NaN,v=NaN,b=function(t){a.stoped||(i=t.alpha||0,r=t.beta||0,o=t.gamma||0,s=h.call(a,{alpha:i,beta:r,gamma:o},a.options.validRange),isNaN(d)&&(d=o,a.filterX.lastValue=o),isNaN(v)&&(v=r,a.filterY.lastValue=r),s&&(a.options.X?(c=a.options.relativeGamma?o-d:o,c=a.filterX.stableFix(c),c=a.filterX.changeLimit(c),c=a.filterX.linearRegressionMedian(+c)):c=0,a.options.Y?(l=a.options.relativeBeta?r-v:r,l=a.filterY.stableFix(l),l=a.filterY.changeLimit(l),l=a.filterY.linearRegressionMedian(+l)):l=0,a.isValid(c,l)&&(a.options.useRequestAnimationFrame?e.window.requestAnimationFrame((function(){n(c,l,{alpha:i,beta:l-v,gamma:c-d})})):n(c,l,{alpha:i,beta:l-v,gamma:c-d}),a.lastX=c,a.lastY=l)))};this.stoped=!1,p?(y(!0,this.options.interval),this.watchListener=function(t){if("param"in t){var e=t.param,n=e.x,i=e.y,r=e.z;if(n===a.prevAcceler.x&&i===a.prevAcceler.y&&r===a.prevAcceler.z)return;a.prevAcceler={x:n,y:i,z:r},b({alpha:180*+r,beta:-90*+i,gamma:90*+n})}},e.document.addEventListener("motion.gyro",this.watchListener,!1)):m&&!t.isMiniProgram()?(g(!0,this.options.interval/1e3),this.watchListener=function(t){if(t&&"data"in t){var e=t.data,n=e.x,a=e.y,i=e.z;b({alpha:180*i,beta:-90*a,gamma:90*n})}},e.document.addEventListener("accelerometerChange",this.watchListener,!1)):(this.watchListener=function(t){(f=(new Date).getTime())-u>=a.options.interval&&(u=f,b(t))},e.window.addEventListener("deviceorientation",this.watchListener,!1))}},a.unWatch=function(){t.assertExist(this.watchListener),p?(y(!1),e.document.removeEventListener("motion.gyro",this.watchListener)):m?(g(!1),e.document.removeEventListener("accelerometerChange",this.watchListener)):e.window.removeEventListener("deviceorientation",this.watchListener),this.stoped=!0,this.watchListener=void 0},a.pause=function(){this.stoped=!0,m&&g(!1)},a.continue=function(){this.stoped=!1,m&&g(!0,this.options.interval/1e3)},a.isValid=function(t,e){return this.lastX!==t||this.lastY!==e},n}();function g(t,n){e.window.AlipayJSBridge.call("watchShake",{monitorGyroscope:!1,monitorAccelerometer:!!t,interval:t?parseFloat(n.toFixed(3)):10},(function(){}))}function y(t,n){var a={on:t,frequency:n};e.window.WindVane.call("WVMotion","listenGyro",a,(function(t){console.info("Call WVMotion success.")}),(function(t){console.error("Call WVMotion failed: "+JSON.stringify(t)+".")}))}var b,M=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 v({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={x:e,y:n,beta:a.beta,gamma:a.gamma};t.dispatchMotion(i)}))),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}();var x=function(t){function n(){var e;return(e=t.apply(this,arguments)||this).order=90,e.adapter=null,e.handleConnect=function(){var t;w||(null==(t=e.adapter)||t.connect())},e.handleDisconnect=function(){var t;null==(t=e.adapter)||t.disconnect()},e}r(n,t);var a=n.prototype;return a.onCompositionConstructed=function(){var t;this.adapter=R(),null==(t=this.adapter)||t.connect(),this.bindAccelerDocumentEvent()},a.onCompositionReset=function(t){var e,n=t.loaderData.deviceTransformer=new o(t);null==(e=this.adapter)||e.addTransformer(n)},a.onCompositionUpdate=function(t){var e=t.loaderData.deviceTransformer;e&&e.updateOrientation()},a.onCompositionDestroyed=function(t){var e,n;(null==(e=this.adapter)?void 0:e.removeTransformer(t.loaderData.deviceTransformer))&&(null==(n=this.adapter)||n.disconnect())},a.bindAccelerDocumentEvent=function(){this.unbindAccelerDocumentEvent(),e.document.addEventListener("resume",this.handleConnect,!1),e.document.addEventListener("pause",this.handleDisconnect,!1),e.document.addEventListener("back",this.handleDisconnect,!1)},a.unbindAccelerDocumentEvent=function(){e.document.removeEventListener("resume",this.handleConnect),e.document.removeEventListener("pause",this.handleDisconnect),e.document.removeEventListener("back",this.handleDisconnect)},a.dispose=function(){R().disconnect(),this.unbindAccelerDocumentEvent()},n}(t.AbstractPlugin),w=!1;function R(){return b||(b=new M),b}"function"==typeof SuppressedError&&SuppressedError,exports.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)||null==(n=a.loaderData.deviceTransformer)?void 0:n.removeTarget(t.name)}))},e}(t.Behaviour),exports.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}([t.effectsClass("OrientationComponent")],exports.OrientationComponent),t.registerPlugin("orientation-transformer",x,t.VFXItem);var O="2.7.4";t.logger.info("Plugin orientation transformer version: 2.7.4."),O!==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!"),exports.OrientationAdapterAcceler=M,exports.OrientationPluginLoader=x,exports.closeDeviceMotion=function(){w=!0,R().disconnect()},exports.getAdapter=R,exports.openDeviceMotion=function(){w=!1,R().connect()},exports.version=O;
|
|
2
2
|
//# sourceMappingURL=alipay.js.map
|
package/dist/alipay.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import*as t from"@galacean/effects/alipay";import{isArray as e,isIOSByUA as n,isMiniProgram as a,assertExist as i,AbstractPlugin as r,effectsClass as o,Behaviour as s,registerPlugin as c,VFXItem as l,logger as h}from"@galacean/effects/alipay";import{window as u,document as f}from"@galacean/appx-adapter/alipay";function m(t,e){return m=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},m(t,e)}function p(t,e){if("function"!=typeof e&&null!==e)throw new 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&&m(t,e)}var v=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,a=e.x,i=e.y,r=e.beta,o=e.gamma,s=null==(n=this.records[t])?void 0:n.item;if(s){var c=this.records[t].position,l=this.records[t].rotation,h=this.targets[t],u=d(a,this.betaRange),f=d(i,this.gammaRange);if(h){var m,p,v=[c[0]+1.2*g(y(u,this.gammaRange[0],this.gammaRange[1]),h.xMin,h.xMax),c[1]+1.2*g(y(f,this.betaRange[0],this.betaRange[1]),h.yMin,h.yMax),c[2]],b=y(d(.8*o,this.gammaRange),this.gammaRange[0],this.gammaRange[1]),M=y(d(.8*r,this.betaRange),this.betaRange[0],this.betaRange[1]),R=[l[0]+g(M,h.hMin,h.hMax),l[1]+g(b,h.vMin,h.vMax),l[2]];(m=s.transform).setPosition.apply(m,[].concat(v)),(p=s.transform).setRotation.apply(p,[].concat(R)),this.currentPos[t]=v.slice(),this.currentRot[t]=R.slice()}}},t}();function d(t,e){return t<e[0]?e[0]:t>e[1]?e[1]:t}function g(t,e,n){return e+(n-e)*t}function y(t,e,n){return(t-e)/(n-e)}function b(){return b=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},b.apply(this,arguments)}function M(t,n){var a=!0,i=!0,r=!0;if(e(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(n.beta)&&n.beta.length>=2&&(i=t.beta>=n.beta[0]&&t.beta<=n.beta[1]),e(n.gamma)&&n.gamma.length>=2&&(r=t.gamma>=n.gamma[0]&&t.gamma<=n.gamma[1]),a&&i&&r}var R=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),Math.abs(t-e)<1&&(n=e),this.lastValue=n,n},e.linearRegressionMedian=function(t){var e,n,a;return this.valuePool.push(t),this.valuePool.length>=5?(n=this.valuePool,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 h=i/a,u=r/a;return n.a=(o-a*h*u)/(s-a*h*h),n.b=u-n.a*h,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),n=n.map((function(t,e){return a(e)})),e=a(n.length/2),this.valuePool.shift()):e=this.lastValue,e},t}();var x=n()&&void 0!==u.AlipayJSBridge,w=void 0!==u.WindVane,L={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},E=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=b({},L.validRange,t.validRange),n=b({},L,t);n.validRange=e,this.options=n;var a=this.options.stableRange;this.filterX=new R({stableRange:a}),this.filterY=new R({stableRange:a})}var e=t.prototype;return e.watch=function(t){var e=this;if("function"==typeof t&&!this.watchListener){var n,i,r,o,s,c,l=0,h=0,m=NaN,p=NaN,v=function(a){e.stoped||(n=a.alpha||0,i=a.beta||0,r=a.gamma||0,o=M.call(e,{alpha:n,beta:i,gamma:r},e.options.validRange),isNaN(m)&&(m=r,e.filterX.lastValue=r),isNaN(p)&&(p=i,e.filterY.lastValue=i),o&&(e.options.X?(s=e.options.relativeGamma?r-m:r,s=e.filterX.stableFix(s),s=e.filterX.changeLimit(s),s=e.filterX.linearRegressionMedian(+s)):s=0,e.options.Y?(c=e.options.relativeBeta?i-p:i,c=e.filterY.stableFix(c),c=e.filterY.changeLimit(c),c=e.filterY.linearRegressionMedian(+c)):c=0,e.isValid(s,c)&&(e.options.useRequestAnimationFrame?u.requestAnimationFrame((function(){t(s,c,{alpha:n,beta:c-p,gamma:s-m})})):t(s,c,{alpha:n,beta:c-p,gamma:s-m}),e.lastX=s,e.lastY=c)))};this.stoped=!1,w?(A(!0,this.options.interval),this.watchListener=function(t){if("param"in t){var n=t.param,a=n.x,i=n.y,r=n.z;if(a===e.prevAcceler.x&&i===e.prevAcceler.y&&r===e.prevAcceler.z)return;e.prevAcceler={x:a,y:i,z:r},v({alpha:180*+r,beta:-90*+i,gamma:90*+a})}},f.addEventListener("motion.gyro",this.watchListener,!1)):x&&!a()?(D(!0,this.options.interval/1e3),this.watchListener=function(t){if(t&&"data"in t){var e=t.data,n=e.x,a=e.y,i=e.z;v({alpha:180*i,beta:-90*a,gamma:90*n})}},f.addEventListener("accelerometerChange",this.watchListener,!1)):(this.watchListener=function(t){(h=(new Date).getTime())-l>=e.options.interval&&(l=h,v(t))},u.addEventListener("deviceorientation",this.watchListener,!1))}},e.unWatch=function(){i(this.watchListener),w?(A(!1),f.removeEventListener("motion.gyro",this.watchListener)):x?(D(!1),f.removeEventListener("accelerometerChange",this.watchListener)):u.removeEventListener("deviceorientation",this.watchListener),this.stoped=!0,this.watchListener=void 0},e.pause=function(){this.stoped=!0,x&&D(!1)},e.continue=function(){this.stoped=!1,x&&D(!0,this.options.interval/1e3)},e.isValid=function(t,e){return this.lastX!==t||this.lastY!==e},t}();function D(t,e){u.AlipayJSBridge.call("watchShake",{monitorGyroscope:!1,monitorAccelerometer:!!t,interval:t?parseFloat(e.toFixed(3)):10},(function(){}))}function A(t,e){var n={on:t,frequency:e};u.WindVane.call("WVMotion","listenGyro",n,(function(t){console.info("Call WVMotion success.")}),(function(t){console.error("Call WVMotion failed: "+JSON.stringify(t)+".")}))}var O,P=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 E({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={x:e,y:n,beta:a.beta,gamma:a.gamma};t.dispatchMotion(i)}))),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}();var T=function(t){function e(){var e;return(e=t.apply(this,arguments)||this).order=90,e.adapter=null,e.handleConnect=function(){var t;C||(null==(t=e.adapter)||t.connect())},e.handleDisconnect=function(){var t;null==(t=e.adapter)||t.disconnect()},e}p(e,t);var n=e.prototype;return n.onCompositionConstructed=function(){var t;this.adapter=V(),null==(t=this.adapter)||t.connect(),this.bindAccelerDocumentEvent()},n.onCompositionReset=function(t){var e,n=t.loaderData.deviceTransformer=new v(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(),f.addEventListener("resume",this.handleConnect,!1),f.addEventListener("pause",this.handleDisconnect,!1),f.addEventListener("back",this.handleDisconnect,!1)},n.unbindAccelerDocumentEvent=function(){f.removeEventListener("resume",this.handleConnect),f.removeEventListener("pause",this.handleDisconnect),f.removeEventListener("back",this.handleDisconnect)},n.dispose=function(){V().disconnect(),this.unbindAccelerDocumentEvent()},e}(r),C=!1;function V(){return O||(O=new P),O}function X(){C=!0,V().disconnect()}function Y(){C=!1,V().connect()}"function"==typeof SuppressedError&&SuppressedError;var N=function(t){function e(){return t.apply(this,arguments)}p(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)||null==(n=a.loaderData.deviceTransformer)?void 0:n.removeTarget(t.name)}))},e}(s);N=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}([o("OrientationComponent")],N),c("orientation-transformer",T,l);var F="2.7.2";h.info("Plugin orientation transformer version: 2.7.2."),F!==t.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!");export{P as OrientationAdapterAcceler,N as OrientationComponent,T as OrientationPluginLoader,X as closeDeviceMotion,V as getAdapter,Y as openDeviceMotion,F as version};
|
|
1
|
+
import*as t from"@galacean/effects/alipay";import{isArray as e,isIOSByUA as n,isMiniProgram as a,assertExist as i,AbstractPlugin as r,effectsClass as o,Behaviour as s,registerPlugin as c,VFXItem as l,logger as h}from"@galacean/effects/alipay";import{window as u,document as f}from"@galacean/appx-adapter/alipay";function m(t,e){return m=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},m(t,e)}function p(t,e){if("function"!=typeof e&&null!==e)throw new 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&&m(t,e)}var v=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,a=e.x,i=e.y,r=e.beta,o=e.gamma,s=null==(n=this.records[t])?void 0:n.item;if(s){var c=this.records[t].position,l=this.records[t].rotation,h=this.targets[t],u=d(a,this.betaRange),f=d(i,this.gammaRange);if(h){var m,p,v=[c[0]+1.2*g(y(u,this.gammaRange[0],this.gammaRange[1]),h.xMin,h.xMax),c[1]+1.2*g(y(f,this.betaRange[0],this.betaRange[1]),h.yMin,h.yMax),c[2]],b=y(d(.8*o,this.gammaRange),this.gammaRange[0],this.gammaRange[1]),M=y(d(.8*r,this.betaRange),this.betaRange[0],this.betaRange[1]),R=[l[0]+g(M,h.hMin,h.hMax),l[1]+g(b,h.vMin,h.vMax),l[2]];(m=s.transform).setPosition.apply(m,[].concat(v)),(p=s.transform).setRotation.apply(p,[].concat(R)),this.currentPos[t]=v.slice(),this.currentRot[t]=R.slice()}}},t}();function d(t,e){return t<e[0]?e[0]:t>e[1]?e[1]:t}function g(t,e,n){return e+(n-e)*t}function y(t,e,n){return(t-e)/(n-e)}function b(){return b=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},b.apply(this,arguments)}function M(t,n){var a=!0,i=!0,r=!0;if(e(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(n.beta)&&n.beta.length>=2&&(i=t.beta>=n.beta[0]&&t.beta<=n.beta[1]),e(n.gamma)&&n.gamma.length>=2&&(r=t.gamma>=n.gamma[0]&&t.gamma<=n.gamma[1]),a&&i&&r}var R=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),Math.abs(t-e)<1&&(n=e),this.lastValue=n,n},e.linearRegressionMedian=function(t){var e,n,a;return this.valuePool.push(t),this.valuePool.length>=5?(n=this.valuePool,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 h=i/a,u=r/a;return n.a=(o-a*h*u)/(s-a*h*h),n.b=u-n.a*h,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),n=n.map((function(t,e){return a(e)})),e=a(n.length/2),this.valuePool.shift()):e=this.lastValue,e},t}();var x=n()&&void 0!==u.AlipayJSBridge,w=void 0!==u.WindVane,L={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},E=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=b({},L.validRange,t.validRange),n=b({},L,t);n.validRange=e,this.options=n;var a=this.options.stableRange;this.filterX=new R({stableRange:a}),this.filterY=new R({stableRange:a})}var e=t.prototype;return e.watch=function(t){var e=this;if("function"==typeof t&&!this.watchListener){var n,i,r,o,s,c,l=0,h=0,m=NaN,p=NaN,v=function(a){e.stoped||(n=a.alpha||0,i=a.beta||0,r=a.gamma||0,o=M.call(e,{alpha:n,beta:i,gamma:r},e.options.validRange),isNaN(m)&&(m=r,e.filterX.lastValue=r),isNaN(p)&&(p=i,e.filterY.lastValue=i),o&&(e.options.X?(s=e.options.relativeGamma?r-m:r,s=e.filterX.stableFix(s),s=e.filterX.changeLimit(s),s=e.filterX.linearRegressionMedian(+s)):s=0,e.options.Y?(c=e.options.relativeBeta?i-p:i,c=e.filterY.stableFix(c),c=e.filterY.changeLimit(c),c=e.filterY.linearRegressionMedian(+c)):c=0,e.isValid(s,c)&&(e.options.useRequestAnimationFrame?u.requestAnimationFrame((function(){t(s,c,{alpha:n,beta:c-p,gamma:s-m})})):t(s,c,{alpha:n,beta:c-p,gamma:s-m}),e.lastX=s,e.lastY=c)))};this.stoped=!1,w?(A(!0,this.options.interval),this.watchListener=function(t){if("param"in t){var n=t.param,a=n.x,i=n.y,r=n.z;if(a===e.prevAcceler.x&&i===e.prevAcceler.y&&r===e.prevAcceler.z)return;e.prevAcceler={x:a,y:i,z:r},v({alpha:180*+r,beta:-90*+i,gamma:90*+a})}},f.addEventListener("motion.gyro",this.watchListener,!1)):x&&!a()?(D(!0,this.options.interval/1e3),this.watchListener=function(t){if(t&&"data"in t){var e=t.data,n=e.x,a=e.y,i=e.z;v({alpha:180*i,beta:-90*a,gamma:90*n})}},f.addEventListener("accelerometerChange",this.watchListener,!1)):(this.watchListener=function(t){(h=(new Date).getTime())-l>=e.options.interval&&(l=h,v(t))},u.addEventListener("deviceorientation",this.watchListener,!1))}},e.unWatch=function(){i(this.watchListener),w?(A(!1),f.removeEventListener("motion.gyro",this.watchListener)):x?(D(!1),f.removeEventListener("accelerometerChange",this.watchListener)):u.removeEventListener("deviceorientation",this.watchListener),this.stoped=!0,this.watchListener=void 0},e.pause=function(){this.stoped=!0,x&&D(!1)},e.continue=function(){this.stoped=!1,x&&D(!0,this.options.interval/1e3)},e.isValid=function(t,e){return this.lastX!==t||this.lastY!==e},t}();function D(t,e){u.AlipayJSBridge.call("watchShake",{monitorGyroscope:!1,monitorAccelerometer:!!t,interval:t?parseFloat(e.toFixed(3)):10},(function(){}))}function A(t,e){var n={on:t,frequency:e};u.WindVane.call("WVMotion","listenGyro",n,(function(t){console.info("Call WVMotion success.")}),(function(t){console.error("Call WVMotion failed: "+JSON.stringify(t)+".")}))}var O,P=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 E({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={x:e,y:n,beta:a.beta,gamma:a.gamma};t.dispatchMotion(i)}))),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}();var T=function(t){function e(){var e;return(e=t.apply(this,arguments)||this).order=90,e.adapter=null,e.handleConnect=function(){var t;C||(null==(t=e.adapter)||t.connect())},e.handleDisconnect=function(){var t;null==(t=e.adapter)||t.disconnect()},e}p(e,t);var n=e.prototype;return n.onCompositionConstructed=function(){var t;this.adapter=V(),null==(t=this.adapter)||t.connect(),this.bindAccelerDocumentEvent()},n.onCompositionReset=function(t){var e,n=t.loaderData.deviceTransformer=new v(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(),f.addEventListener("resume",this.handleConnect,!1),f.addEventListener("pause",this.handleDisconnect,!1),f.addEventListener("back",this.handleDisconnect,!1)},n.unbindAccelerDocumentEvent=function(){f.removeEventListener("resume",this.handleConnect),f.removeEventListener("pause",this.handleDisconnect),f.removeEventListener("back",this.handleDisconnect)},n.dispose=function(){V().disconnect(),this.unbindAccelerDocumentEvent()},e}(r),C=!1;function V(){return O||(O=new P),O}function X(){C=!0,V().disconnect()}function Y(){C=!1,V().connect()}"function"==typeof SuppressedError&&SuppressedError;var N=function(t){function e(){return t.apply(this,arguments)}p(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)||null==(n=a.loaderData.deviceTransformer)?void 0:n.removeTarget(t.name)}))},e}(s);N=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}([o("OrientationComponent")],N),c("orientation-transformer",T,l);var F="2.7.4";h.info("Plugin orientation transformer version: 2.7.4."),F!==t.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!");export{P as OrientationAdapterAcceler,N as OrientationComponent,T as OrientationPluginLoader,X as closeDeviceMotion,V as getAdapter,Y as openDeviceMotion,F as version};
|
|
2
2
|
//# sourceMappingURL=alipay.mjs.map
|
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.7.
|
|
6
|
+
* Version: v2.7.4
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
'use strict';
|
|
@@ -799,7 +799,7 @@ exports.OrientationComponent = __decorate([
|
|
|
799
799
|
EFFECTS.registerPlugin("orientation-transformer", OrientationPluginLoader, EFFECTS.VFXItem);
|
|
800
800
|
/**
|
|
801
801
|
* 插件版本号
|
|
802
|
-
*/ var version = "2.7.
|
|
802
|
+
*/ var version = "2.7.4";
|
|
803
803
|
EFFECTS.logger.info("Plugin orientation transformer version: " + version + ".");
|
|
804
804
|
if (version !== EFFECTS__namespace.version) {
|
|
805
805
|
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.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.7.2";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.7.4
|
|
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.7.4";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.7.
|
|
6
|
+
* Version: v2.7.4
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import * as EFFECTS from '@galacean/effects';
|
|
@@ -776,7 +776,7 @@ OrientationComponent = __decorate([
|
|
|
776
776
|
registerPlugin("orientation-transformer", OrientationPluginLoader, VFXItem);
|
|
777
777
|
/**
|
|
778
778
|
* 插件版本号
|
|
779
|
-
*/ var version = "2.7.
|
|
779
|
+
*/ var version = "2.7.4";
|
|
780
780
|
logger.info("Plugin orientation transformer version: " + version + ".");
|
|
781
781
|
if (version !== EFFECTS.version) {
|
|
782
782
|
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.7.
|
|
3
|
+
"version": "2.7.4",
|
|
4
4
|
"description": "Galacean Effects player orientation transformer plugin",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"typesVersions": {
|
|
25
25
|
"*": {
|
|
26
|
-
"
|
|
26
|
+
"*": [
|
|
27
27
|
"./dist/index.d.ts"
|
|
28
28
|
]
|
|
29
29
|
}
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"registry": "https://registry.npmjs.org"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@galacean/effects": "2.7.
|
|
46
|
+
"@galacean/effects": "2.7.4"
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|
|
49
49
|
"dev": "vite",
|