@anov/3d 0.0.310 → 0.0.311
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.
|
@@ -1,7 +1,10 @@
|
|
|
1
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
|
|
2
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
3
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
3
5
|
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
6
|
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; }
|
|
7
|
+
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; }
|
|
5
8
|
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
9
|
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
10
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
@@ -48,23 +51,43 @@ var MaterialManager = /*#__PURE__*/function () {
|
|
|
48
51
|
}
|
|
49
52
|
}, {
|
|
50
53
|
key: "changeByObject",
|
|
51
|
-
value: function
|
|
52
|
-
var
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
54
|
+
value: function () {
|
|
55
|
+
var _changeByObject = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(object, json) {
|
|
56
|
+
var id, materials, _json$properties, properties, materialMap;
|
|
57
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
58
|
+
while (1) switch (_context.prev = _context.next) {
|
|
59
|
+
case 0:
|
|
60
|
+
id = json.target, materials = json.materials, _json$properties = json.properties, properties = _json$properties === void 0 ? {} : _json$properties;
|
|
61
|
+
if (object) {
|
|
62
|
+
_context.next = 4;
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
console.error("Target with id ".concat(id, " not found"));
|
|
66
|
+
return _context.abrupt("return");
|
|
67
|
+
case 4:
|
|
68
|
+
materialMap = this.originalMaterial.get(id);
|
|
69
|
+
if (!materialMap) {
|
|
70
|
+
materialMap = new Map();
|
|
71
|
+
this.originalMaterial.set(id, materialMap);
|
|
72
|
+
}
|
|
73
|
+
if (!Array.isArray(materials)) {
|
|
74
|
+
_context.next = 10;
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
return _context.abrupt("return", this.applyMaterials(object, materials, properties, materialMap));
|
|
78
|
+
case 10:
|
|
79
|
+
return _context.abrupt("return", this.applySingleMaterial(object, materials, properties, materialMap));
|
|
80
|
+
case 11:
|
|
81
|
+
case "end":
|
|
82
|
+
return _context.stop();
|
|
83
|
+
}
|
|
84
|
+
}, _callee, this);
|
|
85
|
+
}));
|
|
86
|
+
function changeByObject(_x, _x2) {
|
|
87
|
+
return _changeByObject.apply(this, arguments);
|
|
64
88
|
}
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
89
|
+
return changeByObject;
|
|
90
|
+
}()
|
|
68
91
|
/**
|
|
69
92
|
* Restore material for target objects
|
|
70
93
|
* @param json Material restoration configuration
|
|
@@ -92,243 +115,326 @@ var MaterialManager = /*#__PURE__*/function () {
|
|
|
92
115
|
}
|
|
93
116
|
}, {
|
|
94
117
|
key: "applyMaterials",
|
|
95
|
-
value: function
|
|
96
|
-
var
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
118
|
+
value: function () {
|
|
119
|
+
var _applyMaterials = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(target, materials, rootProperties, materialMap) {
|
|
120
|
+
var _this3 = this;
|
|
121
|
+
var results, _iterator, _step, _loop;
|
|
122
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context4) {
|
|
123
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
124
|
+
case 0:
|
|
125
|
+
_context4.next = 2;
|
|
126
|
+
return Promise.all(materials.map( /*#__PURE__*/function () {
|
|
127
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref) {
|
|
128
|
+
var meshIndex, primitiveIndex, materialId, _ref$properties, properties, template, meshes;
|
|
129
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
130
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
131
|
+
case 0:
|
|
132
|
+
meshIndex = _ref.meshIndex, primitiveIndex = _ref.primitiveIndex, materialId = _ref.materialId, _ref$properties = _ref.properties, properties = _ref$properties === void 0 ? {} : _ref$properties;
|
|
133
|
+
_this3.traverseMeshes(target, meshIndex, primitiveIndex, function (mesh) {
|
|
134
|
+
if (!materialMap.has(mesh.uuid)) materialMap.set(mesh.uuid, mesh.material.clone());
|
|
135
|
+
});
|
|
136
|
+
if (!materialId) {
|
|
137
|
+
_context2.next = 15;
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
_context2.next = 5;
|
|
141
|
+
return SurfaceMaterial.getMaterial(materialId);
|
|
142
|
+
case 5:
|
|
143
|
+
template = _context2.sent;
|
|
144
|
+
if (template) {
|
|
145
|
+
_context2.next = 8;
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
return _context2.abrupt("return", null);
|
|
149
|
+
case 8:
|
|
150
|
+
if (materialId === 'Glass') template.opacity = 0.8;
|
|
151
|
+
template.depthWrite = true;
|
|
152
|
+
_context2.next = 12;
|
|
153
|
+
return _this3.applyMaterialOptions(template, _objectSpread(_objectSpread({}, rootProperties), properties));
|
|
154
|
+
case 12:
|
|
155
|
+
return _context2.abrupt("return", {
|
|
156
|
+
meshIndex: meshIndex,
|
|
157
|
+
primitiveIndex: primitiveIndex,
|
|
158
|
+
template: template
|
|
159
|
+
});
|
|
160
|
+
case 15:
|
|
161
|
+
meshes = [];
|
|
162
|
+
_this3.traverseMeshes(target, meshIndex, primitiveIndex, function (mesh) {
|
|
163
|
+
return meshes.push(mesh);
|
|
164
|
+
});
|
|
165
|
+
_context2.next = 19;
|
|
166
|
+
return Promise.all(meshes.map(function (mesh) {
|
|
167
|
+
return _this3.applyMaterialOptions(mesh.material, _objectSpread(_objectSpread({}, rootProperties), properties));
|
|
168
|
+
}));
|
|
169
|
+
case 19:
|
|
170
|
+
return _context2.abrupt("return", null);
|
|
171
|
+
case 20:
|
|
172
|
+
case "end":
|
|
173
|
+
return _context2.stop();
|
|
174
|
+
}
|
|
175
|
+
}, _callee2);
|
|
176
|
+
}));
|
|
177
|
+
return function (_x7) {
|
|
178
|
+
return _ref2.apply(this, arguments);
|
|
179
|
+
};
|
|
180
|
+
}()));
|
|
181
|
+
case 2:
|
|
182
|
+
results = _context4.sent;
|
|
183
|
+
// 阶段二:所有加载完毕,统一同步替换,一帧内完成
|
|
184
|
+
_iterator = _createForOfIteratorHelper(results);
|
|
185
|
+
_context4.prev = 4;
|
|
186
|
+
_loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
|
|
187
|
+
var result, meshIndex, primitiveIndex, template;
|
|
188
|
+
return _regeneratorRuntime().wrap(function _loop$(_context3) {
|
|
189
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
190
|
+
case 0:
|
|
191
|
+
result = _step.value;
|
|
192
|
+
if (result) {
|
|
193
|
+
_context3.next = 3;
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
return _context3.abrupt("return", 1);
|
|
197
|
+
case 3:
|
|
198
|
+
meshIndex = result.meshIndex, primitiveIndex = result.primitiveIndex, template = result.template;
|
|
199
|
+
_this3.traverseMeshes(target, meshIndex, primitiveIndex, function (mesh) {
|
|
200
|
+
mesh.material = template;
|
|
201
|
+
});
|
|
202
|
+
case 5:
|
|
203
|
+
case "end":
|
|
204
|
+
return _context3.stop();
|
|
205
|
+
}
|
|
206
|
+
}, _loop);
|
|
207
|
+
});
|
|
208
|
+
_iterator.s();
|
|
209
|
+
case 7:
|
|
210
|
+
if ((_step = _iterator.n()).done) {
|
|
211
|
+
_context4.next = 13;
|
|
125
212
|
break;
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
213
|
+
}
|
|
214
|
+
return _context4.delegateYield(_loop(), "t0", 9);
|
|
215
|
+
case 9:
|
|
216
|
+
if (!_context4.t0) {
|
|
217
|
+
_context4.next = 11;
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
return _context4.abrupt("continue", 11);
|
|
221
|
+
case 11:
|
|
222
|
+
_context4.next = 7;
|
|
223
|
+
break;
|
|
224
|
+
case 13:
|
|
225
|
+
_context4.next = 18;
|
|
226
|
+
break;
|
|
227
|
+
case 15:
|
|
228
|
+
_context4.prev = 15;
|
|
229
|
+
_context4.t1 = _context4["catch"](4);
|
|
230
|
+
_iterator.e(_context4.t1);
|
|
231
|
+
case 18:
|
|
232
|
+
_context4.prev = 18;
|
|
233
|
+
_iterator.f();
|
|
234
|
+
return _context4.finish(18);
|
|
235
|
+
case 21:
|
|
236
|
+
emitter.emit('onMaterialChanged', {
|
|
237
|
+
target: target
|
|
238
|
+
});
|
|
239
|
+
return _context4.abrupt("return", target);
|
|
240
|
+
case 23:
|
|
241
|
+
case "end":
|
|
242
|
+
return _context4.stop();
|
|
243
|
+
}
|
|
244
|
+
}, _callee3, null, [[4, 15, 18, 21]]);
|
|
245
|
+
}));
|
|
246
|
+
function applyMaterials(_x3, _x4, _x5, _x6) {
|
|
247
|
+
return _applyMaterials.apply(this, arguments);
|
|
248
|
+
}
|
|
249
|
+
return applyMaterials;
|
|
250
|
+
}()
|
|
145
251
|
}, {
|
|
146
252
|
key: "applySingleMaterial",
|
|
147
253
|
value: function () {
|
|
148
|
-
var _applySingleMaterial = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
254
|
+
var _applySingleMaterial = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(target, materialId) {
|
|
149
255
|
var properties,
|
|
150
256
|
materialMap,
|
|
151
257
|
material,
|
|
152
|
-
|
|
153
|
-
return _regeneratorRuntime().wrap(function
|
|
154
|
-
while (1) switch (
|
|
258
|
+
_args5 = arguments;
|
|
259
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context5) {
|
|
260
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
155
261
|
case 0:
|
|
156
|
-
properties =
|
|
157
|
-
materialMap =
|
|
262
|
+
properties = _args5.length > 2 && _args5[2] !== undefined ? _args5[2] : {};
|
|
263
|
+
materialMap = _args5.length > 3 ? _args5[3] : undefined;
|
|
158
264
|
this.traverseMeshes(target, undefined, undefined, function (mesh) {
|
|
159
265
|
if (!materialMap.has(mesh.uuid)) materialMap.set(mesh.uuid, mesh.material.clone());
|
|
160
266
|
});
|
|
161
|
-
|
|
267
|
+
_context5.next = 5;
|
|
162
268
|
return SurfaceMaterial.getMaterial(materialId);
|
|
163
269
|
case 5:
|
|
164
|
-
material =
|
|
270
|
+
material = _context5.sent;
|
|
165
271
|
material.depthWrite = true;
|
|
166
272
|
material.side = DoubleSide;
|
|
167
|
-
|
|
273
|
+
_context5.next = 10;
|
|
274
|
+
return this.applyMaterialOptions(material, properties);
|
|
275
|
+
case 10:
|
|
168
276
|
this.traverseMeshes(target, undefined, undefined, function (mesh) {
|
|
169
277
|
mesh.material = material;
|
|
170
278
|
});
|
|
171
279
|
emitter.emit('onMaterialChanged', {
|
|
172
280
|
target: target
|
|
173
281
|
});
|
|
174
|
-
case
|
|
282
|
+
case 12:
|
|
175
283
|
case "end":
|
|
176
|
-
return
|
|
284
|
+
return _context5.stop();
|
|
177
285
|
}
|
|
178
|
-
},
|
|
286
|
+
}, _callee4, this);
|
|
179
287
|
}));
|
|
180
|
-
function applySingleMaterial(
|
|
288
|
+
function applySingleMaterial(_x8, _x9) {
|
|
181
289
|
return _applySingleMaterial.apply(this, arguments);
|
|
182
290
|
}
|
|
183
291
|
return applySingleMaterial;
|
|
184
292
|
}()
|
|
185
293
|
}, {
|
|
186
|
-
key: "
|
|
187
|
-
value: function
|
|
294
|
+
key: "loadTexture",
|
|
295
|
+
value: function loadTexture(loader, url, option) {
|
|
188
296
|
var _this4 = this;
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
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;
|
|
201
|
-
|
|
202
|
-
// 设置颜色
|
|
203
|
-
if (color) material.color = new ANOV.Color(color);
|
|
204
|
-
|
|
205
|
-
// 设置粗糙度
|
|
206
|
-
if (roughness !== undefined) material.roughness = roughness;
|
|
207
|
-
|
|
208
|
-
// 设置金属度
|
|
209
|
-
if (metalness !== undefined) material.metalness = metalness;
|
|
210
|
-
|
|
211
|
-
// 纹理加载器
|
|
212
|
-
var textureLoader = new ANOV.TextureLoader();
|
|
213
|
-
|
|
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;
|
|
297
|
+
return new Promise(function (resolve) {
|
|
298
|
+
loader.load(url, function (texture) {
|
|
299
|
+
_this4.applyTextureTransform(texture, option);
|
|
300
|
+
resolve(texture);
|
|
223
301
|
});
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
}
|
|
237
|
-
|
|
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;
|
|
247
|
-
});
|
|
248
|
-
}
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
}, {
|
|
305
|
+
key: "applyMaterialOptions",
|
|
306
|
+
value: function () {
|
|
307
|
+
var _applyMaterialOptions = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(material, option) {
|
|
308
|
+
var color, roughness, metalness, diffuseMap, normalMap, glossinessMap, reflectionMap, metalnessMap, roughnessMap, offset, repeat, rotation, textureLoader;
|
|
309
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context6) {
|
|
310
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
311
|
+
case 0:
|
|
312
|
+
color = option.color, roughness = option.roughness, metalness = option.metalness, diffuseMap = option.diffuseMap, normalMap = option.normalMap, glossinessMap = option.glossinessMap, reflectionMap = option.reflectionMap, metalnessMap = option.metalnessMap, roughnessMap = option.roughnessMap, offset = option.offset, repeat = option.repeat, rotation = option.rotation; // 设置颜色
|
|
313
|
+
if (color) material.color = new ANOV.Color(color);
|
|
249
314
|
|
|
250
|
-
|
|
251
|
-
|
|
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;
|
|
259
|
-
});
|
|
260
|
-
} else if (reflectionMap) {
|
|
261
|
-
material.metalnessMap = textureLoader.load(reflectionMap, function (texture) {
|
|
262
|
-
_this4.applyTextureTransform(texture, {
|
|
263
|
-
offset: offset,
|
|
264
|
-
repeat: repeat,
|
|
265
|
-
rotation: rotation
|
|
266
|
-
});
|
|
267
|
-
material.needsUpdate = true;
|
|
268
|
-
});
|
|
269
|
-
}
|
|
315
|
+
// 设置粗糙度
|
|
316
|
+
if (roughness !== undefined) material.roughness = roughness;
|
|
270
317
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
// material.displacementMap = textureLoader.load(displaceMap, (texture) => {
|
|
274
|
-
// this.applyTextureTransform(texture, { offset, repeat, rotation })
|
|
275
|
-
// material.displacementScale = 0.1 // 可以根据需要调整
|
|
276
|
-
// material.needsUpdate = true
|
|
277
|
-
// })
|
|
278
|
-
// }
|
|
318
|
+
// 设置金属度
|
|
319
|
+
if (metalness !== undefined) material.metalness = metalness;
|
|
279
320
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
321
|
+
// 纹理加载器
|
|
322
|
+
textureLoader = new ANOV.TextureLoader(); // 应用漫反射贴图 (diffuse/albedo map)
|
|
323
|
+
if (!diffuseMap) {
|
|
324
|
+
_context6.next = 9;
|
|
325
|
+
break;
|
|
326
|
+
}
|
|
327
|
+
_context6.next = 8;
|
|
328
|
+
return this.loadTexture(textureLoader, diffuseMap, option);
|
|
329
|
+
case 8:
|
|
330
|
+
material.map = _context6.sent;
|
|
331
|
+
case 9:
|
|
332
|
+
if (!normalMap) {
|
|
333
|
+
_context6.next = 13;
|
|
334
|
+
break;
|
|
335
|
+
}
|
|
336
|
+
_context6.next = 12;
|
|
337
|
+
return this.loadTexture(textureLoader, normalMap, option);
|
|
338
|
+
case 12:
|
|
339
|
+
material.normalMap = _context6.sent;
|
|
340
|
+
case 13:
|
|
341
|
+
if (!roughnessMap) {
|
|
342
|
+
_context6.next = 17;
|
|
343
|
+
break;
|
|
344
|
+
}
|
|
345
|
+
_context6.next = 16;
|
|
346
|
+
return this.loadTexture(textureLoader, roughnessMap, option);
|
|
347
|
+
case 16:
|
|
348
|
+
material.roughnessMap = _context6.sent;
|
|
349
|
+
case 17:
|
|
350
|
+
if (!metalnessMap) {
|
|
351
|
+
_context6.next = 23;
|
|
352
|
+
break;
|
|
353
|
+
}
|
|
354
|
+
_context6.next = 20;
|
|
355
|
+
return this.loadTexture(textureLoader, metalnessMap, option);
|
|
356
|
+
case 20:
|
|
357
|
+
material.metalnessMap = _context6.sent;
|
|
358
|
+
_context6.next = 27;
|
|
359
|
+
break;
|
|
360
|
+
case 23:
|
|
361
|
+
if (!reflectionMap) {
|
|
362
|
+
_context6.next = 27;
|
|
363
|
+
break;
|
|
364
|
+
}
|
|
365
|
+
_context6.next = 26;
|
|
366
|
+
return this.loadTexture(textureLoader, reflectionMap, option);
|
|
367
|
+
case 26:
|
|
368
|
+
material.metalnessMap = _context6.sent;
|
|
369
|
+
case 27:
|
|
370
|
+
material.needsUpdate = true;
|
|
288
371
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
// })
|
|
298
|
-
// }
|
|
299
|
-
// else if (material.bumpMap !== undefined) {
|
|
300
|
-
// material.bumpMap = textureLoader.load(heightMap, (texture) => {
|
|
301
|
-
// this.applyTextureTransform(texture, { offset, repeat, rotation })
|
|
302
|
-
// material.bumpScale = 0.1 // 可以根据需要调整
|
|
303
|
-
// material.needsUpdate = true
|
|
304
|
-
// })
|
|
305
|
-
// }
|
|
306
|
-
// }
|
|
372
|
+
// 应用位移贴图 (displacement map)
|
|
373
|
+
// if (displaceMap) {
|
|
374
|
+
// material.displacementMap = textureLoader.load(displaceMap, (texture) => {
|
|
375
|
+
// this.applyTextureTransform(texture, { offset, repeat, rotation })
|
|
376
|
+
// material.displacementScale = 0.1 // 可以根据需要调整
|
|
377
|
+
// material.needsUpdate = true
|
|
378
|
+
// })
|
|
379
|
+
// }
|
|
307
380
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
// })
|
|
317
|
-
// }
|
|
318
|
-
// // 或者作为金属度贴图
|
|
319
|
-
// else if (material.metalnessMap !== undefined) {
|
|
320
|
-
// material.metalnessMap = textureLoader.load(reflectionMap, (texture) => {
|
|
321
|
-
// this.applyTextureTransform(texture, { offset, repeat, rotation })
|
|
322
|
-
// material.needsUpdate = true
|
|
323
|
-
// })
|
|
324
|
-
// }
|
|
325
|
-
// }
|
|
381
|
+
// 应用光泽度贴图 (通常对应 roughnessMap 的反向)
|
|
382
|
+
// if (glossinessMap && !roughnessMap) {
|
|
383
|
+
// // 只有在没有专门的 roughnessMap 时才使用 glossinessMap
|
|
384
|
+
// material.roughnessMap = textureLoader.load(glossinessMap, (texture) => {
|
|
385
|
+
// this.applyTextureTransform(texture, { offset, repeat, rotation })
|
|
386
|
+
// material.needsUpdate = true
|
|
387
|
+
// })
|
|
388
|
+
// }
|
|
326
389
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
390
|
+
// 应用高度贴图 (displacement map 或 bump map)
|
|
391
|
+
// if (heightMap) {
|
|
392
|
+
// // 优先使用 displacementMap,如果不支持则使用 bumpMap
|
|
393
|
+
// if (material.displacementMap !== undefined) {
|
|
394
|
+
// material.displacementMap = textureLoader.load(heightMap, (texture) => {
|
|
395
|
+
// this.applyTextureTransform(texture, { offset, repeat, rotation })
|
|
396
|
+
// material.displacementScale = 0.1 // 可以根据需要调整
|
|
397
|
+
// material.needsUpdate = true
|
|
398
|
+
// })
|
|
399
|
+
// }
|
|
400
|
+
// else if (material.bumpMap !== undefined) {
|
|
401
|
+
// material.bumpMap = textureLoader.load(heightMap, (texture) => {
|
|
402
|
+
// this.applyTextureTransform(texture, { offset, repeat, rotation })
|
|
403
|
+
// material.bumpScale = 0.1 // 可以根据需要调整
|
|
404
|
+
// material.needsUpdate = true
|
|
405
|
+
// })
|
|
406
|
+
// }
|
|
407
|
+
// }
|
|
330
408
|
|
|
331
|
-
|
|
409
|
+
// 应用反射贴图 (environment map)
|
|
410
|
+
// if (reflectionMap) {
|
|
411
|
+
// // 如果是环境贴图
|
|
412
|
+
// if (material.envMap !== undefined) {
|
|
413
|
+
// // 这里假设是立方体贴图,实际使用时可能需要 CubeTextureLoader
|
|
414
|
+
// material.envMap = textureLoader.load(reflectionMap, (texture) => {
|
|
415
|
+
// material.envMapIntensity = 1.0 // 可以根据需要调整
|
|
416
|
+
// material.needsUpdate = true
|
|
417
|
+
// })
|
|
418
|
+
// }
|
|
419
|
+
// // 或者作为金属度贴图
|
|
420
|
+
// else if (material.metalnessMap !== undefined) {
|
|
421
|
+
// material.metalnessMap = textureLoader.load(reflectionMap, (texture) => {
|
|
422
|
+
// this.applyTextureTransform(texture, { offset, repeat, rotation })
|
|
423
|
+
// material.needsUpdate = true
|
|
424
|
+
// })
|
|
425
|
+
// }
|
|
426
|
+
// }
|
|
427
|
+
case 28:
|
|
428
|
+
case "end":
|
|
429
|
+
return _context6.stop();
|
|
430
|
+
}
|
|
431
|
+
}, _callee5, this);
|
|
432
|
+
}));
|
|
433
|
+
function applyMaterialOptions(_x10, _x11) {
|
|
434
|
+
return _applyMaterialOptions.apply(this, arguments);
|
|
435
|
+
}
|
|
436
|
+
return applyMaterialOptions;
|
|
437
|
+
}() // 辅助方法:应用纹理变换
|
|
332
438
|
}, {
|
|
333
439
|
key: "applyTextureTransform",
|
|
334
440
|
value: function applyTextureTransform(texture, _ref3) {
|