@anov/3d 0.0.286 → 0.0.288

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.
Files changed (99) hide show
  1. package/dist/anov3d.js +40 -43
  2. package/dist/anov3d.js.map +1 -1
  3. package/dist/applicationApi.js +94 -118
  4. package/dist/applicationApi.js.map +1 -1
  5. package/dist/hooksManager.js +10 -10
  6. package/dist/hooksManager.js.map +1 -1
  7. package/dist/index.js +1 -1
  8. package/dist/index.js.map +1 -1
  9. package/dist/messageStatus.js +3 -3
  10. package/dist/messageStatus.js.map +1 -1
  11. package/dist/module/animation/index.js +61 -113
  12. package/dist/module/animation/index.js.map +1 -1
  13. package/dist/module/animation/motion/index.js +58 -91
  14. package/dist/module/animation/motion/index.js.map +1 -1
  15. package/dist/module/animation/strategy.js +7 -21
  16. package/dist/module/animation/strategy.js.map +1 -1
  17. package/dist/module/camera/index.js +216 -278
  18. package/dist/module/camera/index.js.map +1 -1
  19. package/dist/module/develop/index.js +27 -35
  20. package/dist/module/develop/index.js.map +1 -1
  21. package/dist/module/entity/area/index.js +29 -87
  22. package/dist/module/entity/area/index.js.map +1 -1
  23. package/dist/module/entity/bar/index.js +5 -24
  24. package/dist/module/entity/bar/index.js.map +1 -1
  25. package/dist/module/entity/bar/style/bar_01.js +13 -52
  26. package/dist/module/entity/bar/style/bar_01.js.map +1 -1
  27. package/dist/module/entity/bar/style/index.js +7 -21
  28. package/dist/module/entity/bar/style/index.js.map +1 -1
  29. package/dist/module/entity/baseEntity.js +43 -66
  30. package/dist/module/entity/baseEntity.js.map +1 -1
  31. package/dist/module/entity/batch/index.js +77 -168
  32. package/dist/module/entity/batch/index.js.map +1 -1
  33. package/dist/module/entity/dispose.js +14 -16
  34. package/dist/module/entity/dispose.js.map +1 -1
  35. package/dist/module/entity/flyline/index.js +34 -90
  36. package/dist/module/entity/flyline/index.js.map +1 -1
  37. package/dist/module/entity/group/index.js +59 -75
  38. package/dist/module/entity/group/index.js.map +1 -1
  39. package/dist/module/entity/heatmap/index.js +62 -79
  40. package/dist/module/entity/heatmap/index.js.map +1 -1
  41. package/dist/module/entity/hybridList.js +49 -67
  42. package/dist/module/entity/hybridList.js.map +1 -1
  43. package/dist/module/entity/index.js +442 -644
  44. package/dist/module/entity/index.js.map +1 -1
  45. package/dist/module/entity/infoPanel/index.js +23 -76
  46. package/dist/module/entity/infoPanel/index.js.map +1 -1
  47. package/dist/module/entity/light/pointLight/index.js +48 -84
  48. package/dist/module/entity/light/pointLight/index.js.map +1 -1
  49. package/dist/module/entity/mark/index.js +51 -101
  50. package/dist/module/entity/mark/index.js.map +1 -1
  51. package/dist/module/entity/model/index.js +108 -151
  52. package/dist/module/entity/model/index.js.map +1 -1
  53. package/dist/module/entity/model/load/loadFbx.js +8 -8
  54. package/dist/module/entity/model/load/loadFbx.js.map +1 -1
  55. package/dist/module/entity/model/load/loadGlb.js +13 -11
  56. package/dist/module/entity/model/load/loadGlb.js.map +1 -1
  57. package/dist/module/entity/model/load.js +19 -57
  58. package/dist/module/entity/model/load.js.map +1 -1
  59. package/dist/module/entity/poi/index.js +34 -90
  60. package/dist/module/entity/poi/index.js.map +1 -1
  61. package/dist/module/entity/shape/index.js +67 -136
  62. package/dist/module/entity/shape/index.js.map +1 -1
  63. package/dist/module/entity/spline/index.js +22 -75
  64. package/dist/module/entity/spline/index.js.map +1 -1
  65. package/dist/module/entity/strategy.js +92 -274
  66. package/dist/module/entity/strategy.js.map +1 -1
  67. package/dist/module/entity/traffic/realismTraffic/index.js +59 -88
  68. package/dist/module/entity/traffic/realismTraffic/index.js.map +1 -1
  69. package/dist/module/entity/traffic/streamerTraffic/index.js +50 -81
  70. package/dist/module/entity/traffic/streamerTraffic/index.js.map +1 -1
  71. package/dist/module/entity/utils.js +11 -13
  72. package/dist/module/entity/utils.js.map +1 -1
  73. package/dist/module/entity/videoPanel/index.js +23 -76
  74. package/dist/module/entity/videoPanel/index.js.map +1 -1
  75. package/dist/module/environment/index.js +54 -73
  76. package/dist/module/environment/index.js.map +1 -1
  77. package/dist/module/environment/season/index.js +342 -184
  78. package/dist/module/environment/season/index.js.map +1 -1
  79. package/dist/module/eventBus/entityEvents.js +1 -1
  80. package/dist/module/eventBus/entityEvents.js.map +1 -1
  81. package/dist/module/eventBus/index.js +79 -93
  82. package/dist/module/eventBus/index.js.map +1 -1
  83. package/dist/module/material/index.js +279 -334
  84. package/dist/module/material/index.js.map +1 -1
  85. package/dist/module/scene/fileParse.js +277 -369
  86. package/dist/module/scene/fileParse.js.map +1 -1
  87. package/dist/module/scene/index.js +106 -161
  88. package/dist/module/scene/index.js.map +1 -1
  89. package/dist/module/tool/index.js +26 -33
  90. package/dist/module/tool/index.js.map +1 -1
  91. package/dist/sdkEntry.js +2 -23
  92. package/dist/sdkEntry.js.map +1 -1
  93. package/dist/utils/abstract.js +12 -15
  94. package/dist/utils/abstract.js.map +1 -1
  95. package/dist/utils/index.js +23 -24
  96. package/dist/utils/index.js.map +1 -1
  97. package/dist/utils/messageFn.js +17 -18
  98. package/dist/utils/messageFn.js.map +1 -1
  99. package/package.json +6 -3
