@galacean/effects-plugin-orientation-transformer 2.0.0-alpha.10 → 2.0.0-alpha.12
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/composition-transformer-acceler.d.ts +2 -6
- package/dist/index.js +103 -101
- 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 +104 -102
- package/dist/index.mjs.map +1 -1
- package/dist/orientation-adapter-acceler.d.ts +2 -0
- package/dist/transform-vfx-item.d.ts +0 -4
- package/dist/utils/filtering.d.ts +1 -1
- package/package.json +3 -3
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import type { Composition, spec } from '@galacean/effects';
|
|
2
|
-
type
|
|
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 }:
|
|
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: v2.0.0-alpha.
|
|
6
|
+
* Version: v2.0.0-alpha.12
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
'use strict';
|
|
@@ -34,75 +34,6 @@ function _inherits(subClass, superClass) {
|
|
|
34
34
|
if (superClass) _set_prototype_of(subClass, superClass);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
var OrientationComponent = /*#__PURE__*/ function(ItemBehaviour) {
|
|
38
|
-
_inherits(OrientationComponent, ItemBehaviour);
|
|
39
|
-
function OrientationComponent() {
|
|
40
|
-
return ItemBehaviour.apply(this, arguments);
|
|
41
|
-
}
|
|
42
|
-
var _proto = OrientationComponent.prototype;
|
|
43
|
-
_proto.fromData = function fromData(data) {
|
|
44
|
-
ItemBehaviour.prototype.fromData.call(this, data);
|
|
45
|
-
var targets = data.content.options.targets;
|
|
46
|
-
if (targets) {
|
|
47
|
-
this.targets = targets.map(function(t) {
|
|
48
|
-
return {
|
|
49
|
-
name: t.name,
|
|
50
|
-
xMin: +t.xMin || 0,
|
|
51
|
-
yMin: +t.yMin || 0,
|
|
52
|
-
xMax: +t.xMax || 0,
|
|
53
|
-
yMax: +t.yMax || 0,
|
|
54
|
-
vMin: +t.vMin || 0,
|
|
55
|
-
hMin: +t.hMin || 0,
|
|
56
|
-
vMax: +t.vMax || 0,
|
|
57
|
-
hMax: +t.hMax || 0
|
|
58
|
-
};
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
_proto.start = function start() {
|
|
63
|
-
var _this_item_composition;
|
|
64
|
-
var transformer = (_this_item_composition = this.item.composition) == null ? void 0 : _this_item_composition.loaderData.deviceTransformer;
|
|
65
|
-
if (transformer) {
|
|
66
|
-
var _this_targets;
|
|
67
|
-
(_this_targets = this.targets) == null ? void 0 : _this_targets.forEach(function(target) {
|
|
68
|
-
return transformer.addTarget(target);
|
|
69
|
-
});
|
|
70
|
-
transformer.initComposition();
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
_proto.update = function update(dt) {
|
|
74
|
-
var _this_item_composition;
|
|
75
|
-
var transformer = (_this_item_composition = this.item.composition) == null ? void 0 : _this_item_composition.loaderData.deviceTransformer;
|
|
76
|
-
if (transformer) {
|
|
77
|
-
transformer.updateOrientation();
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
_proto.onDestroy = function onDestroy() {
|
|
81
|
-
var _this = this;
|
|
82
|
-
var _this_targets;
|
|
83
|
-
(_this_targets = this.targets) == null ? void 0 : _this_targets.forEach(function(target) {
|
|
84
|
-
var _this_item_composition_loaderData_deviceTransformer, _this_item_composition;
|
|
85
|
-
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);
|
|
86
|
-
});
|
|
87
|
-
};
|
|
88
|
-
return OrientationComponent;
|
|
89
|
-
}(effects.ItemBehaviour);
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* 水平旋转变化起始角(手机处于改角度时无变化)
|
|
93
|
-
*/ var VERTICAL_INIT_DEGREE = 45;
|
|
94
|
-
var TransformVFXItem = /*#__PURE__*/ function(VFXItem) {
|
|
95
|
-
_inherits(TransformVFXItem, VFXItem);
|
|
96
|
-
function TransformVFXItem(engine, props) {
|
|
97
|
-
var _this;
|
|
98
|
-
_this = VFXItem.call(this, engine, props) || this;
|
|
99
|
-
var component = _this.addComponent(OrientationComponent);
|
|
100
|
-
component.fromData(props);
|
|
101
|
-
return _this;
|
|
102
|
-
}
|
|
103
|
-
return TransformVFXItem;
|
|
104
|
-
}(effects.VFXItem);
|
|
105
|
-
|
|
106
37
|
var CompositionTransformerAcceler = /*#__PURE__*/ function() {
|
|
107
38
|
function CompositionTransformerAcceler(composition) {
|
|
108
39
|
this.composition = composition;
|
|
@@ -121,10 +52,12 @@ var CompositionTransformerAcceler = /*#__PURE__*/ function() {
|
|
|
121
52
|
}
|
|
122
53
|
var _proto = CompositionTransformerAcceler.prototype;
|
|
123
54
|
_proto.update = function update(param) {
|
|
124
|
-
var x = param.x, y = param.y;
|
|
55
|
+
var x = param.x, y = param.y, beta = param.beta, gamma = param.gamma;
|
|
125
56
|
this.currentEvent = {
|
|
126
57
|
x: x,
|
|
127
|
-
y: y
|
|
58
|
+
y: y,
|
|
59
|
+
beta: beta,
|
|
60
|
+
gamma: gamma
|
|
128
61
|
};
|
|
129
62
|
};
|
|
130
63
|
_proto.updateOrientation = function updateOrientation() {
|
|
@@ -168,7 +101,7 @@ var CompositionTransformerAcceler = /*#__PURE__*/ function() {
|
|
|
168
101
|
delete this.records[name];
|
|
169
102
|
};
|
|
170
103
|
_proto.moveLayer = function moveLayer(name, param) {
|
|
171
|
-
var x = param.x, y = param.y;
|
|
104
|
+
var x = param.x, y = param.y, b = param.beta, g = param.gamma;
|
|
172
105
|
var _this_records_name;
|
|
173
106
|
var layer = (_this_records_name = this.records[name]) == null ? void 0 : _this_records_name.item;
|
|
174
107
|
if (layer) {
|
|
@@ -177,14 +110,15 @@ var CompositionTransformerAcceler = /*#__PURE__*/ function() {
|
|
|
177
110
|
var target = this.targets[name];
|
|
178
111
|
var beta = clamp(x, this.betaRange), gamma = clamp(y, this.gammaRange);
|
|
179
112
|
if (target) {
|
|
180
|
-
var
|
|
113
|
+
var // console.log(y, initY, y - initY);
|
|
114
|
+
_layer_transform, _layer_transform1;
|
|
181
115
|
var position = [
|
|
182
|
-
initPosition[0] + 1.2 * mapRange((beta
|
|
183
|
-
initPosition[1] + 1.2 * mapRange((gamma
|
|
116
|
+
initPosition[0] + 1.2 * mapRange(normalize(beta, this.gammaRange[0], this.gammaRange[1]), target.xMin, target.xMax),
|
|
117
|
+
initPosition[1] + 1.2 * mapRange(normalize(gamma, this.betaRange[0], this.betaRange[1]), target.yMin, target.yMax),
|
|
184
118
|
initPosition[2]
|
|
185
119
|
];
|
|
186
|
-
var br = (clamp(
|
|
187
|
-
var gr = (clamp(
|
|
120
|
+
var br = normalize(clamp(g * 0.8, this.gammaRange), this.gammaRange[0], this.gammaRange[1]);
|
|
121
|
+
var gr = normalize(clamp(b * 0.8, this.betaRange), this.betaRange[0], this.betaRange[1]);
|
|
188
122
|
var rotation = [
|
|
189
123
|
initRotation[0] + mapRange(gr, target.hMin, target.hMax),
|
|
190
124
|
initRotation[1] + mapRange(br, target.vMin, target.vMax),
|
|
@@ -210,6 +144,9 @@ function clamp(x, range) {
|
|
|
210
144
|
function mapRange(t, min, max) {
|
|
211
145
|
return min + (max - min) * t;
|
|
212
146
|
}
|
|
147
|
+
function normalize(a, min, max) {
|
|
148
|
+
return (a - min) / (max - min);
|
|
149
|
+
}
|
|
213
150
|
|
|
214
151
|
function getObjectType(obj) {
|
|
215
152
|
return Object.prototype.toString.call(obj);
|
|
@@ -472,13 +409,11 @@ var DeviceOrientation = /*#__PURE__*/ function() {
|
|
|
472
409
|
}
|
|
473
410
|
var timefragment = 0; // 时间片计时
|
|
474
411
|
var nowts = 0; // 当前时间
|
|
475
|
-
|
|
476
|
-
var referBeta =
|
|
412
|
+
// 初始化角度,作为单独一个用户的空间旋转的参照
|
|
413
|
+
var referGamma = NaN, referBeta = NaN;
|
|
477
414
|
var alpha;
|
|
478
415
|
var beta;
|
|
479
416
|
var gamma;
|
|
480
|
-
var gammaFixed;
|
|
481
|
-
var betaFixed;
|
|
482
417
|
var isInValidDegRange;
|
|
483
418
|
var x; // 最终输出的 x
|
|
484
419
|
var y; // 最终输出的 y
|
|
@@ -489,23 +424,23 @@ var DeviceOrientation = /*#__PURE__*/ function() {
|
|
|
489
424
|
alpha = e.alpha; // 垂直于屏幕的轴 0 ~ 360
|
|
490
425
|
beta = e.beta; // 横向 X 轴 -180 ~ 180
|
|
491
426
|
gamma = e.gamma; // 纵向 Y 轴 -90 ~ 90
|
|
492
|
-
if (!referBeta) {
|
|
493
|
-
referBeta = beta || 0;
|
|
494
|
-
}
|
|
495
|
-
if (!referGamma) {
|
|
496
|
-
referGamma = gamma || 0;
|
|
497
|
-
}
|
|
498
|
-
//
|
|
499
427
|
isInValidDegRange = angleLimit.call(_this, {
|
|
500
428
|
alpha: alpha,
|
|
501
429
|
beta: beta,
|
|
502
430
|
gamma: gamma
|
|
503
431
|
}, _this.options.validRange);
|
|
432
|
+
if (isNaN(referGamma)) {
|
|
433
|
+
referGamma = gamma;
|
|
434
|
+
_this.filterX.lastValue = gamma;
|
|
435
|
+
}
|
|
436
|
+
if (isNaN(referBeta)) {
|
|
437
|
+
referBeta = beta;
|
|
438
|
+
_this.filterY.lastValue = beta;
|
|
439
|
+
}
|
|
504
440
|
if (isInValidDegRange) {
|
|
505
441
|
// 最终结果值
|
|
506
442
|
if (_this.options.X) {
|
|
507
|
-
|
|
508
|
-
x = _this.options.relativeGamma ? gammaFixed : gamma;
|
|
443
|
+
x = _this.options.relativeGamma ? gamma - referGamma : gamma;
|
|
509
444
|
x = _this.filterX.stableFix(x);
|
|
510
445
|
x = _this.filterX.changeLimit(x);
|
|
511
446
|
x = _this.filterX.linearRegressionMedian(+x);
|
|
@@ -513,9 +448,7 @@ var DeviceOrientation = /*#__PURE__*/ function() {
|
|
|
513
448
|
x = 0;
|
|
514
449
|
}
|
|
515
450
|
if (_this.options.Y) {
|
|
516
|
-
|
|
517
|
-
betaFixed = beta - referBeta;
|
|
518
|
-
y = _this.options.relativeBeta ? betaFixed : beta;
|
|
451
|
+
y = _this.options.relativeBeta ? beta - referBeta : beta;
|
|
519
452
|
y = _this.filterY.stableFix(y);
|
|
520
453
|
y = _this.filterY.changeLimit(y);
|
|
521
454
|
y = _this.filterY.linearRegressionMedian(+y);
|
|
@@ -527,15 +460,15 @@ var DeviceOrientation = /*#__PURE__*/ function() {
|
|
|
527
460
|
window.requestAnimationFrame(function() {
|
|
528
461
|
callback(x, y, {
|
|
529
462
|
alpha: alpha,
|
|
530
|
-
beta:
|
|
531
|
-
gamma:
|
|
463
|
+
beta: y - referBeta,
|
|
464
|
+
gamma: x - referGamma
|
|
532
465
|
});
|
|
533
466
|
});
|
|
534
467
|
} else {
|
|
535
468
|
callback(x, y, {
|
|
536
469
|
alpha: alpha,
|
|
537
|
-
beta:
|
|
538
|
-
gamma:
|
|
470
|
+
beta: y - referBeta,
|
|
471
|
+
gamma: x - referGamma
|
|
539
472
|
});
|
|
540
473
|
}
|
|
541
474
|
_this.lastX = x;
|
|
@@ -693,10 +626,13 @@ function switchWindVane(open, interval) {
|
|
|
693
626
|
validRange: this.validRange,
|
|
694
627
|
stableRange: 3
|
|
695
628
|
});
|
|
696
|
-
this.accelerMotion.watch(function(x, y) {
|
|
629
|
+
this.accelerMotion.watch(function(x, y, param) {
|
|
630
|
+
var beta = param.beta, gamma = param.gamma;
|
|
697
631
|
var motion = {
|
|
698
632
|
x: x,
|
|
699
|
-
y: y
|
|
633
|
+
y: y,
|
|
634
|
+
beta: beta,
|
|
635
|
+
gamma: gamma
|
|
700
636
|
};
|
|
701
637
|
_this.dispatchMotion(motion);
|
|
702
638
|
});
|
|
@@ -819,8 +755,74 @@ function openDeviceMotion() {
|
|
|
819
755
|
getAdapter().connect();
|
|
820
756
|
}
|
|
821
757
|
|
|
758
|
+
var OrientationComponent = /*#__PURE__*/ function(ItemBehaviour) {
|
|
759
|
+
_inherits(OrientationComponent, ItemBehaviour);
|
|
760
|
+
function OrientationComponent() {
|
|
761
|
+
return ItemBehaviour.apply(this, arguments);
|
|
762
|
+
}
|
|
763
|
+
var _proto = OrientationComponent.prototype;
|
|
764
|
+
_proto.fromData = function fromData(data) {
|
|
765
|
+
ItemBehaviour.prototype.fromData.call(this, data);
|
|
766
|
+
var targets = data.content.options.targets;
|
|
767
|
+
if (targets) {
|
|
768
|
+
this.targets = targets.map(function(t) {
|
|
769
|
+
return {
|
|
770
|
+
name: t.name,
|
|
771
|
+
xMin: +t.xMin || 0,
|
|
772
|
+
yMin: +t.yMin || 0,
|
|
773
|
+
xMax: +t.xMax || 0,
|
|
774
|
+
yMax: +t.yMax || 0,
|
|
775
|
+
vMin: +t.vMin || 0,
|
|
776
|
+
hMin: +t.hMin || 0,
|
|
777
|
+
vMax: +t.vMax || 0,
|
|
778
|
+
hMax: +t.hMax || 0
|
|
779
|
+
};
|
|
780
|
+
});
|
|
781
|
+
}
|
|
782
|
+
};
|
|
783
|
+
_proto.start = function start() {
|
|
784
|
+
var _this_item_composition;
|
|
785
|
+
var transformer = (_this_item_composition = this.item.composition) == null ? void 0 : _this_item_composition.loaderData.deviceTransformer;
|
|
786
|
+
if (transformer) {
|
|
787
|
+
var _this_targets;
|
|
788
|
+
(_this_targets = this.targets) == null ? void 0 : _this_targets.forEach(function(target) {
|
|
789
|
+
return transformer.addTarget(target);
|
|
790
|
+
});
|
|
791
|
+
transformer.initComposition();
|
|
792
|
+
}
|
|
793
|
+
};
|
|
794
|
+
_proto.update = function update(dt) {
|
|
795
|
+
var _this_item_composition;
|
|
796
|
+
var transformer = (_this_item_composition = this.item.composition) == null ? void 0 : _this_item_composition.loaderData.deviceTransformer;
|
|
797
|
+
if (transformer) {
|
|
798
|
+
transformer.updateOrientation();
|
|
799
|
+
}
|
|
800
|
+
};
|
|
801
|
+
_proto.onDestroy = function onDestroy() {
|
|
802
|
+
var _this = this;
|
|
803
|
+
var _this_targets;
|
|
804
|
+
(_this_targets = this.targets) == null ? void 0 : _this_targets.forEach(function(target) {
|
|
805
|
+
var _this_item_composition_loaderData_deviceTransformer, _this_item_composition;
|
|
806
|
+
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);
|
|
807
|
+
});
|
|
808
|
+
};
|
|
809
|
+
return OrientationComponent;
|
|
810
|
+
}(effects.ItemBehaviour);
|
|
811
|
+
|
|
812
|
+
var TransformVFXItem = /*#__PURE__*/ function(VFXItem) {
|
|
813
|
+
_inherits(TransformVFXItem, VFXItem);
|
|
814
|
+
function TransformVFXItem(engine, props) {
|
|
815
|
+
var _this;
|
|
816
|
+
_this = VFXItem.call(this, engine, props) || this;
|
|
817
|
+
var component = _this.addComponent(OrientationComponent);
|
|
818
|
+
component.fromData(props);
|
|
819
|
+
return _this;
|
|
820
|
+
}
|
|
821
|
+
return TransformVFXItem;
|
|
822
|
+
}(effects.VFXItem);
|
|
823
|
+
|
|
822
824
|
effects.registerPlugin("orientation-transformer", OrientationPluginLoader, TransformVFXItem);
|
|
823
|
-
var version = "2.0.0-alpha.
|
|
825
|
+
var version = "2.0.0-alpha.12";
|
|
824
826
|
effects.logger.info("plugin orientation transformer version: " + version);
|
|
825
827
|
|
|
826
828
|
exports.OrientationAdapterAcceler = OrientationAdapterAcceler;
|