@anov/3d 0.0.263 → 0.0.264

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.
@@ -20,6 +20,10 @@ import { entityStrategy, eventPenetrateType } from "./strategy";
20
20
  import createDisposeFn from "./dispose";
21
21
  import { getMinimumEntity } from "./utils";
22
22
  export var hybridList = new HybridList();
23
+
24
+ /**
25
+ * todo: 统一优化
26
+ */
23
27
  var Entity = /*#__PURE__*/function () {
24
28
  function Entity(app) {
25
29
  _classCallCheck(this, Entity);
@@ -93,7 +97,7 @@ var Entity = /*#__PURE__*/function () {
93
97
  value: function () {
94
98
  var _singleCreate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(id, strategy, option, group, layerId) {
95
99
  var _this = this;
96
- var entityInfoArray, targetEntityInfo, _option$interactable, interactable, _option$interactiveEf, interactiveEffect, entity;
100
+ var entityInfoArray, targetEntityInfo, _option$interactable, interactable, _option$interactiveEf, interactiveEffect, _option$collision, collision, entity;
97
101
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
98
102
  while (1) switch (_context2.prev = _context2.next) {
99
103
  case 0:
@@ -102,13 +106,14 @@ var Entity = /*#__PURE__*/function () {
102
106
  case 2:
103
107
  entityInfoArray = _context2.sent;
104
108
  targetEntityInfo = entityInfoArray[0];
105
- _option$interactable = option.interactable, interactable = _option$interactable === void 0 ? true : _option$interactable, _option$interactiveEf = option.interactiveEffect, interactiveEffect = _option$interactiveEf === void 0 ? false : _option$interactiveEf;
109
+ _option$interactable = option.interactable, interactable = _option$interactable === void 0 ? true : _option$interactable, _option$interactiveEf = option.interactiveEffect, interactiveEffect = _option$interactiveEf === void 0 ? false : _option$interactiveEf, _option$collision = option.collision, collision = _option$collision === void 0 ? true : _option$collision;
110
+ interactable = interactable && collision;
106
111
  if (!(targetEntityInfo.status === 'rejected')) {
107
- _context2.next = 7;
112
+ _context2.next = 8;
108
113
  break;
109
114
  }
110
115
  throw new Error(targetEntityInfo.reason);
111
- case 7:
116
+ case 8:
112
117
  entity = targetEntityInfo.value;
113
118
  entity.tag = 'entity'; // used for event penetration identification
114
119
  entity.entityId = id;
@@ -137,7 +142,7 @@ var Entity = /*#__PURE__*/function () {
137
142
  scale: entity.scale.toArray(),
138
143
  visible: entity.visible
139
144
  }));
140
- case 16:
145
+ case 17:
141
146
  case "end":
142
147
  return _context2.stop();
143
148
  }
@@ -159,11 +164,15 @@ var Entity = /*#__PURE__*/function () {
159
164
  legends = _json$legends === void 0 ? [] : _json$legends,
160
165
  _json$interactable = json.interactable,
161
166
  interactable = _json$interactable === void 0 ? true : _json$interactable,
167
+ _json$collision = json.collision,
168
+ collision = _json$collision === void 0 ? true : _json$collision,
162
169
  name = json.name;
170
+ interactable = interactable && collision;
163
171
  var group = new Group();
164
172
 
165
173
  // TODO 优化,定制化非实体逻辑
166
- items.forEach( /*#__PURE__*/function () {
174
+
175
+ var promises = items.map( /*#__PURE__*/function () {
167
176
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(item) {
168
177
  var currentData;
169
178
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
@@ -179,6 +188,8 @@ var Entity = /*#__PURE__*/function () {
179
188
  _context3.next = 5;
180
189
  return _this2.singleCreate(item.id, strategy, currentData, group, id);
181
190
  case 5:
191
+ return _context3.abrupt("return", _context3.sent);
192
+ case 6:
182
193
  case "end":
183
194
  return _context3.stop();
184
195
  }
@@ -188,21 +199,23 @@ var Entity = /*#__PURE__*/function () {
188
199
  return _ref2.apply(this, arguments);
189
200
  };
190
201
  }());
191
- group.userData.entityParams = {
192
- id: id,
193
- type: 'layer',
194
- itemType: itemType,
195
- interactable: interactable,
196
- name: name
197
- };
198
- hybridList.add(id, group);
199
- use.useScene().scene.add(group);
200
- return _objectSpread(_objectSpread({}, json), {}, {
201
- id: id,
202
- position: group.position.toArray(),
203
- rotation: group.rotation.toArray(),
204
- scale: group.scale.toArray(),
205
- visible: group.visible
202
+ return Promise.all(promises).then(function () {
203
+ group.userData.entityParams = {
204
+ id: id,
205
+ type: 'layer',
206
+ itemType: itemType,
207
+ interactable: interactable,
208
+ name: name
209
+ };
210
+ hybridList.add(id, group);
211
+ use.useScene().scene.add(group);
212
+ return _objectSpread(_objectSpread({}, json), {}, {
213
+ id: id,
214
+ position: group.position.toArray(),
215
+ rotation: group.rotation.toArray(),
216
+ scale: group.scale.toArray(),
217
+ visible: group.visible
218
+ });
206
219
  });
207
220
  }
208
221
 
@@ -216,11 +229,11 @@ var Entity = /*#__PURE__*/function () {
216
229
  value: (function () {
217
230
  var _create = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(json) {
218
231
  var _this3 = this;
219
- var id, type, itemType, _json$interactable2, interactable, asyncTask;
232
+ var id, type, itemType, asyncTask;
220
233
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
221
234
  while (1) switch (_context5.prev = _context5.next) {
222
235
  case 0:
223
- id = json.id, type = json.type, itemType = json.itemType, _json$interactable2 = json.interactable, interactable = _json$interactable2 === void 0 ? true : _json$interactable2;
236
+ id = json.id, type = json.type, itemType = json.itemType;
224
237
  asyncTask = Promise.resolve().then( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
225
238
  var strategy, res;
226
239
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
@@ -231,7 +244,7 @@ var Entity = /*#__PURE__*/function () {
231
244
  case 2:
232
245
  strategy = _context4.sent;
233
246
  if (itemType && type === 'layer') res = _this3.multiCreate(id, strategy, json);else res = _this3.singleCreate(id, strategy, json);
234
- return _context4.abrupt("return", _this3.handleResult(id, res, interactable));
247
+ return _context4.abrupt("return", _this3.handleResult(id, res));
235
248
  case 5:
236
249
  case "end":
237
250
  return _context4.stop();
@@ -257,7 +270,7 @@ var Entity = /*#__PURE__*/function () {
257
270
  value: function () {
258
271
  var _singleUpdate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(id, strategy, option, group) {
259
272
  var _this4 = this;
260
- var target, _target$userData$enti, entityParams, entityInfoArray, targetEntityInfo, _option$interactiveEf2, interactiveEffect, entity;
273
+ var target, _target$userData$enti, entityParams, entityInfoArray, targetEntityInfo, _option$interactiveEf2, interactiveEffect, entity, interactable;
261
274
  return _regeneratorRuntime().wrap(function _callee6$(_context6) {
262
275
  while (1) switch (_context6.prev = _context6.next) {
263
276
  case 0:
@@ -279,7 +292,11 @@ var Entity = /*#__PURE__*/function () {
279
292
  entity = targetEntityInfo.value;
280
293
  entity.tag = 'entity'; // use used for event penetration identification
281
294
  entity.entityId = id;
282
- entity.userData.entityParams = entityParams;
295
+ interactable = entityParams.interactable;
296
+ if (option.collision !== undefined) interactable = option.collision;
297
+ entity.userData.entityParams = _objectSpread(_objectSpread({}, entityParams), {}, {
298
+ interactable: interactable
299
+ }, option);
283
300
 
284
301
  // 兼容修改图层下的单个实体
285
302
  if (!group && entityParams.layerId) group = hybridList.get(entityParams.layerId);
@@ -304,7 +321,7 @@ var Entity = /*#__PURE__*/function () {
304
321
  scale: entity.scale.toArray(),
305
322
  visible: entity.visible
306
323
  }));
307
- case 20:
324
+ case 22:
308
325
  case "end":
309
326
  return _context6.stop();
310
327
  }
@@ -317,54 +334,75 @@ var Entity = /*#__PURE__*/function () {
317
334
  }()
318
335
  }, {
319
336
  key: "multiUpdate",
320
- value: function multiUpdate(id, strategy, option) {
321
- var _this5 = this;
322
- var group = hybridList.get(id);
323
- var items = option.items,
324
- legends = option.legends,
325
- itemType = option.itemType;
326
- items.forEach( /*#__PURE__*/function () {
327
- var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(item) {
328
- var legendItem, currentItem;
329
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
330
- while (1) switch (_context7.prev = _context7.next) {
331
- case 0:
332
- legendItem = legends === null || legends === void 0 ? void 0 : legends.find(function (legend) {
333
- return legend.name === item.legend;
334
- });
335
- currentItem = legendItem ? _objectSpread(_objectSpread({}, legendItem), item) : item;
336
- if (!hybridList.get(item.id)) {
337
- _context7.next = 7;
338
- break;
339
- }
340
- _context7.next = 5;
341
- return _this5.singleUpdate(item.id, strategy, currentItem, group);
342
- case 5:
343
- _context7.next = 10;
344
- break;
345
- case 7:
346
- currentItem.type = itemType;
347
- _context7.next = 10;
348
- return _this5.singleCreate(item.id, strategy, currentItem, group);
349
- case 10:
350
- case "end":
351
- return _context7.stop();
352
- }
353
- }, _callee7);
354
- }));
355
- return function (_x13) {
356
- return _ref4.apply(this, arguments);
357
- };
358
- }());
359
- return _objectSpread(_objectSpread({}, option), {}, {
360
- id: id,
361
- position: group.position.toArray(),
362
- rotation: group.rotation.toArray(),
363
- scale: group.scale.toArray(),
364
- visible: group.visible
365
- });
366
- }
367
-
337
+ value: function () {
338
+ var _multiUpdate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(id, strategy, option) {
339
+ var _this5 = this;
340
+ var group, items, legends, itemType, promises, interactable;
341
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
342
+ while (1) switch (_context8.prev = _context8.next) {
343
+ case 0:
344
+ group = hybridList.get(id);
345
+ items = option.items, legends = option.legends, itemType = option.itemType;
346
+ promises = items.map( /*#__PURE__*/function () {
347
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(item) {
348
+ var legendItem, currentItem;
349
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
350
+ while (1) switch (_context7.prev = _context7.next) {
351
+ case 0:
352
+ legendItem = legends === null || legends === void 0 ? void 0 : legends.find(function (legend) {
353
+ return legend.name === item.legend;
354
+ });
355
+ currentItem = legendItem ? _objectSpread(_objectSpread({}, legendItem), item) : item;
356
+ if (!hybridList.get(item.id)) {
357
+ _context7.next = 8;
358
+ break;
359
+ }
360
+ _context7.next = 5;
361
+ return _this5.singleUpdate(item.id, strategy, currentItem, group);
362
+ case 5:
363
+ return _context7.abrupt("return", _context7.sent);
364
+ case 8:
365
+ currentItem.type = itemType;
366
+ _context7.next = 11;
367
+ return _this5.singleCreate(item.id, strategy, currentItem, group);
368
+ case 11:
369
+ return _context7.abrupt("return", _context7.sent);
370
+ case 12:
371
+ case "end":
372
+ return _context7.stop();
373
+ }
374
+ }, _callee7);
375
+ }));
376
+ return function (_x16) {
377
+ return _ref4.apply(this, arguments);
378
+ };
379
+ }());
380
+ _context8.next = 5;
381
+ return Promise.all(promises);
382
+ case 5:
383
+ interactable = group.userData.entityParams.interactable;
384
+ if (option.collision !== undefined) interactable = option.collision;
385
+ group.userData.entityParams = _objectSpread(_objectSpread({}, group.userData.entityParams), {}, {
386
+ interactable: interactable
387
+ }, option);
388
+ return _context8.abrupt("return", _objectSpread(_objectSpread({}, option), {}, {
389
+ id: id,
390
+ position: group.position.toArray(),
391
+ rotation: group.rotation.toArray(),
392
+ scale: group.scale.toArray(),
393
+ visible: group.visible
394
+ }));
395
+ case 9:
396
+ case "end":
397
+ return _context8.stop();
398
+ }
399
+ }, _callee8);
400
+ }));
401
+ function multiUpdate(_x13, _x14, _x15) {
402
+ return _multiUpdate.apply(this, arguments);
403
+ }
404
+ return multiUpdate;
405
+ }()
368
406
  /**
369
407
  * update entity
370
408
  * @param json
@@ -373,42 +411,42 @@ var Entity = /*#__PURE__*/function () {
373
411
  }, {
374
412
  key: "update",
375
413
  value: (function () {
376
- var _update = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(json) {
414
+ var _update = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(json) {
377
415
  var _this6 = this;
378
- var id, _json$interactable3, interactable;
379
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
380
- while (1) switch (_context9.prev = _context9.next) {
416
+ var id;
417
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
418
+ while (1) switch (_context10.prev = _context10.next) {
381
419
  case 0:
382
- id = json.id, _json$interactable3 = json.interactable, interactable = _json$interactable3 === void 0 ? true : _json$interactable3;
383
- Promise.resolve().then( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
420
+ id = json.id;
421
+ Promise.resolve().then( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
384
422
  var target, _target$userData$enti2, type, itemType, strategy, res;
385
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
386
- while (1) switch (_context8.prev = _context8.next) {
423
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
424
+ while (1) switch (_context9.prev = _context9.next) {
387
425
  case 0:
388
426
  target = hybridList.get(id);
389
427
  _target$userData$enti2 = target.userData.entityParams, type = _target$userData$enti2.type, itemType = _target$userData$enti2.itemType;
390
- _context8.next = 4;
428
+ _context9.next = 4;
391
429
  return _this6.registerStrategy(itemType || type);
392
430
  case 4:
393
- strategy = _context8.sent;
394
- if (itemType && type === 'layer') res = Promise.all(_this6.multiUpdate(id, strategy, _objectSpread({
431
+ strategy = _context9.sent;
432
+ if (itemType && type === 'layer') res = _this6.multiUpdate(id, strategy, _objectSpread({
395
433
  itemType: itemType
396
- }, json)));else res = _this6.singleUpdate(id, strategy, json);
397
- _this6.handleResult(id, res, interactable);
434
+ }, json));else res = _this6.singleUpdate(id, strategy, json);
435
+ _this6.handleResult(id, res);
398
436
  case 7:
399
437
  case "end":
400
- return _context8.stop();
438
+ return _context9.stop();
401
439
  }
402
- }, _callee8);
440
+ }, _callee9);
403
441
  })));
404
- return _context9.abrupt("return", json);
442
+ return _context10.abrupt("return", json);
405
443
  case 3:
406
444
  case "end":
407
- return _context9.stop();
445
+ return _context10.stop();
408
446
  }
409
- }, _callee9);
447
+ }, _callee10);
410
448
  }));
411
- function update(_x14) {
449
+ function update(_x17) {
412
450
  return _update.apply(this, arguments);
413
451
  }
414
452
  return update;
@@ -416,32 +454,32 @@ var Entity = /*#__PURE__*/function () {
416
454
  }, {
417
455
  key: "execute",
418
456
  value: function () {
419
- var _execute = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(json) {
457
+ var _execute = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(json) {
420
458
  var _this7 = this;
421
- var id, method, args, _json$interactable4, interactable;
422
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
423
- while (1) switch (_context11.prev = _context11.next) {
459
+ var id, method, args;
460
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
461
+ while (1) switch (_context12.prev = _context12.next) {
424
462
  case 0:
425
- id = json.id, method = json.method, args = json.args, _json$interactable4 = json.interactable, interactable = _json$interactable4 === void 0 ? true : _json$interactable4;
463
+ id = json.id, method = json.method, args = json.args;
426
464
  if (id && method) {
427
- Promise.resolve().then( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
465
+ Promise.resolve().then( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
428
466
  var target, type, strategy, entityInfoArray, targetEntityInfo, entity;
429
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
430
- while (1) switch (_context10.prev = _context10.next) {
467
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
468
+ while (1) switch (_context11.prev = _context11.next) {
431
469
  case 0:
432
470
  target = hybridList.get(id);
433
471
  type = target.userData.entityParams.type;
434
- _context10.next = 4;
472
+ _context11.next = 4;
435
473
  return _this7.registerStrategy(type);
436
474
  case 4:
437
- strategy = _context10.sent;
438
- _context10.next = 7;
475
+ strategy = _context11.sent;
476
+ _context11.next = 7;
439
477
  return Promise.allSettled([strategy[method](args, target)]);
440
478
  case 7:
441
- entityInfoArray = _context10.sent;
479
+ entityInfoArray = _context11.sent;
442
480
  targetEntityInfo = entityInfoArray[0];
443
481
  if (!(targetEntityInfo.status === 'rejected')) {
444
- _context10.next = 11;
482
+ _context11.next = 11;
445
483
  break;
446
484
  }
447
485
  throw new Error(targetEntityInfo.reason);
@@ -454,22 +492,22 @@ var Entity = /*#__PURE__*/function () {
454
492
  rotation: entity.rotation.toArray(),
455
493
  scale: entity.scale.toArray(),
456
494
  visible: entity.visible
457
- }), interactable);
495
+ }));
458
496
  case 14:
459
497
  case "end":
460
- return _context10.stop();
498
+ return _context11.stop();
461
499
  }
462
- }, _callee10);
500
+ }, _callee11);
463
501
  })));
