@galacean/effects-plugin-orientation-transformer 2.0.0-alpha.4 → 2.0.0-alpha.6
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 +4 -10
- package/dist/index.js +359 -342
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +3 -4
- package/dist/index.min.js.map +1 -1
- package/dist/index.mjs +360 -343
- package/dist/index.mjs.map +1 -1
- package/dist/transform-vfx-item.d.ts +4 -0
- package/package.json +3 -3
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.6
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
'use strict';
|
|
@@ -12,155 +12,197 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
12
12
|
|
|
13
13
|
var effects = require('@galacean/effects');
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
if (
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
};
|
|
15
|
+
function _set_prototype_of(o, p) {
|
|
16
|
+
_set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
|
17
|
+
o.__proto__ = p;
|
|
18
|
+
return o;
|
|
19
|
+
};
|
|
20
|
+
return _set_prototype_of(o, p);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function _inherits(subClass, superClass) {
|
|
24
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
25
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
26
|
+
}
|
|
27
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
28
|
+
constructor: {
|
|
29
|
+
value: subClass,
|
|
30
|
+
writable: true,
|
|
31
|
+
configurable: true
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
if (superClass) _set_prototype_of(subClass, superClass);
|
|
35
|
+
}
|
|
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);
|
|
88
105
|
|
|
89
|
-
var CompositionTransformerAcceler =
|
|
106
|
+
var CompositionTransformerAcceler = /*#__PURE__*/ function() {
|
|
90
107
|
function CompositionTransformerAcceler(composition) {
|
|
91
108
|
this.composition = composition;
|
|
92
109
|
this.targets = {};
|
|
93
110
|
this.records = {};
|
|
94
|
-
this.
|
|
95
|
-
this.
|
|
96
|
-
this.
|
|
111
|
+
this.currentPos = {};
|
|
112
|
+
this.currentRot = {};
|
|
113
|
+
this.gammaRange = [
|
|
114
|
+
-89,
|
|
115
|
+
89
|
|
116
|
+
];
|
|
117
|
+
this.betaRange = [
|
|
118
|
+
-89,
|
|
119
|
+
89
|
|
120
|
+
];
|
|
97
121
|
}
|
|
98
|
-
CompositionTransformerAcceler.prototype
|
|
99
|
-
|
|
100
|
-
|
|
122
|
+
var _proto = CompositionTransformerAcceler.prototype;
|
|
123
|
+
_proto.update = function update(param) {
|
|
124
|
+
var x = param.x, y = param.y;
|
|
125
|
+
this.currentEvent = {
|
|
126
|
+
x: x,
|
|
127
|
+
y: y
|
|
128
|
+
};
|
|
101
129
|
};
|
|
102
|
-
|
|
130
|
+
_proto.updateOrientation = function updateOrientation() {
|
|
103
131
|
var _this = this;
|
|
104
132
|
var event = this.currentEvent;
|
|
105
133
|
if (event) {
|
|
106
|
-
Object.getOwnPropertyNames(this.targets).forEach(function
|
|
134
|
+
Object.getOwnPropertyNames(this.targets).forEach(function(name) {
|
|
107
135
|
_this.moveLayer(name, event);
|
|
108
136
|
});
|
|
109
137
|
}
|
|
110
138
|
};
|
|
111
|
-
|
|
139
|
+
_proto.initComposition = function initComposition() {
|
|
112
140
|
var items = this.composition.items;
|
|
113
|
-
for
|
|
141
|
+
for(var i = 0; i < items.length; i++){
|
|
114
142
|
var item = items[i];
|
|
115
143
|
var target = this.targets[item.name];
|
|
116
144
|
if (target) {
|
|
117
145
|
var position = item.transform.position.toArray();
|
|
118
|
-
var
|
|
146
|
+
var rotation = item.transform.rotation.toArray();
|
|
147
|
+
var currentPosition = this.currentPos[item.name];
|
|
148
|
+
var currentRot = this.currentRot[item.name];
|
|
119
149
|
this.records[item.name] = {
|
|
120
150
|
item: item,
|
|
121
151
|
position: position,
|
|
152
|
+
rotation: rotation
|
|
122
153
|
};
|
|
123
154
|
if (currentPosition) {
|
|
124
|
-
|
|
125
|
-
|
|
155
|
+
item.transform.setPosition(currentPosition[0], currentPosition[1], currentPosition[2]);
|
|
156
|
+
}
|
|
157
|
+
if (currentRot) {
|
|
158
|
+
item.transform.setRotation(currentRot[0], currentRot[1], currentRot[2]);
|
|
126
159
|
}
|
|
127
160
|
}
|
|
128
161
|
}
|
|
129
162
|
};
|
|
130
|
-
|
|
163
|
+
_proto.addTarget = function addTarget(target) {
|
|
131
164
|
this.targets[target.name] = target;
|
|
132
165
|
};
|
|
133
|
-
|
|
166
|
+
_proto.removeTarget = function removeTarget(name) {
|
|
134
167
|
delete this.targets[name];
|
|
135
168
|
delete this.records[name];
|
|
136
169
|
};
|
|
137
|
-
|
|
138
|
-
var
|
|
139
|
-
var
|
|
140
|
-
var
|
|
141
|
-
var layer = (_c = this.records[name]) === null || _c === void 0 ? void 0 : _c.item;
|
|
170
|
+
_proto.moveLayer = function moveLayer(name, param) {
|
|
171
|
+
var x = param.x, y = param.y;
|
|
172
|
+
var _this_records_name;
|
|
173
|
+
var layer = (_this_records_name = this.records[name]) == null ? void 0 : _this_records_name.item;
|
|
142
174
|
if (layer) {
|
|
143
175
|
var initPosition = this.records[name].position;
|
|
176
|
+
var initRotation = this.records[name].rotation;
|
|
144
177
|
var target = this.targets[name];
|
|
145
178
|
var beta = clamp(x, this.betaRange), gamma = clamp(y, this.gammaRange);
|
|
146
179
|
if (target) {
|
|
180
|
+
var _layer_transform, _layer_transform1;
|
|
147
181
|
var position = [
|
|
148
182
|
initPosition[0] + 1.2 * mapRange((beta - this.gammaRange[0]) / (this.gammaRange[1] - this.gammaRange[0]), target.xMin, target.xMax),
|
|
149
183
|
initPosition[1] + 1.2 * mapRange((gamma - this.betaRange[0]) / (this.betaRange[1] - this.betaRange[0]), target.yMin, target.yMax),
|
|
150
|
-
initPosition[2]
|
|
184
|
+
initPosition[2]
|
|
151
185
|
];
|
|
152
|
-
|
|
153
|
-
this.
|
|
186
|
+
var br = (clamp(x * 2, this.betaRange) - this.betaRange[0]) / (this.betaRange[1] - this.betaRange[0]);
|
|
187
|
+
var gr = (clamp(y * 2 - VERTICAL_INIT_DEGREE, this.gammaRange) - this.gammaRange[0]) / (this.gammaRange[1] - this.gammaRange[0]);
|
|
188
|
+
var rotation = [
|
|
189
|
+
initRotation[0] + mapRange(gr, target.hMin, target.hMax),
|
|
190
|
+
initRotation[1] + mapRange(br, target.vMin, target.vMax),
|
|
191
|
+
initRotation[2]
|
|
192
|
+
];
|
|
193
|
+
(_layer_transform = layer.transform).setPosition.apply(_layer_transform, [].concat(position));
|
|
194
|
+
(_layer_transform1 = layer.transform).setRotation.apply(_layer_transform1, [].concat(rotation));
|
|
195
|
+
this.currentPos[name] = position.slice();
|
|
196
|
+
this.currentRot[name] = rotation.slice();
|
|
154
197
|
}
|
|
155
198
|
}
|
|
156
199
|
};
|
|
157
200
|
return CompositionTransformerAcceler;
|
|
158
|
-
}()
|
|
201
|
+
}();
|
|
159
202
|
function clamp(x, range) {
|
|
160
203
|
if (x < range[0]) {
|
|
161
204
|
return range[0];
|
|
162
|
-
}
|
|
163
|
-
else if (x > range[1]) {
|
|
205
|
+
} else if (x > range[1]) {
|
|
164
206
|
return range[1];
|
|
165
207
|
}
|
|
166
208
|
return x;
|
|
@@ -178,71 +220,75 @@ function getObjectType(obj) {
|
|
|
178
220
|
* @internal
|
|
179
221
|
* @param angleObj 角度数值对象
|
|
180
222
|
* @param validRange 角度限制值
|
|
181
|
-
*/
|
|
182
|
-
function angleLimit(angleObj, validRange) {
|
|
223
|
+
*/ function angleLimit(angleObj, validRange) {
|
|
183
224
|
var flagAlpha = true;
|
|
184
225
|
var flagBeta = true;
|
|
185
226
|
var flagGamma = true;
|
|
186
|
-
if (getObjectType(validRange.alpha) ===
|
|
227
|
+
if (getObjectType(validRange.alpha) === "[object Array]" && validRange.alpha.length >= 2) {
|
|
187
228
|
var referAlphaA = angleObj.alpha + validRange.alpha[0];
|
|
188
229
|
var referAlphaB = angleObj.alpha + validRange.alpha[1];
|
|
189
230
|
referAlphaA = referAlphaA < 0 ? referAlphaA + 360 : referAlphaA;
|
|
190
231
|
referAlphaB = referAlphaB > 360 ? referAlphaB - 360 : referAlphaB;
|
|
191
232
|
if (referAlphaA < referAlphaB) {
|
|
192
233
|
flagAlpha = angleObj.alpha > referAlphaA && angleObj.alpha < referAlphaB;
|
|
193
|
-
}
|
|
194
|
-
else {
|
|
234
|
+
} else {
|
|
195
235
|
flagAlpha = angleObj.alpha > referAlphaA || angleObj.alpha < referAlphaB;
|
|
196
236
|
}
|
|
197
237
|
}
|
|
198
|
-
if (getObjectType(validRange.beta) ===
|
|
238
|
+
if (getObjectType(validRange.beta) === "[object Array]" && validRange.beta.length >= 2) {
|
|
199
239
|
flagBeta = angleObj.beta >= validRange.beta[0] && angleObj.beta <= validRange.beta[1];
|
|
200
240
|
}
|
|
201
|
-
if (getObjectType(validRange.gamma) ===
|
|
241
|
+
if (getObjectType(validRange.gamma) === "[object Array]" && validRange.gamma.length >= 2) {
|
|
202
242
|
flagGamma = angleObj.gamma >= validRange.gamma[0] && angleObj.gamma <= validRange.gamma[1];
|
|
203
243
|
}
|
|
204
244
|
return flagAlpha && flagBeta && flagGamma;
|
|
205
245
|
}
|
|
206
246
|
|
|
247
|
+
function _extends() {
|
|
248
|
+
_extends = Object.assign || function assign(target) {
|
|
249
|
+
for(var i = 1; i < arguments.length; i++){
|
|
250
|
+
var source = arguments[i];
|
|
251
|
+
for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
|
|
252
|
+
}
|
|
253
|
+
return target;
|
|
254
|
+
};
|
|
255
|
+
return _extends.apply(this, arguments);
|
|
256
|
+
}
|
|
257
|
+
|
|
207
258
|
function deepMerge(target, args) {
|
|
208
259
|
if (!effects.isObject(target) && !effects.isArray(target)) {
|
|
209
260
|
return target;
|
|
210
261
|
}
|
|
211
|
-
var result = effects.isArray(target) ?
|
|
262
|
+
var result = effects.isArray(target) ? [].concat(target) : _extends({}, target);
|
|
212
263
|
var length = arguments.length;
|
|
213
|
-
for
|
|
264
|
+
for(var index = 1; index < length; index++){
|
|
214
265
|
var source = arguments[index] || {};
|
|
215
266
|
if (effects.isObject(source)) {
|
|
216
267
|
var prop = void 0;
|
|
217
|
-
for
|
|
268
|
+
for(prop in source){
|
|
218
269
|
if (source.hasOwnProperty(prop)) {
|
|
219
270
|
if (effects.isObject(result[prop]) && effects.isObject(source[prop])) {
|
|
220
271
|
result[prop] = deepMerge(result[prop], source[prop]);
|
|
221
|
-
}
|
|
222
|
-
else if (effects.isObject(source[prop])) {
|
|
272
|
+
} else if (effects.isObject(source[prop])) {
|
|
223
273
|
result[prop] = deepMerge(source[prop]);
|
|
224
|
-
}
|
|
225
|
-
else if (effects.isArray(source[prop])) {
|
|
274
|
+
} else if (effects.isArray(source[prop])) {
|
|
226
275
|
result[prop] = deepMerge(source[prop]);
|
|
227
|
-
}
|
|
228
|
-
else {
|
|
276
|
+
} else {
|
|
229
277
|
result[prop] = source[prop];
|
|
230
278
|
}
|
|
231
279
|
}
|
|
232
280
|
}
|
|
233
|
-
for
|
|
234
|
-
if (effects.isObject(result[prop]) &&
|
|
235
|
-
result.hasOwnProperty(prop) &&
|
|
236
|
-
!source.hasOwnProperty(prop)) {
|
|
281
|
+
for(prop in result){
|
|
282
|
+
if (effects.isObject(result[prop]) && result.hasOwnProperty(prop) && !source.hasOwnProperty(prop)) {
|
|
237
283
|
result[prop] = deepMerge(result[prop]);
|
|
238
284
|
}
|
|
239
285
|
}
|
|
240
286
|
}
|
|
241
287
|
}
|
|
242
288
|
if (length === 1) {
|
|
243
|
-
for
|
|
244
|
-
if (effects.isObject(result[
|
|
245
|
-
result[
|
|
289
|
+
for(var prop1 in result){
|
|
290
|
+
if (effects.isObject(result[prop1]) && result.hasOwnProperty(prop1)) {
|
|
291
|
+
result[prop1] = deepMerge(result[prop1]);
|
|
246
292
|
}
|
|
247
293
|
}
|
|
248
294
|
}
|
|
@@ -257,38 +303,33 @@ function isIOS() {
|
|
|
257
303
|
|
|
258
304
|
/**
|
|
259
305
|
* 稳定区间
|
|
260
|
-
*/
|
|
261
|
-
var STABLE_RANGE = 3;
|
|
306
|
+
*/ var STABLE_RANGE = 3;
|
|
262
307
|
/**
|
|
263
308
|
* 每次增幅的最大值
|
|
264
|
-
*/
|
|
265
|
-
var MAX_CHANGE = 5;
|
|
309
|
+
*/ var MAX_CHANGE = 5;
|
|
266
310
|
/**
|
|
267
311
|
* 每次增幅的最小值
|
|
268
|
-
*/
|
|
269
|
-
var MIN_CHANGE = 1;
|
|
312
|
+
*/ var MIN_CHANGE = 1;
|
|
270
313
|
/**
|
|
271
314
|
* 数据缓存队列的长度
|
|
272
|
-
*/
|
|
273
|
-
var VALUE_POOL_LENGTH = 5;
|
|
315
|
+
*/ var VALUE_POOL_LENGTH = 5;
|
|
274
316
|
/**
|
|
275
317
|
* 滤波方法
|
|
276
|
-
*/
|
|
277
|
-
var Filtering = /** @class */ (function () {
|
|
318
|
+
*/ var Filtering = /*#__PURE__*/ function() {
|
|
278
319
|
function Filtering(options) {
|
|
279
|
-
if (options === void 0)
|
|
320
|
+
if (options === void 0) options = {};
|
|
280
321
|
this.options = options;
|
|
281
322
|
this.lastValue = 0;
|
|
282
323
|
this.valuePool = [];
|
|
283
324
|
}
|
|
325
|
+
var _proto = Filtering.prototype;
|
|
284
326
|
/**
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
Filtering.prototype.stableFix = function (value) {
|
|
327
|
+
* 0deg 左右保持一定的稳定区间 STABLE_RANGE
|
|
328
|
+
* - 小于 STABLE_RANGE 的算 0
|
|
329
|
+
* - 大于 STABLE_RANGE 的减去 STABLE_RANGE
|
|
330
|
+
* @param value - 输入值
|
|
331
|
+
* @returns
|
|
332
|
+
*/ _proto.stableFix = function stableFix(value) {
|
|
292
333
|
var stableRange = this.options.stableRange || STABLE_RANGE;
|
|
293
334
|
if (Math.abs(value) < stableRange) {
|
|
294
335
|
return 0;
|
|
@@ -296,13 +337,12 @@ var Filtering = /** @class */ (function () {
|
|
|
296
337
|
return value > stableRange ? value - stableRange : value + stableRange;
|
|
297
338
|
};
|
|
298
339
|
/**
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
Filtering.prototype.changeLimit = function (value) {
|
|
340
|
+
* 变幅限制
|
|
341
|
+
* - 最大变化 MAX_CHANGE
|
|
342
|
+
* - 最小变化 MIN_CHANGE
|
|
343
|
+
* @param value
|
|
344
|
+
* @returns
|
|
345
|
+
*/ _proto.changeLimit = function changeLimit(value) {
|
|
306
346
|
var lastValue = this.lastValue;
|
|
307
347
|
var result = value;
|
|
308
348
|
if (Math.abs(value - lastValue) > MAX_CHANGE) {
|
|
@@ -314,21 +354,20 @@ var Filtering = /** @class */ (function () {
|
|
|
314
354
|
this.lastValue = result;
|
|
315
355
|
return result;
|
|
316
356
|
};
|
|
317
|
-
|
|
357
|
+
_proto.linearRegressionMedian = function linearRegressionMedian(value) {
|
|
318
358
|
// 在队列中装载数据,达到队列阀值长度时开始计算
|
|
319
359
|
this.valuePool.push(value);
|
|
320
360
|
var result;
|
|
321
361
|
if (this.valuePool.length >= VALUE_POOL_LENGTH) {
|
|
322
362
|
result = getLinearRegressionFixedVal(this.valuePool);
|
|
323
363
|
this.valuePool.shift();
|
|
324
|
-
}
|
|
325
|
-
else {
|
|
364
|
+
} else {
|
|
326
365
|
result = this.lastValue;
|
|
327
366
|
}
|
|
328
367
|
return result;
|
|
329
368
|
};
|
|
330
369
|
return Filtering;
|
|
331
|
-
}()
|
|
370
|
+
}();
|
|
332
371
|
// 计算出线性回归参数
|
|
333
372
|
function linearRegression(x, y) {
|
|
334
373
|
var result = {};
|
|
@@ -338,30 +377,30 @@ function linearRegression(x, y) {
|
|
|
338
377
|
var sumXY = 0;
|
|
339
378
|
var sumXX = 0;
|
|
340
379
|
var sumYY = 0;
|
|
341
|
-
for
|
|
380
|
+
for(var i = 0; i < y.length; i++){
|
|
342
381
|
sumX += x[i];
|
|
343
382
|
sumY += y[i];
|
|
344
|
-
sumXY +=
|
|
345
|
-
sumXX +=
|
|
346
|
-
sumYY +=
|
|
383
|
+
sumXY += x[i] * y[i];
|
|
384
|
+
sumXX += x[i] * x[i];
|
|
385
|
+
sumYY += y[i] * y[i];
|
|
347
386
|
}
|
|
348
387
|
var avgX = sumX / n;
|
|
349
388
|
var avgY = sumY / n;
|
|
350
|
-
result[
|
|
351
|
-
result[
|
|
352
|
-
result[
|
|
389
|
+
result["a"] = (sumXY - n * avgX * avgY) / (sumXX - n * avgX * avgX);
|
|
390
|
+
result["b"] = avgY - result.a * avgX;
|
|
391
|
+
result["miss"] = Math.pow((n * sumXY - sumX * sumY) / Math.sqrt((n * sumXX - sumX * sumX) * (n * sumYY - sumY * sumY)), 2);
|
|
353
392
|
return result;
|
|
354
393
|
}
|
|
355
394
|
// 生成线性回归函数 F(x) = ax + b
|
|
356
395
|
function createLinearRegressionFx(values) {
|
|
357
396
|
var x = [];
|
|
358
397
|
var y = [];
|
|
359
|
-
values.forEach(function
|
|
398
|
+
values.forEach(function(item, index) {
|
|
360
399
|
x.push(index); // 数据是连续的,所以直接取数组下标为 x
|
|
361
400
|
y.push(item);
|
|
362
401
|
});
|
|
363
402
|
var key = linearRegression(x, y);
|
|
364
|
-
return function
|
|
403
|
+
return function(x) {
|
|
365
404
|
return key.a * x + key.b;
|
|
366
405
|
};
|
|
367
406
|
}
|
|
@@ -369,14 +408,14 @@ function createLinearRegressionFx(values) {
|
|
|
369
408
|
function getLinearRegressionFixedVal(valuePool) {
|
|
370
409
|
var fx = createLinearRegressionFx(valuePool);
|
|
371
410
|
// 这个迭代修正很重要
|
|
372
|
-
valuePool = valuePool.map(function
|
|
411
|
+
valuePool = valuePool.map(function(item, index) {
|
|
373
412
|
return fx(index);
|
|
374
413
|
});
|
|
375
414
|
return fx(valuePool.length / 2);
|
|
376
415
|
}
|
|
377
416
|
|
|
378
|
-
var useJSBridge = isIOS() && typeof window.AlipayJSBridge !==
|
|
379
|
-
var useWindVane = typeof window.WindVane !==
|
|
417
|
+
var useJSBridge = isIOS() && typeof window.AlipayJSBridge !== "undefined";
|
|
418
|
+
var useWindVane = typeof window.WindVane !== "undefined";
|
|
380
419
|
// 默认参数
|
|
381
420
|
var defaultOptions = {
|
|
382
421
|
X: true,
|
|
@@ -386,31 +425,45 @@ var defaultOptions = {
|
|
|
386
425
|
relativeBeta: false,
|
|
387
426
|
relativeGamma: false,
|
|
388
427
|
validRange: {
|
|
389
|
-
alpha: [
|
|
390
|
-
|
|
391
|
-
|
|
428
|
+
alpha: [
|
|
429
|
+
-60,
|
|
430
|
+
60
|
|
431
|
+
],
|
|
432
|
+
beta: [
|
|
433
|
+
-60,
|
|
434
|
+
180
|
|
435
|
+
],
|
|
436
|
+
gamma: [
|
|
437
|
+
-89,
|
|
438
|
+
89
|
|
439
|
+
]
|
|
392
440
|
},
|
|
393
|
-
stableRange: 3
|
|
441
|
+
stableRange: 3
|
|
394
442
|
};
|
|
395
|
-
var DeviceOrientation =
|
|
443
|
+
var DeviceOrientation = /*#__PURE__*/ function() {
|
|
396
444
|
function DeviceOrientation(options) {
|
|
397
|
-
if (options === void 0)
|
|
445
|
+
if (options === void 0) options = {};
|
|
398
446
|
this.lastX = 0;
|
|
399
447
|
this.lastY = 0;
|
|
400
448
|
this.prevAcceler = {
|
|
401
449
|
x: 0,
|
|
402
450
|
y: 0,
|
|
403
|
-
z: 0
|
|
451
|
+
z: 0
|
|
404
452
|
};
|
|
405
453
|
this.stoped = false;
|
|
406
454
|
this.options = deepMerge(defaultOptions, options);
|
|
407
455
|
var stableRange = this.options.stableRange;
|
|
408
|
-
this.filterX = new Filtering({
|
|
409
|
-
|
|
456
|
+
this.filterX = new Filtering({
|
|
457
|
+
stableRange: stableRange
|
|
458
|
+
});
|
|
459
|
+
this.filterY = new Filtering({
|
|
460
|
+
stableRange: stableRange
|
|
461
|
+
});
|
|
410
462
|
}
|
|
411
|
-
DeviceOrientation.prototype
|
|
463
|
+
var _proto = DeviceOrientation.prototype;
|
|
464
|
+
_proto.watch = function watch(callback) {
|
|
412
465
|
var _this = this;
|
|
413
|
-
if (typeof callback !==
|
|
466
|
+
if (typeof callback !== "function") {
|
|
414
467
|
return;
|
|
415
468
|
}
|
|
416
469
|
// 目前只能绑定一个方法,此处可以扩展成一个方法队列
|
|
@@ -429,7 +482,7 @@ var DeviceOrientation = /** @class */ (function () {
|
|
|
429
482
|
var isInValidDegRange;
|
|
430
483
|
var x; // 最终输出的 x
|
|
431
484
|
var y; // 最终输出的 y
|
|
432
|
-
var handleWatch = function
|
|
485
|
+
var handleWatch = function(e) {
|
|
433
486
|
if (_this.stoped) {
|
|
434
487
|
return;
|
|
435
488
|
}
|
|
@@ -446,7 +499,7 @@ var DeviceOrientation = /** @class */ (function () {
|
|
|
446
499
|
isInValidDegRange = angleLimit.call(_this, {
|
|
447
500
|
alpha: alpha,
|
|
448
501
|
beta: beta,
|
|
449
|
-
gamma: gamma
|
|
502
|
+
gamma: gamma
|
|
450
503
|
}, _this.options.validRange);
|
|
451
504
|
if (isInValidDegRange) {
|
|
452
505
|
// 最终结果值
|
|
@@ -456,8 +509,7 @@ var DeviceOrientation = /** @class */ (function () {
|
|
|
456
509
|
x = _this.filterX.stableFix(x);
|
|
457
510
|
x = _this.filterX.changeLimit(x);
|
|
458
511
|
x = _this.filterX.linearRegressionMedian(+x);
|
|
459
|
-
}
|
|
460
|
-
else {
|
|
512
|
+
} else {
|
|
461
513
|
x = 0;
|
|
462
514
|
}
|
|
463
515
|
if (_this.options.Y) {
|
|
@@ -467,18 +519,24 @@ var DeviceOrientation = /** @class */ (function () {
|
|
|
467
519
|
y = _this.filterY.stableFix(y);
|
|
468
520
|
y = _this.filterY.changeLimit(y);
|
|
469
521
|
y = _this.filterY.linearRegressionMedian(+y);
|
|
470
|
-
}
|
|
471
|
-
else {
|
|
522
|
+
} else {
|
|
472
523
|
y = 0;
|
|
473
524
|
}
|
|
474
525
|
if (_this.isValid(x, y)) {
|
|
475
526
|
if (_this.options.useRequestAnimationFrame) {
|
|
476
|
-
window.requestAnimationFrame(function
|
|
477
|
-
callback(x, y, {
|
|
527
|
+
window.requestAnimationFrame(function() {
|
|
528
|
+
callback(x, y, {
|
|
529
|
+
alpha: alpha,
|
|
530
|
+
beta: beta,
|
|
531
|
+
gamma: gamma
|
|
532
|
+
});
|
|
533
|
+
});
|
|
534
|
+
} else {
|
|
535
|
+
callback(x, y, {
|
|
536
|
+
alpha: alpha,
|
|
537
|
+
beta: beta,
|
|
538
|
+
gamma: gamma
|
|
478
539
|
});
|
|
479
|
-
}
|
|
480
|
-
else {
|
|
481
|
-
callback(x, y, { alpha: alpha, beta: beta, gamma: gamma });
|
|
482
540
|
}
|
|
483
541
|
_this.lastX = x;
|
|
484
542
|
_this.lastY = y;
|
|
@@ -489,51 +547,52 @@ var DeviceOrientation = /** @class */ (function () {
|
|
|
489
547
|
this.stoped = false;
|
|
490
548
|
if (useWindVane) {
|
|
491
549
|
switchWindVane(true, this.options.interval);
|
|
492
|
-
this.watchListener = function
|
|
493
|
-
if (
|
|
494
|
-
var
|
|
550
|
+
this.watchListener = function(e) {
|
|
551
|
+
if ("param" in e) {
|
|
552
|
+
var _e_param = e.param, x = _e_param.x, y = _e_param.y, z = _e_param.z;
|
|
495
553
|
// 即使手机没动,也会不停触发,所以这里加个判断,值相等则不调用回调
|
|
496
|
-
if (
|
|
554
|
+
if (x === _this.prevAcceler.x && y === _this.prevAcceler.y && z === _this.prevAcceler.z) {
|
|
497
555
|
return;
|
|
498
556
|
}
|
|
499
|
-
_this.prevAcceler = {
|
|
557
|
+
_this.prevAcceler = {
|
|
558
|
+
x: x,
|
|
559
|
+
y: y,
|
|
560
|
+
z: z
|
|
561
|
+
};
|
|
500
562
|
var evt = {
|
|
501
563
|
alpha: +z * 180,
|
|
502
|
-
beta: +
|
|
503
|
-
gamma: +
|
|
564
|
+
beta: +y * -90,
|
|
565
|
+
gamma: +x * 90
|
|
504
566
|
};
|
|
505
567
|
handleWatch(evt);
|
|
506
568
|
}
|
|
507
569
|
};
|
|
508
|
-
document.addEventListener(
|
|
509
|
-
}
|
|
510
|
-
else if (useJSBridge) {
|
|
570
|
+
document.addEventListener("motion.gyro", this.watchListener, false);
|
|
571
|
+
} else if (useJSBridge) {
|
|
511
572
|
switchIOSEvent(true, this.options.interval / 1000);
|
|
512
|
-
this.watchListener = function
|
|
513
|
-
if (e &&
|
|
573
|
+
this.watchListener = function(e) {
|
|
574
|
+
if (e && "data" in e) {
|
|
514
575
|
/*
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
var _a = e.data, x_2 = _a.x, y_2 = _a.y, z = _a.z;
|
|
576
|
+
data:
|
|
577
|
+
{
|
|
578
|
+
data: {
|
|
579
|
+
x: 0.0, // gamma -1 ~ 1
|
|
580
|
+
y: 0.0, // beta -1 ~ 1
|
|
581
|
+
z: 0.0, // alpha
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
*/ var _e_data = e.data, x = _e_data.x, y = _e_data.y, z = _e_data.z;
|
|
525
585
|
var evt = {
|
|
526
586
|
alpha: z * 180,
|
|
527
|
-
beta:
|
|
528
|
-
gamma:
|
|
587
|
+
beta: y * -90,
|
|
588
|
+
gamma: x * 90
|
|
529
589
|
};
|
|
530
590
|
handleWatch(evt);
|
|
531
591
|
}
|
|
532
592
|
};
|
|
533
|
-
document.addEventListener(
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
this.watchListener = function (e) {
|
|
593
|
+
document.addEventListener("accelerometerChange", this.watchListener, false);
|
|
594
|
+
} else {
|
|
595
|
+
this.watchListener = function(e) {
|
|
537
596
|
nowts = new Date().getTime();
|
|
538
597
|
// 控制时间片
|
|
539
598
|
if (nowts - timefragment >= _this.options.interval) {
|
|
@@ -541,80 +600,87 @@ var DeviceOrientation = /** @class */ (function () {
|
|
|
541
600
|
handleWatch(e);
|
|
542
601
|
}
|
|
543
602
|
};
|
|
544
|
-
window.addEventListener(
|
|
603
|
+
window.addEventListener("deviceorientation", this.watchListener, false);
|
|
545
604
|
}
|
|
546
605
|
};
|
|
547
|
-
|
|
606
|
+
_proto.unWatch = function unWatch() {
|
|
548
607
|
effects.assertExist(this.watchListener);
|
|
549
608
|
if (useWindVane) {
|
|
550
609
|
switchWindVane(false);
|
|
551
|
-
document.removeEventListener(
|
|
552
|
-
}
|
|
553
|
-
else if (useJSBridge) {
|
|
610
|
+
document.removeEventListener("motion.gyro", this.watchListener);
|
|
611
|
+
} else if (useJSBridge) {
|
|
554
612
|
switchIOSEvent(false);
|
|
555
|
-
document.removeEventListener(
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
window.removeEventListener('deviceorientation', this.watchListener);
|
|
613
|
+
document.removeEventListener("accelerometerChange", this.watchListener);
|
|
614
|
+
} else {
|
|
615
|
+
window.removeEventListener("deviceorientation", this.watchListener);
|
|
559
616
|
}
|
|
560
617
|
this.stoped = true;
|
|
561
618
|
this.watchListener = undefined;
|
|
562
619
|
};
|
|
563
|
-
|
|
620
|
+
_proto.pause = function pause() {
|
|
564
621
|
this.stoped = true;
|
|
565
622
|
if (useJSBridge) {
|
|
566
623
|
switchIOSEvent(false);
|
|
567
624
|
}
|
|
568
625
|
};
|
|
569
|
-
|
|
626
|
+
_proto.continue = function _continue() {
|
|
570
627
|
this.stoped = false;
|
|
571
628
|
if (useJSBridge) {
|
|
572
629
|
switchIOSEvent(true, this.options.interval / 1000);
|
|
573
630
|
}
|
|
574
631
|
};
|
|
575
|
-
|
|
632
|
+
_proto.isValid = function isValid(x, y) {
|
|
576
633
|
// 判断是否和上次的值一样,检测有没有变
|
|
577
634
|
return this.lastX !== x || this.lastY !== y;
|
|
578
635
|
};
|
|
579
636
|
return DeviceOrientation;
|
|
580
|
-
}()
|
|
637
|
+
}();
|
|
581
638
|
// 开启/关闭 iOS 的陀螺仪监听
|
|
582
639
|
function switchIOSEvent(open, interval) {
|
|
583
|
-
window.AlipayJSBridge.call(
|
|
640
|
+
window.AlipayJSBridge.call("watchShake", {
|
|
584
641
|
monitorGyroscope: false,
|
|
585
642
|
monitorAccelerometer: !!open,
|
|
586
|
-
interval: !open ? 10 : parseFloat(interval.toFixed(3))
|
|
587
|
-
}, function
|
|
643
|
+
interval: !open ? 10 : parseFloat(interval.toFixed(3))
|
|
644
|
+
}, function() {});
|
|
588
645
|
}
|
|
589
646
|
function switchWindVane(open, interval) {
|
|
590
647
|
var params = {
|
|
591
648
|
// 是开启还是关闭陀螺仪的监听
|
|
592
649
|
on: open,
|
|
593
650
|
// 陀螺仪事件的时间间隔
|
|
594
|
-
frequency: interval
|
|
651
|
+
frequency: interval
|
|
595
652
|
};
|
|
596
|
-
window.WindVane.call(
|
|
597
|
-
console.info(
|
|
598
|
-
}, function
|
|
599
|
-
console.error(
|
|
653
|
+
window.WindVane.call("WVMotion", "listenGyro", params, function(e) {
|
|
654
|
+
console.info("call WVMotion success");
|
|
655
|
+
}, function(e) {
|
|
656
|
+
console.error("call WVMotion failed:" + JSON.stringify(e));
|
|
600
657
|
});
|
|
601
658
|
}
|
|
602
659
|
|
|
603
660
|
/**
|
|
604
661
|
*
|
|
605
|
-
*/
|
|
606
|
-
var OrientationAdapterAcceler = /** @class */ (function () {
|
|
662
|
+
*/ var OrientationAdapterAcceler = /*#__PURE__*/ function() {
|
|
607
663
|
function OrientationAdapterAcceler() {
|
|
608
664
|
this.transformers = [];
|
|
609
665
|
this.connected = false;
|
|
610
666
|
this.accelerMotion = null;
|
|
611
667
|
this.validRange = {
|
|
612
|
-
alpha: [
|
|
613
|
-
|
|
614
|
-
|
|
668
|
+
alpha: [
|
|
669
|
+
-60,
|
|
670
|
+
60
|
|
671
|
+
],
|
|
672
|
+
beta: [
|
|
673
|
+
-80,
|
|
674
|
+
80
|
|
675
|
+
],
|
|
676
|
+
gamma: [
|
|
677
|
+
-89,
|
|
678
|
+
89
|
|
679
|
+
]
|
|
615
680
|
};
|
|
616
681
|
}
|
|
617
|
-
OrientationAdapterAcceler.prototype
|
|
682
|
+
var _proto = OrientationAdapterAcceler.prototype;
|
|
683
|
+
_proto.connect = function connect() {
|
|
618
684
|
var _this = this;
|
|
619
685
|
if (!this.connected) {
|
|
620
686
|
this.accelerMotion = new DeviceOrientation({
|
|
@@ -625,37 +691,38 @@ var OrientationAdapterAcceler = /** @class */ (function () {
|
|
|
625
691
|
relativeBeta: false,
|
|
626
692
|
relativeGamma: false,
|
|
627
693
|
validRange: this.validRange,
|
|
628
|
-
stableRange: 3
|
|
694
|
+
stableRange: 3
|
|
629
695
|
});
|
|
630
|
-
this.accelerMotion.watch(function
|
|
696
|
+
this.accelerMotion.watch(function(x, y) {
|
|
631
697
|
var motion = {
|
|
632
698
|
x: x,
|
|
633
|
-
y: y
|
|
699
|
+
y: y
|
|
634
700
|
};
|
|
635
701
|
_this.dispatchMotion(motion);
|
|
636
702
|
});
|
|
637
703
|
}
|
|
638
704
|
this.connected = true;
|
|
639
705
|
};
|
|
640
|
-
|
|
706
|
+
_proto.disconnect = function disconnect() {
|
|
641
707
|
if (this.accelerMotion) {
|
|
642
708
|
this.accelerMotion.unWatch();
|
|
643
709
|
}
|
|
644
710
|
this.connected = false;
|
|
645
711
|
};
|
|
646
712
|
/**
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
713
|
+
*
|
|
714
|
+
* @param motion
|
|
715
|
+
*/ _proto.dispatchMotion = function dispatchMotion(motion) {
|
|
716
|
+
this.transformers.forEach(function(t) {
|
|
717
|
+
return t.update(motion);
|
|
718
|
+
});
|
|
719
|
+
};
|
|
720
|
+
_proto.addTransformer = function addTransformer(transformer) {
|
|
654
721
|
if (!this.transformers.includes(transformer)) {
|
|
655
722
|
this.transformers.push(transformer);
|
|
656
723
|
}
|
|
657
724
|
};
|
|
658
|
-
|
|
725
|
+
_proto.removeTransformer = function removeTransformer(transformer) {
|
|
659
726
|
var index = this.transformers.indexOf(transformer);
|
|
660
727
|
if (index > -1) {
|
|
661
728
|
this.transformers.splice(index, 1);
|
|
@@ -663,7 +730,7 @@ var OrientationAdapterAcceler = /** @class */ (function () {
|
|
|
663
730
|
return this.transformers.length === 0;
|
|
664
731
|
};
|
|
665
732
|
return OrientationAdapterAcceler;
|
|
666
|
-
}()
|
|
733
|
+
}();
|
|
667
734
|
var adapter;
|
|
668
735
|
function getAccelerAdapter() {
|
|
669
736
|
if (!adapter) {
|
|
@@ -672,72 +739,74 @@ function getAccelerAdapter() {
|
|
|
672
739
|
return adapter;
|
|
673
740
|
}
|
|
674
741
|
|
|
675
|
-
var OrientationPluginLoader =
|
|
676
|
-
|
|
742
|
+
var OrientationPluginLoader = /*#__PURE__*/ function(AbstractPlugin) {
|
|
743
|
+
_inherits(OrientationPluginLoader, AbstractPlugin);
|
|
677
744
|
function OrientationPluginLoader() {
|
|
678
|
-
var _this
|
|
745
|
+
var _this;
|
|
746
|
+
_this = AbstractPlugin.apply(this, arguments) || this;
|
|
679
747
|
_this.order = 90;
|
|
680
748
|
_this.adapter = null;
|
|
681
|
-
_this.handleConnect = function
|
|
682
|
-
var _a;
|
|
749
|
+
_this.handleConnect = function() {
|
|
683
750
|
if (!closeManually) {
|
|
684
|
-
|
|
751
|
+
var _this_adapter;
|
|
752
|
+
(_this_adapter = _this.adapter) == null ? void 0 : _this_adapter.connect();
|
|
685
753
|
}
|
|
686
754
|
};
|
|
687
|
-
_this.handleDisconnect = function
|
|
688
|
-
var
|
|
689
|
-
(
|
|
755
|
+
_this.handleDisconnect = function() {
|
|
756
|
+
var _this_adapter;
|
|
757
|
+
(_this_adapter = _this.adapter) == null ? void 0 : _this_adapter.disconnect();
|
|
690
758
|
};
|
|
691
759
|
return _this;
|
|
692
760
|
}
|
|
693
|
-
OrientationPluginLoader.prototype
|
|
694
|
-
|
|
761
|
+
var _proto = OrientationPluginLoader.prototype;
|
|
762
|
+
_proto.onCompositionConstructed = function onCompositionConstructed() {
|
|
763
|
+
var _this_adapter;
|
|
695
764
|
this.adapter = getAdapter();
|
|
696
|
-
(
|
|
765
|
+
(_this_adapter = this.adapter) == null ? void 0 : _this_adapter.connect();
|
|
697
766
|
this.bindAccelerDocumentEvent();
|
|
698
767
|
};
|
|
699
|
-
|
|
700
|
-
var
|
|
768
|
+
_proto.onCompositionReset = function onCompositionReset(composition) {
|
|
769
|
+
var _this_adapter;
|
|
701
770
|
var transformer = composition.loaderData.deviceTransformer = new CompositionTransformerAcceler(composition);
|
|
702
|
-
(
|
|
771
|
+
(_this_adapter = this.adapter) == null ? void 0 : _this_adapter.addTransformer(transformer);
|
|
703
772
|
};
|
|
704
|
-
|
|
773
|
+
_proto.onCompositionUpdate = function onCompositionUpdate(composition) {
|
|
705
774
|
var transformer = composition.loaderData.deviceTransformer;
|
|
706
775
|
if (transformer) {
|
|
707
776
|
transformer.updateOrientation();
|
|
708
777
|
}
|
|
709
778
|
};
|
|
710
|
-
|
|
711
|
-
var
|
|
712
|
-
var empty = (
|
|
779
|
+
_proto.onCompositionDestroyed = function onCompositionDestroyed(composition) {
|
|
780
|
+
var _this_adapter;
|
|
781
|
+
var empty = (_this_adapter = this.adapter) == null ? void 0 : _this_adapter.removeTransformer(composition.loaderData.deviceTransformer);
|
|
713
782
|
if (empty) {
|
|
714
|
-
|
|
783
|
+
var _this_adapter1;
|
|
784
|
+
(_this_adapter1 = this.adapter) == null ? void 0 : _this_adapter1.disconnect();
|
|
715
785
|
}
|
|
716
786
|
};
|
|
717
|
-
|
|
787
|
+
_proto.bindAccelerDocumentEvent = function bindAccelerDocumentEvent() {
|
|
718
788
|
this.unbindAccelerDocumentEvent(); // 保证全局只监听一份
|
|
719
|
-
document.addEventListener(
|
|
720
|
-
document.addEventListener(
|
|
721
|
-
document.addEventListener(
|
|
789
|
+
document.addEventListener("resume", this.handleConnect, false);
|
|
790
|
+
document.addEventListener("pause", this.handleDisconnect, false);
|
|
791
|
+
document.addEventListener("back", this.handleDisconnect, false);
|
|
722
792
|
};
|
|
723
|
-
|
|
724
|
-
document.removeEventListener(
|
|
725
|
-
document.removeEventListener(
|
|
726
|
-
document.removeEventListener(
|
|
793
|
+
_proto.unbindAccelerDocumentEvent = function unbindAccelerDocumentEvent() {
|
|
794
|
+
document.removeEventListener("resume", this.handleConnect);
|
|
795
|
+
document.removeEventListener("pause", this.handleDisconnect);
|
|
796
|
+
document.removeEventListener("back", this.handleDisconnect);
|
|
727
797
|
};
|
|
728
|
-
|
|
798
|
+
_proto.dispose = function dispose() {
|
|
729
799
|
getAdapter().disconnect();
|
|
730
800
|
this.unbindAccelerDocumentEvent();
|
|
731
801
|
};
|
|
732
802
|
return OrientationPluginLoader;
|
|
733
|
-
}(effects.AbstractPlugin)
|
|
803
|
+
}(effects.AbstractPlugin);
|
|
734
804
|
// 是否是手动关闭,如果是,那么 resume 时不要恢复
|
|
735
805
|
var closeManually = false;
|
|
736
806
|
/**
|
|
737
807
|
*
|
|
738
808
|
* @returns
|
|
739
|
-
*/
|
|
740
|
-
function getAdapter() {
|
|
809
|
+
*/ function getAdapter() {
|
|
741
810
|
// 运动感应类型(默认使用加速度,Native 环境使用陀螺仪)
|
|
742
811
|
return getAccelerAdapter();
|
|
743
812
|
}
|
|
@@ -750,61 +819,9 @@ function openDeviceMotion() {
|
|
|
750
819
|
getAdapter().connect();
|
|
751
820
|
}
|
|
752
821
|
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
757
|
-
}
|
|
758
|
-
OrientationComponent.prototype.fromData = function (data) {
|
|
759
|
-
_super.prototype.fromData.call(this, data);
|
|
760
|
-
var targets = data.content.options.targets;
|
|
761
|
-
if (targets) {
|
|
762
|
-
this.targets = targets.map(function (t) { return ({
|
|
763
|
-
name: t.name,
|
|
764
|
-
xMin: +t.xMin || 0,
|
|
765
|
-
yMin: +t.yMin || 0,
|
|
766
|
-
xMax: +t.xMax || 0,
|
|
767
|
-
yMax: +t.yMax || 0,
|
|
768
|
-
}); });
|
|
769
|
-
}
|
|
770
|
-
};
|
|
771
|
-
OrientationComponent.prototype.start = function () {
|
|
772
|
-
var _a, _b;
|
|
773
|
-
var transformer = (_a = this.item.composition) === null || _a === void 0 ? void 0 : _a.loaderData.deviceTransformer;
|
|
774
|
-
if (transformer) {
|
|
775
|
-
(_b = this.targets) === null || _b === void 0 ? void 0 : _b.forEach(function (target) { return transformer.addTarget(target); });
|
|
776
|
-
transformer.initComposition();
|
|
777
|
-
}
|
|
778
|
-
};
|
|
779
|
-
OrientationComponent.prototype.update = function (dt) {
|
|
780
|
-
var _a;
|
|
781
|
-
var transformer = (_a = this.item.composition) === null || _a === void 0 ? void 0 : _a.loaderData.deviceTransformer;
|
|
782
|
-
if (transformer) {
|
|
783
|
-
transformer.updateOrientation();
|
|
784
|
-
}
|
|
785
|
-
};
|
|
786
|
-
OrientationComponent.prototype.onDestroy = function () {
|
|
787
|
-
var _this = this;
|
|
788
|
-
var _a;
|
|
789
|
-
(_a = this.targets) === null || _a === void 0 ? void 0 : _a.forEach(function (target) { var _a, _b; return (_b = (_a = _this.item.composition) === null || _a === void 0 ? void 0 : _a.loaderData.deviceTransformer) === null || _b === void 0 ? void 0 : _b.removeTarget(target.name); });
|
|
790
|
-
};
|
|
791
|
-
return OrientationComponent;
|
|
792
|
-
}(effects.ItemBehaviour));
|
|
793
|
-
|
|
794
|
-
var TransformVFXItem = /** @class */ (function (_super) {
|
|
795
|
-
__extends(TransformVFXItem, _super);
|
|
796
|
-
function TransformVFXItem(engine, props) {
|
|
797
|
-
var _this = _super.call(this, engine, props) || this;
|
|
798
|
-
var component = _this.addComponent(OrientationComponent);
|
|
799
|
-
component.fromData(props);
|
|
800
|
-
return _this;
|
|
801
|
-
}
|
|
802
|
-
return TransformVFXItem;
|
|
803
|
-
}(effects.VFXItem));
|
|
804
|
-
|
|
805
|
-
effects.registerPlugin('orientation-transformer', OrientationPluginLoader, TransformVFXItem);
|
|
806
|
-
var version = "2.0.0-alpha.4";
|
|
807
|
-
effects.logger.info('plugin orientation transformer version: ' + version);
|
|
822
|
+
effects.registerPlugin("orientation-transformer", OrientationPluginLoader, TransformVFXItem);
|
|
823
|
+
var version = "2.0.0-alpha.6";
|
|
824
|
+
effects.logger.info("plugin orientation transformer version: " + version);
|
|
808
825
|
|
|
809
826
|
exports.OrientationAdapterAcceler = OrientationAdapterAcceler;
|
|
810
827
|
exports.closeDeviceMotion = closeDeviceMotion;
|