@galacean/effects-plugin-orientation-transformer 1.4.0 → 1.4.2

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.
@@ -1,8 +1,5 @@
1
1
  import type { Composition, spec } from '@galacean/effects';
2
- type EventType = {
3
- x: number;
4
- y: number;
5
- };
2
+ import type { AccelerMotionData } from './orientation-adapter-acceler';
6
3
  export declare class CompositionTransformerAcceler {
7
4
  private readonly composition;
8
5
  private readonly targets;
@@ -13,11 +10,10 @@ export declare class CompositionTransformerAcceler {
13
10
  private betaRange;
14
11
  private currentEvent?;
15
12
  constructor(composition: Composition);
16
- update({ x, y }: EventType): void;
13
+ update({ x, y, beta, gamma }: AccelerMotionData): void;
17
14
  updateOrientation(): void;
18
15
  initComposition(): void;
19
16
  addTarget(target: spec.PluginGyroscopeTarget): void;
20
17
  removeTarget(name: string): void;
21
18
  private moveLayer;
22
19
  }
23
- export {};
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: v1.4.0
6
+ * Version: v1.4.2
7
7
  */
8
8
 
9
9
  'use strict';
@@ -86,55 +86,6 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
86
86
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
87
87
  };
88
88
 
89
- /**
90
- * 水平旋转变化起始角(手机处于改角度时无变化)
91
- * 待调试
92
- */
93
- var VERTICAL_INIT_DEGREE = 45;
94
- var TransformVFXItem = /** @class */ (function (_super) {
95
- __extends(TransformVFXItem, _super);
96
- function TransformVFXItem() {
97
- return _super !== null && _super.apply(this, arguments) || this;
98
- }
99
- Object.defineProperty(TransformVFXItem.prototype, "type", {
100
- get: function () {
101
- return 'orientation-transformer';
102
- },
103
- enumerable: false,
104
- configurable: true
105
- });
106
- TransformVFXItem.prototype.onConstructed = function (options) {
107
- var targets = options.content.options.targets;
108
- if (targets) {
109
- this.targets = targets.map(function (t) { return ({
110
- name: t.name,
111
- xMin: +t.xMin || 0,
112
- yMin: +t.yMin || 0,
113
- xMax: +t.xMax || 0,
114
- yMax: +t.yMax || 0,
115
- vMin: +t.vMin || 0,
116
- hMin: +t.hMin || 0,
117
- vMax: +t.vMax || 0,
118
- hMax: +t.hMax || 0,
119
- }); });
120
- }
121
- };
122
- TransformVFXItem.prototype.onItemRemoved = function (composition) {
123
- var _a;
124
- (_a = this.targets) === null || _a === void 0 ? void 0 : _a.forEach(function (target) { var _a; return (_a = composition.loaderData.deviceTransformer) === null || _a === void 0 ? void 0 : _a.removeTarget(target.name); });
125
- };
126
- TransformVFXItem.prototype.doCreateContent = function (composition) {
127
- var _a;
128
- var transformer = composition.loaderData.deviceTransformer;
129
- if (transformer) {
130
- (_a = this.targets) === null || _a === void 0 ? void 0 : _a.forEach(function (target) { return transformer.addTarget(target); });
131
- transformer.initComposition();
132
- }
133
- return {};
134
- };
135
- return TransformVFXItem;
136
- }(effects.VFXItem));
137
-
138
89
  var CompositionTransformerAcceler = /** @class */ (function () {
139
90
  function CompositionTransformerAcceler(composition) {
140
91
  this.composition = composition;
@@ -146,8 +97,8 @@ var CompositionTransformerAcceler = /** @class */ (function () {
146
97
  this.betaRange = [-89, 89];
147
98
  }
148
99
  CompositionTransformerAcceler.prototype.update = function (_a) {
149
- var x = _a.x, y = _a.y;
150
- this.currentEvent = { x: x, y: y };
100
+ var x = _a.x, y = _a.y, beta = _a.beta, gamma = _a.gamma;
101
+ this.currentEvent = { x: x, y: y, beta: beta, gamma: gamma };
151
102
  };
152
103
  CompositionTransformerAcceler.prototype.updateOrientation = function () {
153
104
  var _this = this;
@@ -192,7 +143,7 @@ var CompositionTransformerAcceler = /** @class */ (function () {
192
143
  CompositionTransformerAcceler.prototype.moveLayer = function (name, _a) {
193
144
  var _b, _c;
194
145
  var _d;
195
- var x = _a.x, y = _a.y;
146
+ var x = _a.x, y = _a.y, b = _a.beta, g = _a.gamma;
196
147
  var layer = (_d = this.records[name]) === null || _d === void 0 ? void 0 : _d.item;
197
148
  if (layer) {
198
149
  var initPosition = this.records[name].position;
@@ -201,17 +152,18 @@ var CompositionTransformerAcceler = /** @class */ (function () {
201
152
  var beta = clamp(x, this.betaRange), gamma = clamp(y, this.gammaRange);
202
153
  if (target) {
203
154
  var position = [
204
- initPosition[0] + 1.2 * mapRange((beta - this.gammaRange[0]) / (this.gammaRange[1] - this.gammaRange[0]), target.xMin, target.xMax),
205
- initPosition[1] + 1.2 * mapRange((gamma - this.betaRange[0]) / (this.betaRange[1] - this.betaRange[0]), target.yMin, target.yMax),
155
+ initPosition[0] + 1.2 * mapRange(normalize(beta, this.gammaRange[0], this.gammaRange[1]), target.xMin, target.xMax),
156
+ initPosition[1] + 1.2 * mapRange(normalize(gamma, this.betaRange[0], this.betaRange[1]), target.yMin, target.yMax),
206
157
  initPosition[2],
207
158
  ];
208
- var br = (clamp(x * 2, this.betaRange) - this.betaRange[0]) / (this.betaRange[1] - this.betaRange[0]);
209
- var gr = (clamp(y * 2 - VERTICAL_INIT_DEGREE, this.gammaRange) - this.gammaRange[0]) / (this.gammaRange[1] - this.gammaRange[0]);
159
+ var br = normalize(clamp(g * 0.8, this.gammaRange), this.gammaRange[0], this.gammaRange[1]);
160
+ var gr = normalize(clamp(b * 0.8, this.betaRange), this.betaRange[0], this.betaRange[1]);
210
161
  var rotation = [
211
162
  initRotation[0] + mapRange(gr, target.hMin, target.hMax),
212
163
  initRotation[1] + mapRange(br, target.vMin, target.vMax),
213
164
  initRotation[2],
214
165
  ];
166
+ // console.log(y, initY, y - initY);
215
167
  (_b = layer.transform).setPosition.apply(_b, __spreadArray([], __read(position), false));
216
168
  (_c = layer.transform).setRotation.apply(_c, __spreadArray([], __read(rotation), false));
217
169
  this.currentPos[name] = position.slice();
@@ -233,6 +185,9 @@ function clamp(x, range) {
233
185
  function mapRange(t, min, max) {
234
186
  return min + (max - min) * t;
235
187
  }
188
+ function normalize(a, min, max) {
189
+ return (a - min) / (max - min);
190
+ }
236
191
 
237
192
  function getObjectType(obj) {
238
193
  return Object.prototype.toString.call(obj);
@@ -484,13 +439,11 @@ var DeviceOrientation = /** @class */ (function () {
484
439
  }
485
440
  var timefragment = 0; // 时间片计时
486
441
  var nowts = 0; // 当前时间
487
- var referGamma = 0; // 初始化角度,作为单独一个用户的空间旋转的参照
488
- var referBeta = 0;
442
+ // 初始化角度,作为单独一个用户的空间旋转的参照
443
+ var referGamma = NaN, referBeta = NaN;
489
444
  var alpha;
490
445
  var beta;
491
446
  var gamma;
492
- var gammaFixed;
493
- var betaFixed;
494
447
  var isInValidDegRange;
495
448
  var x; // 最终输出的 x
496
449
  var y; // 最终输出的 y
@@ -501,23 +454,23 @@ var DeviceOrientation = /** @class */ (function () {
501
454
  alpha = e.alpha; // 垂直于屏幕的轴 0 ~ 360
502
455
  beta = e.beta; // 横向 X 轴 -180 ~ 180
503
456
  gamma = e.gamma; // 纵向 Y 轴 -90 ~ 90
504
- if (!referBeta) {
505
- referBeta = beta || 0;
506
- }
507
- if (!referGamma) {
508
- referGamma = gamma || 0;
509
- }
510
- //
511
457
  isInValidDegRange = angleLimit.call(_this, {
512
458
  alpha: alpha,
513
459
  beta: beta,
514
460
  gamma: gamma,
515
461
  }, _this.options.validRange);
462
+ if (isNaN(referGamma)) {
463
+ referGamma = gamma;
464
+ _this.filterX.lastValue = gamma;
465
+ }
466
+ if (isNaN(referBeta)) {
467
+ referBeta = beta;
468
+ _this.filterY.lastValue = beta;
469
+ }
516
470
  if (isInValidDegRange) {
517
471
  // 最终结果值
518
472
  if (_this.options.X) {
519
- gammaFixed = gamma - referGamma;
520
- x = _this.options.relativeGamma ? gammaFixed : gamma;
473
+ x = _this.options.relativeGamma ? gamma - referGamma : gamma;
521
474
  x = _this.filterX.stableFix(x);
522
475
  x = _this.filterX.changeLimit(x);
523
476
  x = _this.filterX.linearRegressionMedian(+x);
@@ -526,9 +479,7 @@ var DeviceOrientation = /** @class */ (function () {
526
479
  x = 0;
527
480
  }
528
481
  if (_this.options.Y) {
529
- // beta 相对 referBeta 的角度
530
- betaFixed = beta - referBeta;
531
- y = _this.options.relativeBeta ? betaFixed : beta;
482
+ y = _this.options.relativeBeta ? beta - referBeta : beta;
532
483
  y = _this.filterY.stableFix(y);
533
484
  y = _this.filterY.changeLimit(y);
534
485
  y = _this.filterY.linearRegressionMedian(+y);
@@ -539,11 +490,11 @@ var DeviceOrientation = /** @class */ (function () {
539
490
  if (_this.isValid(x, y)) {
540
491
  if (_this.options.useRequestAnimationFrame) {
541
492
  window.requestAnimationFrame(function () {
542
- callback(x, y, { alpha: alpha, beta: beta, gamma: gamma });
493
+ callback(x, y, { alpha: alpha, beta: y - referBeta, gamma: x - referGamma });
543
494
  });
544
495
  }
545
496
  else {
546
- callback(x, y, { alpha: alpha, beta: beta, gamma: gamma });
497
+ callback(x, y, { alpha: alpha, beta: y - referBeta, gamma: x - referGamma });
547
498
  }
548
499
  _this.lastX = x;
549
500
  _this.lastY = y;
@@ -692,10 +643,13 @@ var OrientationAdapterAcceler = /** @class */ (function () {
692
643
  validRange: this.validRange,
693
644
  stableRange: 3, // 稳定区间
694
645
  });
695
- this.accelerMotion.watch(function (x, y) {
646
+ this.accelerMotion.watch(function (x, y, _a) {
647
+ var beta = _a.beta, gamma = _a.gamma;
696
648
  var motion = {
697
649
  x: x,
698
650
  y: y,
651
+ beta: beta,
652
+ gamma: gamma,
699
653
  };
700
654
  _this.dispatchMotion(motion);
701
655
  });
@@ -815,8 +769,52 @@ function openDeviceMotion() {
815
769
  getAdapter().connect();
816
770
  }
817
771
 
772
+ var TransformVFXItem = /** @class */ (function (_super) {
773
+ __extends(TransformVFXItem, _super);
774
+ function TransformVFXItem() {
775
+ return _super !== null && _super.apply(this, arguments) || this;
776
+ }
777
+ Object.defineProperty(TransformVFXItem.prototype, "type", {
778
+ get: function () {
779
+ return 'orientation-transformer';
780
+ },
781
+ enumerable: false,
782
+ configurable: true
783
+ });
784
+ TransformVFXItem.prototype.onConstructed = function (options) {
785
+ var targets = options.content.options.targets;
786
+ if (targets) {
787
+ this.targets = targets.map(function (t) { return ({
788
+ name: t.name,
789
+ xMin: +t.xMin || 0,
790
+ yMin: +t.yMin || 0,
791
+ xMax: +t.xMax || 0,
792
+ yMax: +t.yMax || 0,
793
+ vMin: +t.vMin || 0,
794
+ hMin: +t.hMin || 0,
795
+ vMax: +t.vMax || 0,
796
+ hMax: +t.hMax || 0,
797
+ }); });
798
+ }
799
+ };
800
+ TransformVFXItem.prototype.onItemRemoved = function (composition) {
801
+ var _a;
802
+ (_a = this.targets) === null || _a === void 0 ? void 0 : _a.forEach(function (target) { var _a; return (_a = composition.loaderData.deviceTransformer) === null || _a === void 0 ? void 0 : _a.removeTarget(target.name); });
803
+ };
804
+ TransformVFXItem.prototype.doCreateContent = function (composition) {
805
+ var _a;
806
+ var transformer = composition.loaderData.deviceTransformer;
807
+ if (transformer) {
808
+ (_a = this.targets) === null || _a === void 0 ? void 0 : _a.forEach(function (target) { return transformer.addTarget(target); });
809
+ transformer.initComposition();
810
+ }
811
+ return {};
812
+ };
813
+ return TransformVFXItem;
814
+ }(effects.VFXItem));
815
+
818
816
  effects.registerPlugin('orientation-transformer', OrientationPluginLoader, TransformVFXItem);
819
- var version = "1.4.0";
817
+ var version = "1.4.2";
820
818
  effects.logger.info('plugin orientation transformer version: ' + version);
821
819
 
822
820
  exports.OrientationAdapterAcceler = OrientationAdapterAcceler;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/dist/index.min.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: v1.4.0
6
+ * Version: v1.4.2
7
7
  */
8
- !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=function(t,e){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},n(t,e)};function o(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function o(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(o.prototype=e.prototype,new o)}var r=function(){return r=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},r.apply(this,arguments)};function i(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var o,r,i=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(o=i.next()).done;)a.push(o.value)}catch(t){r={error:t}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}return a}function a(t,e,n){if(n||2===arguments.length)for(var o,r=0,i=e.length;r<i;r++)!o&&r in e||(o||(o=Array.prototype.slice.call(e,0,r)),o[r]=e[r]);return t.concat(o||Array.prototype.slice.call(e))}"function"==typeof SuppressedError&&SuppressedError;var s=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return o(e,t),Object.defineProperty(e.prototype,"type",{get:function(){return"orientation-transformer"},enumerable:!1,configurable:!0}),e.prototype.onConstructed=function(t){var e=t.content.options.targets;e&&(this.targets=e.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}})))},e.prototype.onItemRemoved=function(t){var e;null===(e=this.targets)||void 0===e||e.forEach((function(e){var n;return null===(n=t.loaderData.deviceTransformer)||void 0===n?void 0:n.removeTarget(e.name)}))},e.prototype.doCreateContent=function(t){var e,n=t.loaderData.deviceTransformer;return n&&(null===(e=this.targets)||void 0===e||e.forEach((function(t){return n.addTarget(t)})),n.initComposition()),{}},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]}return t.prototype.update=function(t){var e=t.x,n=t.y;this.currentEvent={x:e,y:n}},t.prototype.updateOrientation=function(){var t=this,e=this.currentEvent;e&&Object.getOwnPropertyNames(this.targets).forEach((function(n){t.moveLayer(n,e)}))},t.prototype.initComposition=function(){for(var t=this.composition.items,e=0;e<t.length;e++){var n=t[e];if(this.targets[n.name]){var o=n.transform.position.toArray(),r=n.transform.rotation.toArray(),i=this.currentPos[n.name],a=this.currentRot[n.name];this.records[n.name]={item:n,position:o,rotation:r},i&&n.transform.setPosition(i[0],i[1],i[2]),a&&n.transform.setRotation(a[0],a[1],a[2])}}},t.prototype.addTarget=function(t){this.targets[t.name]=t},t.prototype.removeTarget=function(t){delete this.targets[t],delete this.records[t]},t.prototype.moveLayer=function(t,e){var n,o,r,s=e.x,c=e.y,h=null===(r=this.records[t])||void 0===r?void 0:r.item;if(h){var p=this.records[t].position,f=this.records[t].rotation,d=this.targets[t],m=l(s,this.betaRange),v=l(c,this.gammaRange);if(d){var g=[p[0]+1.2*u((m-this.gammaRange[0])/(this.gammaRange[1]-this.gammaRange[0]),d.xMin,d.xMax),p[1]+1.2*u((v-this.betaRange[0])/(this.betaRange[1]-this.betaRange[0]),d.yMin,d.yMax),p[2]],y=(l(2*s,this.betaRange)-this.betaRange[0])/(this.betaRange[1]-this.betaRange[0]),b=(l(2*c-45,this.gammaRange)-this.gammaRange[0])/(this.gammaRange[1]-this.gammaRange[0]),w=[f[0]+u(b,d.hMin,d.hMax),f[1]+u(y,d.vMin,d.vMax),f[2]];(n=h.transform).setPosition.apply(n,a([],i(g),!1)),(o=h.transform).setRotation.apply(o,a([],i(w),!1)),this.currentPos[t]=g.slice(),this.currentRot[t]=w.slice()}}},t}();function l(t,e){return t<e[0]?e[0]:t>e[1]?e[1]:t}function u(t,e,n){return e+(n-e)*t}function h(t){return Object.prototype.toString.call(t)}function p(t,e){var n=!0,o=!0,r=!0;if("[object Array]"===h(e.alpha)&&e.alpha.length>=2){var i=t.alpha+e.alpha[0],a=t.alpha+e.alpha[1];n=(i=i<0?i+360:i)<(a=a>360?a-360:a)?t.alpha>i&&t.alpha<a:t.alpha>i||t.alpha<a}return"[object Array]"===h(e.beta)&&e.beta.length>=2&&(o=t.beta>=e.beta[0]&&t.beta<=e.beta[1]),"[object Array]"===h(e.gamma)&&e.gamma.length>=2&&(r=t.gamma>=e.gamma[0]&&t.gamma<=e.gamma[1]),n&&o&&r}function f(t,n){if(!e.isObject(t)&&!e.isArray(t))return t;for(var o=e.isArray(t)?a([],i(t),!1):r({},t),s=arguments.length,c=1;c<s;c++){var l=arguments[c]||{};if(e.isObject(l)){var u=void 0;for(u in l)l.hasOwnProperty(u)&&(e.isObject(o[u])&&e.isObject(l[u])?o[u]=f(o[u],l[u]):e.isObject(l[u])||e.isArray(l[u])?o[u]=f(l[u]):o[u]=l[u]);for(u in o)e.isObject(o[u])&&o.hasOwnProperty(u)&&!l.hasOwnProperty(u)&&(o[u]=f(o[u]))}}if(1===s)for(var u in o)e.isObject(o[u])&&o.hasOwnProperty(u)&&(o[u]=f(o[u]));return o}var d=function(){function t(t){void 0===t&&(t={}),this.options=t,this.lastValue=0,this.valuePool=[]}return t.prototype.stableFix=function(t){var e=this.options.stableRange||3;return Math.abs(t)<e?0:t>e?t-e:t+e},t.prototype.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},t.prototype.linearRegressionMedian=function(t){var e,n,o;return this.valuePool.push(t),this.valuePool.length>=5?(n=this.valuePool,o=function(t){var e=[],n=[];t.forEach((function(t,o){e.push(o),n.push(t)}));var o=function(t,e){for(var n={},o=e.length,r=0,i=0,a=0,s=0,c=0,l=0;l<e.length;l++)r+=t[l],i+=e[l],a+=t[l]*e[l],s+=t[l]*t[l],c+=e[l]*e[l];var u=r/o,h=i/o;return n.a=(a-o*u*h)/(s-o*u*u),n.b=h-n.a*u,n.miss=Math.pow((o*a-r*i)/Math.sqrt((o*s-r*r)*(o*c-i*i)),2),n}(e,n);return function(t){return o.a*t+o.b}}(n),n=n.map((function(t,e){return o(e)})),e=o(n.length/2),this.valuePool.shift()):e=this.lastValue,e},t}();var m,v=((m=navigator.userAgent.toLowerCase().match(/cpu (iphone )?os (.*?) like mac os/))?parseInt(m[2],10):0)&&void 0!==window.AlipayJSBridge,g=void 0!==window.WindVane,y={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},b=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=f(y,t);var e=this.options.stableRange;this.filterX=new d({stableRange:e}),this.filterY=new d({stableRange:e})}return t.prototype.watch=function(t){var e=this;if("function"==typeof t&&!this.watchListener){var n,o,r,i,a,s,c,l=0,u=0,h=0,f=0,d=function(l){e.stoped||(n=l.alpha,o=l.beta,r=l.gamma,f||(f=o||0),h||(h=r||0),p.call(e,{alpha:n,beta:o,gamma:r},e.options.validRange)&&(e.options.X?(i=r-h,s=e.options.relativeGamma?i:r,s=e.filterX.stableFix(s),s=e.filterX.changeLimit(s),s=e.filterX.linearRegressionMedian(+s)):s=0,e.options.Y?(a=o-f,c=e.options.relativeBeta?a:o,c=e.filterY.stableFix(c),c=e.filterY.changeLimit(c),c=e.filterY.linearRegressionMedian(+c)):c=0,e.isValid(s,c)&&(e.options.useRequestAnimationFrame?window.requestAnimationFrame((function(){t(s,c,{alpha:n,beta:o,gamma:r})})):t(s,c,{alpha:n,beta:o,gamma:r}),e.lastX=s,e.lastY=c)))};this.stoped=!1,g?(M(!0,this.options.interval),this.watchListener=function(t){if("param"in t){var n=t.param,o=n.x,r=n.y,i=n.z;if(o===e.prevAcceler.x&&r===e.prevAcceler.y&&i===e.prevAcceler.z)return;e.prevAcceler={x:o,y:r,z:i},d({alpha:180*+i,beta:-90*+r,gamma:90*+o})}},document.addEventListener("motion.gyro",this.watchListener,!1)):v?(w(!0,this.options.interval/1e3),this.watchListener=function(t){if(t&&"data"in t){var e=t.data,n=e.x,o=e.y,r=e.z;d({alpha:180*r,beta:-90*o,gamma:90*n})}},document.addEventListener("accelerometerChange",this.watchListener,!1)):(this.watchListener=function(t){(u=(new Date).getTime())-l>=e.options.interval&&(l=u,d(t))},window.addEventListener("deviceorientation",this.watchListener,!1))}},t.prototype.unWatch=function(){e.assertExist(this.watchListener),g?(M(!1),document.removeEventListener("motion.gyro",this.watchListener)):v?(w(!1),document.removeEventListener("accelerometerChange",this.watchListener)):window.removeEventListener("deviceorientation",this.watchListener),this.stoped=!0,this.watchListener=void 0},t.prototype.pause=function(){this.stoped=!0,v&&w(!1)},t.prototype.continue=function(){this.stoped=!1,v&&w(!0,this.options.interval/1e3)},t.prototype.isValid=function(t,e){return this.lastX!==t||this.lastY!==e},t}();function w(t,e){window.AlipayJSBridge.call("watchShake",{monitorGyroscope:!1,monitorAccelerometer:!!t,interval:t?parseFloat(e.toFixed(3)):10},(function(){}))}function M(t,e){var n={on:t,frequency:e};window.WindVane.call("WVMotion","listenGyro",n,(function(t){console.info("call WVMotion success")}),(function(t){console.error("call WVMotion failed:"+JSON.stringify(t))}))}var R,x=function(){function t(){this.transformers=[],this.connected=!1,this.accelerMotion=null,this.validRange={alpha:[-60,60],beta:[-80,80],gamma:[-89,89]}}return t.prototype.connect=function(){var t=this;this.connected||(this.accelerMotion=new b({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){var o={x:e,y:n};t.dispatchMotion(o)}))),this.connected=!0},t.prototype.disconnect=function(){this.accelerMotion&&this.accelerMotion.unWatch(),this.connected=!1},t.prototype.dispatchMotion=function(t){this.transformers.forEach((function(e){return e.update(t)}))},t.prototype.addTransformer=function(t){this.transformers.includes(t)||this.transformers.push(t)},t.prototype.removeTransformer=function(t){var e=this.transformers.indexOf(t);return e>-1&&this.transformers.splice(e,1),0===this.transformers.length},t}();var A=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.order=90,e.adapter=null,e.handleConnect=function(){var t;L||null===(t=e.adapter)||void 0===t||t.connect()},e.handleDisconnect=function(){var t;null===(t=e.adapter)||void 0===t||t.disconnect()},e}return o(e,t),e.prototype.onCompositionConstructed=function(){var t;this.adapter=O(),null===(t=this.adapter)||void 0===t||t.connect(),this.bindAccelerDocumentEvent()},e.prototype.onCompositionReset=function(t){var e,n=t.loaderData.deviceTransformer=new c(t);null===(e=this.adapter)||void 0===e||e.addTransformer(n)},e.prototype.onCompositionUpdate=function(t){var e=t.loaderData.deviceTransformer;e&&e.updateOrientation()},e.prototype.onCompositionDestroyed=function(t){var e,n;(null===(e=this.adapter)||void 0===e?void 0:e.removeTransformer(t.loaderData.deviceTransformer))&&(null===(n=this.adapter)||void 0===n||n.disconnect())},e.prototype.bindAccelerDocumentEvent=function(){this.unbindAccelerDocumentEvent(),document.addEventListener("resume",this.handleConnect,!1),document.addEventListener("pause",this.handleDisconnect,!1),document.addEventListener("back",this.handleDisconnect,!1)},e.prototype.unbindAccelerDocumentEvent=function(){document.removeEventListener("resume",this.handleConnect),document.removeEventListener("pause",this.handleDisconnect),document.removeEventListener("back",this.handleDisconnect)},e.prototype.dispose=function(){O().disconnect(),this.unbindAccelerDocumentEvent()},e}(e.AbstractPlugin),L=!1;function O(){return R||(R=new x),R}e.registerPlugin("orientation-transformer",A,s);var E="1.4.0";e.logger.info("plugin orientation transformer version: "+E),t.OrientationAdapterAcceler=x,t.closeDeviceMotion=function(){L=!0,O().disconnect()},t.getAdapter=O,t.openDeviceMotion=function(){L=!1,O().connect()},t.version=E,Object.defineProperty(t,"__esModule",{value:!0})}));
8
+ !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=function(t,e){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},n(t,e)};function o(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function o(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(o.prototype=e.prototype,new o)}var a=function(){return a=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var a in e=arguments[n])Object.prototype.hasOwnProperty.call(e,a)&&(t[a]=e[a]);return t},a.apply(this,arguments)};function r(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var o,a,r=n.call(t),i=[];try{for(;(void 0===e||e-- >0)&&!(o=r.next()).done;)i.push(o.value)}catch(t){a={error:t}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(a)throw a.error}}return i}function i(t,e,n){if(n||2===arguments.length)for(var o,a=0,r=e.length;a<r;a++)!o&&a in e||(o||(o=Array.prototype.slice.call(e,0,a)),o[a]=e[a]);return t.concat(o||Array.prototype.slice.call(e))}"function"==typeof SuppressedError&&SuppressedError;var s=function(){function t(t){this.composition=t,this.targets={},this.records={},this.currentPos={},this.currentRot={},this.gammaRange=[-89,89],this.betaRange=[-89,89]}return t.prototype.update=function(t){var e=t.x,n=t.y,o=t.beta,a=t.gamma;this.currentEvent={x:e,y:n,beta:o,gamma:a}},t.prototype.updateOrientation=function(){var t=this,e=this.currentEvent;e&&Object.getOwnPropertyNames(this.targets).forEach((function(n){t.moveLayer(n,e)}))},t.prototype.initComposition=function(){for(var t=this.composition.items,e=0;e<t.length;e++){var n=t[e];if(this.targets[n.name]){var o=n.transform.position.toArray(),a=n.transform.rotation.toArray(),r=this.currentPos[n.name],i=this.currentRot[n.name];this.records[n.name]={item:n,position:o,rotation:a},r&&n.transform.setPosition(r[0],r[1],r[2]),i&&n.transform.setRotation(i[0],i[1],i[2])}}},t.prototype.addTarget=function(t){this.targets[t.name]=t},t.prototype.removeTarget=function(t){delete this.targets[t],delete this.records[t]},t.prototype.moveLayer=function(t,e){var n,o,a,s=e.x,h=e.y,p=e.beta,f=e.gamma,m=null===(a=this.records[t])||void 0===a?void 0:a.item;if(m){var d=this.records[t].position,v=this.records[t].rotation,g=this.targets[t],y=c(s,this.betaRange),b=c(h,this.gammaRange);if(g){var w=[d[0]+1.2*l(u(y,this.gammaRange[0],this.gammaRange[1]),g.xMin,g.xMax),d[1]+1.2*l(u(b,this.betaRange[0],this.betaRange[1]),g.yMin,g.yMax),d[2]],M=u(c(.8*f,this.gammaRange),this.gammaRange[0],this.gammaRange[1]),x=u(c(.8*p,this.betaRange),this.betaRange[0],this.betaRange[1]),R=[v[0]+l(x,g.hMin,g.hMax),v[1]+l(M,g.vMin,g.vMax),v[2]];(n=m.transform).setPosition.apply(n,i([],r(w),!1)),(o=m.transform).setRotation.apply(o,i([],r(R),!1)),this.currentPos[t]=w.slice(),this.currentRot[t]=R.slice()}}},t}();function c(t,e){return t<e[0]?e[0]:t>e[1]?e[1]:t}function l(t,e,n){return e+(n-e)*t}function u(t,e,n){return(t-e)/(n-e)}function h(t){return Object.prototype.toString.call(t)}function p(t,e){var n=!0,o=!0,a=!0;if("[object Array]"===h(e.alpha)&&e.alpha.length>=2){var r=t.alpha+e.alpha[0],i=t.alpha+e.alpha[1];n=(r=r<0?r+360:r)<(i=i>360?i-360:i)?t.alpha>r&&t.alpha<i:t.alpha>r||t.alpha<i}return"[object Array]"===h(e.beta)&&e.beta.length>=2&&(o=t.beta>=e.beta[0]&&t.beta<=e.beta[1]),"[object Array]"===h(e.gamma)&&e.gamma.length>=2&&(a=t.gamma>=e.gamma[0]&&t.gamma<=e.gamma[1]),n&&o&&a}function f(t,n){if(!e.isObject(t)&&!e.isArray(t))return t;for(var o=e.isArray(t)?i([],r(t),!1):a({},t),s=arguments.length,c=1;c<s;c++){var l=arguments[c]||{};if(e.isObject(l)){var u=void 0;for(u in l)l.hasOwnProperty(u)&&(e.isObject(o[u])&&e.isObject(l[u])?o[u]=f(o[u],l[u]):e.isObject(l[u])||e.isArray(l[u])?o[u]=f(l[u]):o[u]=l[u]);for(u in o)e.isObject(o[u])&&o.hasOwnProperty(u)&&!l.hasOwnProperty(u)&&(o[u]=f(o[u]))}}if(1===s)for(var u in o)e.isObject(o[u])&&o.hasOwnProperty(u)&&(o[u]=f(o[u]));return o}var m=function(){function t(t){void 0===t&&(t={}),this.options=t,this.lastValue=0,this.valuePool=[]}return t.prototype.stableFix=function(t){var e=this.options.stableRange||3;return Math.abs(t)<e?0:t>e?t-e:t+e},t.prototype.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},t.prototype.linearRegressionMedian=function(t){var e,n,o;return this.valuePool.push(t),this.valuePool.length>=5?(n=this.valuePool,o=function(t){var e=[],n=[];t.forEach((function(t,o){e.push(o),n.push(t)}));var o=function(t,e){for(var n={},o=e.length,a=0,r=0,i=0,s=0,c=0,l=0;l<e.length;l++)a+=t[l],r+=e[l],i+=t[l]*e[l],s+=t[l]*t[l],c+=e[l]*e[l];var u=a/o,h=r/o;return n.a=(i-o*u*h)/(s-o*u*u),n.b=h-n.a*u,n.miss=Math.pow((o*i-a*r)/Math.sqrt((o*s-a*a)*(o*c-r*r)),2),n}(e,n);return function(t){return o.a*t+o.b}}(n),n=n.map((function(t,e){return o(e)})),e=o(n.length/2),this.valuePool.shift()):e=this.lastValue,e},t}();var d,v=((d=navigator.userAgent.toLowerCase().match(/cpu (iphone )?os (.*?) like mac os/))?parseInt(d[2],10):0)&&void 0!==window.AlipayJSBridge,g=void 0!==window.WindVane,y={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},b=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=f(y,t);var e=this.options.stableRange;this.filterX=new m({stableRange:e}),this.filterY=new m({stableRange:e})}return t.prototype.watch=function(t){var e=this;if("function"==typeof t&&!this.watchListener){var n,o,a,r,i,s,c=0,l=0,u=NaN,h=NaN,f=function(c){e.stoped||(n=c.alpha,o=c.beta,a=c.gamma,r=p.call(e,{alpha:n,beta:o,gamma:a},e.options.validRange),isNaN(u)&&(u=a,e.filterX.lastValue=a),isNaN(h)&&(h=o,e.filterY.lastValue=o),r&&(e.options.X?(i=e.options.relativeGamma?a-u:a,i=e.filterX.stableFix(i),i=e.filterX.changeLimit(i),i=e.filterX.linearRegressionMedian(+i)):i=0,e.options.Y?(s=e.options.relativeBeta?o-h:o,s=e.filterY.stableFix(s),s=e.filterY.changeLimit(s),s=e.filterY.linearRegressionMedian(+s)):s=0,e.isValid(i,s)&&(e.options.useRequestAnimationFrame?window.requestAnimationFrame((function(){t(i,s,{alpha:n,beta:s-h,gamma:i-u})})):t(i,s,{alpha:n,beta:s-h,gamma:i-u}),e.lastX=i,e.lastY=s)))};this.stoped=!1,g?(M(!0,this.options.interval),this.watchListener=function(t){if("param"in t){var n=t.param,o=n.x,a=n.y,r=n.z;if(o===e.prevAcceler.x&&a===e.prevAcceler.y&&r===e.prevAcceler.z)return;e.prevAcceler={x:o,y:a,z:r},f({alpha:180*+r,beta:-90*+a,gamma:90*+o})}},document.addEventListener("motion.gyro",this.watchListener,!1)):v?(w(!0,this.options.interval/1e3),this.watchListener=function(t){if(t&&"data"in t){var e=t.data,n=e.x,o=e.y,a=e.z;f({alpha:180*a,beta:-90*o,gamma:90*n})}},document.addEventListener("accelerometerChange",this.watchListener,!1)):(this.watchListener=function(t){(l=(new Date).getTime())-c>=e.options.interval&&(c=l,f(t))},window.addEventListener("deviceorientation",this.watchListener,!1))}},t.prototype.unWatch=function(){e.assertExist(this.watchListener),g?(M(!1),document.removeEventListener("motion.gyro",this.watchListener)):v?(w(!1),document.removeEventListener("accelerometerChange",this.watchListener)):window.removeEventListener("deviceorientation",this.watchListener),this.stoped=!0,this.watchListener=void 0},t.prototype.pause=function(){this.stoped=!0,v&&w(!1)},t.prototype.continue=function(){this.stoped=!1,v&&w(!0,this.options.interval/1e3)},t.prototype.isValid=function(t,e){return this.lastX!==t||this.lastY!==e},t}();function w(t,e){window.AlipayJSBridge.call("watchShake",{monitorGyroscope:!1,monitorAccelerometer:!!t,interval:t?parseFloat(e.toFixed(3)):10},(function(){}))}function M(t,e){var n={on:t,frequency:e};window.WindVane.call("WVMotion","listenGyro",n,(function(t){console.info("call WVMotion success")}),(function(t){console.error("call WVMotion failed:"+JSON.stringify(t))}))}var x,R=function(){function t(){this.transformers=[],this.connected=!1,this.accelerMotion=null,this.validRange={alpha:[-60,60],beta:[-80,80],gamma:[-89,89]}}return t.prototype.connect=function(){var t=this;this.connected||(this.accelerMotion=new b({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,o){var a={x:e,y:n,beta:o.beta,gamma:o.gamma};t.dispatchMotion(a)}))),this.connected=!0},t.prototype.disconnect=function(){this.accelerMotion&&this.accelerMotion.unWatch(),this.connected=!1},t.prototype.dispatchMotion=function(t){this.transformers.forEach((function(e){return e.update(t)}))},t.prototype.addTransformer=function(t){this.transformers.includes(t)||this.transformers.push(t)},t.prototype.removeTransformer=function(t){var e=this.transformers.indexOf(t);return e>-1&&this.transformers.splice(e,1),0===this.transformers.length},t}();var A=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.order=90,e.adapter=null,e.handleConnect=function(){var t;L||null===(t=e.adapter)||void 0===t||t.connect()},e.handleDisconnect=function(){var t;null===(t=e.adapter)||void 0===t||t.disconnect()},e}return o(e,t),e.prototype.onCompositionConstructed=function(){var t;this.adapter=O(),null===(t=this.adapter)||void 0===t||t.connect(),this.bindAccelerDocumentEvent()},e.prototype.onCompositionReset=function(t){var e,n=t.loaderData.deviceTransformer=new s(t);null===(e=this.adapter)||void 0===e||e.addTransformer(n)},e.prototype.onCompositionUpdate=function(t){var e=t.loaderData.deviceTransformer;e&&e.updateOrientation()},e.prototype.onCompositionDestroyed=function(t){var e,n;(null===(e=this.adapter)||void 0===e?void 0:e.removeTransformer(t.loaderData.deviceTransformer))&&(null===(n=this.adapter)||void 0===n||n.disconnect())},e.prototype.bindAccelerDocumentEvent=function(){this.unbindAccelerDocumentEvent(),document.addEventListener("resume",this.handleConnect,!1),document.addEventListener("pause",this.handleDisconnect,!1),document.addEventListener("back",this.handleDisconnect,!1)},e.prototype.unbindAccelerDocumentEvent=function(){document.removeEventListener("resume",this.handleConnect),document.removeEventListener("pause",this.handleDisconnect),document.removeEventListener("back",this.handleDisconnect)},e.prototype.dispose=function(){O().disconnect(),this.unbindAccelerDocumentEvent()},e}(e.AbstractPlugin),L=!1;function O(){return x||(x=new R),x}var E=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return o(e,t),Object.defineProperty(e.prototype,"type",{get:function(){return"orientation-transformer"},enumerable:!1,configurable:!0}),e.prototype.onConstructed=function(t){var e=t.content.options.targets;e&&(this.targets=e.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}})))},e.prototype.onItemRemoved=function(t){var e;null===(e=this.targets)||void 0===e||e.forEach((function(e){var n;return null===(n=t.loaderData.deviceTransformer)||void 0===n?void 0:n.removeTarget(e.name)}))},e.prototype.doCreateContent=function(t){var e,n=t.loaderData.deviceTransformer;return n&&(null===(e=this.targets)||void 0===e||e.forEach((function(t){return n.addTarget(t)})),n.initComposition()),{}},e}(e.VFXItem);e.registerPlugin("orientation-transformer",A,E);var P="1.4.2";e.logger.info("plugin orientation transformer version: "+P),t.OrientationAdapterAcceler=R,t.closeDeviceMotion=function(){L=!0,O().disconnect()},t.getAdapter=O,t.openDeviceMotion=function(){L=!1,O().connect()},t.version=P,Object.defineProperty(t,"__esModule",{value:!0})}));
9
9
  //# sourceMappingURL=index.min.js.map
