@anov/3d 0.0.287 → 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 +276 -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 +3 -3
@@ -1,25 +1,21 @@
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 { SurfaceMaterial } from '@anov/3d-ability';
14
9
  import * as ANOV from '@anov/3d-core';
15
10
  import { DoubleSide, utils } from '@anov/3d-core';
16
11
  import { hybridList } from "../entity";
17
- var emitter = utils.emitter;
18
- var MaterialManager = /*#__PURE__*/function () {
12
+ const {
13
+ emitter
14
+ } = utils;
15
+ class MaterialManager {
19
16
  // 记录初始材质信息
20
17
 
21
- function MaterialManager(app) {
22
- _classCallCheck(this, MaterialManager);
18
+ constructor(app) {
23
19
  _defineProperty(this, "app", void 0);
24
20
  _defineProperty(this, "originalMaterial", new Map());
25
21
  this.app = app;
@@ -29,363 +25,312 @@ var MaterialManager = /*#__PURE__*/function () {
29
25
  * Change material for target objects
30
26
  * @param json Material change configuration
31
27
  */
32
- _createClass(MaterialManager, [{
33
- key: "change",
34
- value: function change(json) {
35
- var _this = this;
36
- var processChange = function processChange(data) {
37
- var id = data.target;
38
- var object = hybridList.get(id);
39
- if (!object) {
40
- console.error("Target with id ".concat(id, " not found"));
41
- return;
42
- }
43
- _this.changeByObject(object, data);
44
- };
45
- if (Array.isArray(json.batch))
46
- // 支持多对象批量替换
47
- json.batch.forEach(processChange);else processChange(json);
48
- }
49
- }, {
50
- key: "changeByObject",
51
- value: function changeByObject(object, json) {
52
- var id = json.target,
53
- materials = json.materials,
54
- _json$properties = json.properties,
55
- properties = _json$properties === void 0 ? {} : _json$properties;
28
+ change(json) {
29
+ const processChange = data => {
30
+ const {
31
+ target: id
32
+ } = data;
33
+ const object = hybridList.get(id);
56
34
  if (!object) {
57
- console.error("Target with id ".concat(id, " not found"));
35
+ console.error(`Target with id ${id} not found`);
58
36
  return;
59
37
  }
60
- var materialMap = this.originalMaterial.get(id);
61
- if (!materialMap) {
62
- materialMap = new Map();
63
- this.originalMaterial.set(id, materialMap);
64
- }
65
- if (Array.isArray(materials)) this.applyMaterials(object, materials, properties, materialMap);else this.applySingleMaterial(object, materials, properties, materialMap);
38
+ this.changeByObject(object, data);
39
+ };
40
+ if (Array.isArray(json.batch))
41
+ // 支持多对象批量替换
42
+ json.batch.forEach(processChange);else processChange(json);
43
+ }
44
+ changeByObject(object, json) {
45
+ const {
46
+ target: id,
47
+ materials,
48
+ properties = {}
49
+ } = json;
50
+ if (!object) {
51
+ console.error(`Target with id ${id} not found`);
52
+ return;
66
53
  }
54
+ let materialMap = this.originalMaterial.get(id);
55
+ if (!materialMap) {
56
+ materialMap = new Map();
57
+ this.originalMaterial.set(id, materialMap);
58
+ }
59
+ if (Array.isArray(materials)) this.applyMaterials(object, materials, properties, materialMap);else this.applySingleMaterial(object, materials, properties, materialMap);
60
+ }
67
61
 
68
- /**
69
- * Restore material for target objects
70
- * @param json Material restoration configuration
71
- */
72
- }, {
73
- key: "restore",
74
- value: function restore(json) {
75
- var _this2 = this;
76
- var processRestore = function processRestore(data) {
77
- var id = data.target,
78
- materials = data.materials;
79
- var object = hybridList.get(id);
80
- if (!object) {
81
- console.error("Target with id ".concat(id, " not found"));
82
- return;
62
+ /**
63
+ * Restore material for target objects
64
+ * @param json Material restoration configuration
65
+ */
66
+ restore(json) {
67
+ const processRestore = data => {
68
+ const {
69
+ target: id,
70
+ materials
71
+ } = data;
72
+ const object = hybridList.get(id);
73
+ if (!object) {
74
+ console.error(`Target with id ${id} not found`);
75
+ return;
76
+ }
77
+ const materialMap = this.originalMaterial.get(id);
78
+ if (!materialMap) return;
79
+ if (materials) this.restoreMaterials(object, materials, materialMap);else this.restoreAllMaterials(object, materialMap);
80
+ emitter.emit('onMaterialChanged', {
81
+ target: object
82
+ });
83
+ };
84
+ if (Array.isArray(json.batch)) json.batch.forEach(processRestore);else processRestore(json);
85
+ }
86
+ applyMaterials(target, materials, rootProperties, materialMap) {
87
+ var _this = this;
88
+ let materialTemplate;
89
+ materials.forEach( /*#__PURE__*/function () {
90
+ var _ref = _asyncToGenerator(function* ({
91
+ meshIndex,
92
+ primitiveIndex,
93
+ materialId,
94
+ properties = {}
95
+ }) {
96
+ _this.traverseMeshes(target, meshIndex, primitiveIndex, mesh => {
97
+ if (!materialMap.has(mesh.uuid)) materialMap.set(mesh.uuid, mesh.material.clone());
98
+ });
99
+ if (materialId) {
100
+ materialTemplate = yield SurfaceMaterial.getMaterial(materialId);
101
+ if (materialId === 'Glass')
102
+ // TODO: 默认玻璃材质的透明度太低
103
+ materialTemplate.opacity = 0.8;
104
+ materialTemplate.depthWrite = true;
105
+ _this.applyMaterialOptions(materialTemplate, _objectSpread(_objectSpread({}, rootProperties), properties));
106
+ _this.traverseMeshes(target, meshIndex, primitiveIndex, mesh => {
107
+ mesh.material = materialTemplate;
108
+ });
109
+ } else {
110
+ _this.traverseMeshes(target, meshIndex, primitiveIndex, mesh => {
111
+ _this.applyMaterialOptions(mesh.material, _objectSpread(_objectSpread({}, rootProperties), properties));
112
+ });
83
113
  }
84
- var materialMap = _this2.originalMaterial.get(id);
85
- if (!materialMap) return;
86
- if (materials) _this2.restoreMaterials(object, materials, materialMap);else _this2.restoreAllMaterials(object, materialMap);
87
114
  emitter.emit('onMaterialChanged', {
88
- target: object
115
+ target
89
116
  });
117
+ });
118
+ return function (_x) {
119
+ return _ref.apply(this, arguments);
90
120
  };
91
- if (Array.isArray(json.batch)) json.batch.forEach(processRestore);else processRestore(json);
92
- }
93
- }, {
94
- key: "applyMaterials",
95
- value: function applyMaterials(target, materials, rootProperties, materialMap) {
96
- var _this3 = this;
97
- var materialTemplate;
98
- materials.forEach( /*#__PURE__*/function () {
99
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
100
- var meshIndex, primitiveIndex, materialId, _ref$properties, properties;
101
- return _regeneratorRuntime().wrap(function _callee$(_context) {
102
- while (1) switch (_context.prev = _context.next) {
103
- case 0:
104
- meshIndex = _ref.meshIndex, primitiveIndex = _ref.primitiveIndex, materialId = _ref.materialId, _ref$properties = _ref.properties, properties = _ref$properties === void 0 ? {} : _ref$properties;
105
- _this3.traverseMeshes(target, meshIndex, primitiveIndex, function (mesh) {
106
- if (!materialMap.has(mesh.uuid)) materialMap.set(mesh.uuid, mesh.material.clone());
107
- });
108
- if (!materialId) {
109
- _context.next = 12;
110
- break;
111
- }
112
- _context.next = 5;
113
- return SurfaceMaterial.getMaterial(materialId);
114
- case 5:
115
- materialTemplate = _context.sent;
116
- if (materialId === 'Glass')
117
- // TODO: 默认玻璃材质的透明度太低
118
- materialTemplate.opacity = 0.8;
119
- materialTemplate.depthWrite = true;
120
- _this3.applyMaterialOptions(materialTemplate, _objectSpread(_objectSpread({}, rootProperties), properties));
121
- _this3.traverseMeshes(target, meshIndex, primitiveIndex, function (mesh) {
122
- mesh.material = materialTemplate;
123
- });
124
- _context.next = 13;
125
- break;
126
- case 12:
127
- _this3.traverseMeshes(target, meshIndex, primitiveIndex, function (mesh) {
128
- _this3.applyMaterialOptions(mesh.material, _objectSpread(_objectSpread({}, rootProperties), properties));
129
- });
130
- case 13:
131
- emitter.emit('onMaterialChanged', {
132
- target: target
133
- });
134
- case 14:
135
- case "end":
136
- return _context.stop();
137
- }
138
- }, _callee);
139
- }));
140
- return function (_x) {
141
- return _ref2.apply(this, arguments);
142
- };
143
- }());
144
- }
145
- }, {
146
- key: "applySingleMaterial",
147
- value: function () {
148
- var _applySingleMaterial = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(target, materialId) {
149
- var properties,
150
- materialMap,
151
- material,
152
- _args2 = arguments;
153
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
154
- while (1) switch (_context2.prev = _context2.next) {
155
- case 0:
156
- properties = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : {};
157
- materialMap = _args2.length > 3 ? _args2[3] : undefined;
158
- this.traverseMeshes(target, undefined, undefined, function (mesh) {
159
- if (!materialMap.has(mesh.uuid)) materialMap.set(mesh.uuid, mesh.material.clone());
160
- });
161
- _context2.next = 5;
162
- return SurfaceMaterial.getMaterial(materialId);
163
- case 5:
164
- material = _context2.sent;
165
- material.depthWrite = true;
166
- material.side = DoubleSide;
167
- this.applyMaterialOptions(material, properties);
168
- this.traverseMeshes(target, undefined, undefined, function (mesh) {
169
- mesh.material = material;
170
- });
171
- emitter.emit('onMaterialChanged', {
172
- target: target
173
- });
174
- case 11:
175
- case "end":
176
- return _context2.stop();
177
- }
178
- }, _callee2, this);
179
- }));
180
- function applySingleMaterial(_x2, _x3) {
181
- return _applySingleMaterial.apply(this, arguments);
182
- }
183
- return applySingleMaterial;
184
- }()
185
- }, {
186
- key: "applyMaterialOptions",
187
- value: function applyMaterialOptions(material, option) {
188
- var _this4 = this;
189
- var color = option.color,
190
- roughness = option.roughness,
191
- metalness = option.metalness,
192
- diffuseMap = option.diffuseMap,
193
- normalMap = option.normalMap,
194
- glossinessMap = option.glossinessMap,
195
- reflectionMap = option.reflectionMap,
196
- metalnessMap = option.metalnessMap,
197
- roughnessMap = option.roughnessMap,
198
- offset = option.offset,
199
- repeat = option.repeat,
200
- rotation = option.rotation;
121
+ }());
122
+ }
123
+ applySingleMaterial(target, materialId, properties = {}, materialMap) {
124
+ var _this2 = this;
125
+ return _asyncToGenerator(function* () {
126
+ _this2.traverseMeshes(target, undefined, undefined, mesh => {
127
+ if (!materialMap.has(mesh.uuid)) materialMap.set(mesh.uuid, mesh.material.clone());
128
+ });
129
+ const material = yield SurfaceMaterial.getMaterial(materialId);
130
+ material.depthWrite = true;
131
+ material.side = DoubleSide;
132
+ _this2.applyMaterialOptions(material, properties);
133
+ _this2.traverseMeshes(target, undefined, undefined, mesh => {
134
+ mesh.material = material;
135
+ });
136
+ emitter.emit('onMaterialChanged', {
137
+ target
138
+ });
139
+ })();
140
+ }
141
+ applyMaterialOptions(material, option) {
142
+ const {
143
+ color,
144
+ roughness,
145
+ metalness,
146
+ diffuseMap,
147
+ normalMap,
148
+ glossinessMap,
149
+ reflectionMap,
150
+ metalnessMap,
151
+ roughnessMap,
152
+ offset,
153
+ repeat,
154
+ rotation
155
+ } = option;
201
156
 
202
- // 设置颜色
203
- if (color) material.color = new ANOV.Color(color);
157
+ // 设置颜色
158
+ if (color) material.color = new ANOV.Color(color);
204
159
 
205
- // 设置粗糙度
206
- if (roughness !== undefined) material.roughness = roughness;
160
+ // 设置粗糙度
161
+ if (roughness !== undefined) material.roughness = roughness;
207
162
 
208
- // 设置金属度
209
- if (metalness !== undefined) material.metalness = metalness;
163
+ // 设置金属度
164
+ if (metalness !== undefined) material.metalness = metalness;
210
165
 
211
- // 纹理加载器
212
- var textureLoader = new ANOV.TextureLoader();
166
+ // 纹理加载器
167
+ const textureLoader = new ANOV.TextureLoader();
213
168
 
214
- // 应用漫反射贴图 (diffuse/albedo map)
215
- if (diffuseMap) {
216
- material.map = textureLoader.load(diffuseMap, function (texture) {
217
- _this4.applyTextureTransform(texture, {
218
- offset: offset,
219
- repeat: repeat,
220
- rotation: rotation
221
- });
222
- material.needsUpdate = true;
169
+ // 应用漫反射贴图 (diffuse/albedo map)
170
+ if (diffuseMap) {
171
+ material.map = textureLoader.load(diffuseMap, texture => {
172
+ this.applyTextureTransform(texture, {
173
+ offset,
174
+ repeat,
175
+ rotation
223
176
  });
224
- }
177
+ material.needsUpdate = true;
178
+ });
179
+ }
225
180
 
226
- // 应用法线贴图
227
- if (normalMap) {
228
- material.normalMap = textureLoader.load(normalMap, function (texture) {
229
- _this4.applyTextureTransform(texture, {
230
- offset: offset,
231
- repeat: repeat,
232
- rotation: rotation
233
- });
234
- material.needsUpdate = true;
181
+ // 应用法线贴图
182
+ if (normalMap) {
183
+ material.normalMap = textureLoader.load(normalMap, texture => {
184
+ this.applyTextureTransform(texture, {
185
+ offset,
186
+ repeat,
187
+ rotation
235
188
  });
236
- }
189
+ material.needsUpdate = true;
190
+ });
191
+ }
237
192
 
238
- // 应用粗糙度贴图
239
- if (roughnessMap) {
240
- material.roughnessMap = textureLoader.load(roughnessMap, function (texture) {
241
- _this4.applyTextureTransform(texture, {
242
- offset: offset,
243
- repeat: repeat,
244
- rotation: rotation
245
- });
246
- material.needsUpdate = true;
193
+ // 应用粗糙度贴图
194
+ if (roughnessMap) {
195
+ material.roughnessMap = textureLoader.load(roughnessMap, texture => {
196
+ this.applyTextureTransform(texture, {
197
+ offset,
198
+ repeat,
199
+ rotation
247
200
  });
248
- }
201
+ material.needsUpdate = true;
202
+ });
203
+ }
249
204
 
250
- // 应用金属度贴图
251
- if (metalnessMap) {
252
- material.metalnessMap = textureLoader.load(metalnessMap, function (texture) {
253
- _this4.applyTextureTransform(texture, {
254
- offset: offset,
255
- repeat: repeat,
256
- rotation: rotation
257
- });
258
- material.needsUpdate = true;
205
+ // 应用金属度贴图
206
+ if (metalnessMap) {
207
+ material.metalnessMap = textureLoader.load(metalnessMap, texture => {
208
+ this.applyTextureTransform(texture, {
209
+ offset,
210
+ repeat,
211
+ rotation
259
212
  });
260
- }
213
+ material.needsUpdate = true;
214
+ });
215
+ }
261
216
 
262
- // 应用位移贴图 (displacement map)
263
- // if (displaceMap) {
264
- // material.displacementMap = textureLoader.load(displaceMap, (texture) => {
265
- // this.applyTextureTransform(texture, { offset, repeat, rotation })
266
- // material.displacementScale = 0.1 // 可以根据需要调整
267
- // material.needsUpdate = true
268
- // })
269
- // }
217
+ // 应用位移贴图 (displacement map)
218
+ // if (displaceMap) {
219
+ // material.displacementMap = textureLoader.load(displaceMap, (texture) => {
220
+ // this.applyTextureTransform(texture, { offset, repeat, rotation })
221
+ // material.displacementScale = 0.1 // 可以根据需要调整
222
+ // material.needsUpdate = true
223
+ // })
224
+ // }
270
225
 
271
- // 应用光泽度贴图 (通常对应 roughnessMap 的反向)
272
- // if (glossinessMap && !roughnessMap) {
273
- // // 只有在没有专门的 roughnessMap 时才使用 glossinessMap
274
- // material.roughnessMap = textureLoader.load(glossinessMap, (texture) => {
275
- // this.applyTextureTransform(texture, { offset, repeat, rotation })
276
- // material.needsUpdate = true
277
- // })
278
- // }
226
+ // 应用光泽度贴图 (通常对应 roughnessMap 的反向)
227
+ // if (glossinessMap && !roughnessMap) {
228
+ // // 只有在没有专门的 roughnessMap 时才使用 glossinessMap
229
+ // material.roughnessMap = textureLoader.load(glossinessMap, (texture) => {
230
+ // this.applyTextureTransform(texture, { offset, repeat, rotation })
231
+ // material.needsUpdate = true
232
+ // })
233
+ // }
279
234
 
280
- // 应用高度贴图 (displacement map 或 bump map)
281
- // if (heightMap) {
282
- // // 优先使用 displacementMap,如果不支持则使用 bumpMap
283
- // if (material.displacementMap !== undefined) {
284
- // material.displacementMap = textureLoader.load(heightMap, (texture) => {
285
- // this.applyTextureTransform(texture, { offset, repeat, rotation })
286
- // material.displacementScale = 0.1 // 可以根据需要调整
287
- // material.needsUpdate = true
288
- // })
289
- // }
290
- // else if (material.bumpMap !== undefined) {
291
- // material.bumpMap = textureLoader.load(heightMap, (texture) => {
292
- // this.applyTextureTransform(texture, { offset, repeat, rotation })
293
- // material.bumpScale = 0.1 // 可以根据需要调整
294
- // material.needsUpdate = true
295
- // })
296
- // }
297
- // }
235
+ // 应用高度贴图 (displacement map 或 bump map)
236
+ // if (heightMap) {
237
+ // // 优先使用 displacementMap,如果不支持则使用 bumpMap
238
+ // if (material.displacementMap !== undefined) {
239
+ // material.displacementMap = textureLoader.load(heightMap, (texture) => {
240
+ // this.applyTextureTransform(texture, { offset, repeat, rotation })
241
+ // material.displacementScale = 0.1 // 可以根据需要调整
242
+ // material.needsUpdate = true
243
+ // })
244
+ // }
245
+ // else if (material.bumpMap !== undefined) {
246
+ // material.bumpMap = textureLoader.load(heightMap, (texture) => {
247
+ // this.applyTextureTransform(texture, { offset, repeat, rotation })
248
+ // material.bumpScale = 0.1 // 可以根据需要调整
249
+ // material.needsUpdate = true
250
+ // })
251
+ // }
252
+ // }
298
253
 
299
- // 应用反射贴图 (environment map)
300
- if (reflectionMap) {
301
- // 如果是环境贴图
302
- if (material.envMap !== undefined) {
303
- // 这里假设是立方体贴图,实际使用时可能需要 CubeTextureLoader
304
- material.envMap = textureLoader.load(reflectionMap, function (texture) {
305
- material.envMapIntensity = 1.0; // 可以根据需要调整
306
- material.needsUpdate = true;
307
- });
308
- }
309
- // 或者作为金属度贴图
310
- else if (material.metalnessMap !== undefined) {
311
- material.metalnessMap = textureLoader.load(reflectionMap, function (texture) {
312
- _this4.applyTextureTransform(texture, {
313
- offset: offset,
314
- repeat: repeat,
315
- rotation: rotation
316
- });
317
- material.needsUpdate = true;
254
+ // 应用反射贴图 (environment map)
255
+ if (reflectionMap) {
256
+ // 如果是环境贴图
257
+ if (material.envMap !== undefined) {
258
+ // 这里假设是立方体贴图,实际使用时可能需要 CubeTextureLoader
259
+ material.envMap = textureLoader.load(reflectionMap, texture => {
260
+ material.envMapIntensity = 1.0; // 可以根据需要调整
261
+ material.needsUpdate = true;
262
+ });
263
+ }
264
+ // 或者作为金属度贴图
265
+ else if (material.metalnessMap !== undefined) {
266
+ material.metalnessMap = textureLoader.load(reflectionMap, texture => {
267
+ this.applyTextureTransform(texture, {
268
+ offset,
269
+ repeat,
270
+ rotation
318
271
  });
319
- }
272
+ material.needsUpdate = true;
273
+ });
320
274
  }
321
-
322
- // 立即更新非纹理属性
323
- if (color || roughness !== undefined) material.needsUpdate = true;
324
275
  }
325
276
 
326
- // 辅助方法:应用纹理变换
327
- }, {
328
- key: "applyTextureTransform",
329
- value: function applyTextureTransform(texture, _ref3) {
330
- var offset = _ref3.offset,
331
- repeat = _ref3.repeat,
332
- rotation = _ref3.rotation;
333
- if (!texture) return;
334
-
335
- // 设置纹理偏移
336
- if (offset) {
337
- texture.offset.set(offset.x !== undefined ? offset.x : 0,
338
- // 假设传入的是百分比
339
- offset.y !== undefined ? offset.y : 0);
340
- }
341
-
342
- // 设置纹理重复
343
- if (repeat) {
344
- texture.repeat.set(repeat.x !== undefined ? repeat.x : 1, repeat.y !== undefined ? repeat.y : 1);
345
- }
277
+ // 立即更新非纹理属性
278
+ if (color || roughness !== undefined) material.needsUpdate = true;
279
+ }
346
280
 
347
- // 设置纹理旋转
348
- if (rotation !== undefined) texture.rotation = rotation * Math.PI / 180; // 转换为弧度
281
+ // 辅助方法:应用纹理变换
282
+ applyTextureTransform(texture, {
283
+ offset,
284
+ repeat,
285
+ rotation
286
+ }) {
287
+ if (!texture) return;
349
288
 
350
- // 设置纹理包裹模式
351
- texture.wrapS = ANOV.RepeatWrapping;
352
- texture.wrapT = ANOV.RepeatWrapping;
289
+ // 设置纹理偏移
290
+ if (offset) {
291
+ texture.offset.set(offset.x !== undefined ? offset.x : 0,
292
+ // 假设传入的是百分比
293
+ offset.y !== undefined ? offset.y : 0);
353
294
  }
354
- }, {
355
- key: "restoreMaterials",
356
- value: function restoreMaterials(target, materials, materialMap) {
357
- var _this5 = this;
358
- materials.forEach(function (_ref4) {
359
- var meshIndex = _ref4.meshIndex,
360
- primitiveIndex = _ref4.primitiveIndex;
361
- _this5.traverseMeshes(target, meshIndex, primitiveIndex, function (mesh) {
362
- if (materialMap.has(mesh.uuid)) mesh.material = materialMap.get(mesh.uuid);
363
- });
364
- });
295
+
296
+ // 设置纹理重复
297
+ if (repeat) {
298
+ texture.repeat.set(repeat.x !== undefined ? repeat.x : 1, repeat.y !== undefined ? repeat.y : 1);
365
299
  }
366
- }, {
367
- key: "restoreAllMaterials",
368
- value: function restoreAllMaterials(target, materialMap) {
369
- this.traverseMeshes(target, undefined, undefined, function (mesh) {
300
+
301
+ // 设置纹理旋转
302
+ if (rotation !== undefined) texture.rotation = rotation * Math.PI / 180; // 转换为弧度
303
+
304
+ // 设置纹理包裹模式
305
+ texture.wrapS = ANOV.RepeatWrapping;
306
+ texture.wrapT = ANOV.RepeatWrapping;
307
+ }
308
+ restoreMaterials(target, materials, materialMap) {
309
+ materials.forEach(({
310
+ meshIndex,
311
+ primitiveIndex
312
+ }) => {
313
+ this.traverseMeshes(target, meshIndex, primitiveIndex, mesh => {
370
314
  if (materialMap.has(mesh.uuid)) mesh.material = materialMap.get(mesh.uuid);
371
315
  });
372
- }
373
- }, {
374
- key: "traverseMeshes",
375
- value: function traverseMeshes(target, meshIndex, primitiveIndex, callback) {
376
- target.traverse(function (object) {
377
- if (object.type === 'Mesh') {
378
- var _object$userData = object.userData,
379
- _object$userData$mesh = _object$userData.meshIndex,
380
- currentMeshIndex = _object$userData$mesh === void 0 ? 0 : _object$userData$mesh,
381
- _object$userData$prim = _object$userData.primitiveIndex,
382
- currentPrimitiveIndex = _object$userData$prim === void 0 ? 0 : _object$userData$prim;
383
- if ((meshIndex === undefined || meshIndex === currentMeshIndex) && (primitiveIndex === undefined || primitiveIndex === currentPrimitiveIndex)) callback === null || callback === void 0 || callback(object);
384
- }
385
- });
386
- }
387
- }]);
388
- return MaterialManager;
389
- }();
316
+ });
317
+ }
318
+ restoreAllMaterials(target, materialMap) {
319
+ this.traverseMeshes(target, undefined, undefined, mesh => {
320
+ if (materialMap.has(mesh.uuid)) mesh.material = materialMap.get(mesh.uuid);
321
+ });
322
+ }
323
+ traverseMeshes(target, meshIndex, primitiveIndex, callback) {
324
+ target.traverse(object => {
325
+ if (object.type === 'Mesh') {
326
+ const {
327
+ meshIndex: currentMeshIndex = 0,
328
+ primitiveIndex: currentPrimitiveIndex = 0
329
+ } = object.userData;
330
+ if ((meshIndex === undefined || meshIndex === currentMeshIndex) && (primitiveIndex === undefined || primitiveIndex === currentPrimitiveIndex)) callback === null || callback === void 0 || callback(object);
331
+ }
332
+ });
333
+ }
334
+ }
390
335
  export default MaterialManager;
391
336
  //# sourceMappingURL=index.js.map