@galacean/engine-loader 1.0.0-alpha.6 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.js +1278 -1637
- package/dist/main.js.map +1 -1
- package/dist/miniprogram.js +1299 -1658
- package/dist/module.js +1280 -1624
- package/dist/module.js.map +1 -1
- package/package.json +5 -5
- package/types/AnimationClipLoader.d.ts +0 -1
- package/types/GLTFLoader.d.ts +4 -7
- package/types/gltf/GLTFResource.d.ts +11 -7
- package/types/gltf/GLTFUtil.d.ts +8 -8
- package/types/gltf/extensions/KHR_materials_variants.d.ts +1 -6
- package/types/gltf/extensions/index.d.ts +2 -5
- package/types/index.d.ts +2 -2
- package/types/resource-deserialize/resources/prefab/PrefabDesign.d.ts +4 -4
- package/types/GLTFContentRestorer.d.ts +0 -85
- package/types/Texture2DContentRestorer.d.ts +0 -14
- package/types/TextureCubeContentRestorer.d.ts +0 -14
- package/types/gltf/GLTFPipeline.d.ts +0 -23
- package/types/gltf/GLTFSchema.d.ts +0 -816
- package/types/gltf/extensions/GLTFExtensionParser.d.ts +0 -52
- package/types/gltf/extensions/GLTFExtensionSchema.d.ts +0 -149
- package/types/gltf/extensions/OASIS_animation_event.d.ts +0 -1
- package/types/gltf/extensions/OASIS_materials_remap.d.ts +0 -1
- package/types/gltf/index.d.ts +0 -6
- package/types/gltf/parser/GLTFAnimationParser.d.ts +0 -12
- package/types/gltf/parser/GLTFBufferParser.d.ts +0 -7
- package/types/gltf/parser/GLTFEntityParser.d.ts +0 -9
- package/types/gltf/parser/GLTFMaterialParser.d.ts +0 -15
- package/types/gltf/parser/GLTFMeshParser.d.ts +0 -19
- package/types/gltf/parser/GLTFParser.d.ts +0 -63
- package/types/gltf/parser/GLTFParserContext.d.ts +0 -48
- package/types/gltf/parser/GLTFSceneParser.d.ts +0 -11
- package/types/gltf/parser/GLTFSkinParser.d.ts +0 -6
- package/types/gltf/parser/GLTFTextureParser.d.ts +0 -8
- package/types/gltf/parser/GLTFValidator.d.ts +0 -6
- package/types/gltf/parser/index.d.ts +0 -11
package/dist/miniprogram.js
CHANGED
|
@@ -5,57 +5,40 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var miniprogram = require('@galacean/engine-core/dist/miniprogram');
|
|
6
6
|
var engineMiniprogramAdapter = require('@galacean/engine-miniprogram-adapter');
|
|
7
7
|
var miniprogram$1 = require('@galacean/engine-math/dist/miniprogram');
|
|
8
|
-
var miniprogram$2 = require('@galacean/engine-
|
|
9
|
-
var miniprogram$3 = require('@galacean/engine-
|
|
8
|
+
var miniprogram$2 = require('@galacean/engine-draco/dist/miniprogram');
|
|
9
|
+
var miniprogram$3 = require('@galacean/engine-rhi-webgl/dist/miniprogram');
|
|
10
10
|
|
|
11
|
-
function
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
for (var key in source) {
|
|
17
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
18
|
-
target[key] = source[key];
|
|
11
|
+
function _extends() {
|
|
12
|
+
_extends = Object.assign || function assign(target) {
|
|
13
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
14
|
+
var source = arguments[i];
|
|
15
|
+
for (var key in source) if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
|
|
19
16
|
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return target;
|
|
24
|
-
};
|
|
25
17
|
|
|
26
|
-
|
|
27
|
-
}
|
|
18
|
+
return target;
|
|
19
|
+
};
|
|
28
20
|
|
|
29
|
-
|
|
30
|
-
return extends_.apply(this, arguments);
|
|
21
|
+
return _extends.apply(this, arguments);
|
|
31
22
|
}
|
|
32
23
|
|
|
33
|
-
function
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return o;
|
|
37
|
-
};
|
|
24
|
+
function _set_prototype_of(o, p) {
|
|
25
|
+
_set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
|
26
|
+
o.__proto__ = p;
|
|
38
27
|
|
|
39
|
-
|
|
40
|
-
}
|
|
28
|
+
return o;
|
|
29
|
+
};
|
|
41
30
|
|
|
42
|
-
|
|
43
|
-
return setPrototypeOf(o, p);
|
|
31
|
+
return _set_prototype_of(o, p);
|
|
44
32
|
}
|
|
45
33
|
|
|
46
34
|
function _inherits(subClass, superClass) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
52
|
-
constructor: {
|
|
53
|
-
value: subClass,
|
|
54
|
-
writable: true,
|
|
55
|
-
configurable: true
|
|
35
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
36
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
56
37
|
}
|
|
57
|
-
|
|
58
|
-
|
|
38
|
+
|
|
39
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } });
|
|
40
|
+
|
|
41
|
+
if (superClass) _set_prototype_of(subClass, superClass);
|
|
59
42
|
}
|
|
60
43
|
|
|
61
44
|
/******************************************************************************
|
|
@@ -108,10 +91,10 @@ function __generator(thisArg, body) {
|
|
|
108
91
|
}
|
|
109
92
|
}
|
|
110
93
|
|
|
111
|
-
var AnimatorControllerLoader = /*#__PURE__*/ function(
|
|
112
|
-
_inherits(AnimatorControllerLoader,
|
|
94
|
+
var AnimatorControllerLoader = /*#__PURE__*/ function(Loader) {
|
|
95
|
+
_inherits(AnimatorControllerLoader, Loader);
|
|
113
96
|
function AnimatorControllerLoader() {
|
|
114
|
-
return
|
|
97
|
+
return Loader.apply(this, arguments);
|
|
115
98
|
}
|
|
116
99
|
var _proto = AnimatorControllerLoader.prototype;
|
|
117
100
|
_proto.load = function load(item, resourceManager) {
|
|
@@ -132,16 +115,13 @@ var AnimatorControllerLoader = /*#__PURE__*/ function(Loader1) {
|
|
|
132
115
|
var states = stateMachineData.states;
|
|
133
116
|
var stateMachine = layer.stateMachine = new miniprogram.AnimatorStateMachine();
|
|
134
117
|
states.forEach(function(stateData, stateIndex) {
|
|
135
|
-
var name = stateData.name, speed = stateData.speed, wrapMode = stateData.wrapMode, clipStartNormalizedTime = stateData.clipStartNormalizedTime, clipEndNormalizedTime = stateData.clipEndNormalizedTime, isDefaultState = stateData.isDefaultState, clipData = stateData.clip
|
|
118
|
+
var name = stateData.name, speed = stateData.speed, wrapMode = stateData.wrapMode, clipStartNormalizedTime = stateData.clipStartNormalizedTime, clipEndNormalizedTime = stateData.clipEndNormalizedTime, isDefaultState = stateData.isDefaultState, clipData = stateData.clip;
|
|
136
119
|
var state = stateMachine.addState(name);
|
|
137
120
|
isDefaultState && (stateMachine.defaultState = state);
|
|
138
121
|
state.speed = speed;
|
|
139
122
|
state.wrapMode = wrapMode;
|
|
140
123
|
state.clipStartTime = clipStartNormalizedTime;
|
|
141
124
|
state.clipEndTime = clipEndNormalizedTime;
|
|
142
|
-
scripts == null ? void 0 : scripts.forEach(function(script) {
|
|
143
|
-
state.addStateMachineScript(miniprogram.Loader.getClass(script));
|
|
144
|
-
});
|
|
145
125
|
if (clipData) {
|
|
146
126
|
promises.push(new Promise(function(resolve) {
|
|
147
127
|
//@ts-ignore
|
|
@@ -274,39 +254,34 @@ EnvLoader = __decorate([
|
|
|
274
254
|
], EnvLoader);
|
|
275
255
|
|
|
276
256
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
resolve(value);
|
|
287
|
-
} else {
|
|
288
|
-
Promise.resolve(value).then(_next, _throw);
|
|
289
|
-
}
|
|
257
|
+
try {
|
|
258
|
+
var info = gen[key](arg);
|
|
259
|
+
var value = info.value;
|
|
260
|
+
} catch (error) {
|
|
261
|
+
reject(error);
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
if (info.done) resolve(value);
|
|
265
|
+
else Promise.resolve(value).then(_next, _throw);
|
|
290
266
|
}
|
|
267
|
+
function _async_to_generator(fn) {
|
|
268
|
+
return function() {
|
|
269
|
+
var self = this, args = arguments;
|
|
291
270
|
|
|
292
|
-
function
|
|
293
|
-
|
|
294
|
-
var self = this,
|
|
295
|
-
args = arguments;
|
|
296
|
-
return new Promise(function (resolve, reject) {
|
|
297
|
-
var gen = fn.apply(self, args);
|
|
271
|
+
return new Promise(function(resolve, reject) {
|
|
272
|
+
var gen = fn.apply(self, args);
|
|
298
273
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
274
|
+
function _next(value) {
|
|
275
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
276
|
+
}
|
|
302
277
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
278
|
+
function _throw(err) {
|
|
279
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
280
|
+
}
|
|
306
281
|
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
282
|
+
_next(undefined);
|
|
283
|
+
});
|
|
284
|
+
};
|
|
310
285
|
}
|
|
311
286
|
|
|
312
287
|
var FontLoader = /*#__PURE__*/ function(Loader) {
|
|
@@ -339,7 +314,7 @@ var FontLoader = /*#__PURE__*/ function(Loader) {
|
|
|
339
314
|
});
|
|
340
315
|
};
|
|
341
316
|
_proto._registerFont = function _registerFont(fontName, fontUrl) {
|
|
342
|
-
return
|
|
317
|
+
return _async_to_generator(function() {
|
|
343
318
|
var fontFace;
|
|
344
319
|
return __generator(this, function(_state) {
|
|
345
320
|
switch(_state.label){
|
|
@@ -367,192 +342,52 @@ FontLoader = __decorate([
|
|
|
367
342
|
], false)
|
|
368
343
|
], FontLoader);
|
|
369
344
|
|
|
370
|
-
function _arrayLikeToArray(arr, len) {
|
|
371
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
372
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
373
|
-
return arr2;
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
function _unsupportedIterableToArray(o, minLen) {
|
|
377
|
-
if (!o) return;
|
|
378
|
-
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
379
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
380
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
381
|
-
if (n === "Map" || n === "Set") return Array.from(n);
|
|
382
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
|
|
383
|
-
return _arrayLikeToArray(o, minLen);
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
function _createForOfIteratorHelperLoose(o, allowArrayLike) {
|
|
387
|
-
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
388
|
-
if (it) return (it = it.call(o)).next.bind(it);
|
|
389
|
-
// Fallback for engines without symbol support
|
|
390
|
-
if (
|
|
391
|
-
Array.isArray(o) ||
|
|
392
|
-
(it = _unsupportedIterableToArray(o)) ||
|
|
393
|
-
(allowArrayLike && o && typeof o.length === "number")
|
|
394
|
-
) {
|
|
395
|
-
if (it) o = it;
|
|
396
|
-
var i = 0;
|
|
397
|
-
return function () {
|
|
398
|
-
if (i >= o.length) return { done: true };
|
|
399
|
-
return { done: false, value: o[i++] };
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
throw new TypeError("Invalid attempt to iterate non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
403
|
-
}
|
|
404
|
-
|
|
405
345
|
/**
|
|
406
346
|
* @internal
|
|
407
|
-
*/ var
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
347
|
+
*/ var ParserContext = /*#__PURE__*/ function() {
|
|
348
|
+
function ParserContext(url) {
|
|
349
|
+
this.hasSkinned = false;
|
|
350
|
+
/** chain asset promise */ this.chainPromises = [];
|
|
351
|
+
this.accessorBufferCache = {};
|
|
352
|
+
this.texturesPromiseInfo = new PromiseInfo();
|
|
353
|
+
this.materialsPromiseInfo = new PromiseInfo();
|
|
354
|
+
this.meshesPromiseInfo = new PromiseInfo();
|
|
355
|
+
this.animationClipsPromiseInfo = new PromiseInfo();
|
|
356
|
+
this.defaultSceneRootPromiseInfo = new PromiseInfo();
|
|
357
|
+
this.masterPromiseInfo = new PromiseInfo();
|
|
358
|
+
this.promiseMap = {};
|
|
359
|
+
var promiseMap = this.promiseMap;
|
|
360
|
+
promiseMap["" + url + "?q=textures"] = this._initPromiseInfo(this.texturesPromiseInfo);
|
|
361
|
+
promiseMap["" + url + "?q=materials"] = this._initPromiseInfo(this.materialsPromiseInfo);
|
|
362
|
+
promiseMap["" + url + "?q=meshes"] = this._initPromiseInfo(this.meshesPromiseInfo);
|
|
363
|
+
promiseMap["" + url + "?q=animations"] = this._initPromiseInfo(this.animationClipsPromiseInfo);
|
|
364
|
+
promiseMap["" + url + "?q=defaultSceneRoot"] = this._initPromiseInfo(this.defaultSceneRootPromiseInfo);
|
|
365
|
+
promiseMap["" + url] = this._initPromiseInfo(this.masterPromiseInfo);
|
|
417
366
|
}
|
|
418
|
-
var _proto =
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
return miniprogram.request(bufferRequestInfo.url, bufferRequestInfo.config);
|
|
426
|
-
})).then(function(buffers) {
|
|
427
|
-
// Buffer parse
|
|
428
|
-
if (_this.isGLB) {
|
|
429
|
-
var glbBufferSlice = _this.glbBufferSlices;
|
|
430
|
-
var bigBuffer = buffers[0];
|
|
431
|
-
var bufferCount = glbBufferSlice.length;
|
|
432
|
-
buffers.length = bufferCount;
|
|
433
|
-
for(var i = 0; i < bufferCount; i++){
|
|
434
|
-
var slice = glbBufferSlice[i];
|
|
435
|
-
buffers[i] = bigBuffer.slice(slice.x, slice.x + slice.y);
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
// Restore texture
|
|
439
|
-
miniprogram.AssetPromise.all(_this.bufferTextures.map(function(textureRestoreInfo) {
|
|
440
|
-
var bufferView = textureRestoreInfo.bufferView;
|
|
441
|
-
var buffer = buffers[bufferView.buffer];
|
|
442
|
-
var _bufferView_byteOffset;
|
|
443
|
-
var bufferData = new Uint8Array(buffer, (_bufferView_byteOffset = bufferView.byteOffset) != null ? _bufferView_byteOffset : 0, bufferView.byteLength);
|
|
444
|
-
return GLTFUtil.loadImageBuffer(bufferData, textureRestoreInfo.mimeType).then(function(image) {
|
|
445
|
-
textureRestoreInfo.texture.setImageSource(image);
|
|
446
|
-
textureRestoreInfo.texture.generateMipmaps();
|
|
447
|
-
});
|
|
448
|
-
})).then(function() {
|
|
449
|
-
// Restore mesh
|
|
450
|
-
for(var _iterator = _createForOfIteratorHelperLoose(_this.meshes), _step; !(_step = _iterator()).done;){
|
|
451
|
-
var meshInfo = _step.value;
|
|
452
|
-
var mesh = meshInfo.mesh;
|
|
453
|
-
for(var _iterator1 = _createForOfIteratorHelperLoose(meshInfo.vertexBuffers), _step1; !(_step1 = _iterator1()).done;){
|
|
454
|
-
var bufferRestoreInfo = _step1.value;
|
|
455
|
-
var vertexData = _this._getBufferData(buffers, bufferRestoreInfo.data);
|
|
456
|
-
bufferRestoreInfo.buffer.setData(vertexData);
|
|
457
|
-
}
|
|
458
|
-
if (meshInfo.indexBuffer) {
|
|
459
|
-
var indexData = _this._getBufferData(buffers, meshInfo.indexBuffer);
|
|
460
|
-
mesh.setIndices(indexData);
|
|
461
|
-
}
|
|
462
|
-
for(var _iterator2 = _createForOfIteratorHelperLoose(meshInfo.blendShapes), _step2; !(_step2 = _iterator2()).done;){
|
|
463
|
-
var restoreInfo = _step2.value;
|
|
464
|
-
var frame = restoreInfo.blendShape.frames[0];
|
|
465
|
-
var positionData = _this._getBufferData(buffers, restoreInfo.position);
|
|
466
|
-
frame.deltaPositions = GLTFUtil.floatBufferToVector3Array(positionData);
|
|
467
|
-
if (restoreInfo.normal) {
|
|
468
|
-
var normalData = _this._getBufferData(buffers, restoreInfo.normal);
|
|
469
|
-
frame.deltaNormals = GLTFUtil.floatBufferToVector3Array(normalData);
|
|
470
|
-
}
|
|
471
|
-
if (restoreInfo.tangent) {
|
|
472
|
-
var tangentData = _this._getBufferData(buffers, restoreInfo.tangent);
|
|
473
|
-
frame.deltaTangents = GLTFUtil.floatBufferToVector3Array(tangentData);
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
mesh.uploadData(true);
|
|
477
|
-
}
|
|
478
|
-
resolve(_this.resource);
|
|
479
|
-
}).catch(reject);
|
|
480
|
-
}).catch(reject);
|
|
367
|
+
var _proto = ParserContext.prototype;
|
|
368
|
+
_proto._initPromiseInfo = function _initPromiseInfo(promiseInfo) {
|
|
369
|
+
var promise = new miniprogram.AssetPromise(function(resolve, reject, setProgress, onCancel) {
|
|
370
|
+
promiseInfo.resolve = resolve;
|
|
371
|
+
promiseInfo.reject = reject;
|
|
372
|
+
promiseInfo.setProgress = setProgress;
|
|
373
|
+
promiseInfo.onCancel = onCancel;
|
|
481
374
|
});
|
|
375
|
+
promiseInfo.promise = promise;
|
|
376
|
+
return promise;
|
|
482
377
|
};
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
var buffer = buffers[main.bufferIndex];
|
|
486
|
-
var data = new main.TypedArray(buffer, main.byteOffset, main.length);
|
|
487
|
-
var sparseCount = restoreInfo.sparseCount;
|
|
488
|
-
if (sparseCount) {
|
|
489
|
-
var sparseIndex = restoreInfo.sparseIndices;
|
|
490
|
-
var sparseIndexBuffer = buffers[sparseIndex.bufferIndex];
|
|
491
|
-
var sparseIndexData = new sparseIndex.TypedArray(sparseIndexBuffer, sparseIndex.byteOffset, sparseIndex.length);
|
|
492
|
-
var sparseValue = restoreInfo.sparseValues;
|
|
493
|
-
var sparseValueBuffer = buffers[sparseValue.bufferIndex];
|
|
494
|
-
var sparseValueData = new sparseValue.TypedArray(sparseValueBuffer, sparseValue.byteOffset, sparseValue.length);
|
|
495
|
-
var typeSize = restoreInfo.typeSize;
|
|
496
|
-
for(var i = 0; i < sparseCount; i++){
|
|
497
|
-
var replaceIndex = sparseIndexData[i];
|
|
498
|
-
for(var j = 0; j < typeSize; j++){
|
|
499
|
-
data[replaceIndex * typeSize + j] = sparseValueData[i * typeSize + j];
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
return data;
|
|
504
|
-
};
|
|
505
|
-
return GLTFContentRestorer;
|
|
506
|
-
}(miniprogram.ContentRestorer);
|
|
507
|
-
/**
|
|
508
|
-
* @internal
|
|
509
|
-
*/ var BufferRequestInfo = function BufferRequestInfo(url, config) {
|
|
510
|
-
this.url = url;
|
|
511
|
-
this.config = config;
|
|
512
|
-
};
|
|
513
|
-
/**
|
|
514
|
-
* @internal
|
|
515
|
-
*/ var BufferTextureRestoreInfo = function BufferTextureRestoreInfo(texture, bufferView, mimeType) {
|
|
516
|
-
this.texture = texture;
|
|
517
|
-
this.bufferView = bufferView;
|
|
518
|
-
this.mimeType = mimeType;
|
|
519
|
-
};
|
|
520
|
-
/**
|
|
521
|
-
* @internal
|
|
522
|
-
*/ var ModelMeshRestoreInfo = function ModelMeshRestoreInfo() {
|
|
523
|
-
this.vertexBuffers = [];
|
|
524
|
-
this.blendShapes = [];
|
|
525
|
-
};
|
|
378
|
+
return ParserContext;
|
|
379
|
+
}();
|
|
526
380
|
/**
|
|
527
381
|
* @internal
|
|
528
|
-
*/ var
|
|
529
|
-
this.buffer = buffer;
|
|
382
|
+
*/ var BufferInfo = function BufferInfo(data, interleaved, stride) {
|
|
530
383
|
this.data = data;
|
|
384
|
+
this.interleaved = interleaved;
|
|
385
|
+
this.stride = stride;
|
|
386
|
+
this.vertexBindingInfos = {};
|
|
531
387
|
};
|
|
532
388
|
/**
|
|
533
389
|
* @internal
|
|
534
|
-
*/ var
|
|
535
|
-
this.main = main;
|
|
536
|
-
this.typeSize = typeSize;
|
|
537
|
-
this.sparseCount = sparseCount;
|
|
538
|
-
this.sparseIndices = sparseIndices;
|
|
539
|
-
this.sparseValues = sparseValues;
|
|
540
|
-
};
|
|
541
|
-
/**
|
|
542
|
-
* @internal
|
|
543
|
-
*/ var RestoreDataAccessor = function RestoreDataAccessor(bufferIndex, TypedArray, byteOffset, length) {
|
|
544
|
-
this.bufferIndex = bufferIndex;
|
|
545
|
-
this.TypedArray = TypedArray;
|
|
546
|
-
this.byteOffset = byteOffset;
|
|
547
|
-
this.length = length;
|
|
548
|
-
};
|
|
549
|
-
/**
|
|
550
|
-
* @internal
|
|
551
|
-
*/ var BlendShapeRestoreInfo = function BlendShapeRestoreInfo(blendShape, position, normal, tangent) {
|
|
552
|
-
this.blendShape = blendShape;
|
|
553
|
-
this.position = position;
|
|
554
|
-
this.normal = normal;
|
|
555
|
-
this.tangent = tangent;
|
|
390
|
+
*/ var PromiseInfo = function PromiseInfo() {
|
|
556
391
|
};
|
|
557
392
|
|
|
558
393
|
/**
|
|
@@ -702,54 +537,6 @@ var TextureWrapMode;
|
|
|
702
537
|
*/ "REPEAT"] = 10497] = "REPEAT";
|
|
703
538
|
})(TextureWrapMode || (TextureWrapMode = {}));
|
|
704
539
|
|
|
705
|
-
/**
|
|
706
|
-
* @internal
|
|
707
|
-
*/ var GLTFParserContext = /*#__PURE__*/ function() {
|
|
708
|
-
function GLTFParserContext(url) {
|
|
709
|
-
this.hasSkinned = false;
|
|
710
|
-
this.chainPromises = [];
|
|
711
|
-
this.accessorBufferCache = {};
|
|
712
|
-
this.texturesPromiseInfo = new PromiseInfo();
|
|
713
|
-
this.materialsPromiseInfo = new PromiseInfo();
|
|
714
|
-
this.meshesPromiseInfo = new PromiseInfo();
|
|
715
|
-
this.animationClipsPromiseInfo = new PromiseInfo();
|
|
716
|
-
this.defaultSceneRootPromiseInfo = new PromiseInfo();
|
|
717
|
-
this.masterPromiseInfo = new PromiseInfo();
|
|
718
|
-
this.promiseMap = {};
|
|
719
|
-
var promiseMap = this.promiseMap;
|
|
720
|
-
promiseMap["" + url + "?q=textures"] = this._initPromiseInfo(this.texturesPromiseInfo);
|
|
721
|
-
promiseMap["" + url + "?q=materials"] = this._initPromiseInfo(this.materialsPromiseInfo);
|
|
722
|
-
promiseMap["" + url + "?q=meshes"] = this._initPromiseInfo(this.meshesPromiseInfo);
|
|
723
|
-
promiseMap["" + url + "?q=animations"] = this._initPromiseInfo(this.animationClipsPromiseInfo);
|
|
724
|
-
promiseMap["" + url + "?q=defaultSceneRoot"] = this._initPromiseInfo(this.defaultSceneRootPromiseInfo);
|
|
725
|
-
promiseMap["" + url] = this._initPromiseInfo(this.masterPromiseInfo);
|
|
726
|
-
}
|
|
727
|
-
var _proto = GLTFParserContext.prototype;
|
|
728
|
-
_proto._initPromiseInfo = function _initPromiseInfo(promiseInfo) {
|
|
729
|
-
var promise = new miniprogram.AssetPromise(function(resolve, reject, setProgress, onCancel) {
|
|
730
|
-
promiseInfo.resolve = resolve;
|
|
731
|
-
promiseInfo.reject = reject;
|
|
732
|
-
promiseInfo.setProgress = setProgress;
|
|
733
|
-
promiseInfo.onCancel = onCancel;
|
|
734
|
-
});
|
|
735
|
-
promiseInfo.promise = promise;
|
|
736
|
-
return promise;
|
|
737
|
-
};
|
|
738
|
-
return GLTFParserContext;
|
|
739
|
-
}();
|
|
740
|
-
/**
|
|
741
|
-
* @internal
|
|
742
|
-
*/ var BufferInfo = function BufferInfo(data, interleaved, stride) {
|
|
743
|
-
this.data = data;
|
|
744
|
-
this.interleaved = interleaved;
|
|
745
|
-
this.stride = stride;
|
|
746
|
-
this.vertexBindingInfos = {};
|
|
747
|
-
};
|
|
748
|
-
/**
|
|
749
|
-
* @internal
|
|
750
|
-
*/ var PromiseInfo = function PromiseInfo() {
|
|
751
|
-
};
|
|
752
|
-
|
|
753
540
|
/**
|
|
754
541
|
* @internal
|
|
755
542
|
*/ var GLTFUtil = /*#__PURE__*/ function() {
|
|
@@ -858,18 +645,18 @@ var TextureWrapMode;
|
|
|
858
645
|
throw new Error("Galacean.GLTFLoader: Unsupported normalized accessor component type.");
|
|
859
646
|
}
|
|
860
647
|
};
|
|
861
|
-
GLTFUtil.getAccessorBuffer = function getAccessorBuffer(context,
|
|
648
|
+
GLTFUtil.getAccessorBuffer = function getAccessorBuffer(context, gltf, accessor) {
|
|
862
649
|
var buffers = context.buffers;
|
|
650
|
+
var bufferViews = gltf.bufferViews;
|
|
863
651
|
var componentType = accessor.componentType;
|
|
864
652
|
var bufferView = bufferViews[accessor.bufferView];
|
|
865
|
-
var
|
|
866
|
-
var buffer = buffers[bufferIndex];
|
|
653
|
+
var buffer = buffers[bufferView.buffer];
|
|
867
654
|
var bufferByteOffset = bufferView.byteOffset || 0;
|
|
868
655
|
var byteOffset = accessor.byteOffset || 0;
|
|
869
656
|
var TypedArray = GLTFUtil.getComponentType(componentType);
|
|
870
|
-
var
|
|
657
|
+
var dataElmentSize = GLTFUtil.getAccessorTypeSize(accessor.type);
|
|
871
658
|
var dataElementBytes = TypedArray.BYTES_PER_ELEMENT;
|
|
872
|
-
var elementStride =
|
|
659
|
+
var elementStride = dataElmentSize * dataElementBytes;
|
|
873
660
|
var accessorCount = accessor.count;
|
|
874
661
|
var bufferStride = bufferView.byteStride;
|
|
875
662
|
var bufferInfo;
|
|
@@ -884,25 +671,24 @@ var TextureWrapMode;
|
|
|
884
671
|
var count = accessorCount * (bufferStride / dataElementBytes);
|
|
885
672
|
var data = new TypedArray(buffer, offset, count);
|
|
886
673
|
accessorBufferCache[bufferCacheKey] = bufferInfo = new BufferInfo(data, true, bufferStride);
|
|
887
|
-
bufferInfo.restoreInfo = new BufferDataRestoreInfo(new RestoreDataAccessor(bufferIndex, TypedArray, offset, count));
|
|
888
674
|
}
|
|
889
675
|
} else {
|
|
890
676
|
var offset1 = bufferByteOffset + byteOffset;
|
|
891
|
-
var count1 = accessorCount *
|
|
677
|
+
var count1 = accessorCount * dataElmentSize;
|
|
892
678
|
var data1 = new TypedArray(buffer, offset1, count1);
|
|
893
679
|
bufferInfo = new BufferInfo(data1, false, elementStride);
|
|
894
|
-
bufferInfo.restoreInfo = new BufferDataRestoreInfo(new RestoreDataAccessor(bufferIndex, TypedArray, offset1, count1));
|
|
895
680
|
}
|
|
896
681
|
if (accessor.sparse) {
|
|
897
|
-
GLTFUtil.processingSparseData(
|
|
682
|
+
var data2 = GLTFUtil.processingSparseData(gltf, accessor, buffers, bufferInfo.data);
|
|
683
|
+
bufferInfo = new BufferInfo(data2, false, bufferInfo.stride);
|
|
898
684
|
}
|
|
899
685
|
return bufferInfo;
|
|
900
686
|
};
|
|
901
687
|
/**
|
|
902
688
|
* @deprecated
|
|
903
689
|
* Get accessor data.
|
|
904
|
-
*/ GLTFUtil.getAccessorData = function getAccessorData(
|
|
905
|
-
var bufferViews =
|
|
690
|
+
*/ GLTFUtil.getAccessorData = function getAccessorData(gltf, accessor, buffers) {
|
|
691
|
+
var bufferViews = gltf.bufferViews;
|
|
906
692
|
var bufferView = bufferViews[accessor.bufferView];
|
|
907
693
|
var arrayBuffer = buffers[bufferView.buffer];
|
|
908
694
|
var accessorByteOffset = accessor.hasOwnProperty("byteOffset") ? accessor.byteOffset : 0;
|
|
@@ -952,46 +738,38 @@ var TextureWrapMode;
|
|
|
952
738
|
return typedArray;
|
|
953
739
|
};
|
|
954
740
|
GLTFUtil.getBufferViewData = function getBufferViewData(bufferView, buffers) {
|
|
955
|
-
var _bufferView_byteOffset = bufferView.byteOffset, byteOffset = _bufferView_byteOffset === void 0 ? 0 : _bufferView_byteOffset;
|
|
956
|
-
var arrayBuffer = buffers[
|
|
957
|
-
return arrayBuffer.slice(byteOffset, byteOffset +
|
|
741
|
+
var buffer = bufferView.buffer, _bufferView_byteOffset = bufferView.byteOffset, byteOffset = _bufferView_byteOffset === void 0 ? 0 : _bufferView_byteOffset, byteLength = bufferView.byteLength;
|
|
742
|
+
var arrayBuffer = buffers[buffer];
|
|
743
|
+
return arrayBuffer.slice(byteOffset, byteOffset + byteLength);
|
|
958
744
|
};
|
|
959
745
|
/**
|
|
960
746
|
* Get accessor data.
|
|
961
|
-
*/ GLTFUtil.processingSparseData = function processingSparseData(
|
|
962
|
-
var
|
|
747
|
+
*/ GLTFUtil.processingSparseData = function processingSparseData(gltf, accessor, buffers, originData) {
|
|
748
|
+
var bufferViews = gltf.bufferViews;
|
|
963
749
|
var accessorTypeSize = GLTFUtil.getAccessorTypeSize(accessor.type);
|
|
964
750
|
var TypedArray = GLTFUtil.getComponentType(accessor.componentType);
|
|
965
|
-
var data =
|
|
751
|
+
var data = originData.slice();
|
|
966
752
|
var _accessor_sparse = accessor.sparse, count = _accessor_sparse.count, indices = _accessor_sparse.indices, values = _accessor_sparse.values;
|
|
967
753
|
var indicesBufferView = bufferViews[indices.bufferView];
|
|
968
754
|
var valuesBufferView = bufferViews[values.bufferView];
|
|
969
|
-
var
|
|
970
|
-
var
|
|
971
|
-
var indicesArrayBuffer = buffers[indicesBufferIndex];
|
|
972
|
-
var valuesArrayBuffer = buffers[valuesBufferIndex];
|
|
755
|
+
var indicesArrayBuffer = buffers[indicesBufferView.buffer];
|
|
756
|
+
var valuesArrayBuffer = buffers[valuesBufferView.buffer];
|
|
973
757
|
var _indices_byteOffset, _indicesBufferView_byteOffset;
|
|
974
758
|
var indicesByteOffset = ((_indices_byteOffset = indices.byteOffset) != null ? _indices_byteOffset : 0) + ((_indicesBufferView_byteOffset = indicesBufferView.byteOffset) != null ? _indicesBufferView_byteOffset : 0);
|
|
975
759
|
var indicesByteLength = indicesBufferView.byteLength;
|
|
976
760
|
var _values_byteOffset, _valuesBufferView_byteOffset;
|
|
977
761
|
var valuesByteOffset = ((_values_byteOffset = values.byteOffset) != null ? _values_byteOffset : 0) + ((_valuesBufferView_byteOffset = valuesBufferView.byteOffset) != null ? _valuesBufferView_byteOffset : 0);
|
|
978
762
|
var valuesByteLength = valuesBufferView.byteLength;
|
|
979
|
-
restoreInfo.typeSize = accessorTypeSize;
|
|
980
|
-
restoreInfo.sparseCount = count;
|
|
981
763
|
var IndexTypeArray = GLTFUtil.getComponentType(indices.componentType);
|
|
982
|
-
var
|
|
983
|
-
var
|
|
984
|
-
restoreInfo.sparseIndices = new RestoreDataAccessor(indicesBufferIndex, IndexTypeArray, indicesByteOffset, indexLength);
|
|
985
|
-
var valueLength = valuesByteLength / TypedArray.BYTES_PER_ELEMENT;
|
|
986
|
-
var valuesArray = new TypedArray(valuesArrayBuffer, valuesByteOffset, valueLength);
|
|
987
|
-
restoreInfo.sparseValues = new RestoreDataAccessor(valuesBufferIndex, TypedArray, valuesByteOffset, valueLength);
|
|
764
|
+
var indicesArray = new IndexTypeArray(indicesArrayBuffer, indicesByteOffset, indicesByteLength / IndexTypeArray.BYTES_PER_ELEMENT);
|
|
765
|
+
var valuesArray = new TypedArray(valuesArrayBuffer, valuesByteOffset, valuesByteLength / TypedArray.BYTES_PER_ELEMENT);
|
|
988
766
|
for(var i = 0; i < count; i++){
|
|
989
767
|
var replaceIndex = indicesArray[i];
|
|
990
768
|
for(var j = 0; j < accessorTypeSize; j++){
|
|
991
769
|
data[replaceIndex * accessorTypeSize + j] = valuesArray[i * accessorTypeSize + j];
|
|
992
770
|
}
|
|
993
771
|
}
|
|
994
|
-
|
|
772
|
+
return data;
|
|
995
773
|
};
|
|
996
774
|
GLTFUtil.getIndexFormat = function getIndexFormat(type) {
|
|
997
775
|
switch(type){
|
|
@@ -1089,7 +867,7 @@ var TextureWrapMode;
|
|
|
1089
867
|
};
|
|
1090
868
|
/**
|
|
1091
869
|
* Parse the glb format.
|
|
1092
|
-
*/ GLTFUtil.parseGLB = function parseGLB(
|
|
870
|
+
*/ GLTFUtil.parseGLB = function parseGLB(glb) {
|
|
1093
871
|
var UINT32_LENGTH = 4;
|
|
1094
872
|
var GLB_HEADER_MAGIC = 0x46546c67; // 'glTF'
|
|
1095
873
|
var GLB_HEADER_LENGTH = 12;
|
|
@@ -1117,11 +895,10 @@ var TextureWrapMode;
|
|
|
1117
895
|
return null;
|
|
1118
896
|
}
|
|
1119
897
|
var glTFData = new Uint8Array(glb, GLB_HEADER_LENGTH + 2 * UINT32_LENGTH, chunkLength);
|
|
1120
|
-
var
|
|
898
|
+
var gltf = JSON.parse(GLTFUtil.decodeText(glTFData));
|
|
1121
899
|
// read all buffers
|
|
1122
900
|
var buffers = [];
|
|
1123
901
|
var byteOffset = GLB_HEADER_LENGTH + 2 * UINT32_LENGTH + chunkLength;
|
|
1124
|
-
var restoreGLBBufferSlice = context.contentRestorer.glbBufferSlices;
|
|
1125
902
|
while(byteOffset < header.length){
|
|
1126
903
|
chunkLength = dataView.getUint32(byteOffset, true);
|
|
1127
904
|
chunkType = dataView.getUint32(byteOffset + UINT32_LENGTH, true);
|
|
@@ -1132,11 +909,10 @@ var TextureWrapMode;
|
|
|
1132
909
|
var currentOffset = byteOffset + 2 * UINT32_LENGTH;
|
|
1133
910
|
var buffer = glb.slice(currentOffset, currentOffset + chunkLength);
|
|
1134
911
|
buffers.push(buffer);
|
|
1135
|
-
restoreGLBBufferSlice.push(new miniprogram$1.Vector2(currentOffset, chunkLength));
|
|
1136
912
|
byteOffset += chunkLength + 2 * UINT32_LENGTH;
|
|
1137
913
|
}
|
|
1138
914
|
return {
|
|
1139
|
-
|
|
915
|
+
gltf: gltf,
|
|
1140
916
|
buffers: buffers
|
|
1141
917
|
};
|
|
1142
918
|
};
|
|
@@ -1151,342 +927,633 @@ var TextureWrapMode;
|
|
|
1151
927
|
return GLTFUtil;
|
|
1152
928
|
}();
|
|
1153
929
|
|
|
1154
|
-
function
|
|
1155
|
-
|
|
930
|
+
function _array_like_to_array(arr, len) {
|
|
931
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
932
|
+
|
|
933
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
934
|
+
|
|
935
|
+
return arr2;
|
|
1156
936
|
}
|
|
1157
937
|
|
|
1158
|
-
function
|
|
1159
|
-
|
|
938
|
+
function _array_without_holes(arr) {
|
|
939
|
+
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
1160
940
|
}
|
|
1161
941
|
|
|
1162
|
-
function
|
|
1163
|
-
|
|
942
|
+
function _iterable_to_array(iter) {
|
|
943
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) {
|
|
944
|
+
return Array.from(iter);
|
|
945
|
+
}
|
|
1164
946
|
}
|
|
1165
947
|
|
|
1166
|
-
function
|
|
1167
|
-
|
|
948
|
+
function _non_iterable_spread() {
|
|
949
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
1168
950
|
}
|
|
1169
951
|
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
var
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
for(var _len = arguments.length, extra = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++){
|
|
1189
|
-
extra[_key - 3] = arguments[_key];
|
|
1190
|
-
}
|
|
1191
|
-
throw "Not implemented.";
|
|
1192
|
-
};
|
|
1193
|
-
/**
|
|
1194
|
-
* Additive parse to the resource.
|
|
1195
|
-
* @param context - The parser context
|
|
1196
|
-
* @param parseResource - The parsed resource
|
|
1197
|
-
* @param extensionSchema - The extension schema
|
|
1198
|
-
* @param extensionOwnerSchema - The extension owner schema
|
|
1199
|
-
* @returns The void or promise
|
|
1200
|
-
*/ _proto.additiveParse = function additiveParse(context, parseResource, extensionSchema, extensionOwnerSchema) {
|
|
952
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
953
|
+
if (!o) return;
|
|
954
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
955
|
+
|
|
956
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
957
|
+
|
|
958
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
959
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
960
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
function _to_consumable_array(arr) {
|
|
964
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
var Parser = /*#__PURE__*/ function() {
|
|
968
|
+
function Parser() {}
|
|
969
|
+
Parser.parseEngineResource = function parseEngineResource(extensionName, extensionSchema, parseResource, context) {
|
|
1201
970
|
for(var _len = arguments.length, extra = new Array(_len > 4 ? _len - 4 : 0), _key = 4; _key < _len; _key++){
|
|
1202
971
|
extra[_key - 4] = arguments[_key];
|
|
1203
972
|
}
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
* If this method is registered, the default pipeline processing will be ignored.
|
|
1215
|
-
*/ "CreateAndParse"] = 0] = "CreateAndParse";
|
|
1216
|
-
GLTFExtensionMode[GLTFExtensionMode[/** Additive parse mode. */ "AdditiveParse"] = 1] = "AdditiveParse";
|
|
1217
|
-
})(exports.GLTFExtensionMode || (exports.GLTFExtensionMode = {}));
|
|
1218
|
-
|
|
1219
|
-
/**
|
|
1220
|
-
* Base class of glTF parser.
|
|
1221
|
-
*/ var GLTFParser = /*#__PURE__*/ function() {
|
|
1222
|
-
function GLTFParser() {}
|
|
1223
|
-
/**
|
|
1224
|
-
* Execute all parses of extension to initialize plugin.
|
|
1225
|
-
* @remarks Some plugins require initialization.
|
|
1226
|
-
* @returns The void or promise
|
|
1227
|
-
*/ GLTFParser.executeExtensionsInitialize = function executeExtensionsInitialize(extensionName) {
|
|
1228
|
-
var parsers = GLTFParser._extensionParsers[extensionName];
|
|
1229
|
-
var length = parsers == null ? void 0 : parsers.length;
|
|
1230
|
-
if (length) {
|
|
1231
|
-
return parsers[length - 1].initialize();
|
|
973
|
+
var parsers = Parser._extensionParsers[extensionName];
|
|
974
|
+
if (parsers == null ? void 0 : parsers.length) {
|
|
975
|
+
for(var i = 0; i < parsers.length; i++){
|
|
976
|
+
var _parsers_i;
|
|
977
|
+
(_parsers_i = parsers[i]).parseEngineResource.apply(_parsers_i, [
|
|
978
|
+
extensionSchema,
|
|
979
|
+
parseResource,
|
|
980
|
+
context
|
|
981
|
+
].concat(_to_consumable_array(extra)));
|
|
982
|
+
}
|
|
1232
983
|
}
|
|
1233
984
|
};
|
|
1234
|
-
|
|
1235
|
-
* Execute all parses of extension to create resource.
|
|
1236
|
-
* @param extensions - Related extensions field
|
|
1237
|
-
* @param context - The parser context
|
|
1238
|
-
* @param ownerSchema - The extension owner schema
|
|
1239
|
-
* @param extra - Extra params
|
|
1240
|
-
* @returns
|
|
1241
|
-
*/ GLTFParser.executeExtensionsCreateAndParse = function executeExtensionsCreateAndParse(extensions, context, ownerSchema) {
|
|
1242
|
-
if (extensions === void 0) extensions = {};
|
|
985
|
+
Parser.createEngineResource = function createEngineResource(extensionName, extensionSchema, context) {
|
|
1243
986
|
for(var _len = arguments.length, extra = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++){
|
|
1244
987
|
extra[_key - 3] = arguments[_key];
|
|
1245
988
|
}
|
|
1246
|
-
var
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
var extensionName = extensionArray[i];
|
|
1251
|
-
var extensionSchema = extensions[extensionName];
|
|
1252
|
-
resource = (_GLTFParser = GLTFParser)._createAndParse.apply(_GLTFParser, [
|
|
1253
|
-
extensionName,
|
|
1254
|
-
context,
|
|
1255
|
-
extensionSchema,
|
|
1256
|
-
ownerSchema
|
|
1257
|
-
].concat(_toConsumableArray(extra)));
|
|
1258
|
-
if (resource) {
|
|
1259
|
-
return resource;
|
|
1260
|
-
}
|
|
1261
|
-
}
|
|
1262
|
-
};
|
|
1263
|
-
/**
|
|
1264
|
-
* Execute all parses of extension to parse resource.
|
|
1265
|
-
* @param extensions - Related extensions field
|
|
1266
|
-
* @param context - The parser context
|
|
1267
|
-
* @param parseResource - The parsed resource
|
|
1268
|
-
* @param ownerSchema - The extension owner schema
|
|
1269
|
-
* @param extra - Extra params
|
|
1270
|
-
*/ GLTFParser.executeExtensionsAdditiveAndParse = function executeExtensionsAdditiveAndParse(extensions, context, parseResource, ownerSchema) {
|
|
1271
|
-
for(var _len = arguments.length, extra = new Array(_len > 4 ? _len - 4 : 0), _key = 4; _key < _len; _key++){
|
|
1272
|
-
extra[_key - 4] = arguments[_key];
|
|
1273
|
-
}
|
|
1274
|
-
for(var extensionName in extensions){
|
|
1275
|
-
var _GLTFParser;
|
|
1276
|
-
var extensionSchema = extensions[extensionName];
|
|
1277
|
-
(_GLTFParser = GLTFParser)._additiveParse.apply(_GLTFParser, [
|
|
1278
|
-
extensionName,
|
|
1279
|
-
context,
|
|
1280
|
-
parseResource,
|
|
989
|
+
var parsers = Parser._extensionParsers[extensionName];
|
|
990
|
+
if (parsers == null ? void 0 : parsers.length) {
|
|
991
|
+
var _parsers_;
|
|
992
|
+
return (_parsers_ = parsers[0]).createEngineResource.apply(_parsers_, [
|
|
1281
993
|
extensionSchema,
|
|
1282
|
-
|
|
1283
|
-
].concat(
|
|
994
|
+
context
|
|
995
|
+
].concat(_to_consumable_array(extra)));
|
|
1284
996
|
}
|
|
1285
997
|
};
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
* @returns Boolean
|
|
1290
|
-
*/ GLTFParser.hasExtensionParser = function hasExtensionParser(extensionName) {
|
|
1291
|
-
var _GLTFParser__extensionParsers_extensionName;
|
|
1292
|
-
return !!((_GLTFParser__extensionParsers_extensionName = GLTFParser._extensionParsers[extensionName]) == null ? void 0 : _GLTFParser__extensionParsers_extensionName.length);
|
|
998
|
+
Parser.hasExtensionParser = function hasExtensionParser(extensionName) {
|
|
999
|
+
var parsers = Parser._extensionParsers[extensionName];
|
|
1000
|
+
return !!(parsers == null ? void 0 : parsers.length);
|
|
1293
1001
|
};
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
*/ GLTFParser.getExtensionParser = function getExtensionParser(extensionName, mode) {
|
|
1300
|
-
var parsers = GLTFParser._extensionParsers[extensionName];
|
|
1301
|
-
var length = parsers == null ? void 0 : parsers.length;
|
|
1302
|
-
if (length) {
|
|
1303
|
-
// only use the last parser.
|
|
1304
|
-
for(var i = length - 1; i >= 0; --i){
|
|
1305
|
-
var currentParser = parsers[i];
|
|
1306
|
-
if (currentParser._mode === mode) {
|
|
1307
|
-
return currentParser;
|
|
1308
|
-
}
|
|
1002
|
+
Parser.initialize = function initialize(extensionName) {
|
|
1003
|
+
var parsers = Parser._extensionParsers[extensionName];
|
|
1004
|
+
if (parsers == null ? void 0 : parsers.length) {
|
|
1005
|
+
for(var i = 0; i < parsers.length; i++){
|
|
1006
|
+
parsers[i].initialize();
|
|
1309
1007
|
}
|
|
1310
1008
|
}
|
|
1311
1009
|
};
|
|
1312
1010
|
/**
|
|
1313
1011
|
* @internal
|
|
1314
|
-
*/
|
|
1315
|
-
if (!
|
|
1316
|
-
|
|
1317
|
-
}
|
|
1318
|
-
GLTFParser._extensionParsers[extensionName].push(extensionParser);
|
|
1319
|
-
};
|
|
1320
|
-
GLTFParser._createAndParse = function _createAndParse(extensionName, context, extensionSchema, ownerSchema) {
|
|
1321
|
-
for(var _len = arguments.length, extra = new Array(_len > 4 ? _len - 4 : 0), _key = 4; _key < _len; _key++){
|
|
1322
|
-
extra[_key - 4] = arguments[_key];
|
|
1323
|
-
}
|
|
1324
|
-
var parser = GLTFParser.getExtensionParser(extensionName, exports.GLTFExtensionMode.CreateAndParse);
|
|
1325
|
-
if (parser) {
|
|
1326
|
-
var _parser;
|
|
1327
|
-
return (_parser = parser).createAndParse.apply(_parser, [
|
|
1328
|
-
context,
|
|
1329
|
-
extensionSchema,
|
|
1330
|
-
ownerSchema
|
|
1331
|
-
].concat(_toConsumableArray(extra)));
|
|
1332
|
-
}
|
|
1333
|
-
};
|
|
1334
|
-
GLTFParser._additiveParse = function _additiveParse(extensionName, context, parseResource, extensionSchema, ownerSchema) {
|
|
1335
|
-
for(var _len = arguments.length, extra = new Array(_len > 5 ? _len - 5 : 0), _key = 5; _key < _len; _key++){
|
|
1336
|
-
extra[_key - 5] = arguments[_key];
|
|
1337
|
-
}
|
|
1338
|
-
var parser = GLTFParser.getExtensionParser(extensionName, exports.GLTFExtensionMode.AdditiveParse);
|
|
1339
|
-
if (parser) {
|
|
1340
|
-
var _parser;
|
|
1341
|
-
(_parser = parser).additiveParse.apply(_parser, [
|
|
1342
|
-
context,
|
|
1343
|
-
parseResource,
|
|
1344
|
-
extensionSchema,
|
|
1345
|
-
ownerSchema
|
|
1346
|
-
].concat(_toConsumableArray(extra)));
|
|
1012
|
+
*/ Parser._addExtensionParser = function _addExtensionParser(extensionName, extensionParser) {
|
|
1013
|
+
if (!Parser._extensionParsers[extensionName]) {
|
|
1014
|
+
Parser._extensionParsers[extensionName] = [];
|
|
1347
1015
|
}
|
|
1016
|
+
Parser._extensionParsers[extensionName].push(extensionParser);
|
|
1348
1017
|
};
|
|
1349
|
-
return
|
|
1018
|
+
return Parser;
|
|
1350
1019
|
}();
|
|
1351
|
-
|
|
1020
|
+
(function() {
|
|
1021
|
+
Parser._extensionParsers = {};
|
|
1022
|
+
})();
|
|
1352
1023
|
/**
|
|
1353
1024
|
* Declare ExtensionParser's decorator.
|
|
1354
1025
|
* @param extensionName - Extension name
|
|
1355
|
-
*/ function
|
|
1026
|
+
*/ function registerExtension(extensionName) {
|
|
1356
1027
|
return function(parser) {
|
|
1357
1028
|
var extensionParser = new parser();
|
|
1358
|
-
|
|
1359
|
-
GLTFParser._addExtensionParser(extensionName, extensionParser);
|
|
1029
|
+
Parser._addExtensionParser(extensionName, extensionParser);
|
|
1360
1030
|
};
|
|
1361
1031
|
}
|
|
1362
1032
|
|
|
1363
|
-
var
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
var glTF = context.glTF; context.buffers; var glTFResource = context.glTFResource;
|
|
1371
|
-
glTFResource.entities;
|
|
1372
|
-
var animations = glTF.animations; glTF.accessors; glTF.bufferViews;
|
|
1373
|
-
if (!animations) {
|
|
1374
|
-
return;
|
|
1033
|
+
var ExtensionParser = /*#__PURE__*/ function() {
|
|
1034
|
+
function ExtensionParser() {}
|
|
1035
|
+
var _proto = ExtensionParser.prototype;
|
|
1036
|
+
_proto.initialize = function initialize() {};
|
|
1037
|
+
_proto.parseEngineResource = function parseEngineResource(schema, parseResource, context) {
|
|
1038
|
+
for(var _len = arguments.length, extra = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++){
|
|
1039
|
+
extra[_key - 3] = arguments[_key];
|
|
1375
1040
|
}
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
var
|
|
1379
|
-
|
|
1380
|
-
for(var i = 0; i < animationClipCount; i++){
|
|
1381
|
-
var animationInfo = animations[i];
|
|
1382
|
-
var _animationInfo_name = animationInfo.name, name = _animationInfo_name === void 0 ? "AnimationClip" + i : _animationInfo_name;
|
|
1383
|
-
var animationClip = GLTFParser.executeExtensionsCreateAndParse(animationInfo.extensions, context, animationInfo);
|
|
1384
|
-
if (!animationClip) {
|
|
1385
|
-
animationClip = new miniprogram.AnimationClip(name);
|
|
1386
|
-
GLTFAnimationParser._parseStandardProperty(context, animationClip, animationInfo);
|
|
1387
|
-
}
|
|
1388
|
-
animationClipPromises.push(animationClip);
|
|
1041
|
+
};
|
|
1042
|
+
_proto.createEngineResource = function createEngineResource(schema, context) {
|
|
1043
|
+
for(var _len = arguments.length, extra = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++){
|
|
1044
|
+
extra[_key - 2] = arguments[_key];
|
|
1389
1045
|
}
|
|
1390
|
-
return
|
|
1391
|
-
glTFResource.animations = animationClips;
|
|
1392
|
-
for(var i = 0; i < glTF.animations.length; i++){
|
|
1393
|
-
var animationInfo = glTF.animations[i];
|
|
1394
|
-
GLTFParser.executeExtensionsAdditiveAndParse(animationInfo.extensions, context, animationClips[i], animationInfo);
|
|
1395
|
-
}
|
|
1396
|
-
animationClipsPromiseInfo.resolve(animationClips);
|
|
1397
|
-
return animationClipsPromiseInfo.promise;
|
|
1398
|
-
});
|
|
1046
|
+
return null;
|
|
1399
1047
|
};
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
var outputAccessor = accessors[gltfSampler.output];
|
|
1413
|
-
var input = GLTFUtil.getAccessorBuffer(context, bufferViews, inputAccessor).data;
|
|
1414
|
-
var output = GLTFUtil.getAccessorBuffer(context, bufferViews, outputAccessor).data;
|
|
1415
|
-
if (outputAccessor.normalized) {
|
|
1416
|
-
var scale = GLTFUtil.getNormalizedComponentScale(outputAccessor.componentType);
|
|
1417
|
-
var scaled = new Float32Array(output.length);
|
|
1418
|
-
for(var k = 0, v = output.length; k < v; k++){
|
|
1419
|
-
scaled[k] = output[k] * scale;
|
|
1420
|
-
}
|
|
1421
|
-
output = scaled;
|
|
1422
|
-
}
|
|
1423
|
-
var outputStride = output.length / input.length;
|
|
1424
|
-
var _gltfSampler_interpolation;
|
|
1425
|
-
var interpolation = (_gltfSampler_interpolation = gltfSampler.interpolation) != null ? _gltfSampler_interpolation : AnimationSamplerInterpolation.Linear;
|
|
1426
|
-
var samplerInterpolation = void 0;
|
|
1427
|
-
switch(interpolation){
|
|
1428
|
-
case AnimationSamplerInterpolation.CubicSpine:
|
|
1429
|
-
samplerInterpolation = miniprogram.InterpolationType.CubicSpine;
|
|
1430
|
-
break;
|
|
1431
|
-
case AnimationSamplerInterpolation.Step:
|
|
1432
|
-
samplerInterpolation = miniprogram.InterpolationType.Step;
|
|
1433
|
-
break;
|
|
1434
|
-
case AnimationSamplerInterpolation.Linear:
|
|
1435
|
-
samplerInterpolation = miniprogram.InterpolationType.Linear;
|
|
1436
|
-
break;
|
|
1437
|
-
}
|
|
1438
|
-
input[input.length - 1];
|
|
1439
|
-
sampleDataCollection.push({
|
|
1440
|
-
type: outputAccessor.type,
|
|
1441
|
-
interpolation: samplerInterpolation,
|
|
1442
|
-
input: input,
|
|
1443
|
-
output: output,
|
|
1444
|
-
outputSize: outputStride
|
|
1445
|
-
});
|
|
1048
|
+
return ExtensionParser;
|
|
1049
|
+
}();
|
|
1050
|
+
|
|
1051
|
+
var KHR_draco_mesh_compression = /*#__PURE__*/ function(ExtensionParser) {
|
|
1052
|
+
_inherits(KHR_draco_mesh_compression1, ExtensionParser);
|
|
1053
|
+
function KHR_draco_mesh_compression1() {
|
|
1054
|
+
return ExtensionParser.apply(this, arguments);
|
|
1055
|
+
}
|
|
1056
|
+
var _proto = KHR_draco_mesh_compression1.prototype;
|
|
1057
|
+
_proto.initialize = function initialize() {
|
|
1058
|
+
if (!KHR_draco_mesh_compression._decoder) {
|
|
1059
|
+
KHR_draco_mesh_compression._decoder = new miniprogram$2.DRACODecoder();
|
|
1446
1060
|
}
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
ComponentType = miniprogram.Transform;
|
|
1462
|
-
propertyName = "position";
|
|
1463
|
-
break;
|
|
1464
|
-
case AnimationChannelTargetPath.ROTATION:
|
|
1465
|
-
ComponentType = miniprogram.Transform;
|
|
1466
|
-
propertyName = "rotationQuaternion";
|
|
1467
|
-
break;
|
|
1468
|
-
case AnimationChannelTargetPath.SCALE:
|
|
1469
|
-
ComponentType = miniprogram.Transform;
|
|
1470
|
-
propertyName = "scale";
|
|
1471
|
-
break;
|
|
1472
|
-
case AnimationChannelTargetPath.WEIGHTS:
|
|
1473
|
-
ComponentType = miniprogram.SkinnedMeshRenderer;
|
|
1474
|
-
propertyName = "blendShapeWeights";
|
|
1475
|
-
break;
|
|
1061
|
+
};
|
|
1062
|
+
_proto.createEngineResource = function createEngineResource(schema, context, gltfPrimitive) {
|
|
1063
|
+
var gltf = context.gltf, buffers = context.buffers;
|
|
1064
|
+
var bufferViews = gltf.bufferViews, accessors = gltf.accessors;
|
|
1065
|
+
var bufferViewIndex = schema.bufferView, gltfAttributeMap = schema.attributes;
|
|
1066
|
+
var attributeMap = {};
|
|
1067
|
+
var attributeTypeMap = {};
|
|
1068
|
+
for(var attributeName in gltfAttributeMap){
|
|
1069
|
+
attributeMap[attributeName] = gltfAttributeMap[attributeName];
|
|
1070
|
+
}
|
|
1071
|
+
for(var attributeName1 in gltfPrimitive.attributes){
|
|
1072
|
+
if (gltfAttributeMap[attributeName1] !== undefined) {
|
|
1073
|
+
var accessorDef = accessors[gltfPrimitive.attributes[attributeName1]];
|
|
1074
|
+
attributeTypeMap[attributeName1] = GLTFUtil.getComponentType(accessorDef.componentType).name;
|
|
1476
1075
|
}
|
|
1477
|
-
var curve = this._addCurve(target.path, gltfChannel, sampleDataCollection);
|
|
1478
|
-
animationClip.addCurveBinding(relativePath, ComponentType, propertyName, curve);
|
|
1479
1076
|
}
|
|
1077
|
+
var indexAccessor = accessors[gltfPrimitive.indices];
|
|
1078
|
+
var indexType = GLTFUtil.getComponentType(indexAccessor.componentType).name;
|
|
1079
|
+
var taskConfig = {
|
|
1080
|
+
attributeIDs: attributeMap,
|
|
1081
|
+
attributeTypes: attributeTypeMap,
|
|
1082
|
+
useUniqueIDs: true,
|
|
1083
|
+
indexType: indexType
|
|
1084
|
+
};
|
|
1085
|
+
var buffer = GLTFUtil.getBufferViewData(bufferViews[bufferViewIndex], buffers);
|
|
1086
|
+
return KHR_draco_mesh_compression._decoder.decode(buffer, taskConfig).then(function(parsedGeometry) {
|
|
1087
|
+
return parsedGeometry;
|
|
1088
|
+
});
|
|
1480
1089
|
};
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1090
|
+
return KHR_draco_mesh_compression1;
|
|
1091
|
+
}(ExtensionParser);
|
|
1092
|
+
KHR_draco_mesh_compression = __decorate([
|
|
1093
|
+
registerExtension("KHR_draco_mesh_compression")
|
|
1094
|
+
], KHR_draco_mesh_compression);
|
|
1095
|
+
|
|
1096
|
+
function _instanceof(left, right) {
|
|
1097
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
1098
|
+
return !!right[Symbol.hasInstance](left);
|
|
1099
|
+
} else return left instanceof right;
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
var KHR_lights_punctual = /*#__PURE__*/ function(ExtensionParser) {
|
|
1103
|
+
_inherits(KHR_lights_punctual, ExtensionParser);
|
|
1104
|
+
function KHR_lights_punctual() {
|
|
1105
|
+
return ExtensionParser.apply(this, arguments);
|
|
1106
|
+
}
|
|
1107
|
+
var _proto = KHR_lights_punctual.prototype;
|
|
1108
|
+
_proto.parseEngineResource = function parseEngineResource(schema, entity, context) {
|
|
1109
|
+
var color = schema.color, _schema_intensity = schema.intensity, intensity = _schema_intensity === void 0 ? 1 : _schema_intensity, type = schema.type, range = schema.range, spot = schema.spot;
|
|
1110
|
+
var glTFResource = context.glTFResource;
|
|
1111
|
+
var light;
|
|
1112
|
+
if (type === "directional") {
|
|
1113
|
+
light = entity.addComponent(miniprogram.DirectLight);
|
|
1114
|
+
} else if (type === "point") {
|
|
1115
|
+
light = entity.addComponent(miniprogram.PointLight);
|
|
1116
|
+
} else if (type === "spot") {
|
|
1117
|
+
light = entity.addComponent(miniprogram.SpotLight);
|
|
1118
|
+
}
|
|
1119
|
+
if (color) {
|
|
1120
|
+
light.color.set(color[0], color[1], color[2], 1);
|
|
1121
|
+
}
|
|
1122
|
+
light.intensity = intensity;
|
|
1123
|
+
if (range && !_instanceof(light, miniprogram.DirectLight)) {
|
|
1124
|
+
light.distance = range;
|
|
1125
|
+
}
|
|
1126
|
+
if (spot && _instanceof(light, miniprogram.SpotLight)) {
|
|
1127
|
+
var _spot_innerConeAngle = spot.innerConeAngle, innerConeAngle = _spot_innerConeAngle === void 0 ? 0 : _spot_innerConeAngle, _spot_outerConeAngle = spot.outerConeAngle, outerConeAngle = _spot_outerConeAngle === void 0 ? Math.PI / 4 : _spot_outerConeAngle;
|
|
1128
|
+
light.angle = innerConeAngle;
|
|
1129
|
+
light.penumbra = outerConeAngle - innerConeAngle;
|
|
1130
|
+
}
|
|
1131
|
+
if (!glTFResource.lights) glTFResource.lights = [];
|
|
1132
|
+
glTFResource.lights.push(light);
|
|
1133
|
+
};
|
|
1134
|
+
return KHR_lights_punctual;
|
|
1135
|
+
}(ExtensionParser);
|
|
1136
|
+
KHR_lights_punctual = __decorate([
|
|
1137
|
+
registerExtension("KHR_lights_punctual")
|
|
1138
|
+
], KHR_lights_punctual);
|
|
1139
|
+
|
|
1140
|
+
var MaterialParser = /*#__PURE__*/ function(Parser1) {
|
|
1141
|
+
_inherits(MaterialParser, Parser1);
|
|
1142
|
+
function MaterialParser() {
|
|
1143
|
+
return Parser1.apply(this, arguments);
|
|
1144
|
+
}
|
|
1145
|
+
var _proto = MaterialParser.prototype;
|
|
1146
|
+
_proto.parse = function parse(context) {
|
|
1147
|
+
var gltf = context.gltf, glTFResource = context.glTFResource;
|
|
1148
|
+
var engine = glTFResource.engine, textures = glTFResource.textures;
|
|
1149
|
+
if (!gltf.materials) return;
|
|
1150
|
+
var materialsPromiseInfo = context.materialsPromiseInfo;
|
|
1151
|
+
var materials = [];
|
|
1152
|
+
for(var i = 0; i < gltf.materials.length; i++){
|
|
1153
|
+
var _gltf_materials_i = gltf.materials[i], _gltf_materials_i_extensions = _gltf_materials_i.extensions, extensions = _gltf_materials_i_extensions === void 0 ? {} : _gltf_materials_i_extensions, pbrMetallicRoughness = _gltf_materials_i.pbrMetallicRoughness, normalTexture = _gltf_materials_i.normalTexture, occlusionTexture = _gltf_materials_i.occlusionTexture, emissiveTexture = _gltf_materials_i.emissiveTexture, emissiveFactor = _gltf_materials_i.emissiveFactor, alphaMode = _gltf_materials_i.alphaMode, alphaCutoff = _gltf_materials_i.alphaCutoff, doubleSided = _gltf_materials_i.doubleSided, _gltf_materials_i_name = _gltf_materials_i.name, name = _gltf_materials_i_name === void 0 ? "" : _gltf_materials_i_name;
|
|
1154
|
+
var KHR_materials_unlit = extensions.KHR_materials_unlit, KHR_materials_pbrSpecularGlossiness = extensions.KHR_materials_pbrSpecularGlossiness, KHR_materials_clearcoat = extensions.KHR_materials_clearcoat, OASIS_materials_remap = extensions.OASIS_materials_remap;
|
|
1155
|
+
var material = null;
|
|
1156
|
+
if (KHR_materials_unlit) {
|
|
1157
|
+
material = Parser.createEngineResource("KHR_materials_unlit", KHR_materials_unlit, context);
|
|
1158
|
+
} else if (KHR_materials_pbrSpecularGlossiness) {
|
|
1159
|
+
material = Parser.createEngineResource("KHR_materials_pbrSpecularGlossiness", KHR_materials_pbrSpecularGlossiness, context);
|
|
1160
|
+
} else {
|
|
1161
|
+
material = new miniprogram.PBRMaterial(engine);
|
|
1162
|
+
}
|
|
1163
|
+
material.name = name;
|
|
1164
|
+
if (KHR_materials_clearcoat) {
|
|
1165
|
+
Parser.parseEngineResource("KHR_materials_clearcoat", KHR_materials_clearcoat, material, context);
|
|
1166
|
+
}
|
|
1167
|
+
if (pbrMetallicRoughness) {
|
|
1168
|
+
var baseColorFactor = pbrMetallicRoughness.baseColorFactor, baseColorTexture = pbrMetallicRoughness.baseColorTexture, metallicFactor = pbrMetallicRoughness.metallicFactor, roughnessFactor = pbrMetallicRoughness.roughnessFactor, metallicRoughnessTexture = pbrMetallicRoughness.metallicRoughnessTexture;
|
|
1169
|
+
if (baseColorFactor) {
|
|
1170
|
+
material.baseColor = new miniprogram$1.Color(miniprogram$1.Color.linearToGammaSpace(baseColorFactor[0]), miniprogram$1.Color.linearToGammaSpace(baseColorFactor[1]), miniprogram$1.Color.linearToGammaSpace(baseColorFactor[2]), baseColorFactor[3]);
|
|
1171
|
+
}
|
|
1172
|
+
if (baseColorTexture) {
|
|
1173
|
+
material.baseTexture = textures[baseColorTexture.index];
|
|
1174
|
+
MaterialParser._parseTextureTransform(material, baseColorTexture.extensions, context);
|
|
1175
|
+
}
|
|
1176
|
+
if (!KHR_materials_unlit && !KHR_materials_pbrSpecularGlossiness) {
|
|
1177
|
+
var m = material;
|
|
1178
|
+
m.metallic = metallicFactor != null ? metallicFactor : 1;
|
|
1179
|
+
m.roughness = roughnessFactor != null ? roughnessFactor : 1;
|
|
1180
|
+
if (metallicRoughnessTexture) {
|
|
1181
|
+
m.roughnessMetallicTexture = textures[metallicRoughnessTexture.index];
|
|
1182
|
+
MaterialParser._parseTextureTransform(material, metallicRoughnessTexture.extensions, context);
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
if (!KHR_materials_unlit) {
|
|
1187
|
+
var m1 = material;
|
|
1188
|
+
if (emissiveTexture) {
|
|
1189
|
+
m1.emissiveTexture = textures[emissiveTexture.index];
|
|
1190
|
+
MaterialParser._parseTextureTransform(material, emissiveTexture.extensions, context);
|
|
1191
|
+
}
|
|
1192
|
+
if (emissiveFactor) {
|
|
1193
|
+
m1.emissiveColor = new miniprogram$1.Color(miniprogram$1.Color.linearToGammaSpace(emissiveFactor[0]), miniprogram$1.Color.linearToGammaSpace(emissiveFactor[1]), miniprogram$1.Color.linearToGammaSpace(emissiveFactor[2]));
|
|
1194
|
+
}
|
|
1195
|
+
if (normalTexture) {
|
|
1196
|
+
var index = normalTexture.index, scale = normalTexture.scale;
|
|
1197
|
+
m1.normalTexture = textures[index];
|
|
1198
|
+
MaterialParser._parseTextureTransform(material, normalTexture.extensions, context);
|
|
1199
|
+
if (scale !== undefined) {
|
|
1200
|
+
m1.normalTextureIntensity = scale;
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
if (occlusionTexture) {
|
|
1204
|
+
var index1 = occlusionTexture.index, strength = occlusionTexture.strength, texCoord = occlusionTexture.texCoord;
|
|
1205
|
+
m1.occlusionTexture = textures[index1];
|
|
1206
|
+
MaterialParser._parseTextureTransform(material, occlusionTexture.extensions, context);
|
|
1207
|
+
if (strength !== undefined) {
|
|
1208
|
+
m1.occlusionTextureIntensity = strength;
|
|
1209
|
+
}
|
|
1210
|
+
if (texCoord === miniprogram.TextureCoordinate.UV1) {
|
|
1211
|
+
m1.occlusionTextureCoord = miniprogram.TextureCoordinate.UV1;
|
|
1212
|
+
} else if (texCoord > miniprogram.TextureCoordinate.UV1) {
|
|
1213
|
+
miniprogram.Logger.warn("Occlusion texture uv coordinate must be UV0 or UV1.");
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
if (OASIS_materials_remap) {
|
|
1218
|
+
var _gltf_extensions;
|
|
1219
|
+
gltf.extensions = (_gltf_extensions = gltf.extensions) != null ? _gltf_extensions : {};
|
|
1220
|
+
var _gltf_extensions_OASIS_materials_remap;
|
|
1221
|
+
gltf.extensions["OASIS_materials_remap"] = (_gltf_extensions_OASIS_materials_remap = gltf.extensions["OASIS_materials_remap"]) != null ? _gltf_extensions_OASIS_materials_remap : {};
|
|
1222
|
+
gltf.extensions["OASIS_materials_remap"][i] = Parser.createEngineResource("OASIS_materials_remap", OASIS_materials_remap, context);
|
|
1223
|
+
}
|
|
1224
|
+
if (doubleSided) {
|
|
1225
|
+
material.renderFace = miniprogram.RenderFace.Double;
|
|
1226
|
+
} else {
|
|
1227
|
+
material.renderFace = miniprogram.RenderFace.Front;
|
|
1228
|
+
}
|
|
1229
|
+
switch(alphaMode){
|
|
1230
|
+
case MaterialAlphaMode.OPAQUE:
|
|
1231
|
+
material.isTransparent = false;
|
|
1232
|
+
break;
|
|
1233
|
+
case MaterialAlphaMode.BLEND:
|
|
1234
|
+
material.isTransparent = true;
|
|
1235
|
+
break;
|
|
1236
|
+
case MaterialAlphaMode.MASK:
|
|
1237
|
+
material.alphaCutoff = alphaCutoff != null ? alphaCutoff : 0.5;
|
|
1238
|
+
break;
|
|
1239
|
+
}
|
|
1240
|
+
materials[i] = material;
|
|
1241
|
+
}
|
|
1242
|
+
glTFResource.materials = materials;
|
|
1243
|
+
materialsPromiseInfo.resolve(materials);
|
|
1244
|
+
return materialsPromiseInfo.promise;
|
|
1245
|
+
};
|
|
1246
|
+
/** @internal */ MaterialParser._parseTextureTransform = function _parseTextureTransform(material, extensions, context) {
|
|
1247
|
+
if (extensions === void 0) extensions = {};
|
|
1248
|
+
var schema = extensions.KHR_texture_transform;
|
|
1249
|
+
if (schema) {
|
|
1250
|
+
Parser.parseEngineResource("KHR_texture_transform", schema, material, context);
|
|
1251
|
+
}
|
|
1252
|
+
};
|
|
1253
|
+
return MaterialParser;
|
|
1254
|
+
}(Parser);
|
|
1255
|
+
|
|
1256
|
+
var KHR_materials_clearcoat = /*#__PURE__*/ function(ExtensionParser) {
|
|
1257
|
+
_inherits(KHR_materials_clearcoat, ExtensionParser);
|
|
1258
|
+
function KHR_materials_clearcoat() {
|
|
1259
|
+
return ExtensionParser.apply(this, arguments);
|
|
1260
|
+
}
|
|
1261
|
+
var _proto = KHR_materials_clearcoat.prototype;
|
|
1262
|
+
_proto.parseEngineResource = function parseEngineResource(schema, material, context) {
|
|
1263
|
+
var textures = context.glTFResource.textures;
|
|
1264
|
+
var _schema_clearcoatFactor = schema.clearcoatFactor, clearcoatFactor = _schema_clearcoatFactor === void 0 ? 0 : _schema_clearcoatFactor, clearcoatTexture = schema.clearcoatTexture, _schema_clearcoatRoughnessFactor = schema.clearcoatRoughnessFactor, clearcoatRoughnessFactor = _schema_clearcoatRoughnessFactor === void 0 ? 0 : _schema_clearcoatRoughnessFactor, clearcoatRoughnessTexture = schema.clearcoatRoughnessTexture, clearcoatNormalTexture = schema.clearcoatNormalTexture;
|
|
1265
|
+
material.clearCoat = clearcoatFactor;
|
|
1266
|
+
material.clearCoatRoughness = clearcoatRoughnessFactor;
|
|
1267
|
+
if (clearcoatTexture) {
|
|
1268
|
+
material.clearCoatTexture = textures[clearcoatTexture.index];
|
|
1269
|
+
MaterialParser._parseTextureTransform(material, clearcoatTexture.extensions, context);
|
|
1270
|
+
}
|
|
1271
|
+
if (clearcoatRoughnessTexture) {
|
|
1272
|
+
material.clearCoatRoughnessTexture = textures[clearcoatRoughnessTexture.index];
|
|
1273
|
+
MaterialParser._parseTextureTransform(material, clearcoatRoughnessTexture.extensions, context);
|
|
1274
|
+
}
|
|
1275
|
+
if (clearcoatNormalTexture) {
|
|
1276
|
+
material.clearCoatNormalTexture = textures[clearcoatNormalTexture.index];
|
|
1277
|
+
MaterialParser._parseTextureTransform(material, clearcoatNormalTexture.extensions, context);
|
|
1278
|
+
}
|
|
1279
|
+
};
|
|
1280
|
+
return KHR_materials_clearcoat;
|
|
1281
|
+
}(ExtensionParser);
|
|
1282
|
+
KHR_materials_clearcoat = __decorate([
|
|
1283
|
+
registerExtension("KHR_materials_clearcoat")
|
|
1284
|
+
], KHR_materials_clearcoat);
|
|
1285
|
+
|
|
1286
|
+
var KHR_materials_pbrSpecularGlossiness = /*#__PURE__*/ function(ExtensionParser) {
|
|
1287
|
+
_inherits(KHR_materials_pbrSpecularGlossiness, ExtensionParser);
|
|
1288
|
+
function KHR_materials_pbrSpecularGlossiness() {
|
|
1289
|
+
return ExtensionParser.apply(this, arguments);
|
|
1290
|
+
}
|
|
1291
|
+
var _proto = KHR_materials_pbrSpecularGlossiness.prototype;
|
|
1292
|
+
_proto.createEngineResource = function createEngineResource(schema, context) {
|
|
1293
|
+
var _context_glTFResource = context.glTFResource, engine = _context_glTFResource.engine, textures = _context_glTFResource.textures;
|
|
1294
|
+
var material = new miniprogram.PBRSpecularMaterial(engine);
|
|
1295
|
+
var diffuseFactor = schema.diffuseFactor, diffuseTexture = schema.diffuseTexture, specularFactor = schema.specularFactor, glossinessFactor = schema.glossinessFactor, specularGlossinessTexture = schema.specularGlossinessTexture;
|
|
1296
|
+
if (diffuseFactor) {
|
|
1297
|
+
material.baseColor = new miniprogram$1.Color(miniprogram$1.Color.linearToGammaSpace(diffuseFactor[0]), miniprogram$1.Color.linearToGammaSpace(diffuseFactor[1]), miniprogram$1.Color.linearToGammaSpace(diffuseFactor[2]), diffuseFactor[3]);
|
|
1298
|
+
}
|
|
1299
|
+
if (diffuseTexture) {
|
|
1300
|
+
material.baseTexture = textures[diffuseTexture.index];
|
|
1301
|
+
MaterialParser._parseTextureTransform(material, diffuseTexture.extensions, context);
|
|
1302
|
+
}
|
|
1303
|
+
if (specularFactor) {
|
|
1304
|
+
material.specularColor = new miniprogram$1.Color(miniprogram$1.Color.linearToGammaSpace(specularFactor[0]), miniprogram$1.Color.linearToGammaSpace(specularFactor[1]), miniprogram$1.Color.linearToGammaSpace(specularFactor[2]));
|
|
1305
|
+
}
|
|
1306
|
+
if (glossinessFactor !== undefined) {
|
|
1307
|
+
material.glossiness = glossinessFactor;
|
|
1308
|
+
}
|
|
1309
|
+
if (specularGlossinessTexture) {
|
|
1310
|
+
material.specularGlossinessTexture = textures[specularGlossinessTexture.index];
|
|
1311
|
+
MaterialParser._parseTextureTransform(material, specularGlossinessTexture.extensions, context);
|
|
1312
|
+
}
|
|
1313
|
+
return material;
|
|
1314
|
+
};
|
|
1315
|
+
return KHR_materials_pbrSpecularGlossiness;
|
|
1316
|
+
}(ExtensionParser);
|
|
1317
|
+
KHR_materials_pbrSpecularGlossiness = __decorate([
|
|
1318
|
+
registerExtension("KHR_materials_pbrSpecularGlossiness")
|
|
1319
|
+
], KHR_materials_pbrSpecularGlossiness);
|
|
1320
|
+
|
|
1321
|
+
var KHR_materials_unlit = /*#__PURE__*/ function(ExtensionParser) {
|
|
1322
|
+
_inherits(KHR_materials_unlit, ExtensionParser);
|
|
1323
|
+
function KHR_materials_unlit() {
|
|
1324
|
+
return ExtensionParser.apply(this, arguments);
|
|
1325
|
+
}
|
|
1326
|
+
var _proto = KHR_materials_unlit.prototype;
|
|
1327
|
+
_proto.createEngineResource = function createEngineResource(schema, context) {
|
|
1328
|
+
var engine = context.glTFResource.engine;
|
|
1329
|
+
var material = new miniprogram.UnlitMaterial(engine);
|
|
1330
|
+
return material;
|
|
1331
|
+
};
|
|
1332
|
+
return KHR_materials_unlit;
|
|
1333
|
+
}(ExtensionParser);
|
|
1334
|
+
KHR_materials_unlit = __decorate([
|
|
1335
|
+
registerExtension("KHR_materials_unlit")
|
|
1336
|
+
], KHR_materials_unlit);
|
|
1337
|
+
|
|
1338
|
+
var KHR_materials_variants = /*#__PURE__*/ function(ExtensionParser) {
|
|
1339
|
+
_inherits(KHR_materials_variants, ExtensionParser);
|
|
1340
|
+
function KHR_materials_variants() {
|
|
1341
|
+
return ExtensionParser.apply(this, arguments);
|
|
1342
|
+
}
|
|
1343
|
+
var _proto = KHR_materials_variants.prototype;
|
|
1344
|
+
_proto.parseEngineResource = function parseEngineResource(schema, renderer, context) {
|
|
1345
|
+
var _context_gltf = context.gltf, _context_gltf_extensions = _context_gltf.extensions, _context_gltf_extensions_KHR_materials_variants = _context_gltf_extensions.KHR_materials_variants, variantNames = _context_gltf_extensions_KHR_materials_variants.variants, glTFResource = context.glTFResource;
|
|
1346
|
+
var mappings = schema.mappings;
|
|
1347
|
+
for(var i = 0; i < mappings.length; i++){
|
|
1348
|
+
var _mappings_i = mappings[i], material = _mappings_i.material, variants = _mappings_i.variants;
|
|
1349
|
+
if (!glTFResource.variants) glTFResource.variants = [];
|
|
1350
|
+
glTFResource.variants.push({
|
|
1351
|
+
renderer: renderer,
|
|
1352
|
+
material: glTFResource.materials[material],
|
|
1353
|
+
variants: variants.map(function(index) {
|
|
1354
|
+
return variantNames[index].name;
|
|
1355
|
+
})
|
|
1356
|
+
});
|
|
1357
|
+
}
|
|
1358
|
+
};
|
|
1359
|
+
return KHR_materials_variants;
|
|
1360
|
+
}(ExtensionParser);
|
|
1361
|
+
KHR_materials_variants = __decorate([
|
|
1362
|
+
registerExtension("KHR_materials_variants")
|
|
1363
|
+
], KHR_materials_variants);
|
|
1364
|
+
|
|
1365
|
+
var KHR_mesh_quantization = /*#__PURE__*/ function(ExtensionParser) {
|
|
1366
|
+
_inherits(KHR_mesh_quantization, ExtensionParser);
|
|
1367
|
+
function KHR_mesh_quantization() {
|
|
1368
|
+
return ExtensionParser.apply(this, arguments);
|
|
1369
|
+
}
|
|
1370
|
+
return KHR_mesh_quantization;
|
|
1371
|
+
}(ExtensionParser);
|
|
1372
|
+
KHR_mesh_quantization = __decorate([
|
|
1373
|
+
registerExtension("KHR_mesh_quantization")
|
|
1374
|
+
], KHR_mesh_quantization);
|
|
1375
|
+
|
|
1376
|
+
var KHR_texture_transform = /*#__PURE__*/ function(ExtensionParser) {
|
|
1377
|
+
_inherits(KHR_texture_transform, ExtensionParser);
|
|
1378
|
+
function KHR_texture_transform() {
|
|
1379
|
+
return ExtensionParser.apply(this, arguments);
|
|
1380
|
+
}
|
|
1381
|
+
var _proto = KHR_texture_transform.prototype;
|
|
1382
|
+
_proto.parseEngineResource = function parseEngineResource(schema, material, context) {
|
|
1383
|
+
var offset = schema.offset, rotation = schema.rotation, scale = schema.scale, texCoord = schema.texCoord;
|
|
1384
|
+
if (offset) {
|
|
1385
|
+
material.tilingOffset.z = offset[0];
|
|
1386
|
+
material.tilingOffset.w = offset[1];
|
|
1387
|
+
}
|
|
1388
|
+
if (scale) {
|
|
1389
|
+
material.tilingOffset.x = scale[0];
|
|
1390
|
+
material.tilingOffset.y = scale[1];
|
|
1391
|
+
}
|
|
1392
|
+
if (rotation) {
|
|
1393
|
+
miniprogram.Logger.warn("rotation in KHR_texture_transform is not supported now");
|
|
1394
|
+
}
|
|
1395
|
+
if (texCoord) {
|
|
1396
|
+
miniprogram.Logger.warn("texCoord in KHR_texture_transform is not supported now");
|
|
1397
|
+
}
|
|
1398
|
+
};
|
|
1399
|
+
return KHR_texture_transform;
|
|
1400
|
+
}(ExtensionParser);
|
|
1401
|
+
KHR_texture_transform = __decorate([
|
|
1402
|
+
registerExtension("KHR_texture_transform")
|
|
1403
|
+
], KHR_texture_transform);
|
|
1404
|
+
|
|
1405
|
+
var GalaceanMaterialsRemap = /*#__PURE__*/ function(ExtensionParser) {
|
|
1406
|
+
_inherits(GalaceanMaterialsRemap, ExtensionParser);
|
|
1407
|
+
function GalaceanMaterialsRemap() {
|
|
1408
|
+
return ExtensionParser.apply(this, arguments);
|
|
1409
|
+
}
|
|
1410
|
+
var _proto = GalaceanMaterialsRemap.prototype;
|
|
1411
|
+
_proto.createEngineResource = function createEngineResource(schema, context) {
|
|
1412
|
+
var engine = context.glTFResource.engine;
|
|
1413
|
+
// @ts-ignore
|
|
1414
|
+
return engine.resourceManager.getResourceByRef(schema);
|
|
1415
|
+
};
|
|
1416
|
+
return GalaceanMaterialsRemap;
|
|
1417
|
+
}(ExtensionParser);
|
|
1418
|
+
GalaceanMaterialsRemap = __decorate([
|
|
1419
|
+
registerExtension("OASIS_materials_remap")
|
|
1420
|
+
], GalaceanMaterialsRemap);
|
|
1421
|
+
|
|
1422
|
+
function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
|
|
1423
|
+
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
1424
|
+
|
|
1425
|
+
if (it) return (it = it.call(o)).next.bind(it);
|
|
1426
|
+
// Fallback for engines without symbol support
|
|
1427
|
+
if (Array.isArray(o) || (it = _unsupported_iterable_to_array(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
1428
|
+
if (it) o = it;
|
|
1429
|
+
|
|
1430
|
+
var i = 0;
|
|
1431
|
+
|
|
1432
|
+
return function() {
|
|
1433
|
+
if (i >= o.length) return { done: true };
|
|
1434
|
+
|
|
1435
|
+
return { done: false, value: o[i++] };
|
|
1436
|
+
};
|
|
1437
|
+
}
|
|
1438
|
+
|
|
1439
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
1440
|
+
}
|
|
1441
|
+
|
|
1442
|
+
var AnimationParser = /*#__PURE__*/ function(Parser) {
|
|
1443
|
+
_inherits(AnimationParser, Parser);
|
|
1444
|
+
function AnimationParser() {
|
|
1445
|
+
return Parser.apply(this, arguments);
|
|
1446
|
+
}
|
|
1447
|
+
var _proto = AnimationParser.prototype;
|
|
1448
|
+
_proto.parse = function parse(context) {
|
|
1449
|
+
var gltf = context.gltf; context.buffers; var glTFResource = context.glTFResource;
|
|
1450
|
+
var entities = glTFResource.entities;
|
|
1451
|
+
var animations = gltf.animations, accessors = gltf.accessors;
|
|
1452
|
+
if (!animations) {
|
|
1453
|
+
return;
|
|
1454
|
+
}
|
|
1455
|
+
var animationClipsPromiseInfo = context.animationClipsPromiseInfo;
|
|
1456
|
+
var animationClipCount = animations.length;
|
|
1457
|
+
var animationClips = new Array(animationClipCount);
|
|
1458
|
+
var animationsIndices = new Array(animationClipCount);
|
|
1459
|
+
for(var i = 0; i < animationClipCount; i++){
|
|
1460
|
+
var gltfAnimation = animations[i];
|
|
1461
|
+
var channels = gltfAnimation.channels, samplers = gltfAnimation.samplers, _gltfAnimation_name = gltfAnimation.name, name = _gltfAnimation_name === void 0 ? "AnimationClip" + i : _gltfAnimation_name;
|
|
1462
|
+
var animationClip = new miniprogram.AnimationClip(name);
|
|
1463
|
+
var sampleDataCollection = new Array();
|
|
1464
|
+
// parse samplers
|
|
1465
|
+
for(var j = 0, m = samplers.length; j < m; j++){
|
|
1466
|
+
var gltfSampler = samplers[j];
|
|
1467
|
+
var inputAccessor = accessors[gltfSampler.input];
|
|
1468
|
+
var outputAccessor = accessors[gltfSampler.output];
|
|
1469
|
+
var input = GLTFUtil.getAccessorBuffer(context, gltf, inputAccessor).data;
|
|
1470
|
+
var output = GLTFUtil.getAccessorBuffer(context, gltf, outputAccessor).data;
|
|
1471
|
+
if (outputAccessor.normalized) {
|
|
1472
|
+
var scale = GLTFUtil.getNormalizedComponentScale(outputAccessor.componentType);
|
|
1473
|
+
var scaled = new Float32Array(output.length);
|
|
1474
|
+
for(var k = 0, v = output.length; k < v; k++){
|
|
1475
|
+
scaled[k] = output[k] * scale;
|
|
1476
|
+
}
|
|
1477
|
+
output = scaled;
|
|
1478
|
+
}
|
|
1479
|
+
var outputStride = output.length / input.length;
|
|
1480
|
+
var _gltfSampler_interpolation;
|
|
1481
|
+
var interpolation = (_gltfSampler_interpolation = gltfSampler.interpolation) != null ? _gltfSampler_interpolation : AnimationSamplerInterpolation.Linear;
|
|
1482
|
+
var samplerInterpolation = void 0;
|
|
1483
|
+
switch(interpolation){
|
|
1484
|
+
case AnimationSamplerInterpolation.CubicSpine:
|
|
1485
|
+
samplerInterpolation = miniprogram.InterpolationType.CubicSpine;
|
|
1486
|
+
break;
|
|
1487
|
+
case AnimationSamplerInterpolation.Step:
|
|
1488
|
+
samplerInterpolation = miniprogram.InterpolationType.Step;
|
|
1489
|
+
break;
|
|
1490
|
+
case AnimationSamplerInterpolation.Linear:
|
|
1491
|
+
samplerInterpolation = miniprogram.InterpolationType.Linear;
|
|
1492
|
+
break;
|
|
1493
|
+
}
|
|
1494
|
+
input[input.length - 1];
|
|
1495
|
+
sampleDataCollection.push({
|
|
1496
|
+
type: outputAccessor.type,
|
|
1497
|
+
interpolation: samplerInterpolation,
|
|
1498
|
+
input: input,
|
|
1499
|
+
output: output,
|
|
1500
|
+
outputSize: outputStride
|
|
1501
|
+
});
|
|
1502
|
+
}
|
|
1503
|
+
for(var j1 = 0, m1 = channels.length; j1 < m1; j1++){
|
|
1504
|
+
var gltfChannel = channels[j1];
|
|
1505
|
+
var target = gltfChannel.target;
|
|
1506
|
+
var channelTargetEntity = entities[target.node];
|
|
1507
|
+
var relativePath = "";
|
|
1508
|
+
var entity = channelTargetEntity;
|
|
1509
|
+
while(entity.parent){
|
|
1510
|
+
relativePath = relativePath === "" ? "" + entity.name : entity.name + "/" + relativePath;
|
|
1511
|
+
entity = entity.parent;
|
|
1512
|
+
}
|
|
1513
|
+
var ComponentType = void 0;
|
|
1514
|
+
var propertyName = void 0;
|
|
1515
|
+
switch(target.path){
|
|
1516
|
+
case AnimationChannelTargetPath.TRANSLATION:
|
|
1517
|
+
ComponentType = miniprogram.Transform;
|
|
1518
|
+
propertyName = "position";
|
|
1519
|
+
break;
|
|
1520
|
+
case AnimationChannelTargetPath.ROTATION:
|
|
1521
|
+
ComponentType = miniprogram.Transform;
|
|
1522
|
+
propertyName = "rotationQuaternion";
|
|
1523
|
+
break;
|
|
1524
|
+
case AnimationChannelTargetPath.SCALE:
|
|
1525
|
+
ComponentType = miniprogram.Transform;
|
|
1526
|
+
propertyName = "scale";
|
|
1527
|
+
break;
|
|
1528
|
+
case AnimationChannelTargetPath.WEIGHTS:
|
|
1529
|
+
ComponentType = miniprogram.SkinnedMeshRenderer;
|
|
1530
|
+
propertyName = "blendShapeWeights";
|
|
1531
|
+
break;
|
|
1532
|
+
}
|
|
1533
|
+
var curve = this._addCurve(target.path, gltfChannel, sampleDataCollection);
|
|
1534
|
+
animationClip.addCurveBinding(relativePath, ComponentType, propertyName, curve);
|
|
1535
|
+
}
|
|
1536
|
+
animationClips[i] = animationClip;
|
|
1537
|
+
animationsIndices[i] = {
|
|
1538
|
+
name: name,
|
|
1539
|
+
index: i
|
|
1540
|
+
};
|
|
1541
|
+
}
|
|
1542
|
+
glTFResource.animations = animationClips;
|
|
1543
|
+
// @ts-ignore for editor
|
|
1544
|
+
glTFResource._animationsIndices = animationsIndices;
|
|
1545
|
+
animationClipsPromiseInfo.resolve(animationClips);
|
|
1546
|
+
return animationClipsPromiseInfo.promise;
|
|
1547
|
+
};
|
|
1548
|
+
_proto._addCurve = function _addCurve(animationchannelTargetPath, gltfChannel, sampleDataCollection) {
|
|
1549
|
+
var sampleData = sampleDataCollection[gltfChannel.sampler];
|
|
1550
|
+
var input = sampleData.input, output = sampleData.output, outputSize = sampleData.outputSize;
|
|
1551
|
+
switch(animationchannelTargetPath){
|
|
1552
|
+
case AnimationChannelTargetPath.TRANSLATION:
|
|
1553
|
+
case AnimationChannelTargetPath.SCALE:
|
|
1554
|
+
{
|
|
1555
|
+
var curve = new miniprogram.AnimationVector3Curve();
|
|
1556
|
+
var interpolation = curve.interpolation = sampleData.interpolation;
|
|
1490
1557
|
var offset = 0;
|
|
1491
1558
|
for(var i = 0, n = input.length; i < n; i++){
|
|
1492
1559
|
var keyframe = new miniprogram.Keyframe();
|
|
@@ -1546,42 +1613,35 @@ var GLTFAnimationParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
1546
1613
|
}
|
|
1547
1614
|
}
|
|
1548
1615
|
};
|
|
1549
|
-
return
|
|
1550
|
-
}(
|
|
1616
|
+
return AnimationParser;
|
|
1617
|
+
}(Parser);
|
|
1551
1618
|
|
|
1552
|
-
var
|
|
1553
|
-
_inherits(
|
|
1554
|
-
function
|
|
1555
|
-
return
|
|
1619
|
+
var BufferParser = /*#__PURE__*/ function(Parser) {
|
|
1620
|
+
_inherits(BufferParser, Parser);
|
|
1621
|
+
function BufferParser() {
|
|
1622
|
+
return Parser.apply(this, arguments);
|
|
1556
1623
|
}
|
|
1557
|
-
var _proto =
|
|
1624
|
+
var _proto = BufferParser.prototype;
|
|
1558
1625
|
_proto.parse = function parse(context) {
|
|
1559
|
-
var glTFResource = context.glTFResource
|
|
1626
|
+
var glTFResource = context.glTFResource;
|
|
1560
1627
|
var url = glTFResource.url;
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
if (isGLB) {
|
|
1568
|
-
return miniprogram.request(url, requestConfig).then(function(glb) {
|
|
1569
|
-
restoreBufferRequests.push(new BufferRequestInfo(url, requestConfig));
|
|
1570
|
-
return GLTFUtil.parseGLB(context, glb);
|
|
1571
|
-
}).then(function(param) {
|
|
1572
|
-
var glTF = param.glTF, buffers = param.buffers;
|
|
1573
|
-
context.glTF = glTF;
|
|
1628
|
+
if (this._isGLB(url)) {
|
|
1629
|
+
return miniprogram.request(url, {
|
|
1630
|
+
type: "arraybuffer"
|
|
1631
|
+
}).then(GLTFUtil.parseGLB).then(function(param) {
|
|
1632
|
+
var gltf = param.gltf, buffers = param.buffers;
|
|
1633
|
+
context.gltf = gltf;
|
|
1574
1634
|
context.buffers = buffers;
|
|
1575
1635
|
});
|
|
1576
1636
|
} else {
|
|
1577
1637
|
return miniprogram.request(url, {
|
|
1578
1638
|
type: "json"
|
|
1579
|
-
}).then(function(
|
|
1580
|
-
context.
|
|
1581
|
-
return Promise.all(
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1639
|
+
}).then(function(gltf) {
|
|
1640
|
+
context.gltf = gltf;
|
|
1641
|
+
return Promise.all(gltf.buffers.map(function(buffer) {
|
|
1642
|
+
return miniprogram.request(GLTFUtil.parseRelativeUrl(url, buffer.uri), {
|
|
1643
|
+
type: "arraybuffer"
|
|
1644
|
+
});
|
|
1585
1645
|
})).then(function(buffers) {
|
|
1586
1646
|
context.buffers = buffers;
|
|
1587
1647
|
});
|
|
@@ -1592,24 +1652,24 @@ var GLTFBufferParser = /*#__PURE__*/ function(GLTFParser) {
|
|
|
1592
1652
|
var index = url.lastIndexOf(".");
|
|
1593
1653
|
return url.substring(index + 1, index + 4) === "glb";
|
|
1594
1654
|
};
|
|
1595
|
-
return
|
|
1596
|
-
}(
|
|
1655
|
+
return BufferParser;
|
|
1656
|
+
}(Parser);
|
|
1597
1657
|
|
|
1598
|
-
var
|
|
1599
|
-
_inherits(
|
|
1600
|
-
function
|
|
1601
|
-
return
|
|
1658
|
+
var EntityParser = /*#__PURE__*/ function(Parser) {
|
|
1659
|
+
_inherits(EntityParser, Parser);
|
|
1660
|
+
function EntityParser() {
|
|
1661
|
+
return Parser.apply(this, arguments);
|
|
1602
1662
|
}
|
|
1603
|
-
var _proto =
|
|
1663
|
+
var _proto = EntityParser.prototype;
|
|
1604
1664
|
_proto.parse = function parse(context) {
|
|
1605
|
-
var glTFResource = context.glTFResource, nodes = context.
|
|
1665
|
+
var glTFResource = context.glTFResource, nodes = context.gltf.nodes;
|
|
1606
1666
|
var engine = glTFResource.engine;
|
|
1607
1667
|
if (!nodes) return;
|
|
1608
1668
|
var entities = [];
|
|
1609
1669
|
for(var i = 0; i < nodes.length; i++){
|
|
1610
1670
|
var gltfNode = nodes[i];
|
|
1611
1671
|
var matrix = gltfNode.matrix, translation = gltfNode.translation, rotation = gltfNode.rotation, scale = gltfNode.scale;
|
|
1612
|
-
var entity = new miniprogram.Entity(engine, gltfNode.name || "" +
|
|
1672
|
+
var entity = new miniprogram.Entity(engine, gltfNode.name || "" + EntityParser._defaultName + i);
|
|
1613
1673
|
var transform = entity.transform;
|
|
1614
1674
|
if (matrix) {
|
|
1615
1675
|
var localMatrix = transform.localMatrix;
|
|
@@ -1633,7 +1693,7 @@ var GLTFEntityParser = /*#__PURE__*/ function(GLTFParser) {
|
|
|
1633
1693
|
this._createSceneRoots(context, glTFResource);
|
|
1634
1694
|
};
|
|
1635
1695
|
_proto._buildEntityTree = function _buildEntityTree(context, glTFResource) {
|
|
1636
|
-
var nodes = context.
|
|
1696
|
+
var nodes = context.gltf.nodes;
|
|
1637
1697
|
var entities = glTFResource.entities;
|
|
1638
1698
|
for(var i = 0; i < nodes.length; i++){
|
|
1639
1699
|
var children = nodes[i].children;
|
|
@@ -1647,7 +1707,7 @@ var GLTFEntityParser = /*#__PURE__*/ function(GLTFParser) {
|
|
|
1647
1707
|
}
|
|
1648
1708
|
};
|
|
1649
1709
|
_proto._createSceneRoots = function _createSceneRoots(context, glTFResource) {
|
|
1650
|
-
var
|
|
1710
|
+
var _context_gltf = context.gltf, tmp = _context_gltf.scene, sceneID = tmp === void 0 ? 0 : tmp, scenes = _context_gltf.scenes;
|
|
1651
1711
|
var engine = glTFResource.engine, entities = glTFResource.entities;
|
|
1652
1712
|
if (!scenes) return;
|
|
1653
1713
|
var sceneRoots = [];
|
|
@@ -1667,193 +1727,79 @@ var GLTFEntityParser = /*#__PURE__*/ function(GLTFParser) {
|
|
|
1667
1727
|
glTFResource.sceneRoots = sceneRoots;
|
|
1668
1728
|
glTFResource.defaultSceneRoot = sceneRoots[sceneID];
|
|
1669
1729
|
};
|
|
1670
|
-
return
|
|
1671
|
-
}(
|
|
1672
|
-
|
|
1730
|
+
return EntityParser;
|
|
1731
|
+
}(Parser);
|
|
1732
|
+
(function() {
|
|
1733
|
+
/** @internal */ EntityParser._defaultName = "_GLTF_ENTITY_";
|
|
1734
|
+
})();
|
|
1673
1735
|
|
|
1674
|
-
var
|
|
1675
|
-
_inherits(
|
|
1676
|
-
function
|
|
1677
|
-
return
|
|
1736
|
+
var MeshParser = /*#__PURE__*/ function(Parser1) {
|
|
1737
|
+
_inherits(MeshParser, Parser1);
|
|
1738
|
+
function MeshParser() {
|
|
1739
|
+
return Parser1.apply(this, arguments);
|
|
1678
1740
|
}
|
|
1679
|
-
var _proto =
|
|
1741
|
+
var _proto = MeshParser.prototype;
|
|
1680
1742
|
_proto.parse = function parse(context) {
|
|
1681
|
-
var
|
|
1682
|
-
|
|
1743
|
+
var _loop = function(i) {
|
|
1744
|
+
var _loop = function(j) {
|
|
1745
|
+
var gltfPrimitive = gltfMesh.primitives[j];
|
|
1746
|
+
var _gltfPrimitive_extensions = gltfPrimitive.extensions, extensions = _gltfPrimitive_extensions === void 0 ? {} : _gltfPrimitive_extensions;
|
|
1747
|
+
var KHR_draco_mesh_compression = extensions.KHR_draco_mesh_compression;
|
|
1748
|
+
primitivePromises[j] = new Promise(function(resolve) {
|
|
1749
|
+
var mesh = new miniprogram.ModelMesh(engine, gltfMesh.name || j + "");
|
|
1750
|
+
if (KHR_draco_mesh_compression) {
|
|
1751
|
+
Parser.createEngineResource("KHR_draco_mesh_compression", KHR_draco_mesh_compression, context, gltfPrimitive).then(function(decodedGeometry) {
|
|
1752
|
+
return _this._parseMeshFromGLTFPrimitiveDraco(mesh, gltfMesh, gltfPrimitive, gltf, function(attributeSemantic) {
|
|
1753
|
+
for(var j = 0; j < decodedGeometry.attributes.length; j++){
|
|
1754
|
+
if (decodedGeometry.attributes[j].name === attributeSemantic) {
|
|
1755
|
+
return decodedGeometry.attributes[j].array;
|
|
1756
|
+
}
|
|
1757
|
+
}
|
|
1758
|
+
return null;
|
|
1759
|
+
}, function(attributeSemantic, shapeIndex) {
|
|
1760
|
+
throw "BlendShape animation is not supported when using draco.";
|
|
1761
|
+
}, function() {
|
|
1762
|
+
return decodedGeometry.index.array;
|
|
1763
|
+
}, context.keepMeshData);
|
|
1764
|
+
}).then(resolve);
|
|
1765
|
+
} else {
|
|
1766
|
+
_this._parseMeshFromGLTFPrimitive(context, mesh, gltfMesh, gltfPrimitive, gltf, function(attributeSemantic) {
|
|
1767
|
+
return null;
|
|
1768
|
+
}, function(attributeName, shapeIndex) {
|
|
1769
|
+
var shapeAccessorIdx = gltfPrimitive.targets[shapeIndex];
|
|
1770
|
+
var attributeAccessorIdx = shapeAccessorIdx[attributeName];
|
|
1771
|
+
if (attributeAccessorIdx) {
|
|
1772
|
+
var accessor = gltf.accessors[attributeAccessorIdx];
|
|
1773
|
+
return GLTFUtil.getAccessorData(gltf, accessor, buffers);
|
|
1774
|
+
} else {
|
|
1775
|
+
return null;
|
|
1776
|
+
}
|
|
1777
|
+
}, function() {
|
|
1778
|
+
var indexAccessor = gltf.accessors[gltfPrimitive.indices];
|
|
1779
|
+
return GLTFUtil.getAccessorData(gltf, indexAccessor, buffers);
|
|
1780
|
+
}, context.keepMeshData).then(resolve);
|
|
1781
|
+
}
|
|
1782
|
+
});
|
|
1783
|
+
};
|
|
1784
|
+
var gltfMesh = gltf.meshes[i];
|
|
1785
|
+
var primitivePromises = [];
|
|
1786
|
+
for(var j = 0; j < gltfMesh.primitives.length; j++)_loop(j);
|
|
1787
|
+
meshPromises[i] = Promise.all(primitivePromises);
|
|
1788
|
+
};
|
|
1789
|
+
var _this = this;
|
|
1790
|
+
var gltf = context.gltf, buffers = context.buffers, glTFResource = context.glTFResource;
|
|
1683
1791
|
var engine = glTFResource.engine;
|
|
1684
|
-
|
|
1685
|
-
for(var i = 0; i < glTF.materials.length; i++){
|
|
1686
|
-
var materialInfo = glTF.materials[i];
|
|
1687
|
-
var material = GLTFParser.executeExtensionsCreateAndParse(materialInfo.extensions, context, materialInfo);
|
|
1688
|
-
if (!material) {
|
|
1689
|
-
material = new miniprogram.PBRMaterial(engine);
|
|
1690
|
-
material.name = materialInfo.name;
|
|
1691
|
-
GLTFMaterialParser._parseStandardProperty(context, material, materialInfo);
|
|
1692
|
-
}
|
|
1693
|
-
materialPromises.push(material);
|
|
1694
|
-
}
|
|
1695
|
-
return miniprogram.AssetPromise.all(materialPromises).then(function(materials) {
|
|
1696
|
-
glTFResource.materials = materials;
|
|
1697
|
-
for(var i = 0; i < glTF.materials.length; i++){
|
|
1698
|
-
var materialInfo = glTF.materials[i];
|
|
1699
|
-
GLTFParser.executeExtensionsAdditiveAndParse(materialInfo.extensions, context, materials[i], materialInfo);
|
|
1700
|
-
}
|
|
1701
|
-
materialsPromiseInfo.resolve(materials);
|
|
1702
|
-
return materialsPromiseInfo.promise;
|
|
1703
|
-
});
|
|
1704
|
-
};
|
|
1705
|
-
/**
|
|
1706
|
-
* @internal
|
|
1707
|
-
*/ GLTFMaterialParser._checkOtherTextureTransform = function _checkOtherTextureTransform(texture, textureName) {
|
|
1708
|
-
var _texture_extensions;
|
|
1709
|
-
if ((_texture_extensions = texture.extensions) == null ? void 0 : _texture_extensions.KHR_texture_transform) {
|
|
1710
|
-
miniprogram.Logger.warn("" + textureName + " texture always use the KHR_texture_transform of the base texture.");
|
|
1711
|
-
}
|
|
1712
|
-
};
|
|
1713
|
-
/**
|
|
1714
|
-
* @internal
|
|
1715
|
-
*/ GLTFMaterialParser._parseStandardProperty = function _parseStandardProperty(context, material, materialInfo) {
|
|
1716
|
-
var textures = context.glTFResource.textures;
|
|
1717
|
-
var pbrMetallicRoughness = materialInfo.pbrMetallicRoughness, normalTexture = materialInfo.normalTexture, occlusionTexture = materialInfo.occlusionTexture, emissiveTexture = materialInfo.emissiveTexture, emissiveFactor = materialInfo.emissiveFactor, alphaMode = materialInfo.alphaMode, alphaCutoff = materialInfo.alphaCutoff, doubleSided = materialInfo.doubleSided;
|
|
1718
|
-
if (pbrMetallicRoughness) {
|
|
1719
|
-
var baseColorFactor = pbrMetallicRoughness.baseColorFactor, baseColorTexture = pbrMetallicRoughness.baseColorTexture, metallicFactor = pbrMetallicRoughness.metallicFactor, roughnessFactor = pbrMetallicRoughness.roughnessFactor, metallicRoughnessTexture = pbrMetallicRoughness.metallicRoughnessTexture;
|
|
1720
|
-
if (baseColorFactor) {
|
|
1721
|
-
material.baseColor = new miniprogram$1.Color(miniprogram$1.Color.linearToGammaSpace(baseColorFactor[0]), miniprogram$1.Color.linearToGammaSpace(baseColorFactor[1]), miniprogram$1.Color.linearToGammaSpace(baseColorFactor[2]), baseColorFactor[3]);
|
|
1722
|
-
}
|
|
1723
|
-
if (baseColorTexture) {
|
|
1724
|
-
material.baseTexture = textures[baseColorTexture.index];
|
|
1725
|
-
GLTFParser.executeExtensionsAdditiveAndParse(baseColorTexture.extensions, context, material, baseColorTexture);
|
|
1726
|
-
}
|
|
1727
|
-
if (material.constructor === miniprogram.PBRMaterial) {
|
|
1728
|
-
material.metallic = metallicFactor != null ? metallicFactor : 1;
|
|
1729
|
-
material.roughness = roughnessFactor != null ? roughnessFactor : 1;
|
|
1730
|
-
if (metallicRoughnessTexture) {
|
|
1731
|
-
material.roughnessMetallicTexture = textures[metallicRoughnessTexture.index];
|
|
1732
|
-
GLTFMaterialParser._checkOtherTextureTransform(metallicRoughnessTexture, "Roughness metallic");
|
|
1733
|
-
}
|
|
1734
|
-
}
|
|
1735
|
-
}
|
|
1736
|
-
if (material.constructor === miniprogram.PBRMaterial || material.constructor === miniprogram.PBRSpecularMaterial) {
|
|
1737
|
-
if (emissiveTexture) {
|
|
1738
|
-
material.emissiveTexture = textures[emissiveTexture.index];
|
|
1739
|
-
GLTFMaterialParser._checkOtherTextureTransform(emissiveTexture, "Emissive");
|
|
1740
|
-
}
|
|
1741
|
-
if (emissiveFactor) {
|
|
1742
|
-
material.emissiveColor = new miniprogram$1.Color(miniprogram$1.Color.linearToGammaSpace(emissiveFactor[0]), miniprogram$1.Color.linearToGammaSpace(emissiveFactor[1]), miniprogram$1.Color.linearToGammaSpace(emissiveFactor[2]));
|
|
1743
|
-
}
|
|
1744
|
-
if (normalTexture) {
|
|
1745
|
-
var index = normalTexture.index, scale = normalTexture.scale;
|
|
1746
|
-
material.normalTexture = textures[index];
|
|
1747
|
-
GLTFMaterialParser._checkOtherTextureTransform(normalTexture, "Normal");
|
|
1748
|
-
if (scale !== undefined) {
|
|
1749
|
-
material.normalTextureIntensity = scale;
|
|
1750
|
-
}
|
|
1751
|
-
}
|
|
1752
|
-
if (occlusionTexture) {
|
|
1753
|
-
var index1 = occlusionTexture.index, strength = occlusionTexture.strength, texCoord = occlusionTexture.texCoord;
|
|
1754
|
-
material.occlusionTexture = textures[index1];
|
|
1755
|
-
GLTFMaterialParser._checkOtherTextureTransform(occlusionTexture, "Occlusion");
|
|
1756
|
-
if (strength !== undefined) {
|
|
1757
|
-
material.occlusionTextureIntensity = strength;
|
|
1758
|
-
}
|
|
1759
|
-
if (texCoord === miniprogram.TextureCoordinate.UV1) {
|
|
1760
|
-
material.occlusionTextureCoord = miniprogram.TextureCoordinate.UV1;
|
|
1761
|
-
} else if (texCoord > miniprogram.TextureCoordinate.UV1) {
|
|
1762
|
-
miniprogram.Logger.warn("Occlusion texture uv coordinate must be UV0 or UV1.");
|
|
1763
|
-
}
|
|
1764
|
-
}
|
|
1765
|
-
}
|
|
1766
|
-
if (doubleSided) {
|
|
1767
|
-
material.renderFace = miniprogram.RenderFace.Double;
|
|
1768
|
-
} else {
|
|
1769
|
-
material.renderFace = miniprogram.RenderFace.Front;
|
|
1770
|
-
}
|
|
1771
|
-
switch(alphaMode){
|
|
1772
|
-
case MaterialAlphaMode.OPAQUE:
|
|
1773
|
-
material.isTransparent = false;
|
|
1774
|
-
break;
|
|
1775
|
-
case MaterialAlphaMode.BLEND:
|
|
1776
|
-
material.isTransparent = true;
|
|
1777
|
-
break;
|
|
1778
|
-
case MaterialAlphaMode.MASK:
|
|
1779
|
-
material.alphaCutoff = alphaCutoff != null ? alphaCutoff : 0.5;
|
|
1780
|
-
break;
|
|
1781
|
-
}
|
|
1782
|
-
};
|
|
1783
|
-
return GLTFMaterialParser;
|
|
1784
|
-
}(GLTFParser);
|
|
1785
|
-
|
|
1786
|
-
function _instanceof(left, right) {
|
|
1787
|
-
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
1788
|
-
return !!right[Symbol.hasInstance](left);
|
|
1789
|
-
} else {
|
|
1790
|
-
return left instanceof right;
|
|
1791
|
-
}
|
|
1792
|
-
}
|
|
1793
|
-
|
|
1794
|
-
var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
1795
|
-
_inherits(GLTFMeshParser, GLTFParser1);
|
|
1796
|
-
function GLTFMeshParser() {
|
|
1797
|
-
return GLTFParser1.apply(this, arguments);
|
|
1798
|
-
}
|
|
1799
|
-
var _proto = GLTFMeshParser.prototype;
|
|
1800
|
-
_proto.parse = function parse(context) {
|
|
1801
|
-
var _loop = function(i) {
|
|
1802
|
-
var _loop = function(j) {
|
|
1803
|
-
var gltfPrimitive = gltfMesh.primitives[j];
|
|
1804
|
-
primitivePromises[j] = new Promise(function(resolve) {
|
|
1805
|
-
var mesh = GLTFParser.executeExtensionsCreateAndParse(gltfPrimitive.extensions, context, gltfPrimitive, gltfMesh);
|
|
1806
|
-
if (mesh) {
|
|
1807
|
-
if (_instanceof(mesh, miniprogram.ModelMesh)) {
|
|
1808
|
-
resolve(mesh);
|
|
1809
|
-
} else {
|
|
1810
|
-
mesh.then(function(mesh) {
|
|
1811
|
-
return resolve(mesh);
|
|
1812
|
-
});
|
|
1813
|
-
}
|
|
1814
|
-
} else {
|
|
1815
|
-
var mesh1 = new miniprogram.ModelMesh(engine, gltfMesh.name || j + "");
|
|
1816
|
-
var meshRestoreInfo = new ModelMeshRestoreInfo();
|
|
1817
|
-
meshRestoreInfo.mesh = mesh1;
|
|
1818
|
-
context.contentRestorer.meshes.push(meshRestoreInfo);
|
|
1819
|
-
GLTFMeshParser._parseMeshFromGLTFPrimitive(context, mesh1, meshRestoreInfo, gltfMesh, gltfPrimitive, glTF, function(attributeSemantic) {
|
|
1820
|
-
return null;
|
|
1821
|
-
}, function(attributeName, shapeIndex) {
|
|
1822
|
-
var shapeAccessorIdx = gltfPrimitive.targets[shapeIndex];
|
|
1823
|
-
var attributeAccessorIdx = shapeAccessorIdx[attributeName];
|
|
1824
|
-
if (attributeAccessorIdx) {
|
|
1825
|
-
var accessor = glTF.accessors[attributeAccessorIdx];
|
|
1826
|
-
return GLTFUtil.getAccessorBuffer(context, context.glTF.bufferViews, accessor);
|
|
1827
|
-
} else {
|
|
1828
|
-
return null;
|
|
1829
|
-
}
|
|
1830
|
-
}, function() {
|
|
1831
|
-
var indexAccessor = glTF.accessors[gltfPrimitive.indices];
|
|
1832
|
-
return GLTFUtil.getAccessorData(glTF, indexAccessor, buffers);
|
|
1833
|
-
}, context.keepMeshData).then(resolve);
|
|
1834
|
-
}
|
|
1835
|
-
});
|
|
1836
|
-
};
|
|
1837
|
-
var gltfMesh = glTF.meshes[i];
|
|
1838
|
-
var primitivePromises = [];
|
|
1839
|
-
for(var j = 0; j < gltfMesh.primitives.length; j++)_loop(j);
|
|
1840
|
-
meshPromises[i] = Promise.all(primitivePromises);
|
|
1841
|
-
};
|
|
1842
|
-
var glTF = context.glTF, buffers = context.buffers, glTFResource = context.glTFResource;
|
|
1843
|
-
var engine = glTFResource.engine;
|
|
1844
|
-
if (!glTF.meshes) return;
|
|
1792
|
+
if (!gltf.meshes) return;
|
|
1845
1793
|
var meshesPromiseInfo = context.meshesPromiseInfo;
|
|
1846
1794
|
var meshPromises = [];
|
|
1847
|
-
for(var i = 0; i <
|
|
1795
|
+
for(var i = 0; i < gltf.meshes.length; i++)_loop(i);
|
|
1848
1796
|
miniprogram.AssetPromise.all(meshPromises).then(function(meshes) {
|
|
1849
1797
|
glTFResource.meshes = meshes;
|
|
1850
1798
|
meshesPromiseInfo.resolve(meshes);
|
|
1851
1799
|
}).catch(meshesPromiseInfo.reject);
|
|
1852
1800
|
return meshesPromiseInfo.promise;
|
|
1853
1801
|
};
|
|
1854
|
-
|
|
1855
|
-
* @internal
|
|
1856
|
-
*/ GLTFMeshParser._parseMeshFromGLTFPrimitive = function _parseMeshFromGLTFPrimitive(context, mesh, meshRestoreInfo, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
|
|
1802
|
+
_proto._parseMeshFromGLTFPrimitive = function _parseMeshFromGLTFPrimitive(context, mesh, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
|
|
1857
1803
|
var accessors = gltf.accessors;
|
|
1858
1804
|
context.buffers;
|
|
1859
1805
|
var attributes = gltfPrimitive.attributes, targets = gltfPrimitive.targets, indices = gltfPrimitive.indices, mode = gltfPrimitive.mode;
|
|
@@ -1861,16 +1807,18 @@ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
1861
1807
|
var vertexElements = new Array();
|
|
1862
1808
|
var vertexCount;
|
|
1863
1809
|
var bufferBindIndex = 0;
|
|
1810
|
+
var positions;
|
|
1811
|
+
keepMeshData && (positions = new Array(vertexCount));
|
|
1864
1812
|
for(var attribute in attributes){
|
|
1865
1813
|
var accessor = accessors[attributes[attribute]];
|
|
1866
|
-
var accessorBuffer = GLTFUtil.getAccessorBuffer(context, gltf
|
|
1867
|
-
var
|
|
1814
|
+
var accessorBuffer = GLTFUtil.getAccessorBuffer(context, gltf, accessor);
|
|
1815
|
+
var dataElmentSize = GLTFUtil.getAccessorTypeSize(accessor.type);
|
|
1868
1816
|
var attributeCount = accessor.count;
|
|
1869
1817
|
var vertices = accessorBuffer.data;
|
|
1870
1818
|
var vertexElement = void 0;
|
|
1871
1819
|
var meshId = mesh.instanceId;
|
|
1872
1820
|
var vertexBindingInfos = accessorBuffer.vertexBindingInfos;
|
|
1873
|
-
var elementFormat = GLTFUtil.getElementFormat(accessor.componentType,
|
|
1821
|
+
var elementFormat = GLTFUtil.getElementFormat(accessor.componentType, dataElmentSize, accessor.normalized);
|
|
1874
1822
|
if (accessorBuffer.interleaved) {
|
|
1875
1823
|
var byteOffset = accessor.byteOffset || 0;
|
|
1876
1824
|
var stride = accessorBuffer.stride;
|
|
@@ -1882,7 +1830,6 @@ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
1882
1830
|
vertexBuffer = new miniprogram.Buffer(engine, miniprogram.BufferBindFlag.VertexBuffer, vertices.byteLength, miniprogram.BufferUsage.Static);
|
|
1883
1831
|
vertexBuffer.setData(vertices);
|
|
1884
1832
|
accessorBuffer.vertexBuffer = vertexBuffer;
|
|
1885
|
-
meshRestoreInfo.vertexBuffers.push(new BufferRestoreInfo(vertexBuffer, accessorBuffer.restoreInfo));
|
|
1886
1833
|
}
|
|
1887
1834
|
mesh.setVertexBufferBinding(vertexBuffer, stride, bufferBindIndex);
|
|
1888
1835
|
vertexBindingInfos[meshId] = bufferBindIndex++;
|
|
@@ -1893,7 +1840,6 @@ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
1893
1840
|
vertexElement = new miniprogram.VertexElement(attribute, 0, elementFormat, bufferBindIndex);
|
|
1894
1841
|
var vertexBuffer1 = new miniprogram.Buffer(engine, miniprogram.BufferBindFlag.VertexBuffer, vertices.byteLength, miniprogram.BufferUsage.Static);
|
|
1895
1842
|
vertexBuffer1.setData(vertices);
|
|
1896
|
-
meshRestoreInfo.vertexBuffers.push(new BufferRestoreInfo(vertexBuffer1, accessorBuffer.restoreInfo));
|
|
1897
1843
|
mesh.setVertexBufferBinding(vertexBuffer1, accessorBuffer.stride, bufferBindIndex);
|
|
1898
1844
|
vertexBindingInfos[meshId] = bufferBindIndex++;
|
|
1899
1845
|
}
|
|
@@ -1904,22 +1850,30 @@ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
1904
1850
|
if (accessor.min && accessor.max) {
|
|
1905
1851
|
min.copyFromArray(accessor.min);
|
|
1906
1852
|
max.copyFromArray(accessor.max);
|
|
1853
|
+
if (keepMeshData) {
|
|
1854
|
+
var stride1 = vertices.length / attributeCount;
|
|
1855
|
+
for(var j = 0; j < attributeCount; j++){
|
|
1856
|
+
var offset = j * stride1;
|
|
1857
|
+
positions[j] = new miniprogram$1.Vector3(vertices[offset], vertices[offset + 1], vertices[offset + 2]);
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1907
1860
|
} else {
|
|
1908
|
-
var position =
|
|
1861
|
+
var position = MeshParser._tempVector3;
|
|
1909
1862
|
min.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
|
|
1910
1863
|
max.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
|
|
1911
|
-
var
|
|
1912
|
-
for(var
|
|
1913
|
-
var
|
|
1914
|
-
position.copyFromArray(vertices,
|
|
1864
|
+
var stride2 = vertices.length / attributeCount;
|
|
1865
|
+
for(var j1 = 0; j1 < attributeCount; j1++){
|
|
1866
|
+
var offset1 = j1 * stride2;
|
|
1867
|
+
position.copyFromArray(vertices, offset1);
|
|
1915
1868
|
miniprogram$1.Vector3.min(min, position, min);
|
|
1916
1869
|
miniprogram$1.Vector3.max(max, position, max);
|
|
1870
|
+
keepMeshData && (positions[j1] = position.clone());
|
|
1917
1871
|
}
|
|
1918
1872
|
}
|
|
1919
1873
|
if (accessor.normalized) {
|
|
1920
|
-
var
|
|
1921
|
-
min.scale(
|
|
1922
|
-
max.scale(
|
|
1874
|
+
var sacleFactor = GLTFUtil.getNormalizedComponentScale(accessor.componentType);
|
|
1875
|
+
min.scale(sacleFactor);
|
|
1876
|
+
max.scale(sacleFactor);
|
|
1923
1877
|
}
|
|
1924
1878
|
}
|
|
1925
1879
|
}
|
|
@@ -1927,68 +1881,179 @@ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
1927
1881
|
// Indices
|
|
1928
1882
|
if (indices !== undefined) {
|
|
1929
1883
|
var indexAccessor = gltf.accessors[indices];
|
|
1930
|
-
var
|
|
1931
|
-
mesh.setIndices(
|
|
1884
|
+
var indexData = getIndexBufferData();
|
|
1885
|
+
mesh.setIndices(indexData);
|
|
1932
1886
|
mesh.addSubMesh(0, indexAccessor.count, mode);
|
|
1933
|
-
meshRestoreInfo.indexBuffer = accessorBuffer1.restoreInfo;
|
|
1934
1887
|
} else {
|
|
1935
1888
|
mesh.addSubMesh(0, vertexCount, mode);
|
|
1936
1889
|
}
|
|
1937
1890
|
// BlendShapes
|
|
1938
|
-
targets &&
|
|
1891
|
+
targets && this._createBlendShape(mesh, gltfMesh, targets, getBlendShapeData);
|
|
1939
1892
|
mesh.uploadData(!keepMeshData);
|
|
1893
|
+
//@ts-ignore
|
|
1894
|
+
mesh._positions = positions;
|
|
1940
1895
|
return Promise.resolve(mesh);
|
|
1941
1896
|
};
|
|
1942
|
-
|
|
1943
|
-
* @internal
|
|
1944
|
-
*/ GLTFMeshParser._createBlendShape = function _createBlendShape(mesh, meshRestoreInfo, glTFMesh, glTFTargets, getBlendShapeData) {
|
|
1897
|
+
_proto._createBlendShape = function _createBlendShape(mesh, glTFMesh, glTFTargets, getBlendShapeData) {
|
|
1945
1898
|
var blendShapeNames = glTFMesh.extras ? glTFMesh.extras.targetNames : null;
|
|
1946
1899
|
for(var i = 0, n = glTFTargets.length; i < n; i++){
|
|
1947
1900
|
var name = blendShapeNames ? blendShapeNames[i] : "blendShape" + i;
|
|
1948
|
-
var
|
|
1949
|
-
var
|
|
1950
|
-
var
|
|
1951
|
-
var deltaPositions =
|
|
1952
|
-
var deltaNormals =
|
|
1953
|
-
var deltaTangents =
|
|
1901
|
+
var deltaPosBuffer = getBlendShapeData("POSITION", i);
|
|
1902
|
+
var deltaNorBuffer = getBlendShapeData("NORMAL", i);
|
|
1903
|
+
var deltaTanBuffer = getBlendShapeData("TANGENT", i);
|
|
1904
|
+
var deltaPositions = deltaPosBuffer ? GLTFUtil.floatBufferToVector3Array(deltaPosBuffer) : null;
|
|
1905
|
+
var deltaNormals = deltaNorBuffer ? GLTFUtil.floatBufferToVector3Array(deltaNorBuffer) : null;
|
|
1906
|
+
var deltaTangents = deltaTanBuffer ? GLTFUtil.floatBufferToVector3Array(deltaTanBuffer) : null;
|
|
1954
1907
|
var blendShape = new miniprogram.BlendShape(name);
|
|
1955
1908
|
blendShape.addFrame(1.0, deltaPositions, deltaNormals, deltaTangents);
|
|
1956
1909
|
mesh.addBlendShape(blendShape);
|
|
1957
|
-
meshRestoreInfo.blendShapes.push(new BlendShapeRestoreInfo(blendShape, deltaPosBufferInfo.restoreInfo, deltaNorBufferInfo == null ? void 0 : deltaNorBufferInfo.restoreInfo, deltaTanBufferInfo == null ? void 0 : deltaTanBufferInfo.restoreInfo));
|
|
1958
1910
|
}
|
|
1959
1911
|
};
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1912
|
+
/**
|
|
1913
|
+
* @deprecated
|
|
1914
|
+
*/ _proto._parseMeshFromGLTFPrimitiveDraco = function _parseMeshFromGLTFPrimitiveDraco(mesh, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
|
|
1915
|
+
var attributes = gltfPrimitive.attributes, targets = gltfPrimitive.targets, indices = gltfPrimitive.indices, mode = gltfPrimitive.mode;
|
|
1916
|
+
var vertexCount;
|
|
1917
|
+
var accessors = gltf.accessors;
|
|
1918
|
+
var accessor = accessors[attributes["POSITION"]];
|
|
1919
|
+
var positionBuffer = getVertexBufferData("POSITION");
|
|
1920
|
+
var positions = GLTFUtil.floatBufferToVector3Array(positionBuffer);
|
|
1921
|
+
mesh.setPositions(positions);
|
|
1922
|
+
var bounds = mesh.bounds;
|
|
1923
|
+
vertexCount = accessor.count;
|
|
1924
|
+
if (accessor.min && accessor.max) {
|
|
1925
|
+
bounds.min.copyFromArray(accessor.min);
|
|
1926
|
+
bounds.max.copyFromArray(accessor.max);
|
|
1927
|
+
} else {
|
|
1928
|
+
var position = MeshParser._tempVector3;
|
|
1929
|
+
var min = bounds.min, max = bounds.max;
|
|
1930
|
+
min.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
|
|
1931
|
+
max.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
|
|
1932
|
+
var stride = positionBuffer.length / vertexCount;
|
|
1933
|
+
for(var j = 0; j < vertexCount; j++){
|
|
1934
|
+
var offset = j * stride;
|
|
1935
|
+
position.copyFromArray(positionBuffer, offset);
|
|
1936
|
+
miniprogram$1.Vector3.min(min, position, min);
|
|
1937
|
+
miniprogram$1.Vector3.max(max, position, max);
|
|
1938
|
+
}
|
|
1939
|
+
}
|
|
1940
|
+
for(var attributeSemantic in attributes){
|
|
1941
|
+
if (attributeSemantic === "POSITION") {
|
|
1942
|
+
continue;
|
|
1943
|
+
}
|
|
1944
|
+
var bufferData = getVertexBufferData(attributeSemantic);
|
|
1945
|
+
switch(attributeSemantic){
|
|
1946
|
+
case "NORMAL":
|
|
1947
|
+
var normals = GLTFUtil.floatBufferToVector3Array(bufferData);
|
|
1948
|
+
mesh.setNormals(normals);
|
|
1949
|
+
break;
|
|
1950
|
+
case "TEXCOORD_0":
|
|
1951
|
+
var texturecoords = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
1952
|
+
mesh.setUVs(texturecoords, 0);
|
|
1953
|
+
break;
|
|
1954
|
+
case "TEXCOORD_1":
|
|
1955
|
+
var texturecoords1 = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
1956
|
+
mesh.setUVs(texturecoords1, 1);
|
|
1957
|
+
break;
|
|
1958
|
+
case "TEXCOORD_2":
|
|
1959
|
+
var texturecoords2 = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
1960
|
+
mesh.setUVs(texturecoords2, 2);
|
|
1961
|
+
break;
|
|
1962
|
+
case "TEXCOORD_3":
|
|
1963
|
+
var texturecoords3 = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
1964
|
+
mesh.setUVs(texturecoords3, 3);
|
|
1965
|
+
break;
|
|
1966
|
+
case "TEXCOORD_4":
|
|
1967
|
+
var texturecoords4 = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
1968
|
+
mesh.setUVs(texturecoords4, 4);
|
|
1969
|
+
break;
|
|
1970
|
+
case "TEXCOORD_5":
|
|
1971
|
+
var texturecoords5 = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
1972
|
+
mesh.setUVs(texturecoords5, 5);
|
|
1973
|
+
break;
|
|
1974
|
+
case "TEXCOORD_6":
|
|
1975
|
+
var texturecoords6 = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
1976
|
+
mesh.setUVs(texturecoords6, 6);
|
|
1977
|
+
break;
|
|
1978
|
+
case "TEXCOORD_7":
|
|
1979
|
+
var texturecoords7 = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
1980
|
+
mesh.setUVs(texturecoords7, 7);
|
|
1981
|
+
break;
|
|
1982
|
+
case "COLOR_0":
|
|
1983
|
+
var colors = GLTFUtil.floatBufferToColorArray(bufferData, accessors[attributes["COLOR_0"]].type === AccessorType.VEC3);
|
|
1984
|
+
mesh.setColors(colors);
|
|
1985
|
+
break;
|
|
1986
|
+
case "TANGENT":
|
|
1987
|
+
var tangents = GLTFUtil.floatBufferToVector4Array(bufferData);
|
|
1988
|
+
mesh.setTangents(tangents);
|
|
1989
|
+
break;
|
|
1990
|
+
case "JOINTS_0":
|
|
1991
|
+
var joints = GLTFUtil.floatBufferToVector4Array(bufferData);
|
|
1992
|
+
mesh.setBoneIndices(joints);
|
|
1993
|
+
break;
|
|
1994
|
+
case "WEIGHTS_0":
|
|
1995
|
+
var weights = GLTFUtil.floatBufferToVector4Array(bufferData);
|
|
1996
|
+
mesh.setBoneWeights(weights);
|
|
1997
|
+
break;
|
|
1998
|
+
}
|
|
1999
|
+
}
|
|
2000
|
+
// Indices
|
|
2001
|
+
if (indices !== undefined) {
|
|
2002
|
+
var indexAccessor = gltf.accessors[indices];
|
|
2003
|
+
var indexData = getIndexBufferData();
|
|
2004
|
+
mesh.setIndices(indexData);
|
|
2005
|
+
mesh.addSubMesh(0, indexAccessor.count, mode);
|
|
2006
|
+
} else {
|
|
2007
|
+
mesh.addSubMesh(0, vertexCount, mode);
|
|
2008
|
+
}
|
|
2009
|
+
// BlendShapes
|
|
2010
|
+
targets && this._createBlendShape(mesh, gltfMesh, targets, getBlendShapeData);
|
|
2011
|
+
mesh.uploadData(!keepMeshData);
|
|
2012
|
+
return Promise.resolve(mesh);
|
|
2013
|
+
};
|
|
2014
|
+
return MeshParser;
|
|
2015
|
+
}(Parser);
|
|
2016
|
+
(function() {
|
|
2017
|
+
MeshParser._tempVector3 = new miniprogram$1.Vector3();
|
|
2018
|
+
})();
|
|
1963
2019
|
|
|
1964
|
-
var
|
|
1965
|
-
_inherits(
|
|
1966
|
-
function
|
|
1967
|
-
return
|
|
2020
|
+
var SceneParser$1 = /*#__PURE__*/ function(Parser1) {
|
|
2021
|
+
_inherits(SceneParser, Parser1);
|
|
2022
|
+
function SceneParser() {
|
|
2023
|
+
return Parser1.apply(this, arguments);
|
|
1968
2024
|
}
|
|
1969
|
-
var _proto =
|
|
2025
|
+
var _proto = SceneParser.prototype;
|
|
1970
2026
|
_proto.parse = function parse(context) {
|
|
1971
|
-
var glTFResource = context.glTFResource,
|
|
2027
|
+
var glTFResource = context.glTFResource, gltf = context.gltf;
|
|
1972
2028
|
var entities = glTFResource.entities;
|
|
1973
|
-
var nodes =
|
|
2029
|
+
var nodes = gltf.nodes, gltfCameras = gltf.cameras;
|
|
1974
2030
|
if (!nodes) return;
|
|
1975
2031
|
var defaultSceneRootPromiseInfo = context.defaultSceneRootPromiseInfo;
|
|
2032
|
+
var promises = [];
|
|
1976
2033
|
for(var i = 0; i < nodes.length; i++){
|
|
1977
|
-
var
|
|
1978
|
-
var cameraID =
|
|
2034
|
+
var gltfNode = nodes[i];
|
|
2035
|
+
var cameraID = gltfNode.camera, meshID = gltfNode.mesh, _gltfNode_extensions = gltfNode.extensions, extensions = _gltfNode_extensions === void 0 ? {} : _gltfNode_extensions;
|
|
2036
|
+
var KHR_lights_punctual = extensions.KHR_lights_punctual;
|
|
1979
2037
|
var entity = entities[i];
|
|
1980
2038
|
if (cameraID !== undefined) {
|
|
1981
|
-
this._createCamera(glTFResource,
|
|
2039
|
+
this._createCamera(glTFResource, gltfCameras[cameraID], entity);
|
|
1982
2040
|
}
|
|
1983
2041
|
if (meshID !== undefined) {
|
|
1984
|
-
this._createRenderer(context,
|
|
2042
|
+
promises.push(this._createRenderer(context, gltfNode, entity));
|
|
2043
|
+
}
|
|
2044
|
+
if (KHR_lights_punctual) {
|
|
2045
|
+
var lightIndex = KHR_lights_punctual.light;
|
|
2046
|
+
var lights = gltf.extensions.KHR_lights_punctual.lights;
|
|
2047
|
+
Parser.parseEngineResource("KHR_lights_punctual", lights[lightIndex], entity, context);
|
|
1985
2048
|
}
|
|
1986
|
-
GLTFParser.executeExtensionsAdditiveAndParse(extensions, context, entity, glTFNode);
|
|
1987
2049
|
}
|
|
1988
2050
|
if (glTFResource.defaultSceneRoot) {
|
|
1989
2051
|
this._createAnimator(context);
|
|
1990
2052
|
}
|
|
1991
|
-
|
|
2053
|
+
gltf.extensions && delete gltf.extensions["OASIS_materials_remap"];
|
|
2054
|
+
miniprogram.AssetPromise.all(promises).then(function() {
|
|
2055
|
+
return defaultSceneRootPromiseInfo.resolve(glTFResource.defaultSceneRoot);
|
|
2056
|
+
}).catch(defaultSceneRootPromiseInfo.reject);
|
|
1992
2057
|
return defaultSceneRootPromiseInfo.promise;
|
|
1993
2058
|
};
|
|
1994
2059
|
_proto._createCamera = function _createCamera(context, cameraSchema, entity) {
|
|
@@ -2024,16 +2089,8 @@ var GLTFSceneParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
2024
2089
|
// @todo: use engine camera by default
|
|
2025
2090
|
camera.enabled = false;
|
|
2026
2091
|
};
|
|
2027
|
-
_proto._createRenderer = function _createRenderer(context,
|
|
2028
|
-
var
|
|
2029
|
-
var glTFMeshes = glTF.meshes;
|
|
2030
|
-
var engine = glTFResource.engine, meshes = glTFResource.meshes, materials = glTFResource.materials, skins = glTFResource.skins;
|
|
2031
|
-
var meshID = glTFNode.mesh, skinID = glTFNode.skin;
|
|
2032
|
-
var glTFMesh = glTFMeshes[meshID];
|
|
2033
|
-
var glTFMeshPrimitives = glTFMesh.primitives;
|
|
2034
|
-
var blendShapeWeights = glTFNode.weights || glTFMesh.weights;
|
|
2035
|
-
for(var i = 0; i < glTFMeshPrimitives.length; i++){
|
|
2036
|
-
var gltfPrimitive = glTFMeshPrimitives[i];
|
|
2092
|
+
_proto._createRenderer = function _createRenderer(context, gltfNode, entity) {
|
|
2093
|
+
var _loop = function(i) {
|
|
2037
2094
|
var mesh = meshes[meshID][i];
|
|
2038
2095
|
var renderer = void 0;
|
|
2039
2096
|
if (skinID !== undefined || blendShapeWeights) {
|
|
@@ -2051,11 +2108,32 @@ var GLTFSceneParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
2051
2108
|
renderer = entity.addComponent(miniprogram.MeshRenderer);
|
|
2052
2109
|
renderer.mesh = mesh;
|
|
2053
2110
|
}
|
|
2054
|
-
var materialIndex =
|
|
2055
|
-
var
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2111
|
+
var materialIndex = gltfMeshPrimitives[i].material;
|
|
2112
|
+
var remapMaterials = gltf.extensions && gltf.extensions["OASIS_materials_remap"];
|
|
2113
|
+
if (remapMaterials && remapMaterials[materialIndex]) {
|
|
2114
|
+
promises.push(remapMaterials[materialIndex].then(function(mtl) {
|
|
2115
|
+
renderer.setMaterial(mtl);
|
|
2116
|
+
}));
|
|
2117
|
+
} else {
|
|
2118
|
+
var material = (materials == null ? void 0 : materials[materialIndex]) || SceneParser._getDefaultMaterial(engine);
|
|
2119
|
+
renderer.setMaterial(material);
|
|
2120
|
+
}
|
|
2121
|
+
var _gltfMeshPrimitives_i = gltfMeshPrimitives[i], _gltfMeshPrimitives_i_extensions = _gltfMeshPrimitives_i.extensions, extensions = _gltfMeshPrimitives_i_extensions === void 0 ? {} : _gltfMeshPrimitives_i_extensions;
|
|
2122
|
+
var KHR_materials_variants = extensions.KHR_materials_variants;
|
|
2123
|
+
if (KHR_materials_variants) {
|
|
2124
|
+
Parser.parseEngineResource("KHR_materials_variants", KHR_materials_variants, renderer, context);
|
|
2125
|
+
}
|
|
2126
|
+
};
|
|
2127
|
+
var glTFResource = context.glTFResource, gltf = context.gltf;
|
|
2128
|
+
var gltfMeshes = gltf.meshes;
|
|
2129
|
+
var engine = glTFResource.engine, meshes = glTFResource.meshes, materials = glTFResource.materials, skins = glTFResource.skins;
|
|
2130
|
+
var meshID = gltfNode.mesh, skinID = gltfNode.skin;
|
|
2131
|
+
var glTFMesh = gltfMeshes[meshID];
|
|
2132
|
+
var gltfMeshPrimitives = glTFMesh.primitives;
|
|
2133
|
+
var blendShapeWeights = gltfNode.weights || glTFMesh.weights;
|
|
2134
|
+
var promises = [];
|
|
2135
|
+
for(var i = 0; i < gltfMeshPrimitives.length; i++)_loop(i);
|
|
2136
|
+
return Promise.all(promises);
|
|
2059
2137
|
};
|
|
2060
2138
|
_proto._createAnimator = function _createAnimator(context) {
|
|
2061
2139
|
if (!context.hasSkinned && !context.glTFResource.animations) {
|
|
@@ -2082,25 +2160,25 @@ var GLTFSceneParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
2082
2160
|
}
|
|
2083
2161
|
}
|
|
2084
2162
|
};
|
|
2085
|
-
|
|
2086
|
-
if (!
|
|
2087
|
-
|
|
2163
|
+
SceneParser._getDefaultMaterial = function _getDefaultMaterial(engine) {
|
|
2164
|
+
if (!SceneParser._defaultMaterial) {
|
|
2165
|
+
SceneParser._defaultMaterial = new miniprogram.BlinnPhongMaterial(engine);
|
|
2088
2166
|
}
|
|
2089
|
-
return
|
|
2167
|
+
return SceneParser._defaultMaterial;
|
|
2090
2168
|
};
|
|
2091
|
-
return
|
|
2092
|
-
}(
|
|
2169
|
+
return SceneParser;
|
|
2170
|
+
}(Parser);
|
|
2093
2171
|
|
|
2094
|
-
var
|
|
2095
|
-
_inherits(
|
|
2096
|
-
function
|
|
2097
|
-
return
|
|
2172
|
+
var SkinParser = /*#__PURE__*/ function(Parser) {
|
|
2173
|
+
_inherits(SkinParser, Parser);
|
|
2174
|
+
function SkinParser() {
|
|
2175
|
+
return Parser.apply(this, arguments);
|
|
2098
2176
|
}
|
|
2099
|
-
var _proto =
|
|
2177
|
+
var _proto = SkinParser.prototype;
|
|
2100
2178
|
_proto.parse = function parse(context) {
|
|
2101
|
-
var glTFResource = context.glTFResource,
|
|
2179
|
+
var glTFResource = context.glTFResource, gltf = context.gltf; context.buffers;
|
|
2102
2180
|
var entities = glTFResource.entities;
|
|
2103
|
-
var gltfSkins =
|
|
2181
|
+
var gltfSkins = gltf.skins;
|
|
2104
2182
|
if (!gltfSkins) return;
|
|
2105
2183
|
var count = gltfSkins.length;
|
|
2106
2184
|
var skins = new Array(count);
|
|
@@ -2110,8 +2188,8 @@ var GLTFSkinParser = /*#__PURE__*/ function(GLTFParser) {
|
|
|
2110
2188
|
var skin = new miniprogram.Skin(name);
|
|
2111
2189
|
skin.inverseBindMatrices.length = jointCount;
|
|
2112
2190
|
// parse IBM
|
|
2113
|
-
var accessor =
|
|
2114
|
-
var buffer = GLTFUtil.getAccessorBuffer(context,
|
|
2191
|
+
var accessor = gltf.accessors[inverseBindMatrices];
|
|
2192
|
+
var buffer = GLTFUtil.getAccessorBuffer(context, gltf, accessor).data;
|
|
2115
2193
|
for(var i1 = 0; i1 < jointCount; i1++){
|
|
2116
2194
|
var inverseBindMatrix = new miniprogram$1.Matrix();
|
|
2117
2195
|
inverseBindMatrix.copyFromArray(buffer, i1 * 16);
|
|
@@ -2146,7 +2224,7 @@ var GLTFSkinParser = /*#__PURE__*/ function(GLTFParser) {
|
|
|
2146
2224
|
};
|
|
2147
2225
|
_proto._findSkeletonRootBone = function _findSkeletonRootBone(joints, entities) {
|
|
2148
2226
|
var paths = {};
|
|
2149
|
-
for(var _iterator =
|
|
2227
|
+
for(var _iterator = _create_for_of_iterator_helper_loose(joints), _step; !(_step = _iterator()).done;){
|
|
2150
2228
|
var index = _step.value;
|
|
2151
2229
|
var path = new Array();
|
|
2152
2230
|
var entity = entities[index];
|
|
@@ -2172,24 +2250,24 @@ var GLTFSkinParser = /*#__PURE__*/ function(GLTFParser) {
|
|
|
2172
2250
|
rootNode = entity1;
|
|
2173
2251
|
}
|
|
2174
2252
|
};
|
|
2175
|
-
return
|
|
2176
|
-
}(
|
|
2253
|
+
return SkinParser;
|
|
2254
|
+
}(Parser);
|
|
2177
2255
|
|
|
2178
|
-
var
|
|
2179
|
-
_inherits(
|
|
2180
|
-
function
|
|
2181
|
-
return
|
|
2256
|
+
var TextureParser = /*#__PURE__*/ function(Parser) {
|
|
2257
|
+
_inherits(TextureParser, Parser);
|
|
2258
|
+
function TextureParser() {
|
|
2259
|
+
return Parser.apply(this, arguments);
|
|
2182
2260
|
}
|
|
2183
|
-
var _proto =
|
|
2261
|
+
var _proto = TextureParser.prototype;
|
|
2184
2262
|
_proto.parse = function parse(context) {
|
|
2185
2263
|
var _this = this;
|
|
2186
|
-
var glTFResource = context.glTFResource,
|
|
2264
|
+
var glTFResource = context.glTFResource, gltf = context.gltf, buffers = context.buffers;
|
|
2187
2265
|
var engine = glTFResource.engine, url = glTFResource.url;
|
|
2188
|
-
if (
|
|
2266
|
+
if (gltf.textures) {
|
|
2189
2267
|
var texturesPromiseInfo = context.texturesPromiseInfo;
|
|
2190
|
-
miniprogram.AssetPromise.all(
|
|
2268
|
+
miniprogram.AssetPromise.all(gltf.textures.map(function(param, index) {
|
|
2191
2269
|
var sampler = param.sampler, _param_source = param.source, source = _param_source === void 0 ? 0 : _param_source, textureName = param.name;
|
|
2192
|
-
var
|
|
2270
|
+
var _gltf_images_source = gltf.images[source], uri = _gltf_images_source.uri, bufferViewIndex = _gltf_images_source.bufferView, mimeType = _gltf_images_source.mimeType, imageName = _gltf_images_source.name;
|
|
2193
2271
|
if (uri) {
|
|
2194
2272
|
// TODO: support ktx extension https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_texture_basisu/README.md
|
|
2195
2273
|
var index1 = uri.lastIndexOf(".");
|
|
@@ -2203,24 +2281,21 @@ var GLTFTextureParser = /*#__PURE__*/ function(GLTFParser) {
|
|
|
2203
2281
|
texture.name = textureName || imageName || "texture_" + index1;
|
|
2204
2282
|
}
|
|
2205
2283
|
if (sampler !== undefined) {
|
|
2206
|
-
_this._parseSampler(texture,
|
|
2284
|
+
_this._parseSampler(texture, gltf.samplers[sampler]);
|
|
2207
2285
|
}
|
|
2208
2286
|
return texture;
|
|
2209
2287
|
});
|
|
2210
2288
|
} else {
|
|
2211
|
-
var bufferView =
|
|
2212
|
-
var
|
|
2213
|
-
|
|
2214
|
-
return GLTFUtil.loadImageBuffer(imageBuffer, mimeType).then(function(image) {
|
|
2289
|
+
var bufferView = gltf.bufferViews[bufferViewIndex];
|
|
2290
|
+
var bufferViewData = GLTFUtil.getBufferViewData(bufferView, buffers);
|
|
2291
|
+
return GLTFUtil.loadImageBuffer(bufferViewData, mimeType).then(function(image) {
|
|
2215
2292
|
var texture = new miniprogram.Texture2D(engine, image.width, image.height);
|
|
2216
2293
|
texture.setImageSource(image);
|
|
2217
2294
|
texture.generateMipmaps();
|
|
2218
2295
|
texture.name = textureName || imageName || "texture_" + index;
|
|
2219
2296
|
if (sampler !== undefined) {
|
|
2220
|
-
_this._parseSampler(texture,
|
|
2297
|
+
_this._parseSampler(texture, gltf.samplers[sampler]);
|
|
2221
2298
|
}
|
|
2222
|
-
var bufferTextureRestoreInfo = new BufferTextureRestoreInfo(texture, bufferView, mimeType);
|
|
2223
|
-
context.contentRestorer.bufferTextures.push(bufferTextureRestoreInfo);
|
|
2224
2299
|
return texture;
|
|
2225
2300
|
});
|
|
2226
2301
|
}
|
|
@@ -2243,36 +2318,36 @@ var GLTFTextureParser = /*#__PURE__*/ function(GLTFParser) {
|
|
|
2243
2318
|
}
|
|
2244
2319
|
}
|
|
2245
2320
|
if (wrapS) {
|
|
2246
|
-
texture.wrapModeU =
|
|
2321
|
+
texture.wrapModeU = TextureParser._wrapMap[wrapS];
|
|
2247
2322
|
}
|
|
2248
2323
|
if (wrapT) {
|
|
2249
|
-
texture.wrapModeV =
|
|
2324
|
+
texture.wrapModeV = TextureParser._wrapMap[wrapT];
|
|
2250
2325
|
}
|
|
2251
2326
|
};
|
|
2252
|
-
return
|
|
2253
|
-
}(
|
|
2254
|
-
|
|
2255
|
-
|
|
2327
|
+
return TextureParser;
|
|
2328
|
+
}(Parser);
|
|
2329
|
+
(function() {
|
|
2330
|
+
var _obj;
|
|
2331
|
+
TextureParser._wrapMap = (_obj = {}, _obj[TextureWrapMode.CLAMP_TO_EDGE] = miniprogram.TextureWrapMode.Clamp, _obj[TextureWrapMode.MIRRORED_REPEAT] = miniprogram.TextureWrapMode.Mirror, _obj[TextureWrapMode.REPEAT] = miniprogram.TextureWrapMode.Repeat, _obj);
|
|
2332
|
+
})();
|
|
2256
2333
|
|
|
2257
|
-
var
|
|
2258
|
-
_inherits(
|
|
2259
|
-
function
|
|
2260
|
-
return
|
|
2334
|
+
var Validator = /*#__PURE__*/ function(Parser1) {
|
|
2335
|
+
_inherits(Validator, Parser1);
|
|
2336
|
+
function Validator() {
|
|
2337
|
+
return Parser1.apply(this, arguments);
|
|
2261
2338
|
}
|
|
2262
|
-
var _proto =
|
|
2339
|
+
var _proto = Validator.prototype;
|
|
2263
2340
|
_proto.parse = function parse(context) {
|
|
2264
|
-
var
|
|
2265
|
-
var
|
|
2266
|
-
if (!(
|
|
2267
|
-
throw "Only support
|
|
2341
|
+
var _context_gltf = context.gltf, version = _context_gltf.asset.version, extensionsUsed = _context_gltf.extensionsUsed, extensionsRequired = _context_gltf.extensionsRequired;
|
|
2342
|
+
var gltfVersion = Number(version);
|
|
2343
|
+
if (!(gltfVersion >= 2 && gltfVersion < 3)) {
|
|
2344
|
+
throw "Only support gltf 2.x.";
|
|
2268
2345
|
}
|
|
2269
|
-
var promises = [];
|
|
2270
2346
|
if (extensionsUsed) {
|
|
2271
2347
|
miniprogram.Logger.info("extensionsUsed: ", extensionsUsed);
|
|
2272
2348
|
for(var i = 0; i < extensionsUsed.length; i++){
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
miniprogram.Logger.warn("Extension " + extensionUsed + " is not implemented, you can customize this extension in gltf.");
|
|
2349
|
+
if (!Parser.hasExtensionParser(extensionsUsed[i])) {
|
|
2350
|
+
miniprogram.Logger.warn("Extension " + extensionsUsed[i] + " is not implemented, you can customize this extension in gltf.");
|
|
2276
2351
|
}
|
|
2277
2352
|
}
|
|
2278
2353
|
}
|
|
@@ -2280,66 +2355,68 @@ var GLTFValidator = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
2280
2355
|
miniprogram.Logger.info("extensionsRequired: " + extensionsRequired);
|
|
2281
2356
|
for(var i1 = 0; i1 < extensionsRequired.length; i1++){
|
|
2282
2357
|
var extensionRequired = extensionsRequired[i1];
|
|
2283
|
-
if (!
|
|
2358
|
+
if (!Parser.hasExtensionParser(extensionRequired)) {
|
|
2284
2359
|
miniprogram.Logger.error("GLTF parser has not supported required extension " + extensionRequired + ".");
|
|
2285
2360
|
} else {
|
|
2286
|
-
|
|
2361
|
+
Parser.initialize(extensionRequired);
|
|
2287
2362
|
}
|
|
2288
2363
|
}
|
|
2289
2364
|
}
|
|
2290
|
-
return miniprogram.AssetPromise.all(promises).then(null);
|
|
2291
2365
|
};
|
|
2292
|
-
return
|
|
2293
|
-
}(
|
|
2366
|
+
return Validator;
|
|
2367
|
+
}(Parser);
|
|
2294
2368
|
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
*/ var GLTFPipeline = /*#__PURE__*/ function() {
|
|
2298
|
-
function GLTFPipeline() {
|
|
2299
|
-
for(var _len = arguments.length, parsers = new Array(_len), _key = 0; _key < _len; _key++){
|
|
2300
|
-
parsers[_key] = arguments[_key];
|
|
2301
|
-
}
|
|
2369
|
+
var GLTFParser = /*#__PURE__*/ function() {
|
|
2370
|
+
function GLTFParser(pipes) {
|
|
2302
2371
|
var _this = this;
|
|
2303
|
-
this.
|
|
2304
|
-
|
|
2305
|
-
_this.
|
|
2372
|
+
this._pipes = [];
|
|
2373
|
+
pipes.forEach(function(pipe, index) {
|
|
2374
|
+
_this._pipes[index] = new pipe();
|
|
2306
2375
|
});
|
|
2307
2376
|
}
|
|
2308
|
-
var _proto =
|
|
2309
|
-
|
|
2310
|
-
* @internal
|
|
2311
|
-
*/ _proto._parse = function _parse(context) {
|
|
2377
|
+
var _proto = GLTFParser.prototype;
|
|
2378
|
+
_proto.parse = function parse(context) {
|
|
2312
2379
|
var _this = this;
|
|
2313
2380
|
var glTFResource = context.glTFResource;
|
|
2314
|
-
var
|
|
2381
|
+
var lastPipe;
|
|
2315
2382
|
return new miniprogram.AssetPromise(function(resolve, reject) {
|
|
2316
|
-
_this.
|
|
2317
|
-
if (
|
|
2318
|
-
|
|
2383
|
+
_this._pipes.forEach(function(parser) {
|
|
2384
|
+
if (lastPipe) {
|
|
2385
|
+
lastPipe = lastPipe.then(function() {
|
|
2319
2386
|
return parser.parse(context);
|
|
2320
2387
|
});
|
|
2321
|
-
if (
|
|
2322
|
-
context.chainPromises.push(
|
|
2388
|
+
if (lastPipe.cancel) {
|
|
2389
|
+
context.chainPromises.push(lastPipe);
|
|
2323
2390
|
}
|
|
2324
2391
|
} else {
|
|
2325
|
-
|
|
2392
|
+
lastPipe = parser.parse(context);
|
|
2326
2393
|
}
|
|
2327
2394
|
});
|
|
2328
|
-
if (
|
|
2329
|
-
|
|
2395
|
+
if (lastPipe) {
|
|
2396
|
+
lastPipe.then(function() {
|
|
2330
2397
|
resolve(glTFResource);
|
|
2331
2398
|
}).catch(reject);
|
|
2332
2399
|
}
|
|
2333
2400
|
});
|
|
2334
2401
|
};
|
|
2335
|
-
return
|
|
2402
|
+
return GLTFParser;
|
|
2336
2403
|
}();
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2404
|
+
(function() {
|
|
2405
|
+
GLTFParser.defaultPipeline = new GLTFParser([
|
|
2406
|
+
BufferParser,
|
|
2407
|
+
Validator,
|
|
2408
|
+
TextureParser,
|
|
2409
|
+
MaterialParser,
|
|
2410
|
+
MeshParser,
|
|
2411
|
+
EntityParser,
|
|
2412
|
+
SkinParser,
|
|
2413
|
+
AnimationParser,
|
|
2414
|
+
SceneParser$1
|
|
2415
|
+
]);
|
|
2416
|
+
})();
|
|
2340
2417
|
|
|
2341
2418
|
/**
|
|
2342
|
-
* Product after
|
|
2419
|
+
* Product after GLTF parser, usually, `defaultSceneRoot` is only needed to use.
|
|
2343
2420
|
*/ var GLTFResource = /*#__PURE__*/ function(EngineObject) {
|
|
2344
2421
|
_inherits(GLTFResource, EngineObject);
|
|
2345
2422
|
function GLTFResource(engine, url) {
|
|
@@ -2351,8 +2428,11 @@ var GLTFValidator = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
2351
2428
|
var _proto = GLTFResource.prototype;
|
|
2352
2429
|
/**
|
|
2353
2430
|
* @override
|
|
2354
|
-
*/ _proto.
|
|
2355
|
-
|
|
2431
|
+
*/ _proto.destroy = function destroy() {
|
|
2432
|
+
if (this._destroyed) {
|
|
2433
|
+
return;
|
|
2434
|
+
}
|
|
2435
|
+
EngineObject.prototype.destroy.call(this);
|
|
2356
2436
|
this.defaultSceneRoot.destroy();
|
|
2357
2437
|
this.textures = null;
|
|
2358
2438
|
this.materials = null;
|
|
@@ -2363,7 +2443,7 @@ var GLTFValidator = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
2363
2443
|
this.cameras = null;
|
|
2364
2444
|
this.lights = null;
|
|
2365
2445
|
this.sceneRoots = null;
|
|
2366
|
-
this.
|
|
2446
|
+
this.variants = null;
|
|
2367
2447
|
};
|
|
2368
2448
|
return GLTFResource;
|
|
2369
2449
|
}(miniprogram.EngineObject);
|
|
@@ -2374,30 +2454,23 @@ var GLTFLoader = /*#__PURE__*/ function(Loader) {
|
|
|
2374
2454
|
return Loader.apply(this, arguments);
|
|
2375
2455
|
}
|
|
2376
2456
|
var _proto = GLTFLoader.prototype;
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
*/ _proto.load = function load(item, resourceManager) {
|
|
2457
|
+
_proto.load = function load(item, resourceManager) {
|
|
2458
|
+
var _item_params;
|
|
2380
2459
|
var url = item.url;
|
|
2381
|
-
var
|
|
2382
|
-
var context = new GLTFParserContext(url);
|
|
2460
|
+
var context = new ParserContext(url);
|
|
2383
2461
|
var glTFResource = new GLTFResource(resourceManager.engine, url);
|
|
2384
|
-
var restorer = new GLTFContentRestorer(glTFResource);
|
|
2385
2462
|
var masterPromiseInfo = context.masterPromiseInfo;
|
|
2386
|
-
context.contentRestorer = restorer;
|
|
2387
2463
|
context.glTFResource = glTFResource;
|
|
2388
|
-
var
|
|
2389
|
-
context.keepMeshData = (
|
|
2464
|
+
var _item_params_keepMeshData;
|
|
2465
|
+
context.keepMeshData = (_item_params_keepMeshData = (_item_params = item.params) == null ? void 0 : _item_params.keepMeshData) != null ? _item_params_keepMeshData : false;
|
|
2390
2466
|
masterPromiseInfo.onCancel(function() {
|
|
2391
2467
|
var chainPromises = context.chainPromises;
|
|
2392
|
-
for(var _iterator =
|
|
2468
|
+
for(var _iterator = _create_for_of_iterator_helper_loose(chainPromises), _step; !(_step = _iterator()).done;){
|
|
2393
2469
|
var promise = _step.value;
|
|
2394
2470
|
promise.cancel();
|
|
2395
2471
|
}
|
|
2396
2472
|
});
|
|
2397
|
-
|
|
2398
|
-
resourceManager.addContentRestorer(restorer);
|
|
2399
|
-
masterPromiseInfo.resolve(glTFResource);
|
|
2400
|
-
}).catch(function(e) {
|
|
2473
|
+
GLTFParser.defaultPipeline.parse(context).then(masterPromiseInfo.resolve).catch(function(e) {
|
|
2401
2474
|
console.error(e);
|
|
2402
2475
|
masterPromiseInfo.reject("Error loading glTF model from " + url + " .");
|
|
2403
2476
|
});
|
|
@@ -2406,7 +2479,7 @@ var GLTFLoader = /*#__PURE__*/ function(Loader) {
|
|
|
2406
2479
|
return GLTFLoader;
|
|
2407
2480
|
}(miniprogram.Loader);
|
|
2408
2481
|
GLTFLoader = __decorate([
|
|
2409
|
-
miniprogram.resourceLoader(miniprogram.AssetType.
|
|
2482
|
+
miniprogram.resourceLoader(miniprogram.AssetType.Prefab, [
|
|
2410
2483
|
"gltf",
|
|
2411
2484
|
"glb"
|
|
2412
2485
|
])
|
|
@@ -2653,37 +2726,75 @@ var HDRLoader = (_HDRLoader = /*#__PURE__*/ function(Loader) {
|
|
|
2653
2726
|
color.a *= M;
|
|
2654
2727
|
};
|
|
2655
2728
|
return HDRLoader1;
|
|
2656
|
-
}(miniprogram.Loader),
|
|
2657
|
-
_HDRLoader._rightBottomBack,
|
|
2658
|
-
|
|
2659
|
-
_HDRLoader.
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
_HDRLoader.
|
|
2664
|
-
|
|
2665
|
-
_HDRLoader.
|
|
2666
|
-
|
|
2667
|
-
_HDRLoader._leftBottomFront,
|
|
2668
|
-
|
|
2669
|
-
_HDRLoader.
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
_HDRLoader.
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
_HDRLoader.
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2729
|
+
}(miniprogram.Loader), function() {
|
|
2730
|
+
_HDRLoader._rightBottomBack = new miniprogram$1.Vector3(1.0, -1.0, -1.0);
|
|
2731
|
+
}(), function() {
|
|
2732
|
+
_HDRLoader._rightBottomFront = new miniprogram$1.Vector3(1.0, -1.0, 1.0);
|
|
2733
|
+
}(), function() {
|
|
2734
|
+
_HDRLoader._rightUpBack = new miniprogram$1.Vector3(1.0, 1.0, -1.0);
|
|
2735
|
+
}(), function() {
|
|
2736
|
+
_HDRLoader._rightUpFront = new miniprogram$1.Vector3(1.0, 1.0, 1.0);
|
|
2737
|
+
}(), function() {
|
|
2738
|
+
_HDRLoader._leftBottomBack = new miniprogram$1.Vector3(-1.0, -1.0, -1.0);
|
|
2739
|
+
}(), function() {
|
|
2740
|
+
_HDRLoader._leftBottomFront = new miniprogram$1.Vector3(-1.0, -1.0, 1.0);
|
|
2741
|
+
}(), function() {
|
|
2742
|
+
_HDRLoader._leftUpBack = new miniprogram$1.Vector3(-1.0, 1.0, -1.0);
|
|
2743
|
+
}(), function() {
|
|
2744
|
+
_HDRLoader._leftUpFront = new miniprogram$1.Vector3(-1.0, 1.0, 1.0);
|
|
2745
|
+
}(), function() {
|
|
2746
|
+
_HDRLoader._faceRight = [
|
|
2747
|
+
_HDRLoader._rightBottomBack,
|
|
2748
|
+
_HDRLoader._rightBottomFront,
|
|
2749
|
+
_HDRLoader._rightUpBack,
|
|
2750
|
+
_HDRLoader._rightUpFront
|
|
2751
|
+
];
|
|
2752
|
+
}(), function() {
|
|
2753
|
+
_HDRLoader._faceLeft = [
|
|
2754
|
+
_HDRLoader._leftBottomFront,
|
|
2755
|
+
_HDRLoader._leftBottomBack,
|
|
2756
|
+
_HDRLoader._leftUpFront,
|
|
2757
|
+
_HDRLoader._leftUpBack
|
|
2758
|
+
];
|
|
2759
|
+
}(), function() {
|
|
2760
|
+
_HDRLoader._faceUp = [
|
|
2761
|
+
_HDRLoader._leftBottomFront,
|
|
2762
|
+
_HDRLoader._rightBottomFront,
|
|
2763
|
+
_HDRLoader._leftBottomBack,
|
|
2764
|
+
_HDRLoader._rightBottomBack
|
|
2765
|
+
];
|
|
2766
|
+
}(), function() {
|
|
2767
|
+
_HDRLoader._faceBottom = [
|
|
2768
|
+
_HDRLoader._leftUpBack,
|
|
2769
|
+
_HDRLoader._rightUpBack,
|
|
2770
|
+
_HDRLoader._leftUpFront,
|
|
2771
|
+
_HDRLoader._rightUpFront
|
|
2772
|
+
];
|
|
2773
|
+
}(), function() {
|
|
2774
|
+
_HDRLoader._faceFront = [
|
|
2775
|
+
_HDRLoader._leftBottomBack,
|
|
2776
|
+
_HDRLoader._rightBottomBack,
|
|
2777
|
+
_HDRLoader._leftUpBack,
|
|
2778
|
+
_HDRLoader._rightUpBack
|
|
2779
|
+
];
|
|
2780
|
+
}(), function() {
|
|
2781
|
+
_HDRLoader._faceBack = [
|
|
2782
|
+
_HDRLoader._rightBottomFront,
|
|
2783
|
+
_HDRLoader._leftBottomFront,
|
|
2784
|
+
_HDRLoader._rightUpFront,
|
|
2785
|
+
_HDRLoader._leftUpFront
|
|
2786
|
+
];
|
|
2787
|
+
}(), function() {
|
|
2788
|
+
_HDRLoader._tempVector3 = new miniprogram$1.Vector3();
|
|
2789
|
+
}(), function() {
|
|
2790
|
+
_HDRLoader._temp2Vector3 = new miniprogram$1.Vector3();
|
|
2791
|
+
}(), function() {
|
|
2792
|
+
_HDRLoader._temp3Vector3 = new miniprogram$1.Vector3();
|
|
2793
|
+
}(), function() {
|
|
2794
|
+
_HDRLoader._temp4Vector3 = new miniprogram$1.Vector3();
|
|
2795
|
+
}(), function() {
|
|
2796
|
+
_HDRLoader._temp5Vector3 = new miniprogram$1.Vector3();
|
|
2797
|
+
}(), _HDRLoader);
|
|
2687
2798
|
HDRLoader = __decorate([
|
|
2688
2799
|
miniprogram.resourceLoader(miniprogram.AssetType.HDR, [
|
|
2689
2800
|
"hdr"
|
|
@@ -2756,40 +2867,40 @@ function getEngineFormat(internalFormat) {
|
|
|
2756
2867
|
// case GLCompressedTextureInternalFormat.RGBA_S3TC_DXT3_EXT:
|
|
2757
2868
|
// case GLCompressedTextureInternalFormat.RGBA_S3TC_DXT5_EXT:
|
|
2758
2869
|
// break;
|
|
2759
|
-
case miniprogram$
|
|
2870
|
+
case miniprogram$3.GLCompressedTextureInternalFormat.RGB_S3TC_DXT1_EXT:
|
|
2760
2871
|
return miniprogram.TextureFormat.DXT1;
|
|
2761
|
-
case miniprogram$
|
|
2872
|
+
case miniprogram$3.GLCompressedTextureInternalFormat.RGBA_S3TC_DXT5_EXT:
|
|
2762
2873
|
return miniprogram.TextureFormat.DXT5;
|
|
2763
|
-
case miniprogram$
|
|
2874
|
+
case miniprogram$3.GLCompressedTextureInternalFormat.RGB_ETC1_WEBGL:
|
|
2764
2875
|
return miniprogram.TextureFormat.ETC1_RGB;
|
|
2765
|
-
case miniprogram$
|
|
2876
|
+
case miniprogram$3.GLCompressedTextureInternalFormat.RGB8_ETC2:
|
|
2766
2877
|
return miniprogram.TextureFormat.ETC2_RGB;
|
|
2767
|
-
case miniprogram$
|
|
2878
|
+
case miniprogram$3.GLCompressedTextureInternalFormat.RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
|
|
2768
2879
|
return miniprogram.TextureFormat.ETC2_RGBA5;
|
|
2769
|
-
case miniprogram$
|
|
2880
|
+
case miniprogram$3.GLCompressedTextureInternalFormat.RGBA8_ETC2_EAC:
|
|
2770
2881
|
return miniprogram.TextureFormat.ETC2_RGBA8;
|
|
2771
|
-
case miniprogram$
|
|
2882
|
+
case miniprogram$3.GLCompressedTextureInternalFormat.RGB_PVRTC_2BPPV1_IMG:
|
|
2772
2883
|
return miniprogram.TextureFormat.PVRTC_RGB2;
|
|
2773
|
-
case miniprogram$
|
|
2884
|
+
case miniprogram$3.GLCompressedTextureInternalFormat.RGBA_PVRTC_2BPPV1_IMG:
|
|
2774
2885
|
return miniprogram.TextureFormat.PVRTC_RGBA2;
|
|
2775
|
-
case miniprogram$
|
|
2886
|
+
case miniprogram$3.GLCompressedTextureInternalFormat.RGB_PVRTC_4BPPV1_IMG:
|
|
2776
2887
|
return miniprogram.TextureFormat.PVRTC_RGB4;
|
|
2777
|
-
case miniprogram$
|
|
2888
|
+
case miniprogram$3.GLCompressedTextureInternalFormat.RGBA_PVRTC_4BPPV1_IMG:
|
|
2778
2889
|
return miniprogram.TextureFormat.PVRTC_RGBA4;
|
|
2779
|
-
case miniprogram$
|
|
2890
|
+
case miniprogram$3.GLCompressedTextureInternalFormat.RGBA_ASTC_4X4_KHR:
|
|
2780
2891
|
return miniprogram.TextureFormat.ASTC_4x4;
|
|
2781
|
-
case miniprogram$
|
|
2892
|
+
case miniprogram$3.GLCompressedTextureInternalFormat.RGBA_ASTC_5X5_KHR:
|
|
2782
2893
|
return miniprogram.TextureFormat.ASTC_5x5;
|
|
2783
|
-
case miniprogram$
|
|
2894
|
+
case miniprogram$3.GLCompressedTextureInternalFormat.RGBA_ASTC_6X6_KHR:
|
|
2784
2895
|
return miniprogram.TextureFormat.ASTC_6x6;
|
|
2785
|
-
case miniprogram$
|
|
2896
|
+
case miniprogram$3.GLCompressedTextureInternalFormat.RGBA_ASTC_8X8_KHR:
|
|
2786
2897
|
return miniprogram.TextureFormat.ASTC_8x8;
|
|
2787
|
-
case miniprogram$
|
|
2898
|
+
case miniprogram$3.GLCompressedTextureInternalFormat.RGBA_ASTC_10X10_KHR:
|
|
2788
2899
|
return miniprogram.TextureFormat.ASTC_10x10;
|
|
2789
|
-
case miniprogram$
|
|
2900
|
+
case miniprogram$3.GLCompressedTextureInternalFormat.RGBA_ASTC_12X12_KHR:
|
|
2790
2901
|
return miniprogram.TextureFormat.ASTC_12x12;
|
|
2791
2902
|
default:
|
|
2792
|
-
var formatName = miniprogram$
|
|
2903
|
+
var formatName = miniprogram$3.GLCompressedTextureInternalFormat[internalFormat];
|
|
2793
2904
|
throw new Error("this format is not supported in Galacean Engine: " + formatName);
|
|
2794
2905
|
}
|
|
2795
2906
|
}
|
|
@@ -3053,19 +3164,21 @@ MaterialLoader = __decorate([
|
|
|
3053
3164
|
], MaterialLoader);
|
|
3054
3165
|
|
|
3055
3166
|
function _defineProperties(target, props) {
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3167
|
+
for (var i = 0; i < props.length; i++) {
|
|
3168
|
+
var descriptor = props[i];
|
|
3169
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
3170
|
+
descriptor.configurable = true;
|
|
3171
|
+
|
|
3172
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
3173
|
+
|
|
3174
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
3175
|
+
}
|
|
3063
3176
|
}
|
|
3177
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
3178
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
3179
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
3064
3180
|
|
|
3065
|
-
|
|
3066
|
-
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
3067
|
-
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
3068
|
-
return Constructor;
|
|
3181
|
+
return Constructor;
|
|
3069
3182
|
}
|
|
3070
3183
|
|
|
3071
3184
|
var BufferReader = /*#__PURE__*/ function() {
|
|
@@ -3174,7 +3287,7 @@ var BufferReader = /*#__PURE__*/ function() {
|
|
|
3174
3287
|
if (byteLength < maxByteLength) this._offset++;
|
|
3175
3288
|
return new Uint8Array(this._dataView.buffer, this._dataView.byteOffset + byteOffset, byteLength);
|
|
3176
3289
|
};
|
|
3177
|
-
|
|
3290
|
+
_create_class(BufferReader, [
|
|
3178
3291
|
{
|
|
3179
3292
|
key: "offset",
|
|
3180
3293
|
get: function get() {
|
|
@@ -3184,12 +3297,14 @@ var BufferReader = /*#__PURE__*/ function() {
|
|
|
3184
3297
|
]);
|
|
3185
3298
|
return BufferReader;
|
|
3186
3299
|
}();
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3300
|
+
(function() {
|
|
3301
|
+
BufferReader.imageMapping = {
|
|
3302
|
+
0: "image/png",
|
|
3303
|
+
1: "image/jpg",
|
|
3304
|
+
2: "image/webp",
|
|
3305
|
+
3: "ktx"
|
|
3306
|
+
};
|
|
3307
|
+
})();
|
|
3193
3308
|
|
|
3194
3309
|
var decoderMap = {};
|
|
3195
3310
|
/**
|
|
@@ -3228,7 +3343,7 @@ var FileHeader = /*#__PURE__*/ function() {
|
|
|
3228
3343
|
header.headerLength = nameUint8Array.byteLength + typeUint8Array.byteLength + 9;
|
|
3229
3344
|
return header;
|
|
3230
3345
|
};
|
|
3231
|
-
|
|
3346
|
+
_create_class(FileHeader, [
|
|
3232
3347
|
{
|
|
3233
3348
|
key: "dataLength",
|
|
3234
3349
|
get: function get() {
|
|
@@ -3447,38 +3562,36 @@ exports.Texture2DDecoder = __decorate([
|
|
|
3447
3562
|
decoder("Texture2D")
|
|
3448
3563
|
], exports.Texture2DDecoder);
|
|
3449
3564
|
|
|
3450
|
-
function
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
|
|
3565
|
+
function _is_native_reflect_construct() {
|
|
3566
|
+
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
|
3567
|
+
if (Reflect.construct.sham) return false;
|
|
3568
|
+
if (typeof Proxy === "function") return true;
|
|
3454
3569
|
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
-
return true;
|
|
3458
|
-
} catch (e) {
|
|
3459
|
-
return false;
|
|
3460
|
-
}
|
|
3461
|
-
}
|
|
3570
|
+
try {
|
|
3571
|
+
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
|
3462
3572
|
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3467
|
-
construct = function construct(Parent, args, Class) {
|
|
3468
|
-
var a = [null];
|
|
3469
|
-
a.push.apply(a, args);
|
|
3470
|
-
var Constructor = Function.bind.apply(Parent, a);
|
|
3471
|
-
var instance = new Constructor();
|
|
3472
|
-
if (Class) _setPrototypeOf(instance, Class.prototype);
|
|
3473
|
-
return instance;
|
|
3474
|
-
};
|
|
3475
|
-
}
|
|
3476
|
-
|
|
3477
|
-
return construct.apply(null, arguments);
|
|
3573
|
+
return true;
|
|
3574
|
+
} catch (e) {
|
|
3575
|
+
return false;
|
|
3576
|
+
}
|
|
3478
3577
|
}
|
|
3479
3578
|
|
|
3480
3579
|
function _construct(Parent, args, Class) {
|
|
3481
|
-
|
|
3580
|
+
if (_is_native_reflect_construct()) _construct = Reflect.construct;
|
|
3581
|
+
else {
|
|
3582
|
+
_construct = function construct(Parent, args, Class) {
|
|
3583
|
+
var a = [null];
|
|
3584
|
+
a.push.apply(a, args);
|
|
3585
|
+
var Constructor = Function.bind.apply(Parent, a);
|
|
3586
|
+
var instance = new Constructor();
|
|
3587
|
+
|
|
3588
|
+
if (Class) _set_prototype_of(instance, Class.prototype);
|
|
3589
|
+
|
|
3590
|
+
return instance;
|
|
3591
|
+
};
|
|
3592
|
+
}
|
|
3593
|
+
|
|
3594
|
+
return _construct.apply(null, arguments);
|
|
3482
3595
|
}
|
|
3483
3596
|
|
|
3484
3597
|
var ReflectionParser = /*#__PURE__*/ function() {
|
|
@@ -3593,7 +3706,9 @@ var ReflectionParser = /*#__PURE__*/ function() {
|
|
|
3593
3706
|
};
|
|
3594
3707
|
return ReflectionParser;
|
|
3595
3708
|
}();
|
|
3596
|
-
|
|
3709
|
+
(function() {
|
|
3710
|
+
ReflectionParser.customParseComponentHandles = new Map();
|
|
3711
|
+
})();
|
|
3597
3712
|
|
|
3598
3713
|
var PrefabParser = /*#__PURE__*/ function() {
|
|
3599
3714
|
function PrefabParser() {}
|
|
@@ -3847,7 +3962,7 @@ var SceneParserContext = /*#__PURE__*/ function() {
|
|
|
3847
3962
|
};
|
|
3848
3963
|
_proto._organizeEntities = function _organizeEntities() {
|
|
3849
3964
|
var _this_context = this.context, entityConfigMap = _this_context.entityConfigMap, entityMap = _this_context.entityMap, scene = _this_context.scene, rootIds = _this_context.rootIds;
|
|
3850
|
-
for(var _iterator =
|
|
3965
|
+
for(var _iterator = _create_for_of_iterator_helper_loose(rootIds), _step; !(_step = _iterator()).done;){
|
|
3851
3966
|
var rootId = _step.value;
|
|
3852
3967
|
PrefabParser.parseChildren(entityConfigMap, entityMap, rootId);
|
|
3853
3968
|
}
|
|
@@ -4011,7 +4126,7 @@ var SourceFontLoader = /*#__PURE__*/ function(Loader) {
|
|
|
4011
4126
|
});
|
|
4012
4127
|
};
|
|
4013
4128
|
_proto._registerFont = function _registerFont(fontName, fontUrl) {
|
|
4014
|
-
return
|
|
4129
|
+
return _async_to_generator(function() {
|
|
4015
4130
|
var fontFace;
|
|
4016
4131
|
return __generator(this, function(_state) {
|
|
4017
4132
|
switch(_state.label){
|
|
@@ -4048,6 +4163,7 @@ var SpriteAtlasLoader = /*#__PURE__*/ function(Loader) {
|
|
|
4048
4163
|
_this = Loader.apply(this, arguments) || this;
|
|
4049
4164
|
_this._tempRect = new miniprogram$1.Rect();
|
|
4050
4165
|
_this._tempVec2 = new miniprogram$1.Vector2();
|
|
4166
|
+
_this._tempVec4 = new miniprogram$1.Vector4();
|
|
4051
4167
|
return _this;
|
|
4052
4168
|
}
|
|
4053
4169
|
var _proto = SpriteAtlasLoader.prototype;
|
|
@@ -4065,57 +4181,65 @@ var SpriteAtlasLoader = /*#__PURE__*/ function(Loader) {
|
|
|
4065
4181
|
}));
|
|
4066
4182
|
chainPromises.push(configPromise);
|
|
4067
4183
|
configPromise.then(function(atlasData) {
|
|
4068
|
-
var
|
|
4069
|
-
|
|
4070
|
-
|
|
4071
|
-
|
|
4072
|
-
|
|
4073
|
-
|
|
4074
|
-
|
|
4075
|
-
|
|
4076
|
-
|
|
4077
|
-
return imagePromises.then(function(imgs) {
|
|
4078
|
-
var engine = resourceManager.engine;
|
|
4079
|
-
// Generate a SpriteAtlas object.
|
|
4080
|
-
var tempRect = _this._tempRect, tempVec2 = _this._tempVec2;
|
|
4081
|
-
var spriteAtlas = new miniprogram.SpriteAtlas(engine);
|
|
4082
|
-
for(var i = 0; i < atlasItemsLen; i++){
|
|
4083
|
-
// Generate Texture2D according to configuration.
|
|
4084
|
-
var originalImg = imgs[i];
|
|
4085
|
-
var width = originalImg.width, height = originalImg.height;
|
|
4086
|
-
var texture = new miniprogram.Texture2D(engine, width, height, format);
|
|
4087
|
-
texture.setImageSource(originalImg);
|
|
4088
|
-
texture.generateMipmaps();
|
|
4089
|
-
// Generate all the sprites on this texture.
|
|
4090
|
-
var atlasItem = atlasItems[i];
|
|
4091
|
-
var sprites = atlasItem.sprites;
|
|
4092
|
-
var sourceWidthReciprocal = 1.0 / width;
|
|
4093
|
-
var sourceHeightReciprocal = 1.0 / height;
|
|
4094
|
-
for(var j = sprites.length - 1; j >= 0; j--){
|
|
4095
|
-
var atlasSprite = sprites[j];
|
|
4096
|
-
var region = atlasSprite.region, atlasRegionOffset = atlasSprite.atlasRegionOffset, atlasRegion = atlasSprite.atlasRegion, id = atlasSprite.id, pivot = atlasSprite.pivot;
|
|
4097
|
-
var sprite = new miniprogram.Sprite(engine, texture, region ? tempRect.set(region.x, region.y, region.w, region.h) : undefined, pivot ? tempVec2.set(pivot.x, pivot.y) : undefined, undefined, atlasSprite.name);
|
|
4098
|
-
sprite.atlasRegion.set(atlasRegion.x * sourceWidthReciprocal, atlasRegion.y * sourceHeightReciprocal, atlasRegion.w * sourceWidthReciprocal, atlasRegion.h * sourceHeightReciprocal);
|
|
4099
|
-
atlasSprite.atlasRotated && (sprite.atlasRotated = true);
|
|
4100
|
-
if (atlasRegionOffset) {
|
|
4101
|
-
var offsetLeft = atlasRegionOffset.x, offsetTop = atlasRegionOffset.y, offsetRight = atlasRegionOffset.z, offsetBottom = atlasRegionOffset.w;
|
|
4102
|
-
sprite.atlasRegionOffset.set(offsetLeft * sourceWidthReciprocal, offsetTop * sourceHeightReciprocal, offsetRight * sourceWidthReciprocal, offsetBottom * sourceHeightReciprocal);
|
|
4184
|
+
var _loop = function(i) {
|
|
4185
|
+
var atlasItem = atlasItems[i];
|
|
4186
|
+
if (atlasItem.img) {
|
|
4187
|
+
chainPromises.push(resourceManager.load({
|
|
4188
|
+
url: atlasItem.img,
|
|
4189
|
+
type: miniprogram.AssetType.Texture2D,
|
|
4190
|
+
params: {
|
|
4191
|
+
format: format,
|
|
4192
|
+
mipmap: mipmap
|
|
4103
4193
|
}
|
|
4104
|
-
|
|
4194
|
+
}).then(function(texture) {
|
|
4195
|
+
anisoLevel && (texture.anisoLevel = anisoLevel);
|
|
4196
|
+
filterMode !== undefined && (texture.filterMode = filterMode);
|
|
4197
|
+
wrapModeU !== undefined && (texture.wrapModeU = wrapModeU);
|
|
4198
|
+
wrapModeV !== undefined && (texture.wrapModeV = wrapModeV);
|
|
4199
|
+
for(var i = 0; i < atlasItem.sprites.length; i++){
|
|
4105
4200
|
// @ts-ignore
|
|
4106
|
-
|
|
4201
|
+
spriteAtlas._addSprite(_this._makeSprite(engine, atlasItem.sprites[i], texture));
|
|
4107
4202
|
}
|
|
4203
|
+
}).catch(reject));
|
|
4204
|
+
} else {
|
|
4205
|
+
for(var i1 = 0; i1 < atlasItem.sprites.length; i1++){
|
|
4108
4206
|
// @ts-ignore
|
|
4109
|
-
spriteAtlas._addSprite(
|
|
4207
|
+
spriteAtlas._addSprite(_this._makeSprite(engine, atlasItem.sprites[i1]));
|
|
4110
4208
|
}
|
|
4111
4209
|
}
|
|
4210
|
+
};
|
|
4211
|
+
var atlasItems = atlasData.atlasItems, mipmap = atlasData.mipmap, anisoLevel = atlasData.anisoLevel, filterMode = atlasData.filterMode, wrapModeU = atlasData.wrapModeU, wrapModeV = atlasData.wrapModeV, format = atlasData.format;
|
|
4212
|
+
var atlasItemsLen = atlasItems ? atlasItems.length : 0;
|
|
4213
|
+
var engine = resourceManager.engine;
|
|
4214
|
+
var spriteAtlas = new miniprogram.SpriteAtlas(engine);
|
|
4215
|
+
if (atlasItemsLen < 0) {
|
|
4112
4216
|
resolve(spriteAtlas);
|
|
4113
|
-
|
|
4114
|
-
|
|
4115
|
-
|
|
4116
|
-
|
|
4217
|
+
return;
|
|
4218
|
+
}
|
|
4219
|
+
chainPromises.length = 0;
|
|
4220
|
+
for(var i = 0; i < atlasItems.length; i++)_loop(i);
|
|
4221
|
+
miniprogram.AssetPromise.all(chainPromises).then(function() {
|
|
4222
|
+
resolve(spriteAtlas);
|
|
4223
|
+
}).catch(reject);
|
|
4224
|
+
}).catch(reject);
|
|
4117
4225
|
});
|
|
4118
4226
|
};
|
|
4227
|
+
_proto._makeSprite = function _makeSprite(engine, config, texture) {
|
|
4228
|
+
// Generate a SpriteAtlas object.
|
|
4229
|
+
var region = config.region, atlasRegionOffset = config.atlasRegionOffset, atlasRegion = config.atlasRegion, pivot = config.pivot, border = config.border;
|
|
4230
|
+
var sprite = new miniprogram.Sprite(engine, texture, region ? this._tempRect.set(region.x, region.y, region.w, region.h) : undefined, pivot ? this._tempVec2.set(pivot.x, pivot.y) : undefined, border ? this._tempVec4.set(border.x, border.y, border.z, border.w) : undefined, config.name);
|
|
4231
|
+
if (texture) {
|
|
4232
|
+
var invW = 1 / texture.width;
|
|
4233
|
+
var invH = 1 / texture.height;
|
|
4234
|
+
sprite.atlasRegion.set(atlasRegion.x * invW, atlasRegion.y * invH, atlasRegion.w * invW, atlasRegion.h * invH);
|
|
4235
|
+
if (atlasRegionOffset) {
|
|
4236
|
+
var offsetLeft = atlasRegionOffset.x, offsetTop = atlasRegionOffset.y, offsetRight = atlasRegionOffset.z, offsetBottom = atlasRegionOffset.w;
|
|
4237
|
+
sprite.atlasRegionOffset.set(offsetLeft * invW, offsetTop * invH, offsetRight * invW, offsetBottom * invH);
|
|
4238
|
+
}
|
|
4239
|
+
config.atlasRotated && (sprite.atlasRotated = true);
|
|
4240
|
+
}
|
|
4241
|
+
return sprite;
|
|
4242
|
+
};
|
|
4119
4243
|
return SpriteAtlasLoader;
|
|
4120
4244
|
}(miniprogram.Loader);
|
|
4121
4245
|
SpriteAtlasLoader = __decorate([
|
|
@@ -4136,13 +4260,19 @@ var SpriteLoader = /*#__PURE__*/ function(Loader) {
|
|
|
4136
4260
|
_this.request(item.url, _extends({}, item, {
|
|
4137
4261
|
type: "json"
|
|
4138
4262
|
})).then(function(data) {
|
|
4139
|
-
|
|
4140
|
-
|
|
4141
|
-
|
|
4142
|
-
|
|
4143
|
-
|
|
4144
|
-
|
|
4145
|
-
|
|
4263
|
+
if (data.belongToAtlas) {
|
|
4264
|
+
resourceManager// @ts-ignore
|
|
4265
|
+
.getResourceByRef(data.belongToAtlas).then(function(atlas) {
|
|
4266
|
+
resolve(atlas.getSprite(data.fullPath));
|
|
4267
|
+
}).catch(reject);
|
|
4268
|
+
} else if (data.texture) {
|
|
4269
|
+
resourceManager// @ts-ignore
|
|
4270
|
+
.getResourceByRef(data.texture).then(function(texture) {
|
|
4271
|
+
resolve(new miniprogram.Sprite(resourceManager.engine, texture, data.region, data.pivot, data.border));
|
|
4272
|
+
}).catch(reject);
|
|
4273
|
+
} else {
|
|
4274
|
+
resolve(new miniprogram.Sprite(resourceManager.engine, null, data.region, data.pivot, data.border));
|
|
4275
|
+
}
|
|
4146
4276
|
}).catch(reject);
|
|
4147
4277
|
});
|
|
4148
4278
|
};
|
|
@@ -4154,57 +4284,28 @@ SpriteLoader = __decorate([
|
|
|
4154
4284
|
], false)
|
|
4155
4285
|
], SpriteLoader);
|
|
4156
4286
|
|
|
4157
|
-
/**
|
|
4158
|
-
* @internal
|
|
4159
|
-
*/ var Texture2DContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
|
|
4160
|
-
_inherits(Texture2DContentRestorer, ContentRestorer);
|
|
4161
|
-
function Texture2DContentRestorer(resource, url, requestConfig) {
|
|
4162
|
-
var _this;
|
|
4163
|
-
_this = ContentRestorer.call(this, resource) || this;
|
|
4164
|
-
_this.url = url;
|
|
4165
|
-
_this.requestConfig = requestConfig;
|
|
4166
|
-
return _this;
|
|
4167
|
-
}
|
|
4168
|
-
var _proto = Texture2DContentRestorer.prototype;
|
|
4169
|
-
/**
|
|
4170
|
-
* @override
|
|
4171
|
-
*/ _proto.restoreContent = function restoreContent() {
|
|
4172
|
-
var _this = this;
|
|
4173
|
-
return miniprogram.request(this.url, this.requestConfig).then(function(image) {
|
|
4174
|
-
var resource = _this.resource;
|
|
4175
|
-
resource.setImageSource(image);
|
|
4176
|
-
resource.generateMipmaps();
|
|
4177
|
-
return resource;
|
|
4178
|
-
});
|
|
4179
|
-
};
|
|
4180
|
-
return Texture2DContentRestorer;
|
|
4181
|
-
}(miniprogram.ContentRestorer);
|
|
4182
|
-
|
|
4183
4287
|
var Texture2DLoader = /*#__PURE__*/ function(Loader) {
|
|
4184
4288
|
_inherits(Texture2DLoader, Loader);
|
|
4185
4289
|
function Texture2DLoader() {
|
|
4186
4290
|
return Loader.apply(this, arguments);
|
|
4187
4291
|
}
|
|
4188
4292
|
var _proto = Texture2DLoader.prototype;
|
|
4189
|
-
|
|
4190
|
-
* @override
|
|
4191
|
-
*/ _proto.load = function load(item, resourceManager) {
|
|
4293
|
+
_proto.load = function load(item, resourceManager) {
|
|
4192
4294
|
var _this = this;
|
|
4193
4295
|
return new miniprogram.AssetPromise(function(resolve, reject) {
|
|
4194
|
-
|
|
4195
|
-
var requestConfig = _extends({}, item, {
|
|
4296
|
+
_this.request(item.url, _extends({}, item, {
|
|
4196
4297
|
type: "image"
|
|
4197
|
-
})
|
|
4198
|
-
|
|
4199
|
-
var params = item.params;
|
|
4200
|
-
var texture = new miniprogram.Texture2D(resourceManager.engine, image.width, image.height, params
|
|
4298
|
+
})).then(function(image) {
|
|
4299
|
+
var _item_params;
|
|
4300
|
+
var params = (_item_params = item.params) != null ? _item_params : {};
|
|
4301
|
+
var texture = new miniprogram.Texture2D(resourceManager.engine, image.width, image.height, params.format, params.mipmap);
|
|
4302
|
+
/** @ts-ignore */ if (!texture._platformTexture) return;
|
|
4201
4303
|
texture.setImageSource(image);
|
|
4202
4304
|
texture.generateMipmaps();
|
|
4203
|
-
if (url.indexOf("data:") !== 0) {
|
|
4204
|
-
var
|
|
4205
|
-
texture.name =
|
|
4305
|
+
if (item.url.indexOf("data:") !== 0) {
|
|
4306
|
+
var splitPath = item.url.split("/");
|
|
4307
|
+
texture.name = splitPath[splitPath.length - 1];
|
|
4206
4308
|
}
|
|
4207
|
-
resourceManager.addContentRestorer(new Texture2DContentRestorer(texture, url, requestConfig));
|
|
4208
4309
|
resolve(texture);
|
|
4209
4310
|
}).catch(function(e) {
|
|
4210
4311
|
reject(e);
|
|
@@ -4222,70 +4323,32 @@ Texture2DLoader = __decorate([
|
|
|
4222
4323
|
])
|
|
4223
4324
|
], Texture2DLoader);
|
|
4224
4325
|
|
|
4225
|
-
/**
|
|
4226
|
-
* @internal
|
|
4227
|
-
*/ var TextureCubeContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
|
|
4228
|
-
_inherits(TextureCubeContentRestorer, ContentRestorer);
|
|
4229
|
-
function TextureCubeContentRestorer(resource, urls, requestConfig) {
|
|
4230
|
-
var _this;
|
|
4231
|
-
_this = ContentRestorer.call(this, resource) || this;
|
|
4232
|
-
_this.urls = urls;
|
|
4233
|
-
_this.requestConfig = requestConfig;
|
|
4234
|
-
return _this;
|
|
4235
|
-
}
|
|
4236
|
-
var _proto = TextureCubeContentRestorer.prototype;
|
|
4237
|
-
/**
|
|
4238
|
-
* @override
|
|
4239
|
-
*/ _proto.restoreContent = function restoreContent() {
|
|
4240
|
-
var _this = this;
|
|
4241
|
-
return new miniprogram.AssetPromise(function(resolve, reject) {
|
|
4242
|
-
Promise.all(_this.urls.map(function(url) {
|
|
4243
|
-
return miniprogram.request(url, _this.requestConfig);
|
|
4244
|
-
})).then(function(images) {
|
|
4245
|
-
var resource = _this.resource;
|
|
4246
|
-
for(var faceIndex = 0; faceIndex < 6; faceIndex++){
|
|
4247
|
-
resource.setImageSource(miniprogram.TextureCubeFace.PositiveX + faceIndex, images[faceIndex], 0);
|
|
4248
|
-
}
|
|
4249
|
-
resource.generateMipmaps();
|
|
4250
|
-
resolve(resource);
|
|
4251
|
-
}).catch(function(e) {
|
|
4252
|
-
reject(e);
|
|
4253
|
-
});
|
|
4254
|
-
});
|
|
4255
|
-
};
|
|
4256
|
-
return TextureCubeContentRestorer;
|
|
4257
|
-
}(miniprogram.ContentRestorer);
|
|
4258
|
-
|
|
4259
4326
|
var TextureCubeLoader = /*#__PURE__*/ function(Loader) {
|
|
4260
4327
|
_inherits(TextureCubeLoader, Loader);
|
|
4261
4328
|
function TextureCubeLoader() {
|
|
4262
4329
|
return Loader.apply(this, arguments);
|
|
4263
4330
|
}
|
|
4264
4331
|
var _proto = TextureCubeLoader.prototype;
|
|
4265
|
-
|
|
4266
|
-
* @override
|
|
4267
|
-
*/ _proto.load = function load(item, resourceManager) {
|
|
4332
|
+
_proto.load = function load(item, resourceManager) {
|
|
4268
4333
|
var _this = this;
|
|
4269
4334
|
return new miniprogram.AssetPromise(function(resolve, reject) {
|
|
4270
|
-
|
|
4271
|
-
|
|
4272
|
-
|
|
4273
|
-
|
|
4274
|
-
Promise.all(urls.map(function(url) {
|
|
4275
|
-
return _this.request(url, requestConfig);
|
|
4335
|
+
Promise.all(item.urls.map(function(url) {
|
|
4336
|
+
return _this.request(url, _extends({}, item, {
|
|
4337
|
+
type: "image"
|
|
4338
|
+
}));
|
|
4276
4339
|
})).then(function(images) {
|
|
4277
4340
|
var _images_ = images[0], width = _images_.width, height = _images_.height;
|
|
4278
4341
|
if (width !== height) {
|
|
4279
4342
|
console.error("The cube texture must have the same width and height");
|
|
4280
4343
|
return;
|
|
4281
4344
|
}
|
|
4282
|
-
var
|
|
4345
|
+
var tex = new miniprogram.TextureCube(resourceManager.engine, width);
|
|
4346
|
+
/** @ts-ignore */ if (!tex._platformTexture) return;
|
|
4283
4347
|
for(var faceIndex = 0; faceIndex < 6; faceIndex++){
|
|
4284
|
-
|
|
4348
|
+
tex.setImageSource(miniprogram.TextureCubeFace.PositiveX + faceIndex, images[faceIndex], 0);
|
|
4285
4349
|
}
|
|
4286
|
-
|
|
4287
|
-
|
|
4288
|
-
resolve(texture);
|
|
4350
|
+
tex.generateMipmaps();
|
|
4351
|
+
resolve(tex);
|
|
4289
4352
|
}).catch(function(e) {
|
|
4290
4353
|
reject(e);
|
|
4291
4354
|
});
|
|
@@ -4299,30 +4362,6 @@ TextureCubeLoader = __decorate([
|
|
|
4299
4362
|
])
|
|
4300
4363
|
], TextureCubeLoader);
|
|
4301
4364
|
|
|
4302
|
-
var AnimationClipLoader = /*#__PURE__*/ function(Loader) {
|
|
4303
|
-
_inherits(AnimationClipLoader, Loader);
|
|
4304
|
-
function AnimationClipLoader() {
|
|
4305
|
-
return Loader.apply(this, arguments);
|
|
4306
|
-
}
|
|
4307
|
-
var _proto = AnimationClipLoader.prototype;
|
|
4308
|
-
_proto.load = function load(item, resourceManager) {
|
|
4309
|
-
var _this = this;
|
|
4310
|
-
return new miniprogram.AssetPromise(function(resolve, reject) {
|
|
4311
|
-
_this.request(item.url, _extends({}, item, {
|
|
4312
|
-
type: "arraybuffer"
|
|
4313
|
-
})).then(function(data) {
|
|
4314
|
-
return decode(data, resourceManager.engine);
|
|
4315
|
-
}).catch(reject);
|
|
4316
|
-
});
|
|
4317
|
-
};
|
|
4318
|
-
return AnimationClipLoader;
|
|
4319
|
-
}(miniprogram.Loader);
|
|
4320
|
-
AnimationClipLoader = __decorate([
|
|
4321
|
-
miniprogram.resourceLoader(miniprogram.AssetType.AnimationClip, [
|
|
4322
|
-
"ani"
|
|
4323
|
-
])
|
|
4324
|
-
], AnimationClipLoader);
|
|
4325
|
-
|
|
4326
4365
|
var SceneLoader = /*#__PURE__*/ function(Loader) {
|
|
4327
4366
|
_inherits(SceneLoader, Loader);
|
|
4328
4367
|
function SceneLoader() {
|
|
@@ -4408,7 +4447,7 @@ SceneLoader = __decorate([
|
|
|
4408
4447
|
"prefab"
|
|
4409
4448
|
], true)
|
|
4410
4449
|
], SceneLoader);
|
|
4411
|
-
ReflectionParser.registerCustomParseComponent("TextRenderer", /*#__PURE__*/
|
|
4450
|
+
ReflectionParser.registerCustomParseComponent("TextRenderer", /*#__PURE__*/ _async_to_generator(function(instance, item, engine) {
|
|
4412
4451
|
var props;
|
|
4413
4452
|
return __generator(this, function(_state) {
|
|
4414
4453
|
props = item.props;
|
|
@@ -4423,408 +4462,10 @@ ReflectionParser.registerCustomParseComponent("TextRenderer", /*#__PURE__*/ _asy
|
|
|
4423
4462
|
});
|
|
4424
4463
|
}));
|
|
4425
4464
|
|
|
4426
|
-
var _KHR_draco_mesh_compression;
|
|
4427
|
-
var KHR_draco_mesh_compression = (_KHR_draco_mesh_compression = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
4428
|
-
_inherits(KHR_draco_mesh_compression1, GLTFExtensionParser);
|
|
4429
|
-
function KHR_draco_mesh_compression1() {
|
|
4430
|
-
return GLTFExtensionParser.apply(this, arguments);
|
|
4431
|
-
}
|
|
4432
|
-
var _proto = KHR_draco_mesh_compression1.prototype;
|
|
4433
|
-
/**
|
|
4434
|
-
* @override
|
|
4435
|
-
*/ _proto.initialize = function initialize() {
|
|
4436
|
-
if (!KHR_draco_mesh_compression._decoder) {
|
|
4437
|
-
KHR_draco_mesh_compression._decoder = new miniprogram$3.DRACODecoder();
|
|
4438
|
-
}
|
|
4439
|
-
};
|
|
4440
|
-
/**
|
|
4441
|
-
* @override
|
|
4442
|
-
*/ _proto.createAndParse = function createAndParse(context, schema, glTFPrimitive, glTFMesh) {
|
|
4443
|
-
var _this = this;
|
|
4444
|
-
var glTF = context.glTF, buffers = context.buffers, engine = context.glTFResource.engine;
|
|
4445
|
-
var bufferViews = glTF.bufferViews, accessors = glTF.accessors;
|
|
4446
|
-
var bufferViewIndex = schema.bufferView, gltfAttributeMap = schema.attributes;
|
|
4447
|
-
var attributeMap = {};
|
|
4448
|
-
var attributeTypeMap = {};
|
|
4449
|
-
for(var attributeName in gltfAttributeMap){
|
|
4450
|
-
attributeMap[attributeName] = gltfAttributeMap[attributeName];
|
|
4451
|
-
}
|
|
4452
|
-
for(var attributeName1 in glTFPrimitive.attributes){
|
|
4453
|
-
if (gltfAttributeMap[attributeName1] !== undefined) {
|
|
4454
|
-
var accessorDef = accessors[glTFPrimitive.attributes[attributeName1]];
|
|
4455
|
-
attributeTypeMap[attributeName1] = GLTFUtil.getComponentType(accessorDef.componentType).name;
|
|
4456
|
-
}
|
|
4457
|
-
}
|
|
4458
|
-
var indexAccessor = accessors[glTFPrimitive.indices];
|
|
4459
|
-
var indexType = GLTFUtil.getComponentType(indexAccessor.componentType).name;
|
|
4460
|
-
var taskConfig = {
|
|
4461
|
-
attributeIDs: attributeMap,
|
|
4462
|
-
attributeTypes: attributeTypeMap,
|
|
4463
|
-
useUniqueIDs: true,
|
|
4464
|
-
indexType: indexType
|
|
4465
|
-
};
|
|
4466
|
-
var buffer = GLTFUtil.getBufferViewData(bufferViews[bufferViewIndex], buffers);
|
|
4467
|
-
return KHR_draco_mesh_compression._decoder.decode(buffer, taskConfig).then(function(decodedGeometry) {
|
|
4468
|
-
var mesh = new miniprogram.ModelMesh(engine, glTFMesh.name);
|
|
4469
|
-
return _this._parseMeshFromGLTFPrimitiveDraco(mesh, glTFMesh, glTFPrimitive, glTF, function(attributeSemantic) {
|
|
4470
|
-
for(var j = 0; j < decodedGeometry.attributes.length; j++){
|
|
4471
|
-
if (decodedGeometry.attributes[j].name === attributeSemantic) {
|
|
4472
|
-
return decodedGeometry.attributes[j].array;
|
|
4473
|
-
}
|
|
4474
|
-
}
|
|
4475
|
-
return null;
|
|
4476
|
-
}, function(attributeSemantic, shapeIndex) {
|
|
4477
|
-
throw "BlendShape animation is not supported when using draco.";
|
|
4478
|
-
}, function() {
|
|
4479
|
-
return decodedGeometry.index.array;
|
|
4480
|
-
}, context.keepMeshData);
|
|
4481
|
-
});
|
|
4482
|
-
};
|
|
4483
|
-
_proto._parseMeshFromGLTFPrimitiveDraco = function _parseMeshFromGLTFPrimitiveDraco(mesh, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
|
|
4484
|
-
var attributes = gltfPrimitive.attributes, targets = gltfPrimitive.targets, indices = gltfPrimitive.indices, mode = gltfPrimitive.mode;
|
|
4485
|
-
var vertexCount;
|
|
4486
|
-
var accessors = gltf.accessors;
|
|
4487
|
-
var accessor = accessors[attributes["POSITION"]];
|
|
4488
|
-
var positionBuffer = getVertexBufferData("POSITION");
|
|
4489
|
-
var positions = GLTFUtil.floatBufferToVector3Array(positionBuffer);
|
|
4490
|
-
mesh.setPositions(positions);
|
|
4491
|
-
var bounds = mesh.bounds;
|
|
4492
|
-
vertexCount = accessor.count;
|
|
4493
|
-
if (accessor.min && accessor.max) {
|
|
4494
|
-
bounds.min.copyFromArray(accessor.min);
|
|
4495
|
-
bounds.max.copyFromArray(accessor.max);
|
|
4496
|
-
} else {
|
|
4497
|
-
var position = KHR_draco_mesh_compression._tempVector3;
|
|
4498
|
-
var min = bounds.min, max = bounds.max;
|
|
4499
|
-
min.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
|
|
4500
|
-
max.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
|
|
4501
|
-
var stride = positionBuffer.length / vertexCount;
|
|
4502
|
-
for(var j = 0; j < vertexCount; j++){
|
|
4503
|
-
var offset = j * stride;
|
|
4504
|
-
position.copyFromArray(positionBuffer, offset);
|
|
4505
|
-
miniprogram$1.Vector3.min(min, position, min);
|
|
4506
|
-
miniprogram$1.Vector3.max(max, position, max);
|
|
4507
|
-
}
|
|
4508
|
-
}
|
|
4509
|
-
for(var attributeSemantic in attributes){
|
|
4510
|
-
if (attributeSemantic === "POSITION") {
|
|
4511
|
-
continue;
|
|
4512
|
-
}
|
|
4513
|
-
var bufferData = getVertexBufferData(attributeSemantic);
|
|
4514
|
-
switch(attributeSemantic){
|
|
4515
|
-
case "NORMAL":
|
|
4516
|
-
var normals = GLTFUtil.floatBufferToVector3Array(bufferData);
|
|
4517
|
-
mesh.setNormals(normals);
|
|
4518
|
-
break;
|
|
4519
|
-
case "TEXCOORD_0":
|
|
4520
|
-
var texturecoords = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
4521
|
-
mesh.setUVs(texturecoords, 0);
|
|
4522
|
-
break;
|
|
4523
|
-
case "TEXCOORD_1":
|
|
4524
|
-
var texturecoords1 = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
4525
|
-
mesh.setUVs(texturecoords1, 1);
|
|
4526
|
-
break;
|
|
4527
|
-
case "TEXCOORD_2":
|
|
4528
|
-
var texturecoords2 = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
4529
|
-
mesh.setUVs(texturecoords2, 2);
|
|
4530
|
-
break;
|
|
4531
|
-
case "TEXCOORD_3":
|
|
4532
|
-
var texturecoords3 = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
4533
|
-
mesh.setUVs(texturecoords3, 3);
|
|
4534
|
-
break;
|
|
4535
|
-
case "TEXCOORD_4":
|
|
4536
|
-
var texturecoords4 = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
4537
|
-
mesh.setUVs(texturecoords4, 4);
|
|
4538
|
-
break;
|
|
4539
|
-
case "TEXCOORD_5":
|
|
4540
|
-
var texturecoords5 = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
4541
|
-
mesh.setUVs(texturecoords5, 5);
|
|
4542
|
-
break;
|
|
4543
|
-
case "TEXCOORD_6":
|
|
4544
|
-
var texturecoords6 = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
4545
|
-
mesh.setUVs(texturecoords6, 6);
|
|
4546
|
-
break;
|
|
4547
|
-
case "TEXCOORD_7":
|
|
4548
|
-
var texturecoords7 = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
4549
|
-
mesh.setUVs(texturecoords7, 7);
|
|
4550
|
-
break;
|
|
4551
|
-
case "COLOR_0":
|
|
4552
|
-
var colors = GLTFUtil.floatBufferToColorArray(bufferData, accessors[attributes["COLOR_0"]].type === AccessorType.VEC3);
|
|
4553
|
-
mesh.setColors(colors);
|
|
4554
|
-
break;
|
|
4555
|
-
case "TANGENT":
|
|
4556
|
-
var tangents = GLTFUtil.floatBufferToVector4Array(bufferData);
|
|
4557
|
-
mesh.setTangents(tangents);
|
|
4558
|
-
break;
|
|
4559
|
-
case "JOINTS_0":
|
|
4560
|
-
var joints = GLTFUtil.floatBufferToVector4Array(bufferData);
|
|
4561
|
-
mesh.setBoneIndices(joints);
|
|
4562
|
-
break;
|
|
4563
|
-
case "WEIGHTS_0":
|
|
4564
|
-
var weights = GLTFUtil.floatBufferToVector4Array(bufferData);
|
|
4565
|
-
mesh.setBoneWeights(weights);
|
|
4566
|
-
break;
|
|
4567
|
-
}
|
|
4568
|
-
}
|
|
4569
|
-
// Indices
|
|
4570
|
-
if (indices !== undefined) {
|
|
4571
|
-
var indexAccessor = gltf.accessors[indices];
|
|
4572
|
-
var indexData = getIndexBufferData();
|
|
4573
|
-
mesh.setIndices(indexData);
|
|
4574
|
-
mesh.addSubMesh(0, indexAccessor.count, mode);
|
|
4575
|
-
} else {
|
|
4576
|
-
mesh.addSubMesh(0, vertexCount, mode);
|
|
4577
|
-
}
|
|
4578
|
-
// BlendShapes
|
|
4579
|
-
targets && GLTFMeshParser._createBlendShape(mesh, null, gltfMesh, targets, getBlendShapeData);
|
|
4580
|
-
mesh.uploadData(!keepMeshData);
|
|
4581
|
-
return Promise.resolve(mesh);
|
|
4582
|
-
};
|
|
4583
|
-
return KHR_draco_mesh_compression1;
|
|
4584
|
-
}(GLTFExtensionParser), _KHR_draco_mesh_compression._tempVector3 = new miniprogram$1.Vector3(), _KHR_draco_mesh_compression);
|
|
4585
|
-
KHR_draco_mesh_compression = __decorate([
|
|
4586
|
-
registerGLTFExtension("KHR_draco_mesh_compression", exports.GLTFExtensionMode.CreateAndParse)
|
|
4587
|
-
], KHR_draco_mesh_compression);
|
|
4588
|
-
|
|
4589
|
-
var KHR_lights_punctual = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
4590
|
-
_inherits(KHR_lights_punctual, GLTFExtensionParser);
|
|
4591
|
-
function KHR_lights_punctual() {
|
|
4592
|
-
return GLTFExtensionParser.apply(this, arguments);
|
|
4593
|
-
}
|
|
4594
|
-
var _proto = KHR_lights_punctual.prototype;
|
|
4595
|
-
/**
|
|
4596
|
-
* @override
|
|
4597
|
-
*/ _proto.additiveParse = function additiveParse(context, entity, extensionSchema) {
|
|
4598
|
-
var lightsSchema = context.glTF.extensions.KHR_lights_punctual.lights;
|
|
4599
|
-
var lightSchema = lightsSchema[extensionSchema.light];
|
|
4600
|
-
var color = lightSchema.color, _lightSchema_intensity = lightSchema.intensity, intensity = _lightSchema_intensity === void 0 ? 1 : _lightSchema_intensity, type = lightSchema.type, range = lightSchema.range, spot = lightSchema.spot;
|
|
4601
|
-
var glTFResource = context.glTFResource;
|
|
4602
|
-
var light;
|
|
4603
|
-
if (type === "directional") {
|
|
4604
|
-
light = entity.addComponent(miniprogram.DirectLight);
|
|
4605
|
-
} else if (type === "point") {
|
|
4606
|
-
light = entity.addComponent(miniprogram.PointLight);
|
|
4607
|
-
} else if (type === "spot") {
|
|
4608
|
-
light = entity.addComponent(miniprogram.SpotLight);
|
|
4609
|
-
}
|
|
4610
|
-
if (color) {
|
|
4611
|
-
light.color.set(color[0], color[1], color[2], 1);
|
|
4612
|
-
}
|
|
4613
|
-
light.intensity = intensity;
|
|
4614
|
-
if (range && !_instanceof(light, miniprogram.DirectLight)) {
|
|
4615
|
-
light.distance = range;
|
|
4616
|
-
}
|
|
4617
|
-
if (spot && _instanceof(light, miniprogram.SpotLight)) {
|
|
4618
|
-
var _spot_innerConeAngle = spot.innerConeAngle, innerConeAngle = _spot_innerConeAngle === void 0 ? 0 : _spot_innerConeAngle, _spot_outerConeAngle = spot.outerConeAngle, outerConeAngle = _spot_outerConeAngle === void 0 ? Math.PI / 4 : _spot_outerConeAngle;
|
|
4619
|
-
light.angle = innerConeAngle;
|
|
4620
|
-
light.penumbra = outerConeAngle - innerConeAngle;
|
|
4621
|
-
}
|
|
4622
|
-
if (!glTFResource.lights) glTFResource.lights = [];
|
|
4623
|
-
glTFResource.lights.push(light);
|
|
4624
|
-
};
|
|
4625
|
-
return KHR_lights_punctual;
|
|
4626
|
-
}(GLTFExtensionParser);
|
|
4627
|
-
KHR_lights_punctual = __decorate([
|
|
4628
|
-
registerGLTFExtension("KHR_lights_punctual", exports.GLTFExtensionMode.AdditiveParse)
|
|
4629
|
-
], KHR_lights_punctual);
|
|
4630
|
-
|
|
4631
|
-
var KHR_materials_clearcoat = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
4632
|
-
_inherits(KHR_materials_clearcoat, GLTFExtensionParser);
|
|
4633
|
-
function KHR_materials_clearcoat() {
|
|
4634
|
-
return GLTFExtensionParser.apply(this, arguments);
|
|
4635
|
-
}
|
|
4636
|
-
var _proto = KHR_materials_clearcoat.prototype;
|
|
4637
|
-
/**
|
|
4638
|
-
* @override
|
|
4639
|
-
*/ _proto.additiveParse = function additiveParse(context, material, schema) {
|
|
4640
|
-
var textures = context.glTFResource.textures;
|
|
4641
|
-
var _schema_clearcoatFactor = schema.clearcoatFactor, clearcoatFactor = _schema_clearcoatFactor === void 0 ? 0 : _schema_clearcoatFactor, clearcoatTexture = schema.clearcoatTexture, _schema_clearcoatRoughnessFactor = schema.clearcoatRoughnessFactor, clearcoatRoughnessFactor = _schema_clearcoatRoughnessFactor === void 0 ? 0 : _schema_clearcoatRoughnessFactor, clearcoatRoughnessTexture = schema.clearcoatRoughnessTexture, clearcoatNormalTexture = schema.clearcoatNormalTexture;
|
|
4642
|
-
material.clearCoat = clearcoatFactor;
|
|
4643
|
-
material.clearCoatRoughness = clearcoatRoughnessFactor;
|
|
4644
|
-
if (clearcoatTexture) {
|
|
4645
|
-
material.clearCoatTexture = textures[clearcoatTexture.index];
|
|
4646
|
-
GLTFMaterialParser._checkOtherTextureTransform(clearcoatTexture, "Clear coat");
|
|
4647
|
-
}
|
|
4648
|
-
if (clearcoatRoughnessTexture) {
|
|
4649
|
-
material.clearCoatRoughnessTexture = textures[clearcoatRoughnessTexture.index];
|
|
4650
|
-
GLTFMaterialParser._checkOtherTextureTransform(clearcoatRoughnessTexture, "Clear coat roughness");
|
|
4651
|
-
}
|
|
4652
|
-
if (clearcoatNormalTexture) {
|
|
4653
|
-
material.clearCoatNormalTexture = textures[clearcoatNormalTexture.index];
|
|
4654
|
-
GLTFMaterialParser._checkOtherTextureTransform(clearcoatNormalTexture, "Clear coat normal");
|
|
4655
|
-
}
|
|
4656
|
-
};
|
|
4657
|
-
return KHR_materials_clearcoat;
|
|
4658
|
-
}(GLTFExtensionParser);
|
|
4659
|
-
KHR_materials_clearcoat = __decorate([
|
|
4660
|
-
registerGLTFExtension("KHR_materials_clearcoat", exports.GLTFExtensionMode.AdditiveParse)
|
|
4661
|
-
], KHR_materials_clearcoat);
|
|
4662
|
-
|
|
4663
|
-
var KHR_materials_pbrSpecularGlossiness = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
4664
|
-
_inherits(KHR_materials_pbrSpecularGlossiness, GLTFExtensionParser);
|
|
4665
|
-
function KHR_materials_pbrSpecularGlossiness() {
|
|
4666
|
-
return GLTFExtensionParser.apply(this, arguments);
|
|
4667
|
-
}
|
|
4668
|
-
var _proto = KHR_materials_pbrSpecularGlossiness.prototype;
|
|
4669
|
-
/**
|
|
4670
|
-
* @override
|
|
4671
|
-
*/ _proto.createAndParse = function createAndParse(context, schema, ownerSchema) {
|
|
4672
|
-
var _context_glTFResource = context.glTFResource, engine = _context_glTFResource.engine, textures = _context_glTFResource.textures;
|
|
4673
|
-
var material = new miniprogram.PBRSpecularMaterial(engine);
|
|
4674
|
-
var diffuseFactor = schema.diffuseFactor, diffuseTexture = schema.diffuseTexture, specularFactor = schema.specularFactor, glossinessFactor = schema.glossinessFactor, specularGlossinessTexture = schema.specularGlossinessTexture;
|
|
4675
|
-
if (diffuseFactor) {
|
|
4676
|
-
material.baseColor = new miniprogram$1.Color(miniprogram$1.Color.linearToGammaSpace(diffuseFactor[0]), miniprogram$1.Color.linearToGammaSpace(diffuseFactor[1]), miniprogram$1.Color.linearToGammaSpace(diffuseFactor[2]), diffuseFactor[3]);
|
|
4677
|
-
}
|
|
4678
|
-
if (diffuseTexture) {
|
|
4679
|
-
material.baseTexture = textures[diffuseTexture.index];
|
|
4680
|
-
GLTFParser.executeExtensionsAdditiveAndParse(diffuseTexture.extensions, context, material, diffuseTexture);
|
|
4681
|
-
}
|
|
4682
|
-
if (specularFactor) {
|
|
4683
|
-
material.specularColor = new miniprogram$1.Color(miniprogram$1.Color.linearToGammaSpace(specularFactor[0]), miniprogram$1.Color.linearToGammaSpace(specularFactor[1]), miniprogram$1.Color.linearToGammaSpace(specularFactor[2]));
|
|
4684
|
-
}
|
|
4685
|
-
if (glossinessFactor !== undefined) {
|
|
4686
|
-
material.glossiness = glossinessFactor;
|
|
4687
|
-
}
|
|
4688
|
-
if (specularGlossinessTexture) {
|
|
4689
|
-
material.specularGlossinessTexture = textures[specularGlossinessTexture.index];
|
|
4690
|
-
GLTFMaterialParser._checkOtherTextureTransform(specularGlossinessTexture, "Specular glossiness");
|
|
4691
|
-
}
|
|
4692
|
-
material.name = ownerSchema.name;
|
|
4693
|
-
GLTFMaterialParser._parseStandardProperty(context, material, ownerSchema);
|
|
4694
|
-
return material;
|
|
4695
|
-
};
|
|
4696
|
-
return KHR_materials_pbrSpecularGlossiness;
|
|
4697
|
-
}(GLTFExtensionParser);
|
|
4698
|
-
KHR_materials_pbrSpecularGlossiness = __decorate([
|
|
4699
|
-
registerGLTFExtension("KHR_materials_pbrSpecularGlossiness", exports.GLTFExtensionMode.CreateAndParse)
|
|
4700
|
-
], KHR_materials_pbrSpecularGlossiness);
|
|
4701
|
-
|
|
4702
|
-
var KHR_materials_unlit = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
4703
|
-
_inherits(KHR_materials_unlit, GLTFExtensionParser);
|
|
4704
|
-
function KHR_materials_unlit() {
|
|
4705
|
-
return GLTFExtensionParser.apply(this, arguments);
|
|
4706
|
-
}
|
|
4707
|
-
var _proto = KHR_materials_unlit.prototype;
|
|
4708
|
-
/**
|
|
4709
|
-
* @override
|
|
4710
|
-
*/ _proto.createAndParse = function createAndParse(context, _, ownerSchema) {
|
|
4711
|
-
var engine = context.glTFResource.engine;
|
|
4712
|
-
var material = new miniprogram.UnlitMaterial(engine);
|
|
4713
|
-
material.name = ownerSchema.name;
|
|
4714
|
-
GLTFMaterialParser._parseStandardProperty(context, material, ownerSchema);
|
|
4715
|
-
return material;
|
|
4716
|
-
};
|
|
4717
|
-
return KHR_materials_unlit;
|
|
4718
|
-
}(GLTFExtensionParser);
|
|
4719
|
-
KHR_materials_unlit = __decorate([
|
|
4720
|
-
registerGLTFExtension("KHR_materials_unlit", exports.GLTFExtensionMode.CreateAndParse)
|
|
4721
|
-
], KHR_materials_unlit);
|
|
4722
|
-
|
|
4723
|
-
var KHR_mesh_quantization = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
4724
|
-
_inherits(KHR_mesh_quantization, GLTFExtensionParser);
|
|
4725
|
-
function KHR_mesh_quantization() {
|
|
4726
|
-
return GLTFExtensionParser.apply(this, arguments);
|
|
4727
|
-
}
|
|
4728
|
-
return KHR_mesh_quantization;
|
|
4729
|
-
}(GLTFExtensionParser);
|
|
4730
|
-
KHR_mesh_quantization = __decorate([
|
|
4731
|
-
registerGLTFExtension("KHR_mesh_quantization", exports.GLTFExtensionMode.AdditiveParse)
|
|
4732
|
-
], KHR_mesh_quantization);
|
|
4733
|
-
|
|
4734
|
-
var KHR_texture_transform = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
4735
|
-
_inherits(KHR_texture_transform, GLTFExtensionParser);
|
|
4736
|
-
function KHR_texture_transform() {
|
|
4737
|
-
return GLTFExtensionParser.apply(this, arguments);
|
|
4738
|
-
}
|
|
4739
|
-
var _proto = KHR_texture_transform.prototype;
|
|
4740
|
-
/**
|
|
4741
|
-
* @override
|
|
4742
|
-
*/ _proto.additiveParse = function additiveParse(context, material, schema) {
|
|
4743
|
-
var offset = schema.offset, rotation = schema.rotation, scale = schema.scale, texCoord = schema.texCoord;
|
|
4744
|
-
if (offset) {
|
|
4745
|
-
material.tilingOffset.z = offset[0];
|
|
4746
|
-
material.tilingOffset.w = offset[1];
|
|
4747
|
-
}
|
|
4748
|
-
if (scale) {
|
|
4749
|
-
material.tilingOffset.x = scale[0];
|
|
4750
|
-
material.tilingOffset.y = scale[1];
|
|
4751
|
-
}
|
|
4752
|
-
if (rotation) {
|
|
4753
|
-
miniprogram.Logger.warn("rotation in KHR_texture_transform is not supported now");
|
|
4754
|
-
}
|
|
4755
|
-
if (texCoord) {
|
|
4756
|
-
miniprogram.Logger.warn("texCoord in KHR_texture_transform is not supported now");
|
|
4757
|
-
}
|
|
4758
|
-
};
|
|
4759
|
-
return KHR_texture_transform;
|
|
4760
|
-
}(GLTFExtensionParser);
|
|
4761
|
-
KHR_texture_transform = __decorate([
|
|
4762
|
-
registerGLTFExtension("KHR_texture_transform", exports.GLTFExtensionMode.AdditiveParse)
|
|
4763
|
-
], KHR_texture_transform);
|
|
4764
|
-
|
|
4765
|
-
var GalaceanMaterialsRemap = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
4766
|
-
_inherits(GalaceanMaterialsRemap, GLTFExtensionParser);
|
|
4767
|
-
function GalaceanMaterialsRemap() {
|
|
4768
|
-
return GLTFExtensionParser.apply(this, arguments);
|
|
4769
|
-
}
|
|
4770
|
-
var _proto = GalaceanMaterialsRemap.prototype;
|
|
4771
|
-
/**
|
|
4772
|
-
* @override
|
|
4773
|
-
*/ _proto.createAndParse = function createAndParse(context, schema) {
|
|
4774
|
-
var engine = context.glTFResource.engine;
|
|
4775
|
-
// @ts-ignore
|
|
4776
|
-
return engine.resourceManager.getResourceByRef(schema);
|
|
4777
|
-
};
|
|
4778
|
-
return GalaceanMaterialsRemap;
|
|
4779
|
-
}(GLTFExtensionParser);
|
|
4780
|
-
GalaceanMaterialsRemap = __decorate([
|
|
4781
|
-
registerGLTFExtension("OASIS_materials_remap", exports.GLTFExtensionMode.CreateAndParse)
|
|
4782
|
-
], GalaceanMaterialsRemap);
|
|
4783
|
-
|
|
4784
|
-
var OASIS_animation_event = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
4785
|
-
_inherits(OASIS_animation_event, GLTFExtensionParser);
|
|
4786
|
-
function OASIS_animation_event() {
|
|
4787
|
-
return GLTFExtensionParser.apply(this, arguments);
|
|
4788
|
-
}
|
|
4789
|
-
var _proto = OASIS_animation_event.prototype;
|
|
4790
|
-
/**
|
|
4791
|
-
* @override
|
|
4792
|
-
*/ _proto.additiveParse = function additiveParse(context, animationClip, schema) {
|
|
4793
|
-
context.glTFResource.engine;
|
|
4794
|
-
var events = schema.events;
|
|
4795
|
-
events.map(function(eventData) {
|
|
4796
|
-
var event = new miniprogram.AnimationEvent();
|
|
4797
|
-
event.functionName = eventData.functionName;
|
|
4798
|
-
event.time = eventData.time;
|
|
4799
|
-
event.parameter = eventData.parameter;
|
|
4800
|
-
animationClip.addEvent(event);
|
|
4801
|
-
});
|
|
4802
|
-
};
|
|
4803
|
-
return OASIS_animation_event;
|
|
4804
|
-
}(GLTFExtensionParser);
|
|
4805
|
-
OASIS_animation_event = __decorate([
|
|
4806
|
-
registerGLTFExtension("OASIS_animation_event", exports.GLTFExtensionMode.AdditiveParse)
|
|
4807
|
-
], OASIS_animation_event);
|
|
4808
|
-
|
|
4809
4465
|
exports.ComponentMap = ComponentMap;
|
|
4810
|
-
exports.GLTFAnimationParser = GLTFAnimationParser;
|
|
4811
|
-
exports.GLTFBufferParser = GLTFBufferParser;
|
|
4812
|
-
exports.GLTFEntityParser = GLTFEntityParser;
|
|
4813
|
-
exports.GLTFExtensionParser = GLTFExtensionParser;
|
|
4814
|
-
exports.GLTFMaterialParser = GLTFMaterialParser;
|
|
4815
|
-
exports.GLTFMeshParser = GLTFMeshParser;
|
|
4816
|
-
exports.GLTFParser = GLTFParser;
|
|
4817
|
-
exports.GLTFParserContext = GLTFParserContext;
|
|
4818
|
-
exports.GLTFPipeline = GLTFPipeline;
|
|
4819
4466
|
exports.GLTFResource = GLTFResource;
|
|
4820
|
-
exports.GLTFSceneParser = GLTFSceneParser;
|
|
4821
|
-
exports.GLTFSkinParser = GLTFSkinParser;
|
|
4822
|
-
exports.GLTFTextureParser = GLTFTextureParser;
|
|
4823
|
-
exports.GLTFUtil = GLTFUtil;
|
|
4824
|
-
exports.GLTFValidator = GLTFValidator;
|
|
4825
4467
|
exports.PrefabParser = PrefabParser;
|
|
4826
4468
|
exports.ReflectionParser = ReflectionParser;
|
|
4827
4469
|
exports.SceneParser = SceneParser;
|
|
4828
4470
|
exports.decode = decode;
|
|
4829
4471
|
exports.parseSingleKTX = parseSingleKTX;
|
|
4830
|
-
exports.registerGLTFExtension = registerGLTFExtension;
|