@@ -1,15 +1,10 @@
1
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
3
1
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4
2
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
5
3
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
6
4
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
7
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
8
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
9
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
10
5
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
11
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
12
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
6
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
7
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
13
8
  import { Group, use, utils } from '@anov/3d-core';
14
9
  import { MaterialSwitchSystem, createHighSelectedTool } from '@anov/3d-ability';
15
10
  import debounce from 'lodash/debounce';
@@ -19,14 +14,13 @@ import HybridList from "./hybridList";
19
14
  import { entityStrategy, eventPenetrateType } from "./strategy";
20
15
  import createDisposeFn from "./dispose";
21
16
  import { getMinimumEntity } from "./utils";
22
- export var hybridList = new HybridList();
17
+ export const hybridList = new HybridList();
23
18
 
24
19
  /**
25
20
  * todo: 统一优化
26
21
  */
27
- var Entity = /*#__PURE__*/function () {
28
- function Entity(app) {
29
- _classCallCheck(this, Entity);
22
+ class Entity {
23
+ constructor(app) {
30
24
  _defineProperty(this, "app", void 0);
31
25
  _defineProperty(this, "catchStrategy", new Map());
32
26
  _defineProperty(this, "select", void 0);
@@ -37,14 +31,15 @@ var Entity = /*#__PURE__*/function () {
37
31
  isApi: true
38
32
  });
39
33
  use.useScene().scene.add(this.materialSwitchSystem);
40
- this.materialSwitchSystem.addEventListener('onStyleChanged', function (_ref) {
41
- var style = _ref.style;
34
+ this.materialSwitchSystem.addEventListener('onStyleChanged', ({
35
+ style
36
+ }) => {
42
37
  sendToMessage({
43
38
  messageType: MessageType.Event,
44
39
  messageName: 'onStyleChanged',
45
40
  status: EMessageStatus.Success
46
41
  }, {
47
- style: style
42
+ style
48
43
  });
49
44
  });
50
45
  }
@@ -54,660 +49,463 @@ var Entity = /*#__PURE__*/function () {
54
49
  * @param entityType
55
50
  * @returns
56
51
  */
57
- _createClass(Entity, [{
58
- key: "registerStrategy",
59
- value: (function () {
60
- var _registerStrategy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(entityType) {
61
- var strategyMap, strategyClass;
62
- return _regeneratorRuntime().wrap(function _callee$(_context) {
63
- while (1) switch (_context.prev = _context.next) {
64
- case 0:
65
- strategyMap = _objectSpread({}, entityStrategy);
66
- if (entityType in strategyMap) {
67
- _context.next = 3;
68
- break;
69
- }
70
- throw new Error("entityType ".concat(entityType, " is not supported"));
71
- case 3:
72
- if (!(entityType in strategyMap && !this.catchStrategy.has(entityType))) {
73
- _context.next = 8;
74
- break;
75
- }
76
- _context.next = 6;
77
- return strategyMap[entityType]();
78
- case 6:
79
- strategyClass = _context.sent;
80
- // eslint-disable-next-line new-cap
81
- this.catchStrategy.set(entityType, new strategyClass());
82
- case 8:
83
- return _context.abrupt("return", this.catchStrategy.get(entityType));
84
- case 9:
85
- case "end":
86
- return _context.stop();
87
- }
88
- }, _callee, this);
89
- }));
90
- function registerStrategy(_x) {
91
- return _registerStrategy.apply(this, arguments);
92
- }
93
- return registerStrategy;
94
- }())
95
- }, {
96
- key: "singleCreate",
97
- value: function () {
98
- var _singleCreate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(id, strategy, option, group, layerId) {
99
- var _this = this;
100
- var entityInfoArray, targetEntityInfo, _option$interactable, interactable, _option$interactiveEf, interactiveEffect, _option$collision, collision, entity;
101
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
102
- while (1) switch (_context2.prev = _context2.next) {
103
- case 0:
104
- _context2.next = 2;
105
- return Promise.allSettled([strategy.create(option)]);
106
- case 2:
107
- entityInfoArray = _context2.sent;
108
- targetEntityInfo = entityInfoArray[0];
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;
111
- if (!(targetEntityInfo.status === 'rejected')) {
112
- _context2.next = 8;
113
- break;
114
- }
115
- throw new Error(targetEntityInfo.reason);
116
- case 8:
117
- entity = targetEntityInfo.value;
118
- entity.tag = 'entity'; // used for event penetration identification
119
- entity.entityId = id;
120
- entity.userData.entityParams = {
121
- id: id,
122
- type: option.type,
123
- layerId: layerId,
124
- interactable: interactable,
125
- name: option.name,
126
- interactiveEffect: interactiveEffect
127
- };
128
- if (entity.userData.entityParams.type === 'model' && entity.visible) this.materialSwitchSystem.addObject(entity);
129
- hybridList.add(id, entity);
130
- group === null || group === void 0 || group.add(entity);
131
- if (interactiveEffect && entity.userData.entityParams.type === 'model') {
132
- entity.addEventListener('mouseover', function () {
133
- var _this$select;
134
- if (entity.userData.entityParams.interactiveEffect) (_this$select = _this.select) === null || _this$select === void 0 || _this$select.call(_this, [entity]);
135
- });
136
- entity.addEventListener('mouseout', function () {
137
- var _this$select2;
138
- (_this$select2 = _this.select) === null || _this$select2 === void 0 || _this$select2.call(_this, []);
139
- });
140
- }
141
- return _context2.abrupt("return", _objectSpread(_objectSpread({}, option), {}, {
142
- id: id,
143
- position: entity.position.toArray(),
144
- rotation: entity.rotation.toArray(),
145
- scale: entity.scale.toArray(),
146
- visible: entity.visible
147
- }));
148
- case 17:
149
- case "end":
150
- return _context2.stop();
151
- }
152
- }, _callee2, this);
153
- }));
154
- function singleCreate(_x2, _x3, _x4, _x5, _x6) {
155
- return _singleCreate.apply(this, arguments);
52
+ registerStrategy(entityType) {
53
+ var _this = this;
54
+ return _asyncToGenerator(function* () {
55
+ const strategyMap = _objectSpread({}, entityStrategy);
56
+ if (!(entityType in strategyMap)) throw new Error(`entityType ${entityType} is not supported`);
57
+ if (entityType in strategyMap && !_this.catchStrategy.has(entityType)) {
58
+ const strategyClass = yield strategyMap[entityType]();
59
+
60
+ // eslint-disable-next-line new-cap
61
+ _this.catchStrategy.set(entityType, new strategyClass());
156
62
  }
157
- return singleCreate;
158
- }()
159
- }, {
160
- key: "multiCreate",
161
- value: function multiCreate(id, strategy, json) {
162
- var _this2 = this;
163
- var itemType = json.itemType,
164
- _json$items = json.items,
165
- items = _json$items === void 0 ? [] : _json$items,
166
- _json$legends = json.legends,
167
- legends = _json$legends === void 0 ? [] : _json$legends,
168
- _json$interactable = json.interactable,
169
- interactable = _json$interactable === void 0 ? true : _json$interactable,
170
- _json$collision = json.collision,
171
- collision = _json$collision === void 0 ? true : _json$collision,
172
- name = json.name;
63
+ return _this.catchStrategy.get(entityType);
64
+ })();
65
+ }
66
+ singleCreate(id, strategy, option, group, layerId) {
67
+ var _this2 = this;
68
+ return _asyncToGenerator(function* () {
69
+ const entityInfoArray = yield Promise.allSettled([strategy.create(option)]);
70
+ const targetEntityInfo = entityInfoArray[0];
71
+ let {
72
+ interactable = true,
73
+ interactiveEffect = false,
74
+ collision = true
75
+ } = option;
173
76
  interactable = interactable && collision;
174
- var group = new Group();
77
+ if (targetEntityInfo.status === 'rejected') throw new Error(targetEntityInfo.reason);
78
+ const entity = targetEntityInfo.value;
79
+ entity.tag = 'entity'; // used for event penetration identification
80
+ entity.entityId = id;
81
+ entity.userData.entityParams = {
82
+ id,
83
+ type: option.type,
84
+ layerId,
85
+ interactable,
86
+ name: option.name,
87
+ interactiveEffect
88
+ };
89
+ if (entity.userData.entityParams.type === 'model' && entity.visible) _this2.materialSwitchSystem.addObject(entity);
90
+ hybridList.add(id, entity);
91
+ group === null || group === void 0 || group.add(entity);
92
+ if (interactiveEffect && entity.userData.entityParams.type === 'model') {
93
+ entity.addEventListener('mouseover', () => {
94
+ var _this2$select;
95
+ if (entity.userData.entityParams.interactiveEffect) (_this2$select = _this2.select) === null || _this2$select === void 0 || _this2$select.call(_this2, [entity]);
96
+ });
97
+ entity.addEventListener('mouseout', () => {
98
+ var _this2$select2;
99
+ (_this2$select2 = _this2.select) === null || _this2$select2 === void 0 || _this2$select2.call(_this2, []);
100
+ });
101
+ }
102
+ return _objectSpread(_objectSpread({}, option), {}, {
103
+ id,
104
+ position: entity.position.toArray(),
105
+ rotation: entity.rotation.toArray(),
106
+ scale: entity.scale.toArray(),
107
+ visible: entity.visible
108
+ });
109
+ })();
110
+ }
111
+ multiCreate(id, strategy, json) {
112
+ var _this3 = this;
113
+ let {
114
+ itemType,
115
+ items = [],
116
+ legends = [],
117
+ interactable = true,
118
+ collision = true,
119
+ name
120
+ } = json;
121
+ interactable = interactable && collision;
122
+ const group = new Group();
175
123
 
176
- // TODO 优化,定制化非实体逻辑
124
+ // TODO 优化,定制化非实体逻辑
177
125
 
178
- var promises = items.map( /*#__PURE__*/function () {
179
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(item) {
180
- var currentData;
181
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
182
- while (1) switch (_context3.prev = _context3.next) {
183
- case 0:
184
- currentData = item;
185
- if (currentData.legend) {
186
- currentData = _objectSpread(_objectSpread({}, legends.find(function (legend) {
187
- return legend.name === item.legend;
188
- })), item);
189
- }
190
- currentData.type = itemType;
191
- _context3.next = 5;
192
- return _this2.singleCreate(item.id, strategy, currentData, group, id);
193
- case 5:
194
- return _context3.abrupt("return", _context3.sent);
195
- case 6:
196
- case "end":
197
- return _context3.stop();
198
- }
199
- }, _callee3);
200
- }));
201
- return function (_x7) {
202
- return _ref2.apply(this, arguments);
203
- };
204
- }());
205
- return Promise.all(promises).then(function () {
206
- group.userData.entityParams = {
207
- id: id,
208
- type: 'layer',
209
- itemType: itemType,
210
- interactable: interactable,
211
- name: name
212
- };
213
- hybridList.add(id, group);
214
- use.useScene().scene.add(group);
215
- return _objectSpread(_objectSpread({}, json), {}, {
216
- id: id,
217
- position: group.position.toArray(),
218
- rotation: group.rotation.toArray(),
219
- scale: group.scale.toArray(),
220
- visible: group.visible
221
- });
126
+ const promises = items.map( /*#__PURE__*/function () {
127
+ var _ref = _asyncToGenerator(function* (item) {
128
+ let currentData = item;
129
+ if (currentData.legend) {
130
+ currentData = _objectSpread(_objectSpread({}, legends.find(legend => legend.name === item.legend)), item);
131
+ }
132
+ currentData.type = itemType;
133
+ return yield _this3.singleCreate(item.id, strategy, currentData, group, id);
222
134
  });
223
- }
135
+ return function (_x) {
136
+ return _ref.apply(this, arguments);
137
+ };
138
+ }());
139
+ return Promise.all(promises).then(() => {
140
+ group.userData.entityParams = {
141
+ id,
142
+ type: 'layer',
143
+ itemType,
144
+ interactable,
145
+ name
146
+ };
147
+ hybridList.add(id, group);
148
+ use.useScene().scene.add(group);
149
+ return _objectSpread(_objectSpread({}, json), {}, {
150
+ id,
151
+ position: group.position.toArray(),
152
+ rotation: group.rotation.toArray(),
153
+ scale: group.scale.toArray(),
154
+ visible: group.visible
155
+ });
156
+ });
157
+ }
224
158
 
225
- /**
226
- * create entity
227
- * @param json
228
- * @returns
229
- */
230
- }, {
231
- key: "create",
232
- value: (function () {
233
- var _create = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(json) {
234
- var _this3 = this;
235
- var id, type, itemType, asyncTask;
236
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
237
- while (1) switch (_context5.prev = _context5.next) {
238
- case 0:
239
- id = json.id, type = json.type, itemType = json.itemType;
240
- asyncTask = Promise.resolve().then( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
241
- var strategy, res;
242
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
243
- while (1) switch (_context4.prev = _context4.next) {
244
- case 0:
245
- _context4.next = 2;
246
- return _this3.registerStrategy(itemType || type);
247
- case 2:
248
- strategy = _context4.sent;
249
- if (itemType && type === 'layer') res = _this3.multiCreate(id, strategy, json);else res = _this3.singleCreate(id, strategy, json);
250
- return _context4.abrupt("return", _this3.handleResult(id, res));
251
- case 5:
252
- case "end":
253
- return _context4.stop();
254
- }
255
- }, _callee4);
256
- })));
257
- return _context5.abrupt("return", _objectSpread(_objectSpread({}, json), {}, {
258
- asyncTask: asyncTask
259
- }));
260
- case 3:
261
- case "end":
262
- return _context5.stop();
263
- }
264
- }, _callee5);
159
+ /**
160
+ * create entity
161
+ * @param json
162
+ * @returns
163
+ */
164
+ create(json) {
165
+ var _this4 = this;
166
+ return _asyncToGenerator(function* () {
167
+ const {
168
+ id,
169
+ type,
170
+ itemType
171
+ } = json;
172
+ const asyncTask = Promise.resolve().then( /*#__PURE__*/_asyncToGenerator(function* () {
173
+ const strategy = yield _this4.registerStrategy(itemType || type);
174
+ let res;
175
+ if (itemType && type === 'layer') res = _this4.multiCreate(id, strategy, json);else res = _this4.singleCreate(id, strategy, json);
176
+ return _this4.handleResult(id, res);
265
177
  }));
266
- function create(_x8) {
267
- return _create.apply(this, arguments);
268
- }
269
- return create;
270
- }())
271
- }, {
272
- key: "singleUpdate",
273
- value: function () {
274
- var _singleUpdate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(id, strategy, option, group) {
275
- var _this4 = this;
276
- var target, _target$userData$enti, entityParams, entityInfoArray, targetEntityInfo, _option$interactiveEf2, interactiveEffect, entity, interactable;
277
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
278
- while (1) switch (_context6.prev = _context6.next) {
279
- case 0:
280
- target = hybridList.get(id);
281
- _target$userData$enti = target.userData.entityParams, entityParams = _target$userData$enti === void 0 ? {} : _target$userData$enti;
282
- if (target.userData.entityParams.type === 'model') this.materialSwitchSystem.removeObject(target);
283
- _context6.next = 5;
284
- return Promise.allSettled([strategy.update(target, option)]);
285
- case 5:
286
- entityInfoArray = _context6.sent;
287
- targetEntityInfo = entityInfoArray[0];
288
- _option$interactiveEf2 = option.interactiveEffect, interactiveEffect = _option$interactiveEf2 === void 0 ? false : _option$interactiveEf2;
289
- if (!(targetEntityInfo.status === 'rejected')) {
290
- _context6.next = 10;
291
- break;
292
- }
293
- throw new Error(targetEntityInfo.reason);
294
- case 10:
295
- entity = targetEntityInfo.value;
296
- entity.tag = 'entity'; // use used for event penetration identification
297
- entity.entityId = id;
298
- interactable = entityParams.interactable;
299
- if (option.collision !== undefined) interactable = option.collision;
300
- entity.userData.entityParams = _objectSpread(_objectSpread(_objectSpread({}, entityParams), {}, {
301
- interactable: interactable
302
- }, option), {}, {
303
- interactiveEffect: interactiveEffect
304
- });
178
+ return _objectSpread(_objectSpread({}, json), {}, {
179
+ asyncTask
180
+ });
181
+ })();
182
+ }
183
+ singleUpdate(id, strategy, option, group) {
184
+ var _this5 = this;
185
+ return _asyncToGenerator(function* () {
186
+ const target = hybridList.get(id);
187
+ const {
188
+ entityParams = {}
189
+ } = target.userData;
190
+ if (target.userData.entityParams.type === 'model') _this5.materialSwitchSystem.removeObject(target);
191
+ const entityInfoArray = yield Promise.allSettled([strategy.update(target, option)]);
192
+ const targetEntityInfo = entityInfoArray[0];
193
+ const {
194
+ interactiveEffect = false
195
+ } = option;
196
+ if (targetEntityInfo.status === 'rejected') throw new Error(targetEntityInfo.reason);
197
+ const entity = targetEntityInfo.value;
198
+ entity.tag = 'entity'; // use used for event penetration identification
199
+ entity.entityId = id;
200
+ let interactable = entityParams.interactable;
201
+ if (option.collision !== undefined) interactable = option.collision;
202
+ entity.userData.entityParams = _objectSpread(_objectSpread(_objectSpread({}, entityParams), {}, {
203
+ interactable
204
+ }, option), {}, {
205
+ interactiveEffect
206
+ });
305
207
 
306
- // 兼容修改图层下的单个实体
307
- if (!group && entityParams.layerId) group = hybridList.get(entityParams.layerId);
308
- if (group) {
309
- group.remove(hybridList.get(id));
310
- group.add(entity);
311
- }
312
- hybridList.update(id, entity);
313
- if (interactiveEffect && entity.userData.entityParams.type === 'model') {
314
- entity.addEventListener('mouseover', function () {
315
- var _this4$select;
316
- if (entity.userData.entityParams.interactiveEffect) (_this4$select = _this4.select) === null || _this4$select === void 0 || _this4$select.call(_this4, [entity]);
317
- });
318
- entity.addEventListener('mouseout', function () {
319
- var _this4$select2;
320
- (_this4$select2 = _this4.select) === null || _this4$select2 === void 0 || _this4$select2.call(_this4, []);
321
- });
322
- }
323
- if (entity.userData.entityParams.type === 'model' && entity.visible) this.materialSwitchSystem.addObject(entity);
324
- return _context6.abrupt("return", _objectSpread(_objectSpread({}, option), {}, {
325
- id: id,
326
- position: entity.position.toArray(),
327
- rotation: entity.rotation.toArray(),
328
- scale: entity.scale.toArray(),
329
- visible: entity.visible
330
- }));
331
- case 22:
332
- case "end":
333
- return _context6.stop();
334
- }
335
- }, _callee6, this);
336
- }));
337
- function singleUpdate(_x9, _x10, _x11, _x12) {
338
- return _singleUpdate.apply(this, arguments);
208
+ // 兼容修改图层下的单个实体
209
+ if (!group && entityParams.layerId) group = hybridList.get(entityParams.layerId);
210
+ if (group) {
211
+ group.remove(hybridList.get(id));
212
+ group.add(entity);
339
213
  }
340
- return singleUpdate;
341
- }()
342
- }, {
343
- key: "multiUpdate",
344
- value: function () {
345
- var _multiUpdate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(id, strategy, option) {
346
- var _this5 = this;
347
- var group, items, legends, itemType, promises, interactable;
348
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
349
- while (1) switch (_context8.prev = _context8.next) {
350
- case 0:
351
- group = hybridList.get(id);
352
- items = option.items, legends = option.legends, itemType = option.itemType;
353
- promises = items.map( /*#__PURE__*/function () {
354
- var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(item) {
355
- var legendItem, currentItem;
356
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
357
- while (1) switch (_context7.prev = _context7.next) {
358
- case 0:
359
- legendItem = legends === null || legends === void 0 ? void 0 : legends.find(function (legend) {
360
- return legend.name === item.legend;
361
- });
362
- currentItem = legendItem ? _objectSpread(_objectSpread({}, legendItem), item) : item;
363
- if (!hybridList.get(item.id)) {
364
- _context7.next = 8;
365
- break;
366
- }
367
- _context7.next = 5;
368
- return _this5.singleUpdate(item.id, strategy, currentItem, group);
369
- case 5:
370
- return _context7.abrupt("return", _context7.sent);
371
- case 8:
372
- currentItem.type = itemType;
373
- _context7.next = 11;
374
- return _this5.singleCreate(item.id, strategy, currentItem, group);
375
- case 11:
376
- return _context7.abrupt("return", _context7.sent);
377
- case 12:
378
- case "end":
379
- return _context7.stop();
380
- }
381
- }, _callee7);
382
- }));
383
- return function (_x16) {
384
- return _ref4.apply(this, arguments);
385
- };
386
- }());
387
- _context8.next = 5;
388
- return Promise.all(promises);
389
- case 5:
390
- interactable = group.userData.entityParams.interactable;
391
- if (option.collision !== undefined) interactable = option.collision;
392
- group.userData.entityParams = _objectSpread(_objectSpread({}, group.userData.entityParams), {}, {
393
- interactable: interactable
394
- }, option);
395
- return _context8.abrupt("return", _objectSpread(_objectSpread({}, option), {}, {
396
- id: id,
397
- position: group.position.toArray(),
398
- rotation: group.rotation.toArray(),
399
- scale: group.scale.toArray(),
400
- visible: group.visible
401
- }));
402
- case 9:
403
- case "end":
404
- return _context8.stop();
405
- }
406
- }, _callee8);
407
- }));
408
- function multiUpdate(_x13, _x14, _x15) {
409
- return _multiUpdate.apply(this, arguments);
214
+ hybridList.update(id, entity);
215
+ if (interactiveEffect && entity.userData.entityParams.type === 'model') {
216
+ entity.addEventListener('mouseover', () => {
217
+ var _this5$select;
218
+ if (entity.userData.entityParams.interactiveEffect) (_this5$select = _this5.select) === null || _this5$select === void 0 || _this5$select.call(_this5, [entity]);
219
+ });
220
+ entity.addEventListener('mouseout', () => {
221
+ var _this5$select2;
222
+ (_this5$select2 = _this5.select) === null || _this5$select2 === void 0 || _this5$select2.call(_this5, []);
223
+ });
410
224
  }
411
- return multiUpdate;
412
- }()
413
- /**
414
- * update entity
415
- * @param json
416
- * @returns
417
- */
418
- }, {
419
- key: "update",
420
- value: (function () {
421
- var _update = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(json) {
422
- var _this6 = this;
423
- var id;
424
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
425
- while (1) switch (_context10.prev = _context10.next) {
426
- case 0:
427
- id = json.id;
428
- Promise.resolve().then( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
429
- var target, _target$userData$enti2, type, itemType, strategy, res;
430
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
431
- while (1) switch (_context9.prev = _context9.next) {
432
- case 0:
433
- target = hybridList.get(id);
434
- _target$userData$enti2 = target.userData.entityParams, type = _target$userData$enti2.type, itemType = _target$userData$enti2.itemType;
435
- _context9.next = 4;
436
- return _this6.registerStrategy(itemType || type);
437
- case 4:
438
- strategy = _context9.sent;
439
- if (itemType && type === 'layer') res = _this6.multiUpdate(id, strategy, _objectSpread({
440
- itemType: itemType
441
- }, json));else res = _this6.singleUpdate(id, strategy, json);
442
- _this6.handleResult(id, res);
443
- case 7:
444
- case "end":
445
- return _context9.stop();
446
- }
447
- }, _callee9);
448
- })));
449
- return _context10.abrupt("return", json);
450
- case 3:
451
- case "end":
452
- return _context10.stop();
225
+ if (entity.userData.entityParams.type === 'model' && entity.visible) _this5.materialSwitchSystem.addObject(entity);
226
+ return _objectSpread(_objectSpread({}, option), {}, {
227
+ id,
228
+ position: entity.position.toArray(),
229
+ rotation: entity.rotation.toArray(),
230
+ scale: entity.scale.toArray(),
231
+ visible: entity.visible
232
+ });
233
+ })();
234
+ }
235
+ multiUpdate(id, strategy, option) {
236
+ var _this6 = this;
237
+ return _asyncToGenerator(function* () {
238
+ const group = hybridList.get(id);
239
+ const {
240
+ items,
241
+ legends,
242
+ itemType
243
+ } = option;
244
+ const promises = items.map( /*#__PURE__*/function () {
245
+ var _ref3 = _asyncToGenerator(function* (item) {
246
+ const legendItem = legends === null || legends === void 0 ? void 0 : legends.find(legend => legend.name === item.legend);
247
+ const currentItem = legendItem ? _objectSpread(_objectSpread({}, legendItem), item) : item;
248
+ if (hybridList.get(item.id)) {
249
+ return yield _this6.singleUpdate(item.id, strategy, currentItem, group);
250
+ } else {
251
+ currentItem.type = itemType;
252
+ return yield _this6.singleCreate(item.id, strategy, currentItem, group);
453
253
  }
454
- }, _callee10);
455
- }));
456
- function update(_x17) {
457
- return _update.apply(this, arguments);
458
- }
459
- return update;
460
- }())
461
- }, {
462
- key: "execute",
463
- value: function () {
464
- var _execute = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(json) {
465
- var _this7 = this;
466
- var id, method, args;
467
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
468
- while (1) switch (_context12.prev = _context12.next) {
469
- case 0:
470
- id = json.id, method = json.method, args = json.args;
471
- if (id && method) {
472
- Promise.resolve().then( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
473
- var target, type, strategy, entityInfoArray, targetEntityInfo, entity;
474
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
475
- while (1) switch (_context11.prev = _context11.next) {
476
- case 0:
477
- target = hybridList.get(id);
478
- type = target.userData.entityParams.type;
479
- _context11.next = 4;
480
- return _this7.registerStrategy(type);
481
- case 4:
482
- strategy = _context11.sent;
483
- _context11.next = 7;
484
- return Promise.allSettled([strategy[method](args, target)]);
485
- case 7:
486
- entityInfoArray = _context11.sent;
487
- targetEntityInfo = entityInfoArray[0];
488
- if (!(targetEntityInfo.status === 'rejected')) {
489
- _context11.next = 11;
490
- break;
491
- }
492
- throw new Error(targetEntityInfo.reason);
493
- case 11:
494
- entity = targetEntityInfo.value;
495
- hybridList.update(id, entity);
496
- _this7.handleResult(id, _objectSpread(_objectSpread({}, json), {}, {
497
- id: id,
498
- position: entity.position.toArray(),
499
- rotation: entity.rotation.toArray(),
500
- scale: entity.scale.toArray(),
501
- visible: entity.visible
502
- }));
503
- case 14:
504
- case "end":
505
- return _context11.stop();
506
- }
507
- }, _callee11);
508
- })));
509
- }
510
- return _context12.abrupt("return", json);
511
- case 3:
512
- case "end":
513
- return _context12.stop();
254
+ });
255
+ return function (_x2) {
256
+ return _ref3.apply(this, arguments);
257
+ };
258
+ }());
259
+ yield Promise.all(promises);
260
+ let interactable = group.userData.entityParams.interactable;
261
+ if (option.collision !== undefined) interactable = option.collision;
262
+ group.userData.entityParams = _objectSpread(_objectSpread({}, group.userData.entityParams), {}, {
263
+ interactable
264
+ }, option);
265
+ return _objectSpread(_objectSpread({}, option), {}, {
266
+ id,
267
+ position: group.position.toArray(),
268
+ rotation: group.rotation.toArray(),
269
+ scale: group.scale.toArray(),
270
+ visible: group.visible
271
+ });
272
+ })();
273
+ }
274
+
275
+ /**
276
+ * update entity
277
+ * @param json
278
+ * @returns
279
+ */
280
+ update(json) {
281
+ var _this7 = this;
282
+ return _asyncToGenerator(function* () {
283
+ const {
284
+ id
285
+ } = json;
286
+ Promise.resolve().then( /*#__PURE__*/_asyncToGenerator(function* () {
287
+ const target = hybridList.get(id);
288
+ const {
289
+ entityParams: {
290
+ type,
291
+ itemType
514
292
  }
515
- }, _callee12);
293
+ } = target.userData;
294
+ const strategy = yield _this7.registerStrategy(itemType || type);
295
+ let res;
296
+ if (itemType && type === 'layer') res = _this7.multiUpdate(id, strategy, _objectSpread({
297
+ itemType
298
+ }, json));else res = _this7.singleUpdate(id, strategy, json);
299
+ _this7.handleResult(id, res);
516
300
  }));
517
- function execute(_x18) {
518
- return _execute.apply(this, arguments);
301
+ return json;
302
+ })();
303
+ }
304
+ execute(json) {
305
+ var _this8 = this;
306
+ return _asyncToGenerator(function* () {
307
+ const {
308
+ id,
309
+ method,
310
+ args
311
+ } = json;
312
+ if (id && method) {
313
+ Promise.resolve().then( /*#__PURE__*/_asyncToGenerator(function* () {
314
+ const target = hybridList.get(id);
315
+ const {
316
+ entityParams: {
317
+ type
318
+ }
319
+ } = target.userData;
320
+ const strategy = yield _this8.registerStrategy(type);
321
+ const entityInfoArray = yield Promise.allSettled([strategy[method](args, target)]);
322
+ const targetEntityInfo = entityInfoArray[0];
323
+ if (targetEntityInfo.status === 'rejected') throw new Error(targetEntityInfo.reason);
324
+ const entity = targetEntityInfo.value;
325
+ hybridList.update(id, entity);
326
+ _this8.handleResult(id, _objectSpread(_objectSpread({}, json), {}, {
327
+ id,
328
+ position: entity.position.toArray(),
329
+ rotation: entity.rotation.toArray(),
330
+ scale: entity.scale.toArray(),
331
+ visible: entity.visible
332
+ }));
333
+ }));
519
334
  }
520
- return execute;
521
- }()
522
- /**
523
- * handle create or update loadded result
524
- * @param id
525
- * @param res
526
- */
527
- }, {
528
- key: "handleResult",
529
- value: (function () {
530
- var _handleResult = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(id, res) {
531
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
532
- while (1) switch (_context13.prev = _context13.next) {
533
- case 0:
534
- return _context13.abrupt("return", Promise.resolve(res).then(function () {
535
- sendToMessage({
536
- messageType: MessageType.Event,
537
- messageName: 'onLoaded',
538
- status: EMessageStatus.Success,
539
- global: false
540
- }, {
541
- id: id,
542
- success: true
543
- });
544
- }).catch(function () {
545
- sendToMessage({
546
- messageType: MessageType.Event,
547
- messageName: 'onLoaded',
548
- status: EMessageStatus.Success,
549
- global: false
550
- }, {
551
- id: id,
552
- success: false
553
- });
554
- }).finally(function () {
555
- utils.emitter.emit('onEntityLoaded', {
556
- id: id
557
- });
558
- }));
559
- case 1:
560
- case "end":
561
- return _context13.stop();
562
- }
563
- }, _callee13);
564
- }));
565
- function handleResult(_x19, _x20) {
566
- return _handleResult.apply(this, arguments);
335
+ return json;
336
+ })();
337
+ }
338
+
339
+ /**
340
+ * handle create or update loadded result
341
+ * @param id
342
+ * @param res
343
+ */
344
+ handleResult(id, res) {
345
+ return _asyncToGenerator(function* () {
346
+ return Promise.resolve(res).then(() => {
347
+ sendToMessage({
348
+ messageType: MessageType.Event,
349
+ messageName: 'onLoaded',
350
+ status: EMessageStatus.Success,
351
+ global: false
352
+ }, {
353
+ id,
354
+ success: true
355
+ });
356
+ }).catch(() => {
357
+ sendToMessage({
358
+ messageType: MessageType.Event,
359
+ messageName: 'onLoaded',
360
+ status: EMessageStatus.Success,
361
+ global: false
362
+ }, {
363
+ id,
364
+ success: false
365
+ });
366
+ }).finally(() => {
367
+ utils.emitter.emit('onEntityLoaded', {
368
+ id
369
+ });
370
+ });
371
+ })();
372
+ }
373
+ customizer(objValue, srcValue) {
374
+ if (Array.isArray(objValue) && srcValue) return srcValue;
375
+ }
376
+
377
+ /**
378
+ * delete entity
379
+ * @param json
380
+ */
381
+ delete(json) {
382
+ const {
383
+ id
384
+ } = json;
385
+ const target = hybridList.get(id);
386
+ if (!target) throw new Error(`entity ${id} is not exist`);
387
+ if (target.userData.entityParams.type === 'model') this.materialSwitchSystem.removeObject(target);
388
+ const deleteChildren = entityId => {
389
+ const entity = hybridList.get(entityId);
390
+ if (!entity) return;
391
+ if (entity.children) {
392
+ entity.children.forEach(child => {
393
+ const {
394
+ id
395
+ } = child.userData.entityParams || {};
396
+ id && deleteChildren(id);
397
+ });
567
398
  }
568
- return handleResult;
569
- }())
570
- }, {
571
- key: "customizer",
572
- value: function customizer(objValue, srcValue) {
573
- if (Array.isArray(objValue) && srcValue) return srcValue;
574
- }
399
+ hybridList.has(entityId) && hybridList.delete(entityId);
400
+ };
401
+ deleteChildren(id);
402
+ target.removeFromParent();
403
+ const entityDispose = createDisposeFn();
575
404
 