464
502
  }
465
- return _context11.abrupt("return", json);
503
+ return _context12.abrupt("return", json);
466
504
  case 3:
467
505
  case "end":
468
- return _context11.stop();
506
+ return _context12.stop();
469
507
  }
470
- }, _callee11);
508
+ }, _callee12);
471
509
  }));
472
- function execute(_x15) {
510
+ function execute(_x18) {
473
511
  return _execute.apply(this, arguments);
474
512
  }
475
513
  return execute;
@@ -482,11 +520,11 @@ var Entity = /*#__PURE__*/function () {
482
520
  }, {
483
521
  key: "handleResult",
484
522
  value: (function () {
485
- var _handleResult = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(id, res, interactable) {
486
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
487
- while (1) switch (_context12.prev = _context12.next) {
523
+ var _handleResult = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(id, res) {
524
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
525
+ while (1) switch (_context13.prev = _context13.next) {
488
526
  case 0:
489
- return _context12.abrupt("return", Promise.resolve(res).then(function () {
527
+ return _context13.abrupt("return", Promise.resolve(res).then(function () {
490
528
  sendToMessage({
491
529
  messageType: MessageType.Event,
492
530
  messageName: 'onLoaded',
@@ -507,17 +545,17 @@ var Entity = /*#__PURE__*/function () {
507
545
  success: false
508
546
  });
509
547
  }).finally(function () {
510
- interactable && utils.emitter.emit('onEntityLoaded', {
548
+ utils.emitter.emit('onEntityLoaded', {
511
549
  id: id
512
550
  });
513
551
  }));
514
552
  case 1:
515
553
  case "end":
516
- return _context12.stop();
554
+ return _context13.stop();
517
555
  }
518
- }, _callee12);
556
+ }, _callee13);
519
557
  }));
520
- function handleResult(_x16, _x17, _x18) {
558
+ function handleResult(_x19, _x20) {
521
559
  return _handleResult.apply(this, arguments);
522
560
  }
523
561
  return handleResult;
@@ -609,6 +647,10 @@ var Entity = /*#__PURE__*/function () {
609
647
  var target = hybridList.get(id);
610
648
  if (!target) throw new Error("entity ".concat(id, " is not exist"));
611
649
  if (!(target.userData.entityParams.type === 'model' || target.userData.entityParams.type === 'poi')) return;
650
+ if (!target.userData.entityParams.interactable) {
651
+ this.unregisterEvents(opts);
652
+ return;
653
+ }
612
654
 
613
655
  // @ts-ignore
614
656
  if (eventPenetrateType.includes(target.entityType)) {