package/dist/index.mjs CHANGED
@@ -3,10 +3,10 @@
3
3
  * Description: Galacean Effects player orientation transformer plugin
4
4
  * Author: Ant Group CO., Ltd.
5
5
  * Contributors: 燃然,意绮
6
- * Version: v1.4.0
6
+ * Version: v1.4.2
7
7
  */
8
8
 
9
- import { VFXItem, isObject, isArray, assertExist, AbstractPlugin, registerPlugin, logger } from '@galacean/effects';
9
+ import { isObject, isArray, assertExist, AbstractPlugin, VFXItem, registerPlugin, logger } from '@galacean/effects';
10
10
 
11
11
  /******************************************************************************
12
12
  Copyright (c) Microsoft Corporation.
@@ -82,55 +82,6 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
82
82
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
83
83
  };
84
84
 
85
- /**
86
- * 水平旋转变化起始角(手机处于改角度时无变化)
87
- * 待调试
88
- */
89
- var VERTICAL_INIT_DEGREE = 45;
90
- var TransformVFXItem = /** @class */ (function (_super) {
91
- __extends(TransformVFXItem, _super);
92
- function TransformVFXItem() {
93
- return _super !== null && _super.apply(this, arguments) || this;
94
- }
95
- Object.defineProperty(TransformVFXItem.prototype, "type", {
96
- get: function () {
97
- return 'orientation-transformer';
98
- },
99
- enumerable: false,
100
- configurable: true
101
- });
102
- TransformVFXItem.prototype.onConstructed = function (options) {
103
- var targets = options.content.options.targets;
104
- if (targets) {
105
- this.targets = targets.map(function (t) { return ({
106
- name: t.name,
107
- xMin: +t.xMin || 0,
108
- yMin: +t.yMin || 0,
109
- xMax: +t.xMax || 0,
110
- yMax: +t.yMax || 0,
111
- vMin: +t.vMin || 0,
112
- hMin: +t.hMin || 0,
113
- vMax: +t.vMax || 0,
114
- hMax: +t.hMax || 0,
115
- }); });
116
- }
117
- };
118
- TransformVFXItem.prototype.onItemRemoved = function (composition) {
119
- var _a;
120
- (_a = this.targets) === null || _a === void 0 ? void 0 : _a.forEach(function (target) { var _a; return (_a = composition.loaderData.deviceTransformer) === null || _a === void 0 ? void 0 : _a.removeTarget(target.name); });
121
- };
122
- TransformVFXItem.prototype.doCreateContent = function (composition) {
123
- var _a;
124
- var transformer = composition.loaderData.deviceTransformer;
125
- if (transformer) {
126
- (_a = this.targets) === null || _a === void 0 ? void 0 : _a.forEach(function (target) { return transformer.addTarget(target); });
127
- transformer.initComposition();
128
- }
129
- return {};
130
- };
131
- return TransformVFXItem;
132
- }(VFXItem));
133
-
134
85
  var CompositionTransformerAcceler = /** @class */ (function () {
135
86
  function CompositionTransformerAcceler(composition) {
136
87
  this.composition = composition;
@@ -142,8 +93,8 @@ var CompositionTransformerAcceler = /** @class */ (function () {
142
93
  this.betaRange = [-89, 89];
143
94
  }
144
95
  CompositionTransformerAcceler.prototype.update = function (_a) {
145
- var x = _a.x, y = _a.y;
146
- this.currentEvent = { x: x, y: y };
96
+ var x = _a.x, y = _a.y, beta = _a.beta, gamma = _a.gamma;
97
+ this.currentEvent = { x: x, y: y, beta: beta, gamma: gamma };
147
98
  };
148
99
  CompositionTransformerAcceler.prototype.updateOrientation = function () {
149
100
  var _this = this;
@@ -188,7 +139,7 @@ var CompositionTransformerAcceler = /** @class */ (function () {
188
139
  CompositionTransformerAcceler.prototype.moveLayer = function (name, _a) {
189
140
  var _b, _c;
190
141
  var _d;
191
- var x = _a.x, y = _a.y;
142
+ var x = _a.x, y = _a.y, b = _a.beta, g = _a.gamma;
192
143
  var layer = (_d = this.records[name]) === null || _d === void 0 ? void 0 : _d.item;
193
144
  if (layer) {
194
145
  var initPosition = this.records[name].position;
@@ -197,17 +148,18 @@ var CompositionTransformerAcceler = /** @class */ (function () {
197
148
  var beta = clamp(x, this.betaRange), gamma = clamp(y, this.gammaRange);
198
149
  if (target) {
199
150
  var position = [
200
- initPosition[0] + 1.2 * mapRange((beta - this.gammaRange[0]) / (this.gammaRange[1] - this.gammaRange[0]), target.xMin, target.xMax),
201
- initPosition[1] + 1.2 * mapRange((gamma - this.betaRange[0]) / (this.betaRange[1] - this.betaRange[0]), target.yMin, target.yMax),
151
+ initPosition[0] + 1.2 * mapRange(normalize(beta, this.gammaRange[0], this.gammaRange[1]), target.xMin, target.xMax),
152
+ initPosition[1] + 1.2 * mapRange(normalize(gamma, this.betaRange[0], this.betaRange[1]), target.yMin, target.yMax),
202
153
  initPosition[2],
203
154
  ];
204
- var br = (clamp(x * 2, this.betaRange) - this.betaRange[0]) / (this.betaRange[1] - this.betaRange[0]);
205
- var gr = (clamp(y * 2 - VERTICAL_INIT_DEGREE, this.gammaRange) - this.gammaRange[0]) / (this.gammaRange[1] - this.gammaRange[0]);
155
+ var br = normalize(clamp(g * 0.8, this.gammaRange), this.gammaRange[0], this.gammaRange[1]);
156
+ var gr = normalize(clamp(b * 0.8, this.betaRange), this.betaRange[0], this.betaRange[1]);
206
157
  var rotation = [
207
158
  initRotation[0] + mapRange(gr, target.hMin, target.hMax),
208
159
  initRotation[1] + mapRange(br, target.vMin, target.vMax),
209
160
  initRotation[2],
210
161
  ];
162
+ // console.log(y, initY, y - initY);
211
163
  (_b = layer.transform).setPosition.apply(_b, __spreadArray([], __read(position), false));
212
164
  (_c = layer.transform).setRotation.apply(_c, __spreadArray([], __read(rotation), false));
213
165
  this.currentPos[name] = position.slice();
@@ -229,6 +181,9 @@ function clamp(x, range) {
229
181
  function mapRange(t, min, max) {
230
182
  return min + (max - min) * t;
231
183
  }
184
+ function normalize(a, min, max) {
185
+ return (a - min) / (max - min);
186
+ }
232
187
 
233
188
  function getObjectType(obj) {
234
189
  return Object.prototype.toString.call(obj);
@@ -480,13 +435,11 @@ var DeviceOrientation = /** @class */ (function () {
480
435
  }
481
436
  var timefragment = 0; // 时间片计时
482
437
  var nowts = 0; // 当前时间
483
- var referGamma = 0; // 初始化角度,作为单独一个用户的空间旋转的参照
484
- var referBeta = 0;
438
+ // 初始化角度,作为单独一个用户的空间旋转的参照
439
+ var referGamma = NaN, referBeta = NaN;
485
440
  var alpha;
486
441
  var beta;
487
442
  var gamma;
488
- var gammaFixed;
489
- var betaFixed;
490
443
  var isInValidDegRange;
491
444
  var x; // 最终输出的 x
492
445
  var y; // 最终输出的 y
@@ -497,23 +450,23 @@ var DeviceOrientation = /** @class */ (function () {
497
450
  alpha = e.alpha; // 垂直于屏幕的轴 0 ~ 360
498
451
  beta = e.beta; // 横向 X 轴 -180 ~ 180
499
452
  gamma = e.gamma; // 纵向 Y 轴 -90 ~ 90
500
- if (!referBeta) {
501
- referBeta = beta || 0;
502
- }
503
- if (!referGamma) {
504
- referGamma = gamma || 0;
505
- }
506
- //
507
453
  isInValidDegRange = angleLimit.call(_this, {
508
454
  alpha: alpha,
509
455
  beta: beta,
510
456
  gamma: gamma,
511
457
  }, _this.options.validRange);
458
+ if (isNaN(referGamma)) {
459
+ referGamma = gamma;
460
+ _this.filterX.lastValue = gamma;
461
+ }
462
+ if (isNaN(referBeta)) {
463
+ referBeta = beta;
464
+ _this.filterY.lastValue = beta;
465
+ }
512
466
  if (isInValidDegRange) {
513
467
  // 最终结果值
514
468
  if (_this.options.X) {
515
- gammaFixed = gamma - referGamma;
516
- x = _this.options.relativeGamma ? gammaFixed : gamma;
469
+ x = _this.options.relativeGamma ? gamma - referGamma : gamma;
517
470
  x = _this.filterX.stableFix(x);
518
471
  x = _this.filterX.changeLimit(x);
519
472
  x = _this.filterX.linearRegressionMedian(+x);
@@ -522,9 +475,7 @@ var DeviceOrientation = /** @class */ (function () {
522
475
  x = 0;
523
476
  }
524
477
  if (_this.options.Y) {
525
- // beta 相对 referBeta 的角度
526
- betaFixed = beta - referBeta;
527
- y = _this.options.relativeBeta ? betaFixed : beta;
478
+ y = _this.options.relativeBeta ? beta - referBeta : beta;
528
479
  y = _this.filterY.stableFix(y);
529
480
  y = _this.filterY.changeLimit(y);
530
481
  y = _this.filterY.linearRegressionMedian(+y);
@@ -535,11 +486,11 @@ var DeviceOrientation = /** @class */ (function () {
535
486
  if (_this.isValid(x, y)) {
536
487
  if (_this.options.useRequestAnimationFrame) {
537
488
  window.requestAnimationFrame(function () {
538
- callback(x, y, { alpha: alpha, beta: beta, gamma: gamma });
489
+ callback(x, y, { alpha: alpha, beta: y - referBeta, gamma: x - referGamma });
539
490
  });
540
491
  }
541
492
  else {
542
- callback(x, y, { alpha: alpha, beta: beta, gamma: gamma });
493
+ callback(x, y, { alpha: alpha, beta: y - referBeta, gamma: x - referGamma });
543
494
  }
544
495
  _this.lastX = x;
545
496
  _this.lastY = y;
@@ -688,10 +639,13 @@ var OrientationAdapterAcceler = /** @class */ (function () {
688
639
  validRange: this.validRange,
689
640
  stableRange: 3, // 稳定区间
690
641
  });
691
- this.accelerMotion.watch(function (x, y) {
642
+ this.accelerMotion.watch(function (x, y, _a) {
643
+ var beta = _a.beta, gamma = _a.gamma;
692
644
  var motion = {
693
645
  x: x,
694
646
  y: y,
647
+ beta: beta,
648
+ gamma: gamma,
695
649
  };
696
650
  _this.dispatchMotion(motion);
697
651
  });
@@ -811,8 +765,52 @@ function openDeviceMotion() {
811
765
  getAdapter().connect();
812
766
  }
813
767
 
768
+ var TransformVFXItem = /** @class */ (function (_super) {
769
+ __extends(TransformVFXItem, _super);
770
+ function TransformVFXItem() {
771
+ return _super !== null && _super.apply(this, arguments) || this;
772
+ }
773
+ Object.defineProperty(TransformVFXItem.prototype, "type", {
774
+ get: function () {
775
+ return 'orientation-transformer';
776
+ },
777
+ enumerable: false,
778
+ configurable: true
779
+ });
780
+ TransformVFXItem.prototype.onConstructed = function (options) {
781
+ var targets = options.content.options.targets;
782
+ if (targets) {
783
+ this.targets = targets.map(function (t) { return ({
784
+ name: t.name,
785
+ xMin: +t.xMin || 0,
786
+ yMin: +t.yMin || 0,
787
+ xMax: +t.xMax || 0,
788
+ yMax: +t.yMax || 0,
789
+ vMin: +t.vMin || 0,
790
+ hMin: +t.hMin || 0,
791
+ vMax: +t.vMax || 0,
792
+ hMax: +t.hMax || 0,
793
+ }); });
794
+ }
795
+ };
796
+ TransformVFXItem.prototype.onItemRemoved = function (composition) {
797
+ var _a;
798
+ (_a = this.targets) === null || _a === void 0 ? void 0 : _a.forEach(function (target) { var _a; return (_a = composition.loaderData.deviceTransformer) === null || _a === void 0 ? void 0 : _a.removeTarget(target.name); });
799
+ };
800
+ TransformVFXItem.prototype.doCreateContent = function (composition) {
801
+ var _a;
802
+ var transformer = composition.loaderData.deviceTransformer;
803
+ if (transformer) {
804
+ (_a = this.targets) === null || _a === void 0 ? void 0 : _a.forEach(function (target) { return transformer.addTarget(target); });
805
+ transformer.initComposition();
806
+ }
807
+ return {};
808
+ };
809
+ return TransformVFXItem;
810
+ }(VFXItem));
811
+
814
812
  registerPlugin('orientation-transformer', OrientationPluginLoader, TransformVFXItem);
815
- var version = "1.4.0";
813
+ var version = "1.4.2";
816
814
  logger.info('plugin orientation transformer version: ' + version);
817
815
 
818
816
  export { OrientationAdapterAcceler, closeDeviceMotion, getAdapter, openDeviceMotion, version };
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -2,6 +2,8 @@ import type { CompositionTransformerAcceler } from './composition-transformer-ac
2
2
  export type AccelerMotionData = {
3
3
  x: number;
4
4
  y: number;
5
+ beta: number;
6
+ gamma: number;
5
7
  };
6
8
  /**
7
9
  *
@@ -1,11 +1,6 @@
1
1
  import type { spec, Composition } from '@galacean/effects';
2
2
  import { VFXItem } from '@galacean/effects';
3
3
  import type { TransformItem } from './transform-item';
4
- /**
5
- * 水平旋转变化起始角(手机处于改角度时无变化)
6
- * 待调试
7
- */
8
- export declare const VERTICAL_INIT_DEGREE = 45;
9
4
  export declare class TransformVFXItem extends VFXItem<TransformItem> {
10
5
  private targets?;
11
6
  get type(): spec.ItemType;
@@ -16,7 +16,7 @@ type FilteringOptions = {
16
16
  */
17
17
  export declare class Filtering {
18
18
  private readonly options;
19
- private lastValue;
19
+ lastValue: number;
20
20
  private valuePool;
21
21
  constructor(options?: FilteringOptions);
22
22
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@galacean/effects-plugin-orientation-transformer",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
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": "1.4.0"
34
+ "@galacean/effects": "1.4.2"
35
35
  },
36
36
  "scripts": {
37
37
  "dev": "vite",