@galacean/engine-loader 1.0.0 → 1.0.1
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 +1764 -1208
- package/dist/main.js.map +1 -1
- package/dist/miniprogram.js +1784 -1228
- package/dist/module.js +1751 -1210
- package/dist/module.js.map +1 -1
- package/package.json +5 -5
- package/types/AnimationClipLoader.d.ts +1 -0
- package/types/GLTFContentRestorer.d.ts +92 -0
- package/types/GLTFLoader.d.ts +3 -0
- package/types/ProjectLoader.d.ts +1 -0
- package/types/Texture2DContentRestorer.d.ts +11 -0
- package/types/TextureCubeContentRestorer.d.ts +11 -0
- package/types/gltf/GLTFPipeline.d.ts +23 -0
- package/types/gltf/GLTFResource.d.ts +7 -15
- package/types/gltf/GLTFSchema.d.ts +816 -0
- package/types/gltf/GLTFUtil.d.ts +4 -4
- package/types/gltf/GLTFUtils.d.ts +48 -0
- package/types/gltf/extensions/GALACEAN_animation_event.d.ts +1 -0
- package/types/gltf/extensions/GLTFExtensionParser.d.ts +52 -0
- package/types/gltf/extensions/GLTFExtensionSchema.d.ts +149 -0
- package/types/gltf/extensions/KHR_materials_ior.d.ts +1 -0
- package/types/gltf/extensions/KHR_materials_variants.d.ts +6 -1
- package/types/gltf/extensions/index.d.ts +5 -1
- package/types/gltf/index.d.ts +6 -0
- package/types/gltf/parser/GLTFAnimationParser.d.ts +12 -0
- package/types/gltf/parser/GLTFBufferParser.d.ts +7 -0
- package/types/gltf/parser/GLTFEntityParser.d.ts +9 -0
- package/types/gltf/parser/GLTFMaterialParser.d.ts +15 -0
- package/types/gltf/parser/GLTFMeshParser.d.ts +19 -0
- package/types/gltf/parser/GLTFParser.d.ts +63 -0
- package/types/gltf/parser/GLTFParserContext.d.ts +53 -0
- package/types/gltf/parser/GLTFSceneParser.d.ts +11 -0
- package/types/gltf/parser/GLTFSchemaParser.d.ts +7 -0
- package/types/gltf/parser/GLTFSkinParser.d.ts +7 -0
- package/types/gltf/parser/GLTFTextureParser.d.ts +9 -0
- package/types/gltf/parser/GLTFValidator.d.ts +6 -0
- package/types/gltf/parser/index.d.ts +11 -0
- package/types/index.d.ts +2 -2
- package/types/ktx2/BinomialLLCTranscoder/BinomialLLCTranscoder.d.ts +13 -0
- package/types/ktx2/BinomialLLCTranscoder/TranscodeWorkerCode.d.ts +33 -0
- package/types/ktx2/KTX2Container.d.ts +72 -0
- package/types/ktx2/KTX2Loader.d.ts +53 -0
- package/types/ktx2/KTX2TargetFormat.d.ts +21 -0
- package/types/ktx2/KhronosTranscoder/KhronosTranscoder.d.ts +17 -0
- package/types/ktx2/KhronosTranscoder/TranscoderWorkerCode.d.ts +34 -0
- package/types/ktx2/TranscodeResult.d.ts +10 -0
- package/types/ktx2/WorkerPool.d.ts +32 -0
- package/types/ktx2/constants.d.ts +7 -0
- package/types/ktx2/transcoder/AbstractTranscoder.d.ts +55 -0
- package/types/ktx2/transcoder/BinomialLLCTranscoder.d.ts +8 -0
- package/types/ktx2/transcoder/BinomialLLCWorkerCode.d.ts +2 -0
- package/types/ktx2/transcoder/KhronosTranscoder.d.ts +13 -0
- package/types/ktx2/transcoder/KhronosWorkerCode.d.ts +1 -0
- package/types/ktx2/zstddec.d.ts +62 -0
- package/types/resource-deserialize/index.d.ts +3 -3
- package/types/resource-deserialize/resources/mesh/MeshDecoder.d.ts +1 -1
- package/types/resource-deserialize/resources/parser/PrefabParser.d.ts +5 -0
- package/types/resource-deserialize/resources/parser/ReflectionParser.d.ts +14 -0
- package/types/resource-deserialize/resources/scene/SceneParser.d.ts +1 -1
- package/types/resource-deserialize/resources/scene/SceneParserContext.d.ts +1 -1
- package/types/resource-deserialize/resources/schema/BasicSchema.d.ts +61 -0
- package/types/resource-deserialize/resources/schema/MaterialSchema.d.ts +91 -0
- package/types/resource-deserialize/resources/schema/ProjectSchema.d.ts +9 -0
- package/types/resource-deserialize/resources/schema/SceneSchema.d.ts +41 -0
- package/types/resource-deserialize/resources/schema/index.d.ts +3 -0
package/dist/miniprogram.js
CHANGED
|
@@ -5,8 +5,8 @@ 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-rhi-webgl/dist/miniprogram');
|
|
9
|
+
var miniprogram$3 = require('@galacean/engine-draco/dist/miniprogram');
|
|
10
10
|
|
|
11
11
|
function _extends() {
|
|
12
12
|
_extends = Object.assign || function assign(target) {
|
|
@@ -91,10 +91,10 @@ function __generator(thisArg, body) {
|
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
var AnimatorControllerLoader = /*#__PURE__*/ function(
|
|
95
|
-
_inherits(AnimatorControllerLoader,
|
|
94
|
+
var AnimatorControllerLoader = /*#__PURE__*/ function(Loader1) {
|
|
95
|
+
_inherits(AnimatorControllerLoader, Loader1);
|
|
96
96
|
function AnimatorControllerLoader() {
|
|
97
|
-
return
|
|
97
|
+
return Loader1.apply(this, arguments);
|
|
98
98
|
}
|
|
99
99
|
var _proto = AnimatorControllerLoader.prototype;
|
|
100
100
|
_proto.load = function load(item, resourceManager) {
|
|
@@ -115,13 +115,17 @@ var AnimatorControllerLoader = /*#__PURE__*/ function(Loader) {
|
|
|
115
115
|
var states = stateMachineData.states;
|
|
116
116
|
var stateMachine = layer.stateMachine = new miniprogram.AnimatorStateMachine();
|
|
117
117
|
states.forEach(function(stateData, stateIndex) {
|
|
118
|
-
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, scripts = stateData.scripts;
|
|
119
119
|
var state = stateMachine.addState(name);
|
|
120
120
|
isDefaultState && (stateMachine.defaultState = state);
|
|
121
121
|
state.speed = speed;
|
|
122
122
|
state.wrapMode = wrapMode;
|
|
123
123
|
state.clipStartTime = clipStartNormalizedTime;
|
|
124
124
|
state.clipEndTime = clipEndNormalizedTime;
|
|
125
|
+
var scriptsObject = JSON.parse(scripts);
|
|
126
|
+
scriptsObject == null ? void 0 : scriptsObject.forEach(function(script) {
|
|
127
|
+
state.addStateMachineScript(miniprogram.Loader.getClass(script));
|
|
128
|
+
});
|
|
125
129
|
if (clipData) {
|
|
126
130
|
promises.push(new Promise(function(resolve) {
|
|
127
131
|
//@ts-ignore
|
|
@@ -219,7 +223,8 @@ var EnvLoader = /*#__PURE__*/ function(Loader) {
|
|
|
219
223
|
var shArray = new Float32Array(arraybuffer, 0, 27);
|
|
220
224
|
var shByteLength = 27 * 4;
|
|
221
225
|
var size = (_ref = new Uint16Array(arraybuffer, shByteLength, 1)) == null ? void 0 : _ref[0];
|
|
222
|
-
var
|
|
226
|
+
var engine = resourceManager.engine;
|
|
227
|
+
var texture = new miniprogram.TextureCube(engine, size);
|
|
223
228
|
texture.filterMode = miniprogram.TextureFilterMode.Trilinear;
|
|
224
229
|
var mipmapCount = texture.mipmapCount;
|
|
225
230
|
var offset = shByteLength + 2;
|
|
@@ -232,7 +237,7 @@ var EnvLoader = /*#__PURE__*/ function(Loader) {
|
|
|
232
237
|
texture.setPixelBuffer(miniprogram.TextureCubeFace.PositiveX + face, data, mipLevel);
|
|
233
238
|
}
|
|
234
239
|
}
|
|
235
|
-
var ambientLight = new miniprogram.AmbientLight();
|
|
240
|
+
var ambientLight = new miniprogram.AmbientLight(engine);
|
|
236
241
|
var sh = new miniprogram$1.SphericalHarmonics3();
|
|
237
242
|
ambientLight.diffuseMode = miniprogram.DiffuseMode.SphericalHarmonics;
|
|
238
243
|
sh.copyFromArray(shArray);
|
|
@@ -342,52 +347,205 @@ FontLoader = __decorate([
|
|
|
342
347
|
], false)
|
|
343
348
|
], FontLoader);
|
|
344
349
|
|
|
350
|
+
function _array_like_to_array(arr, len) {
|
|
351
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
352
|
+
|
|
353
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
354
|
+
|
|
355
|
+
return arr2;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
359
|
+
if (!o) return;
|
|
360
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
361
|
+
|
|
362
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
363
|
+
|
|
364
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
365
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
366
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
|
|
370
|
+
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
371
|
+
|
|
372
|
+
if (it) return (it = it.call(o)).next.bind(it);
|
|
373
|
+
// Fallback for engines without symbol support
|
|
374
|
+
if (Array.isArray(o) || (it = _unsupported_iterable_to_array(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
375
|
+
if (it) o = it;
|
|
376
|
+
|
|
377
|
+
var i = 0;
|
|
378
|
+
|
|
379
|
+
return function() {
|
|
380
|
+
if (i >= o.length) return { done: true };
|
|
381
|
+
|
|
382
|
+
return { done: false, value: o[i++] };
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
387
|
+
}
|
|
388
|
+
|
|
345
389
|
/**
|
|
346
390
|
* @internal
|
|
347
|
-
*/ var
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
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);
|
|
391
|
+
*/ var GLTFContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
|
|
392
|
+
_inherits(GLTFContentRestorer, ContentRestorer);
|
|
393
|
+
function GLTFContentRestorer() {
|
|
394
|
+
var _this;
|
|
395
|
+
_this = ContentRestorer.apply(this, arguments) || this;
|
|
396
|
+
_this.bufferRequests = [];
|
|
397
|
+
_this.glbBufferSlices = [];
|
|
398
|
+
_this.bufferTextures = [];
|
|
399
|
+
_this.meshes = [];
|
|
400
|
+
return _this;
|
|
366
401
|
}
|
|
367
|
-
var _proto =
|
|
368
|
-
_proto.
|
|
369
|
-
var
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
402
|
+
var _proto = GLTFContentRestorer.prototype;
|
|
403
|
+
_proto.restoreContent = function restoreContent() {
|
|
404
|
+
var _this = this;
|
|
405
|
+
return new miniprogram.AssetPromise(function(resolve, reject) {
|
|
406
|
+
Promise.all(_this.bufferRequests.map(function(bufferRequestInfo) {
|
|
407
|
+
return miniprogram.request(bufferRequestInfo.url, bufferRequestInfo.config);
|
|
408
|
+
})).then(function(buffers) {
|
|
409
|
+
// Buffer parse
|
|
410
|
+
if (_this.isGLB) {
|
|
411
|
+
var glbBufferSlice = _this.glbBufferSlices;
|
|
412
|
+
var bigBuffer = buffers[0];
|
|
413
|
+
var bufferCount = glbBufferSlice.length;
|
|
414
|
+
buffers.length = bufferCount;
|
|
415
|
+
for(var i = 0; i < bufferCount; i++){
|
|
416
|
+
var slice = glbBufferSlice[i];
|
|
417
|
+
buffers[i] = bigBuffer.slice(slice.x, slice.x + slice.y);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
// Restore texture
|
|
421
|
+
miniprogram.AssetPromise.all(_this.bufferTextures.map(function(textureRestoreInfo) {
|
|
422
|
+
var bufferView = textureRestoreInfo.bufferView;
|
|
423
|
+
var buffer = buffers[bufferView.buffer];
|
|
424
|
+
var _bufferView_byteOffset;
|
|
425
|
+
var bufferData = new Uint8Array(buffer, (_bufferView_byteOffset = bufferView.byteOffset) != null ? _bufferView_byteOffset : 0, bufferView.byteLength);
|
|
426
|
+
return GLTFUtils.loadImageBuffer(bufferData, textureRestoreInfo.mimeType).then(function(image) {
|
|
427
|
+
textureRestoreInfo.texture.setImageSource(image);
|
|
428
|
+
textureRestoreInfo.texture.generateMipmaps();
|
|
429
|
+
});
|
|
430
|
+
})).then(function() {
|
|
431
|
+
// Restore mesh
|
|
432
|
+
for(var _iterator = _create_for_of_iterator_helper_loose(_this.meshes), _step; !(_step = _iterator()).done;){
|
|
433
|
+
var meshInfo = _step.value;
|
|
434
|
+
var mesh = meshInfo.mesh;
|
|
435
|
+
for(var _iterator1 = _create_for_of_iterator_helper_loose(meshInfo.vertexBuffers), _step1; !(_step1 = _iterator1()).done;){
|
|
436
|
+
var bufferRestoreInfo = _step1.value;
|
|
437
|
+
var vertexData = _this._getBufferData(buffers, bufferRestoreInfo.data);
|
|
438
|
+
bufferRestoreInfo.buffer.setData(vertexData);
|
|
439
|
+
}
|
|
440
|
+
if (meshInfo.indexBuffer) {
|
|
441
|
+
var indexData = _this._getBufferData(buffers, meshInfo.indexBuffer);
|
|
442
|
+
mesh.setIndices(indexData);
|
|
443
|
+
}
|
|
444
|
+
for(var _iterator2 = _create_for_of_iterator_helper_loose(meshInfo.blendShapes), _step2; !(_step2 = _iterator2()).done;){
|
|
445
|
+
var restoreInfo = _step2.value;
|
|
446
|
+
var frame = restoreInfo.blendShape.frames[0];
|
|
447
|
+
var position = restoreInfo.position;
|
|
448
|
+
var positionData = _this._getBufferData(buffers, position.buffer);
|
|
449
|
+
frame.deltaPositions = GLTFUtils.bufferToVector3Array(positionData, position.stride, position.byteOffset, position.count);
|
|
450
|
+
if (restoreInfo.normal) {
|
|
451
|
+
var normal = restoreInfo.normal;
|
|
452
|
+
var normalData = _this._getBufferData(buffers, normal.buffer);
|
|
453
|
+
frame.deltaNormals = GLTFUtils.bufferToVector3Array(normalData, normal.stride, normal.byteOffset, normal.count);
|
|
454
|
+
}
|
|
455
|
+
if (restoreInfo.tangent) {
|
|
456
|
+
var tangent = restoreInfo.tangent;
|
|
457
|
+
var tangentData = _this._getBufferData(buffers, tangent.buffer);
|
|
458
|
+
frame.deltaTangents = GLTFUtils.bufferToVector3Array(tangentData, tangent.stride, tangent.byteOffset, tangent.count);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
mesh.uploadData(true);
|
|
462
|
+
}
|
|
463
|
+
resolve(_this.resource);
|
|
464
|
+
}).catch(reject);
|
|
465
|
+
}).catch(reject);
|
|
374
466
|
});
|
|
375
|
-
promiseInfo.promise = promise;
|
|
376
|
-
return promise;
|
|
377
467
|
};
|
|
378
|
-
|
|
379
|
-
|
|
468
|
+
_proto._getBufferData = function _getBufferData(buffers, restoreInfo) {
|
|
469
|
+
var main = restoreInfo.main;
|
|
470
|
+
var buffer = buffers[main.bufferIndex];
|
|
471
|
+
var data = new main.TypedArray(buffer, main.byteOffset, main.length);
|
|
472
|
+
var sparseCount = restoreInfo.sparseCount;
|
|
473
|
+
if (sparseCount) {
|
|
474
|
+
var sparseIndex = restoreInfo.sparseIndices;
|
|
475
|
+
var sparseIndexBuffer = buffers[sparseIndex.bufferIndex];
|
|
476
|
+
var sparseIndexData = new sparseIndex.TypedArray(sparseIndexBuffer, sparseIndex.byteOffset, sparseIndex.length);
|
|
477
|
+
var sparseValue = restoreInfo.sparseValues;
|
|
478
|
+
var sparseValueBuffer = buffers[sparseValue.bufferIndex];
|
|
479
|
+
var sparseValueData = new sparseValue.TypedArray(sparseValueBuffer, sparseValue.byteOffset, sparseValue.length);
|
|
480
|
+
var typeSize = restoreInfo.typeSize;
|
|
481
|
+
for(var i = 0; i < sparseCount; i++){
|
|
482
|
+
var replaceIndex = sparseIndexData[i];
|
|
483
|
+
for(var j = 0; j < typeSize; j++){
|
|
484
|
+
data[replaceIndex * typeSize + j] = sparseValueData[i * typeSize + j];
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
return data;
|
|
489
|
+
};
|
|
490
|
+
return GLTFContentRestorer;
|
|
491
|
+
}(miniprogram.ContentRestorer);
|
|
380
492
|
/**
|
|
381
493
|
* @internal
|
|
382
|
-
*/ var
|
|
494
|
+
*/ var BufferRequestInfo = function BufferRequestInfo(url, config) {
|
|
495
|
+
this.url = url;
|
|
496
|
+
this.config = config;
|
|
497
|
+
};
|
|
498
|
+
/**
|
|
499
|
+
* @internal
|
|
500
|
+
*/ var BufferTextureRestoreInfo = function BufferTextureRestoreInfo(texture, bufferView, mimeType) {
|
|
501
|
+
this.texture = texture;
|
|
502
|
+
this.bufferView = bufferView;
|
|
503
|
+
this.mimeType = mimeType;
|
|
504
|
+
};
|
|
505
|
+
/**
|
|
506
|
+
* @internal
|
|
507
|
+
*/ var ModelMeshRestoreInfo = function ModelMeshRestoreInfo() {
|
|
508
|
+
this.vertexBuffers = [];
|
|
509
|
+
this.blendShapes = [];
|
|
510
|
+
};
|
|
511
|
+
/**
|
|
512
|
+
* @internal
|
|
513
|
+
*/ var BufferRestoreInfo = function BufferRestoreInfo(buffer, data) {
|
|
514
|
+
this.buffer = buffer;
|
|
383
515
|
this.data = data;
|
|
384
|
-
this.interleaved = interleaved;
|
|
385
|
-
this.stride = stride;
|
|
386
|
-
this.vertexBindingInfos = {};
|
|
387
516
|
};
|
|
388
517
|
/**
|
|
389
518
|
* @internal
|
|
390
|
-
*/ var
|
|
519
|
+
*/ var BufferDataRestoreInfo = function BufferDataRestoreInfo(main, typeSize, sparseCount, sparseIndices, sparseValues) {
|
|
520
|
+
this.main = main;
|
|
521
|
+
this.typeSize = typeSize;
|
|
522
|
+
this.sparseCount = sparseCount;
|
|
523
|
+
this.sparseIndices = sparseIndices;
|
|
524
|
+
this.sparseValues = sparseValues;
|
|
525
|
+
};
|
|
526
|
+
/**
|
|
527
|
+
* @internal
|
|
528
|
+
*/ var RestoreDataAccessor = function RestoreDataAccessor(bufferIndex, TypedArray, byteOffset, length) {
|
|
529
|
+
this.bufferIndex = bufferIndex;
|
|
530
|
+
this.TypedArray = TypedArray;
|
|
531
|
+
this.byteOffset = byteOffset;
|
|
532
|
+
this.length = length;
|
|
533
|
+
};
|
|
534
|
+
/**
|
|
535
|
+
* @internal
|
|
536
|
+
*/ var BlendShapeRestoreInfo = function BlendShapeRestoreInfo(blendShape, position, normal, tangent) {
|
|
537
|
+
this.blendShape = blendShape;
|
|
538
|
+
this.position = position;
|
|
539
|
+
this.normal = normal;
|
|
540
|
+
this.tangent = tangent;
|
|
541
|
+
};
|
|
542
|
+
/**
|
|
543
|
+
* @internal
|
|
544
|
+
*/ var BlendShapeDataRestoreInfo = function BlendShapeDataRestoreInfo(buffer, stride, byteOffset, count) {
|
|
545
|
+
this.buffer = buffer;
|
|
546
|
+
this.stride = stride;
|
|
547
|
+
this.byteOffset = byteOffset;
|
|
548
|
+
this.count = count;
|
|
391
549
|
};
|
|
392
550
|
|
|
393
551
|
/**
|
|
@@ -539,9 +697,62 @@ var TextureWrapMode;
|
|
|
539
697
|
|
|
540
698
|
/**
|
|
541
699
|
* @internal
|
|
542
|
-
*/ var
|
|
543
|
-
function
|
|
544
|
-
|
|
700
|
+
*/ var GLTFParserContext = /*#__PURE__*/ function() {
|
|
701
|
+
function GLTFParserContext(url) {
|
|
702
|
+
this.hasSkinned = false;
|
|
703
|
+
this.chainPromises = [];
|
|
704
|
+
this.accessorBufferCache = {};
|
|
705
|
+
this.texturesPromiseInfo = new PromiseInfo();
|
|
706
|
+
this.materialsPromiseInfo = new PromiseInfo();
|
|
707
|
+
this.meshesPromiseInfo = new PromiseInfo();
|
|
708
|
+
this.animationClipsPromiseInfo = new PromiseInfo();
|
|
709
|
+
this.defaultSceneRootPromiseInfo = new PromiseInfo();
|
|
710
|
+
this.masterPromiseInfo = new PromiseInfo();
|
|
711
|
+
this.promiseMap = {};
|
|
712
|
+
var promiseMap = this.promiseMap;
|
|
713
|
+
promiseMap["" + url + "?q=textures"] = this._initPromiseInfo(this.texturesPromiseInfo);
|
|
714
|
+
promiseMap["" + url + "?q=materials"] = this._initPromiseInfo(this.materialsPromiseInfo);
|
|
715
|
+
promiseMap["" + url + "?q=meshes"] = this._initPromiseInfo(this.meshesPromiseInfo);
|
|
716
|
+
promiseMap["" + url + "?q=animations"] = this._initPromiseInfo(this.animationClipsPromiseInfo);
|
|
717
|
+
promiseMap["" + url + "?q=defaultSceneRoot"] = this._initPromiseInfo(this.defaultSceneRootPromiseInfo);
|
|
718
|
+
promiseMap["" + url] = this._initPromiseInfo(this.masterPromiseInfo);
|
|
719
|
+
}
|
|
720
|
+
var _proto = GLTFParserContext.prototype;
|
|
721
|
+
/**
|
|
722
|
+
* Get all the buffer data.
|
|
723
|
+
*/ _proto.getBuffers = function getBuffers() {
|
|
724
|
+
return Promise.resolve(this._buffers);
|
|
725
|
+
};
|
|
726
|
+
_proto._initPromiseInfo = function _initPromiseInfo(promiseInfo) {
|
|
727
|
+
var promise = new miniprogram.AssetPromise(function(resolve, reject, setProgress, onCancel) {
|
|
728
|
+
promiseInfo.resolve = resolve;
|
|
729
|
+
promiseInfo.reject = reject;
|
|
730
|
+
promiseInfo.setProgress = setProgress;
|
|
731
|
+
promiseInfo.onCancel = onCancel;
|
|
732
|
+
});
|
|
733
|
+
promiseInfo.promise = promise;
|
|
734
|
+
return promise;
|
|
735
|
+
};
|
|
736
|
+
return GLTFParserContext;
|
|
737
|
+
}();
|
|
738
|
+
/**
|
|
739
|
+
* @internal
|
|
740
|
+
*/ var BufferInfo = function BufferInfo(data, interleaved, stride) {
|
|
741
|
+
this.data = data;
|
|
742
|
+
this.interleaved = interleaved;
|
|
743
|
+
this.stride = stride;
|
|
744
|
+
this.vertexBindingInfos = {};
|
|
745
|
+
};
|
|
746
|
+
/**
|
|
747
|
+
* @internal
|
|
748
|
+
*/ var PromiseInfo = function PromiseInfo() {
|
|
749
|
+
};
|
|
750
|
+
|
|
751
|
+
/**
|
|
752
|
+
* @internal
|
|
753
|
+
*/ var GLTFUtils = /*#__PURE__*/ function() {
|
|
754
|
+
function GLTFUtils() {}
|
|
755
|
+
GLTFUtils.floatBufferToVector2Array = function floatBufferToVector2Array(buffer) {
|
|
545
756
|
var bufferLen = buffer.length;
|
|
546
757
|
var array = new Array(bufferLen / 2);
|
|
547
758
|
for(var i = 0; i < bufferLen; i += 2){
|
|
@@ -549,7 +760,7 @@ var TextureWrapMode;
|
|
|
549
760
|
}
|
|
550
761
|
return array;
|
|
551
762
|
};
|
|
552
|
-
|
|
763
|
+
GLTFUtils.floatBufferToVector3Array = function floatBufferToVector3Array(buffer) {
|
|
553
764
|
var bufferLen = buffer.length;
|
|
554
765
|
var array = new Array(bufferLen / 3);
|
|
555
766
|
for(var i = 0; i < bufferLen; i += 3){
|
|
@@ -557,7 +768,7 @@ var TextureWrapMode;
|
|
|
557
768
|
}
|
|
558
769
|
return array;
|
|
559
770
|
};
|
|
560
|
-
|
|
771
|
+
GLTFUtils.floatBufferToVector4Array = function floatBufferToVector4Array(buffer) {
|
|
561
772
|
var bufferLen = buffer.length;
|
|
562
773
|
var array = new Array(bufferLen / 4);
|
|
563
774
|
for(var i = 0; i < bufferLen; i += 4){
|
|
@@ -565,7 +776,7 @@ var TextureWrapMode;
|
|
|
565
776
|
}
|
|
566
777
|
return array;
|
|
567
778
|
};
|
|
568
|
-
|
|
779
|
+
GLTFUtils.floatBufferToColorArray = function floatBufferToColorArray(buffer, isColor3) {
|
|
569
780
|
var bufferLen = buffer.length;
|
|
570
781
|
var colors = new Array(bufferLen / (isColor3 ? 3 : 4));
|
|
571
782
|
if (isColor3) {
|
|
@@ -580,21 +791,8 @@ var TextureWrapMode;
|
|
|
580
791
|
return colors;
|
|
581
792
|
};
|
|
582
793
|
/**
|
|
583
|
-
* Parse binary text for glb loader.
|
|
584
|
-
*/ GLTFUtil.decodeText = function decodeText(array) {
|
|
585
|
-
if (typeof TextDecoder !== "undefined") {
|
|
586
|
-
return new TextDecoder().decode(array);
|
|
587
|
-
}
|
|
588
|
-
// TextDecoder polyfill
|
|
589
|
-
var s = "";
|
|
590
|
-
for(var i = 0, il = array.length; i < il; i++){
|
|
591
|
-
s += String.fromCharCode(array[i]);
|
|
592
|
-
}
|
|
593
|
-
return decodeURIComponent(encodeURIComponent(s));
|
|
594
|
-
};
|
|
595
|
-
/**
|
|
596
794
|
* Get the number of bytes occupied by accessor type.
|
|
597
|
-
*/
|
|
795
|
+
*/ GLTFUtils.getAccessorTypeSize = function getAccessorTypeSize(accessorType) {
|
|
598
796
|
switch(accessorType){
|
|
599
797
|
case AccessorType.SCALAR:
|
|
600
798
|
return 1;
|
|
@@ -614,7 +812,7 @@ var TextureWrapMode;
|
|
|
614
812
|
};
|
|
615
813
|
/**
|
|
616
814
|
* Get the TypedArray corresponding to the component type.
|
|
617
|
-
*/
|
|
815
|
+
*/ GLTFUtils.getComponentType = function getComponentType(componentType) {
|
|
618
816
|
switch(componentType){
|
|
619
817
|
case AccessorComponentType.BYTE:
|
|
620
818
|
return Int8Array;
|
|
@@ -630,7 +828,7 @@ var TextureWrapMode;
|
|
|
630
828
|
return Float32Array;
|
|
631
829
|
}
|
|
632
830
|
};
|
|
633
|
-
|
|
831
|
+
GLTFUtils.getNormalizedComponentScale = function getNormalizedComponentScale(componentType) {
|
|
634
832
|
// Reference: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization#encoding-quantized-data
|
|
635
833
|
switch(componentType){
|
|
636
834
|
case AccessorComponentType.BYTE:
|
|
@@ -645,60 +843,75 @@ var TextureWrapMode;
|
|
|
645
843
|
throw new Error("Galacean.GLTFLoader: Unsupported normalized accessor component type.");
|
|
646
844
|
}
|
|
647
845
|
};
|
|
648
|
-
|
|
649
|
-
var buffers = context.buffers;
|
|
650
|
-
var bufferViews = gltf.bufferViews;
|
|
846
|
+
GLTFUtils.getAccessorBuffer = function getAccessorBuffer(context, bufferViews, accessor) {
|
|
651
847
|
var componentType = accessor.componentType;
|
|
652
848
|
var bufferView = bufferViews[accessor.bufferView];
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
var
|
|
666
|
-
var
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
var
|
|
671
|
-
var
|
|
672
|
-
|
|
673
|
-
|
|
849
|
+
return context.getBuffers().then(function(buffers) {
|
|
850
|
+
var bufferIndex = bufferView.buffer;
|
|
851
|
+
var buffer = buffers[bufferIndex];
|
|
852
|
+
var _bufferView_byteOffset;
|
|
853
|
+
var bufferByteOffset = (_bufferView_byteOffset = bufferView.byteOffset) != null ? _bufferView_byteOffset : 0;
|
|
854
|
+
var _accessor_byteOffset;
|
|
855
|
+
var byteOffset = (_accessor_byteOffset = accessor.byteOffset) != null ? _accessor_byteOffset : 0;
|
|
856
|
+
var TypedArray = GLTFUtils.getComponentType(componentType);
|
|
857
|
+
var dataElementSize = GLTFUtils.getAccessorTypeSize(accessor.type);
|
|
858
|
+
var dataElementBytes = TypedArray.BYTES_PER_ELEMENT;
|
|
859
|
+
var elementStride = dataElementSize * dataElementBytes;
|
|
860
|
+
var accessorCount = accessor.count;
|
|
861
|
+
var bufferStride = bufferView.byteStride;
|
|
862
|
+
var bufferInfo;
|
|
863
|
+
// According to the glTF official documentation only byteStride not undefined is allowed
|
|
864
|
+
if (bufferStride !== undefined && bufferStride !== elementStride) {
|
|
865
|
+
var bufferSlice = Math.floor(byteOffset / bufferStride);
|
|
866
|
+
var bufferCacheKey = accessor.bufferView + ":" + componentType + ":" + bufferSlice + ":" + accessorCount;
|
|
867
|
+
var accessorBufferCache = context.accessorBufferCache;
|
|
868
|
+
bufferInfo = accessorBufferCache[bufferCacheKey];
|
|
869
|
+
if (!bufferInfo) {
|
|
870
|
+
var offset = bufferByteOffset + bufferSlice * bufferStride;
|
|
871
|
+
var count = accessorCount * (bufferStride / dataElementBytes);
|
|
872
|
+
var data = new TypedArray(buffer, offset, count);
|
|
873
|
+
accessorBufferCache[bufferCacheKey] = bufferInfo = new BufferInfo(data, true, bufferStride);
|
|
874
|
+
bufferInfo.restoreInfo = new BufferDataRestoreInfo(new RestoreDataAccessor(bufferIndex, TypedArray, offset, count));
|
|
875
|
+
}
|
|
876
|
+
} else {
|
|
877
|
+
var offset1 = bufferByteOffset + byteOffset;
|
|
878
|
+
var count1 = accessorCount * dataElementSize;
|
|
879
|
+
var data1 = new TypedArray(buffer, offset1, count1);
|
|
880
|
+
bufferInfo = new BufferInfo(data1, false, elementStride);
|
|
881
|
+
bufferInfo.restoreInfo = new BufferDataRestoreInfo(new RestoreDataAccessor(bufferIndex, TypedArray, offset1, count1));
|
|
674
882
|
}
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
883
|
+
if (accessor.sparse) {
|
|
884
|
+
GLTFUtils.processingSparseData(bufferViews, accessor, buffers, bufferInfo);
|
|
885
|
+
}
|
|
886
|
+
return bufferInfo;
|
|
887
|
+
});
|
|
888
|
+
};
|
|
889
|
+
GLTFUtils.bufferToVector3Array = function bufferToVector3Array(data, byteStride, accessorByteOffset, count) {
|
|
890
|
+
var bytesPerElement = data.BYTES_PER_ELEMENT;
|
|
891
|
+
var offset = accessorByteOffset % byteStride / bytesPerElement;
|
|
892
|
+
var stride = byteStride / bytesPerElement;
|
|
893
|
+
var vector3s = new Array(count);
|
|
894
|
+
for(var i = 0; i < count; i++){
|
|
895
|
+
var index = offset + i * stride;
|
|
896
|
+
vector3s[i] = new miniprogram$1.Vector3(data[index], data[index + 1], data[index + 2]);
|
|
684
897
|
}
|
|
685
|
-
return
|
|
898
|
+
return vector3s;
|
|
686
899
|
};
|
|
687
900
|
/**
|
|
688
901
|
* @deprecated
|
|
689
902
|
* Get accessor data.
|
|
690
|
-
*/
|
|
691
|
-
var bufferViews =
|
|
903
|
+
*/ GLTFUtils.getAccessorData = function getAccessorData(glTF, accessor, buffers) {
|
|
904
|
+
var bufferViews = glTF.bufferViews;
|
|
692
905
|
var bufferView = bufferViews[accessor.bufferView];
|
|
693
906
|
var arrayBuffer = buffers[bufferView.buffer];
|
|
694
907
|
var accessorByteOffset = accessor.hasOwnProperty("byteOffset") ? accessor.byteOffset : 0;
|
|
695
908
|
var bufferViewByteOffset = bufferView.hasOwnProperty("byteOffset") ? bufferView.byteOffset : 0;
|
|
696
909
|
var byteOffset = accessorByteOffset + bufferViewByteOffset;
|
|
697
|
-
var accessorTypeSize =
|
|
910
|
+
var accessorTypeSize = GLTFUtils.getAccessorTypeSize(accessor.type);
|
|
698
911
|
var length = accessorTypeSize * accessor.count;
|
|
699
912
|
var _bufferView_byteStride;
|
|
700
913
|
var byteStride = (_bufferView_byteStride = bufferView.byteStride) != null ? _bufferView_byteStride : 0;
|
|
701
|
-
var arrayType =
|
|
914
|
+
var arrayType = GLTFUtils.getComponentType(accessor.componentType);
|
|
702
915
|
var uint8Array;
|
|
703
916
|
if (byteStride) {
|
|
704
917
|
var accessorByteSize = accessorTypeSize * arrayType.BYTES_PER_ELEMENT;
|
|
@@ -725,7 +938,7 @@ var TextureWrapMode;
|
|
|
725
938
|
var _values_byteOffset, _valuesBufferView_byteOffset;
|
|
726
939
|
var valuesByteOffset = ((_values_byteOffset = values.byteOffset) != null ? _values_byteOffset : 0) + ((_valuesBufferView_byteOffset = valuesBufferView.byteOffset) != null ? _valuesBufferView_byteOffset : 0);
|
|
727
940
|
var valuesByteLength = valuesBufferView.byteLength;
|
|
728
|
-
var indicesType =
|
|
941
|
+
var indicesType = GLTFUtils.getComponentType(indices.componentType);
|
|
729
942
|
var indicesArray = new indicesType(indicesArrayBuffer, indicesByteOffset, indicesByteLength / indicesType.BYTES_PER_ELEMENT);
|
|
730
943
|
var valuesArray = new arrayType(valuesArrayBuffer, valuesByteOffset, valuesByteLength / arrayType.BYTES_PER_ELEMENT);
|
|
731
944
|
for(var i1 = 0; i1 < count; i1++){
|
|
@@ -737,41 +950,49 @@ var TextureWrapMode;
|
|
|
737
950
|
}
|
|
738
951
|
return typedArray;
|
|
739
952
|
};
|
|
740
|
-
|
|
741
|
-
var
|
|
742
|
-
var arrayBuffer = buffers[buffer];
|
|
743
|
-
return arrayBuffer.slice(byteOffset, byteOffset + byteLength);
|
|
953
|
+
GLTFUtils.getBufferViewData = function getBufferViewData(bufferView, buffers) {
|
|
954
|
+
var _bufferView_byteOffset = bufferView.byteOffset, byteOffset = _bufferView_byteOffset === void 0 ? 0 : _bufferView_byteOffset;
|
|
955
|
+
var arrayBuffer = buffers[bufferView.buffer];
|
|
956
|
+
return arrayBuffer.slice(byteOffset, byteOffset + bufferView.byteLength);
|
|
744
957
|
};
|
|
745
958
|
/**
|
|
746
959
|
* Get accessor data.
|
|
747
|
-
*/
|
|
748
|
-
var
|
|
749
|
-
var accessorTypeSize =
|
|
750
|
-
var TypedArray =
|
|
751
|
-
var data =
|
|
960
|
+
*/ GLTFUtils.processingSparseData = function processingSparseData(bufferViews, accessor, buffers, bufferInfo) {
|
|
961
|
+
var restoreInfo = bufferInfo.restoreInfo;
|
|
962
|
+
var accessorTypeSize = GLTFUtils.getAccessorTypeSize(accessor.type);
|
|
963
|
+
var TypedArray = GLTFUtils.getComponentType(accessor.componentType);
|
|
964
|
+
var data = bufferInfo.data.slice();
|
|
752
965
|
var _accessor_sparse = accessor.sparse, count = _accessor_sparse.count, indices = _accessor_sparse.indices, values = _accessor_sparse.values;
|
|
753
966
|
var indicesBufferView = bufferViews[indices.bufferView];
|
|
754
967
|
var valuesBufferView = bufferViews[values.bufferView];
|
|
755
|
-
var
|
|
756
|
-
var
|
|
968
|
+
var indicesBufferIndex = indicesBufferView.buffer;
|
|
969
|
+
var valuesBufferIndex = valuesBufferView.buffer;
|
|
970
|
+
var indicesArrayBuffer = buffers[indicesBufferIndex];
|
|
971
|
+
var valuesArrayBuffer = buffers[valuesBufferIndex];
|
|
757
972
|
var _indices_byteOffset, _indicesBufferView_byteOffset;
|
|
758
973
|
var indicesByteOffset = ((_indices_byteOffset = indices.byteOffset) != null ? _indices_byteOffset : 0) + ((_indicesBufferView_byteOffset = indicesBufferView.byteOffset) != null ? _indicesBufferView_byteOffset : 0);
|
|
759
974
|
var indicesByteLength = indicesBufferView.byteLength;
|
|
760
975
|
var _values_byteOffset, _valuesBufferView_byteOffset;
|
|
761
976
|
var valuesByteOffset = ((_values_byteOffset = values.byteOffset) != null ? _values_byteOffset : 0) + ((_valuesBufferView_byteOffset = valuesBufferView.byteOffset) != null ? _valuesBufferView_byteOffset : 0);
|
|
762
977
|
var valuesByteLength = valuesBufferView.byteLength;
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
var
|
|
978
|
+
restoreInfo.typeSize = accessorTypeSize;
|
|
979
|
+
restoreInfo.sparseCount = count;
|
|
980
|
+
var IndexTypeArray = GLTFUtils.getComponentType(indices.componentType);
|
|
981
|
+
var indexLength = indicesByteLength / IndexTypeArray.BYTES_PER_ELEMENT;
|
|
982
|
+
var indicesArray = new IndexTypeArray(indicesArrayBuffer, indicesByteOffset, indexLength);
|
|
983
|
+
restoreInfo.sparseIndices = new RestoreDataAccessor(indicesBufferIndex, IndexTypeArray, indicesByteOffset, indexLength);
|
|
984
|
+
var valueLength = valuesByteLength / TypedArray.BYTES_PER_ELEMENT;
|
|
985
|
+
var valuesArray = new TypedArray(valuesArrayBuffer, valuesByteOffset, valueLength);
|
|
986
|
+
restoreInfo.sparseValues = new RestoreDataAccessor(valuesBufferIndex, TypedArray, valuesByteOffset, valueLength);
|
|
766
987
|
for(var i = 0; i < count; i++){
|
|
767
988
|
var replaceIndex = indicesArray[i];
|
|
768
989
|
for(var j = 0; j < accessorTypeSize; j++){
|
|
769
990
|
data[replaceIndex * accessorTypeSize + j] = valuesArray[i * accessorTypeSize + j];
|
|
770
991
|
}
|
|
771
992
|
}
|
|
772
|
-
|
|
993
|
+
bufferInfo.data = data;
|
|
773
994
|
};
|
|
774
|
-
|
|
995
|
+
GLTFUtils.getIndexFormat = function getIndexFormat(type) {
|
|
775
996
|
switch(type){
|
|
776
997
|
case AccessorComponentType.UNSIGNED_BYTE:
|
|
777
998
|
return miniprogram.IndexFormat.UInt8;
|
|
@@ -781,7 +1002,7 @@ var TextureWrapMode;
|
|
|
781
1002
|
return miniprogram.IndexFormat.UInt32;
|
|
782
1003
|
}
|
|
783
1004
|
};
|
|
784
|
-
|
|
1005
|
+
GLTFUtils.getElementFormat = function getElementFormat(type, size, normalized) {
|
|
785
1006
|
if (normalized === void 0) normalized = false;
|
|
786
1007
|
if (type == AccessorComponentType.FLOAT) {
|
|
787
1008
|
switch(size){
|
|
@@ -832,7 +1053,7 @@ var TextureWrapMode;
|
|
|
832
1053
|
};
|
|
833
1054
|
/**
|
|
834
1055
|
* Load image buffer
|
|
835
|
-
*/
|
|
1056
|
+
*/ GLTFUtils.loadImageBuffer = function loadImageBuffer(imageBuffer, type) {
|
|
836
1057
|
return new Promise(function(resolve, reject) {
|
|
837
1058
|
var blob = new engineMiniprogramAdapter.window.Blob([
|
|
838
1059
|
imageBuffer
|
|
@@ -856,18 +1077,9 @@ var TextureWrapMode;
|
|
|
856
1077
|
img.src = engineMiniprogramAdapter.URL.createObjectURL(blob);
|
|
857
1078
|
});
|
|
858
1079
|
};
|
|
859
|
-
GLTFUtil.isAbsoluteUrl = function isAbsoluteUrl(url) {
|
|
860
|
-
return /^(?:http|blob|data:|\/)/.test(url);
|
|
861
|
-
};
|
|
862
|
-
GLTFUtil.parseRelativeUrl = function parseRelativeUrl(baseUrl, relativeUrl) {
|
|
863
|
-
if (GLTFUtil.isAbsoluteUrl(relativeUrl)) {
|
|
864
|
-
return relativeUrl;
|
|
865
|
-
}
|
|
866
|
-
return baseUrl.substring(0, baseUrl.lastIndexOf("/") + 1) + GLTFUtil._formatRelativePath(relativeUrl);
|
|
867
|
-
};
|
|
868
1080
|
/**
|
|
869
1081
|
* Parse the glb format.
|
|
870
|
-
*/
|
|
1082
|
+
*/ GLTFUtils.parseGLB = function parseGLB(context, glb) {
|
|
871
1083
|
var UINT32_LENGTH = 4;
|
|
872
1084
|
var GLB_HEADER_MAGIC = 0x46546c67; // 'glTF'
|
|
873
1085
|
var GLB_HEADER_LENGTH = 12;
|
|
@@ -895,10 +1107,11 @@ var TextureWrapMode;
|
|
|
895
1107
|
return null;
|
|
896
1108
|
}
|
|
897
1109
|
var glTFData = new Uint8Array(glb, GLB_HEADER_LENGTH + 2 * UINT32_LENGTH, chunkLength);
|
|
898
|
-
var
|
|
1110
|
+
var glTF = JSON.parse(miniprogram.Utils.decodeText(glTFData));
|
|
899
1111
|
// read all buffers
|
|
900
1112
|
var buffers = [];
|
|
901
1113
|
var byteOffset = GLB_HEADER_LENGTH + 2 * UINT32_LENGTH + chunkLength;
|
|
1114
|
+
var restoreGLBBufferSlice = context.contentRestorer.glbBufferSlices;
|
|
902
1115
|
while(byteOffset < header.length){
|
|
903
1116
|
chunkLength = dataView.getUint32(byteOffset, true);
|
|
904
1117
|
chunkType = dataView.getUint32(byteOffset + UINT32_LENGTH, true);
|
|
@@ -909,14 +1122,15 @@ var TextureWrapMode;
|
|
|
909
1122
|
var currentOffset = byteOffset + 2 * UINT32_LENGTH;
|
|
910
1123
|
var buffer = glb.slice(currentOffset, currentOffset + chunkLength);
|
|
911
1124
|
buffers.push(buffer);
|
|
1125
|
+
restoreGLBBufferSlice.push(new miniprogram$1.Vector2(currentOffset, chunkLength));
|
|
912
1126
|
byteOffset += chunkLength + 2 * UINT32_LENGTH;
|
|
913
1127
|
}
|
|
914
1128
|
return {
|
|
915
|
-
|
|
1129
|
+
glTF: glTF,
|
|
916
1130
|
buffers: buffers
|
|
917
1131
|
};
|
|
918
1132
|
};
|
|
919
|
-
|
|
1133
|
+
GLTFUtils._formatRelativePath = function _formatRelativePath(path) {
|
|
920
1134
|
// For example input is "a/b", "/a/b", "./a/b", "./a/./b", "./a/../a/b", output is "a/b"
|
|
921
1135
|
return path.split("/").filter(Boolean).reduce(function(acc, cur) {
|
|
922
1136
|
if (cur === "..") acc.pop();
|
|
@@ -924,17 +1138,9 @@ var TextureWrapMode;
|
|
|
924
1138
|
return acc;
|
|
925
1139
|
}, []).join("/");
|
|
926
1140
|
};
|
|
927
|
-
return
|
|
1141
|
+
return GLTFUtils;
|
|
928
1142
|
}();
|
|
929
1143
|
|
|
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;
|
|
936
|
-
}
|
|
937
|
-
|
|
938
1144
|
function _array_without_holes(arr) {
|
|
939
1145
|
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
940
1146
|
}
|
|
@@ -949,527 +1155,260 @@ function _non_iterable_spread() {
|
|
|
949
1155
|
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
950
1156
|
}
|
|
951
1157
|
|
|
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
1158
|
function _to_consumable_array(arr) {
|
|
964
1159
|
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
965
1160
|
}
|
|
966
1161
|
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
1162
|
+
/**
|
|
1163
|
+
* Base class of glTF extension parser.
|
|
1164
|
+
*/ var GLTFExtensionParser = /*#__PURE__*/ function() {
|
|
1165
|
+
function GLTFExtensionParser() {}
|
|
1166
|
+
var _proto = GLTFExtensionParser.prototype;
|
|
1167
|
+
/**
|
|
1168
|
+
* Initialize the parser.
|
|
1169
|
+
* @remarks Some plugins require initialization.
|
|
1170
|
+
* @returns The void or promise
|
|
1171
|
+
*/ _proto.initialize = function initialize() {};
|
|
1172
|
+
/**
|
|
1173
|
+
* Create and parse the resource.
|
|
1174
|
+
* @remarks This method overrides the default resource creation.
|
|
1175
|
+
* @param context - The parser context
|
|
1176
|
+
* @param extensionSchema - The extension schema
|
|
1177
|
+
* @param extensionOwnerSchema - The extension owner schema
|
|
1178
|
+
* @returns The resource or promise
|
|
1179
|
+
*/ _proto.createAndParse = function createAndParse(context, extensionSchema, extensionOwnerSchema) {
|
|
1180
|
+
for(var _len = arguments.length, extra = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++){
|
|
1181
|
+
extra[_key - 3] = arguments[_key];
|
|
1182
|
+
}
|
|
1183
|
+
throw "Not implemented.";
|
|
1184
|
+
};
|
|
1185
|
+
/**
|
|
1186
|
+
* Additive parse to the resource.
|
|
1187
|
+
* @param context - The parser context
|
|
1188
|
+
* @param parseResource - The parsed resource
|
|
1189
|
+
* @param extensionSchema - The extension schema
|
|
1190
|
+
* @param extensionOwnerSchema - The extension owner schema
|
|
1191
|
+
* @returns The void or promise
|
|
1192
|
+
*/ _proto.additiveParse = function additiveParse(context, parseResource, extensionSchema, extensionOwnerSchema) {
|
|
970
1193
|
for(var _len = arguments.length, extra = new Array(_len > 4 ? _len - 4 : 0), _key = 4; _key < _len; _key++){
|
|
971
1194
|
extra[_key - 4] = arguments[_key];
|
|
972
1195
|
}
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
1196
|
+
throw "Not implemented.";
|
|
1197
|
+
};
|
|
1198
|
+
return GLTFExtensionParser;
|
|
1199
|
+
}();
|
|
1200
|
+
exports.GLTFExtensionMode = void 0;
|
|
1201
|
+
(function(GLTFExtensionMode) {
|
|
1202
|
+
GLTFExtensionMode[GLTFExtensionMode[/**
|
|
1203
|
+
* Cerate instance and parse mode.
|
|
1204
|
+
* @remarks
|
|
1205
|
+
* If the glTF property has multiple extensions of `CreateAndParse` mode, only execute the last one.
|
|
1206
|
+
* If this method is registered, the default pipeline processing will be ignored.
|
|
1207
|
+
*/ "CreateAndParse"] = 0] = "CreateAndParse";
|
|
1208
|
+
GLTFExtensionMode[GLTFExtensionMode[/** Additive parse mode. */ "AdditiveParse"] = 1] = "AdditiveParse";
|
|
1209
|
+
})(exports.GLTFExtensionMode || (exports.GLTFExtensionMode = {}));
|
|
1210
|
+
|
|
1211
|
+
/**
|
|
1212
|
+
* Base class of glTF parser.
|
|
1213
|
+
*/ var GLTFParser = /*#__PURE__*/ function() {
|
|
1214
|
+
function GLTFParser() {}
|
|
1215
|
+
/**
|
|
1216
|
+
* Execute all parses of extension to initialize plugin.
|
|
1217
|
+
* @remarks Some plugins require initialization.
|
|
1218
|
+
* @returns The void or promise
|
|
1219
|
+
*/ GLTFParser.executeExtensionsInitialize = function executeExtensionsInitialize(extensionName) {
|
|
1220
|
+
var parsers = GLTFParser._extensionParsers[extensionName];
|
|
1221
|
+
var length = parsers == null ? void 0 : parsers.length;
|
|
1222
|
+
if (length) {
|
|
1223
|
+
return parsers[length - 1].initialize();
|
|
983
1224
|
}
|
|
984
1225
|
};
|
|
985
|
-
|
|
1226
|
+
/**
|
|
1227
|
+
* Execute all parses of extension to create resource.
|
|
1228
|
+
* @param extensions - Related extensions field
|
|
1229
|
+
* @param context - The parser context
|
|
1230
|
+
* @param ownerSchema - The extension owner schema
|
|
1231
|
+
* @param extra - Extra params
|
|
1232
|
+
* @returns
|
|
1233
|
+
*/ GLTFParser.executeExtensionsCreateAndParse = function executeExtensionsCreateAndParse(extensions, context, ownerSchema) {
|
|
1234
|
+
if (extensions === void 0) extensions = {};
|
|
986
1235
|
for(var _len = arguments.length, extra = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++){
|
|
987
1236
|
extra[_key - 3] = arguments[_key];
|
|
988
1237
|
}
|
|
989
|
-
var
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
1238
|
+
var resource = null;
|
|
1239
|
+
var extensionArray = Object.keys(extensions);
|
|
1240
|
+
for(var i = extensionArray.length - 1; i >= 0; --i){
|
|
1241
|
+
var _GLTFParser;
|
|
1242
|
+
var extensionName = extensionArray[i];
|
|
1243
|
+
var extensionSchema = extensions[extensionName];
|
|
1244
|
+
resource = (_GLTFParser = GLTFParser)._createAndParse.apply(_GLTFParser, [
|
|
1245
|
+
extensionName,
|
|
1246
|
+
context,
|
|
1247
|
+
extensionSchema,
|
|
1248
|
+
ownerSchema
|
|
1249
|
+
].concat(_to_consumable_array(extra)));
|
|
1250
|
+
if (resource) {
|
|
1251
|
+
return resource;
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1254
|
+
};
|
|
1255
|
+
/**
|
|
1256
|
+
* Execute all parses of extension to parse resource.
|
|
1257
|
+
* @param extensions - Related extensions field
|
|
1258
|
+
* @param context - The parser context
|
|
1259
|
+
* @param parseResource - The parsed resource
|
|
1260
|
+
* @param ownerSchema - The extension owner schema
|
|
1261
|
+
* @param extra - Extra params
|
|
1262
|
+
*/ GLTFParser.executeExtensionsAdditiveAndParse = function executeExtensionsAdditiveAndParse(extensions, context, parseResource, ownerSchema) {
|
|
1263
|
+
for(var _len = arguments.length, extra = new Array(_len > 4 ? _len - 4 : 0), _key = 4; _key < _len; _key++){
|
|
1264
|
+
extra[_key - 4] = arguments[_key];
|
|
1265
|
+
}
|
|
1266
|
+
for(var extensionName in extensions){
|
|
1267
|
+
var _GLTFParser;
|
|
1268
|
+
var extensionSchema = extensions[extensionName];
|
|
1269
|
+
(_GLTFParser = GLTFParser)._additiveParse.apply(_GLTFParser, [
|
|
1270
|
+
extensionName,
|
|
1271
|
+
context,
|
|
1272
|
+
parseResource,
|
|
993
1273
|
extensionSchema,
|
|
994
|
-
|
|
1274
|
+
ownerSchema
|
|
995
1275
|
].concat(_to_consumable_array(extra)));
|
|
996
1276
|
}
|
|
997
1277
|
};
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1278
|
+
/**
|
|
1279
|
+
* Whether the plugin is registered.
|
|
1280
|
+
* @param extensionName - Extension name
|
|
1281
|
+
* @returns Boolean
|
|
1282
|
+
*/ GLTFParser.hasExtensionParser = function hasExtensionParser(extensionName) {
|
|
1283
|
+
var _GLTFParser__extensionParsers_extensionName;
|
|
1284
|
+
return !!((_GLTFParser__extensionParsers_extensionName = GLTFParser._extensionParsers[extensionName]) == null ? void 0 : _GLTFParser__extensionParsers_extensionName.length);
|
|
1001
1285
|
};
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1286
|
+
/**
|
|
1287
|
+
* Get the last plugin by glTF extension mode.
|
|
1288
|
+
* @param extensionName - Extension name
|
|
1289
|
+
* @param mode - GLTF extension mode
|
|
1290
|
+
* @returns GLTF extension parser
|
|
1291
|
+
*/ GLTFParser.getExtensionParser = function getExtensionParser(extensionName, mode) {
|
|
1292
|
+
var parsers = GLTFParser._extensionParsers[extensionName];
|
|
1293
|
+
var length = parsers == null ? void 0 : parsers.length;
|
|
1294
|
+
if (length) {
|
|
1295
|
+
// only use the last parser.
|
|
1296
|
+
for(var i = length - 1; i >= 0; --i){
|
|
1297
|
+
var currentParser = parsers[i];
|
|
1298
|
+
if (currentParser._mode === mode) {
|
|
1299
|
+
return currentParser;
|
|
1300
|
+
}
|
|
1007
1301
|
}
|
|
1008
1302
|
}
|
|
1009
1303
|
};
|
|
1010
1304
|
/**
|
|
1011
1305
|
* @internal
|
|
1012
|
-
*/
|
|
1013
|
-
if (!
|
|
1014
|
-
|
|
1306
|
+
*/ GLTFParser._addExtensionParser = function _addExtensionParser(extensionName, extensionParser) {
|
|
1307
|
+
if (!GLTFParser._extensionParsers[extensionName]) {
|
|
1308
|
+
GLTFParser._extensionParsers[extensionName] = [];
|
|
1309
|
+
}
|
|
1310
|
+
GLTFParser._extensionParsers[extensionName].push(extensionParser);
|
|
1311
|
+
};
|
|
1312
|
+
GLTFParser._createAndParse = function _createAndParse(extensionName, context, extensionSchema, ownerSchema) {
|
|
1313
|
+
for(var _len = arguments.length, extra = new Array(_len > 4 ? _len - 4 : 0), _key = 4; _key < _len; _key++){
|
|
1314
|
+
extra[_key - 4] = arguments[_key];
|
|
1315
|
+
}
|
|
1316
|
+
var parser = GLTFParser.getExtensionParser(extensionName, exports.GLTFExtensionMode.CreateAndParse);
|
|
1317
|
+
if (parser) {
|
|
1318
|
+
var _parser;
|
|
1319
|
+
return (_parser = parser).createAndParse.apply(_parser, [
|
|
1320
|
+
context,
|
|
1321
|
+
extensionSchema,
|
|
1322
|
+
ownerSchema
|
|
1323
|
+
].concat(_to_consumable_array(extra)));
|
|
1324
|
+
}
|
|
1325
|
+
};
|
|
1326
|
+
GLTFParser._additiveParse = function _additiveParse(extensionName, context, parseResource, extensionSchema, ownerSchema) {
|
|
1327
|
+
for(var _len = arguments.length, extra = new Array(_len > 5 ? _len - 5 : 0), _key = 5; _key < _len; _key++){
|
|
1328
|
+
extra[_key - 5] = arguments[_key];
|
|
1329
|
+
}
|
|
1330
|
+
var parser = GLTFParser.getExtensionParser(extensionName, exports.GLTFExtensionMode.AdditiveParse);
|
|
1331
|
+
if (parser) {
|
|
1332
|
+
var _parser;
|
|
1333
|
+
(_parser = parser).additiveParse.apply(_parser, [
|
|
1334
|
+
context,
|
|
1335
|
+
parseResource,
|
|
1336
|
+
extensionSchema,
|
|
1337
|
+
ownerSchema
|
|
1338
|
+
].concat(_to_consumable_array(extra)));
|
|
1015
1339
|
}
|
|
1016
|
-
Parser._extensionParsers[extensionName].push(extensionParser);
|
|
1017
1340
|
};
|
|
1018
|
-
return
|
|
1341
|
+
return GLTFParser;
|
|
1019
1342
|
}();
|
|
1020
1343
|
(function() {
|
|
1021
|
-
|
|
1344
|
+
GLTFParser._extensionParsers = {};
|
|
1022
1345
|
})();
|
|
1023
1346
|
/**
|
|
1024
1347
|
* Declare ExtensionParser's decorator.
|
|
1025
1348
|
* @param extensionName - Extension name
|
|
1026
|
-
*/ function
|
|
1349
|
+
*/ function registerGLTFExtension(extensionName, mode) {
|
|
1027
1350
|
return function(parser) {
|
|
1028
1351
|
var extensionParser = new parser();
|
|
1029
|
-
|
|
1352
|
+
extensionParser._mode = mode;
|
|
1353
|
+
GLTFParser._addExtensionParser(extensionName, extensionParser);
|
|
1030
1354
|
};
|
|
1031
1355
|
}
|
|
1032
1356
|
|
|
1033
|
-
var
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1357
|
+
var GLTFAnimationParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
1358
|
+
_inherits(GLTFAnimationParser, GLTFParser1);
|
|
1359
|
+
function GLTFAnimationParser() {
|
|
1360
|
+
return GLTFParser1.apply(this, arguments);
|
|
1361
|
+
}
|
|
1362
|
+
var _proto = GLTFAnimationParser.prototype;
|
|
1363
|
+
_proto.parse = function parse(context) {
|
|
1364
|
+
var glTF = context.glTF, glTFResource = context.glTFResource;
|
|
1365
|
+
glTFResource.entities;
|
|
1366
|
+
var animations = glTF.animations; glTF.accessors; glTF.bufferViews;
|
|
1367
|
+
if (!animations) {
|
|
1368
|
+
return;
|
|
1040
1369
|
}
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1370
|
+
var animationClipsPromiseInfo = context.animationClipsPromiseInfo;
|
|
1371
|
+
var animationClipCount = animations.length;
|
|
1372
|
+
var animationClipPromises = [];
|
|
1373
|
+
new Array(animationClipCount);
|
|
1374
|
+
var parseStandardPropertyPromises = new Array();
|
|
1375
|
+
for(var i = 0; i < animationClipCount; i++){
|
|
1376
|
+
var animationInfo = animations[i];
|
|
1377
|
+
var _animationInfo_name = animationInfo.name, name = _animationInfo_name === void 0 ? "AnimationClip" + i : _animationInfo_name;
|
|
1378
|
+
var animationClip = GLTFParser.executeExtensionsCreateAndParse(animationInfo.extensions, context, animationInfo);
|
|
1379
|
+
if (!animationClip) {
|
|
1380
|
+
animationClip = new miniprogram.AnimationClip(name);
|
|
1381
|
+
parseStandardPropertyPromises.push(GLTFAnimationParser._parseStandardProperty(context, animationClip, animationInfo));
|
|
1382
|
+
}
|
|
1383
|
+
animationClipPromises.push(animationClip);
|
|
1045
1384
|
}
|
|
1046
|
-
return
|
|
1385
|
+
return miniprogram.AssetPromise.all(parseStandardPropertyPromises).then(function() {
|
|
1386
|
+
return miniprogram.AssetPromise.all(animationClipPromises).then(function(animationClips) {
|
|
1387
|
+
glTFResource.animations = animationClips;
|
|
1388
|
+
for(var i = 0; i < glTF.animations.length; i++){
|
|
1389
|
+
var animationInfo = glTF.animations[i];
|
|
1390
|
+
GLTFParser.executeExtensionsAdditiveAndParse(animationInfo.extensions, context, animationClips[i], animationInfo);
|
|
1391
|
+
}
|
|
1392
|
+
animationClipsPromiseInfo.resolve(animationClips);
|
|
1393
|
+
return animationClipsPromiseInfo.promise;
|
|
1394
|
+
});
|
|
1395
|
+
});
|
|
1047
1396
|
};
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
var
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
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;
|
|
1075
|
-
}
|
|
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
|
-
});
|
|
1089
|
-
};
|
|
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;
|
|
1397
|
+
/**
|
|
1398
|
+
* @internal
|
|
1399
|
+
*/ GLTFAnimationParser._parseStandardProperty = function _parseStandardProperty(context, animationClip, animationInfo) {
|
|
1400
|
+
var _loop = function(j, m) {
|
|
1401
|
+
var gltfSampler = samplers[j];
|
|
1402
|
+
var inputAccessor = accessors[gltfSampler.input];
|
|
1403
|
+
var outputAccessor = accessors[gltfSampler.output];
|
|
1404
|
+
var promise = Promise.all([
|
|
1405
|
+
GLTFUtils.getAccessorBuffer(context, bufferViews, inputAccessor),
|
|
1406
|
+
GLTFUtils.getAccessorBuffer(context, bufferViews, outputAccessor)
|
|
1407
|
+
]).then(function(bufferInfos) {
|
|
1408
|
+
var input = bufferInfos[0].data;
|
|
1409
|
+
var output = bufferInfos[1].data;
|
|
1471
1410
|
if (outputAccessor.normalized) {
|
|
1472
|
-
var scale =
|
|
1411
|
+
var scale = GLTFUtils.getNormalizedComponentScale(outputAccessor.componentType);
|
|
1473
1412
|
var scaled = new Float32Array(output.length);
|
|
1474
1413
|
for(var k = 0, v = output.length; k < v; k++){
|
|
1475
1414
|
scaled[k] = output[k] * scale;
|
|
@@ -1479,7 +1418,7 @@ var AnimationParser = /*#__PURE__*/ function(Parser) {
|
|
|
1479
1418
|
var outputStride = output.length / input.length;
|
|
1480
1419
|
var _gltfSampler_interpolation;
|
|
1481
1420
|
var interpolation = (_gltfSampler_interpolation = gltfSampler.interpolation) != null ? _gltfSampler_interpolation : AnimationSamplerInterpolation.Linear;
|
|
1482
|
-
var samplerInterpolation
|
|
1421
|
+
var samplerInterpolation;
|
|
1483
1422
|
switch(interpolation){
|
|
1484
1423
|
case AnimationSamplerInterpolation.CubicSpine:
|
|
1485
1424
|
samplerInterpolation = miniprogram.InterpolationType.CubicSpine;
|
|
@@ -1499,9 +1438,21 @@ var AnimationParser = /*#__PURE__*/ function(Parser) {
|
|
|
1499
1438
|
output: output,
|
|
1500
1439
|
outputSize: outputStride
|
|
1501
1440
|
});
|
|
1502
|
-
}
|
|
1503
|
-
|
|
1504
|
-
|
|
1441
|
+
});
|
|
1442
|
+
promises.push(promise);
|
|
1443
|
+
};
|
|
1444
|
+
var _this = this;
|
|
1445
|
+
var glTF = context.glTF, glTFResource = context.glTFResource;
|
|
1446
|
+
var entities = glTFResource.entities;
|
|
1447
|
+
var accessors = glTF.accessors, bufferViews = glTF.bufferViews;
|
|
1448
|
+
var channels = animationInfo.channels, samplers = animationInfo.samplers;
|
|
1449
|
+
var sampleDataCollection = new Array();
|
|
1450
|
+
var promises = new Array();
|
|
1451
|
+
// parse samplers
|
|
1452
|
+
for(var j = 0, m = samplers.length; j < m; j++)_loop(j);
|
|
1453
|
+
return Promise.all(promises).then(function() {
|
|
1454
|
+
for(var j = 0, m = channels.length; j < m; j++){
|
|
1455
|
+
var gltfChannel = channels[j];
|
|
1505
1456
|
var target = gltfChannel.target;
|
|
1506
1457
|
var channelTargetEntity = entities[target.node];
|
|
1507
1458
|
var relativePath = "";
|
|
@@ -1530,25 +1481,15 @@ var AnimationParser = /*#__PURE__*/ function(Parser) {
|
|
|
1530
1481
|
propertyName = "blendShapeWeights";
|
|
1531
1482
|
break;
|
|
1532
1483
|
}
|
|
1533
|
-
var curve =
|
|
1484
|
+
var curve = _this._addCurve(target.path, gltfChannel, sampleDataCollection);
|
|
1534
1485
|
animationClip.addCurveBinding(relativePath, ComponentType, propertyName, curve);
|
|
1535
1486
|
}
|
|
1536
|
-
|
|
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;
|
|
1487
|
+
});
|
|
1547
1488
|
};
|
|
1548
|
-
|
|
1489
|
+
GLTFAnimationParser._addCurve = function _addCurve(animationChannelTargetPath, gltfChannel, sampleDataCollection) {
|
|
1549
1490
|
var sampleData = sampleDataCollection[gltfChannel.sampler];
|
|
1550
1491
|
var input = sampleData.input, output = sampleData.output, outputSize = sampleData.outputSize;
|
|
1551
|
-
switch(
|
|
1492
|
+
switch(animationChannelTargetPath){
|
|
1552
1493
|
case AnimationChannelTargetPath.TRANSLATION:
|
|
1553
1494
|
case AnimationChannelTargetPath.SCALE:
|
|
1554
1495
|
{
|
|
@@ -1613,38 +1554,43 @@ var AnimationParser = /*#__PURE__*/ function(Parser) {
|
|
|
1613
1554
|
}
|
|
1614
1555
|
}
|
|
1615
1556
|
};
|
|
1616
|
-
return
|
|
1617
|
-
}(
|
|
1557
|
+
return GLTFAnimationParser;
|
|
1558
|
+
}(GLTFParser);
|
|
1618
1559
|
|
|
1619
|
-
var
|
|
1620
|
-
_inherits(
|
|
1621
|
-
function
|
|
1622
|
-
return
|
|
1560
|
+
var GLTFBufferParser = /*#__PURE__*/ function(GLTFParser) {
|
|
1561
|
+
_inherits(GLTFBufferParser, GLTFParser);
|
|
1562
|
+
function GLTFBufferParser() {
|
|
1563
|
+
return GLTFParser.apply(this, arguments);
|
|
1623
1564
|
}
|
|
1624
|
-
var _proto =
|
|
1565
|
+
var _proto = GLTFBufferParser.prototype;
|
|
1625
1566
|
_proto.parse = function parse(context) {
|
|
1626
|
-
var glTFResource = context.glTFResource;
|
|
1567
|
+
var glTFResource = context.glTFResource, contentRestorer = context.contentRestorer;
|
|
1627
1568
|
var url = glTFResource.url;
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1569
|
+
var restoreBufferRequests = contentRestorer.bufferRequests;
|
|
1570
|
+
var requestConfig = {
|
|
1571
|
+
type: "arraybuffer"
|
|
1572
|
+
};
|
|
1573
|
+
var isGLB = this._isGLB(url);
|
|
1574
|
+
contentRestorer.isGLB = isGLB;
|
|
1575
|
+
if (isGLB) {
|
|
1576
|
+
return miniprogram.request(url, requestConfig).then(function(glb) {
|
|
1577
|
+
restoreBufferRequests.push(new BufferRequestInfo(url, requestConfig));
|
|
1578
|
+
return GLTFUtils.parseGLB(context, glb);
|
|
1579
|
+
}).then(function(param) {
|
|
1580
|
+
var glTF = param.glTF, buffers = param.buffers;
|
|
1581
|
+
context.glTF = glTF;
|
|
1582
|
+
context._buffers = buffers;
|
|
1635
1583
|
});
|
|
1636
1584
|
} else {
|
|
1637
1585
|
return miniprogram.request(url, {
|
|
1638
1586
|
type: "json"
|
|
1639
|
-
}).then(function(
|
|
1640
|
-
context.
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
}))
|
|
1646
|
-
context.buffers = buffers;
|
|
1647
|
-
});
|
|
1587
|
+
}).then(function(glTF) {
|
|
1588
|
+
context.glTF = glTF;
|
|
1589
|
+
context._buffers = Promise.all(glTF.buffers.map(function(buffer) {
|
|
1590
|
+
var absoluteUrl = miniprogram.Utils.resolveAbsoluteUrl(url, buffer.uri);
|
|
1591
|
+
restoreBufferRequests.push(new BufferRequestInfo(absoluteUrl, requestConfig));
|
|
1592
|
+
return miniprogram.request(absoluteUrl, requestConfig);
|
|
1593
|
+
}));
|
|
1648
1594
|
});
|
|
1649
1595
|
}
|
|
1650
1596
|
};
|
|
@@ -1652,24 +1598,24 @@ var BufferParser = /*#__PURE__*/ function(Parser) {
|
|
|
1652
1598
|
var index = url.lastIndexOf(".");
|
|
1653
1599
|
return url.substring(index + 1, index + 4) === "glb";
|
|
1654
1600
|
};
|
|
1655
|
-
return
|
|
1656
|
-
}(
|
|
1601
|
+
return GLTFBufferParser;
|
|
1602
|
+
}(GLTFParser);
|
|
1657
1603
|
|
|
1658
|
-
var
|
|
1659
|
-
_inherits(
|
|
1660
|
-
function
|
|
1661
|
-
return
|
|
1604
|
+
var GLTFEntityParser = /*#__PURE__*/ function(GLTFParser) {
|
|
1605
|
+
_inherits(GLTFEntityParser, GLTFParser);
|
|
1606
|
+
function GLTFEntityParser() {
|
|
1607
|
+
return GLTFParser.apply(this, arguments);
|
|
1662
1608
|
}
|
|
1663
|
-
var _proto =
|
|
1609
|
+
var _proto = GLTFEntityParser.prototype;
|
|
1664
1610
|
_proto.parse = function parse(context) {
|
|
1665
|
-
var glTFResource = context.glTFResource, nodes = context.
|
|
1611
|
+
var glTFResource = context.glTFResource, nodes = context.glTF.nodes;
|
|
1666
1612
|
var engine = glTFResource.engine;
|
|
1667
1613
|
if (!nodes) return;
|
|
1668
1614
|
var entities = [];
|
|
1669
1615
|
for(var i = 0; i < nodes.length; i++){
|
|
1670
1616
|
var gltfNode = nodes[i];
|
|
1671
1617
|
var matrix = gltfNode.matrix, translation = gltfNode.translation, rotation = gltfNode.rotation, scale = gltfNode.scale;
|
|
1672
|
-
var entity = new miniprogram.Entity(engine, gltfNode.name || "" +
|
|
1618
|
+
var entity = new miniprogram.Entity(engine, gltfNode.name || "" + GLTFEntityParser._defaultName + i);
|
|
1673
1619
|
var transform = entity.transform;
|
|
1674
1620
|
if (matrix) {
|
|
1675
1621
|
var localMatrix = transform.localMatrix;
|
|
@@ -1693,7 +1639,7 @@ var EntityParser = /*#__PURE__*/ function(Parser) {
|
|
|
1693
1639
|
this._createSceneRoots(context, glTFResource);
|
|
1694
1640
|
};
|
|
1695
1641
|
_proto._buildEntityTree = function _buildEntityTree(context, glTFResource) {
|
|
1696
|
-
var nodes = context.
|
|
1642
|
+
var nodes = context.glTF.nodes;
|
|
1697
1643
|
var entities = glTFResource.entities;
|
|
1698
1644
|
for(var i = 0; i < nodes.length; i++){
|
|
1699
1645
|
var children = nodes[i].children;
|
|
@@ -1707,7 +1653,7 @@ var EntityParser = /*#__PURE__*/ function(Parser) {
|
|
|
1707
1653
|
}
|
|
1708
1654
|
};
|
|
1709
1655
|
_proto._createSceneRoots = function _createSceneRoots(context, glTFResource) {
|
|
1710
|
-
var
|
|
1656
|
+
var _context_glTF = context.glTF, tmp = _context_glTF.scene, sceneID = tmp === void 0 ? 0 : tmp, scenes = _context_glTF.scenes;
|
|
1711
1657
|
var engine = glTFResource.engine, entities = glTFResource.entities;
|
|
1712
1658
|
if (!scenes) return;
|
|
1713
1659
|
var sceneRoots = [];
|
|
@@ -1723,337 +1669,433 @@ var EntityParser = /*#__PURE__*/ function(Parser) {
|
|
|
1723
1669
|
}
|
|
1724
1670
|
sceneRoots[i] = rootEntity;
|
|
1725
1671
|
}
|
|
1672
|
+
// @ts-ignore
|
|
1673
|
+
sceneRoots[i]._hookResource = glTFResource;
|
|
1674
|
+
// @ts-ignore
|
|
1675
|
+
glTFResource._addReferCount(1);
|
|
1726
1676
|
}
|
|
1727
1677
|
glTFResource.sceneRoots = sceneRoots;
|
|
1728
1678
|
glTFResource.defaultSceneRoot = sceneRoots[sceneID];
|
|
1729
1679
|
};
|
|
1730
|
-
return
|
|
1731
|
-
}(
|
|
1680
|
+
return GLTFEntityParser;
|
|
1681
|
+
}(GLTFParser);
|
|
1732
1682
|
(function() {
|
|
1733
|
-
/** @internal */
|
|
1683
|
+
/** @internal */ GLTFEntityParser._defaultName = "_GLTF_ENTITY_";
|
|
1734
1684
|
})();
|
|
1735
1685
|
|
|
1736
|
-
var
|
|
1737
|
-
_inherits(
|
|
1738
|
-
function
|
|
1739
|
-
return
|
|
1686
|
+
var GLTFMaterialParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
1687
|
+
_inherits(GLTFMaterialParser, GLTFParser1);
|
|
1688
|
+
function GLTFMaterialParser() {
|
|
1689
|
+
return GLTFParser1.apply(this, arguments);
|
|
1740
1690
|
}
|
|
1741
|
-
var _proto =
|
|
1691
|
+
var _proto = GLTFMaterialParser.prototype;
|
|
1742
1692
|
_proto.parse = function parse(context) {
|
|
1743
|
-
var
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1693
|
+
var glTF = context.glTF, glTFResource = context.glTFResource, materialsPromiseInfo = context.materialsPromiseInfo;
|
|
1694
|
+
if (!glTF.materials) return;
|
|
1695
|
+
var engine = glTFResource.engine;
|
|
1696
|
+
var materialPromises = [];
|
|
1697
|
+
for(var i = 0; i < glTF.materials.length; i++){
|
|
1698
|
+
var materialInfo = glTF.materials[i];
|
|
1699
|
+
var material = GLTFParser.executeExtensionsCreateAndParse(materialInfo.extensions, context, materialInfo);
|
|
1700
|
+
if (!material) {
|
|
1701
|
+
material = new miniprogram.PBRMaterial(engine);
|
|
1702
|
+
material.name = materialInfo.name;
|
|
1703
|
+
GLTFMaterialParser._parseStandardProperty(context, material, materialInfo);
|
|
1704
|
+
}
|
|
1705
|
+
materialPromises.push(material);
|
|
1706
|
+
}
|
|
1707
|
+
return miniprogram.AssetPromise.all(materialPromises).then(function(materials) {
|
|
1708
|
+
glTFResource.materials = materials;
|
|
1709
|
+
for(var i = 0; i < glTF.materials.length; i++){
|
|
1710
|
+
var materialInfo = glTF.materials[i];
|
|
1711
|
+
GLTFParser.executeExtensionsAdditiveAndParse(materialInfo.extensions, context, materials[i], materialInfo);
|
|
1712
|
+
}
|
|
1713
|
+
materialsPromiseInfo.resolve(materials);
|
|
1714
|
+
return materialsPromiseInfo.promise;
|
|
1715
|
+
});
|
|
1716
|
+
};
|
|
1717
|
+
/**
|
|
1718
|
+
* @internal
|
|
1719
|
+
*/ GLTFMaterialParser._checkOtherTextureTransform = function _checkOtherTextureTransform(texture, textureName) {
|
|
1720
|
+
var _texture_extensions;
|
|
1721
|
+
if ((_texture_extensions = texture.extensions) == null ? void 0 : _texture_extensions.KHR_texture_transform) {
|
|
1722
|
+
miniprogram.Logger.warn("" + textureName + " texture always use the KHR_texture_transform of the base texture.");
|
|
1723
|
+
}
|
|
1724
|
+
};
|
|
1725
|
+
/**
|
|
1726
|
+
* @internal
|
|
1727
|
+
*/ GLTFMaterialParser._parseStandardProperty = function _parseStandardProperty(context, material, materialInfo) {
|
|
1728
|
+
var textures = context.glTFResource.textures;
|
|
1729
|
+
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;
|
|
1730
|
+
if (pbrMetallicRoughness) {
|
|
1731
|
+
var baseColorFactor = pbrMetallicRoughness.baseColorFactor, baseColorTexture = pbrMetallicRoughness.baseColorTexture, metallicFactor = pbrMetallicRoughness.metallicFactor, roughnessFactor = pbrMetallicRoughness.roughnessFactor, metallicRoughnessTexture = pbrMetallicRoughness.metallicRoughnessTexture;
|
|
1732
|
+
if (baseColorFactor) {
|
|
1733
|
+
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]);
|
|
1734
|
+
}
|
|
1735
|
+
if (baseColorTexture) {
|
|
1736
|
+
material.baseTexture = textures[baseColorTexture.index];
|
|
1737
|
+
GLTFParser.executeExtensionsAdditiveAndParse(baseColorTexture.extensions, context, material, baseColorTexture);
|
|
1738
|
+
}
|
|
1739
|
+
if (material.constructor === miniprogram.PBRMaterial) {
|
|
1740
|
+
material.metallic = metallicFactor != null ? metallicFactor : 1;
|
|
1741
|
+
material.roughness = roughnessFactor != null ? roughnessFactor : 1;
|
|
1742
|
+
if (metallicRoughnessTexture) {
|
|
1743
|
+
material.roughnessMetallicTexture = textures[metallicRoughnessTexture.index];
|
|
1744
|
+
GLTFMaterialParser._checkOtherTextureTransform(metallicRoughnessTexture, "Roughness metallic");
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1747
|
+
}
|
|
1748
|
+
if (material.constructor === miniprogram.PBRMaterial || material.constructor === miniprogram.PBRSpecularMaterial) {
|
|
1749
|
+
if (emissiveTexture) {
|
|
1750
|
+
material.emissiveTexture = textures[emissiveTexture.index];
|
|
1751
|
+
GLTFMaterialParser._checkOtherTextureTransform(emissiveTexture, "Emissive");
|
|
1752
|
+
}
|
|
1753
|
+
if (emissiveFactor) {
|
|
1754
|
+
material.emissiveColor = new miniprogram$1.Color(miniprogram$1.Color.linearToGammaSpace(emissiveFactor[0]), miniprogram$1.Color.linearToGammaSpace(emissiveFactor[1]), miniprogram$1.Color.linearToGammaSpace(emissiveFactor[2]));
|
|
1755
|
+
}
|
|
1756
|
+
if (normalTexture) {
|
|
1757
|
+
var index = normalTexture.index, scale = normalTexture.scale;
|
|
1758
|
+
material.normalTexture = textures[index];
|
|
1759
|
+
GLTFMaterialParser._checkOtherTextureTransform(normalTexture, "Normal");
|
|
1760
|
+
if (scale !== undefined) {
|
|
1761
|
+
material.normalTextureIntensity = scale;
|
|
1762
|
+
}
|
|
1763
|
+
}
|
|
1764
|
+
if (occlusionTexture) {
|
|
1765
|
+
var index1 = occlusionTexture.index, strength = occlusionTexture.strength, texCoord = occlusionTexture.texCoord;
|
|
1766
|
+
material.occlusionTexture = textures[index1];
|
|
1767
|
+
GLTFMaterialParser._checkOtherTextureTransform(occlusionTexture, "Occlusion");
|
|
1768
|
+
if (strength !== undefined) {
|
|
1769
|
+
material.occlusionTextureIntensity = strength;
|
|
1770
|
+
}
|
|
1771
|
+
if (texCoord === miniprogram.TextureCoordinate.UV1) {
|
|
1772
|
+
material.occlusionTextureCoord = miniprogram.TextureCoordinate.UV1;
|
|
1773
|
+
} else if (texCoord > miniprogram.TextureCoordinate.UV1) {
|
|
1774
|
+
miniprogram.Logger.warn("Occlusion texture uv coordinate must be UV0 or UV1.");
|
|
1775
|
+
}
|
|
1776
|
+
}
|
|
1777
|
+
}
|
|
1778
|
+
if (doubleSided) {
|
|
1779
|
+
material.renderFace = miniprogram.RenderFace.Double;
|
|
1780
|
+
} else {
|
|
1781
|
+
material.renderFace = miniprogram.RenderFace.Front;
|
|
1782
|
+
}
|
|
1783
|
+
switch(alphaMode){
|
|
1784
|
+
case MaterialAlphaMode.OPAQUE:
|
|
1785
|
+
material.isTransparent = false;
|
|
1786
|
+
break;
|
|
1787
|
+
case MaterialAlphaMode.BLEND:
|
|
1788
|
+
material.isTransparent = true;
|
|
1789
|
+
break;
|
|
1790
|
+
case MaterialAlphaMode.MASK:
|
|
1791
|
+
material.alphaCutoff = alphaCutoff != null ? alphaCutoff : 0.5;
|
|
1792
|
+
break;
|
|
1793
|
+
}
|
|
1794
|
+
};
|
|
1795
|
+
return GLTFMaterialParser;
|
|
1796
|
+
}(GLTFParser);
|
|
1797
|
+
|
|
1798
|
+
function _instanceof(left, right) {
|
|
1799
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
1800
|
+
return !!right[Symbol.hasInstance](left);
|
|
1801
|
+
} else return left instanceof right;
|
|
1802
|
+
}
|
|
1803
|
+
|
|
1804
|
+
var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
1805
|
+
_inherits(GLTFMeshParser, GLTFParser1);
|
|
1806
|
+
function GLTFMeshParser() {
|
|
1807
|
+
return GLTFParser1.apply(this, arguments);
|
|
1808
|
+
}
|
|
1809
|
+
var _proto = GLTFMeshParser.prototype;
|
|
1810
|
+
_proto.parse = function parse(context) {
|
|
1811
|
+
var _loop = function(i) {
|
|
1812
|
+
var _loop = function(j) {
|
|
1813
|
+
var gltfPrimitive = gltfMesh.primitives[j];
|
|
1814
|
+
primitivePromises[j] = new Promise(function(resolve) {
|
|
1815
|
+
var mesh = GLTFParser.executeExtensionsCreateAndParse(gltfPrimitive.extensions, context, gltfPrimitive, gltfMesh);
|
|
1816
|
+
if (mesh) {
|
|
1817
|
+
if (_instanceof(mesh, miniprogram.ModelMesh)) {
|
|
1818
|
+
resolve(mesh);
|
|
1819
|
+
} else {
|
|
1820
|
+
mesh.then(function(mesh) {
|
|
1821
|
+
return resolve(mesh);
|
|
1822
|
+
});
|
|
1823
|
+
}
|
|
1824
|
+
} else {
|
|
1825
|
+
var mesh1 = new miniprogram.ModelMesh(engine, gltfMesh.name || j + "");
|
|
1826
|
+
var meshRestoreInfo = new ModelMeshRestoreInfo();
|
|
1827
|
+
meshRestoreInfo.mesh = mesh1;
|
|
1828
|
+
context.contentRestorer.meshes.push(meshRestoreInfo);
|
|
1829
|
+
GLTFMeshParser._parseMeshFromGLTFPrimitive(context, mesh1, meshRestoreInfo, gltfMesh, gltfPrimitive, glTF, function(attributeSemantic) {
|
|
1830
|
+
return null;
|
|
1831
|
+
}, function(attributeName, shapeIndex) {
|
|
1832
|
+
var shapeAccessorIdx = gltfPrimitive.targets[shapeIndex];
|
|
1833
|
+
var attributeAccessorIdx = shapeAccessorIdx[attributeName];
|
|
1834
|
+
if (attributeAccessorIdx) {
|
|
1835
|
+
var accessor = glTF.accessors[attributeAccessorIdx];
|
|
1836
|
+
return GLTFUtils.getAccessorBuffer(context, context.glTF.bufferViews, accessor);
|
|
1837
|
+
} else {
|
|
1838
|
+
return null;
|
|
1839
|
+
}
|
|
1840
|
+
}, function() {
|
|
1841
|
+
var indexAccessor = glTF.accessors[gltfPrimitive.indices];
|
|
1842
|
+
return context.getBuffers().then(function(buffers) {
|
|
1843
|
+
return GLTFUtils.getAccessorData(glTF, indexAccessor, buffers);
|
|
1844
|
+
});
|
|
1845
|
+
}, context.keepMeshData).then(resolve);
|
|
1781
1846
|
}
|
|
1782
1847
|
});
|
|
1783
1848
|
};
|
|
1784
|
-
var gltfMesh =
|
|
1849
|
+
var gltfMesh = glTF.meshes[i];
|
|
1785
1850
|
var primitivePromises = [];
|
|
1786
1851
|
for(var j = 0; j < gltfMesh.primitives.length; j++)_loop(j);
|
|
1787
1852
|
meshPromises[i] = Promise.all(primitivePromises);
|
|
1788
1853
|
};
|
|
1789
|
-
var
|
|
1790
|
-
var gltf = context.gltf, buffers = context.buffers, glTFResource = context.glTFResource;
|
|
1854
|
+
var glTF = context.glTF, glTFResource = context.glTFResource;
|
|
1791
1855
|
var engine = glTFResource.engine;
|
|
1792
|
-
if (!
|
|
1856
|
+
if (!glTF.meshes) return;
|
|
1793
1857
|
var meshesPromiseInfo = context.meshesPromiseInfo;
|
|
1794
1858
|
var meshPromises = [];
|
|
1795
|
-
for(var i = 0; i <
|
|
1859
|
+
for(var i = 0; i < glTF.meshes.length; i++)_loop(i);
|
|
1796
1860
|
miniprogram.AssetPromise.all(meshPromises).then(function(meshes) {
|
|
1797
1861
|
glTFResource.meshes = meshes;
|
|
1798
1862
|
meshesPromiseInfo.resolve(meshes);
|
|
1799
1863
|
}).catch(meshesPromiseInfo.reject);
|
|
1800
1864
|
return meshesPromiseInfo.promise;
|
|
1801
1865
|
};
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
var
|
|
1806
|
-
var engine = mesh.engine;
|
|
1807
|
-
var vertexElements = new Array();
|
|
1808
|
-
var vertexCount;
|
|
1809
|
-
var bufferBindIndex = 0;
|
|
1810
|
-
var positions;
|
|
1811
|
-
keepMeshData && (positions = new Array(vertexCount));
|
|
1812
|
-
for(var attribute in attributes){
|
|
1866
|
+
/**
|
|
1867
|
+
* @internal
|
|
1868
|
+
*/ GLTFMeshParser._parseMeshFromGLTFPrimitive = function _parseMeshFromGLTFPrimitive(context, mesh, meshRestoreInfo, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
|
|
1869
|
+
var _loop = function(attribute) {
|
|
1813
1870
|
var accessor = accessors[attributes[attribute]];
|
|
1814
|
-
var
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
var
|
|
1824
|
-
|
|
1825
|
-
var elementOffset
|
|
1826
|
-
if (
|
|
1827
|
-
|
|
1828
|
-
var
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1871
|
+
var promise = GLTFUtils.getAccessorBuffer(context, gltf.bufferViews, accessor).then(function(accessorBuffer) {
|
|
1872
|
+
var dataElementSize = GLTFUtils.getAccessorTypeSize(accessor.type);
|
|
1873
|
+
var accessorCount = accessor.count;
|
|
1874
|
+
var vertices = accessorBuffer.data;
|
|
1875
|
+
var vertexElement;
|
|
1876
|
+
var meshId = mesh.instanceId;
|
|
1877
|
+
var vertexBindingInfos = accessorBuffer.vertexBindingInfos;
|
|
1878
|
+
var elementNormalized = accessor.normalized;
|
|
1879
|
+
var elementFormat = GLTFUtils.getElementFormat(accessor.componentType, dataElementSize, elementNormalized);
|
|
1880
|
+
var scaleFactor;
|
|
1881
|
+
elementNormalized && (scaleFactor = GLTFUtils.getNormalizedComponentScale(accessor.componentType));
|
|
1882
|
+
var elementOffset;
|
|
1883
|
+
if (accessorBuffer.interleaved) {
|
|
1884
|
+
var byteOffset = accessor.byteOffset || 0;
|
|
1885
|
+
var stride = accessorBuffer.stride;
|
|
1886
|
+
elementOffset = byteOffset % stride;
|
|
1887
|
+
if (vertexBindingInfos[meshId] === undefined) {
|
|
1888
|
+
vertexElement = new miniprogram.VertexElement(attribute, elementOffset, elementFormat, bufferBindIndex);
|
|
1889
|
+
var vertexBuffer = accessorBuffer.vertexBuffer;
|
|
1890
|
+
if (!vertexBuffer) {
|
|
1891
|
+
vertexBuffer = new miniprogram.Buffer(engine, miniprogram.BufferBindFlag.VertexBuffer, vertices.byteLength, miniprogram.BufferUsage.Static);
|
|
1892
|
+
vertexBuffer.setData(vertices);
|
|
1893
|
+
accessorBuffer.vertexBuffer = vertexBuffer;
|
|
1894
|
+
meshRestoreInfo.vertexBuffers.push(new BufferRestoreInfo(vertexBuffer, accessorBuffer.restoreInfo));
|
|
1895
|
+
}
|
|
1896
|
+
mesh.setVertexBufferBinding(vertexBuffer, stride, bufferBindIndex);
|
|
1897
|
+
vertexBindingInfos[meshId] = bufferBindIndex++;
|
|
1898
|
+
} else {
|
|
1899
|
+
vertexElement = new miniprogram.VertexElement(attribute, elementOffset, elementFormat, vertexBindingInfos[meshId]);
|
|
1833
1900
|
}
|
|
1834
|
-
mesh.setVertexBufferBinding(vertexBuffer, stride, bufferBindIndex);
|
|
1835
|
-
vertexBindingInfos[meshId] = bufferBindIndex++;
|
|
1836
1901
|
} else {
|
|
1837
|
-
|
|
1902
|
+
elementOffset = 0;
|
|
1903
|
+
vertexElement = new miniprogram.VertexElement(attribute, elementOffset, elementFormat, bufferBindIndex);
|
|
1904
|
+
var vertexBuffer1 = new miniprogram.Buffer(engine, miniprogram.BufferBindFlag.VertexBuffer, vertices.byteLength, miniprogram.BufferUsage.Static);
|
|
1905
|
+
vertexBuffer1.setData(vertices);
|
|
1906
|
+
meshRestoreInfo.vertexBuffers.push(new BufferRestoreInfo(vertexBuffer1, accessorBuffer.restoreInfo));
|
|
1907
|
+
mesh.setVertexBufferBinding(vertexBuffer1, accessorBuffer.stride, bufferBindIndex);
|
|
1908
|
+
vertexBindingInfos[meshId] = bufferBindIndex++;
|
|
1838
1909
|
}
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1910
|
+
vertexElements.push(vertexElement);
|
|
1911
|
+
if (attribute === "POSITION") {
|
|
1912
|
+
vertexCount = accessorCount;
|
|
1913
|
+
var _mesh_bounds = mesh.bounds, min = _mesh_bounds.min, max = _mesh_bounds.max;
|
|
1914
|
+
if (accessor.min && accessor.max) {
|
|
1915
|
+
min.copyFromArray(accessor.min);
|
|
1916
|
+
max.copyFromArray(accessor.max);
|
|
1917
|
+
if (keepMeshData) {
|
|
1918
|
+
var baseOffset = elementOffset / vertices.BYTES_PER_ELEMENT;
|
|
1919
|
+
var stride1 = vertices.length / accessorCount;
|
|
1920
|
+
for(var j = 0; j < accessorCount; j++){
|
|
1921
|
+
var offset = baseOffset + j * stride1;
|
|
1922
|
+
var position = new miniprogram$1.Vector3(vertices[offset], vertices[offset + 1], vertices[offset + 2]);
|
|
1923
|
+
elementNormalized && position.scale(scaleFactor);
|
|
1924
|
+
positions[j] = position;
|
|
1925
|
+
}
|
|
1926
|
+
}
|
|
1927
|
+
} else {
|
|
1928
|
+
var position1 = GLTFMeshParser._tempVector3;
|
|
1929
|
+
min.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
|
|
1930
|
+
max.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
|
|
1931
|
+
var baseOffset1 = elementOffset / vertices.BYTES_PER_ELEMENT;
|
|
1932
|
+
var stride2 = vertices.length / accessorCount;
|
|
1933
|
+
for(var j1 = 0; j1 < accessorCount; j1++){
|
|
1934
|
+
var offset1 = baseOffset1 + j1 * stride2;
|
|
1935
|
+
position1.copyFromArray(vertices, offset1);
|
|
1936
|
+
miniprogram$1.Vector3.min(min, position1, min);
|
|
1937
|
+
miniprogram$1.Vector3.max(max, position1, max);
|
|
1938
|
+
if (keepMeshData) {
|
|
1939
|
+
var clonePosition = position1.clone();
|
|
1940
|
+
elementNormalized && clonePosition.scale(scaleFactor);
|
|
1941
|
+
positions[j1] = clonePosition;
|
|
1942
|
+
}
|
|
1858
1943
|
}
|
|
1859
1944
|
}
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
miniprogram$1.
|
|
1870
|
-
|
|
1945
|
+
if (elementNormalized) {
|
|
1946
|
+
min.scale(scaleFactor);
|
|
1947
|
+
max.scale(scaleFactor);
|
|
1948
|
+
}
|
|
1949
|
+
} else if (attribute === "JOINTS_0" && keepMeshData) {
|
|
1950
|
+
var baseOffset2 = elementOffset / vertices.BYTES_PER_ELEMENT;
|
|
1951
|
+
var stride3 = vertices.length / accessorCount;
|
|
1952
|
+
for(var j2 = 0; j2 < accessorCount; j2++){
|
|
1953
|
+
var offset2 = baseOffset2 + j2 * stride3;
|
|
1954
|
+
var boneIndex = new miniprogram$1.Vector4(vertices[offset2], vertices[offset2 + 1], vertices[offset2 + 2], vertices[offset2 + 3]);
|
|
1955
|
+
elementNormalized && boneIndex.scale(scaleFactor);
|
|
1956
|
+
boneIndices[j2] = boneIndex;
|
|
1957
|
+
}
|
|
1958
|
+
} else if (attribute === "WEIGHTS_0" && keepMeshData) {
|
|
1959
|
+
var baseOffset3 = elementOffset / vertices.BYTES_PER_ELEMENT;
|
|
1960
|
+
var stride4 = vertices.length / accessorCount;
|
|
1961
|
+
for(var j3 = 0; j3 < accessorCount; j3++){
|
|
1962
|
+
var offset3 = baseOffset3 + j3 * stride4;
|
|
1963
|
+
var boneWeight = new miniprogram$1.Vector4(vertices[offset3], vertices[offset3 + 1], vertices[offset3 + 2], vertices[offset3 + 3]);
|
|
1964
|
+
elementNormalized && boneWeight.scale(scaleFactor);
|
|
1965
|
+
boneWeights[j3] = boneWeight;
|
|
1871
1966
|
}
|
|
1872
1967
|
}
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
}
|
|
1878
|
-
}
|
|
1879
|
-
}
|
|
1880
|
-
mesh.setVertexElements(vertexElements);
|
|
1881
|
-
// Indices
|
|
1882
|
-
if (indices !== undefined) {
|
|
1883
|
-
var indexAccessor = gltf.accessors[indices];
|
|
1884
|
-
var indexData = getIndexBufferData();
|
|
1885
|
-
mesh.setIndices(indexData);
|
|
1886
|
-
mesh.addSubMesh(0, indexAccessor.count, mode);
|
|
1887
|
-
} else {
|
|
1888
|
-
mesh.addSubMesh(0, vertexCount, mode);
|
|
1889
|
-
}
|
|
1890
|
-
// BlendShapes
|
|
1891
|
-
targets && this._createBlendShape(mesh, gltfMesh, targets, getBlendShapeData);
|
|
1892
|
-
mesh.uploadData(!keepMeshData);
|
|
1893
|
-
//@ts-ignore
|
|
1894
|
-
mesh._positions = positions;
|
|
1895
|
-
return Promise.resolve(mesh);
|
|
1896
|
-
};
|
|
1897
|
-
_proto._createBlendShape = function _createBlendShape(mesh, glTFMesh, glTFTargets, getBlendShapeData) {
|
|
1898
|
-
var blendShapeNames = glTFMesh.extras ? glTFMesh.extras.targetNames : null;
|
|
1899
|
-
for(var i = 0, n = glTFTargets.length; i < n; i++){
|
|
1900
|
-
var name = blendShapeNames ? blendShapeNames[i] : "blendShape" + i;
|
|
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;
|
|
1907
|
-
var blendShape = new miniprogram.BlendShape(name);
|
|
1908
|
-
blendShape.addFrame(1.0, deltaPositions, deltaNormals, deltaTangents);
|
|
1909
|
-
mesh.addBlendShape(blendShape);
|
|
1910
|
-
}
|
|
1911
|
-
};
|
|
1912
|
-
/**
|
|
1913
|
-
* @deprecated
|
|
1914
|
-
*/ _proto._parseMeshFromGLTFPrimitiveDraco = function _parseMeshFromGLTFPrimitiveDraco(mesh, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
|
|
1968
|
+
});
|
|
1969
|
+
promises.push(promise);
|
|
1970
|
+
};
|
|
1971
|
+
var accessors = gltf.accessors;
|
|
1915
1972
|
var attributes = gltfPrimitive.attributes, targets = gltfPrimitive.targets, indices = gltfPrimitive.indices, mode = gltfPrimitive.mode;
|
|
1973
|
+
var engine = mesh.engine;
|
|
1974
|
+
var vertexElements = new Array();
|
|
1916
1975
|
var vertexCount;
|
|
1917
|
-
var
|
|
1918
|
-
var
|
|
1919
|
-
var
|
|
1920
|
-
var
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
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
|
-
}
|
|
1976
|
+
var bufferBindIndex = 0;
|
|
1977
|
+
var positions;
|
|
1978
|
+
var boneIndices;
|
|
1979
|
+
var boneWeights;
|
|
1980
|
+
if (keepMeshData) {
|
|
1981
|
+
positions = new Array(vertexCount);
|
|
1982
|
+
boneIndices = new Array(vertexCount);
|
|
1983
|
+
boneWeights = new Array(vertexCount);
|
|
1939
1984
|
}
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1985
|
+
var promises = new Array();
|
|
1986
|
+
for(var attribute in attributes)_loop(attribute);
|
|
1987
|
+
return Promise.all(promises).then(function() {
|
|
1988
|
+
mesh.setVertexElements(vertexElements);
|
|
1989
|
+
// Indices
|
|
1990
|
+
if (indices !== undefined) {
|
|
1991
|
+
var indexAccessor = gltf.accessors[indices];
|
|
1992
|
+
var promise = GLTFUtils.getAccessorBuffer(context, gltf.bufferViews, indexAccessor).then(function(accessorBuffer) {
|
|
1993
|
+
mesh.setIndices(accessorBuffer.data);
|
|
1994
|
+
mesh.addSubMesh(0, indexAccessor.count, mode);
|
|
1995
|
+
meshRestoreInfo.indexBuffer = accessorBuffer.restoreInfo;
|
|
1996
|
+
});
|
|
1997
|
+
promises.push(promise);
|
|
1998
|
+
} else {
|
|
1999
|
+
mesh.addSubMesh(0, vertexCount, mode);
|
|
1943
2000
|
}
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
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;
|
|
2001
|
+
// BlendShapes
|
|
2002
|
+
if (targets) {
|
|
2003
|
+
promises.push(GLTFMeshParser._createBlendShape(mesh, meshRestoreInfo, gltfMesh, accessors, targets, getBlendShapeData));
|
|
1998
2004
|
}
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2005
|
+
return Promise.all(promises).then(function() {
|
|
2006
|
+
mesh.uploadData(!keepMeshData);
|
|
2007
|
+
//@ts-ignore
|
|
2008
|
+
mesh._positions = positions;
|
|
2009
|
+
//@ts-ignore
|
|
2010
|
+
mesh._boneIndices = boneIndices;
|
|
2011
|
+
//@ts-ignore
|
|
2012
|
+
mesh._boneWeights = boneWeights;
|
|
2013
|
+
return Promise.resolve(mesh);
|
|
2014
|
+
});
|
|
2015
|
+
});
|
|
2016
|
+
};
|
|
2017
|
+
/**
|
|
2018
|
+
* @internal
|
|
2019
|
+
*/ GLTFMeshParser._createBlendShape = function _createBlendShape(mesh, meshRestoreInfo, glTFMesh, accessors, glTFTargets, getBlendShapeData) {
|
|
2020
|
+
var _loop = function(i, n) {
|
|
2021
|
+
var name = blendShapeNames ? blendShapeNames[i] : "blendShape" + i;
|
|
2022
|
+
var promise = Promise.all([
|
|
2023
|
+
getBlendShapeData("POSITION", i),
|
|
2024
|
+
getBlendShapeData("NORMAL", i),
|
|
2025
|
+
getBlendShapeData("TANGENT", i)
|
|
2026
|
+
]).then(function(infos) {
|
|
2027
|
+
var posBufferInfo = infos[0];
|
|
2028
|
+
var norBufferInfo = infos[1];
|
|
2029
|
+
var tanBufferInfo = infos[2];
|
|
2030
|
+
var target = glTFTargets[i];
|
|
2031
|
+
var posAccessor;
|
|
2032
|
+
var norAccessor;
|
|
2033
|
+
var tanAccessor;
|
|
2034
|
+
var positions = null;
|
|
2035
|
+
if (posBufferInfo) {
|
|
2036
|
+
posAccessor = accessors[target["POSITION"]];
|
|
2037
|
+
var _posAccessor_byteOffset;
|
|
2038
|
+
positions = GLTFUtils.bufferToVector3Array(posBufferInfo.data, posBufferInfo.stride, (_posAccessor_byteOffset = posAccessor.byteOffset) != null ? _posAccessor_byteOffset : 0, posAccessor.count);
|
|
2039
|
+
}
|
|
2040
|
+
var normals = null;
|
|
2041
|
+
if (norBufferInfo) {
|
|
2042
|
+
norAccessor = accessors[target["NORMAL"]];
|
|
2043
|
+
var _norAccessor_byteOffset;
|
|
2044
|
+
normals = GLTFUtils.bufferToVector3Array(norBufferInfo.data, norBufferInfo.stride, (_norAccessor_byteOffset = norAccessor.byteOffset) != null ? _norAccessor_byteOffset : 0, norAccessor.count);
|
|
2045
|
+
}
|
|
2046
|
+
var tangents = null;
|
|
2047
|
+
if (tanBufferInfo) {
|
|
2048
|
+
tanAccessor = accessors[target["NORMAL"]];
|
|
2049
|
+
var _tanAccessor_byteOffset;
|
|
2050
|
+
tangents = GLTFUtils.bufferToVector3Array(tanBufferInfo.data, tanBufferInfo.stride, (_tanAccessor_byteOffset = tanAccessor.byteOffset) != null ? _tanAccessor_byteOffset : 0, tanAccessor.count);
|
|
2051
|
+
}
|
|
2052
|
+
var blendShape = new miniprogram.BlendShape(name);
|
|
2053
|
+
blendShape.addFrame(1.0, positions, normals, tangents);
|
|
2054
|
+
mesh.addBlendShape(blendShape);
|
|
2055
|
+
var _posAccessor_byteOffset1, _norAccessor_byteOffset1, _tanAccessor_byteOffset1;
|
|
2056
|
+
meshRestoreInfo.blendShapes.push(new BlendShapeRestoreInfo(blendShape, new BlendShapeDataRestoreInfo(posBufferInfo.restoreInfo, posBufferInfo.stride, (_posAccessor_byteOffset1 = posAccessor.byteOffset) != null ? _posAccessor_byteOffset1 : 0, posAccessor.count), norBufferInfo ? new BlendShapeDataRestoreInfo(norBufferInfo.restoreInfo, norBufferInfo.stride, (_norAccessor_byteOffset1 = norAccessor.byteOffset) != null ? _norAccessor_byteOffset1 : 0, norAccessor.count) : null, tanBufferInfo ? new BlendShapeDataRestoreInfo(tanBufferInfo.restoreInfo, tanBufferInfo.stride, (_tanAccessor_byteOffset1 = tanAccessor.byteOffset) != null ? _tanAccessor_byteOffset1 : 0, tanAccessor.count) : null));
|
|
2057
|
+
});
|
|
2058
|
+
promises.push(promise);
|
|
2059
|
+
};
|
|
2060
|
+
var blendShapeNames = glTFMesh.extras ? glTFMesh.extras.targetNames : null;
|
|
2061
|
+
var promises = new Array();
|
|
2062
|
+
for(var i = 0, n = glTFTargets.length; i < n; i++)_loop(i);
|
|
2063
|
+
return Promise.all(promises);
|
|
2013
2064
|
};
|
|
2014
|
-
return
|
|
2015
|
-
}(
|
|
2065
|
+
return GLTFMeshParser;
|
|
2066
|
+
}(GLTFParser);
|
|
2016
2067
|
(function() {
|
|
2017
|
-
|
|
2068
|
+
GLTFMeshParser._tempVector3 = new miniprogram$1.Vector3();
|
|
2018
2069
|
})();
|
|
2019
2070
|
|
|
2020
|
-
var
|
|
2021
|
-
_inherits(
|
|
2022
|
-
function
|
|
2023
|
-
return
|
|
2071
|
+
var GLTFSceneParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
2072
|
+
_inherits(GLTFSceneParser, GLTFParser1);
|
|
2073
|
+
function GLTFSceneParser() {
|
|
2074
|
+
return GLTFParser1.apply(this, arguments);
|
|
2024
2075
|
}
|
|
2025
|
-
var _proto =
|
|
2076
|
+
var _proto = GLTFSceneParser.prototype;
|
|
2026
2077
|
_proto.parse = function parse(context) {
|
|
2027
|
-
var glTFResource = context.glTFResource,
|
|
2078
|
+
var glTFResource = context.glTFResource, glTF = context.glTF;
|
|
2028
2079
|
var entities = glTFResource.entities;
|
|
2029
|
-
var nodes =
|
|
2080
|
+
var nodes = glTF.nodes, cameras = glTF.cameras;
|
|
2030
2081
|
if (!nodes) return;
|
|
2031
2082
|
var defaultSceneRootPromiseInfo = context.defaultSceneRootPromiseInfo;
|
|
2032
|
-
var promises = [];
|
|
2033
2083
|
for(var i = 0; i < nodes.length; i++){
|
|
2034
|
-
var
|
|
2035
|
-
var cameraID =
|
|
2036
|
-
var KHR_lights_punctual = extensions.KHR_lights_punctual;
|
|
2084
|
+
var glTFNode = nodes[i];
|
|
2085
|
+
var cameraID = glTFNode.camera, meshID = glTFNode.mesh, extensions = glTFNode.extensions;
|
|
2037
2086
|
var entity = entities[i];
|
|
2038
2087
|
if (cameraID !== undefined) {
|
|
2039
|
-
this._createCamera(glTFResource,
|
|
2088
|
+
this._createCamera(glTFResource, cameras[cameraID], entity);
|
|
2040
2089
|
}
|
|
2041
2090
|
if (meshID !== undefined) {
|
|
2042
|
-
|
|
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);
|
|
2091
|
+
this._createRenderer(context, glTFNode, entity);
|
|
2048
2092
|
}
|
|
2093
|
+
GLTFParser.executeExtensionsAdditiveAndParse(extensions, context, entity, glTFNode);
|
|
2049
2094
|
}
|
|
2050
2095
|
if (glTFResource.defaultSceneRoot) {
|
|
2051
2096
|
this._createAnimator(context);
|
|
2052
2097
|
}
|
|
2053
|
-
|
|
2054
|
-
miniprogram.AssetPromise.all(promises).then(function() {
|
|
2055
|
-
return defaultSceneRootPromiseInfo.resolve(glTFResource.defaultSceneRoot);
|
|
2056
|
-
}).catch(defaultSceneRootPromiseInfo.reject);
|
|
2098
|
+
defaultSceneRootPromiseInfo.resolve(glTFResource.defaultSceneRoot);
|
|
2057
2099
|
return defaultSceneRootPromiseInfo.promise;
|
|
2058
2100
|
};
|
|
2059
2101
|
_proto._createCamera = function _createCamera(context, cameraSchema, entity) {
|
|
@@ -2089,8 +2131,9 @@ var SceneParser$1 = /*#__PURE__*/ function(Parser1) {
|
|
|
2089
2131
|
// @todo: use engine camera by default
|
|
2090
2132
|
camera.enabled = false;
|
|
2091
2133
|
};
|
|
2092
|
-
_proto._createRenderer = function _createRenderer(context,
|
|
2134
|
+
_proto._createRenderer = function _createRenderer(context, glTFNode, entity) {
|
|
2093
2135
|
var _loop = function(i) {
|
|
2136
|
+
var gltfPrimitive = glTFMeshPrimitives[i];
|
|
2094
2137
|
var mesh = meshes[meshID][i];
|
|
2095
2138
|
var renderer = void 0;
|
|
2096
2139
|
if (skinID !== undefined || blendShapeWeights) {
|
|
@@ -2108,32 +2151,25 @@ var SceneParser$1 = /*#__PURE__*/ function(Parser1) {
|
|
|
2108
2151
|
renderer = entity.addComponent(miniprogram.MeshRenderer);
|
|
2109
2152
|
renderer.mesh = mesh;
|
|
2110
2153
|
}
|
|
2111
|
-
var materialIndex =
|
|
2112
|
-
var
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
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
|
-
}
|
|
2154
|
+
var materialIndex = gltfPrimitive.material;
|
|
2155
|
+
var material = (materials == null ? void 0 : materials[materialIndex]) || GLTFSceneParser._getDefaultMaterial(engine);
|
|
2156
|
+
renderer.setMaterial(material);
|
|
2157
|
+
// Enable vertex color if mesh has COLOR_0 vertex element
|
|
2158
|
+
mesh.vertexElements.forEach(function(element) {
|
|
2159
|
+
if (element.semantic === "COLOR_0") {
|
|
2160
|
+
renderer.enableVertexColor = true;
|
|
2161
|
+
}
|
|
2162
|
+
});
|
|
2163
|
+
GLTFParser.executeExtensionsAdditiveAndParse(gltfPrimitive.extensions, context, renderer, gltfPrimitive);
|
|
2126
2164
|
};
|
|
2127
|
-
var glTFResource = context.glTFResource,
|
|
2128
|
-
var
|
|
2165
|
+
var glTFResource = context.glTFResource, glTF = context.glTF;
|
|
2166
|
+
var glTFMeshes = glTF.meshes;
|
|
2129
2167
|
var engine = glTFResource.engine, meshes = glTFResource.meshes, materials = glTFResource.materials, skins = glTFResource.skins;
|
|
2130
|
-
var meshID =
|
|
2131
|
-
var glTFMesh =
|
|
2132
|
-
var
|
|
2133
|
-
var blendShapeWeights =
|
|
2134
|
-
var
|
|
2135
|
-
for(var i = 0; i < gltfMeshPrimitives.length; i++)_loop(i);
|
|
2136
|
-
return Promise.all(promises);
|
|
2168
|
+
var meshID = glTFNode.mesh, skinID = glTFNode.skin;
|
|
2169
|
+
var glTFMesh = glTFMeshes[meshID];
|
|
2170
|
+
var glTFMeshPrimitives = glTFMesh.primitives;
|
|
2171
|
+
var blendShapeWeights = glTFNode.weights || glTFMesh.weights;
|
|
2172
|
+
for(var i = 0; i < glTFMeshPrimitives.length; i++)_loop(i);
|
|
2137
2173
|
};
|
|
2138
2174
|
_proto._createAnimator = function _createAnimator(context) {
|
|
2139
2175
|
if (!context.hasSkinned && !context.glTFResource.animations) {
|
|
@@ -2160,67 +2196,74 @@ var SceneParser$1 = /*#__PURE__*/ function(Parser1) {
|
|
|
2160
2196
|
}
|
|
2161
2197
|
}
|
|
2162
2198
|
};
|
|
2163
|
-
|
|
2164
|
-
if (!
|
|
2165
|
-
|
|
2199
|
+
GLTFSceneParser._getDefaultMaterial = function _getDefaultMaterial(engine) {
|
|
2200
|
+
if (!GLTFSceneParser._defaultMaterial) {
|
|
2201
|
+
GLTFSceneParser._defaultMaterial = new miniprogram.BlinnPhongMaterial(engine);
|
|
2166
2202
|
}
|
|
2167
|
-
return
|
|
2203
|
+
return GLTFSceneParser._defaultMaterial;
|
|
2168
2204
|
};
|
|
2169
|
-
return
|
|
2170
|
-
}(
|
|
2205
|
+
return GLTFSceneParser;
|
|
2206
|
+
}(GLTFParser);
|
|
2171
2207
|
|
|
2172
|
-
var
|
|
2173
|
-
_inherits(
|
|
2174
|
-
function
|
|
2175
|
-
return
|
|
2208
|
+
var GLTFSkinParser = /*#__PURE__*/ function(GLTFParser) {
|
|
2209
|
+
_inherits(GLTFSkinParser, GLTFParser);
|
|
2210
|
+
function GLTFSkinParser() {
|
|
2211
|
+
return GLTFParser.apply(this, arguments);
|
|
2176
2212
|
}
|
|
2177
|
-
var _proto =
|
|
2213
|
+
var _proto = GLTFSkinParser.prototype;
|
|
2178
2214
|
_proto.parse = function parse(context) {
|
|
2179
|
-
var
|
|
2180
|
-
var entities = glTFResource.entities;
|
|
2181
|
-
var gltfSkins = gltf.skins;
|
|
2182
|
-
if (!gltfSkins) return;
|
|
2183
|
-
var count = gltfSkins.length;
|
|
2184
|
-
var skins = new Array(count);
|
|
2185
|
-
for(var i = 0; i < count; i++){
|
|
2215
|
+
var _loop = function(i) {
|
|
2186
2216
|
var _gltfSkins_i = gltfSkins[i], inverseBindMatrices = _gltfSkins_i.inverseBindMatrices, skeleton = _gltfSkins_i.skeleton, joints = _gltfSkins_i.joints, _gltfSkins_i_name = _gltfSkins_i.name, name = _gltfSkins_i_name === void 0 ? "SKIN_" + i : _gltfSkins_i_name;
|
|
2187
2217
|
var jointCount = joints.length;
|
|
2188
2218
|
var skin = new miniprogram.Skin(name);
|
|
2189
2219
|
skin.inverseBindMatrices.length = jointCount;
|
|
2190
2220
|
// parse IBM
|
|
2191
|
-
var accessor =
|
|
2192
|
-
var
|
|
2193
|
-
|
|
2194
|
-
var
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2221
|
+
var accessor = glTF.accessors[inverseBindMatrices];
|
|
2222
|
+
var promise = GLTFUtils.getAccessorBuffer(context, glTF.bufferViews, accessor).then(function(bufferInfo) {
|
|
2223
|
+
var buffer = bufferInfo.data;
|
|
2224
|
+
for(var i = 0; i < jointCount; i++){
|
|
2225
|
+
var inverseBindMatrix = new miniprogram$1.Matrix();
|
|
2226
|
+
inverseBindMatrix.copyFromArray(buffer, i * 16);
|
|
2227
|
+
skin.inverseBindMatrices[i] = inverseBindMatrix;
|
|
2228
|
+
// get joints
|
|
2229
|
+
for(var i1 = 0; i1 < jointCount; i1++){
|
|
2230
|
+
var jointIndex = joints[i1];
|
|
2231
|
+
var jointName = entities[jointIndex].name;
|
|
2232
|
+
skin.joints[i1] = jointName;
|
|
2233
|
+
// @todo Temporary solution, but it can alleviate the current BUG, and the skinning data mechanism of SkinnedMeshRenderer will be completely refactored in the future
|
|
2234
|
+
for(var j = entities.length - 1; j >= 0; j--){
|
|
2235
|
+
if (jointIndex !== j && entities[j].name === jointName) {
|
|
2236
|
+
entities[j].name = jointName + "_" + j;
|
|
2237
|
+
}
|
|
2238
|
+
}
|
|
2239
|
+
}
|
|
2240
|
+
// get skeleton
|
|
2241
|
+
if (skeleton !== undefined) {
|
|
2242
|
+
skin.skeleton = entities[skeleton].name;
|
|
2243
|
+
} else {
|
|
2244
|
+
var rootBone = _this._findSkeletonRootBone(joints, entities);
|
|
2245
|
+
if (rootBone) {
|
|
2246
|
+
skin.skeleton = rootBone.name;
|
|
2247
|
+
} else {
|
|
2248
|
+
throw "Failed to find skeleton root bone.";
|
|
2249
|
+
}
|
|
2207
2250
|
}
|
|
2208
2251
|
}
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2252
|
+
return skin;
|
|
2253
|
+
});
|
|
2254
|
+
promises.push(promise);
|
|
2255
|
+
};
|
|
2256
|
+
var _this = this;
|
|
2257
|
+
var glTFResource = context.glTFResource, glTF = context.glTF;
|
|
2258
|
+
var entities = glTFResource.entities;
|
|
2259
|
+
var gltfSkins = glTF.skins;
|
|
2260
|
+
if (!gltfSkins) return;
|
|
2261
|
+
var count = gltfSkins.length;
|
|
2262
|
+
var promises = new Array();
|
|
2263
|
+
for(var i = 0; i < count; i++)_loop(i);
|
|
2264
|
+
return miniprogram.AssetPromise.all(promises).then(function(skins) {
|
|
2265
|
+
glTFResource.skins = skins;
|
|
2266
|
+
});
|
|
2224
2267
|
};
|
|
2225
2268
|
_proto._findSkeletonRootBone = function _findSkeletonRootBone(joints, entities) {
|
|
2226
2269
|
var paths = {};
|
|
@@ -2250,53 +2293,62 @@ var SkinParser = /*#__PURE__*/ function(Parser) {
|
|
|
2250
2293
|
rootNode = entity1;
|
|
2251
2294
|
}
|
|
2252
2295
|
};
|
|
2253
|
-
return
|
|
2254
|
-
}(
|
|
2296
|
+
return GLTFSkinParser;
|
|
2297
|
+
}(GLTFParser);
|
|
2255
2298
|
|
|
2256
|
-
var
|
|
2257
|
-
_inherits(
|
|
2258
|
-
function
|
|
2259
|
-
return
|
|
2299
|
+
var GLTFTextureParser = /*#__PURE__*/ function(GLTFParser) {
|
|
2300
|
+
_inherits(GLTFTextureParser, GLTFParser);
|
|
2301
|
+
function GLTFTextureParser() {
|
|
2302
|
+
return GLTFParser.apply(this, arguments);
|
|
2260
2303
|
}
|
|
2261
|
-
var _proto =
|
|
2304
|
+
var _proto = GLTFTextureParser.prototype;
|
|
2262
2305
|
_proto.parse = function parse(context) {
|
|
2263
2306
|
var _this = this;
|
|
2264
|
-
var glTFResource = context.glTFResource,
|
|
2307
|
+
var glTFResource = context.glTFResource, glTF = context.glTF;
|
|
2265
2308
|
var engine = glTFResource.engine, url = glTFResource.url;
|
|
2266
|
-
if (
|
|
2309
|
+
if (glTF.textures) {
|
|
2267
2310
|
var texturesPromiseInfo = context.texturesPromiseInfo;
|
|
2268
|
-
miniprogram.AssetPromise.all(
|
|
2311
|
+
miniprogram.AssetPromise.all(glTF.textures.map(function(param, index) {
|
|
2269
2312
|
var sampler = param.sampler, _param_source = param.source, source = _param_source === void 0 ? 0 : _param_source, textureName = param.name;
|
|
2270
|
-
var
|
|
2313
|
+
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;
|
|
2314
|
+
var samplerInfo = sampler !== undefined && _this._getSamplerInfo(glTF.samplers[sampler]);
|
|
2271
2315
|
if (uri) {
|
|
2272
2316
|
// TODO: support ktx extension https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_texture_basisu/README.md
|
|
2273
2317
|
var index1 = uri.lastIndexOf(".");
|
|
2274
2318
|
var ext = uri.substring(index1 + 1);
|
|
2275
2319
|
var type = ext.startsWith("ktx") ? miniprogram.AssetType.KTX : miniprogram.AssetType.Texture2D;
|
|
2276
2320
|
return engine.resourceManager.load({
|
|
2277
|
-
url:
|
|
2278
|
-
type: type
|
|
2321
|
+
url: miniprogram.Utils.resolveAbsoluteUrl(url, uri),
|
|
2322
|
+
type: type,
|
|
2323
|
+
params: {
|
|
2324
|
+
mipmap: samplerInfo == null ? void 0 : samplerInfo.mipmap
|
|
2325
|
+
}
|
|
2279
2326
|
}).then(function(texture) {
|
|
2280
2327
|
if (!texture.name) {
|
|
2281
2328
|
texture.name = textureName || imageName || "texture_" + index1;
|
|
2282
2329
|
}
|
|
2283
2330
|
if (sampler !== undefined) {
|
|
2284
|
-
_this._parseSampler(texture,
|
|
2331
|
+
_this._parseSampler(texture, samplerInfo);
|
|
2285
2332
|
}
|
|
2286
2333
|
return texture;
|
|
2287
2334
|
});
|
|
2288
2335
|
} else {
|
|
2289
|
-
var bufferView =
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
var
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2336
|
+
var bufferView = glTF.bufferViews[bufferViewIndex];
|
|
2337
|
+
return context.getBuffers().then(function(buffers) {
|
|
2338
|
+
var buffer = buffers[bufferView.buffer];
|
|
2339
|
+
var imageBuffer = new Uint8Array(buffer, bufferView.byteOffset, bufferView.byteLength);
|
|
2340
|
+
return GLTFUtils.loadImageBuffer(imageBuffer, mimeType).then(function(image) {
|
|
2341
|
+
var texture = new miniprogram.Texture2D(engine, image.width, image.height, undefined, samplerInfo == null ? void 0 : samplerInfo.mipmap);
|
|
2342
|
+
texture.setImageSource(image);
|
|
2343
|
+
texture.generateMipmaps();
|
|
2344
|
+
texture.name = textureName || imageName || "texture_" + index;
|
|
2345
|
+
if (sampler !== undefined) {
|
|
2346
|
+
_this._parseSampler(texture, samplerInfo);
|
|
2347
|
+
}
|
|
2348
|
+
var bufferTextureRestoreInfo = new BufferTextureRestoreInfo(texture, bufferView, mimeType);
|
|
2349
|
+
context.contentRestorer.bufferTextures.push(bufferTextureRestoreInfo);
|
|
2350
|
+
return texture;
|
|
2351
|
+
});
|
|
2300
2352
|
});
|
|
2301
2353
|
}
|
|
2302
2354
|
})).then(function(textures) {
|
|
@@ -2306,48 +2358,67 @@ var TextureParser = /*#__PURE__*/ function(Parser) {
|
|
|
2306
2358
|
return texturesPromiseInfo.promise;
|
|
2307
2359
|
}
|
|
2308
2360
|
};
|
|
2309
|
-
_proto.
|
|
2310
|
-
var
|
|
2311
|
-
|
|
2361
|
+
_proto._getSamplerInfo = function _getSamplerInfo(sampler) {
|
|
2362
|
+
var minFilter = sampler.minFilter, magFilter = sampler.magFilter, wrapS = sampler.wrapS, wrapT = sampler.wrapT;
|
|
2363
|
+
var info = {};
|
|
2364
|
+
if (minFilter || magFilter) {
|
|
2365
|
+
info.mipmap = minFilter >= TextureMinFilter.NEAREST_MIPMAP_NEAREST;
|
|
2312
2366
|
if (magFilter === TextureMagFilter.NEAREST) {
|
|
2313
|
-
|
|
2314
|
-
} else if (minFilter <= TextureMinFilter.LINEAR_MIPMAP_NEAREST) {
|
|
2315
|
-
texture.filterMode = miniprogram.TextureFilterMode.Bilinear;
|
|
2367
|
+
info.filterMode = miniprogram.TextureFilterMode.Point;
|
|
2316
2368
|
} else {
|
|
2317
|
-
|
|
2318
|
-
|
|
2369
|
+
if (minFilter <= TextureMinFilter.LINEAR_MIPMAP_NEAREST) {
|
|
2370
|
+
info.filterMode = miniprogram.TextureFilterMode.Bilinear;
|
|
2371
|
+
} else {
|
|
2372
|
+
info.filterMode = miniprogram.TextureFilterMode.Trilinear;
|
|
2373
|
+
}
|
|
2374
|
+
}
|
|
2319
2375
|
}
|
|
2320
2376
|
if (wrapS) {
|
|
2321
|
-
|
|
2377
|
+
info.wrapModeU = GLTFTextureParser._wrapMap[wrapS];
|
|
2322
2378
|
}
|
|
2323
2379
|
if (wrapT) {
|
|
2324
|
-
|
|
2380
|
+
info.wrapModeV = GLTFTextureParser._wrapMap[wrapT];
|
|
2325
2381
|
}
|
|
2382
|
+
return info;
|
|
2326
2383
|
};
|
|
2327
|
-
|
|
2328
|
-
|
|
2384
|
+
_proto._parseSampler = function _parseSampler(texture, samplerInfo) {
|
|
2385
|
+
var filterMode = samplerInfo.filterMode, wrapModeU = samplerInfo.wrapModeU, wrapModeV = samplerInfo.wrapModeV;
|
|
2386
|
+
if (filterMode !== undefined) {
|
|
2387
|
+
texture.filterMode = filterMode;
|
|
2388
|
+
}
|
|
2389
|
+
if (wrapModeU !== undefined) {
|
|
2390
|
+
texture.wrapModeU = wrapModeU;
|
|
2391
|
+
}
|
|
2392
|
+
if (wrapModeV !== undefined) {
|
|
2393
|
+
texture.wrapModeV = wrapModeV;
|
|
2394
|
+
}
|
|
2395
|
+
};
|
|
2396
|
+
return GLTFTextureParser;
|
|
2397
|
+
}(GLTFParser);
|
|
2329
2398
|
(function() {
|
|
2330
2399
|
var _obj;
|
|
2331
|
-
|
|
2400
|
+
GLTFTextureParser._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
2401
|
})();
|
|
2333
2402
|
|
|
2334
|
-
var
|
|
2335
|
-
_inherits(
|
|
2336
|
-
function
|
|
2337
|
-
return
|
|
2403
|
+
var GLTFValidator = /*#__PURE__*/ function(GLTFParser1) {
|
|
2404
|
+
_inherits(GLTFValidator, GLTFParser1);
|
|
2405
|
+
function GLTFValidator() {
|
|
2406
|
+
return GLTFParser1.apply(this, arguments);
|
|
2338
2407
|
}
|
|
2339
|
-
var _proto =
|
|
2408
|
+
var _proto = GLTFValidator.prototype;
|
|
2340
2409
|
_proto.parse = function parse(context) {
|
|
2341
|
-
var
|
|
2342
|
-
var
|
|
2343
|
-
if (!(
|
|
2344
|
-
throw "Only support
|
|
2410
|
+
var _context_glTF = context.glTF, version = _context_glTF.asset.version, extensionsUsed = _context_glTF.extensionsUsed, extensionsRequired = _context_glTF.extensionsRequired;
|
|
2411
|
+
var glTFVersion = Number(version);
|
|
2412
|
+
if (!(glTFVersion >= 2 && glTFVersion < 3)) {
|
|
2413
|
+
throw "Only support glTF 2.x.";
|
|
2345
2414
|
}
|
|
2415
|
+
var promises = [];
|
|
2346
2416
|
if (extensionsUsed) {
|
|
2347
2417
|
miniprogram.Logger.info("extensionsUsed: ", extensionsUsed);
|
|
2348
2418
|
for(var i = 0; i < extensionsUsed.length; i++){
|
|
2349
|
-
|
|
2350
|
-
|
|
2419
|
+
var extensionUsed = extensionsUsed[i];
|
|
2420
|
+
if (!GLTFParser.hasExtensionParser(extensionUsed)) {
|
|
2421
|
+
miniprogram.Logger.warn("Extension " + extensionUsed + " is not implemented, you can customize this extension in gltf.");
|
|
2351
2422
|
}
|
|
2352
2423
|
}
|
|
2353
2424
|
}
|
|
@@ -2355,98 +2426,78 @@ var Validator = /*#__PURE__*/ function(Parser1) {
|
|
|
2355
2426
|
miniprogram.Logger.info("extensionsRequired: " + extensionsRequired);
|
|
2356
2427
|
for(var i1 = 0; i1 < extensionsRequired.length; i1++){
|
|
2357
2428
|
var extensionRequired = extensionsRequired[i1];
|
|
2358
|
-
if (!
|
|
2429
|
+
if (!GLTFParser.hasExtensionParser(extensionRequired)) {
|
|
2359
2430
|
miniprogram.Logger.error("GLTF parser has not supported required extension " + extensionRequired + ".");
|
|
2360
2431
|
} else {
|
|
2361
|
-
|
|
2432
|
+
promises.push(GLTFParser.executeExtensionsInitialize(extensionRequired));
|
|
2362
2433
|
}
|
|
2363
2434
|
}
|
|
2364
2435
|
}
|
|
2436
|
+
return miniprogram.AssetPromise.all(promises).then(null);
|
|
2365
2437
|
};
|
|
2366
|
-
return
|
|
2367
|
-
}(
|
|
2438
|
+
return GLTFValidator;
|
|
2439
|
+
}(GLTFParser);
|
|
2368
2440
|
|
|
2369
|
-
|
|
2370
|
-
|
|
2441
|
+
/**
|
|
2442
|
+
* GLTF pipeline.
|
|
2443
|
+
*/ var GLTFPipeline = /*#__PURE__*/ function() {
|
|
2444
|
+
function GLTFPipeline() {
|
|
2445
|
+
for(var _len = arguments.length, parsers = new Array(_len), _key = 0; _key < _len; _key++){
|
|
2446
|
+
parsers[_key] = arguments[_key];
|
|
2447
|
+
}
|
|
2371
2448
|
var _this = this;
|
|
2372
|
-
this.
|
|
2373
|
-
|
|
2374
|
-
_this.
|
|
2449
|
+
this._parsers = [];
|
|
2450
|
+
parsers.forEach(function(pipe, index) {
|
|
2451
|
+
_this._parsers[index] = new pipe();
|
|
2375
2452
|
});
|
|
2376
2453
|
}
|
|
2377
|
-
var _proto =
|
|
2378
|
-
|
|
2454
|
+
var _proto = GLTFPipeline.prototype;
|
|
2455
|
+
/**
|
|
2456
|
+
* @internal
|
|
2457
|
+
*/ _proto._parse = function _parse(context) {
|
|
2379
2458
|
var _this = this;
|
|
2380
2459
|
var glTFResource = context.glTFResource;
|
|
2381
|
-
var
|
|
2460
|
+
var lastParser;
|
|
2382
2461
|
return new miniprogram.AssetPromise(function(resolve, reject) {
|
|
2383
|
-
_this.
|
|
2384
|
-
if (
|
|
2385
|
-
|
|
2462
|
+
_this._parsers.forEach(function(parser) {
|
|
2463
|
+
if (lastParser) {
|
|
2464
|
+
lastParser = lastParser.then(function() {
|
|
2386
2465
|
return parser.parse(context);
|
|
2387
2466
|
});
|
|
2388
|
-
if (
|
|
2389
|
-
context.chainPromises.push(
|
|
2467
|
+
if (lastParser.cancel) {
|
|
2468
|
+
context.chainPromises.push(lastParser);
|
|
2390
2469
|
}
|
|
2391
2470
|
} else {
|
|
2392
|
-
|
|
2471
|
+
lastParser = parser.parse(context);
|
|
2393
2472
|
}
|
|
2394
2473
|
});
|
|
2395
|
-
if (
|
|
2396
|
-
|
|
2474
|
+
if (lastParser) {
|
|
2475
|
+
lastParser.then(function() {
|
|
2397
2476
|
resolve(glTFResource);
|
|
2398
2477
|
}).catch(reject);
|
|
2399
2478
|
}
|
|
2400
2479
|
});
|
|
2401
2480
|
};
|
|
2402
|
-
return
|
|
2481
|
+
return GLTFPipeline;
|
|
2403
2482
|
}();
|
|
2404
2483
|
(function() {
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
TextureParser,
|
|
2409
|
-
MaterialParser,
|
|
2410
|
-
MeshParser,
|
|
2411
|
-
EntityParser,
|
|
2412
|
-
SkinParser,
|
|
2413
|
-
AnimationParser,
|
|
2414
|
-
SceneParser$1
|
|
2415
|
-
]);
|
|
2484
|
+
/**
|
|
2485
|
+
* Default pipeline.
|
|
2486
|
+
*/ GLTFPipeline.defaultPipeline = new GLTFPipeline(GLTFBufferParser, GLTFValidator, GLTFTextureParser, GLTFMaterialParser, GLTFMeshParser, GLTFEntityParser, GLTFSkinParser, GLTFAnimationParser, GLTFSceneParser);
|
|
2416
2487
|
})();
|
|
2417
2488
|
|
|
2418
2489
|
/**
|
|
2419
|
-
* Product after
|
|
2420
|
-
*/ var GLTFResource = /*#__PURE__*/ function(
|
|
2421
|
-
_inherits(GLTFResource,
|
|
2490
|
+
* Product after glTF parser, usually, `defaultSceneRoot` is only needed to use.
|
|
2491
|
+
*/ var GLTFResource = /*#__PURE__*/ function(ReferResource) {
|
|
2492
|
+
_inherits(GLTFResource, ReferResource);
|
|
2422
2493
|
function GLTFResource(engine, url) {
|
|
2423
2494
|
var _this;
|
|
2424
|
-
_this =
|
|
2495
|
+
_this = ReferResource.call(this, engine) || this;
|
|
2425
2496
|
_this.url = url;
|
|
2426
2497
|
return _this;
|
|
2427
2498
|
}
|
|
2428
|
-
var _proto = GLTFResource.prototype;
|
|
2429
|
-
/**
|
|
2430
|
-
* @override
|
|
2431
|
-
*/ _proto.destroy = function destroy() {
|
|
2432
|
-
if (this._destroyed) {
|
|
2433
|
-
return;
|
|
2434
|
-
}
|
|
2435
|
-
EngineObject.prototype.destroy.call(this);
|
|
2436
|
-
this.defaultSceneRoot.destroy();
|
|
2437
|
-
this.textures = null;
|
|
2438
|
-
this.materials = null;
|
|
2439
|
-
this.meshes = null;
|
|
2440
|
-
this.skins = null;
|
|
2441
|
-
this.animations = null;
|
|
2442
|
-
this.entities = null;
|
|
2443
|
-
this.cameras = null;
|
|
2444
|
-
this.lights = null;
|
|
2445
|
-
this.sceneRoots = null;
|
|
2446
|
-
this.variants = null;
|
|
2447
|
-
};
|
|
2448
2499
|
return GLTFResource;
|
|
2449
|
-
}(miniprogram.
|
|
2500
|
+
}(miniprogram.ReferResource);
|
|
2450
2501
|
|
|
2451
2502
|
var GLTFLoader = /*#__PURE__*/ function(Loader) {
|
|
2452
2503
|
_inherits(GLTFLoader, Loader);
|
|
@@ -2455,14 +2506,16 @@ var GLTFLoader = /*#__PURE__*/ function(Loader) {
|
|
|
2455
2506
|
}
|
|
2456
2507
|
var _proto = GLTFLoader.prototype;
|
|
2457
2508
|
_proto.load = function load(item, resourceManager) {
|
|
2458
|
-
var _item_params;
|
|
2459
2509
|
var url = item.url;
|
|
2460
|
-
var
|
|
2510
|
+
var params = item.params;
|
|
2511
|
+
var context = new GLTFParserContext(url);
|
|
2461
2512
|
var glTFResource = new GLTFResource(resourceManager.engine, url);
|
|
2513
|
+
var restorer = new GLTFContentRestorer(glTFResource);
|
|
2462
2514
|
var masterPromiseInfo = context.masterPromiseInfo;
|
|
2515
|
+
context.contentRestorer = restorer;
|
|
2463
2516
|
context.glTFResource = glTFResource;
|
|
2464
|
-
var
|
|
2465
|
-
context.keepMeshData = (
|
|
2517
|
+
var _params_keepMeshData;
|
|
2518
|
+
context.keepMeshData = (_params_keepMeshData = params == null ? void 0 : params.keepMeshData) != null ? _params_keepMeshData : false;
|
|
2466
2519
|
masterPromiseInfo.onCancel(function() {
|
|
2467
2520
|
var chainPromises = context.chainPromises;
|
|
2468
2521
|
for(var _iterator = _create_for_of_iterator_helper_loose(chainPromises), _step; !(_step = _iterator()).done;){
|
|
@@ -2470,16 +2523,25 @@ var GLTFLoader = /*#__PURE__*/ function(Loader) {
|
|
|
2470
2523
|
promise.cancel();
|
|
2471
2524
|
}
|
|
2472
2525
|
});
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
masterPromiseInfo.
|
|
2526
|
+
((params == null ? void 0 : params.pipeline) || GLTFPipeline.defaultPipeline)._parse(context).then(function(glTFResource) {
|
|
2527
|
+
resourceManager.addContentRestorer(restorer);
|
|
2528
|
+
masterPromiseInfo.resolve(glTFResource);
|
|
2529
|
+
}).catch(function(e) {
|
|
2530
|
+
var msg = "Error loading glTF model from " + url + " : " + e;
|
|
2531
|
+
miniprogram.Logger.error(msg);
|
|
2532
|
+
masterPromiseInfo.reject(msg);
|
|
2533
|
+
context.defaultSceneRootPromiseInfo.reject(e);
|
|
2534
|
+
context.texturesPromiseInfo.reject(e);
|
|
2535
|
+
context.materialsPromiseInfo.reject(e);
|
|
2536
|
+
context.meshesPromiseInfo.reject(e);
|
|
2537
|
+
context.animationClipsPromiseInfo.reject(e);
|
|
2476
2538
|
});
|
|
2477
2539
|
return context.promiseMap;
|
|
2478
2540
|
};
|
|
2479
2541
|
return GLTFLoader;
|
|
2480
2542
|
}(miniprogram.Loader);
|
|
2481
2543
|
GLTFLoader = __decorate([
|
|
2482
|
-
miniprogram.resourceLoader(miniprogram.AssetType.
|
|
2544
|
+
miniprogram.resourceLoader(miniprogram.AssetType.GLTF, [
|
|
2483
2545
|
"gltf",
|
|
2484
2546
|
"glb"
|
|
2485
2547
|
])
|
|
@@ -2565,7 +2627,7 @@ var HDRLoader = (_HDRLoader = /*#__PURE__*/ function(Loader) {
|
|
|
2565
2627
|
return textureArray;
|
|
2566
2628
|
};
|
|
2567
2629
|
HDRLoader1._calcProjectionSpherical = function _calcProjectionSpherical(vDir, pixels, inputWidth, inputHeight) {
|
|
2568
|
-
var theta = Math.atan2(vDir.z,
|
|
2630
|
+
var theta = Math.atan2(vDir.z, vDir.x);
|
|
2569
2631
|
var phi = Math.acos(vDir.y);
|
|
2570
2632
|
while(theta < -PI){
|
|
2571
2633
|
theta += 2 * PI;
|
|
@@ -2867,40 +2929,40 @@ function getEngineFormat(internalFormat) {
|
|
|
2867
2929
|
// case GLCompressedTextureInternalFormat.RGBA_S3TC_DXT3_EXT:
|
|
2868
2930
|
// case GLCompressedTextureInternalFormat.RGBA_S3TC_DXT5_EXT:
|
|
2869
2931
|
// break;
|
|
2870
|
-
case miniprogram$
|
|
2932
|
+
case miniprogram$2.GLCompressedTextureInternalFormat.RGB_S3TC_DXT1_EXT:
|
|
2871
2933
|
return miniprogram.TextureFormat.DXT1;
|
|
2872
|
-
case miniprogram$
|
|
2934
|
+
case miniprogram$2.GLCompressedTextureInternalFormat.RGBA_S3TC_DXT5_EXT:
|
|
2873
2935
|
return miniprogram.TextureFormat.DXT5;
|
|
2874
|
-
case miniprogram$
|
|
2936
|
+
case miniprogram$2.GLCompressedTextureInternalFormat.RGB_ETC1_WEBGL:
|
|
2875
2937
|
return miniprogram.TextureFormat.ETC1_RGB;
|
|
2876
|
-
case miniprogram$
|
|
2938
|
+
case miniprogram$2.GLCompressedTextureInternalFormat.RGB8_ETC2:
|
|
2877
2939
|
return miniprogram.TextureFormat.ETC2_RGB;
|
|
2878
|
-
case miniprogram$
|
|
2940
|
+
case miniprogram$2.GLCompressedTextureInternalFormat.RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
|
|
2879
2941
|
return miniprogram.TextureFormat.ETC2_RGBA5;
|
|
2880
|
-
case miniprogram$
|
|
2942
|
+
case miniprogram$2.GLCompressedTextureInternalFormat.RGBA8_ETC2_EAC:
|
|
2881
2943
|
return miniprogram.TextureFormat.ETC2_RGBA8;
|
|
2882
|
-
case miniprogram$
|
|
2944
|
+
case miniprogram$2.GLCompressedTextureInternalFormat.RGB_PVRTC_2BPPV1_IMG:
|
|
2883
2945
|
return miniprogram.TextureFormat.PVRTC_RGB2;
|
|
2884
|
-
case miniprogram$
|
|
2946
|
+
case miniprogram$2.GLCompressedTextureInternalFormat.RGBA_PVRTC_2BPPV1_IMG:
|
|
2885
2947
|
return miniprogram.TextureFormat.PVRTC_RGBA2;
|
|
2886
|
-
case miniprogram$
|
|
2948
|
+
case miniprogram$2.GLCompressedTextureInternalFormat.RGB_PVRTC_4BPPV1_IMG:
|
|
2887
2949
|
return miniprogram.TextureFormat.PVRTC_RGB4;
|
|
2888
|
-
case miniprogram$
|
|
2950
|
+
case miniprogram$2.GLCompressedTextureInternalFormat.RGBA_PVRTC_4BPPV1_IMG:
|
|
2889
2951
|
return miniprogram.TextureFormat.PVRTC_RGBA4;
|
|
2890
|
-
case miniprogram$
|
|
2952
|
+
case miniprogram$2.GLCompressedTextureInternalFormat.RGBA_ASTC_4X4_KHR:
|
|
2891
2953
|
return miniprogram.TextureFormat.ASTC_4x4;
|
|
2892
|
-
case miniprogram$
|
|
2954
|
+
case miniprogram$2.GLCompressedTextureInternalFormat.RGBA_ASTC_5X5_KHR:
|
|
2893
2955
|
return miniprogram.TextureFormat.ASTC_5x5;
|
|
2894
|
-
case miniprogram$
|
|
2956
|
+
case miniprogram$2.GLCompressedTextureInternalFormat.RGBA_ASTC_6X6_KHR:
|
|
2895
2957
|
return miniprogram.TextureFormat.ASTC_6x6;
|
|
2896
|
-
case miniprogram$
|
|
2958
|
+
case miniprogram$2.GLCompressedTextureInternalFormat.RGBA_ASTC_8X8_KHR:
|
|
2897
2959
|
return miniprogram.TextureFormat.ASTC_8x8;
|
|
2898
|
-
case miniprogram$
|
|
2960
|
+
case miniprogram$2.GLCompressedTextureInternalFormat.RGBA_ASTC_10X10_KHR:
|
|
2899
2961
|
return miniprogram.TextureFormat.ASTC_10x10;
|
|
2900
|
-
case miniprogram$
|
|
2962
|
+
case miniprogram$2.GLCompressedTextureInternalFormat.RGBA_ASTC_12X12_KHR:
|
|
2901
2963
|
return miniprogram.TextureFormat.ASTC_12x12;
|
|
2902
2964
|
default:
|
|
2903
|
-
var formatName = miniprogram$
|
|
2965
|
+
var formatName = miniprogram$2.GLCompressedTextureInternalFormat[internalFormat];
|
|
2904
2966
|
throw new Error("this format is not supported in Galacean Engine: " + formatName);
|
|
2905
2967
|
}
|
|
2906
2968
|
}
|
|
@@ -3074,6 +3136,15 @@ KTXLoader = __decorate([
|
|
|
3074
3136
|
])
|
|
3075
3137
|
], KTXLoader);
|
|
3076
3138
|
|
|
3139
|
+
function parseProperty(object, key, value) {
|
|
3140
|
+
if (typeof value === "object") {
|
|
3141
|
+
for(var subKey in value){
|
|
3142
|
+
parseProperty(object[key], subKey, value[subKey]);
|
|
3143
|
+
}
|
|
3144
|
+
} else {
|
|
3145
|
+
object[key] = value;
|
|
3146
|
+
}
|
|
3147
|
+
}
|
|
3077
3148
|
var MaterialLoader = /*#__PURE__*/ function(Loader) {
|
|
3078
3149
|
_inherits(MaterialLoader, Loader);
|
|
3079
3150
|
function MaterialLoader() {
|
|
@@ -3085,7 +3156,7 @@ var MaterialLoader = /*#__PURE__*/ function(Loader) {
|
|
|
3085
3156
|
return new miniprogram.AssetPromise(function(resolve, reject) {
|
|
3086
3157
|
_this.request(item.url, _extends({}, item, {
|
|
3087
3158
|
type: "json"
|
|
3088
|
-
})).then(function(
|
|
3159
|
+
})).then(function(materialSchema) {
|
|
3089
3160
|
var _loop = function(key) {
|
|
3090
3161
|
var _shaderData_key = shaderData[key], type = _shaderData_key.type, value = _shaderData_key.value;
|
|
3091
3162
|
switch(type){
|
|
@@ -3113,27 +3184,8 @@ var MaterialLoader = /*#__PURE__*/ function(Loader) {
|
|
|
3113
3184
|
}
|
|
3114
3185
|
};
|
|
3115
3186
|
var engine = resourceManager.engine;
|
|
3116
|
-
var name =
|
|
3117
|
-
var material;
|
|
3118
|
-
switch(shader){
|
|
3119
|
-
case "pbr":
|
|
3120
|
-
material = new miniprogram.PBRMaterial(engine);
|
|
3121
|
-
break;
|
|
3122
|
-
case "pbr-specular":
|
|
3123
|
-
material = new miniprogram.PBRSpecularMaterial(engine);
|
|
3124
|
-
break;
|
|
3125
|
-
case "unlit":
|
|
3126
|
-
material = new miniprogram.UnlitMaterial(engine);
|
|
3127
|
-
break;
|
|
3128
|
-
case "blinn-phong":
|
|
3129
|
-
material = new miniprogram.BlinnPhongMaterial(engine);
|
|
3130
|
-
break;
|
|
3131
|
-
case "bake-pbr":
|
|
3132
|
-
// @todo refactor custom shader later
|
|
3133
|
-
// @ts-ignore
|
|
3134
|
-
material = new miniprogram.PBRBaseMaterial(engine, miniprogram.Shader.find("bake-pbr"));
|
|
3135
|
-
break;
|
|
3136
|
-
}
|
|
3187
|
+
var name = materialSchema.name, shader = materialSchema.shader, shaderData = materialSchema.shaderData, macros = materialSchema.macros, renderState = materialSchema.renderState;
|
|
3188
|
+
var material = new miniprogram.Material(engine, miniprogram.Shader.find(shader));
|
|
3137
3189
|
material.name = name;
|
|
3138
3190
|
var texturePromises = new Array();
|
|
3139
3191
|
var materialShaderData = material.shaderData;
|
|
@@ -3146,9 +3198,7 @@ var MaterialLoader = /*#__PURE__*/ function(Loader) {
|
|
|
3146
3198
|
materialShaderData.enableMacro(name1, value);
|
|
3147
3199
|
}
|
|
3148
3200
|
}
|
|
3149
|
-
|
|
3150
|
-
material[key1] = renderState[key1];
|
|
3151
|
-
}
|
|
3201
|
+
parseProperty(material, "renderState", renderState);
|
|
3152
3202
|
return Promise.all(texturePromises).then(function() {
|
|
3153
3203
|
resolve(material);
|
|
3154
3204
|
});
|
|
@@ -3248,7 +3298,7 @@ var BufferReader = /*#__PURE__*/ function() {
|
|
|
3248
3298
|
var strByteLength = this.nextUint16();
|
|
3249
3299
|
var uint8Array = new Uint8Array(this.buffer, this._offset, strByteLength);
|
|
3250
3300
|
this._offset += strByteLength;
|
|
3251
|
-
return
|
|
3301
|
+
return miniprogram.Utils.decodeText(uint8Array);
|
|
3252
3302
|
};
|
|
3253
3303
|
/**
|
|
3254
3304
|
* image data 放在最后
|
|
@@ -3333,8 +3383,8 @@ var FileHeader = /*#__PURE__*/ function() {
|
|
|
3333
3383
|
var typeUint8Array = new Uint8Array(arrayBuffer, 7, typeLen);
|
|
3334
3384
|
var nameLen = dataView.getUint16(7 + typeLen, true);
|
|
3335
3385
|
var nameUint8Array = new Uint8Array(arrayBuffer, 9 + typeLen, nameLen);
|
|
3336
|
-
var name =
|
|
3337
|
-
var type =
|
|
3386
|
+
var name = miniprogram.Utils.decodeText(nameUint8Array);
|
|
3387
|
+
var type = miniprogram.Utils.decodeText(typeUint8Array);
|
|
3338
3388
|
var header = new FileHeader();
|
|
3339
3389
|
header.totalLength = totalLen;
|
|
3340
3390
|
header.name = name;
|
|
@@ -3903,6 +3953,12 @@ exports.AnimationClipDecoder = __decorate([
|
|
|
3903
3953
|
decoder("AnimationClip")
|
|
3904
3954
|
], exports.AnimationClipDecoder);
|
|
3905
3955
|
|
|
3956
|
+
exports.SpecularMode = void 0;
|
|
3957
|
+
(function(SpecularMode) {
|
|
3958
|
+
SpecularMode["Sky"] = "Sky";
|
|
3959
|
+
SpecularMode["Custom"] = "Custom";
|
|
3960
|
+
})(exports.SpecularMode || (exports.SpecularMode = {}));
|
|
3961
|
+
|
|
3906
3962
|
var SceneParserContext = /*#__PURE__*/ function() {
|
|
3907
3963
|
function SceneParserContext(originalData, scene) {
|
|
3908
3964
|
this.originalData = originalData;
|
|
@@ -4030,7 +4086,7 @@ exports.MeshLoader = /*#__PURE__*/ function(Loader) {
|
|
|
4030
4086
|
decode(data, resourceManager.engine).then(function(mesh) {
|
|
4031
4087
|
resolve(mesh);
|
|
4032
4088
|
});
|
|
4033
|
-
});
|
|
4089
|
+
}).catch(reject);
|
|
4034
4090
|
});
|
|
4035
4091
|
};
|
|
4036
4092
|
return MeshLoader;
|
|
@@ -4049,14 +4105,14 @@ exports.EditorTextureLoader = /*#__PURE__*/ function(Loader) {
|
|
|
4049
4105
|
var _proto = EditorTextureLoader.prototype;
|
|
4050
4106
|
_proto.load = function load(item, resourceManager) {
|
|
4051
4107
|
var _this = this;
|
|
4052
|
-
return new miniprogram.AssetPromise(function(resolve) {
|
|
4108
|
+
return new miniprogram.AssetPromise(function(resolve, reject) {
|
|
4053
4109
|
_this.request(item.url, {
|
|
4054
4110
|
type: "arraybuffer"
|
|
4055
4111
|
}).then(function(data) {
|
|
4056
4112
|
decode(data, resourceManager.engine).then(function(texture) {
|
|
4057
4113
|
resolve(texture);
|
|
4058
4114
|
});
|
|
4059
|
-
});
|
|
4115
|
+
}).catch(reject);
|
|
4060
4116
|
});
|
|
4061
4117
|
};
|
|
4062
4118
|
return EditorTextureLoader;
|
|
@@ -4185,7 +4241,7 @@ var SpriteAtlasLoader = /*#__PURE__*/ function(Loader) {
|
|
|
4185
4241
|
var atlasItem = atlasItems[i];
|
|
4186
4242
|
if (atlasItem.img) {
|
|
4187
4243
|
chainPromises.push(resourceManager.load({
|
|
4188
|
-
url: atlasItem.img,
|
|
4244
|
+
url: miniprogram.Utils.resolveAbsoluteUrl(item.url, atlasItem.img),
|
|
4189
4245
|
type: miniprogram.AssetType.Texture2D,
|
|
4190
4246
|
params: {
|
|
4191
4247
|
format: format,
|
|
@@ -4284,6 +4340,30 @@ SpriteLoader = __decorate([
|
|
|
4284
4340
|
], false)
|
|
4285
4341
|
], SpriteLoader);
|
|
4286
4342
|
|
|
4343
|
+
/**
|
|
4344
|
+
* @internal
|
|
4345
|
+
*/ var Texture2DContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
|
|
4346
|
+
_inherits(Texture2DContentRestorer, ContentRestorer);
|
|
4347
|
+
function Texture2DContentRestorer(resource, url, requestConfig) {
|
|
4348
|
+
var _this;
|
|
4349
|
+
_this = ContentRestorer.call(this, resource) || this;
|
|
4350
|
+
_this.url = url;
|
|
4351
|
+
_this.requestConfig = requestConfig;
|
|
4352
|
+
return _this;
|
|
4353
|
+
}
|
|
4354
|
+
var _proto = Texture2DContentRestorer.prototype;
|
|
4355
|
+
_proto.restoreContent = function restoreContent() {
|
|
4356
|
+
var _this = this;
|
|
4357
|
+
return miniprogram.request(this.url, this.requestConfig).then(function(image) {
|
|
4358
|
+
var resource = _this.resource;
|
|
4359
|
+
resource.setImageSource(image);
|
|
4360
|
+
resource.generateMipmaps();
|
|
4361
|
+
return resource;
|
|
4362
|
+
});
|
|
4363
|
+
};
|
|
4364
|
+
return Texture2DContentRestorer;
|
|
4365
|
+
}(miniprogram.ContentRestorer);
|
|
4366
|
+
|
|
4287
4367
|
var Texture2DLoader = /*#__PURE__*/ function(Loader) {
|
|
4288
4368
|
_inherits(Texture2DLoader, Loader);
|
|
4289
4369
|
function Texture2DLoader() {
|
|
@@ -4293,19 +4373,20 @@ var Texture2DLoader = /*#__PURE__*/ function(Loader) {
|
|
|
4293
4373
|
_proto.load = function load(item, resourceManager) {
|
|
4294
4374
|
var _this = this;
|
|
4295
4375
|
return new miniprogram.AssetPromise(function(resolve, reject) {
|
|
4296
|
-
|
|
4376
|
+
var url = item.url;
|
|
4377
|
+
var requestConfig = _extends({}, item, {
|
|
4297
4378
|
type: "image"
|
|
4298
|
-
})
|
|
4299
|
-
|
|
4300
|
-
var params =
|
|
4301
|
-
var texture = new miniprogram.Texture2D(resourceManager.engine, image.width, image.height, params.format, params.mipmap);
|
|
4302
|
-
/** @ts-ignore */ if (!texture._platformTexture) return;
|
|
4379
|
+
});
|
|
4380
|
+
_this.request(url, requestConfig).then(function(image) {
|
|
4381
|
+
var params = item.params;
|
|
4382
|
+
var texture = new miniprogram.Texture2D(resourceManager.engine, image.width, image.height, params == null ? void 0 : params.format, params == null ? void 0 : params.mipmap);
|
|
4303
4383
|
texture.setImageSource(image);
|
|
4304
4384
|
texture.generateMipmaps();
|
|
4305
|
-
if (
|
|
4306
|
-
var
|
|
4307
|
-
texture.name =
|
|
4385
|
+
if (url.indexOf("data:") !== 0) {
|
|
4386
|
+
var index = url.lastIndexOf("/");
|
|
4387
|
+
texture.name = url.substring(index + 1);
|
|
4308
4388
|
}
|
|
4389
|
+
resourceManager.addContentRestorer(new Texture2DContentRestorer(texture, url, requestConfig));
|
|
4309
4390
|
resolve(texture);
|
|
4310
4391
|
}).catch(function(e) {
|
|
4311
4392
|
reject(e);
|
|
@@ -4323,6 +4404,38 @@ Texture2DLoader = __decorate([
|
|
|
4323
4404
|
])
|
|
4324
4405
|
], Texture2DLoader);
|
|
4325
4406
|
|
|
4407
|
+
/**
|
|
4408
|
+
* @internal
|
|
4409
|
+
*/ var TextureCubeContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
|
|
4410
|
+
_inherits(TextureCubeContentRestorer, ContentRestorer);
|
|
4411
|
+
function TextureCubeContentRestorer(resource, urls, requestConfig) {
|
|
4412
|
+
var _this;
|
|
4413
|
+
_this = ContentRestorer.call(this, resource) || this;
|
|
4414
|
+
_this.urls = urls;
|
|
4415
|
+
_this.requestConfig = requestConfig;
|
|
4416
|
+
return _this;
|
|
4417
|
+
}
|
|
4418
|
+
var _proto = TextureCubeContentRestorer.prototype;
|
|
4419
|
+
_proto.restoreContent = function restoreContent() {
|
|
4420
|
+
var _this = this;
|
|
4421
|
+
return new miniprogram.AssetPromise(function(resolve, reject) {
|
|
4422
|
+
Promise.all(_this.urls.map(function(url) {
|
|
4423
|
+
return miniprogram.request(url, _this.requestConfig);
|
|
4424
|
+
})).then(function(images) {
|
|
4425
|
+
var resource = _this.resource;
|
|
4426
|
+
for(var faceIndex = 0; faceIndex < 6; faceIndex++){
|
|
4427
|
+
resource.setImageSource(miniprogram.TextureCubeFace.PositiveX + faceIndex, images[faceIndex], 0);
|
|
4428
|
+
}
|
|
4429
|
+
resource.generateMipmaps();
|
|
4430
|
+
resolve(resource);
|
|
4431
|
+
}).catch(function(e) {
|
|
4432
|
+
reject(e);
|
|
4433
|
+
});
|
|
4434
|
+
});
|
|
4435
|
+
};
|
|
4436
|
+
return TextureCubeContentRestorer;
|
|
4437
|
+
}(miniprogram.ContentRestorer);
|
|
4438
|
+
|
|
4326
4439
|
var TextureCubeLoader = /*#__PURE__*/ function(Loader) {
|
|
4327
4440
|
_inherits(TextureCubeLoader, Loader);
|
|
4328
4441
|
function TextureCubeLoader() {
|
|
@@ -4332,23 +4445,25 @@ var TextureCubeLoader = /*#__PURE__*/ function(Loader) {
|
|
|
4332
4445
|
_proto.load = function load(item, resourceManager) {
|
|
4333
4446
|
var _this = this;
|
|
4334
4447
|
return new miniprogram.AssetPromise(function(resolve, reject) {
|
|
4335
|
-
|
|
4336
|
-
|
|
4337
|
-
|
|
4338
|
-
|
|
4448
|
+
var urls = item.urls;
|
|
4449
|
+
var requestConfig = _extends({}, item, {
|
|
4450
|
+
type: "image"
|
|
4451
|
+
});
|
|
4452
|
+
Promise.all(urls.map(function(url) {
|
|
4453
|
+
return _this.request(url, requestConfig);
|
|
4339
4454
|
})).then(function(images) {
|
|
4340
4455
|
var _images_ = images[0], width = _images_.width, height = _images_.height;
|
|
4341
4456
|
if (width !== height) {
|
|
4342
4457
|
console.error("The cube texture must have the same width and height");
|
|
4343
4458
|
return;
|
|
4344
4459
|
}
|
|
4345
|
-
var
|
|
4346
|
-
/** @ts-ignore */ if (!tex._platformTexture) return;
|
|
4460
|
+
var texture = new miniprogram.TextureCube(resourceManager.engine, width);
|
|
4347
4461
|
for(var faceIndex = 0; faceIndex < 6; faceIndex++){
|
|
4348
|
-
|
|
4462
|
+
texture.setImageSource(miniprogram.TextureCubeFace.PositiveX + faceIndex, images[faceIndex], 0);
|
|
4349
4463
|
}
|
|
4350
|
-
|
|
4351
|
-
|
|
4464
|
+
texture.generateMipmaps();
|
|
4465
|
+
resourceManager.addContentRestorer(new TextureCubeContentRestorer(texture, urls, requestConfig));
|
|
4466
|
+
resolve(texture);
|
|
4352
4467
|
}).catch(function(e) {
|
|
4353
4468
|
reject(e);
|
|
4354
4469
|
});
|
|
@@ -4362,6 +4477,30 @@ TextureCubeLoader = __decorate([
|
|
|
4362
4477
|
])
|
|
4363
4478
|
], TextureCubeLoader);
|
|
4364
4479
|
|
|
4480
|
+
var AnimationClipLoader = /*#__PURE__*/ function(Loader) {
|
|
4481
|
+
_inherits(AnimationClipLoader, Loader);
|
|
4482
|
+
function AnimationClipLoader() {
|
|
4483
|
+
return Loader.apply(this, arguments);
|
|
4484
|
+
}
|
|
4485
|
+
var _proto = AnimationClipLoader.prototype;
|
|
4486
|
+
_proto.load = function load(item, resourceManager) {
|
|
4487
|
+
var _this = this;
|
|
4488
|
+
return new miniprogram.AssetPromise(function(resolve, reject) {
|
|
4489
|
+
_this.request(item.url, _extends({}, item, {
|
|
4490
|
+
type: "arraybuffer"
|
|
4491
|
+
})).then(function(data) {
|
|
4492
|
+
return decode(data, resourceManager.engine).then(resolve);
|
|
4493
|
+
}).catch(reject);
|
|
4494
|
+
});
|
|
4495
|
+
};
|
|
4496
|
+
return AnimationClipLoader;
|
|
4497
|
+
}(miniprogram.Loader);
|
|
4498
|
+
AnimationClipLoader = __decorate([
|
|
4499
|
+
miniprogram.resourceLoader(miniprogram.AssetType.AnimationClip, [
|
|
4500
|
+
"ani"
|
|
4501
|
+
])
|
|
4502
|
+
], AnimationClipLoader);
|
|
4503
|
+
|
|
4365
4504
|
var SceneLoader = /*#__PURE__*/ function(Loader) {
|
|
4366
4505
|
_inherits(SceneLoader, Loader);
|
|
4367
4506
|
function SceneLoader() {
|
|
@@ -4378,16 +4517,32 @@ var SceneLoader = /*#__PURE__*/ function(Loader) {
|
|
|
4378
4517
|
// @ts-ignore
|
|
4379
4518
|
engine.resourceManager.initVirtualResources(data.files);
|
|
4380
4519
|
return SceneParser.parse(engine, data).then(function(scene) {
|
|
4520
|
+
var promises = [];
|
|
4381
4521
|
// parse ambient light
|
|
4382
4522
|
var ambient = data.scene.ambient;
|
|
4383
|
-
var
|
|
4384
|
-
if (ambient.
|
|
4385
|
-
|
|
4386
|
-
|
|
4387
|
-
|
|
4523
|
+
var useCustomAmbient = ambient.specularMode === "Custom";
|
|
4524
|
+
if (useCustomAmbient && ambient.customAmbientLight) {
|
|
4525
|
+
// @ts-ignore
|
|
4526
|
+
// prettier-ignore
|
|
4527
|
+
var customAmbientPromise = resourceManager.getResourceByRef(ambient.customAmbientLight).then(function(ambientLight) {
|
|
4528
|
+
scene.ambientLight = ambientLight;
|
|
4529
|
+
scene.ambientLight.diffuseIntensity = ambient.diffuseIntensity;
|
|
4530
|
+
scene.ambientLight.specularIntensity = ambient.specularIntensity;
|
|
4531
|
+
scene.ambientLight.diffuseMode = ambient.diffuseMode;
|
|
4532
|
+
scene.ambientLight.diffuseSolidColor.copyFrom(ambient.diffuseSolidColor);
|
|
4533
|
+
});
|
|
4534
|
+
promises.push(customAmbientPromise);
|
|
4535
|
+
} else if (!useCustomAmbient && ambient.ambientLight) {
|
|
4536
|
+
// @ts-ignore
|
|
4537
|
+
// prettier-ignore
|
|
4538
|
+
var ambientLightPromise = resourceManager.getResourceByRef(ambient.ambientLight).then(function(ambientLight) {
|
|
4539
|
+
scene.ambientLight = ambientLight;
|
|
4388
4540
|
scene.ambientLight.diffuseIntensity = ambient.diffuseIntensity;
|
|
4389
4541
|
scene.ambientLight.specularIntensity = ambient.specularIntensity;
|
|
4542
|
+
scene.ambientLight.diffuseMode = ambient.diffuseMode;
|
|
4543
|
+
scene.ambientLight.diffuseSolidColor.copyFrom(ambient.diffuseSolidColor);
|
|
4390
4544
|
});
|
|
4545
|
+
promises.push(ambientLightPromise);
|
|
4391
4546
|
} else {
|
|
4392
4547
|
scene.ambientLight.diffuseIntensity = ambient.diffuseIntensity;
|
|
4393
4548
|
scene.ambientLight.specularIntensity = ambient.specularIntensity;
|
|
@@ -4395,30 +4550,34 @@ var SceneLoader = /*#__PURE__*/ function(Loader) {
|
|
|
4395
4550
|
}
|
|
4396
4551
|
var background = data.scene.background;
|
|
4397
4552
|
scene.background.mode = background.mode;
|
|
4398
|
-
var backgroundPromise = Promise.resolve();
|
|
4399
4553
|
switch(scene.background.mode){
|
|
4400
4554
|
case miniprogram.BackgroundMode.SolidColor:
|
|
4401
4555
|
scene.background.solidColor.copyFrom(background.color);
|
|
4402
4556
|
break;
|
|
4403
4557
|
case miniprogram.BackgroundMode.Sky:
|
|
4404
|
-
if (background.
|
|
4558
|
+
if (background.skyMesh && background.skyMaterial) {
|
|
4405
4559
|
// @ts-ignore
|
|
4406
|
-
|
|
4407
|
-
|
|
4408
|
-
var skyMaterial = new miniprogram.SkyBoxMaterial(engine);
|
|
4409
|
-
skyMaterial.textureCubeMap = light.specularTexture;
|
|
4410
|
-
skyMaterial.textureDecodeRGBM = true;
|
|
4411
|
-
sky.material = skyMaterial;
|
|
4412
|
-
sky.mesh = miniprogram.PrimitiveMesh.createCuboid(engine, 1, 1, 1);
|
|
4560
|
+
var skyMeshPromise = resourceManager.getResourceByRef(background.skyMesh).then(function(mesh) {
|
|
4561
|
+
scene.background.sky.mesh = mesh;
|
|
4413
4562
|
});
|
|
4563
|
+
// @ts-ignore
|
|
4564
|
+
// prettier-ignore
|
|
4565
|
+
var skyMaterialPromise = resourceManager.getResourceByRef(background.skyMaterial).then(function(material) {
|
|
4566
|
+
scene.background.sky.material = material;
|
|
4567
|
+
});
|
|
4568
|
+
promises.push(skyMeshPromise, skyMaterialPromise);
|
|
4569
|
+
} else {
|
|
4570
|
+
miniprogram.Logger.warn("Sky background mode requires skyMesh and skyMaterial");
|
|
4414
4571
|
}
|
|
4415
4572
|
break;
|
|
4416
4573
|
case miniprogram.BackgroundMode.Texture:
|
|
4417
4574
|
if (background.texture) {
|
|
4418
4575
|
// @ts-ignore
|
|
4419
|
-
|
|
4576
|
+
// prettier-ignore
|
|
4577
|
+
var backgroundPromise = resourceManager.getResourceByRef(background.texture).then(function(texture) {
|
|
4420
4578
|
scene.background.texture = texture;
|
|
4421
4579
|
});
|
|
4580
|
+
promises.push(backgroundPromise);
|
|
4422
4581
|
}
|
|
4423
4582
|
break;
|
|
4424
4583
|
}
|
|
@@ -4430,10 +4589,7 @@ var SceneLoader = /*#__PURE__*/ function(Loader) {
|
|
|
4430
4589
|
if (shadow.shadowDistance != undefined) scene.shadowDistance = shadow.shadowDistance;
|
|
4431
4590
|
if (shadow.shadowCascades != undefined) scene.shadowCascades = shadow.shadowCascades;
|
|
4432
4591
|
}
|
|
4433
|
-
return Promise.all(
|
|
4434
|
-
ambientLightPromise,
|
|
4435
|
-
backgroundPromise
|
|
4436
|
-
]).then(function() {
|
|
4592
|
+
return Promise.all(promises).then(function() {
|
|
4437
4593
|
resolve(scene);
|
|
4438
4594
|
});
|
|
4439
4595
|
});
|
|
@@ -4462,10 +4618,410 @@ ReflectionParser.registerCustomParseComponent("TextRenderer", /*#__PURE__*/ _asy
|
|
|
4462
4618
|
});
|
|
4463
4619
|
}));
|
|
4464
4620
|
|
|
4621
|
+
var _KHR_draco_mesh_compression;
|
|
4622
|
+
var KHR_draco_mesh_compression = (_KHR_draco_mesh_compression = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
4623
|
+
_inherits(KHR_draco_mesh_compression1, GLTFExtensionParser);
|
|
4624
|
+
function KHR_draco_mesh_compression1() {
|
|
4625
|
+
return GLTFExtensionParser.apply(this, arguments);
|
|
4626
|
+
}
|
|
4627
|
+
var _proto = KHR_draco_mesh_compression1.prototype;
|
|
4628
|
+
_proto.initialize = function initialize() {
|
|
4629
|
+
if (!KHR_draco_mesh_compression._decoder) {
|
|
4630
|
+
KHR_draco_mesh_compression._decoder = new miniprogram$3.DRACODecoder();
|
|
4631
|
+
}
|
|
4632
|
+
};
|
|
4633
|
+
_proto.createAndParse = function createAndParse(context, schema, glTFPrimitive, glTFMesh) {
|
|
4634
|
+
var _this = this;
|
|
4635
|
+
var glTF = context.glTF, engine = context.glTFResource.engine;
|
|
4636
|
+
var bufferViews = glTF.bufferViews, accessors = glTF.accessors;
|
|
4637
|
+
var bufferViewIndex = schema.bufferView, gltfAttributeMap = schema.attributes;
|
|
4638
|
+
var attributeMap = {};
|
|
4639
|
+
var attributeTypeMap = {};
|
|
4640
|
+
for(var attributeName in gltfAttributeMap){
|
|
4641
|
+
attributeMap[attributeName] = gltfAttributeMap[attributeName];
|
|
4642
|
+
}
|
|
4643
|
+
for(var attributeName1 in glTFPrimitive.attributes){
|
|
4644
|
+
if (gltfAttributeMap[attributeName1] !== undefined) {
|
|
4645
|
+
var accessorDef = accessors[glTFPrimitive.attributes[attributeName1]];
|
|
4646
|
+
attributeTypeMap[attributeName1] = GLTFUtils.getComponentType(accessorDef.componentType).name;
|
|
4647
|
+
}
|
|
4648
|
+
}
|
|
4649
|
+
var indexAccessor = accessors[glTFPrimitive.indices];
|
|
4650
|
+
var indexType = GLTFUtils.getComponentType(indexAccessor.componentType).name;
|
|
4651
|
+
var taskConfig = {
|
|
4652
|
+
attributeIDs: attributeMap,
|
|
4653
|
+
attributeTypes: attributeTypeMap,
|
|
4654
|
+
useUniqueIDs: true,
|
|
4655
|
+
indexType: indexType
|
|
4656
|
+
};
|
|
4657
|
+
return context.getBuffers().then(function(buffers) {
|
|
4658
|
+
var buffer = GLTFUtils.getBufferViewData(bufferViews[bufferViewIndex], buffers);
|
|
4659
|
+
return KHR_draco_mesh_compression._decoder.decode(buffer, taskConfig).then(function(decodedGeometry) {
|
|
4660
|
+
var mesh = new miniprogram.ModelMesh(engine, glTFMesh.name);
|
|
4661
|
+
return _this._parseMeshFromGLTFPrimitiveDraco(mesh, glTFMesh, glTFPrimitive, glTF, function(attributeSemantic) {
|
|
4662
|
+
for(var j = 0; j < decodedGeometry.attributes.length; j++){
|
|
4663
|
+
if (decodedGeometry.attributes[j].name === attributeSemantic) {
|
|
4664
|
+
return decodedGeometry.attributes[j].array;
|
|
4665
|
+
}
|
|
4666
|
+
}
|
|
4667
|
+
return null;
|
|
4668
|
+
}, function(attributeSemantic, shapeIndex) {
|
|
4669
|
+
throw "BlendShape animation is not supported when using draco.";
|
|
4670
|
+
}, function() {
|
|
4671
|
+
return decodedGeometry.index.array;
|
|
4672
|
+
}, context.keepMeshData);
|
|
4673
|
+
});
|
|
4674
|
+
});
|
|
4675
|
+
};
|
|
4676
|
+
_proto._parseMeshFromGLTFPrimitiveDraco = function _parseMeshFromGLTFPrimitiveDraco(mesh, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
|
|
4677
|
+
var attributes = gltfPrimitive.attributes, targets = gltfPrimitive.targets, indices = gltfPrimitive.indices, mode = gltfPrimitive.mode;
|
|
4678
|
+
var vertexCount;
|
|
4679
|
+
var accessors = gltf.accessors;
|
|
4680
|
+
var accessor = accessors[attributes["POSITION"]];
|
|
4681
|
+
var positionBuffer = getVertexBufferData("POSITION");
|
|
4682
|
+
var positions = GLTFUtils.floatBufferToVector3Array(positionBuffer);
|
|
4683
|
+
mesh.setPositions(positions);
|
|
4684
|
+
var bounds = mesh.bounds;
|
|
4685
|
+
vertexCount = accessor.count;
|
|
4686
|
+
if (accessor.min && accessor.max) {
|
|
4687
|
+
bounds.min.copyFromArray(accessor.min);
|
|
4688
|
+
bounds.max.copyFromArray(accessor.max);
|
|
4689
|
+
} else {
|
|
4690
|
+
var position = KHR_draco_mesh_compression._tempVector3;
|
|
4691
|
+
var min = bounds.min, max = bounds.max;
|
|
4692
|
+
min.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
|
|
4693
|
+
max.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
|
|
4694
|
+
var stride = positionBuffer.length / vertexCount;
|
|
4695
|
+
for(var j = 0; j < vertexCount; j++){
|
|
4696
|
+
var offset = j * stride;
|
|
4697
|
+
position.copyFromArray(positionBuffer, offset);
|
|
4698
|
+
miniprogram$1.Vector3.min(min, position, min);
|
|
4699
|
+
miniprogram$1.Vector3.max(max, position, max);
|
|
4700
|
+
}
|
|
4701
|
+
}
|
|
4702
|
+
for(var attributeSemantic in attributes){
|
|
4703
|
+
if (attributeSemantic === "POSITION") {
|
|
4704
|
+
continue;
|
|
4705
|
+
}
|
|
4706
|
+
var bufferData = getVertexBufferData(attributeSemantic);
|
|
4707
|
+
switch(attributeSemantic){
|
|
4708
|
+
case "NORMAL":
|
|
4709
|
+
var normals = GLTFUtils.floatBufferToVector3Array(bufferData);
|
|
4710
|
+
mesh.setNormals(normals);
|
|
4711
|
+
break;
|
|
4712
|
+
case "TEXCOORD_0":
|
|
4713
|
+
var texturecoords = GLTFUtils.floatBufferToVector2Array(bufferData);
|
|
4714
|
+
mesh.setUVs(texturecoords, 0);
|
|
4715
|
+
break;
|
|
4716
|
+
case "TEXCOORD_1":
|
|
4717
|
+
var texturecoords1 = GLTFUtils.floatBufferToVector2Array(bufferData);
|
|
4718
|
+
mesh.setUVs(texturecoords1, 1);
|
|
4719
|
+
break;
|
|
4720
|
+
case "TEXCOORD_2":
|
|
4721
|
+
var texturecoords2 = GLTFUtils.floatBufferToVector2Array(bufferData);
|
|
4722
|
+
mesh.setUVs(texturecoords2, 2);
|
|
4723
|
+
break;
|
|
4724
|
+
case "TEXCOORD_3":
|
|
4725
|
+
var texturecoords3 = GLTFUtils.floatBufferToVector2Array(bufferData);
|
|
4726
|
+
mesh.setUVs(texturecoords3, 3);
|
|
4727
|
+
break;
|
|
4728
|
+
case "TEXCOORD_4":
|
|
4729
|
+
var texturecoords4 = GLTFUtils.floatBufferToVector2Array(bufferData);
|
|
4730
|
+
mesh.setUVs(texturecoords4, 4);
|
|
4731
|
+
break;
|
|
4732
|
+
case "TEXCOORD_5":
|
|
4733
|
+
var texturecoords5 = GLTFUtils.floatBufferToVector2Array(bufferData);
|
|
4734
|
+
mesh.setUVs(texturecoords5, 5);
|
|
4735
|
+
break;
|
|
4736
|
+
case "TEXCOORD_6":
|
|
4737
|
+
var texturecoords6 = GLTFUtils.floatBufferToVector2Array(bufferData);
|
|
4738
|
+
mesh.setUVs(texturecoords6, 6);
|
|
4739
|
+
break;
|
|
4740
|
+
case "TEXCOORD_7":
|
|
4741
|
+
var texturecoords7 = GLTFUtils.floatBufferToVector2Array(bufferData);
|
|
4742
|
+
mesh.setUVs(texturecoords7, 7);
|
|
4743
|
+
break;
|
|
4744
|
+
case "COLOR_0":
|
|
4745
|
+
var colors = GLTFUtils.floatBufferToColorArray(bufferData, accessors[attributes["COLOR_0"]].type === AccessorType.VEC3);
|
|
4746
|
+
mesh.setColors(colors);
|
|
4747
|
+
break;
|
|
4748
|
+
case "TANGENT":
|
|
4749
|
+
var tangents = GLTFUtils.floatBufferToVector4Array(bufferData);
|
|
4750
|
+
mesh.setTangents(tangents);
|
|
4751
|
+
break;
|
|
4752
|
+
case "JOINTS_0":
|
|
4753
|
+
var joints = GLTFUtils.floatBufferToVector4Array(bufferData);
|
|
4754
|
+
mesh.setBoneIndices(joints);
|
|
4755
|
+
break;
|
|
4756
|
+
case "WEIGHTS_0":
|
|
4757
|
+
var weights = GLTFUtils.floatBufferToVector4Array(bufferData);
|
|
4758
|
+
mesh.setBoneWeights(weights);
|
|
4759
|
+
break;
|
|
4760
|
+
}
|
|
4761
|
+
}
|
|
4762
|
+
// Indices
|
|
4763
|
+
if (indices !== undefined) {
|
|
4764
|
+
var indexAccessor = gltf.accessors[indices];
|
|
4765
|
+
var indexData = getIndexBufferData();
|
|
4766
|
+
mesh.setIndices(indexData);
|
|
4767
|
+
mesh.addSubMesh(0, indexAccessor.count, mode);
|
|
4768
|
+
} else {
|
|
4769
|
+
mesh.addSubMesh(0, vertexCount, mode);
|
|
4770
|
+
}
|
|
4771
|
+
// BlendShapes
|
|
4772
|
+
targets && GLTFMeshParser._createBlendShape(mesh, null, gltfMesh, accessors, targets, getBlendShapeData);
|
|
4773
|
+
mesh.uploadData(!keepMeshData);
|
|
4774
|
+
return Promise.resolve(mesh);
|
|
4775
|
+
};
|
|
4776
|
+
return KHR_draco_mesh_compression1;
|
|
4777
|
+
}(GLTFExtensionParser), function() {
|
|
4778
|
+
_KHR_draco_mesh_compression._tempVector3 = new miniprogram$1.Vector3();
|
|
4779
|
+
}(), _KHR_draco_mesh_compression);
|
|
4780
|
+
KHR_draco_mesh_compression = __decorate([
|
|
4781
|
+
registerGLTFExtension("KHR_draco_mesh_compression", exports.GLTFExtensionMode.CreateAndParse)
|
|
4782
|
+
], KHR_draco_mesh_compression);
|
|
4783
|
+
|
|
4784
|
+
var KHR_lights_punctual = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
4785
|
+
_inherits(KHR_lights_punctual, GLTFExtensionParser);
|
|
4786
|
+
function KHR_lights_punctual() {
|
|
4787
|
+
return GLTFExtensionParser.apply(this, arguments);
|
|
4788
|
+
}
|
|
4789
|
+
var _proto = KHR_lights_punctual.prototype;
|
|
4790
|
+
_proto.additiveParse = function additiveParse(context, entity, extensionSchema) {
|
|
4791
|
+
var lightsSchema = context.glTF.extensions.KHR_lights_punctual.lights;
|
|
4792
|
+
var lightSchema = lightsSchema[extensionSchema.light];
|
|
4793
|
+
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;
|
|
4794
|
+
var glTFResource = context.glTFResource;
|
|
4795
|
+
var light;
|
|
4796
|
+
if (type === "directional") {
|
|
4797
|
+
light = entity.addComponent(miniprogram.DirectLight);
|
|
4798
|
+
} else if (type === "point") {
|
|
4799
|
+
light = entity.addComponent(miniprogram.PointLight);
|
|
4800
|
+
} else if (type === "spot") {
|
|
4801
|
+
light = entity.addComponent(miniprogram.SpotLight);
|
|
4802
|
+
}
|
|
4803
|
+
if (color) {
|
|
4804
|
+
light.color.set(color[0], color[1], color[2], 1);
|
|
4805
|
+
}
|
|
4806
|
+
light.intensity = intensity;
|
|
4807
|
+
if (range && !_instanceof(light, miniprogram.DirectLight)) {
|
|
4808
|
+
light.distance = range;
|
|
4809
|
+
}
|
|
4810
|
+
if (spot && _instanceof(light, miniprogram.SpotLight)) {
|
|
4811
|
+
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;
|
|
4812
|
+
light.angle = innerConeAngle;
|
|
4813
|
+
light.penumbra = outerConeAngle - innerConeAngle;
|
|
4814
|
+
}
|
|
4815
|
+
if (!glTFResource.lights) glTFResource.lights = [];
|
|
4816
|
+
glTFResource.lights.push(light);
|
|
4817
|
+
};
|
|
4818
|
+
return KHR_lights_punctual;
|
|
4819
|
+
}(GLTFExtensionParser);
|
|
4820
|
+
KHR_lights_punctual = __decorate([
|
|
4821
|
+
registerGLTFExtension("KHR_lights_punctual", exports.GLTFExtensionMode.AdditiveParse)
|
|
4822
|
+
], KHR_lights_punctual);
|
|
4823
|
+
|
|
4824
|
+
var KHR_materials_clearcoat = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
4825
|
+
_inherits(KHR_materials_clearcoat, GLTFExtensionParser);
|
|
4826
|
+
function KHR_materials_clearcoat() {
|
|
4827
|
+
return GLTFExtensionParser.apply(this, arguments);
|
|
4828
|
+
}
|
|
4829
|
+
var _proto = KHR_materials_clearcoat.prototype;
|
|
4830
|
+
_proto.additiveParse = function additiveParse(context, material, schema) {
|
|
4831
|
+
var textures = context.glTFResource.textures;
|
|
4832
|
+
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;
|
|
4833
|
+
material.clearCoat = clearcoatFactor;
|
|
4834
|
+
material.clearCoatRoughness = clearcoatRoughnessFactor;
|
|
4835
|
+
if (clearcoatTexture) {
|
|
4836
|
+
material.clearCoatTexture = textures[clearcoatTexture.index];
|
|
4837
|
+
GLTFMaterialParser._checkOtherTextureTransform(clearcoatTexture, "Clear coat");
|
|
4838
|
+
}
|
|
4839
|
+
if (clearcoatRoughnessTexture) {
|
|
4840
|
+
material.clearCoatRoughnessTexture = textures[clearcoatRoughnessTexture.index];
|
|
4841
|
+
GLTFMaterialParser._checkOtherTextureTransform(clearcoatRoughnessTexture, "Clear coat roughness");
|
|
4842
|
+
}
|
|
4843
|
+
if (clearcoatNormalTexture) {
|
|
4844
|
+
material.clearCoatNormalTexture = textures[clearcoatNormalTexture.index];
|
|
4845
|
+
GLTFMaterialParser._checkOtherTextureTransform(clearcoatNormalTexture, "Clear coat normal");
|
|
4846
|
+
}
|
|
4847
|
+
};
|
|
4848
|
+
return KHR_materials_clearcoat;
|
|
4849
|
+
}(GLTFExtensionParser);
|
|
4850
|
+
KHR_materials_clearcoat = __decorate([
|
|
4851
|
+
registerGLTFExtension("KHR_materials_clearcoat", exports.GLTFExtensionMode.AdditiveParse)
|
|
4852
|
+
], KHR_materials_clearcoat);
|
|
4853
|
+
|
|
4854
|
+
var KHR_materials_ior = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
4855
|
+
_inherits(KHR_materials_ior, GLTFExtensionParser);
|
|
4856
|
+
function KHR_materials_ior() {
|
|
4857
|
+
return GLTFExtensionParser.apply(this, arguments);
|
|
4858
|
+
}
|
|
4859
|
+
var _proto = KHR_materials_ior.prototype;
|
|
4860
|
+
_proto.additiveParse = function additiveParse(context, material, schema) {
|
|
4861
|
+
var _schema_ior = schema.ior, ior = _schema_ior === void 0 ? 1.5 : _schema_ior;
|
|
4862
|
+
material.ior = ior;
|
|
4863
|
+
};
|
|
4864
|
+
return KHR_materials_ior;
|
|
4865
|
+
}(GLTFExtensionParser);
|
|
4866
|
+
KHR_materials_ior = __decorate([
|
|
4867
|
+
registerGLTFExtension("KHR_materials_ior", exports.GLTFExtensionMode.AdditiveParse)
|
|
4868
|
+
], KHR_materials_ior);
|
|
4869
|
+
|
|
4870
|
+
var KHR_materials_pbrSpecularGlossiness = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
4871
|
+
_inherits(KHR_materials_pbrSpecularGlossiness, GLTFExtensionParser);
|
|
4872
|
+
function KHR_materials_pbrSpecularGlossiness() {
|
|
4873
|
+
return GLTFExtensionParser.apply(this, arguments);
|
|
4874
|
+
}
|
|
4875
|
+
var _proto = KHR_materials_pbrSpecularGlossiness.prototype;
|
|
4876
|
+
_proto.createAndParse = function createAndParse(context, schema, ownerSchema) {
|
|
4877
|
+
var _context_glTFResource = context.glTFResource, engine = _context_glTFResource.engine, textures = _context_glTFResource.textures;
|
|
4878
|
+
var material = new miniprogram.PBRSpecularMaterial(engine);
|
|
4879
|
+
var diffuseFactor = schema.diffuseFactor, diffuseTexture = schema.diffuseTexture, specularFactor = schema.specularFactor, glossinessFactor = schema.glossinessFactor, specularGlossinessTexture = schema.specularGlossinessTexture;
|
|
4880
|
+
if (diffuseFactor) {
|
|
4881
|
+
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]);
|
|
4882
|
+
}
|
|
4883
|
+
if (diffuseTexture) {
|
|
4884
|
+
material.baseTexture = textures[diffuseTexture.index];
|
|
4885
|
+
GLTFParser.executeExtensionsAdditiveAndParse(diffuseTexture.extensions, context, material, diffuseTexture);
|
|
4886
|
+
}
|
|
4887
|
+
if (specularFactor) {
|
|
4888
|
+
material.specularColor = new miniprogram$1.Color(miniprogram$1.Color.linearToGammaSpace(specularFactor[0]), miniprogram$1.Color.linearToGammaSpace(specularFactor[1]), miniprogram$1.Color.linearToGammaSpace(specularFactor[2]));
|
|
4889
|
+
}
|
|
4890
|
+
if (glossinessFactor !== undefined) {
|
|
4891
|
+
material.glossiness = glossinessFactor;
|
|
4892
|
+
}
|
|
4893
|
+
if (specularGlossinessTexture) {
|
|
4894
|
+
material.specularGlossinessTexture = textures[specularGlossinessTexture.index];
|
|
4895
|
+
GLTFMaterialParser._checkOtherTextureTransform(specularGlossinessTexture, "Specular glossiness");
|
|
4896
|
+
}
|
|
4897
|
+
material.name = ownerSchema.name;
|
|
4898
|
+
GLTFMaterialParser._parseStandardProperty(context, material, ownerSchema);
|
|
4899
|
+
return material;
|
|
4900
|
+
};
|
|
4901
|
+
return KHR_materials_pbrSpecularGlossiness;
|
|
4902
|
+
}(GLTFExtensionParser);
|
|
4903
|
+
KHR_materials_pbrSpecularGlossiness = __decorate([
|
|
4904
|
+
registerGLTFExtension("KHR_materials_pbrSpecularGlossiness", exports.GLTFExtensionMode.CreateAndParse)
|
|
4905
|
+
], KHR_materials_pbrSpecularGlossiness);
|
|
4906
|
+
|
|
4907
|
+
var KHR_materials_unlit = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
4908
|
+
_inherits(KHR_materials_unlit, GLTFExtensionParser);
|
|
4909
|
+
function KHR_materials_unlit() {
|
|
4910
|
+
return GLTFExtensionParser.apply(this, arguments);
|
|
4911
|
+
}
|
|
4912
|
+
var _proto = KHR_materials_unlit.prototype;
|
|
4913
|
+
_proto.createAndParse = function createAndParse(context, _, ownerSchema) {
|
|
4914
|
+
var engine = context.glTFResource.engine;
|
|
4915
|
+
var material = new miniprogram.UnlitMaterial(engine);
|
|
4916
|
+
material.name = ownerSchema.name;
|
|
4917
|
+
GLTFMaterialParser._parseStandardProperty(context, material, ownerSchema);
|
|
4918
|
+
return material;
|
|
4919
|
+
};
|
|
4920
|
+
return KHR_materials_unlit;
|
|
4921
|
+
}(GLTFExtensionParser);
|
|
4922
|
+
KHR_materials_unlit = __decorate([
|
|
4923
|
+
registerGLTFExtension("KHR_materials_unlit", exports.GLTFExtensionMode.CreateAndParse)
|
|
4924
|
+
], KHR_materials_unlit);
|
|
4925
|
+
|
|
4926
|
+
var KHR_mesh_quantization = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
4927
|
+
_inherits(KHR_mesh_quantization, GLTFExtensionParser);
|
|
4928
|
+
function KHR_mesh_quantization() {
|
|
4929
|
+
return GLTFExtensionParser.apply(this, arguments);
|
|
4930
|
+
}
|
|
4931
|
+
return KHR_mesh_quantization;
|
|
4932
|
+
}(GLTFExtensionParser);
|
|
4933
|
+
KHR_mesh_quantization = __decorate([
|
|
4934
|
+
registerGLTFExtension("KHR_mesh_quantization", exports.GLTFExtensionMode.AdditiveParse)
|
|
4935
|
+
], KHR_mesh_quantization);
|
|
4936
|
+
|
|
4937
|
+
var KHR_texture_transform = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
4938
|
+
_inherits(KHR_texture_transform, GLTFExtensionParser);
|
|
4939
|
+
function KHR_texture_transform() {
|
|
4940
|
+
return GLTFExtensionParser.apply(this, arguments);
|
|
4941
|
+
}
|
|
4942
|
+
var _proto = KHR_texture_transform.prototype;
|
|
4943
|
+
_proto.additiveParse = function additiveParse(context, material, schema) {
|
|
4944
|
+
var offset = schema.offset, rotation = schema.rotation, scale = schema.scale, texCoord = schema.texCoord;
|
|
4945
|
+
if (offset) {
|
|
4946
|
+
material.tilingOffset.z = offset[0];
|
|
4947
|
+
material.tilingOffset.w = offset[1];
|
|
4948
|
+
}
|
|
4949
|
+
if (scale) {
|
|
4950
|
+
material.tilingOffset.x = scale[0];
|
|
4951
|
+
material.tilingOffset.y = scale[1];
|
|
4952
|
+
}
|
|
4953
|
+
if (rotation) {
|
|
4954
|
+
miniprogram.Logger.warn("rotation in KHR_texture_transform is not supported now");
|
|
4955
|
+
}
|
|
4956
|
+
if (texCoord) {
|
|
4957
|
+
miniprogram.Logger.warn("texCoord in KHR_texture_transform is not supported now");
|
|
4958
|
+
}
|
|
4959
|
+
};
|
|
4960
|
+
return KHR_texture_transform;
|
|
4961
|
+
}(GLTFExtensionParser);
|
|
4962
|
+
KHR_texture_transform = __decorate([
|
|
4963
|
+
registerGLTFExtension("KHR_texture_transform", exports.GLTFExtensionMode.AdditiveParse)
|
|
4964
|
+
], KHR_texture_transform);
|
|
4965
|
+
|
|
4966
|
+
var GALACEAN_materials_remap = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
4967
|
+
_inherits(GALACEAN_materials_remap, GLTFExtensionParser);
|
|
4968
|
+
function GALACEAN_materials_remap() {
|
|
4969
|
+
return GLTFExtensionParser.apply(this, arguments);
|
|
4970
|
+
}
|
|
4971
|
+
var _proto = GALACEAN_materials_remap.prototype;
|
|
4972
|
+
_proto.createAndParse = function createAndParse(context, schema) {
|
|
4973
|
+
var engine = context.glTFResource.engine;
|
|
4974
|
+
// @ts-ignore
|
|
4975
|
+
return engine.resourceManager.getResourceByRef(schema);
|
|
4976
|
+
};
|
|
4977
|
+
return GALACEAN_materials_remap;
|
|
4978
|
+
}(GLTFExtensionParser);
|
|
4979
|
+
GALACEAN_materials_remap = __decorate([
|
|
4980
|
+
registerGLTFExtension("GALACEAN_materials_remap", exports.GLTFExtensionMode.CreateAndParse)
|
|
4981
|
+
], GALACEAN_materials_remap);
|
|
4982
|
+
|
|
4983
|
+
var GALACEAN_animation_event = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
4984
|
+
_inherits(GALACEAN_animation_event, GLTFExtensionParser);
|
|
4985
|
+
function GALACEAN_animation_event() {
|
|
4986
|
+
return GLTFExtensionParser.apply(this, arguments);
|
|
4987
|
+
}
|
|
4988
|
+
var _proto = GALACEAN_animation_event.prototype;
|
|
4989
|
+
_proto.additiveParse = function additiveParse(context, animationClip, schema) {
|
|
4990
|
+
context.glTFResource.engine;
|
|
4991
|
+
var events = schema.events;
|
|
4992
|
+
events.map(function(eventData) {
|
|
4993
|
+
var event = new miniprogram.AnimationEvent();
|
|
4994
|
+
event.functionName = eventData.functionName;
|
|
4995
|
+
event.time = eventData.time;
|
|
4996
|
+
event.parameter = eventData.parameter;
|
|
4997
|
+
animationClip.addEvent(event);
|
|
4998
|
+
});
|
|
4999
|
+
};
|
|
5000
|
+
return GALACEAN_animation_event;
|
|
5001
|
+
}(GLTFExtensionParser);
|
|
5002
|
+
GALACEAN_animation_event = __decorate([
|
|
5003
|
+
registerGLTFExtension("GALACEAN_animation_event", exports.GLTFExtensionMode.AdditiveParse)
|
|
5004
|
+
], GALACEAN_animation_event);
|
|
5005
|
+
|
|
4465
5006
|
exports.ComponentMap = ComponentMap;
|
|
5007
|
+
exports.GLTFAnimationParser = GLTFAnimationParser;
|
|
5008
|
+
exports.GLTFBufferParser = GLTFBufferParser;
|
|
5009
|
+
exports.GLTFEntityParser = GLTFEntityParser;
|
|
5010
|
+
exports.GLTFExtensionParser = GLTFExtensionParser;
|
|
5011
|
+
exports.GLTFMaterialParser = GLTFMaterialParser;
|
|
5012
|
+
exports.GLTFMeshParser = GLTFMeshParser;
|
|
5013
|
+
exports.GLTFParser = GLTFParser;
|
|
5014
|
+
exports.GLTFParserContext = GLTFParserContext;
|
|
5015
|
+
exports.GLTFPipeline = GLTFPipeline;
|
|
4466
5016
|
exports.GLTFResource = GLTFResource;
|
|
5017
|
+
exports.GLTFSceneParser = GLTFSceneParser;
|
|
5018
|
+
exports.GLTFSkinParser = GLTFSkinParser;
|
|
5019
|
+
exports.GLTFTextureParser = GLTFTextureParser;
|
|
5020
|
+
exports.GLTFUtils = GLTFUtils;
|
|
5021
|
+
exports.GLTFValidator = GLTFValidator;
|
|
4467
5022
|
exports.PrefabParser = PrefabParser;
|
|
4468
5023
|
exports.ReflectionParser = ReflectionParser;
|
|
4469
5024
|
exports.SceneParser = SceneParser;
|
|
4470
5025
|
exports.decode = decode;
|
|
4471
5026
|
exports.parseSingleKTX = parseSingleKTX;
|
|
5027
|
+
exports.registerGLTFExtension = registerGLTFExtension;
|