@galacean/effects-plugin-orientation-transformer 2.0.0-alpha.7 → 2.0.0-alpha.8
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/index.js +2 -2
- package/dist/index.min.js +2 -2
- package/dist/index.mjs +2 -2
- package/package.json +2 -2
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.
|
|
6
|
+
* Version: v2.0.0-alpha.8
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
'use strict';
|
|
@@ -820,7 +820,7 @@ function openDeviceMotion() {
|
|
|
820
820
|
}
|
|
821
821
|
|
|
822
822
|
effects.registerPlugin("orientation-transformer", OrientationPluginLoader, TransformVFXItem);
|
|
823
|
-
var version = "2.0.0-alpha.
|
|
823
|
+
var version = "2.0.0-alpha.8";
|
|
824
824
|
effects.logger.info("plugin orientation transformer version: " + version);
|
|
825
825
|
|
|
826
826
|
exports.OrientationAdapterAcceler = OrientationAdapterAcceler;
|
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.
|
|
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,o,r=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.content.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),s=function(t){function e(e,n){var a;return(a=t.call(this,e,n)||this).addComponent(r).fromData(n),a}return a(e,t),e}(e.VFXItem),c=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;this.currentEvent={x:e,y:n}},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(),o=this.currentPos[n.name],r=this.currentRot[n.name];this.records[n.name]={item:n,position:a,rotation:i},o&&n.transform.setPosition(o[0],o[1],o[2]),r&&n.transform.setRotation(r[0],r[1],r[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=null==(g=this.records[t])?void 0:g.item;if(i){var o=this.records[t].position,r=this.records[t].rotation,s=this.targets[t],c=h(n,this.betaRange),l=h(a,this.gammaRange);if(s){var u,f,m,d,p,v,g,b,y,M=[o[0]+1.2*(u=(c-this.gammaRange[0])/(this.gammaRange[1]-this.gammaRange[0]),(f=s.xMin)+(s.xMax-f)*u),o[1]+1.2*(m=(l-this.betaRange[0])/(this.betaRange[1]-this.betaRange[0]),(d=s.yMin)+(s.yMax-d)*m),o[2]],w=(h(2*n,this.betaRange)-this.betaRange[0])/(this.betaRange[1]-this.betaRange[0]),R=(h(2*a-45,this.gammaRange)-this.gammaRange[0])/(this.gammaRange[1]-this.gammaRange[0]),x=[r[0]+((p=s.hMin)+(s.hMax-p)*R),r[1]+((v=s.vMin)+(s.vMax-v)*w),r[2]];(b=i.transform).setPosition.apply(b,[].concat(M)),(y=i.transform).setRotation.apply(y,[].concat(x)),this.currentPos[t]=M.slice(),this.currentRot[t]=x.slice()}}},t}();function h(t,e){return t<e[0]?e[0]:t>e[1]?e[1]:t}function l(t){return Object.prototype.toString.call(t)}function u(t,e){var n=!0,a=!0,i=!0;if("[object Array]"===l(e.alpha)&&e.alpha.length>=2){var o=t.alpha+e.alpha[0],r=t.alpha+e.alpha[1];n=(o=o<0?o+360:o)<(r=r>360?r-360:r)?t.alpha>o&&t.alpha<r:t.alpha>o||t.alpha<r}return"[object Array]"===l(e.beta)&&e.beta.length>=2&&(a=t.beta>=e.beta[0]&&t.beta<=e.beta[1]),"[object Array]"===l(e.gamma)&&e.gamma.length>=2&&(i=t.gamma>=e.gamma[0]&&t.gamma<=e.gamma[1]),n&&a&&i}function f(){return(f=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 m=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,o=0,r=0,s=0,c=0,h=0;h<e.length;h++)i+=t[h],o+=e[h],r+=t[h]*e[h],s+=t[h]*t[h],c+=e[h]*e[h];var l=i/a,u=o/a;return n.a=(r-a*l*u)/(s-a*l*l),n.b=u-n.a*l,n.miss=Math.pow((a*r-i*o)/Math.sqrt((a*s-i*i)*(a*c-o*o)),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}(),d=((i=navigator.userAgent.toLowerCase().match(/cpu (iphone )?os (.*?) like mac os/))?parseInt(i[2],10):0)&&void 0!==window.AlipayJSBridge,p=void 0!==window.WindVane,v={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},g=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):f({},n),o=arguments.length,r=1;r<o;r++){var s=arguments[r]||{};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===o)for(var h in i)e.isObject(i[h])&&i.hasOwnProperty(h)&&(i[h]=t(i[h]));return i}(v,t);var n=this.options.stableRange;this.filterX=new m({stableRange:n}),this.filterY=new m({stableRange:n})}var n=t.prototype;return n.watch=function(t){var e,n,a,i,o,r,s,c=this;if("function"==typeof t&&!this.watchListener){var h=0,l=0,f=0,m=0,v=function(h){!c.stoped&&(e=h.alpha,n=h.beta,a=h.gamma,m||(m=n||0),f||(f=a||0),u.call(c,{alpha:e,beta:n,gamma:a},c.options.validRange)&&(c.options.X?(i=a-f,r=c.options.relativeGamma?i:a,r=c.filterX.stableFix(r),r=c.filterX.changeLimit(r),r=c.filterX.linearRegressionMedian(+r)):r=0,c.options.Y?(o=n-m,s=c.options.relativeBeta?o:n,s=c.filterY.stableFix(s),s=c.filterY.changeLimit(s),s=c.filterY.linearRegressionMedian(+s)):s=0,c.isValid(r,s)&&(c.options.useRequestAnimationFrame?window.requestAnimationFrame(function(){t(r,s,{alpha:e,beta:n,gamma:a})}):t(r,s,{alpha:e,beta:n,gamma:a}),c.lastX=r,c.lastY=s)))};this.stoped=!1,p?(y(!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},v({alpha:180*+i,beta:-90*+a,gamma:90*+n}))}},document.addEventListener("motion.gyro",this.watchListener,!1)):d?(b(!0,this.options.interval/1e3),this.watchListener=function(t){if(t&&"data"in t){var e=t.data,n=e.x,a=e.y;v({alpha:180*e.z,beta:-90*a,gamma:90*n})}},document.addEventListener("accelerometerChange",this.watchListener,!1)):(this.watchListener=function(t){(l=new Date().getTime())-h>=c.options.interval&&(h=l,v(t))},window.addEventListener("deviceorientation",this.watchListener,!1))}},n.unWatch=function(){e.assertExist(this.watchListener),p?(y(!1),document.removeEventListener("motion.gyro",this.watchListener)):d?(b(!1),document.removeEventListener("accelerometerChange",this.watchListener)):window.removeEventListener("deviceorientation",this.watchListener),this.stoped=!0,this.watchListener=void 0},n.pause=function(){this.stoped=!0,d&&b(!1)},n.continue=function(){this.stoped=!1,d&&b(!0,this.options.interval/1e3)},n.isValid=function(t,e){return this.lastX!==t||this.lastY!==e},t}();function b(t,e){window.AlipayJSBridge.call("watchShake",{monitorGyroscope:!1,monitorAccelerometer:!!t,interval:t?parseFloat(e.toFixed(3)):10},function(){})}function y(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 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 g({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){t.dispatchMotion({x:e,y:n})})),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}(),w=function(t){function e(){var e;return e=t.apply(this,arguments)||this,e.order=90,e.adapter=null,e.handleConnect=function(){if(!R){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=x(),null==(t=this.adapter)||t.connect(),this.bindAccelerDocumentEvent()},n.onCompositionReset=function(t){var e,n=t.loaderData.deviceTransformer=new c(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(){x().disconnect(),this.unbindAccelerDocumentEvent()},e}(e.AbstractPlugin),R=!1;function x(){return o||(o=new M),o}e.registerPlugin("orientation-transformer",w,s);var A="2.0.0-alpha.7";e.logger.info("plugin orientation transformer version: "+A),t.OrientationAdapterAcceler=M,t.closeDeviceMotion=function(){R=!0,x().disconnect()},t.getAdapter=x,t.openDeviceMotion=function(){R=!1,x().connect()},t.version=A,Object.defineProperty(t,"__esModule",{value:!0})});
|
|
6
|
+
* Version: v2.0.0-alpha.8
|
|
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,o,r=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.content.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),s=function(t){function e(e,n){var a;return(a=t.call(this,e,n)||this).addComponent(r).fromData(n),a}return a(e,t),e}(e.VFXItem),c=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;this.currentEvent={x:e,y:n}},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(),o=this.currentPos[n.name],r=this.currentRot[n.name];this.records[n.name]={item:n,position:a,rotation:i},o&&n.transform.setPosition(o[0],o[1],o[2]),r&&n.transform.setRotation(r[0],r[1],r[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=null==(g=this.records[t])?void 0:g.item;if(i){var o=this.records[t].position,r=this.records[t].rotation,s=this.targets[t],c=h(n,this.betaRange),l=h(a,this.gammaRange);if(s){var u,f,m,d,p,v,g,b,y,M=[o[0]+1.2*(u=(c-this.gammaRange[0])/(this.gammaRange[1]-this.gammaRange[0]),(f=s.xMin)+(s.xMax-f)*u),o[1]+1.2*(m=(l-this.betaRange[0])/(this.betaRange[1]-this.betaRange[0]),(d=s.yMin)+(s.yMax-d)*m),o[2]],w=(h(2*n,this.betaRange)-this.betaRange[0])/(this.betaRange[1]-this.betaRange[0]),R=(h(2*a-45,this.gammaRange)-this.gammaRange[0])/(this.gammaRange[1]-this.gammaRange[0]),x=[r[0]+((p=s.hMin)+(s.hMax-p)*R),r[1]+((v=s.vMin)+(s.vMax-v)*w),r[2]];(b=i.transform).setPosition.apply(b,[].concat(M)),(y=i.transform).setRotation.apply(y,[].concat(x)),this.currentPos[t]=M.slice(),this.currentRot[t]=x.slice()}}},t}();function h(t,e){return t<e[0]?e[0]:t>e[1]?e[1]:t}function l(t){return Object.prototype.toString.call(t)}function u(t,e){var n=!0,a=!0,i=!0;if("[object Array]"===l(e.alpha)&&e.alpha.length>=2){var o=t.alpha+e.alpha[0],r=t.alpha+e.alpha[1];n=(o=o<0?o+360:o)<(r=r>360?r-360:r)?t.alpha>o&&t.alpha<r:t.alpha>o||t.alpha<r}return"[object Array]"===l(e.beta)&&e.beta.length>=2&&(a=t.beta>=e.beta[0]&&t.beta<=e.beta[1]),"[object Array]"===l(e.gamma)&&e.gamma.length>=2&&(i=t.gamma>=e.gamma[0]&&t.gamma<=e.gamma[1]),n&&a&&i}function f(){return(f=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 m=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,o=0,r=0,s=0,c=0,h=0;h<e.length;h++)i+=t[h],o+=e[h],r+=t[h]*e[h],s+=t[h]*t[h],c+=e[h]*e[h];var l=i/a,u=o/a;return n.a=(r-a*l*u)/(s-a*l*l),n.b=u-n.a*l,n.miss=Math.pow((a*r-i*o)/Math.sqrt((a*s-i*i)*(a*c-o*o)),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}(),d=((i=navigator.userAgent.toLowerCase().match(/cpu (iphone )?os (.*?) like mac os/))?parseInt(i[2],10):0)&&void 0!==window.AlipayJSBridge,p=void 0!==window.WindVane,v={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},g=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):f({},n),o=arguments.length,r=1;r<o;r++){var s=arguments[r]||{};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===o)for(var h in i)e.isObject(i[h])&&i.hasOwnProperty(h)&&(i[h]=t(i[h]));return i}(v,t);var n=this.options.stableRange;this.filterX=new m({stableRange:n}),this.filterY=new m({stableRange:n})}var n=t.prototype;return n.watch=function(t){var e,n,a,i,o,r,s,c=this;if("function"==typeof t&&!this.watchListener){var h=0,l=0,f=0,m=0,v=function(h){!c.stoped&&(e=h.alpha,n=h.beta,a=h.gamma,m||(m=n||0),f||(f=a||0),u.call(c,{alpha:e,beta:n,gamma:a},c.options.validRange)&&(c.options.X?(i=a-f,r=c.options.relativeGamma?i:a,r=c.filterX.stableFix(r),r=c.filterX.changeLimit(r),r=c.filterX.linearRegressionMedian(+r)):r=0,c.options.Y?(o=n-m,s=c.options.relativeBeta?o:n,s=c.filterY.stableFix(s),s=c.filterY.changeLimit(s),s=c.filterY.linearRegressionMedian(+s)):s=0,c.isValid(r,s)&&(c.options.useRequestAnimationFrame?window.requestAnimationFrame(function(){t(r,s,{alpha:e,beta:n,gamma:a})}):t(r,s,{alpha:e,beta:n,gamma:a}),c.lastX=r,c.lastY=s)))};this.stoped=!1,p?(y(!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},v({alpha:180*+i,beta:-90*+a,gamma:90*+n}))}},document.addEventListener("motion.gyro",this.watchListener,!1)):d?(b(!0,this.options.interval/1e3),this.watchListener=function(t){if(t&&"data"in t){var e=t.data,n=e.x,a=e.y;v({alpha:180*e.z,beta:-90*a,gamma:90*n})}},document.addEventListener("accelerometerChange",this.watchListener,!1)):(this.watchListener=function(t){(l=new Date().getTime())-h>=c.options.interval&&(h=l,v(t))},window.addEventListener("deviceorientation",this.watchListener,!1))}},n.unWatch=function(){e.assertExist(this.watchListener),p?(y(!1),document.removeEventListener("motion.gyro",this.watchListener)):d?(b(!1),document.removeEventListener("accelerometerChange",this.watchListener)):window.removeEventListener("deviceorientation",this.watchListener),this.stoped=!0,this.watchListener=void 0},n.pause=function(){this.stoped=!0,d&&b(!1)},n.continue=function(){this.stoped=!1,d&&b(!0,this.options.interval/1e3)},n.isValid=function(t,e){return this.lastX!==t||this.lastY!==e},t}();function b(t,e){window.AlipayJSBridge.call("watchShake",{monitorGyroscope:!1,monitorAccelerometer:!!t,interval:t?parseFloat(e.toFixed(3)):10},function(){})}function y(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 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 g({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){t.dispatchMotion({x:e,y:n})})),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}(),w=function(t){function e(){var e;return e=t.apply(this,arguments)||this,e.order=90,e.adapter=null,e.handleConnect=function(){if(!R){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=x(),null==(t=this.adapter)||t.connect(),this.bindAccelerDocumentEvent()},n.onCompositionReset=function(t){var e,n=t.loaderData.deviceTransformer=new c(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(){x().disconnect(),this.unbindAccelerDocumentEvent()},e}(e.AbstractPlugin),R=!1;function x(){return o||(o=new M),o}e.registerPlugin("orientation-transformer",w,s);var A="2.0.0-alpha.8";e.logger.info("plugin orientation transformer version: "+A),t.OrientationAdapterAcceler=M,t.closeDeviceMotion=function(){R=!0,x().disconnect()},t.getAdapter=x,t.openDeviceMotion=function(){R=!1,x().connect()},t.version=A,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.
|
|
6
|
+
* Version: v2.0.0-alpha.8
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { ItemBehaviour, VFXItem, isObject, isArray, assertExist, AbstractPlugin, registerPlugin, logger } from '@galacean/effects';
|
|
@@ -816,7 +816,7 @@ function openDeviceMotion() {
|
|
|
816
816
|
}
|
|
817
817
|
|
|
818
818
|
registerPlugin("orientation-transformer", OrientationPluginLoader, TransformVFXItem);
|
|
819
|
-
var version = "2.0.0-alpha.
|
|
819
|
+
var version = "2.0.0-alpha.8";
|
|
820
820
|
logger.info("plugin orientation transformer version: " + version);
|
|
821
821
|
|
|
822
822
|
export { OrientationAdapterAcceler, closeDeviceMotion, getAdapter, openDeviceMotion, version };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@galacean/effects-plugin-orientation-transformer",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.8",
|
|
4
4
|
"description": "Galacean Effects player orientation transformer plugin",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"registry": "https://registry.npmjs.org"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@galacean/effects": "2.0.0-alpha.
|
|
34
|
+
"@galacean/effects": "2.0.0-alpha.8"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
37
|
"dev": "vite",
|