576
- /**
577
- * delete entity
578
- * @param json
579
- */
580
- }, {
581
- key: "delete",
582
- value: function _delete(json) {
583
- var id = json.id;
584
- var target = hybridList.get(id);
585
- if (!target) throw new Error("entity ".concat(id, " is not exist"));
586
- if (target.userData.entityParams.type === 'model') this.materialSwitchSystem.removeObject(target);
587
- var deleteChildren = function deleteChildren(entityId) {
588
- var entity = hybridList.get(entityId);
589
- if (!entity) return;
590
- if (entity.children) {
591
- entity.children.forEach(function (child) {
592
- var _ref7 = child.userData.entityParams || {},
593
- id = _ref7.id;
594
- id && deleteChildren(id);
595
- });
596
- }
597
- hybridList.has(entityId) && hybridList.delete(entityId);
598
- };
599
- deleteChildren(id);
600
- target.removeFromParent();
601
- var entityDispose = createDisposeFn();
405
+ // @ts-ignore
406
+ // eslint-disable-next-line no-proto
407
+ target.__proto__.dispose = entityDispose;
408
+ // @ts-ignore
409
+ target.dispose();
410
+ hybridList.delete(id);
411
+ }
602
412
 
603
- // @ts-ignore
604
- // eslint-disable-next-line no-proto
605
- target.__proto__.dispose = entityDispose;
606
- // @ts-ignore
607
- target.dispose();
608
- hybridList.delete(id);
609
- }
413
+ /**
414
+ * get entity
415
+ * @param params
416
+ * @returns
417
+ */
418
+ get(params) {
419
+ const {
420
+ id
421
+ } = params;
422
+ const entity = hybridList.get(id);
423
+ const option = this.getEntityOption(entity);
424
+ return _objectSpread(_objectSpread({}, option), {}, {
425
+ id,
426
+ position: entity.position.toArray(),
427
+ rotation: entity.rotation.toArray(),
428
+ scale: entity.scale.toArray(),
429
+ visible: entity.visible,
430
+ type: entity.userData.entityParams.type,
431
+ name: entity.userData.entityParams.name
432
+ });
433
+ }
610
434
 
