@galacean/effects-plugin-orientation-transformer 2.0.0-alpha.11 → 2.0.0-alpha.13
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 +843 -0
- package/dist/alipay.js.map +1 -0
- package/dist/alipay.mjs +834 -0
- package/dist/alipay.mjs.map +1 -0
- package/dist/composition-transformer-acceler.d.ts +2 -6
- package/dist/index.d.ts +2 -1
- package/dist/index.js +121 -102
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +2 -2
- package/dist/index.min.js.map +1 -1
- package/dist/index.mjs +122 -104
- package/dist/index.mjs.map +1 -1
- package/dist/orientation-adapter-acceler.d.ts +2 -0
- package/dist/utils/device.d.ts +3 -0
- package/dist/utils/filtering.d.ts +1 -1
- package/package.json +15 -3
- package/dist/transform-vfx-item.d.ts +0 -10
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: v2.0.0-alpha.
|
|
6
|
+
* Version: v2.0.0-alpha.13
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import {
|
|
9
|
+
import { isObject, isArray, assertExist, AbstractPlugin, effectsClass, ItemBehaviour, registerPlugin, VFXItem, logger, version as version$1 } from '@galacean/effects';
|
|
10
10
|
|
|
11
11
|
function _set_prototype_of(o, p) {
|
|
12
12
|
_set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
|
@@ -30,75 +30,6 @@ function _inherits(subClass, superClass) {
|
|
|
30
30
|
if (superClass) _set_prototype_of(subClass, superClass);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
var OrientationComponent = /*#__PURE__*/ function(ItemBehaviour) {
|
|
34
|
-
_inherits(OrientationComponent, ItemBehaviour);
|
|
35
|
-
function OrientationComponent() {
|
|
36
|
-
return ItemBehaviour.apply(this, arguments);
|
|
37
|
-
}
|
|
38
|
-
var _proto = OrientationComponent.prototype;
|
|
39
|
-
_proto.fromData = function fromData(data) {
|
|
40
|
-
ItemBehaviour.prototype.fromData.call(this, data);
|
|
41
|
-
var targets = data.content.options.targets;
|
|
42
|
-
if (targets) {
|
|
43
|
-
this.targets = targets.map(function(t) {
|
|
44
|
-
return {
|
|
45
|
-
name: t.name,
|
|
46
|
-
xMin: +t.xMin || 0,
|
|
47
|
-
yMin: +t.yMin || 0,
|
|
48
|
-
xMax: +t.xMax || 0,
|
|
49
|
-
yMax: +t.yMax || 0,
|
|
50
|
-
vMin: +t.vMin || 0,
|
|
51
|
-
hMin: +t.hMin || 0,
|
|
52
|
-
vMax: +t.vMax || 0,
|
|
53
|
-
hMax: +t.hMax || 0
|
|
54
|
-
};
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
_proto.start = function start() {
|
|
59
|
-
var _this_item_composition;
|
|
60
|
-
var transformer = (_this_item_composition = this.item.composition) == null ? void 0 : _this_item_composition.loaderData.deviceTransformer;
|
|
61
|
-
if (transformer) {
|
|
62
|
-
var _this_targets;
|
|
63
|
-
(_this_targets = this.targets) == null ? void 0 : _this_targets.forEach(function(target) {
|
|
64
|
-
return transformer.addTarget(target);
|
|
65
|
-
});
|
|
66
|
-
transformer.initComposition();
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
_proto.update = function update(dt) {
|
|
70
|
-
var _this_item_composition;
|
|
71
|
-
var transformer = (_this_item_composition = this.item.composition) == null ? void 0 : _this_item_composition.loaderData.deviceTransformer;
|
|
72
|
-
if (transformer) {
|
|
73
|
-
transformer.updateOrientation();
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
_proto.onDestroy = function onDestroy() {
|
|
77
|
-
var _this = this;
|
|
78
|
-
var _this_targets;
|
|
79
|
-
(_this_targets = this.targets) == null ? void 0 : _this_targets.forEach(function(target) {
|
|
80
|
-
var _this_item_composition_loaderData_deviceTransformer, _this_item_composition;
|
|
81
|
-
return (_this_item_composition = _this.item.composition) == null ? void 0 : (_this_item_composition_loaderData_deviceTransformer = _this_item_composition.loaderData.deviceTransformer) == null ? void 0 : _this_item_composition_loaderData_deviceTransformer.removeTarget(target.name);
|
|
82
|
-
});
|
|
83
|
-
};
|
|
84
|
-
return OrientationComponent;
|
|
85
|
-
}(ItemBehaviour);
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* 水平旋转变化起始角(手机处于改角度时无变化)
|
|
89
|
-
*/ var VERTICAL_INIT_DEGREE = 45;
|
|
90
|
-
var TransformVFXItem = /*#__PURE__*/ function(VFXItem) {
|
|
91
|
-
_inherits(TransformVFXItem, VFXItem);
|
|
92
|
-
function TransformVFXItem(engine, props) {
|
|
93
|
-
var _this;
|
|
94
|
-
_this = VFXItem.call(this, engine, props) || this;
|
|
95
|
-
var component = _this.addComponent(OrientationComponent);
|
|
96
|
-
component.fromData(props);
|
|
97
|
-
return _this;
|
|
98
|
-
}
|
|
99
|
-
return TransformVFXItem;
|
|
100
|
-
}(VFXItem);
|
|
101
|
-
|
|
102
33
|
var CompositionTransformerAcceler = /*#__PURE__*/ function() {
|
|
103
34
|
function CompositionTransformerAcceler(composition) {
|
|
104
35
|
this.composition = composition;
|
|
@@ -117,10 +48,12 @@ var CompositionTransformerAcceler = /*#__PURE__*/ function() {
|
|
|
117
48
|
}
|
|
118
49
|
var _proto = CompositionTransformerAcceler.prototype;
|
|
119
50
|
_proto.update = function update(param) {
|
|
120
|
-
var x = param.x, y = param.y;
|
|
51
|
+
var x = param.x, y = param.y, beta = param.beta, gamma = param.gamma;
|
|
121
52
|
this.currentEvent = {
|
|
122
53
|
x: x,
|
|
123
|
-
y: y
|
|
54
|
+
y: y,
|
|
55
|
+
beta: beta,
|
|
56
|
+
gamma: gamma
|
|
124
57
|
};
|
|
125
58
|
};
|
|
126
59
|
_proto.updateOrientation = function updateOrientation() {
|
|
@@ -164,7 +97,7 @@ var CompositionTransformerAcceler = /*#__PURE__*/ function() {
|
|
|
164
97
|
delete this.records[name];
|
|
165
98
|
};
|
|
166
99
|
_proto.moveLayer = function moveLayer(name, param) {
|
|
167
|
-
var x = param.x, y = param.y;
|
|
100
|
+
var x = param.x, y = param.y, b = param.beta, g = param.gamma;
|
|
168
101
|
var _this_records_name;
|
|
169
102
|
var layer = (_this_records_name = this.records[name]) == null ? void 0 : _this_records_name.item;
|
|
170
103
|
if (layer) {
|
|
@@ -175,12 +108,12 @@ var CompositionTransformerAcceler = /*#__PURE__*/ function() {
|
|
|
175
108
|
if (target) {
|
|
176
109
|
var _layer_transform, _layer_transform1;
|
|
177
110
|
var position = [
|
|
178
|
-
initPosition[0] + 1.2 * mapRange((beta
|
|
179
|
-
initPosition[1] + 1.2 * mapRange((gamma
|
|
111
|
+
initPosition[0] + 1.2 * mapRange(normalize(beta, this.gammaRange[0], this.gammaRange[1]), target.xMin, target.xMax),
|
|
112
|
+
initPosition[1] + 1.2 * mapRange(normalize(gamma, this.betaRange[0], this.betaRange[1]), target.yMin, target.yMax),
|
|
180
113
|
initPosition[2]
|
|
181
114
|
];
|
|
182
|
-
var br = (clamp(
|
|
183
|
-
var gr = (clamp(
|
|
115
|
+
var br = normalize(clamp(g * 0.8, this.gammaRange), this.gammaRange[0], this.gammaRange[1]);
|
|
116
|
+
var gr = normalize(clamp(b * 0.8, this.betaRange), this.betaRange[0], this.betaRange[1]);
|
|
184
117
|
var rotation = [
|
|
185
118
|
initRotation[0] + mapRange(gr, target.hMin, target.hMax),
|
|
186
119
|
initRotation[1] + mapRange(br, target.vMin, target.vMax),
|
|
@@ -206,6 +139,9 @@ function clamp(x, range) {
|
|
|
206
139
|
function mapRange(t, min, max) {
|
|
207
140
|
return min + (max - min) * t;
|
|
208
141
|
}
|
|
142
|
+
function normalize(a, min, max) {
|
|
143
|
+
return (a - min) / (max - min);
|
|
144
|
+
}
|
|
209
145
|
|
|
210
146
|
function getObjectType(obj) {
|
|
211
147
|
return Object.prototype.toString.call(obj);
|
|
@@ -296,6 +232,18 @@ function isIOS() {
|
|
|
296
232
|
var ver = str.match(/cpu (iphone )?os (.*?) like mac os/);
|
|
297
233
|
return ver ? parseInt(ver[2], 10) : 0;
|
|
298
234
|
}
|
|
235
|
+
function isMiniProgram() {
|
|
236
|
+
return isAlipayMiniApp() || isWechatMiniApp();
|
|
237
|
+
}
|
|
238
|
+
function isAlipayMiniApp() {
|
|
239
|
+
var _my;
|
|
240
|
+
//@ts-expect-error
|
|
241
|
+
return typeof my !== "undefined" && ((_my = my) == null ? void 0 : _my.renderTarget) === "web";
|
|
242
|
+
}
|
|
243
|
+
function isWechatMiniApp() {
|
|
244
|
+
//@ts-expect-error
|
|
245
|
+
return window.__wxjs_environment === "miniprogram";
|
|
246
|
+
}
|
|
299
247
|
|
|
300
248
|
/**
|
|
301
249
|
* 稳定区间
|
|
@@ -468,13 +416,11 @@ var DeviceOrientation = /*#__PURE__*/ function() {
|
|
|
468
416
|
}
|
|
469
417
|
var timefragment = 0; // 时间片计时
|
|
470
418
|
var nowts = 0; // 当前时间
|
|
471
|
-
|
|
472
|
-
var referBeta =
|
|
419
|
+
// 初始化角度,作为单独一个用户的空间旋转的参照
|
|
420
|
+
var referGamma = NaN, referBeta = NaN;
|
|
473
421
|
var alpha;
|
|
474
422
|
var beta;
|
|
475
423
|
var gamma;
|
|
476
|
-
var gammaFixed;
|
|
477
|
-
var betaFixed;
|
|
478
424
|
var isInValidDegRange;
|
|
479
425
|
var x; // 最终输出的 x
|
|
480
426
|
var y; // 最终输出的 y
|
|
@@ -485,23 +431,23 @@ var DeviceOrientation = /*#__PURE__*/ function() {
|
|
|
485
431
|
alpha = e.alpha; // 垂直于屏幕的轴 0 ~ 360
|
|
486
432
|
beta = e.beta; // 横向 X 轴 -180 ~ 180
|
|
487
433
|
gamma = e.gamma; // 纵向 Y 轴 -90 ~ 90
|
|
488
|
-
if (!referBeta) {
|
|
489
|
-
referBeta = beta || 0;
|
|
490
|
-
}
|
|
491
|
-
if (!referGamma) {
|
|
492
|
-
referGamma = gamma || 0;
|
|
493
|
-
}
|
|
494
|
-
//
|
|
495
434
|
isInValidDegRange = angleLimit.call(_this, {
|
|
496
435
|
alpha: alpha,
|
|
497
436
|
beta: beta,
|
|
498
437
|
gamma: gamma
|
|
499
438
|
}, _this.options.validRange);
|
|
439
|
+
if (isNaN(referGamma)) {
|
|
440
|
+
referGamma = gamma;
|
|
441
|
+
_this.filterX.lastValue = gamma;
|
|
442
|
+
}
|
|
443
|
+
if (isNaN(referBeta)) {
|
|
444
|
+
referBeta = beta;
|
|
445
|
+
_this.filterY.lastValue = beta;
|
|
446
|
+
}
|
|
500
447
|
if (isInValidDegRange) {
|
|
501
448
|
// 最终结果值
|
|
502
449
|
if (_this.options.X) {
|
|
503
|
-
|
|
504
|
-
x = _this.options.relativeGamma ? gammaFixed : gamma;
|
|
450
|
+
x = _this.options.relativeGamma ? gamma - referGamma : gamma;
|
|
505
451
|
x = _this.filterX.stableFix(x);
|
|
506
452
|
x = _this.filterX.changeLimit(x);
|
|
507
453
|
x = _this.filterX.linearRegressionMedian(+x);
|
|
@@ -509,9 +455,7 @@ var DeviceOrientation = /*#__PURE__*/ function() {
|
|
|
509
455
|
x = 0;
|
|
510
456
|
}
|
|
511
457
|
if (_this.options.Y) {
|
|
512
|
-
|
|
513
|
-
betaFixed = beta - referBeta;
|
|
514
|
-
y = _this.options.relativeBeta ? betaFixed : beta;
|
|
458
|
+
y = _this.options.relativeBeta ? beta - referBeta : beta;
|
|
515
459
|
y = _this.filterY.stableFix(y);
|
|
516
460
|
y = _this.filterY.changeLimit(y);
|
|
517
461
|
y = _this.filterY.linearRegressionMedian(+y);
|
|
@@ -523,15 +467,15 @@ var DeviceOrientation = /*#__PURE__*/ function() {
|
|
|
523
467
|
window.requestAnimationFrame(function() {
|
|
524
468
|
callback(x, y, {
|
|
525
469
|
alpha: alpha,
|
|
526
|
-
beta:
|
|
527
|
-
gamma:
|
|
470
|
+
beta: y - referBeta,
|
|
471
|
+
gamma: x - referGamma
|
|
528
472
|
});
|
|
529
473
|
});
|
|
530
474
|
} else {
|
|
531
475
|
callback(x, y, {
|
|
532
476
|
alpha: alpha,
|
|
533
|
-
beta:
|
|
534
|
-
gamma:
|
|
477
|
+
beta: y - referBeta,
|
|
478
|
+
gamma: x - referGamma
|
|
535
479
|
});
|
|
536
480
|
}
|
|
537
481
|
_this.lastX = x;
|
|
@@ -564,7 +508,7 @@ var DeviceOrientation = /*#__PURE__*/ function() {
|
|
|
564
508
|
}
|
|
565
509
|
};
|
|
566
510
|
document.addEventListener("motion.gyro", this.watchListener, false);
|
|
567
|
-
} else if (useJSBridge) {
|
|
511
|
+
} else if (useJSBridge && !isMiniProgram()) {
|
|
568
512
|
switchIOSEvent(true, this.options.interval / 1000);
|
|
569
513
|
this.watchListener = function(e) {
|
|
570
514
|
if (e && "data" in e) {
|
|
@@ -689,10 +633,13 @@ function switchWindVane(open, interval) {
|
|
|
689
633
|
validRange: this.validRange,
|
|
690
634
|
stableRange: 3
|
|
691
635
|
});
|
|
692
|
-
this.accelerMotion.watch(function(x, y) {
|
|
636
|
+
this.accelerMotion.watch(function(x, y, param) {
|
|
637
|
+
var beta = param.beta, gamma = param.gamma;
|
|
693
638
|
var motion = {
|
|
694
639
|
x: x,
|
|
695
|
-
y: y
|
|
640
|
+
y: y,
|
|
641
|
+
beta: beta,
|
|
642
|
+
gamma: gamma
|
|
696
643
|
};
|
|
697
644
|
_this.dispatchMotion(motion);
|
|
698
645
|
});
|
|
@@ -815,9 +762,80 @@ function openDeviceMotion() {
|
|
|
815
762
|
getAdapter().connect();
|
|
816
763
|
}
|
|
817
764
|
|
|
818
|
-
|
|
819
|
-
var
|
|
765
|
+
function __decorate(decorators, target, key, desc) {
|
|
766
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
767
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
768
|
+
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
769
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
770
|
+
}
|
|
771
|
+
typeof SuppressedError === "function" ? SuppressedError : function _SuppressedError(error, suppressed, message) {
|
|
772
|
+
var e = new Error(message);
|
|
773
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
774
|
+
};
|
|
775
|
+
|
|
776
|
+
var OrientationComponent = /*#__PURE__*/ function(ItemBehaviour) {
|
|
777
|
+
_inherits(OrientationComponent, ItemBehaviour);
|
|
778
|
+
function OrientationComponent() {
|
|
779
|
+
return ItemBehaviour.apply(this, arguments);
|
|
780
|
+
}
|
|
781
|
+
var _proto = OrientationComponent.prototype;
|
|
782
|
+
_proto.fromData = function fromData(data) {
|
|
783
|
+
ItemBehaviour.prototype.fromData.call(this, data);
|
|
784
|
+
var targets = data.options.targets;
|
|
785
|
+
if (targets) {
|
|
786
|
+
this.targets = targets.map(function(t) {
|
|
787
|
+
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
|
+
};
|
|
801
|
+
_proto.start = function start() {
|
|
802
|
+
var _this_item_composition;
|
|
803
|
+
var transformer = (_this_item_composition = this.item.composition) == null ? void 0 : _this_item_composition.loaderData.deviceTransformer;
|
|
804
|
+
if (transformer) {
|
|
805
|
+
var _this_targets;
|
|
806
|
+
(_this_targets = this.targets) == null ? void 0 : _this_targets.forEach(function(target) {
|
|
807
|
+
return transformer.addTarget(target);
|
|
808
|
+
});
|
|
809
|
+
transformer.initComposition();
|
|
810
|
+
}
|
|
811
|
+
};
|
|
812
|
+
_proto.update = function update(dt) {
|
|
813
|
+
var _this_item_composition;
|
|
814
|
+
var transformer = (_this_item_composition = this.item.composition) == null ? void 0 : _this_item_composition.loaderData.deviceTransformer;
|
|
815
|
+
if (transformer) {
|
|
816
|
+
transformer.updateOrientation();
|
|
817
|
+
}
|
|
818
|
+
};
|
|
819
|
+
_proto.onDestroy = function onDestroy() {
|
|
820
|
+
var _this = this;
|
|
821
|
+
var _this_targets;
|
|
822
|
+
(_this_targets = this.targets) == null ? void 0 : _this_targets.forEach(function(target) {
|
|
823
|
+
var _this_item_composition_loaderData_deviceTransformer, _this_item_composition;
|
|
824
|
+
return (_this_item_composition = _this.item.composition) == null ? void 0 : (_this_item_composition_loaderData_deviceTransformer = _this_item_composition.loaderData.deviceTransformer) == null ? void 0 : _this_item_composition_loaderData_deviceTransformer.removeTarget(target.name);
|
|
825
|
+
});
|
|
826
|
+
};
|
|
827
|
+
return OrientationComponent;
|
|
828
|
+
}(ItemBehaviour);
|
|
829
|
+
OrientationComponent = __decorate([
|
|
830
|
+
effectsClass("OrientationComponent")
|
|
831
|
+
], OrientationComponent);
|
|
832
|
+
|
|
833
|
+
registerPlugin("orientation-transformer", OrientationPluginLoader, VFXItem);
|
|
834
|
+
var version = "2.0.0-alpha.13";
|
|
820
835
|
logger.info("plugin orientation transformer version: " + version);
|
|
836
|
+
if (version !== version$1) {
|
|
837
|
+
console.error("注意:请统一 Orientation Transformer 插件与 Player 版本,不统一的版本混用会有不可预知的后果!", "\nAttention: Please ensure the Orientation Transformer plugin is synchronized with the Player version. Mixing and matching incompatible versions may result in unpredictable consequences!");
|
|
838
|
+
}
|
|
821
839
|
|
|
822
|
-
export { OrientationAdapterAcceler, closeDeviceMotion, getAdapter, openDeviceMotion, version };
|
|
840
|
+
export { OrientationAdapterAcceler, OrientationComponent, OrientationPluginLoader, closeDeviceMotion, getAdapter, openDeviceMotion, version };
|
|
823
841
|
//# sourceMappingURL=index.mjs.map
|