611
- /**
612
- * get entity
613
- * @param params
614
- * @returns
615
- */
616
- }, {
617
- key: "get",
618
- value: function get(params) {
619
- var id = params.id;
620
- var entity = hybridList.get(id);
621
- var option = this.getEntityOption(entity);
622
- return _objectSpread(_objectSpread({}, option), {}, {
623
- id: id,
624
- position: entity.position.toArray(),
625
- rotation: entity.rotation.toArray(),
626
- scale: entity.scale.toArray(),
627
- visible: entity.visible,
628
- type: entity.userData.entityParams.type,
629
- name: entity.userData.entityParams.name
630
- });
631
- }
435
+ /**
436
+ * get entity option
437
+ * @param target
438
+ * @returns
439
+ */
440
+ getEntityOption(target) {
441
+ return target && (target.userData.option || {});
442
+ }
632
443
 
633
- /**
634
- * get entity option
635
- * @param target
636
- * @returns
637
- */
638
- }, {
639
- key: "getEntityOption",
640
- value: function getEntityOption(target) {
641
- return target && (target.userData.option || {});
444
+ /**
445
+ * register entity events
446
+ * @param opts
447
+ */
448
+ registerEvents(opts) {
449
+ const {
450
+ eventName,
451
+ entityId: id
452
+ } = opts;
453
+ const realEventName = eventName.slice(2).toLowerCase();
454
+ const target = hybridList.get(id);
455
+ if (!target) throw new Error(`entity ${id} is not exist`);
456
+ if (!(target.userData.entityParams.type === 'model' || target.userData.entityParams.type === 'poi')) return;
457
+ if (!target.userData.entityParams.interactable) {
458
+ this.unregisterEvents(opts);
459
+ return;
642
460
  }
643
461
 
644
- /**
645
- * register entity events
646
- * @param opts
647
- */
648
- }, {
649
- key: "registerEvents",
650
- value: function registerEvents(opts) {
651
- var eventName = opts.eventName,
652
- id = opts.entityId;
653
- var realEventName = eventName.slice(2).toLowerCase();
654
- var target = hybridList.get(id);
655
- if (!target) throw new Error("entity ".concat(id, " is not exist"));
656
- if (!(target.userData.entityParams.type === 'model' || target.userData.entityParams.type === 'poi')) return;
657
- if (!target.userData.entityParams.interactable) {
658
- this.unregisterEvents(opts);
659
- return;
660
- }
661
-
662
- // @ts-ignore
663
- if (eventPenetrateType.includes(target.entityType)) {
664
- target.userData[realEventName] = debounce(function (e) {
665
- var closestMesh = e.newClosestMesh;
666
- var minimumEntity = getMinimumEntity(closestMesh, target);
667
- minimumEntity && sendToMessage({
668
- messageType: MessageType.Event,
669
- messageName: eventName,
670
- status: EMessageStatus.Success,
671
- global: false
672
- }, {
673
- targetId: minimumEntity.entityId,
674
- id: id
675
- });
462
+ // @ts-ignore
463
+ if (eventPenetrateType.includes(target.entityType)) {
464
+ target.userData[realEventName] = debounce(e => {
465
+ const closestMesh = e.newClosestMesh;
466
+ const minimumEntity = getMinimumEntity(closestMesh, target);
467
+ minimumEntity && sendToMessage({
468
+ messageType: MessageType.Event,
469
+ messageName: eventName,
470
+ status: EMessageStatus.Success,
471
+ global: false
472
+ }, {
473
+ targetId: minimumEntity.entityId,
474
+ id
676
475
  });
677
- target.addEventListener(realEventName, target.userData[realEventName]);
678
- } else {
679
- target.userData[realEventName] = debounce(function (e) {
680
- console.log('e:', e);
681
- sendToMessage({
682
- messageType: MessageType.Event,
683
- messageName: eventName,
684
- status: EMessageStatus.Success,
685
- global: false
686
- }, {
687
- targetId: id,
688
- id: id
689
- });
476
+ });
477
+ target.addEventListener(realEventName, target.userData[realEventName]);
478
+ } else {
479
+ target.userData[realEventName] = debounce(e => {
480
+ console.log('e:', e);
481
+ sendToMessage({
482
+ messageType: MessageType.Event,
483
+ messageName: eventName,
484
+ status: EMessageStatus.Success,
485
+ global: false
486
+ }, {
487
+ targetId: id,
488
+ id
690
489
  });
691
- target.addEventListener(realEventName, target.userData[realEventName]);
692
- }
490
+ });
491
+ target.addEventListener(realEventName, target.userData[realEventName]);
693
492
  }
493
+ }
694
494
 
695
- /**
696
- * unregister entity events
697
- * @param opts
698
- */
699
- }, {
700
- key: "unregisterEvents",
701
- value: function unregisterEvents(opts) {
702
- var eventName = opts.eventName,
703
- id = opts.entityId;
704
- var realEventName = eventName.slice(2).toLowerCase();
705
- var target = hybridList.get(id);
706
- if (!target) throw new Error("entity ".concat(id, " is not exist"));
707
- target.removeEventListener(realEventName, target.userData[realEventName]);
708
- }
709
- }]);
710
- return Entity;
711
- }();
495
+ /**
496
+ * unregister entity events
497
+ * @param opts
498
+ */
499
+ unregisterEvents(opts) {
500
+ const {
501
+ eventName,
502
+ entityId: id
503
+ } = opts;
504
+ const realEventName = eventName.slice(2).toLowerCase();
505
+ const target = hybridList.get(id);
506
+ if (!target) throw new Error(`entity ${id} is not exist`);
507
+ target.removeEventListener(realEventName, target.userData[realEventName]);
508
+ }
509
+ }
712
510
  export default Entity;
713
511
  //# sourceMappingURL=index.js.map