@galacean/engine-loader 0.9.0 → 1.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.js +1449 -1050
- package/dist/main.js.map +1 -1
- package/dist/miniprogram.js +1470 -1071
- package/dist/module.js +1436 -1052
- package/dist/module.js.map +1 -1
- package/package.json +5 -5
- package/types/AnimationClipLoader.d.ts +1 -0
- package/types/GLTFContentRestorer.d.ts +85 -0
- package/types/GLTFLoader.d.ts +6 -0
- package/types/Texture2DContentRestorer.d.ts +14 -0
- package/types/TextureCubeContentRestorer.d.ts +14 -0
- package/types/gltf/GLTFPipeline.d.ts +23 -0
- package/types/gltf/GLTFResource.d.ts +7 -11
- package/types/gltf/{Schema.d.ts → GLTFSchema.d.ts} +2 -0
- package/types/gltf/{GLTFUtil.d.ts → GLTFUtils.d.ts} +9 -15
- package/types/gltf/extensions/GALACEAN_animation_event.d.ts +1 -0
- package/types/gltf/extensions/GLTFExtensionParser.d.ts +52 -0
- package/types/gltf/extensions/{Schema.d.ts → GLTFExtensionSchema.d.ts} +9 -2
- package/types/gltf/extensions/KHR_materials_variants.d.ts +6 -1
- package/types/gltf/extensions/index.d.ts +4 -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/{ParserContext.d.ts → GLTFParserContext.d.ts} +6 -4
- package/types/gltf/parser/GLTFSceneParser.d.ts +11 -0
- package/types/gltf/parser/GLTFSkinParser.d.ts +6 -0
- package/types/gltf/parser/GLTFTextureParser.d.ts +8 -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/resource-deserialize/resources/prefab/PrefabDesign.d.ts +4 -4
- package/types/gltf/GLTFParser.d.ts +0 -9
- package/types/gltf/extensions/ExtensionParser.d.ts +0 -8
- package/types/gltf/parser/AnimationParser.d.ts +0 -7
- package/types/gltf/parser/BufferParser.d.ts +0 -7
- package/types/gltf/parser/EntityParser.d.ts +0 -9
- package/types/gltf/parser/MaterialParser.d.ts +0 -8
- package/types/gltf/parser/MeshParser.d.ts +0 -13
- package/types/gltf/parser/Parser.d.ts +0 -21
- package/types/gltf/parser/SceneParser.d.ts +0 -11
- package/types/gltf/parser/SkinParser.d.ts +0 -6
- package/types/gltf/parser/TextureParser.d.ts +0 -8
- package/types/gltf/parser/Validator.d.ts +0 -5
package/dist/main.js
CHANGED
|
@@ -4,8 +4,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var engineCore = require('@galacean/engine-core');
|
|
6
6
|
var engineMath = require('@galacean/engine-math');
|
|
7
|
-
var engineDraco = require('@galacean/engine-draco');
|
|
8
7
|
var engineRhiWebgl = require('@galacean/engine-rhi-webgl');
|
|
8
|
+
var engineDraco = require('@galacean/engine-draco');
|
|
9
9
|
|
|
10
10
|
function _extends() {
|
|
11
11
|
_extends = Object.assign || function assign(target) {
|
|
@@ -90,10 +90,10 @@ function __generator(thisArg, body) {
|
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
var AnimatorControllerLoader = /*#__PURE__*/ function(
|
|
94
|
-
_inherits(AnimatorControllerLoader,
|
|
93
|
+
var AnimatorControllerLoader = /*#__PURE__*/ function(Loader1) {
|
|
94
|
+
_inherits(AnimatorControllerLoader, Loader1);
|
|
95
95
|
function AnimatorControllerLoader() {
|
|
96
|
-
return
|
|
96
|
+
return Loader1.apply(this, arguments);
|
|
97
97
|
}
|
|
98
98
|
var _proto = AnimatorControllerLoader.prototype;
|
|
99
99
|
_proto.load = function load(item, resourceManager) {
|
|
@@ -114,13 +114,16 @@ var AnimatorControllerLoader = /*#__PURE__*/ function(Loader) {
|
|
|
114
114
|
var states = stateMachineData.states;
|
|
115
115
|
var stateMachine = layer.stateMachine = new engineCore.AnimatorStateMachine();
|
|
116
116
|
states.forEach(function(stateData, stateIndex) {
|
|
117
|
-
var name = stateData.name, speed = stateData.speed, wrapMode = stateData.wrapMode, clipStartNormalizedTime = stateData.clipStartNormalizedTime, clipEndNormalizedTime = stateData.clipEndNormalizedTime, isDefaultState = stateData.isDefaultState, clipData = stateData.clip;
|
|
117
|
+
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;
|
|
118
118
|
var state = stateMachine.addState(name);
|
|
119
119
|
isDefaultState && (stateMachine.defaultState = state);
|
|
120
120
|
state.speed = speed;
|
|
121
121
|
state.wrapMode = wrapMode;
|
|
122
122
|
state.clipStartTime = clipStartNormalizedTime;
|
|
123
123
|
state.clipEndTime = clipEndNormalizedTime;
|
|
124
|
+
scripts == null ? void 0 : scripts.forEach(function(script) {
|
|
125
|
+
state.addStateMachineScript(engineCore.Loader.getClass(script));
|
|
126
|
+
});
|
|
124
127
|
if (clipData) {
|
|
125
128
|
promises.push(new Promise(function(resolve) {
|
|
126
129
|
//@ts-ignore
|
|
@@ -341,52 +344,196 @@ FontLoader = __decorate([
|
|
|
341
344
|
], false)
|
|
342
345
|
], FontLoader);
|
|
343
346
|
|
|
347
|
+
function _array_like_to_array(arr, len) {
|
|
348
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
349
|
+
|
|
350
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
351
|
+
|
|
352
|
+
return arr2;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
356
|
+
if (!o) return;
|
|
357
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
358
|
+
|
|
359
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
360
|
+
|
|
361
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
362
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
363
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
|
|
367
|
+
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
368
|
+
|
|
369
|
+
if (it) return (it = it.call(o)).next.bind(it);
|
|
370
|
+
// Fallback for engines without symbol support
|
|
371
|
+
if (Array.isArray(o) || (it = _unsupported_iterable_to_array(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
372
|
+
if (it) o = it;
|
|
373
|
+
|
|
374
|
+
var i = 0;
|
|
375
|
+
|
|
376
|
+
return function() {
|
|
377
|
+
if (i >= o.length) return { done: true };
|
|
378
|
+
|
|
379
|
+
return { done: false, value: o[i++] };
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
384
|
+
}
|
|
385
|
+
|
|
344
386
|
/**
|
|
345
387
|
* @internal
|
|
346
|
-
*/ var
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
this.masterPromiseInfo = new PromiseInfo();
|
|
357
|
-
this.promiseMap = {};
|
|
358
|
-
var promiseMap = this.promiseMap;
|
|
359
|
-
promiseMap["" + url + "?q=textures"] = this._initPromiseInfo(this.texturesPromiseInfo);
|
|
360
|
-
promiseMap["" + url + "?q=materials"] = this._initPromiseInfo(this.materialsPromiseInfo);
|
|
361
|
-
promiseMap["" + url + "?q=meshes"] = this._initPromiseInfo(this.meshesPromiseInfo);
|
|
362
|
-
promiseMap["" + url + "?q=animations"] = this._initPromiseInfo(this.animationClipsPromiseInfo);
|
|
363
|
-
promiseMap["" + url + "?q=defaultSceneRoot"] = this._initPromiseInfo(this.defaultSceneRootPromiseInfo);
|
|
364
|
-
promiseMap["" + url] = this._initPromiseInfo(this.masterPromiseInfo);
|
|
388
|
+
*/ var GLTFContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
|
|
389
|
+
_inherits(GLTFContentRestorer, ContentRestorer);
|
|
390
|
+
function GLTFContentRestorer() {
|
|
391
|
+
var _this;
|
|
392
|
+
_this = ContentRestorer.apply(this, arguments) || this;
|
|
393
|
+
_this.bufferRequests = [];
|
|
394
|
+
_this.glbBufferSlices = [];
|
|
395
|
+
_this.bufferTextures = [];
|
|
396
|
+
_this.meshes = [];
|
|
397
|
+
return _this;
|
|
365
398
|
}
|
|
366
|
-
var _proto =
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
399
|
+
var _proto = GLTFContentRestorer.prototype;
|
|
400
|
+
/**
|
|
401
|
+
* @override
|
|
402
|
+
*/ _proto.restoreContent = function restoreContent() {
|
|
403
|
+
var _this = this;
|
|
404
|
+
return new engineCore.AssetPromise(function(resolve, reject) {
|
|
405
|
+
Promise.all(_this.bufferRequests.map(function(bufferRequestInfo) {
|
|
406
|
+
return engineCore.request(bufferRequestInfo.url, bufferRequestInfo.config);
|
|
407
|
+
})).then(function(buffers) {
|
|
408
|
+
// Buffer parse
|
|
409
|
+
if (_this.isGLB) {
|
|
410
|
+
var glbBufferSlice = _this.glbBufferSlices;
|
|
411
|
+
var bigBuffer = buffers[0];
|
|
412
|
+
var bufferCount = glbBufferSlice.length;
|
|
413
|
+
buffers.length = bufferCount;
|
|
414
|
+
for(var i = 0; i < bufferCount; i++){
|
|
415
|
+
var slice = glbBufferSlice[i];
|
|
416
|
+
buffers[i] = bigBuffer.slice(slice.x, slice.x + slice.y);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
// Restore texture
|
|
420
|
+
engineCore.AssetPromise.all(_this.bufferTextures.map(function(textureRestoreInfo) {
|
|
421
|
+
var bufferView = textureRestoreInfo.bufferView;
|
|
422
|
+
var buffer = buffers[bufferView.buffer];
|
|
423
|
+
var _bufferView_byteOffset;
|
|
424
|
+
var bufferData = new Uint8Array(buffer, (_bufferView_byteOffset = bufferView.byteOffset) != null ? _bufferView_byteOffset : 0, bufferView.byteLength);
|
|
425
|
+
return GLTFUtils.loadImageBuffer(bufferData, textureRestoreInfo.mimeType).then(function(image) {
|
|
426
|
+
textureRestoreInfo.texture.setImageSource(image);
|
|
427
|
+
textureRestoreInfo.texture.generateMipmaps();
|
|
428
|
+
});
|
|
429
|
+
})).then(function() {
|
|
430
|
+
// Restore mesh
|
|
431
|
+
for(var _iterator = _create_for_of_iterator_helper_loose(_this.meshes), _step; !(_step = _iterator()).done;){
|
|
432
|
+
var meshInfo = _step.value;
|
|
433
|
+
var mesh = meshInfo.mesh;
|
|
434
|
+
for(var _iterator1 = _create_for_of_iterator_helper_loose(meshInfo.vertexBuffers), _step1; !(_step1 = _iterator1()).done;){
|
|
435
|
+
var bufferRestoreInfo = _step1.value;
|
|
436
|
+
var vertexData = _this._getBufferData(buffers, bufferRestoreInfo.data);
|
|
437
|
+
bufferRestoreInfo.buffer.setData(vertexData);
|
|
438
|
+
}
|
|
439
|
+
if (meshInfo.indexBuffer) {
|
|
440
|
+
var indexData = _this._getBufferData(buffers, meshInfo.indexBuffer);
|
|
441
|
+
mesh.setIndices(indexData);
|
|
442
|
+
}
|
|
443
|
+
for(var _iterator2 = _create_for_of_iterator_helper_loose(meshInfo.blendShapes), _step2; !(_step2 = _iterator2()).done;){
|
|
444
|
+
var restoreInfo = _step2.value;
|
|
445
|
+
var frame = restoreInfo.blendShape.frames[0];
|
|
446
|
+
var positionData = _this._getBufferData(buffers, restoreInfo.position);
|
|
447
|
+
frame.deltaPositions = GLTFUtils.floatBufferToVector3Array(positionData);
|
|
448
|
+
if (restoreInfo.normal) {
|
|
449
|
+
var normalData = _this._getBufferData(buffers, restoreInfo.normal);
|
|
450
|
+
frame.deltaNormals = GLTFUtils.floatBufferToVector3Array(normalData);
|
|
451
|
+
}
|
|
452
|
+
if (restoreInfo.tangent) {
|
|
453
|
+
var tangentData = _this._getBufferData(buffers, restoreInfo.tangent);
|
|
454
|
+
frame.deltaTangents = GLTFUtils.floatBufferToVector3Array(tangentData);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
mesh.uploadData(true);
|
|
458
|
+
}
|
|
459
|
+
resolve(_this.resource);
|
|
460
|
+
}).catch(reject);
|
|
461
|
+
}).catch(reject);
|
|
373
462
|
});
|
|
374
|
-
promiseInfo.promise = promise;
|
|
375
|
-
return promise;
|
|
376
463
|
};
|
|
377
|
-
|
|
378
|
-
|
|
464
|
+
_proto._getBufferData = function _getBufferData(buffers, restoreInfo) {
|
|
465
|
+
var main = restoreInfo.main;
|
|
466
|
+
var buffer = buffers[main.bufferIndex];
|
|
467
|
+
var data = new main.TypedArray(buffer, main.byteOffset, main.length);
|
|
468
|
+
var sparseCount = restoreInfo.sparseCount;
|
|
469
|
+
if (sparseCount) {
|
|
470
|
+
var sparseIndex = restoreInfo.sparseIndices;
|
|
471
|
+
var sparseIndexBuffer = buffers[sparseIndex.bufferIndex];
|
|
472
|
+
var sparseIndexData = new sparseIndex.TypedArray(sparseIndexBuffer, sparseIndex.byteOffset, sparseIndex.length);
|
|
473
|
+
var sparseValue = restoreInfo.sparseValues;
|
|
474
|
+
var sparseValueBuffer = buffers[sparseValue.bufferIndex];
|
|
475
|
+
var sparseValueData = new sparseValue.TypedArray(sparseValueBuffer, sparseValue.byteOffset, sparseValue.length);
|
|
476
|
+
var typeSize = restoreInfo.typeSize;
|
|
477
|
+
for(var i = 0; i < sparseCount; i++){
|
|
478
|
+
var replaceIndex = sparseIndexData[i];
|
|
479
|
+
for(var j = 0; j < typeSize; j++){
|
|
480
|
+
data[replaceIndex * typeSize + j] = sparseValueData[i * typeSize + j];
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
return data;
|
|
485
|
+
};
|
|
486
|
+
return GLTFContentRestorer;
|
|
487
|
+
}(engineCore.ContentRestorer);
|
|
379
488
|
/**
|
|
380
489
|
* @internal
|
|
381
|
-
*/ var
|
|
490
|
+
*/ var BufferRequestInfo = function BufferRequestInfo(url, config) {
|
|
491
|
+
this.url = url;
|
|
492
|
+
this.config = config;
|
|
493
|
+
};
|
|
494
|
+
/**
|
|
495
|
+
* @internal
|
|
496
|
+
*/ var BufferTextureRestoreInfo = function BufferTextureRestoreInfo(texture, bufferView, mimeType) {
|
|
497
|
+
this.texture = texture;
|
|
498
|
+
this.bufferView = bufferView;
|
|
499
|
+
this.mimeType = mimeType;
|
|
500
|
+
};
|
|
501
|
+
/**
|
|
502
|
+
* @internal
|
|
503
|
+
*/ var ModelMeshRestoreInfo = function ModelMeshRestoreInfo() {
|
|
504
|
+
this.vertexBuffers = [];
|
|
505
|
+
this.blendShapes = [];
|
|
506
|
+
};
|
|
507
|
+
/**
|
|
508
|
+
* @internal
|
|
509
|
+
*/ var BufferRestoreInfo = function BufferRestoreInfo(buffer, data) {
|
|
510
|
+
this.buffer = buffer;
|
|
382
511
|
this.data = data;
|
|
383
|
-
this.interleaved = interleaved;
|
|
384
|
-
this.stride = stride;
|
|
385
|
-
this.vertexBindingInfos = {};
|
|
386
512
|
};
|
|
387
513
|
/**
|
|
388
514
|
* @internal
|
|
389
|
-
*/ var
|
|
515
|
+
*/ var BufferDataRestoreInfo = function BufferDataRestoreInfo(main, typeSize, sparseCount, sparseIndices, sparseValues) {
|
|
516
|
+
this.main = main;
|
|
517
|
+
this.typeSize = typeSize;
|
|
518
|
+
this.sparseCount = sparseCount;
|
|
519
|
+
this.sparseIndices = sparseIndices;
|
|
520
|
+
this.sparseValues = sparseValues;
|
|
521
|
+
};
|
|
522
|
+
/**
|
|
523
|
+
* @internal
|
|
524
|
+
*/ var RestoreDataAccessor = function RestoreDataAccessor(bufferIndex, TypedArray, byteOffset, length) {
|
|
525
|
+
this.bufferIndex = bufferIndex;
|
|
526
|
+
this.TypedArray = TypedArray;
|
|
527
|
+
this.byteOffset = byteOffset;
|
|
528
|
+
this.length = length;
|
|
529
|
+
};
|
|
530
|
+
/**
|
|
531
|
+
* @internal
|
|
532
|
+
*/ var BlendShapeRestoreInfo = function BlendShapeRestoreInfo(blendShape, position, normal, tangent) {
|
|
533
|
+
this.blendShape = blendShape;
|
|
534
|
+
this.position = position;
|
|
535
|
+
this.normal = normal;
|
|
536
|
+
this.tangent = tangent;
|
|
390
537
|
};
|
|
391
538
|
|
|
392
539
|
/**
|
|
@@ -538,9 +685,57 @@ var TextureWrapMode;
|
|
|
538
685
|
|
|
539
686
|
/**
|
|
540
687
|
* @internal
|
|
541
|
-
*/ var
|
|
542
|
-
function
|
|
543
|
-
|
|
688
|
+
*/ var GLTFParserContext = /*#__PURE__*/ function() {
|
|
689
|
+
function GLTFParserContext(url) {
|
|
690
|
+
this.hasSkinned = false;
|
|
691
|
+
this.chainPromises = [];
|
|
692
|
+
this.accessorBufferCache = {};
|
|
693
|
+
this.texturesPromiseInfo = new PromiseInfo();
|
|
694
|
+
this.materialsPromiseInfo = new PromiseInfo();
|
|
695
|
+
this.meshesPromiseInfo = new PromiseInfo();
|
|
696
|
+
this.animationClipsPromiseInfo = new PromiseInfo();
|
|
697
|
+
this.defaultSceneRootPromiseInfo = new PromiseInfo();
|
|
698
|
+
this.masterPromiseInfo = new PromiseInfo();
|
|
699
|
+
this.promiseMap = {};
|
|
700
|
+
var promiseMap = this.promiseMap;
|
|
701
|
+
promiseMap["" + url + "?q=textures"] = this._initPromiseInfo(this.texturesPromiseInfo);
|
|
702
|
+
promiseMap["" + url + "?q=materials"] = this._initPromiseInfo(this.materialsPromiseInfo);
|
|
703
|
+
promiseMap["" + url + "?q=meshes"] = this._initPromiseInfo(this.meshesPromiseInfo);
|
|
704
|
+
promiseMap["" + url + "?q=animations"] = this._initPromiseInfo(this.animationClipsPromiseInfo);
|
|
705
|
+
promiseMap["" + url + "?q=defaultSceneRoot"] = this._initPromiseInfo(this.defaultSceneRootPromiseInfo);
|
|
706
|
+
promiseMap["" + url] = this._initPromiseInfo(this.masterPromiseInfo);
|
|
707
|
+
}
|
|
708
|
+
var _proto = GLTFParserContext.prototype;
|
|
709
|
+
_proto._initPromiseInfo = function _initPromiseInfo(promiseInfo) {
|
|
710
|
+
var promise = new engineCore.AssetPromise(function(resolve, reject, setProgress, onCancel) {
|
|
711
|
+
promiseInfo.resolve = resolve;
|
|
712
|
+
promiseInfo.reject = reject;
|
|
713
|
+
promiseInfo.setProgress = setProgress;
|
|
714
|
+
promiseInfo.onCancel = onCancel;
|
|
715
|
+
});
|
|
716
|
+
promiseInfo.promise = promise;
|
|
717
|
+
return promise;
|
|
718
|
+
};
|
|
719
|
+
return GLTFParserContext;
|
|
720
|
+
}();
|
|
721
|
+
/**
|
|
722
|
+
* @internal
|
|
723
|
+
*/ var BufferInfo = function BufferInfo(data, interleaved, stride) {
|
|
724
|
+
this.data = data;
|
|
725
|
+
this.interleaved = interleaved;
|
|
726
|
+
this.stride = stride;
|
|
727
|
+
this.vertexBindingInfos = {};
|
|
728
|
+
};
|
|
729
|
+
/**
|
|
730
|
+
* @internal
|
|
731
|
+
*/ var PromiseInfo = function PromiseInfo() {
|
|
732
|
+
};
|
|
733
|
+
|
|
734
|
+
/**
|
|
735
|
+
* @internal
|
|
736
|
+
*/ var GLTFUtils = /*#__PURE__*/ function() {
|
|
737
|
+
function GLTFUtils() {}
|
|
738
|
+
GLTFUtils.floatBufferToVector2Array = function floatBufferToVector2Array(buffer) {
|
|
544
739
|
var bufferLen = buffer.length;
|
|
545
740
|
var array = new Array(bufferLen / 2);
|
|
546
741
|
for(var i = 0; i < bufferLen; i += 2){
|
|
@@ -548,7 +743,7 @@ var TextureWrapMode;
|
|
|
548
743
|
}
|
|
549
744
|
return array;
|
|
550
745
|
};
|
|
551
|
-
|
|
746
|
+
GLTFUtils.floatBufferToVector3Array = function floatBufferToVector3Array(buffer) {
|
|
552
747
|
var bufferLen = buffer.length;
|
|
553
748
|
var array = new Array(bufferLen / 3);
|
|
554
749
|
for(var i = 0; i < bufferLen; i += 3){
|
|
@@ -556,7 +751,7 @@ var TextureWrapMode;
|
|
|
556
751
|
}
|
|
557
752
|
return array;
|
|
558
753
|
};
|
|
559
|
-
|
|
754
|
+
GLTFUtils.floatBufferToVector4Array = function floatBufferToVector4Array(buffer) {
|
|
560
755
|
var bufferLen = buffer.length;
|
|
561
756
|
var array = new Array(bufferLen / 4);
|
|
562
757
|
for(var i = 0; i < bufferLen; i += 4){
|
|
@@ -564,7 +759,7 @@ var TextureWrapMode;
|
|
|
564
759
|
}
|
|
565
760
|
return array;
|
|
566
761
|
};
|
|
567
|
-
|
|
762
|
+
GLTFUtils.floatBufferToColorArray = function floatBufferToColorArray(buffer, isColor3) {
|
|
568
763
|
var bufferLen = buffer.length;
|
|
569
764
|
var colors = new Array(bufferLen / (isColor3 ? 3 : 4));
|
|
570
765
|
if (isColor3) {
|
|
@@ -579,21 +774,8 @@ var TextureWrapMode;
|
|
|
579
774
|
return colors;
|
|
580
775
|
};
|
|
581
776
|
/**
|
|
582
|
-
* Parse binary text for glb loader.
|
|
583
|
-
*/ GLTFUtil.decodeText = function decodeText(array) {
|
|
584
|
-
if (typeof TextDecoder !== "undefined") {
|
|
585
|
-
return new TextDecoder().decode(array);
|
|
586
|
-
}
|
|
587
|
-
// TextDecoder polyfill
|
|
588
|
-
var s = "";
|
|
589
|
-
for(var i = 0, il = array.length; i < il; i++){
|
|
590
|
-
s += String.fromCharCode(array[i]);
|
|
591
|
-
}
|
|
592
|
-
return decodeURIComponent(encodeURIComponent(s));
|
|
593
|
-
};
|
|
594
|
-
/**
|
|
595
777
|
* Get the number of bytes occupied by accessor type.
|
|
596
|
-
*/
|
|
778
|
+
*/ GLTFUtils.getAccessorTypeSize = function getAccessorTypeSize(accessorType) {
|
|
597
779
|
switch(accessorType){
|
|
598
780
|
case AccessorType.SCALAR:
|
|
599
781
|
return 1;
|
|
@@ -613,7 +795,7 @@ var TextureWrapMode;
|
|
|
613
795
|
};
|
|
614
796
|
/**
|
|
615
797
|
* Get the TypedArray corresponding to the component type.
|
|
616
|
-
*/
|
|
798
|
+
*/ GLTFUtils.getComponentType = function getComponentType(componentType) {
|
|
617
799
|
switch(componentType){
|
|
618
800
|
case AccessorComponentType.BYTE:
|
|
619
801
|
return Int8Array;
|
|
@@ -629,7 +811,7 @@ var TextureWrapMode;
|
|
|
629
811
|
return Float32Array;
|
|
630
812
|
}
|
|
631
813
|
};
|
|
632
|
-
|
|
814
|
+
GLTFUtils.getNormalizedComponentScale = function getNormalizedComponentScale(componentType) {
|
|
633
815
|
// Reference: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization#encoding-quantized-data
|
|
634
816
|
switch(componentType){
|
|
635
817
|
case AccessorComponentType.BYTE:
|
|
@@ -644,18 +826,18 @@ var TextureWrapMode;
|
|
|
644
826
|
throw new Error("Galacean.GLTFLoader: Unsupported normalized accessor component type.");
|
|
645
827
|
}
|
|
646
828
|
};
|
|
647
|
-
|
|
829
|
+
GLTFUtils.getAccessorBuffer = function getAccessorBuffer(context, bufferViews, accessor) {
|
|
648
830
|
var buffers = context.buffers;
|
|
649
|
-
var bufferViews = gltf.bufferViews;
|
|
650
831
|
var componentType = accessor.componentType;
|
|
651
832
|
var bufferView = bufferViews[accessor.bufferView];
|
|
652
|
-
var
|
|
833
|
+
var bufferIndex = bufferView.buffer;
|
|
834
|
+
var buffer = buffers[bufferIndex];
|
|
653
835
|
var bufferByteOffset = bufferView.byteOffset || 0;
|
|
654
836
|
var byteOffset = accessor.byteOffset || 0;
|
|
655
|
-
var TypedArray =
|
|
656
|
-
var
|
|
837
|
+
var TypedArray = GLTFUtils.getComponentType(componentType);
|
|
838
|
+
var dataElementSize = GLTFUtils.getAccessorTypeSize(accessor.type);
|
|
657
839
|
var dataElementBytes = TypedArray.BYTES_PER_ELEMENT;
|
|
658
|
-
var elementStride =
|
|
840
|
+
var elementStride = dataElementSize * dataElementBytes;
|
|
659
841
|
var accessorCount = accessor.count;
|
|
660
842
|
var bufferStride = bufferView.byteStride;
|
|
661
843
|
var bufferInfo;
|
|
@@ -670,34 +852,35 @@ var TextureWrapMode;
|
|
|
670
852
|
var count = accessorCount * (bufferStride / dataElementBytes);
|
|
671
853
|
var data = new TypedArray(buffer, offset, count);
|
|
672
854
|
accessorBufferCache[bufferCacheKey] = bufferInfo = new BufferInfo(data, true, bufferStride);
|
|
855
|
+
bufferInfo.restoreInfo = new BufferDataRestoreInfo(new RestoreDataAccessor(bufferIndex, TypedArray, offset, count));
|
|
673
856
|
}
|
|
674
857
|
} else {
|
|
675
858
|
var offset1 = bufferByteOffset + byteOffset;
|
|
676
|
-
var count1 = accessorCount *
|
|
859
|
+
var count1 = accessorCount * dataElementSize;
|
|
677
860
|
var data1 = new TypedArray(buffer, offset1, count1);
|
|
678
861
|
bufferInfo = new BufferInfo(data1, false, elementStride);
|
|
862
|
+
bufferInfo.restoreInfo = new BufferDataRestoreInfo(new RestoreDataAccessor(bufferIndex, TypedArray, offset1, count1));
|
|
679
863
|
}
|
|
680
864
|
if (accessor.sparse) {
|
|
681
|
-
|
|
682
|
-
bufferInfo = new BufferInfo(data2, false, bufferInfo.stride);
|
|
865
|
+
GLTFUtils.processingSparseData(bufferViews, accessor, buffers, bufferInfo);
|
|
683
866
|
}
|
|
684
867
|
return bufferInfo;
|
|
685
868
|
};
|
|
686
869
|
/**
|
|
687
870
|
* @deprecated
|
|
688
871
|
* Get accessor data.
|
|
689
|
-
*/
|
|
690
|
-
var bufferViews =
|
|
872
|
+
*/ GLTFUtils.getAccessorData = function getAccessorData(glTF, accessor, buffers) {
|
|
873
|
+
var bufferViews = glTF.bufferViews;
|
|
691
874
|
var bufferView = bufferViews[accessor.bufferView];
|
|
692
875
|
var arrayBuffer = buffers[bufferView.buffer];
|
|
693
876
|
var accessorByteOffset = accessor.hasOwnProperty("byteOffset") ? accessor.byteOffset : 0;
|
|
694
877
|
var bufferViewByteOffset = bufferView.hasOwnProperty("byteOffset") ? bufferView.byteOffset : 0;
|
|
695
878
|
var byteOffset = accessorByteOffset + bufferViewByteOffset;
|
|
696
|
-
var accessorTypeSize =
|
|
879
|
+
var accessorTypeSize = GLTFUtils.getAccessorTypeSize(accessor.type);
|
|
697
880
|
var length = accessorTypeSize * accessor.count;
|
|
698
881
|
var _bufferView_byteStride;
|
|
699
882
|
var byteStride = (_bufferView_byteStride = bufferView.byteStride) != null ? _bufferView_byteStride : 0;
|
|
700
|
-
var arrayType =
|
|
883
|
+
var arrayType = GLTFUtils.getComponentType(accessor.componentType);
|
|
701
884
|
var uint8Array;
|
|
702
885
|
if (byteStride) {
|
|
703
886
|
var accessorByteSize = accessorTypeSize * arrayType.BYTES_PER_ELEMENT;
|
|
@@ -724,7 +907,7 @@ var TextureWrapMode;
|
|
|
724
907
|
var _values_byteOffset, _valuesBufferView_byteOffset;
|
|
725
908
|
var valuesByteOffset = ((_values_byteOffset = values.byteOffset) != null ? _values_byteOffset : 0) + ((_valuesBufferView_byteOffset = valuesBufferView.byteOffset) != null ? _valuesBufferView_byteOffset : 0);
|
|
726
909
|
var valuesByteLength = valuesBufferView.byteLength;
|
|
727
|
-
var indicesType =
|
|
910
|
+
var indicesType = GLTFUtils.getComponentType(indices.componentType);
|
|
728
911
|
var indicesArray = new indicesType(indicesArrayBuffer, indicesByteOffset, indicesByteLength / indicesType.BYTES_PER_ELEMENT);
|
|
729
912
|
var valuesArray = new arrayType(valuesArrayBuffer, valuesByteOffset, valuesByteLength / arrayType.BYTES_PER_ELEMENT);
|
|
730
913
|
for(var i1 = 0; i1 < count; i1++){
|
|
@@ -736,41 +919,49 @@ var TextureWrapMode;
|
|
|
736
919
|
}
|
|
737
920
|
return typedArray;
|
|
738
921
|
};
|
|
739
|
-
|
|
740
|
-
var
|
|
741
|
-
var arrayBuffer = buffers[buffer];
|
|
742
|
-
return arrayBuffer.slice(byteOffset, byteOffset + byteLength);
|
|
922
|
+
GLTFUtils.getBufferViewData = function getBufferViewData(bufferView, buffers) {
|
|
923
|
+
var _bufferView_byteOffset = bufferView.byteOffset, byteOffset = _bufferView_byteOffset === void 0 ? 0 : _bufferView_byteOffset;
|
|
924
|
+
var arrayBuffer = buffers[bufferView.buffer];
|
|
925
|
+
return arrayBuffer.slice(byteOffset, byteOffset + bufferView.byteLength);
|
|
743
926
|
};
|
|
744
927
|
/**
|
|
745
928
|
* Get accessor data.
|
|
746
|
-
*/
|
|
747
|
-
var
|
|
748
|
-
var accessorTypeSize =
|
|
749
|
-
var TypedArray =
|
|
750
|
-
var data =
|
|
929
|
+
*/ GLTFUtils.processingSparseData = function processingSparseData(bufferViews, accessor, buffers, bufferInfo) {
|
|
930
|
+
var restoreInfo = bufferInfo.restoreInfo;
|
|
931
|
+
var accessorTypeSize = GLTFUtils.getAccessorTypeSize(accessor.type);
|
|
932
|
+
var TypedArray = GLTFUtils.getComponentType(accessor.componentType);
|
|
933
|
+
var data = bufferInfo.data.slice();
|
|
751
934
|
var _accessor_sparse = accessor.sparse, count = _accessor_sparse.count, indices = _accessor_sparse.indices, values = _accessor_sparse.values;
|
|
752
935
|
var indicesBufferView = bufferViews[indices.bufferView];
|
|
753
936
|
var valuesBufferView = bufferViews[values.bufferView];
|
|
754
|
-
var
|
|
755
|
-
var
|
|
937
|
+
var indicesBufferIndex = indicesBufferView.buffer;
|
|
938
|
+
var valuesBufferIndex = valuesBufferView.buffer;
|
|
939
|
+
var indicesArrayBuffer = buffers[indicesBufferIndex];
|
|
940
|
+
var valuesArrayBuffer = buffers[valuesBufferIndex];
|
|
756
941
|
var _indices_byteOffset, _indicesBufferView_byteOffset;
|
|
757
942
|
var indicesByteOffset = ((_indices_byteOffset = indices.byteOffset) != null ? _indices_byteOffset : 0) + ((_indicesBufferView_byteOffset = indicesBufferView.byteOffset) != null ? _indicesBufferView_byteOffset : 0);
|
|
758
943
|
var indicesByteLength = indicesBufferView.byteLength;
|
|
759
944
|
var _values_byteOffset, _valuesBufferView_byteOffset;
|
|
760
945
|
var valuesByteOffset = ((_values_byteOffset = values.byteOffset) != null ? _values_byteOffset : 0) + ((_valuesBufferView_byteOffset = valuesBufferView.byteOffset) != null ? _valuesBufferView_byteOffset : 0);
|
|
761
946
|
var valuesByteLength = valuesBufferView.byteLength;
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
var
|
|
947
|
+
restoreInfo.typeSize = accessorTypeSize;
|
|
948
|
+
restoreInfo.sparseCount = count;
|
|
949
|
+
var IndexTypeArray = GLTFUtils.getComponentType(indices.componentType);
|
|
950
|
+
var indexLength = indicesByteLength / IndexTypeArray.BYTES_PER_ELEMENT;
|
|
951
|
+
var indicesArray = new IndexTypeArray(indicesArrayBuffer, indicesByteOffset, indexLength);
|
|
952
|
+
restoreInfo.sparseIndices = new RestoreDataAccessor(indicesBufferIndex, IndexTypeArray, indicesByteOffset, indexLength);
|
|
953
|
+
var valueLength = valuesByteLength / TypedArray.BYTES_PER_ELEMENT;
|
|
954
|
+
var valuesArray = new TypedArray(valuesArrayBuffer, valuesByteOffset, valueLength);
|
|
955
|
+
restoreInfo.sparseValues = new RestoreDataAccessor(valuesBufferIndex, TypedArray, valuesByteOffset, valueLength);
|
|
765
956
|
for(var i = 0; i < count; i++){
|
|
766
957
|
var replaceIndex = indicesArray[i];
|
|
767
958
|
for(var j = 0; j < accessorTypeSize; j++){
|
|
768
959
|
data[replaceIndex * accessorTypeSize + j] = valuesArray[i * accessorTypeSize + j];
|
|
769
960
|
}
|
|
770
961
|
}
|
|
771
|
-
|
|
962
|
+
bufferInfo.data = data;
|
|
772
963
|
};
|
|
773
|
-
|
|
964
|
+
GLTFUtils.getIndexFormat = function getIndexFormat(type) {
|
|
774
965
|
switch(type){
|
|
775
966
|
case AccessorComponentType.UNSIGNED_BYTE:
|
|
776
967
|
return engineCore.IndexFormat.UInt8;
|
|
@@ -780,7 +971,7 @@ var TextureWrapMode;
|
|
|
780
971
|
return engineCore.IndexFormat.UInt32;
|
|
781
972
|
}
|
|
782
973
|
};
|
|
783
|
-
|
|
974
|
+
GLTFUtils.getElementFormat = function getElementFormat(type, size, normalized) {
|
|
784
975
|
if (normalized === void 0) normalized = false;
|
|
785
976
|
if (type == AccessorComponentType.FLOAT) {
|
|
786
977
|
switch(size){
|
|
@@ -831,7 +1022,7 @@ var TextureWrapMode;
|
|
|
831
1022
|
};
|
|
832
1023
|
/**
|
|
833
1024
|
* Load image buffer
|
|
834
|
-
*/
|
|
1025
|
+
*/ GLTFUtils.loadImageBuffer = function loadImageBuffer(imageBuffer, type) {
|
|
835
1026
|
return new Promise(function(resolve, reject) {
|
|
836
1027
|
var blob = new window.Blob([
|
|
837
1028
|
imageBuffer
|
|
@@ -855,18 +1046,9 @@ var TextureWrapMode;
|
|
|
855
1046
|
img.src = URL.createObjectURL(blob);
|
|
856
1047
|
});
|
|
857
1048
|
};
|
|
858
|
-
GLTFUtil.isAbsoluteUrl = function isAbsoluteUrl(url) {
|
|
859
|
-
return /^(?:http|blob|data:|\/)/.test(url);
|
|
860
|
-
};
|
|
861
|
-
GLTFUtil.parseRelativeUrl = function parseRelativeUrl(baseUrl, relativeUrl) {
|
|
862
|
-
if (GLTFUtil.isAbsoluteUrl(relativeUrl)) {
|
|
863
|
-
return relativeUrl;
|
|
864
|
-
}
|
|
865
|
-
return baseUrl.substring(0, baseUrl.lastIndexOf("/") + 1) + GLTFUtil._formatRelativePath(relativeUrl);
|
|
866
|
-
};
|
|
867
1049
|
/**
|
|
868
1050
|
* Parse the glb format.
|
|
869
|
-
*/
|
|
1051
|
+
*/ GLTFUtils.parseGLB = function parseGLB(context, glb) {
|
|
870
1052
|
var UINT32_LENGTH = 4;
|
|
871
1053
|
var GLB_HEADER_MAGIC = 0x46546c67; // 'glTF'
|
|
872
1054
|
var GLB_HEADER_LENGTH = 12;
|
|
@@ -894,10 +1076,11 @@ var TextureWrapMode;
|
|
|
894
1076
|
return null;
|
|
895
1077
|
}
|
|
896
1078
|
var glTFData = new Uint8Array(glb, GLB_HEADER_LENGTH + 2 * UINT32_LENGTH, chunkLength);
|
|
897
|
-
var
|
|
1079
|
+
var glTF = JSON.parse(engineCore.Utils.decodeText(glTFData));
|
|
898
1080
|
// read all buffers
|
|
899
1081
|
var buffers = [];
|
|
900
1082
|
var byteOffset = GLB_HEADER_LENGTH + 2 * UINT32_LENGTH + chunkLength;
|
|
1083
|
+
var restoreGLBBufferSlice = context.contentRestorer.glbBufferSlices;
|
|
901
1084
|
while(byteOffset < header.length){
|
|
902
1085
|
chunkLength = dataView.getUint32(byteOffset, true);
|
|
903
1086
|
chunkType = dataView.getUint32(byteOffset + UINT32_LENGTH, true);
|
|
@@ -908,14 +1091,15 @@ var TextureWrapMode;
|
|
|
908
1091
|
var currentOffset = byteOffset + 2 * UINT32_LENGTH;
|
|
909
1092
|
var buffer = glb.slice(currentOffset, currentOffset + chunkLength);
|
|
910
1093
|
buffers.push(buffer);
|
|
1094
|
+
restoreGLBBufferSlice.push(new engineMath.Vector2(currentOffset, chunkLength));
|
|
911
1095
|
byteOffset += chunkLength + 2 * UINT32_LENGTH;
|
|
912
1096
|
}
|
|
913
1097
|
return {
|
|
914
|
-
|
|
1098
|
+
glTF: glTF,
|
|
915
1099
|
buffers: buffers
|
|
916
1100
|
};
|
|
917
1101
|
};
|
|
918
|
-
|
|
1102
|
+
GLTFUtils._formatRelativePath = function _formatRelativePath(path) {
|
|
919
1103
|
// For example input is "a/b", "/a/b", "./a/b", "./a/./b", "./a/../a/b", output is "a/b"
|
|
920
1104
|
return path.split("/").filter(Boolean).reduce(function(acc, cur) {
|
|
921
1105
|
if (cur === "..") acc.pop();
|
|
@@ -923,17 +1107,9 @@ var TextureWrapMode;
|
|
|
923
1107
|
return acc;
|
|
924
1108
|
}, []).join("/");
|
|
925
1109
|
};
|
|
926
|
-
return
|
|
1110
|
+
return GLTFUtils;
|
|
927
1111
|
}();
|
|
928
1112
|
|
|
929
|
-
function _array_like_to_array(arr, len) {
|
|
930
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
931
|
-
|
|
932
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
933
|
-
|
|
934
|
-
return arr2;
|
|
935
|
-
}
|
|
936
|
-
|
|
937
1113
|
function _array_without_holes(arr) {
|
|
938
1114
|
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
939
1115
|
}
|
|
@@ -948,606 +1124,327 @@ function _non_iterable_spread() {
|
|
|
948
1124
|
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
949
1125
|
}
|
|
950
1126
|
|
|
951
|
-
function _unsupported_iterable_to_array(o, minLen) {
|
|
952
|
-
if (!o) return;
|
|
953
|
-
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
954
|
-
|
|
955
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
956
|
-
|
|
957
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
958
|
-
if (n === "Map" || n === "Set") return Array.from(n);
|
|
959
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
960
|
-
}
|
|
961
|
-
|
|
962
1127
|
function _to_consumable_array(arr) {
|
|
963
1128
|
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
964
1129
|
}
|
|
965
1130
|
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
1131
|
+
/**
|
|
1132
|
+
* Base class of glTF extension parser.
|
|
1133
|
+
*/ var GLTFExtensionParser = /*#__PURE__*/ function() {
|
|
1134
|
+
function GLTFExtensionParser() {}
|
|
1135
|
+
var _proto = GLTFExtensionParser.prototype;
|
|
1136
|
+
/**
|
|
1137
|
+
* Initialize the parser.
|
|
1138
|
+
* @remarks Some plugins require initialization.
|
|
1139
|
+
* @returns The void or promise
|
|
1140
|
+
*/ _proto.initialize = function initialize() {};
|
|
1141
|
+
/**
|
|
1142
|
+
* Create and parse the resource.
|
|
1143
|
+
* @remarks This method overrides the default resource creation.
|
|
1144
|
+
* @param context - The parser context
|
|
1145
|
+
* @param extensionSchema - The extension schema
|
|
1146
|
+
* @param extensionOwnerSchema - The extension owner schema
|
|
1147
|
+
* @returns The resource or promise
|
|
1148
|
+
*/ _proto.createAndParse = function createAndParse(context, extensionSchema, extensionOwnerSchema) {
|
|
1149
|
+
for(var _len = arguments.length, extra = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++){
|
|
1150
|
+
extra[_key - 3] = arguments[_key];
|
|
1151
|
+
}
|
|
1152
|
+
throw "Not implemented.";
|
|
1153
|
+
};
|
|
1154
|
+
/**
|
|
1155
|
+
* Additive parse to the resource.
|
|
1156
|
+
* @param context - The parser context
|
|
1157
|
+
* @param parseResource - The parsed resource
|
|
1158
|
+
* @param extensionSchema - The extension schema
|
|
1159
|
+
* @param extensionOwnerSchema - The extension owner schema
|
|
1160
|
+
* @returns The void or promise
|
|
1161
|
+
*/ _proto.additiveParse = function additiveParse(context, parseResource, extensionSchema, extensionOwnerSchema) {
|
|
969
1162
|
for(var _len = arguments.length, extra = new Array(_len > 4 ? _len - 4 : 0), _key = 4; _key < _len; _key++){
|
|
970
1163
|
extra[_key - 4] = arguments[_key];
|
|
971
1164
|
}
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
1165
|
+
throw "Not implemented.";
|
|
1166
|
+
};
|
|
1167
|
+
return GLTFExtensionParser;
|
|
1168
|
+
}();
|
|
1169
|
+
exports.GLTFExtensionMode = void 0;
|
|
1170
|
+
(function(GLTFExtensionMode) {
|
|
1171
|
+
GLTFExtensionMode[GLTFExtensionMode[/**
|
|
1172
|
+
* Cerate instance and parse mode.
|
|
1173
|
+
* @remarks
|
|
1174
|
+
* If the glTF property has multiple extensions of `CreateAndParse` mode, only execute the last one.
|
|
1175
|
+
* If this method is registered, the default pipeline processing will be ignored.
|
|
1176
|
+
*/ "CreateAndParse"] = 0] = "CreateAndParse";
|
|
1177
|
+
GLTFExtensionMode[GLTFExtensionMode[/** Additive parse mode. */ "AdditiveParse"] = 1] = "AdditiveParse";
|
|
1178
|
+
})(exports.GLTFExtensionMode || (exports.GLTFExtensionMode = {}));
|
|
1179
|
+
|
|
1180
|
+
/**
|
|
1181
|
+
* Base class of glTF parser.
|
|
1182
|
+
*/ var GLTFParser = /*#__PURE__*/ function() {
|
|
1183
|
+
function GLTFParser() {}
|
|
1184
|
+
/**
|
|
1185
|
+
* Execute all parses of extension to initialize plugin.
|
|
1186
|
+
* @remarks Some plugins require initialization.
|
|
1187
|
+
* @returns The void or promise
|
|
1188
|
+
*/ GLTFParser.executeExtensionsInitialize = function executeExtensionsInitialize(extensionName) {
|
|
1189
|
+
var parsers = GLTFParser._extensionParsers[extensionName];
|
|
1190
|
+
var length = parsers == null ? void 0 : parsers.length;
|
|
1191
|
+
if (length) {
|
|
1192
|
+
return parsers[length - 1].initialize();
|
|
982
1193
|
}
|
|
983
1194
|
};
|
|
984
|
-
|
|
1195
|
+
/**
|
|
1196
|
+
* Execute all parses of extension to create resource.
|
|
1197
|
+
* @param extensions - Related extensions field
|
|
1198
|
+
* @param context - The parser context
|
|
1199
|
+
* @param ownerSchema - The extension owner schema
|
|
1200
|
+
* @param extra - Extra params
|
|
1201
|
+
* @returns
|
|
1202
|
+
*/ GLTFParser.executeExtensionsCreateAndParse = function executeExtensionsCreateAndParse(extensions, context, ownerSchema) {
|
|
1203
|
+
if (extensions === void 0) extensions = {};
|
|
985
1204
|
for(var _len = arguments.length, extra = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++){
|
|
986
1205
|
extra[_key - 3] = arguments[_key];
|
|
987
1206
|
}
|
|
988
|
-
var
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
1207
|
+
var resource = null;
|
|
1208
|
+
var extensionArray = Object.keys(extensions);
|
|
1209
|
+
for(var i = extensionArray.length - 1; i >= 0; --i){
|
|
1210
|
+
var _GLTFParser;
|
|
1211
|
+
var extensionName = extensionArray[i];
|
|
1212
|
+
var extensionSchema = extensions[extensionName];
|
|
1213
|
+
resource = (_GLTFParser = GLTFParser)._createAndParse.apply(_GLTFParser, [
|
|
1214
|
+
extensionName,
|
|
1215
|
+
context,
|
|
1216
|
+
extensionSchema,
|
|
1217
|
+
ownerSchema
|
|
1218
|
+
].concat(_to_consumable_array(extra)));
|
|
1219
|
+
if (resource) {
|
|
1220
|
+
return resource;
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
};
|
|
1224
|
+
/**
|
|
1225
|
+
* Execute all parses of extension to parse resource.
|
|
1226
|
+
* @param extensions - Related extensions field
|
|
1227
|
+
* @param context - The parser context
|
|
1228
|
+
* @param parseResource - The parsed resource
|
|
1229
|
+
* @param ownerSchema - The extension owner schema
|
|
1230
|
+
* @param extra - Extra params
|
|
1231
|
+
*/ GLTFParser.executeExtensionsAdditiveAndParse = function executeExtensionsAdditiveAndParse(extensions, context, parseResource, ownerSchema) {
|
|
1232
|
+
for(var _len = arguments.length, extra = new Array(_len > 4 ? _len - 4 : 0), _key = 4; _key < _len; _key++){
|
|
1233
|
+
extra[_key - 4] = arguments[_key];
|
|
1234
|
+
}
|
|
1235
|
+
for(var extensionName in extensions){
|
|
1236
|
+
var _GLTFParser;
|
|
1237
|
+
var extensionSchema = extensions[extensionName];
|
|
1238
|
+
(_GLTFParser = GLTFParser)._additiveParse.apply(_GLTFParser, [
|
|
1239
|
+
extensionName,
|
|
1240
|
+
context,
|
|
1241
|
+
parseResource,
|
|
992
1242
|
extensionSchema,
|
|
993
|
-
|
|
1243
|
+
ownerSchema
|
|
994
1244
|
].concat(_to_consumable_array(extra)));
|
|
995
1245
|
}
|
|
996
1246
|
};
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1247
|
+
/**
|
|
1248
|
+
* Whether the plugin is registered.
|
|
1249
|
+
* @param extensionName - Extension name
|
|
1250
|
+
* @returns Boolean
|
|
1251
|
+
*/ GLTFParser.hasExtensionParser = function hasExtensionParser(extensionName) {
|
|
1252
|
+
var _GLTFParser__extensionParsers_extensionName;
|
|
1253
|
+
return !!((_GLTFParser__extensionParsers_extensionName = GLTFParser._extensionParsers[extensionName]) == null ? void 0 : _GLTFParser__extensionParsers_extensionName.length);
|
|
1000
1254
|
};
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1255
|
+
/**
|
|
1256
|
+
* Get the last plugin by glTF extension mode.
|
|
1257
|
+
* @param extensionName - Extension name
|
|
1258
|
+
* @param mode - GLTF extension mode
|
|
1259
|
+
* @returns GLTF extension parser
|
|
1260
|
+
*/ GLTFParser.getExtensionParser = function getExtensionParser(extensionName, mode) {
|
|
1261
|
+
var parsers = GLTFParser._extensionParsers[extensionName];
|
|
1262
|
+
var length = parsers == null ? void 0 : parsers.length;
|
|
1263
|
+
if (length) {
|
|
1264
|
+
// only use the last parser.
|
|
1265
|
+
for(var i = length - 1; i >= 0; --i){
|
|
1266
|
+
var currentParser = parsers[i];
|
|
1267
|
+
if (currentParser._mode === mode) {
|
|
1268
|
+
return currentParser;
|
|
1269
|
+
}
|
|
1006
1270
|
}
|
|
1007
1271
|
}
|
|
1008
1272
|
};
|
|
1009
1273
|
/**
|
|
1010
1274
|
* @internal
|
|
1011
|
-
*/
|
|
1012
|
-
if (!
|
|
1013
|
-
|
|
1275
|
+
*/ GLTFParser._addExtensionParser = function _addExtensionParser(extensionName, extensionParser) {
|
|
1276
|
+
if (!GLTFParser._extensionParsers[extensionName]) {
|
|
1277
|
+
GLTFParser._extensionParsers[extensionName] = [];
|
|
1278
|
+
}
|
|
1279
|
+
GLTFParser._extensionParsers[extensionName].push(extensionParser);
|
|
1280
|
+
};
|
|
1281
|
+
GLTFParser._createAndParse = function _createAndParse(extensionName, context, extensionSchema, ownerSchema) {
|
|
1282
|
+
for(var _len = arguments.length, extra = new Array(_len > 4 ? _len - 4 : 0), _key = 4; _key < _len; _key++){
|
|
1283
|
+
extra[_key - 4] = arguments[_key];
|
|
1284
|
+
}
|
|
1285
|
+
var parser = GLTFParser.getExtensionParser(extensionName, exports.GLTFExtensionMode.CreateAndParse);
|
|
1286
|
+
if (parser) {
|
|
1287
|
+
var _parser;
|
|
1288
|
+
return (_parser = parser).createAndParse.apply(_parser, [
|
|
1289
|
+
context,
|
|
1290
|
+
extensionSchema,
|
|
1291
|
+
ownerSchema
|
|
1292
|
+
].concat(_to_consumable_array(extra)));
|
|
1014
1293
|
}
|
|
1015
|
-
Parser._extensionParsers[extensionName].push(extensionParser);
|
|
1016
1294
|
};
|
|
1017
|
-
|
|
1295
|
+
GLTFParser._additiveParse = function _additiveParse(extensionName, context, parseResource, extensionSchema, ownerSchema) {
|
|
1296
|
+
for(var _len = arguments.length, extra = new Array(_len > 5 ? _len - 5 : 0), _key = 5; _key < _len; _key++){
|
|
1297
|
+
extra[_key - 5] = arguments[_key];
|
|
1298
|
+
}
|
|
1299
|
+
var parser = GLTFParser.getExtensionParser(extensionName, exports.GLTFExtensionMode.AdditiveParse);
|
|
1300
|
+
if (parser) {
|
|
1301
|
+
var _parser;
|
|
1302
|
+
(_parser = parser).additiveParse.apply(_parser, [
|
|
1303
|
+
context,
|
|
1304
|
+
parseResource,
|
|
1305
|
+
extensionSchema,
|
|
1306
|
+
ownerSchema
|
|
1307
|
+
].concat(_to_consumable_array(extra)));
|
|
1308
|
+
}
|
|
1309
|
+
};
|
|
1310
|
+
return GLTFParser;
|
|
1018
1311
|
}();
|
|
1019
1312
|
(function() {
|
|
1020
|
-
|
|
1313
|
+
GLTFParser._extensionParsers = {};
|
|
1021
1314
|
})();
|
|
1022
1315
|
/**
|
|
1023
1316
|
* Declare ExtensionParser's decorator.
|
|
1024
1317
|
* @param extensionName - Extension name
|
|
1025
|
-
*/ function
|
|
1318
|
+
*/ function registerGLTFExtension(extensionName, mode) {
|
|
1026
1319
|
return function(parser) {
|
|
1027
1320
|
var extensionParser = new parser();
|
|
1028
|
-
|
|
1321
|
+
extensionParser._mode = mode;
|
|
1322
|
+
GLTFParser._addExtensionParser(extensionName, extensionParser);
|
|
1029
1323
|
};
|
|
1030
1324
|
}
|
|
1031
1325
|
|
|
1032
|
-
var
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
_proto.parseEngineResource = function parseEngineResource(schema, parseResource, context) {
|
|
1037
|
-
for(var _len = arguments.length, extra = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++){
|
|
1038
|
-
extra[_key - 3] = arguments[_key];
|
|
1039
|
-
}
|
|
1040
|
-
};
|
|
1041
|
-
_proto.createEngineResource = function createEngineResource(schema, context) {
|
|
1042
|
-
for(var _len = arguments.length, extra = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++){
|
|
1043
|
-
extra[_key - 2] = arguments[_key];
|
|
1044
|
-
}
|
|
1045
|
-
return null;
|
|
1046
|
-
};
|
|
1047
|
-
return ExtensionParser;
|
|
1048
|
-
}();
|
|
1049
|
-
|
|
1050
|
-
var KHR_draco_mesh_compression = /*#__PURE__*/ function(ExtensionParser) {
|
|
1051
|
-
_inherits(KHR_draco_mesh_compression1, ExtensionParser);
|
|
1052
|
-
function KHR_draco_mesh_compression1() {
|
|
1053
|
-
return ExtensionParser.apply(this, arguments);
|
|
1326
|
+
var GLTFAnimationParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
1327
|
+
_inherits(GLTFAnimationParser, GLTFParser1);
|
|
1328
|
+
function GLTFAnimationParser() {
|
|
1329
|
+
return GLTFParser1.apply(this, arguments);
|
|
1054
1330
|
}
|
|
1055
|
-
var _proto =
|
|
1056
|
-
_proto.
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
var gltf = context.gltf, buffers = context.buffers;
|
|
1063
|
-
var bufferViews = gltf.bufferViews, accessors = gltf.accessors;
|
|
1064
|
-
var bufferViewIndex = schema.bufferView, gltfAttributeMap = schema.attributes;
|
|
1065
|
-
var attributeMap = {};
|
|
1066
|
-
var attributeTypeMap = {};
|
|
1067
|
-
for(var attributeName in gltfAttributeMap){
|
|
1068
|
-
attributeMap[attributeName] = gltfAttributeMap[attributeName];
|
|
1331
|
+
var _proto = GLTFAnimationParser.prototype;
|
|
1332
|
+
_proto.parse = function parse(context) {
|
|
1333
|
+
var glTF = context.glTF; context.buffers; var glTFResource = context.glTFResource;
|
|
1334
|
+
glTFResource.entities;
|
|
1335
|
+
var animations = glTF.animations; glTF.accessors; glTF.bufferViews;
|
|
1336
|
+
if (!animations) {
|
|
1337
|
+
return;
|
|
1069
1338
|
}
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1339
|
+
var animationClipsPromiseInfo = context.animationClipsPromiseInfo;
|
|
1340
|
+
var animationClipCount = animations.length;
|
|
1341
|
+
var animationClipPromises = [];
|
|
1342
|
+
new Array(animationClipCount);
|
|
1343
|
+
for(var i = 0; i < animationClipCount; i++){
|
|
1344
|
+
var animationInfo = animations[i];
|
|
1345
|
+
var _animationInfo_name = animationInfo.name, name = _animationInfo_name === void 0 ? "AnimationClip" + i : _animationInfo_name;
|
|
1346
|
+
var animationClip = GLTFParser.executeExtensionsCreateAndParse(animationInfo.extensions, context, animationInfo);
|
|
1347
|
+
if (!animationClip) {
|
|
1348
|
+
animationClip = new engineCore.AnimationClip(name);
|
|
1349
|
+
GLTFAnimationParser._parseStandardProperty(context, animationClip, animationInfo);
|
|
1074
1350
|
}
|
|
1351
|
+
animationClipPromises.push(animationClip);
|
|
1075
1352
|
}
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
var buffer = GLTFUtil.getBufferViewData(bufferViews[bufferViewIndex], buffers);
|
|
1085
|
-
return KHR_draco_mesh_compression._decoder.decode(buffer, taskConfig).then(function(parsedGeometry) {
|
|
1086
|
-
return parsedGeometry;
|
|
1353
|
+
return engineCore.AssetPromise.all(animationClipPromises).then(function(animationClips) {
|
|
1354
|
+
glTFResource.animations = animationClips;
|
|
1355
|
+
for(var i = 0; i < glTF.animations.length; i++){
|
|
1356
|
+
var animationInfo = glTF.animations[i];
|
|
1357
|
+
GLTFParser.executeExtensionsAdditiveAndParse(animationInfo.extensions, context, animationClips[i], animationInfo);
|
|
1358
|
+
}
|
|
1359
|
+
animationClipsPromiseInfo.resolve(animationClips);
|
|
1360
|
+
return animationClipsPromiseInfo.promise;
|
|
1087
1361
|
});
|
|
1088
1362
|
};
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
var
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
var glTFResource = context.glTFResource;
|
|
1110
|
-
var light;
|
|
1111
|
-
if (type === "directional") {
|
|
1112
|
-
light = entity.addComponent(engineCore.DirectLight);
|
|
1113
|
-
} else if (type === "point") {
|
|
1114
|
-
light = entity.addComponent(engineCore.PointLight);
|
|
1115
|
-
} else if (type === "spot") {
|
|
1116
|
-
light = entity.addComponent(engineCore.SpotLight);
|
|
1117
|
-
}
|
|
1118
|
-
if (color) {
|
|
1119
|
-
light.color.set(color[0], color[1], color[2], 1);
|
|
1120
|
-
}
|
|
1121
|
-
light.intensity = intensity;
|
|
1122
|
-
if (range && !_instanceof(light, engineCore.DirectLight)) {
|
|
1123
|
-
light.distance = range;
|
|
1124
|
-
}
|
|
1125
|
-
if (spot && _instanceof(light, engineCore.SpotLight)) {
|
|
1126
|
-
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;
|
|
1127
|
-
light.angle = innerConeAngle;
|
|
1128
|
-
light.penumbra = outerConeAngle - innerConeAngle;
|
|
1129
|
-
}
|
|
1130
|
-
if (!glTFResource.lights) glTFResource.lights = [];
|
|
1131
|
-
glTFResource.lights.push(light);
|
|
1132
|
-
};
|
|
1133
|
-
return KHR_lights_punctual;
|
|
1134
|
-
}(ExtensionParser);
|
|
1135
|
-
KHR_lights_punctual = __decorate([
|
|
1136
|
-
registerExtension("KHR_lights_punctual")
|
|
1137
|
-
], KHR_lights_punctual);
|
|
1138
|
-
|
|
1139
|
-
var MaterialParser = /*#__PURE__*/ function(Parser1) {
|
|
1140
|
-
_inherits(MaterialParser, Parser1);
|
|
1141
|
-
function MaterialParser() {
|
|
1142
|
-
return Parser1.apply(this, arguments);
|
|
1143
|
-
}
|
|
1144
|
-
var _proto = MaterialParser.prototype;
|
|
1145
|
-
_proto.parse = function parse(context) {
|
|
1146
|
-
var gltf = context.gltf, glTFResource = context.glTFResource;
|
|
1147
|
-
var engine = glTFResource.engine, textures = glTFResource.textures;
|
|
1148
|
-
if (!gltf.materials) return;
|
|
1149
|
-
var materialsPromiseInfo = context.materialsPromiseInfo;
|
|
1150
|
-
var materials = [];
|
|
1151
|
-
for(var i = 0; i < gltf.materials.length; i++){
|
|
1152
|
-
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;
|
|
1153
|
-
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;
|
|
1154
|
-
var material = null;
|
|
1155
|
-
if (KHR_materials_unlit) {
|
|
1156
|
-
material = Parser.createEngineResource("KHR_materials_unlit", KHR_materials_unlit, context);
|
|
1157
|
-
} else if (KHR_materials_pbrSpecularGlossiness) {
|
|
1158
|
-
material = Parser.createEngineResource("KHR_materials_pbrSpecularGlossiness", KHR_materials_pbrSpecularGlossiness, context);
|
|
1159
|
-
} else {
|
|
1160
|
-
material = new engineCore.PBRMaterial(engine);
|
|
1161
|
-
}
|
|
1162
|
-
material.name = name;
|
|
1163
|
-
if (KHR_materials_clearcoat) {
|
|
1164
|
-
Parser.parseEngineResource("KHR_materials_clearcoat", KHR_materials_clearcoat, material, context);
|
|
1165
|
-
}
|
|
1166
|
-
if (pbrMetallicRoughness) {
|
|
1167
|
-
var baseColorFactor = pbrMetallicRoughness.baseColorFactor, baseColorTexture = pbrMetallicRoughness.baseColorTexture, metallicFactor = pbrMetallicRoughness.metallicFactor, roughnessFactor = pbrMetallicRoughness.roughnessFactor, metallicRoughnessTexture = pbrMetallicRoughness.metallicRoughnessTexture;
|
|
1168
|
-
if (baseColorFactor) {
|
|
1169
|
-
material.baseColor = new engineMath.Color(engineMath.Color.linearToGammaSpace(baseColorFactor[0]), engineMath.Color.linearToGammaSpace(baseColorFactor[1]), engineMath.Color.linearToGammaSpace(baseColorFactor[2]), baseColorFactor[3]);
|
|
1170
|
-
}
|
|
1171
|
-
if (baseColorTexture) {
|
|
1172
|
-
material.baseTexture = textures[baseColorTexture.index];
|
|
1173
|
-
MaterialParser._parseTextureTransform(material, baseColorTexture.extensions, context);
|
|
1174
|
-
}
|
|
1175
|
-
if (!KHR_materials_unlit && !KHR_materials_pbrSpecularGlossiness) {
|
|
1176
|
-
var m = material;
|
|
1177
|
-
m.metallic = metallicFactor != null ? metallicFactor : 1;
|
|
1178
|
-
m.roughness = roughnessFactor != null ? roughnessFactor : 1;
|
|
1179
|
-
if (metallicRoughnessTexture) {
|
|
1180
|
-
m.roughnessMetallicTexture = textures[metallicRoughnessTexture.index];
|
|
1181
|
-
MaterialParser._parseTextureTransform(material, metallicRoughnessTexture.extensions, context);
|
|
1182
|
-
}
|
|
1183
|
-
}
|
|
1184
|
-
}
|
|
1185
|
-
if (!KHR_materials_unlit) {
|
|
1186
|
-
var m1 = material;
|
|
1187
|
-
if (emissiveTexture) {
|
|
1188
|
-
m1.emissiveTexture = textures[emissiveTexture.index];
|
|
1189
|
-
MaterialParser._parseTextureTransform(material, emissiveTexture.extensions, context);
|
|
1190
|
-
}
|
|
1191
|
-
if (emissiveFactor) {
|
|
1192
|
-
m1.emissiveColor = new engineMath.Color(engineMath.Color.linearToGammaSpace(emissiveFactor[0]), engineMath.Color.linearToGammaSpace(emissiveFactor[1]), engineMath.Color.linearToGammaSpace(emissiveFactor[2]));
|
|
1193
|
-
}
|
|
1194
|
-
if (normalTexture) {
|
|
1195
|
-
var index = normalTexture.index, scale = normalTexture.scale;
|
|
1196
|
-
m1.normalTexture = textures[index];
|
|
1197
|
-
MaterialParser._parseTextureTransform(material, normalTexture.extensions, context);
|
|
1198
|
-
if (scale !== undefined) {
|
|
1199
|
-
m1.normalTextureIntensity = scale;
|
|
1200
|
-
}
|
|
1201
|
-
}
|
|
1202
|
-
if (occlusionTexture) {
|
|
1203
|
-
var index1 = occlusionTexture.index, strength = occlusionTexture.strength, texCoord = occlusionTexture.texCoord;
|
|
1204
|
-
m1.occlusionTexture = textures[index1];
|
|
1205
|
-
MaterialParser._parseTextureTransform(material, occlusionTexture.extensions, context);
|
|
1206
|
-
if (strength !== undefined) {
|
|
1207
|
-
m1.occlusionTextureIntensity = strength;
|
|
1208
|
-
}
|
|
1209
|
-
if (texCoord === engineCore.TextureCoordinate.UV1) {
|
|
1210
|
-
m1.occlusionTextureCoord = engineCore.TextureCoordinate.UV1;
|
|
1211
|
-
} else if (texCoord > engineCore.TextureCoordinate.UV1) {
|
|
1212
|
-
engineCore.Logger.warn("Occlusion texture uv coordinate must be UV0 or UV1.");
|
|
1213
|
-
}
|
|
1363
|
+
/**
|
|
1364
|
+
* @internal
|
|
1365
|
+
*/ GLTFAnimationParser._parseStandardProperty = function _parseStandardProperty(context, animationClip, animationInfo) {
|
|
1366
|
+
var glTF = context.glTF, glTFResource = context.glTFResource;
|
|
1367
|
+
var entities = glTFResource.entities;
|
|
1368
|
+
var accessors = glTF.accessors, bufferViews = glTF.bufferViews;
|
|
1369
|
+
var channels = animationInfo.channels, samplers = animationInfo.samplers;
|
|
1370
|
+
var sampleDataCollection = new Array();
|
|
1371
|
+
// parse samplers
|
|
1372
|
+
for(var j = 0, m = samplers.length; j < m; j++){
|
|
1373
|
+
var gltfSampler = samplers[j];
|
|
1374
|
+
var inputAccessor = accessors[gltfSampler.input];
|
|
1375
|
+
var outputAccessor = accessors[gltfSampler.output];
|
|
1376
|
+
var input = GLTFUtils.getAccessorBuffer(context, bufferViews, inputAccessor).data;
|
|
1377
|
+
var output = GLTFUtils.getAccessorBuffer(context, bufferViews, outputAccessor).data;
|
|
1378
|
+
if (outputAccessor.normalized) {
|
|
1379
|
+
var scale = GLTFUtils.getNormalizedComponentScale(outputAccessor.componentType);
|
|
1380
|
+
var scaled = new Float32Array(output.length);
|
|
1381
|
+
for(var k = 0, v = output.length; k < v; k++){
|
|
1382
|
+
scaled[k] = output[k] * scale;
|
|
1214
1383
|
}
|
|
1384
|
+
output = scaled;
|
|
1215
1385
|
}
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
if (doubleSided) {
|
|
1224
|
-
material.renderFace = engineCore.RenderFace.Double;
|
|
1225
|
-
} else {
|
|
1226
|
-
material.renderFace = engineCore.RenderFace.Front;
|
|
1227
|
-
}
|
|
1228
|
-
switch(alphaMode){
|
|
1229
|
-
case MaterialAlphaMode.OPAQUE:
|
|
1230
|
-
material.isTransparent = false;
|
|
1386
|
+
var outputStride = output.length / input.length;
|
|
1387
|
+
var _gltfSampler_interpolation;
|
|
1388
|
+
var interpolation = (_gltfSampler_interpolation = gltfSampler.interpolation) != null ? _gltfSampler_interpolation : AnimationSamplerInterpolation.Linear;
|
|
1389
|
+
var samplerInterpolation = void 0;
|
|
1390
|
+
switch(interpolation){
|
|
1391
|
+
case AnimationSamplerInterpolation.CubicSpine:
|
|
1392
|
+
samplerInterpolation = engineCore.InterpolationType.CubicSpine;
|
|
1231
1393
|
break;
|
|
1232
|
-
case
|
|
1233
|
-
|
|
1394
|
+
case AnimationSamplerInterpolation.Step:
|
|
1395
|
+
samplerInterpolation = engineCore.InterpolationType.Step;
|
|
1234
1396
|
break;
|
|
1235
|
-
case
|
|
1236
|
-
|
|
1397
|
+
case AnimationSamplerInterpolation.Linear:
|
|
1398
|
+
samplerInterpolation = engineCore.InterpolationType.Linear;
|
|
1237
1399
|
break;
|
|
1238
1400
|
}
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
if (extensions === void 0) extensions = {};
|
|
1247
|
-
var schema = extensions.KHR_texture_transform;
|
|
1248
|
-
if (schema) {
|
|
1249
|
-
Parser.parseEngineResource("KHR_texture_transform", schema, material, context);
|
|
1250
|
-
}
|
|
1251
|
-
};
|
|
1252
|
-
return MaterialParser;
|
|
1253
|
-
}(Parser);
|
|
1254
|
-
|
|
1255
|
-
var KHR_materials_clearcoat = /*#__PURE__*/ function(ExtensionParser) {
|
|
1256
|
-
_inherits(KHR_materials_clearcoat, ExtensionParser);
|
|
1257
|
-
function KHR_materials_clearcoat() {
|
|
1258
|
-
return ExtensionParser.apply(this, arguments);
|
|
1259
|
-
}
|
|
1260
|
-
var _proto = KHR_materials_clearcoat.prototype;
|
|
1261
|
-
_proto.parseEngineResource = function parseEngineResource(schema, material, context) {
|
|
1262
|
-
var textures = context.glTFResource.textures;
|
|
1263
|
-
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;
|
|
1264
|
-
material.clearCoat = clearcoatFactor;
|
|
1265
|
-
material.clearCoatRoughness = clearcoatRoughnessFactor;
|
|
1266
|
-
if (clearcoatTexture) {
|
|
1267
|
-
material.clearCoatTexture = textures[clearcoatTexture.index];
|
|
1268
|
-
MaterialParser._parseTextureTransform(material, clearcoatTexture.extensions, context);
|
|
1269
|
-
}
|
|
1270
|
-
if (clearcoatRoughnessTexture) {
|
|
1271
|
-
material.clearCoatRoughnessTexture = textures[clearcoatRoughnessTexture.index];
|
|
1272
|
-
MaterialParser._parseTextureTransform(material, clearcoatRoughnessTexture.extensions, context);
|
|
1273
|
-
}
|
|
1274
|
-
if (clearcoatNormalTexture) {
|
|
1275
|
-
material.clearCoatNormalTexture = textures[clearcoatNormalTexture.index];
|
|
1276
|
-
MaterialParser._parseTextureTransform(material, clearcoatNormalTexture.extensions, context);
|
|
1277
|
-
}
|
|
1278
|
-
};
|
|
1279
|
-
return KHR_materials_clearcoat;
|
|
1280
|
-
}(ExtensionParser);
|
|
1281
|
-
KHR_materials_clearcoat = __decorate([
|
|
1282
|
-
registerExtension("KHR_materials_clearcoat")
|
|
1283
|
-
], KHR_materials_clearcoat);
|
|
1284
|
-
|
|
1285
|
-
var KHR_materials_pbrSpecularGlossiness = /*#__PURE__*/ function(ExtensionParser) {
|
|
1286
|
-
_inherits(KHR_materials_pbrSpecularGlossiness, ExtensionParser);
|
|
1287
|
-
function KHR_materials_pbrSpecularGlossiness() {
|
|
1288
|
-
return ExtensionParser.apply(this, arguments);
|
|
1289
|
-
}
|
|
1290
|
-
var _proto = KHR_materials_pbrSpecularGlossiness.prototype;
|
|
1291
|
-
_proto.createEngineResource = function createEngineResource(schema, context) {
|
|
1292
|
-
var _context_glTFResource = context.glTFResource, engine = _context_glTFResource.engine, textures = _context_glTFResource.textures;
|
|
1293
|
-
var material = new engineCore.PBRSpecularMaterial(engine);
|
|
1294
|
-
var diffuseFactor = schema.diffuseFactor, diffuseTexture = schema.diffuseTexture, specularFactor = schema.specularFactor, glossinessFactor = schema.glossinessFactor, specularGlossinessTexture = schema.specularGlossinessTexture;
|
|
1295
|
-
if (diffuseFactor) {
|
|
1296
|
-
material.baseColor = new engineMath.Color(engineMath.Color.linearToGammaSpace(diffuseFactor[0]), engineMath.Color.linearToGammaSpace(diffuseFactor[1]), engineMath.Color.linearToGammaSpace(diffuseFactor[2]), diffuseFactor[3]);
|
|
1297
|
-
}
|
|
1298
|
-
if (diffuseTexture) {
|
|
1299
|
-
material.baseTexture = textures[diffuseTexture.index];
|
|
1300
|
-
MaterialParser._parseTextureTransform(material, diffuseTexture.extensions, context);
|
|
1301
|
-
}
|
|
1302
|
-
if (specularFactor) {
|
|
1303
|
-
material.specularColor = new engineMath.Color(engineMath.Color.linearToGammaSpace(specularFactor[0]), engineMath.Color.linearToGammaSpace(specularFactor[1]), engineMath.Color.linearToGammaSpace(specularFactor[2]));
|
|
1304
|
-
}
|
|
1305
|
-
if (glossinessFactor !== undefined) {
|
|
1306
|
-
material.glossiness = glossinessFactor;
|
|
1307
|
-
}
|
|
1308
|
-
if (specularGlossinessTexture) {
|
|
1309
|
-
material.specularGlossinessTexture = textures[specularGlossinessTexture.index];
|
|
1310
|
-
MaterialParser._parseTextureTransform(material, specularGlossinessTexture.extensions, context);
|
|
1311
|
-
}
|
|
1312
|
-
return material;
|
|
1313
|
-
};
|
|
1314
|
-
return KHR_materials_pbrSpecularGlossiness;
|
|
1315
|
-
}(ExtensionParser);
|
|
1316
|
-
KHR_materials_pbrSpecularGlossiness = __decorate([
|
|
1317
|
-
registerExtension("KHR_materials_pbrSpecularGlossiness")
|
|
1318
|
-
], KHR_materials_pbrSpecularGlossiness);
|
|
1319
|
-
|
|
1320
|
-
var KHR_materials_unlit = /*#__PURE__*/ function(ExtensionParser) {
|
|
1321
|
-
_inherits(KHR_materials_unlit, ExtensionParser);
|
|
1322
|
-
function KHR_materials_unlit() {
|
|
1323
|
-
return ExtensionParser.apply(this, arguments);
|
|
1324
|
-
}
|
|
1325
|
-
var _proto = KHR_materials_unlit.prototype;
|
|
1326
|
-
_proto.createEngineResource = function createEngineResource(schema, context) {
|
|
1327
|
-
var engine = context.glTFResource.engine;
|
|
1328
|
-
var material = new engineCore.UnlitMaterial(engine);
|
|
1329
|
-
return material;
|
|
1330
|
-
};
|
|
1331
|
-
return KHR_materials_unlit;
|
|
1332
|
-
}(ExtensionParser);
|
|
1333
|
-
KHR_materials_unlit = __decorate([
|
|
1334
|
-
registerExtension("KHR_materials_unlit")
|
|
1335
|
-
], KHR_materials_unlit);
|
|
1336
|
-
|
|
1337
|
-
var KHR_materials_variants = /*#__PURE__*/ function(ExtensionParser) {
|
|
1338
|
-
_inherits(KHR_materials_variants, ExtensionParser);
|
|
1339
|
-
function KHR_materials_variants() {
|
|
1340
|
-
return ExtensionParser.apply(this, arguments);
|
|
1341
|
-
}
|
|
1342
|
-
var _proto = KHR_materials_variants.prototype;
|
|
1343
|
-
_proto.parseEngineResource = function parseEngineResource(schema, renderer, context) {
|
|
1344
|
-
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;
|
|
1345
|
-
var mappings = schema.mappings;
|
|
1346
|
-
for(var i = 0; i < mappings.length; i++){
|
|
1347
|
-
var _mappings_i = mappings[i], material = _mappings_i.material, variants = _mappings_i.variants;
|
|
1348
|
-
if (!glTFResource.variants) glTFResource.variants = [];
|
|
1349
|
-
glTFResource.variants.push({
|
|
1350
|
-
renderer: renderer,
|
|
1351
|
-
material: glTFResource.materials[material],
|
|
1352
|
-
variants: variants.map(function(index) {
|
|
1353
|
-
return variantNames[index].name;
|
|
1354
|
-
})
|
|
1401
|
+
input[input.length - 1];
|
|
1402
|
+
sampleDataCollection.push({
|
|
1403
|
+
type: outputAccessor.type,
|
|
1404
|
+
interpolation: samplerInterpolation,
|
|
1405
|
+
input: input,
|
|
1406
|
+
output: output,
|
|
1407
|
+
outputSize: outputStride
|
|
1355
1408
|
});
|
|
1356
1409
|
}
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
function KHR_mesh_quantization() {
|
|
1367
|
-
return ExtensionParser.apply(this, arguments);
|
|
1368
|
-
}
|
|
1369
|
-
return KHR_mesh_quantization;
|
|
1370
|
-
}(ExtensionParser);
|
|
1371
|
-
KHR_mesh_quantization = __decorate([
|
|
1372
|
-
registerExtension("KHR_mesh_quantization")
|
|
1373
|
-
], KHR_mesh_quantization);
|
|
1374
|
-
|
|
1375
|
-
var KHR_texture_transform = /*#__PURE__*/ function(ExtensionParser) {
|
|
1376
|
-
_inherits(KHR_texture_transform, ExtensionParser);
|
|
1377
|
-
function KHR_texture_transform() {
|
|
1378
|
-
return ExtensionParser.apply(this, arguments);
|
|
1379
|
-
}
|
|
1380
|
-
var _proto = KHR_texture_transform.prototype;
|
|
1381
|
-
_proto.parseEngineResource = function parseEngineResource(schema, material, context) {
|
|
1382
|
-
var offset = schema.offset, rotation = schema.rotation, scale = schema.scale, texCoord = schema.texCoord;
|
|
1383
|
-
if (offset) {
|
|
1384
|
-
material.tilingOffset.z = offset[0];
|
|
1385
|
-
material.tilingOffset.w = offset[1];
|
|
1386
|
-
}
|
|
1387
|
-
if (scale) {
|
|
1388
|
-
material.tilingOffset.x = scale[0];
|
|
1389
|
-
material.tilingOffset.y = scale[1];
|
|
1390
|
-
}
|
|
1391
|
-
if (rotation) {
|
|
1392
|
-
engineCore.Logger.warn("rotation in KHR_texture_transform is not supported now");
|
|
1393
|
-
}
|
|
1394
|
-
if (texCoord) {
|
|
1395
|
-
engineCore.Logger.warn("texCoord in KHR_texture_transform is not supported now");
|
|
1396
|
-
}
|
|
1397
|
-
};
|
|
1398
|
-
return KHR_texture_transform;
|
|
1399
|
-
}(ExtensionParser);
|
|
1400
|
-
KHR_texture_transform = __decorate([
|
|
1401
|
-
registerExtension("KHR_texture_transform")
|
|
1402
|
-
], KHR_texture_transform);
|
|
1403
|
-
|
|
1404
|
-
var GalaceanMaterialsRemap = /*#__PURE__*/ function(ExtensionParser) {
|
|
1405
|
-
_inherits(GalaceanMaterialsRemap, ExtensionParser);
|
|
1406
|
-
function GalaceanMaterialsRemap() {
|
|
1407
|
-
return ExtensionParser.apply(this, arguments);
|
|
1408
|
-
}
|
|
1409
|
-
var _proto = GalaceanMaterialsRemap.prototype;
|
|
1410
|
-
_proto.createEngineResource = function createEngineResource(schema, context) {
|
|
1411
|
-
var engine = context.glTFResource.engine;
|
|
1412
|
-
// @ts-ignore
|
|
1413
|
-
return engine.resourceManager.getResourceByRef(schema);
|
|
1414
|
-
};
|
|
1415
|
-
return GalaceanMaterialsRemap;
|
|
1416
|
-
}(ExtensionParser);
|
|
1417
|
-
GalaceanMaterialsRemap = __decorate([
|
|
1418
|
-
registerExtension("OASIS_materials_remap")
|
|
1419
|
-
], GalaceanMaterialsRemap);
|
|
1420
|
-
|
|
1421
|
-
function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
|
|
1422
|
-
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
1423
|
-
|
|
1424
|
-
if (it) return (it = it.call(o)).next.bind(it);
|
|
1425
|
-
// Fallback for engines without symbol support
|
|
1426
|
-
if (Array.isArray(o) || (it = _unsupported_iterable_to_array(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
1427
|
-
if (it) o = it;
|
|
1428
|
-
|
|
1429
|
-
var i = 0;
|
|
1430
|
-
|
|
1431
|
-
return function() {
|
|
1432
|
-
if (i >= o.length) return { done: true };
|
|
1433
|
-
|
|
1434
|
-
return { done: false, value: o[i++] };
|
|
1435
|
-
};
|
|
1436
|
-
}
|
|
1437
|
-
|
|
1438
|
-
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
1439
|
-
}
|
|
1440
|
-
|
|
1441
|
-
var AnimationParser = /*#__PURE__*/ function(Parser) {
|
|
1442
|
-
_inherits(AnimationParser, Parser);
|
|
1443
|
-
function AnimationParser() {
|
|
1444
|
-
return Parser.apply(this, arguments);
|
|
1445
|
-
}
|
|
1446
|
-
var _proto = AnimationParser.prototype;
|
|
1447
|
-
_proto.parse = function parse(context) {
|
|
1448
|
-
var gltf = context.gltf; context.buffers; var glTFResource = context.glTFResource;
|
|
1449
|
-
var entities = glTFResource.entities;
|
|
1450
|
-
var animations = gltf.animations, accessors = gltf.accessors;
|
|
1451
|
-
if (!animations) {
|
|
1452
|
-
return;
|
|
1453
|
-
}
|
|
1454
|
-
var animationClipsPromiseInfo = context.animationClipsPromiseInfo;
|
|
1455
|
-
var animationClipCount = animations.length;
|
|
1456
|
-
var animationClips = new Array(animationClipCount);
|
|
1457
|
-
var animationsIndices = new Array(animationClipCount);
|
|
1458
|
-
for(var i = 0; i < animationClipCount; i++){
|
|
1459
|
-
var gltfAnimation = animations[i];
|
|
1460
|
-
var channels = gltfAnimation.channels, samplers = gltfAnimation.samplers, _gltfAnimation_name = gltfAnimation.name, name = _gltfAnimation_name === void 0 ? "AnimationClip" + i : _gltfAnimation_name;
|
|
1461
|
-
var animationClip = new engineCore.AnimationClip(name);
|
|
1462
|
-
var sampleDataCollection = new Array();
|
|
1463
|
-
// parse samplers
|
|
1464
|
-
for(var j = 0, m = samplers.length; j < m; j++){
|
|
1465
|
-
var gltfSampler = samplers[j];
|
|
1466
|
-
var inputAccessor = accessors[gltfSampler.input];
|
|
1467
|
-
var outputAccessor = accessors[gltfSampler.output];
|
|
1468
|
-
var input = GLTFUtil.getAccessorBuffer(context, gltf, inputAccessor).data;
|
|
1469
|
-
var output = GLTFUtil.getAccessorBuffer(context, gltf, outputAccessor).data;
|
|
1470
|
-
if (outputAccessor.normalized) {
|
|
1471
|
-
var scale = GLTFUtil.getNormalizedComponentScale(outputAccessor.componentType);
|
|
1472
|
-
var scaled = new Float32Array(output.length);
|
|
1473
|
-
for(var k = 0, v = output.length; k < v; k++){
|
|
1474
|
-
scaled[k] = output[k] * scale;
|
|
1475
|
-
}
|
|
1476
|
-
output = scaled;
|
|
1477
|
-
}
|
|
1478
|
-
var outputStride = output.length / input.length;
|
|
1479
|
-
var _gltfSampler_interpolation;
|
|
1480
|
-
var interpolation = (_gltfSampler_interpolation = gltfSampler.interpolation) != null ? _gltfSampler_interpolation : AnimationSamplerInterpolation.Linear;
|
|
1481
|
-
var samplerInterpolation = void 0;
|
|
1482
|
-
switch(interpolation){
|
|
1483
|
-
case AnimationSamplerInterpolation.CubicSpine:
|
|
1484
|
-
samplerInterpolation = engineCore.InterpolationType.CubicSpine;
|
|
1485
|
-
break;
|
|
1486
|
-
case AnimationSamplerInterpolation.Step:
|
|
1487
|
-
samplerInterpolation = engineCore.InterpolationType.Step;
|
|
1488
|
-
break;
|
|
1489
|
-
case AnimationSamplerInterpolation.Linear:
|
|
1490
|
-
samplerInterpolation = engineCore.InterpolationType.Linear;
|
|
1491
|
-
break;
|
|
1492
|
-
}
|
|
1493
|
-
input[input.length - 1];
|
|
1494
|
-
sampleDataCollection.push({
|
|
1495
|
-
type: outputAccessor.type,
|
|
1496
|
-
interpolation: samplerInterpolation,
|
|
1497
|
-
input: input,
|
|
1498
|
-
output: output,
|
|
1499
|
-
outputSize: outputStride
|
|
1500
|
-
});
|
|
1410
|
+
for(var j1 = 0, m1 = channels.length; j1 < m1; j1++){
|
|
1411
|
+
var gltfChannel = channels[j1];
|
|
1412
|
+
var target = gltfChannel.target;
|
|
1413
|
+
var channelTargetEntity = entities[target.node];
|
|
1414
|
+
var relativePath = "";
|
|
1415
|
+
var entity = channelTargetEntity;
|
|
1416
|
+
while(entity.parent){
|
|
1417
|
+
relativePath = relativePath === "" ? "" + entity.name : entity.name + "/" + relativePath;
|
|
1418
|
+
entity = entity.parent;
|
|
1501
1419
|
}
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
propertyName = "rotationQuaternion";
|
|
1522
|
-
break;
|
|
1523
|
-
case AnimationChannelTargetPath.SCALE:
|
|
1524
|
-
ComponentType = engineCore.Transform;
|
|
1525
|
-
propertyName = "scale";
|
|
1526
|
-
break;
|
|
1527
|
-
case AnimationChannelTargetPath.WEIGHTS:
|
|
1528
|
-
ComponentType = engineCore.SkinnedMeshRenderer;
|
|
1529
|
-
propertyName = "blendShapeWeights";
|
|
1530
|
-
break;
|
|
1531
|
-
}
|
|
1532
|
-
var curve = this._addCurve(target.path, gltfChannel, sampleDataCollection);
|
|
1533
|
-
animationClip.addCurveBinding(relativePath, ComponentType, propertyName, curve);
|
|
1420
|
+
var ComponentType = void 0;
|
|
1421
|
+
var propertyName = void 0;
|
|
1422
|
+
switch(target.path){
|
|
1423
|
+
case AnimationChannelTargetPath.TRANSLATION:
|
|
1424
|
+
ComponentType = engineCore.Transform;
|
|
1425
|
+
propertyName = "position";
|
|
1426
|
+
break;
|
|
1427
|
+
case AnimationChannelTargetPath.ROTATION:
|
|
1428
|
+
ComponentType = engineCore.Transform;
|
|
1429
|
+
propertyName = "rotationQuaternion";
|
|
1430
|
+
break;
|
|
1431
|
+
case AnimationChannelTargetPath.SCALE:
|
|
1432
|
+
ComponentType = engineCore.Transform;
|
|
1433
|
+
propertyName = "scale";
|
|
1434
|
+
break;
|
|
1435
|
+
case AnimationChannelTargetPath.WEIGHTS:
|
|
1436
|
+
ComponentType = engineCore.SkinnedMeshRenderer;
|
|
1437
|
+
propertyName = "blendShapeWeights";
|
|
1438
|
+
break;
|
|
1534
1439
|
}
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
name: name,
|
|
1538
|
-
index: i
|
|
1539
|
-
};
|
|
1440
|
+
var curve = this._addCurve(target.path, gltfChannel, sampleDataCollection);
|
|
1441
|
+
animationClip.addCurveBinding(relativePath, ComponentType, propertyName, curve);
|
|
1540
1442
|
}
|
|
1541
|
-
glTFResource.animations = animationClips;
|
|
1542
|
-
// @ts-ignore for editor
|
|
1543
|
-
glTFResource._animationsIndices = animationsIndices;
|
|
1544
|
-
animationClipsPromiseInfo.resolve(animationClips);
|
|
1545
|
-
return animationClipsPromiseInfo.promise;
|
|
1546
1443
|
};
|
|
1547
|
-
|
|
1444
|
+
GLTFAnimationParser._addCurve = function _addCurve(animationChannelTargetPath, gltfChannel, sampleDataCollection) {
|
|
1548
1445
|
var sampleData = sampleDataCollection[gltfChannel.sampler];
|
|
1549
1446
|
var input = sampleData.input, output = sampleData.output, outputSize = sampleData.outputSize;
|
|
1550
|
-
switch(
|
|
1447
|
+
switch(animationChannelTargetPath){
|
|
1551
1448
|
case AnimationChannelTargetPath.TRANSLATION:
|
|
1552
1449
|
case AnimationChannelTargetPath.SCALE:
|
|
1553
1450
|
{
|
|
@@ -1612,35 +1509,42 @@ var AnimationParser = /*#__PURE__*/ function(Parser) {
|
|
|
1612
1509
|
}
|
|
1613
1510
|
}
|
|
1614
1511
|
};
|
|
1615
|
-
return
|
|
1616
|
-
}(
|
|
1512
|
+
return GLTFAnimationParser;
|
|
1513
|
+
}(GLTFParser);
|
|
1617
1514
|
|
|
1618
|
-
var
|
|
1619
|
-
_inherits(
|
|
1620
|
-
function
|
|
1621
|
-
return
|
|
1515
|
+
var GLTFBufferParser = /*#__PURE__*/ function(GLTFParser) {
|
|
1516
|
+
_inherits(GLTFBufferParser, GLTFParser);
|
|
1517
|
+
function GLTFBufferParser() {
|
|
1518
|
+
return GLTFParser.apply(this, arguments);
|
|
1622
1519
|
}
|
|
1623
|
-
var _proto =
|
|
1520
|
+
var _proto = GLTFBufferParser.prototype;
|
|
1624
1521
|
_proto.parse = function parse(context) {
|
|
1625
|
-
var glTFResource = context.glTFResource;
|
|
1522
|
+
var glTFResource = context.glTFResource, contentRestorer = context.contentRestorer;
|
|
1626
1523
|
var url = glTFResource.url;
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1524
|
+
var restoreBufferRequests = contentRestorer.bufferRequests;
|
|
1525
|
+
var requestConfig = {
|
|
1526
|
+
type: "arraybuffer"
|
|
1527
|
+
};
|
|
1528
|
+
var isGLB = this._isGLB(url);
|
|
1529
|
+
contentRestorer.isGLB = isGLB;
|
|
1530
|
+
if (isGLB) {
|
|
1531
|
+
return engineCore.request(url, requestConfig).then(function(glb) {
|
|
1532
|
+
restoreBufferRequests.push(new BufferRequestInfo(url, requestConfig));
|
|
1533
|
+
return GLTFUtils.parseGLB(context, glb);
|
|
1534
|
+
}).then(function(param) {
|
|
1535
|
+
var glTF = param.glTF, buffers = param.buffers;
|
|
1536
|
+
context.glTF = glTF;
|
|
1633
1537
|
context.buffers = buffers;
|
|
1634
1538
|
});
|
|
1635
1539
|
} else {
|
|
1636
1540
|
return engineCore.request(url, {
|
|
1637
1541
|
type: "json"
|
|
1638
|
-
}).then(function(
|
|
1639
|
-
context.
|
|
1640
|
-
return Promise.all(
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1542
|
+
}).then(function(glTF) {
|
|
1543
|
+
context.glTF = glTF;
|
|
1544
|
+
return Promise.all(glTF.buffers.map(function(buffer) {
|
|
1545
|
+
var absoluteUrl = engineCore.Utils.resolveAbsoluteUrl(url, buffer.uri);
|
|
1546
|
+
restoreBufferRequests.push(new BufferRequestInfo(absoluteUrl, requestConfig));
|
|
1547
|
+
return engineCore.request(absoluteUrl, requestConfig);
|
|
1644
1548
|
})).then(function(buffers) {
|
|
1645
1549
|
context.buffers = buffers;
|
|
1646
1550
|
});
|
|
@@ -1651,24 +1555,24 @@ var BufferParser = /*#__PURE__*/ function(Parser) {
|
|
|
1651
1555
|
var index = url.lastIndexOf(".");
|
|
1652
1556
|
return url.substring(index + 1, index + 4) === "glb";
|
|
1653
1557
|
};
|
|
1654
|
-
return
|
|
1655
|
-
}(
|
|
1558
|
+
return GLTFBufferParser;
|
|
1559
|
+
}(GLTFParser);
|
|
1656
1560
|
|
|
1657
|
-
var
|
|
1658
|
-
_inherits(
|
|
1659
|
-
function
|
|
1660
|
-
return
|
|
1561
|
+
var GLTFEntityParser = /*#__PURE__*/ function(GLTFParser) {
|
|
1562
|
+
_inherits(GLTFEntityParser, GLTFParser);
|
|
1563
|
+
function GLTFEntityParser() {
|
|
1564
|
+
return GLTFParser.apply(this, arguments);
|
|
1661
1565
|
}
|
|
1662
|
-
var _proto =
|
|
1566
|
+
var _proto = GLTFEntityParser.prototype;
|
|
1663
1567
|
_proto.parse = function parse(context) {
|
|
1664
|
-
var glTFResource = context.glTFResource, nodes = context.
|
|
1568
|
+
var glTFResource = context.glTFResource, nodes = context.glTF.nodes;
|
|
1665
1569
|
var engine = glTFResource.engine;
|
|
1666
1570
|
if (!nodes) return;
|
|
1667
1571
|
var entities = [];
|
|
1668
1572
|
for(var i = 0; i < nodes.length; i++){
|
|
1669
1573
|
var gltfNode = nodes[i];
|
|
1670
1574
|
var matrix = gltfNode.matrix, translation = gltfNode.translation, rotation = gltfNode.rotation, scale = gltfNode.scale;
|
|
1671
|
-
var entity = new engineCore.Entity(engine, gltfNode.name || "" +
|
|
1575
|
+
var entity = new engineCore.Entity(engine, gltfNode.name || "" + GLTFEntityParser._defaultName + i);
|
|
1672
1576
|
var transform = entity.transform;
|
|
1673
1577
|
if (matrix) {
|
|
1674
1578
|
var localMatrix = transform.localMatrix;
|
|
@@ -1692,7 +1596,7 @@ var EntityParser = /*#__PURE__*/ function(Parser) {
|
|
|
1692
1596
|
this._createSceneRoots(context, glTFResource);
|
|
1693
1597
|
};
|
|
1694
1598
|
_proto._buildEntityTree = function _buildEntityTree(context, glTFResource) {
|
|
1695
|
-
var nodes = context.
|
|
1599
|
+
var nodes = context.glTF.nodes;
|
|
1696
1600
|
var entities = glTFResource.entities;
|
|
1697
1601
|
for(var i = 0; i < nodes.length; i++){
|
|
1698
1602
|
var children = nodes[i].children;
|
|
@@ -1706,7 +1610,7 @@ var EntityParser = /*#__PURE__*/ function(Parser) {
|
|
|
1706
1610
|
}
|
|
1707
1611
|
};
|
|
1708
1612
|
_proto._createSceneRoots = function _createSceneRoots(context, glTFResource) {
|
|
1709
|
-
var
|
|
1613
|
+
var _context_glTF = context.glTF, tmp = _context_glTF.scene, sceneID = tmp === void 0 ? 0 : tmp, scenes = _context_glTF.scenes;
|
|
1710
1614
|
var engine = glTFResource.engine, entities = glTFResource.entities;
|
|
1711
1615
|
if (!scenes) return;
|
|
1712
1616
|
var sceneRoots = [];
|
|
@@ -1726,79 +1630,193 @@ var EntityParser = /*#__PURE__*/ function(Parser) {
|
|
|
1726
1630
|
glTFResource.sceneRoots = sceneRoots;
|
|
1727
1631
|
glTFResource.defaultSceneRoot = sceneRoots[sceneID];
|
|
1728
1632
|
};
|
|
1729
|
-
return
|
|
1730
|
-
}(
|
|
1633
|
+
return GLTFEntityParser;
|
|
1634
|
+
}(GLTFParser);
|
|
1731
1635
|
(function() {
|
|
1732
|
-
/** @internal */
|
|
1636
|
+
/** @internal */ GLTFEntityParser._defaultName = "_GLTF_ENTITY_";
|
|
1733
1637
|
})();
|
|
1734
1638
|
|
|
1735
|
-
var
|
|
1736
|
-
_inherits(
|
|
1737
|
-
function
|
|
1738
|
-
return
|
|
1639
|
+
var GLTFMaterialParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
1640
|
+
_inherits(GLTFMaterialParser, GLTFParser1);
|
|
1641
|
+
function GLTFMaterialParser() {
|
|
1642
|
+
return GLTFParser1.apply(this, arguments);
|
|
1739
1643
|
}
|
|
1740
|
-
var _proto =
|
|
1644
|
+
var _proto = GLTFMaterialParser.prototype;
|
|
1741
1645
|
_proto.parse = function parse(context) {
|
|
1742
|
-
var
|
|
1743
|
-
|
|
1744
|
-
var gltfPrimitive = gltfMesh.primitives[j];
|
|
1745
|
-
var _gltfPrimitive_extensions = gltfPrimitive.extensions, extensions = _gltfPrimitive_extensions === void 0 ? {} : _gltfPrimitive_extensions;
|
|
1746
|
-
var KHR_draco_mesh_compression = extensions.KHR_draco_mesh_compression;
|
|
1747
|
-
primitivePromises[j] = new Promise(function(resolve) {
|
|
1748
|
-
var mesh = new engineCore.ModelMesh(engine, gltfMesh.name || j + "");
|
|
1749
|
-
if (KHR_draco_mesh_compression) {
|
|
1750
|
-
Parser.createEngineResource("KHR_draco_mesh_compression", KHR_draco_mesh_compression, context, gltfPrimitive).then(function(decodedGeometry) {
|
|
1751
|
-
return _this._parseMeshFromGLTFPrimitiveDraco(mesh, gltfMesh, gltfPrimitive, gltf, function(attributeSemantic) {
|
|
1752
|
-
for(var j = 0; j < decodedGeometry.attributes.length; j++){
|
|
1753
|
-
if (decodedGeometry.attributes[j].name === attributeSemantic) {
|
|
1754
|
-
return decodedGeometry.attributes[j].array;
|
|
1755
|
-
}
|
|
1756
|
-
}
|
|
1757
|
-
return null;
|
|
1758
|
-
}, function(attributeSemantic, shapeIndex) {
|
|
1759
|
-
throw "BlendShape animation is not supported when using draco.";
|
|
1760
|
-
}, function() {
|
|
1761
|
-
return decodedGeometry.index.array;
|
|
1762
|
-
}, context.keepMeshData);
|
|
1763
|
-
}).then(resolve);
|
|
1764
|
-
} else {
|
|
1765
|
-
_this._parseMeshFromGLTFPrimitive(context, mesh, gltfMesh, gltfPrimitive, gltf, function(attributeSemantic) {
|
|
1766
|
-
return null;
|
|
1767
|
-
}, function(attributeName, shapeIndex) {
|
|
1768
|
-
var shapeAccessorIdx = gltfPrimitive.targets[shapeIndex];
|
|
1769
|
-
var attributeAccessorIdx = shapeAccessorIdx[attributeName];
|
|
1770
|
-
if (attributeAccessorIdx) {
|
|
1771
|
-
var accessor = gltf.accessors[attributeAccessorIdx];
|
|
1772
|
-
return GLTFUtil.getAccessorData(gltf, accessor, buffers);
|
|
1773
|
-
} else {
|
|
1774
|
-
return null;
|
|
1775
|
-
}
|
|
1776
|
-
}, function() {
|
|
1777
|
-
var indexAccessor = gltf.accessors[gltfPrimitive.indices];
|
|
1778
|
-
return GLTFUtil.getAccessorData(gltf, indexAccessor, buffers);
|
|
1779
|
-
}, context.keepMeshData).then(resolve);
|
|
1780
|
-
}
|
|
1781
|
-
});
|
|
1782
|
-
};
|
|
1783
|
-
var gltfMesh = gltf.meshes[i];
|
|
1784
|
-
var primitivePromises = [];
|
|
1785
|
-
for(var j = 0; j < gltfMesh.primitives.length; j++)_loop(j);
|
|
1786
|
-
meshPromises[i] = Promise.all(primitivePromises);
|
|
1787
|
-
};
|
|
1788
|
-
var _this = this;
|
|
1789
|
-
var gltf = context.gltf, buffers = context.buffers, glTFResource = context.glTFResource;
|
|
1646
|
+
var glTF = context.glTF, glTFResource = context.glTFResource, materialsPromiseInfo = context.materialsPromiseInfo;
|
|
1647
|
+
if (!glTF.materials) return;
|
|
1790
1648
|
var engine = glTFResource.engine;
|
|
1791
|
-
|
|
1792
|
-
var
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1649
|
+
var materialPromises = [];
|
|
1650
|
+
for(var i = 0; i < glTF.materials.length; i++){
|
|
1651
|
+
var materialInfo = glTF.materials[i];
|
|
1652
|
+
var material = GLTFParser.executeExtensionsCreateAndParse(materialInfo.extensions, context, materialInfo);
|
|
1653
|
+
if (!material) {
|
|
1654
|
+
material = new engineCore.PBRMaterial(engine);
|
|
1655
|
+
material.name = materialInfo.name;
|
|
1656
|
+
GLTFMaterialParser._parseStandardProperty(context, material, materialInfo);
|
|
1657
|
+
}
|
|
1658
|
+
materialPromises.push(material);
|
|
1659
|
+
}
|
|
1660
|
+
return engineCore.AssetPromise.all(materialPromises).then(function(materials) {
|
|
1661
|
+
glTFResource.materials = materials;
|
|
1662
|
+
for(var i = 0; i < glTF.materials.length; i++){
|
|
1663
|
+
var materialInfo = glTF.materials[i];
|
|
1664
|
+
GLTFParser.executeExtensionsAdditiveAndParse(materialInfo.extensions, context, materials[i], materialInfo);
|
|
1665
|
+
}
|
|
1666
|
+
materialsPromiseInfo.resolve(materials);
|
|
1667
|
+
return materialsPromiseInfo.promise;
|
|
1668
|
+
});
|
|
1800
1669
|
};
|
|
1801
|
-
|
|
1670
|
+
/**
|
|
1671
|
+
* @internal
|
|
1672
|
+
*/ GLTFMaterialParser._checkOtherTextureTransform = function _checkOtherTextureTransform(texture, textureName) {
|
|
1673
|
+
var _texture_extensions;
|
|
1674
|
+
if ((_texture_extensions = texture.extensions) == null ? void 0 : _texture_extensions.KHR_texture_transform) {
|
|
1675
|
+
engineCore.Logger.warn("" + textureName + " texture always use the KHR_texture_transform of the base texture.");
|
|
1676
|
+
}
|
|
1677
|
+
};
|
|
1678
|
+
/**
|
|
1679
|
+
* @internal
|
|
1680
|
+
*/ GLTFMaterialParser._parseStandardProperty = function _parseStandardProperty(context, material, materialInfo) {
|
|
1681
|
+
var textures = context.glTFResource.textures;
|
|
1682
|
+
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;
|
|
1683
|
+
if (pbrMetallicRoughness) {
|
|
1684
|
+
var baseColorFactor = pbrMetallicRoughness.baseColorFactor, baseColorTexture = pbrMetallicRoughness.baseColorTexture, metallicFactor = pbrMetallicRoughness.metallicFactor, roughnessFactor = pbrMetallicRoughness.roughnessFactor, metallicRoughnessTexture = pbrMetallicRoughness.metallicRoughnessTexture;
|
|
1685
|
+
if (baseColorFactor) {
|
|
1686
|
+
material.baseColor = new engineMath.Color(engineMath.Color.linearToGammaSpace(baseColorFactor[0]), engineMath.Color.linearToGammaSpace(baseColorFactor[1]), engineMath.Color.linearToGammaSpace(baseColorFactor[2]), baseColorFactor[3]);
|
|
1687
|
+
}
|
|
1688
|
+
if (baseColorTexture) {
|
|
1689
|
+
material.baseTexture = textures[baseColorTexture.index];
|
|
1690
|
+
GLTFParser.executeExtensionsAdditiveAndParse(baseColorTexture.extensions, context, material, baseColorTexture);
|
|
1691
|
+
}
|
|
1692
|
+
if (material.constructor === engineCore.PBRMaterial) {
|
|
1693
|
+
material.metallic = metallicFactor != null ? metallicFactor : 1;
|
|
1694
|
+
material.roughness = roughnessFactor != null ? roughnessFactor : 1;
|
|
1695
|
+
if (metallicRoughnessTexture) {
|
|
1696
|
+
material.roughnessMetallicTexture = textures[metallicRoughnessTexture.index];
|
|
1697
|
+
GLTFMaterialParser._checkOtherTextureTransform(metallicRoughnessTexture, "Roughness metallic");
|
|
1698
|
+
}
|
|
1699
|
+
}
|
|
1700
|
+
}
|
|
1701
|
+
if (material.constructor === engineCore.PBRMaterial || material.constructor === engineCore.PBRSpecularMaterial) {
|
|
1702
|
+
if (emissiveTexture) {
|
|
1703
|
+
material.emissiveTexture = textures[emissiveTexture.index];
|
|
1704
|
+
GLTFMaterialParser._checkOtherTextureTransform(emissiveTexture, "Emissive");
|
|
1705
|
+
}
|
|
1706
|
+
if (emissiveFactor) {
|
|
1707
|
+
material.emissiveColor = new engineMath.Color(engineMath.Color.linearToGammaSpace(emissiveFactor[0]), engineMath.Color.linearToGammaSpace(emissiveFactor[1]), engineMath.Color.linearToGammaSpace(emissiveFactor[2]));
|
|
1708
|
+
}
|
|
1709
|
+
if (normalTexture) {
|
|
1710
|
+
var index = normalTexture.index, scale = normalTexture.scale;
|
|
1711
|
+
material.normalTexture = textures[index];
|
|
1712
|
+
GLTFMaterialParser._checkOtherTextureTransform(normalTexture, "Normal");
|
|
1713
|
+
if (scale !== undefined) {
|
|
1714
|
+
material.normalTextureIntensity = scale;
|
|
1715
|
+
}
|
|
1716
|
+
}
|
|
1717
|
+
if (occlusionTexture) {
|
|
1718
|
+
var index1 = occlusionTexture.index, strength = occlusionTexture.strength, texCoord = occlusionTexture.texCoord;
|
|
1719
|
+
material.occlusionTexture = textures[index1];
|
|
1720
|
+
GLTFMaterialParser._checkOtherTextureTransform(occlusionTexture, "Occlusion");
|
|
1721
|
+
if (strength !== undefined) {
|
|
1722
|
+
material.occlusionTextureIntensity = strength;
|
|
1723
|
+
}
|
|
1724
|
+
if (texCoord === engineCore.TextureCoordinate.UV1) {
|
|
1725
|
+
material.occlusionTextureCoord = engineCore.TextureCoordinate.UV1;
|
|
1726
|
+
} else if (texCoord > engineCore.TextureCoordinate.UV1) {
|
|
1727
|
+
engineCore.Logger.warn("Occlusion texture uv coordinate must be UV0 or UV1.");
|
|
1728
|
+
}
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1731
|
+
if (doubleSided) {
|
|
1732
|
+
material.renderFace = engineCore.RenderFace.Double;
|
|
1733
|
+
} else {
|
|
1734
|
+
material.renderFace = engineCore.RenderFace.Front;
|
|
1735
|
+
}
|
|
1736
|
+
switch(alphaMode){
|
|
1737
|
+
case MaterialAlphaMode.OPAQUE:
|
|
1738
|
+
material.isTransparent = false;
|
|
1739
|
+
break;
|
|
1740
|
+
case MaterialAlphaMode.BLEND:
|
|
1741
|
+
material.isTransparent = true;
|
|
1742
|
+
break;
|
|
1743
|
+
case MaterialAlphaMode.MASK:
|
|
1744
|
+
material.alphaCutoff = alphaCutoff != null ? alphaCutoff : 0.5;
|
|
1745
|
+
break;
|
|
1746
|
+
}
|
|
1747
|
+
};
|
|
1748
|
+
return GLTFMaterialParser;
|
|
1749
|
+
}(GLTFParser);
|
|
1750
|
+
|
|
1751
|
+
function _instanceof(left, right) {
|
|
1752
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
1753
|
+
return !!right[Symbol.hasInstance](left);
|
|
1754
|
+
} else return left instanceof right;
|
|
1755
|
+
}
|
|
1756
|
+
|
|
1757
|
+
var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
1758
|
+
_inherits(GLTFMeshParser, GLTFParser1);
|
|
1759
|
+
function GLTFMeshParser() {
|
|
1760
|
+
return GLTFParser1.apply(this, arguments);
|
|
1761
|
+
}
|
|
1762
|
+
var _proto = GLTFMeshParser.prototype;
|
|
1763
|
+
_proto.parse = function parse(context) {
|
|
1764
|
+
var _loop = function(i) {
|
|
1765
|
+
var _loop = function(j) {
|
|
1766
|
+
var gltfPrimitive = gltfMesh.primitives[j];
|
|
1767
|
+
primitivePromises[j] = new Promise(function(resolve) {
|
|
1768
|
+
var mesh = GLTFParser.executeExtensionsCreateAndParse(gltfPrimitive.extensions, context, gltfPrimitive, gltfMesh);
|
|
1769
|
+
if (mesh) {
|
|
1770
|
+
if (_instanceof(mesh, engineCore.ModelMesh)) {
|
|
1771
|
+
resolve(mesh);
|
|
1772
|
+
} else {
|
|
1773
|
+
mesh.then(function(mesh) {
|
|
1774
|
+
return resolve(mesh);
|
|
1775
|
+
});
|
|
1776
|
+
}
|
|
1777
|
+
} else {
|
|
1778
|
+
var mesh1 = new engineCore.ModelMesh(engine, gltfMesh.name || j + "");
|
|
1779
|
+
var meshRestoreInfo = new ModelMeshRestoreInfo();
|
|
1780
|
+
meshRestoreInfo.mesh = mesh1;
|
|
1781
|
+
context.contentRestorer.meshes.push(meshRestoreInfo);
|
|
1782
|
+
GLTFMeshParser._parseMeshFromGLTFPrimitive(context, mesh1, meshRestoreInfo, gltfMesh, gltfPrimitive, glTF, function(attributeSemantic) {
|
|
1783
|
+
return null;
|
|
1784
|
+
}, function(attributeName, shapeIndex) {
|
|
1785
|
+
var shapeAccessorIdx = gltfPrimitive.targets[shapeIndex];
|
|
1786
|
+
var attributeAccessorIdx = shapeAccessorIdx[attributeName];
|
|
1787
|
+
if (attributeAccessorIdx) {
|
|
1788
|
+
var accessor = glTF.accessors[attributeAccessorIdx];
|
|
1789
|
+
return GLTFUtils.getAccessorBuffer(context, context.glTF.bufferViews, accessor);
|
|
1790
|
+
} else {
|
|
1791
|
+
return null;
|
|
1792
|
+
}
|
|
1793
|
+
}, function() {
|
|
1794
|
+
var indexAccessor = glTF.accessors[gltfPrimitive.indices];
|
|
1795
|
+
return GLTFUtils.getAccessorData(glTF, indexAccessor, buffers);
|
|
1796
|
+
}, context.keepMeshData).then(resolve);
|
|
1797
|
+
}
|
|
1798
|
+
});
|
|
1799
|
+
};
|
|
1800
|
+
var gltfMesh = glTF.meshes[i];
|
|
1801
|
+
var primitivePromises = [];
|
|
1802
|
+
for(var j = 0; j < gltfMesh.primitives.length; j++)_loop(j);
|
|
1803
|
+
meshPromises[i] = Promise.all(primitivePromises);
|
|
1804
|
+
};
|
|
1805
|
+
var glTF = context.glTF, buffers = context.buffers, glTFResource = context.glTFResource;
|
|
1806
|
+
var engine = glTFResource.engine;
|
|
1807
|
+
if (!glTF.meshes) return;
|
|
1808
|
+
var meshesPromiseInfo = context.meshesPromiseInfo;
|
|
1809
|
+
var meshPromises = [];
|
|
1810
|
+
for(var i = 0; i < glTF.meshes.length; i++)_loop(i);
|
|
1811
|
+
engineCore.AssetPromise.all(meshPromises).then(function(meshes) {
|
|
1812
|
+
glTFResource.meshes = meshes;
|
|
1813
|
+
meshesPromiseInfo.resolve(meshes);
|
|
1814
|
+
}).catch(meshesPromiseInfo.reject);
|
|
1815
|
+
return meshesPromiseInfo.promise;
|
|
1816
|
+
};
|
|
1817
|
+
/**
|
|
1818
|
+
* @internal
|
|
1819
|
+
*/ GLTFMeshParser._parseMeshFromGLTFPrimitive = function _parseMeshFromGLTFPrimitive(context, mesh, meshRestoreInfo, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
|
|
1802
1820
|
var accessors = gltf.accessors;
|
|
1803
1821
|
context.buffers;
|
|
1804
1822
|
var attributes = gltfPrimitive.attributes, targets = gltfPrimitive.targets, indices = gltfPrimitive.indices, mode = gltfPrimitive.mode;
|
|
@@ -1810,14 +1828,14 @@ var MeshParser = /*#__PURE__*/ function(Parser1) {
|
|
|
1810
1828
|
keepMeshData && (positions = new Array(vertexCount));
|
|
1811
1829
|
for(var attribute in attributes){
|
|
1812
1830
|
var accessor = accessors[attributes[attribute]];
|
|
1813
|
-
var accessorBuffer =
|
|
1814
|
-
var
|
|
1831
|
+
var accessorBuffer = GLTFUtils.getAccessorBuffer(context, gltf.bufferViews, accessor);
|
|
1832
|
+
var dataElementSize = GLTFUtils.getAccessorTypeSize(accessor.type);
|
|
1815
1833
|
var attributeCount = accessor.count;
|
|
1816
1834
|
var vertices = accessorBuffer.data;
|
|
1817
1835
|
var vertexElement = void 0;
|
|
1818
1836
|
var meshId = mesh.instanceId;
|
|
1819
1837
|
var vertexBindingInfos = accessorBuffer.vertexBindingInfos;
|
|
1820
|
-
var elementFormat =
|
|
1838
|
+
var elementFormat = GLTFUtils.getElementFormat(accessor.componentType, dataElementSize, accessor.normalized);
|
|
1821
1839
|
if (accessorBuffer.interleaved) {
|
|
1822
1840
|
var byteOffset = accessor.byteOffset || 0;
|
|
1823
1841
|
var stride = accessorBuffer.stride;
|
|
@@ -1829,6 +1847,7 @@ var MeshParser = /*#__PURE__*/ function(Parser1) {
|
|
|
1829
1847
|
vertexBuffer = new engineCore.Buffer(engine, engineCore.BufferBindFlag.VertexBuffer, vertices.byteLength, engineCore.BufferUsage.Static);
|
|
1830
1848
|
vertexBuffer.setData(vertices);
|
|
1831
1849
|
accessorBuffer.vertexBuffer = vertexBuffer;
|
|
1850
|
+
meshRestoreInfo.vertexBuffers.push(new BufferRestoreInfo(vertexBuffer, accessorBuffer.restoreInfo));
|
|
1832
1851
|
}
|
|
1833
1852
|
mesh.setVertexBufferBinding(vertexBuffer, stride, bufferBindIndex);
|
|
1834
1853
|
vertexBindingInfos[meshId] = bufferBindIndex++;
|
|
@@ -1839,6 +1858,7 @@ var MeshParser = /*#__PURE__*/ function(Parser1) {
|
|
|
1839
1858
|
vertexElement = new engineCore.VertexElement(attribute, 0, elementFormat, bufferBindIndex);
|
|
1840
1859
|
var vertexBuffer1 = new engineCore.Buffer(engine, engineCore.BufferBindFlag.VertexBuffer, vertices.byteLength, engineCore.BufferUsage.Static);
|
|
1841
1860
|
vertexBuffer1.setData(vertices);
|
|
1861
|
+
meshRestoreInfo.vertexBuffers.push(new BufferRestoreInfo(vertexBuffer1, accessorBuffer.restoreInfo));
|
|
1842
1862
|
mesh.setVertexBufferBinding(vertexBuffer1, accessorBuffer.stride, bufferBindIndex);
|
|
1843
1863
|
vertexBindingInfos[meshId] = bufferBindIndex++;
|
|
1844
1864
|
}
|
|
@@ -1857,7 +1877,7 @@ var MeshParser = /*#__PURE__*/ function(Parser1) {
|
|
|
1857
1877
|
}
|
|
1858
1878
|
}
|
|
1859
1879
|
} else {
|
|
1860
|
-
var position =
|
|
1880
|
+
var position = GLTFMeshParser._tempVector3;
|
|
1861
1881
|
min.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
|
|
1862
1882
|
max.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
|
|
1863
1883
|
var stride2 = vertices.length / attributeCount;
|
|
@@ -1866,13 +1886,12 @@ var MeshParser = /*#__PURE__*/ function(Parser1) {
|
|
|
1866
1886
|
position.copyFromArray(vertices, offset1);
|
|
1867
1887
|
engineMath.Vector3.min(min, position, min);
|
|
1868
1888
|
engineMath.Vector3.max(max, position, max);
|
|
1869
|
-
keepMeshData && (positions[j1] = position.clone());
|
|
1870
1889
|
}
|
|
1871
1890
|
}
|
|
1872
1891
|
if (accessor.normalized) {
|
|
1873
|
-
var
|
|
1874
|
-
min.scale(
|
|
1875
|
-
max.scale(
|
|
1892
|
+
var scaleFactor = GLTFUtils.getNormalizedComponentScale(accessor.componentType);
|
|
1893
|
+
min.scale(scaleFactor);
|
|
1894
|
+
max.scale(scaleFactor);
|
|
1876
1895
|
}
|
|
1877
1896
|
}
|
|
1878
1897
|
}
|
|
@@ -1880,179 +1899,72 @@ var MeshParser = /*#__PURE__*/ function(Parser1) {
|
|
|
1880
1899
|
// Indices
|
|
1881
1900
|
if (indices !== undefined) {
|
|
1882
1901
|
var indexAccessor = gltf.accessors[indices];
|
|
1883
|
-
var
|
|
1884
|
-
mesh.setIndices(
|
|
1902
|
+
var accessorBuffer1 = GLTFUtils.getAccessorBuffer(context, gltf.bufferViews, indexAccessor);
|
|
1903
|
+
mesh.setIndices(accessorBuffer1.data);
|
|
1885
1904
|
mesh.addSubMesh(0, indexAccessor.count, mode);
|
|
1905
|
+
meshRestoreInfo.indexBuffer = accessorBuffer1.restoreInfo;
|
|
1886
1906
|
} else {
|
|
1887
1907
|
mesh.addSubMesh(0, vertexCount, mode);
|
|
1888
1908
|
}
|
|
1889
1909
|
// BlendShapes
|
|
1890
|
-
targets &&
|
|
1910
|
+
targets && GLTFMeshParser._createBlendShape(mesh, meshRestoreInfo, gltfMesh, targets, getBlendShapeData);
|
|
1891
1911
|
mesh.uploadData(!keepMeshData);
|
|
1892
1912
|
//@ts-ignore
|
|
1893
1913
|
mesh._positions = positions;
|
|
1894
1914
|
return Promise.resolve(mesh);
|
|
1895
1915
|
};
|
|
1896
|
-
|
|
1916
|
+
/**
|
|
1917
|
+
* @internal
|
|
1918
|
+
*/ GLTFMeshParser._createBlendShape = function _createBlendShape(mesh, meshRestoreInfo, glTFMesh, glTFTargets, getBlendShapeData) {
|
|
1897
1919
|
var blendShapeNames = glTFMesh.extras ? glTFMesh.extras.targetNames : null;
|
|
1898
1920
|
for(var i = 0, n = glTFTargets.length; i < n; i++){
|
|
1899
1921
|
var name = blendShapeNames ? blendShapeNames[i] : "blendShape" + i;
|
|
1900
|
-
var
|
|
1901
|
-
var
|
|
1902
|
-
var
|
|
1903
|
-
var deltaPositions =
|
|
1904
|
-
var deltaNormals =
|
|
1905
|
-
var deltaTangents =
|
|
1922
|
+
var deltaPosBufferInfo = getBlendShapeData("POSITION", i);
|
|
1923
|
+
var deltaNorBufferInfo = getBlendShapeData("NORMAL", i);
|
|
1924
|
+
var deltaTanBufferInfo = getBlendShapeData("TANGENT", i);
|
|
1925
|
+
var deltaPositions = deltaPosBufferInfo.data ? GLTFUtils.floatBufferToVector3Array(deltaPosBufferInfo.data) : null;
|
|
1926
|
+
var deltaNormals = (deltaNorBufferInfo == null ? void 0 : deltaNorBufferInfo.data) ? GLTFUtils.floatBufferToVector3Array(deltaNorBufferInfo == null ? void 0 : deltaNorBufferInfo.data) : null;
|
|
1927
|
+
var deltaTangents = (deltaTanBufferInfo == null ? void 0 : deltaTanBufferInfo.data) ? GLTFUtils.floatBufferToVector3Array(deltaTanBufferInfo == null ? void 0 : deltaTanBufferInfo.data) : null;
|
|
1906
1928
|
var blendShape = new engineCore.BlendShape(name);
|
|
1907
1929
|
blendShape.addFrame(1.0, deltaPositions, deltaNormals, deltaTangents);
|
|
1908
1930
|
mesh.addBlendShape(blendShape);
|
|
1931
|
+
meshRestoreInfo.blendShapes.push(new BlendShapeRestoreInfo(blendShape, deltaPosBufferInfo.restoreInfo, deltaNorBufferInfo == null ? void 0 : deltaNorBufferInfo.restoreInfo, deltaTanBufferInfo == null ? void 0 : deltaTanBufferInfo.restoreInfo));
|
|
1909
1932
|
}
|
|
1910
1933
|
};
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
*/ _proto._parseMeshFromGLTFPrimitiveDraco = function _parseMeshFromGLTFPrimitiveDraco(mesh, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
|
|
1914
|
-
var attributes = gltfPrimitive.attributes, targets = gltfPrimitive.targets, indices = gltfPrimitive.indices, mode = gltfPrimitive.mode;
|
|
1915
|
-
var vertexCount;
|
|
1916
|
-
var accessors = gltf.accessors;
|
|
1917
|
-
var accessor = accessors[attributes["POSITION"]];
|
|
1918
|
-
var positionBuffer = getVertexBufferData("POSITION");
|
|
1919
|
-
var positions = GLTFUtil.floatBufferToVector3Array(positionBuffer);
|
|
1920
|
-
mesh.setPositions(positions);
|
|
1921
|
-
var bounds = mesh.bounds;
|
|
1922
|
-
vertexCount = accessor.count;
|
|
1923
|
-
if (accessor.min && accessor.max) {
|
|
1924
|
-
bounds.min.copyFromArray(accessor.min);
|
|
1925
|
-
bounds.max.copyFromArray(accessor.max);
|
|
1926
|
-
} else {
|
|
1927
|
-
var position = MeshParser._tempVector3;
|
|
1928
|
-
var min = bounds.min, max = bounds.max;
|
|
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 stride = positionBuffer.length / vertexCount;
|
|
1932
|
-
for(var j = 0; j < vertexCount; j++){
|
|
1933
|
-
var offset = j * stride;
|
|
1934
|
-
position.copyFromArray(positionBuffer, offset);
|
|
1935
|
-
engineMath.Vector3.min(min, position, min);
|
|
1936
|
-
engineMath.Vector3.max(max, position, max);
|
|
1937
|
-
}
|
|
1938
|
-
}
|
|
1939
|
-
for(var attributeSemantic in attributes){
|
|
1940
|
-
if (attributeSemantic === "POSITION") {
|
|
1941
|
-
continue;
|
|
1942
|
-
}
|
|
1943
|
-
var bufferData = getVertexBufferData(attributeSemantic);
|
|
1944
|
-
switch(attributeSemantic){
|
|
1945
|
-
case "NORMAL":
|
|
1946
|
-
var normals = GLTFUtil.floatBufferToVector3Array(bufferData);
|
|
1947
|
-
mesh.setNormals(normals);
|
|
1948
|
-
break;
|
|
1949
|
-
case "TEXCOORD_0":
|
|
1950
|
-
var texturecoords = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
1951
|
-
mesh.setUVs(texturecoords, 0);
|
|
1952
|
-
break;
|
|
1953
|
-
case "TEXCOORD_1":
|
|
1954
|
-
var texturecoords1 = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
1955
|
-
mesh.setUVs(texturecoords1, 1);
|
|
1956
|
-
break;
|
|
1957
|
-
case "TEXCOORD_2":
|
|
1958
|
-
var texturecoords2 = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
1959
|
-
mesh.setUVs(texturecoords2, 2);
|
|
1960
|
-
break;
|
|
1961
|
-
case "TEXCOORD_3":
|
|
1962
|
-
var texturecoords3 = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
1963
|
-
mesh.setUVs(texturecoords3, 3);
|
|
1964
|
-
break;
|
|
1965
|
-
case "TEXCOORD_4":
|
|
1966
|
-
var texturecoords4 = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
1967
|
-
mesh.setUVs(texturecoords4, 4);
|
|
1968
|
-
break;
|
|
1969
|
-
case "TEXCOORD_5":
|
|
1970
|
-
var texturecoords5 = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
1971
|
-
mesh.setUVs(texturecoords5, 5);
|
|
1972
|
-
break;
|
|
1973
|
-
case "TEXCOORD_6":
|
|
1974
|
-
var texturecoords6 = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
1975
|
-
mesh.setUVs(texturecoords6, 6);
|
|
1976
|
-
break;
|
|
1977
|
-
case "TEXCOORD_7":
|
|
1978
|
-
var texturecoords7 = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
1979
|
-
mesh.setUVs(texturecoords7, 7);
|
|
1980
|
-
break;
|
|
1981
|
-
case "COLOR_0":
|
|
1982
|
-
var colors = GLTFUtil.floatBufferToColorArray(bufferData, accessors[attributes["COLOR_0"]].type === AccessorType.VEC3);
|
|
1983
|
-
mesh.setColors(colors);
|
|
1984
|
-
break;
|
|
1985
|
-
case "TANGENT":
|
|
1986
|
-
var tangents = GLTFUtil.floatBufferToVector4Array(bufferData);
|
|
1987
|
-
mesh.setTangents(tangents);
|
|
1988
|
-
break;
|
|
1989
|
-
case "JOINTS_0":
|
|
1990
|
-
var joints = GLTFUtil.floatBufferToVector4Array(bufferData);
|
|
1991
|
-
mesh.setBoneIndices(joints);
|
|
1992
|
-
break;
|
|
1993
|
-
case "WEIGHTS_0":
|
|
1994
|
-
var weights = GLTFUtil.floatBufferToVector4Array(bufferData);
|
|
1995
|
-
mesh.setBoneWeights(weights);
|
|
1996
|
-
break;
|
|
1997
|
-
}
|
|
1998
|
-
}
|
|
1999
|
-
// Indices
|
|
2000
|
-
if (indices !== undefined) {
|
|
2001
|
-
var indexAccessor = gltf.accessors[indices];
|
|
2002
|
-
var indexData = getIndexBufferData();
|
|
2003
|
-
mesh.setIndices(indexData);
|
|
2004
|
-
mesh.addSubMesh(0, indexAccessor.count, mode);
|
|
2005
|
-
} else {
|
|
2006
|
-
mesh.addSubMesh(0, vertexCount, mode);
|
|
2007
|
-
}
|
|
2008
|
-
// BlendShapes
|
|
2009
|
-
targets && this._createBlendShape(mesh, gltfMesh, targets, getBlendShapeData);
|
|
2010
|
-
mesh.uploadData(!keepMeshData);
|
|
2011
|
-
return Promise.resolve(mesh);
|
|
2012
|
-
};
|
|
2013
|
-
return MeshParser;
|
|
2014
|
-
}(Parser);
|
|
1934
|
+
return GLTFMeshParser;
|
|
1935
|
+
}(GLTFParser);
|
|
2015
1936
|
(function() {
|
|
2016
|
-
|
|
1937
|
+
GLTFMeshParser._tempVector3 = new engineMath.Vector3();
|
|
2017
1938
|
})();
|
|
2018
1939
|
|
|
2019
|
-
var
|
|
2020
|
-
_inherits(
|
|
2021
|
-
function
|
|
2022
|
-
return
|
|
1940
|
+
var GLTFSceneParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
1941
|
+
_inherits(GLTFSceneParser, GLTFParser1);
|
|
1942
|
+
function GLTFSceneParser() {
|
|
1943
|
+
return GLTFParser1.apply(this, arguments);
|
|
2023
1944
|
}
|
|
2024
|
-
var _proto =
|
|
1945
|
+
var _proto = GLTFSceneParser.prototype;
|
|
2025
1946
|
_proto.parse = function parse(context) {
|
|
2026
|
-
var glTFResource = context.glTFResource,
|
|
1947
|
+
var glTFResource = context.glTFResource, glTF = context.glTF;
|
|
2027
1948
|
var entities = glTFResource.entities;
|
|
2028
|
-
var nodes =
|
|
1949
|
+
var nodes = glTF.nodes, cameras = glTF.cameras;
|
|
2029
1950
|
if (!nodes) return;
|
|
2030
1951
|
var defaultSceneRootPromiseInfo = context.defaultSceneRootPromiseInfo;
|
|
2031
|
-
var promises = [];
|
|
2032
1952
|
for(var i = 0; i < nodes.length; i++){
|
|
2033
|
-
var
|
|
2034
|
-
var cameraID =
|
|
2035
|
-
var KHR_lights_punctual = extensions.KHR_lights_punctual;
|
|
1953
|
+
var glTFNode = nodes[i];
|
|
1954
|
+
var cameraID = glTFNode.camera, meshID = glTFNode.mesh, extensions = glTFNode.extensions;
|
|
2036
1955
|
var entity = entities[i];
|
|
2037
1956
|
if (cameraID !== undefined) {
|
|
2038
|
-
this._createCamera(glTFResource,
|
|
1957
|
+
this._createCamera(glTFResource, cameras[cameraID], entity);
|
|
2039
1958
|
}
|
|
2040
1959
|
if (meshID !== undefined) {
|
|
2041
|
-
|
|
2042
|
-
}
|
|
2043
|
-
if (KHR_lights_punctual) {
|
|
2044
|
-
var lightIndex = KHR_lights_punctual.light;
|
|
2045
|
-
var lights = gltf.extensions.KHR_lights_punctual.lights;
|
|
2046
|
-
Parser.parseEngineResource("KHR_lights_punctual", lights[lightIndex], entity, context);
|
|
1960
|
+
this._createRenderer(context, glTFNode, entity);
|
|
2047
1961
|
}
|
|
1962
|
+
GLTFParser.executeExtensionsAdditiveAndParse(extensions, context, entity, glTFNode);
|
|
2048
1963
|
}
|
|
2049
1964
|
if (glTFResource.defaultSceneRoot) {
|
|
2050
1965
|
this._createAnimator(context);
|
|
2051
1966
|
}
|
|
2052
|
-
|
|
2053
|
-
engineCore.AssetPromise.all(promises).then(function() {
|
|
2054
|
-
return defaultSceneRootPromiseInfo.resolve(glTFResource.defaultSceneRoot);
|
|
2055
|
-
}).catch(defaultSceneRootPromiseInfo.reject);
|
|
1967
|
+
defaultSceneRootPromiseInfo.resolve(glTFResource.defaultSceneRoot);
|
|
2056
1968
|
return defaultSceneRootPromiseInfo.promise;
|
|
2057
1969
|
};
|
|
2058
1970
|
_proto._createCamera = function _createCamera(context, cameraSchema, entity) {
|
|
@@ -2088,8 +2000,16 @@ var SceneParser$1 = /*#__PURE__*/ function(Parser1) {
|
|
|
2088
2000
|
// @todo: use engine camera by default
|
|
2089
2001
|
camera.enabled = false;
|
|
2090
2002
|
};
|
|
2091
|
-
_proto._createRenderer = function _createRenderer(context,
|
|
2092
|
-
var
|
|
2003
|
+
_proto._createRenderer = function _createRenderer(context, glTFNode, entity) {
|
|
2004
|
+
var glTFResource = context.glTFResource, glTF = context.glTF;
|
|
2005
|
+
var glTFMeshes = glTF.meshes;
|
|
2006
|
+
var engine = glTFResource.engine, meshes = glTFResource.meshes, materials = glTFResource.materials, skins = glTFResource.skins;
|
|
2007
|
+
var meshID = glTFNode.mesh, skinID = glTFNode.skin;
|
|
2008
|
+
var glTFMesh = glTFMeshes[meshID];
|
|
2009
|
+
var glTFMeshPrimitives = glTFMesh.primitives;
|
|
2010
|
+
var blendShapeWeights = glTFNode.weights || glTFMesh.weights;
|
|
2011
|
+
for(var i = 0; i < glTFMeshPrimitives.length; i++){
|
|
2012
|
+
var gltfPrimitive = glTFMeshPrimitives[i];
|
|
2093
2013
|
var mesh = meshes[meshID][i];
|
|
2094
2014
|
var renderer = void 0;
|
|
2095
2015
|
if (skinID !== undefined || blendShapeWeights) {
|
|
@@ -2107,32 +2027,11 @@ var SceneParser$1 = /*#__PURE__*/ function(Parser1) {
|
|
|
2107
2027
|
renderer = entity.addComponent(engineCore.MeshRenderer);
|
|
2108
2028
|
renderer.mesh = mesh;
|
|
2109
2029
|
}
|
|
2110
|
-
var materialIndex =
|
|
2111
|
-
var
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
}));
|
|
2116
|
-
} else {
|
|
2117
|
-
var material = (materials == null ? void 0 : materials[materialIndex]) || SceneParser._getDefaultMaterial(engine);
|
|
2118
|
-
renderer.setMaterial(material);
|
|
2119
|
-
}
|
|
2120
|
-
var _gltfMeshPrimitives_i = gltfMeshPrimitives[i], _gltfMeshPrimitives_i_extensions = _gltfMeshPrimitives_i.extensions, extensions = _gltfMeshPrimitives_i_extensions === void 0 ? {} : _gltfMeshPrimitives_i_extensions;
|
|
2121
|
-
var KHR_materials_variants = extensions.KHR_materials_variants;
|
|
2122
|
-
if (KHR_materials_variants) {
|
|
2123
|
-
Parser.parseEngineResource("KHR_materials_variants", KHR_materials_variants, renderer, context);
|
|
2124
|
-
}
|
|
2125
|
-
};
|
|
2126
|
-
var glTFResource = context.glTFResource, gltf = context.gltf;
|
|
2127
|
-
var gltfMeshes = gltf.meshes;
|
|
2128
|
-
var engine = glTFResource.engine, meshes = glTFResource.meshes, materials = glTFResource.materials, skins = glTFResource.skins;
|
|
2129
|
-
var meshID = gltfNode.mesh, skinID = gltfNode.skin;
|
|
2130
|
-
var glTFMesh = gltfMeshes[meshID];
|
|
2131
|
-
var gltfMeshPrimitives = glTFMesh.primitives;
|
|
2132
|
-
var blendShapeWeights = gltfNode.weights || glTFMesh.weights;
|
|
2133
|
-
var promises = [];
|
|
2134
|
-
for(var i = 0; i < gltfMeshPrimitives.length; i++)_loop(i);
|
|
2135
|
-
return Promise.all(promises);
|
|
2030
|
+
var materialIndex = gltfPrimitive.material;
|
|
2031
|
+
var material = (materials == null ? void 0 : materials[materialIndex]) || GLTFSceneParser._getDefaultMaterial(engine);
|
|
2032
|
+
renderer.setMaterial(material);
|
|
2033
|
+
GLTFParser.executeExtensionsAdditiveAndParse(gltfPrimitive.extensions, context, renderer, gltfPrimitive);
|
|
2034
|
+
}
|
|
2136
2035
|
};
|
|
2137
2036
|
_proto._createAnimator = function _createAnimator(context) {
|
|
2138
2037
|
if (!context.hasSkinned && !context.glTFResource.animations) {
|
|
@@ -2159,25 +2058,25 @@ var SceneParser$1 = /*#__PURE__*/ function(Parser1) {
|
|
|
2159
2058
|
}
|
|
2160
2059
|
}
|
|
2161
2060
|
};
|
|
2162
|
-
|
|
2163
|
-
if (!
|
|
2164
|
-
|
|
2061
|
+
GLTFSceneParser._getDefaultMaterial = function _getDefaultMaterial(engine) {
|
|
2062
|
+
if (!GLTFSceneParser._defaultMaterial) {
|
|
2063
|
+
GLTFSceneParser._defaultMaterial = new engineCore.BlinnPhongMaterial(engine);
|
|
2165
2064
|
}
|
|
2166
|
-
return
|
|
2065
|
+
return GLTFSceneParser._defaultMaterial;
|
|
2167
2066
|
};
|
|
2168
|
-
return
|
|
2169
|
-
}(
|
|
2067
|
+
return GLTFSceneParser;
|
|
2068
|
+
}(GLTFParser);
|
|
2170
2069
|
|
|
2171
|
-
var
|
|
2172
|
-
_inherits(
|
|
2173
|
-
function
|
|
2174
|
-
return
|
|
2070
|
+
var GLTFSkinParser = /*#__PURE__*/ function(GLTFParser) {
|
|
2071
|
+
_inherits(GLTFSkinParser, GLTFParser);
|
|
2072
|
+
function GLTFSkinParser() {
|
|
2073
|
+
return GLTFParser.apply(this, arguments);
|
|
2175
2074
|
}
|
|
2176
|
-
var _proto =
|
|
2075
|
+
var _proto = GLTFSkinParser.prototype;
|
|
2177
2076
|
_proto.parse = function parse(context) {
|
|
2178
|
-
var glTFResource = context.glTFResource,
|
|
2077
|
+
var glTFResource = context.glTFResource, glTF = context.glTF; context.buffers;
|
|
2179
2078
|
var entities = glTFResource.entities;
|
|
2180
|
-
var gltfSkins =
|
|
2079
|
+
var gltfSkins = glTF.skins;
|
|
2181
2080
|
if (!gltfSkins) return;
|
|
2182
2081
|
var count = gltfSkins.length;
|
|
2183
2082
|
var skins = new Array(count);
|
|
@@ -2187,8 +2086,8 @@ var SkinParser = /*#__PURE__*/ function(Parser) {
|
|
|
2187
2086
|
var skin = new engineCore.Skin(name);
|
|
2188
2087
|
skin.inverseBindMatrices.length = jointCount;
|
|
2189
2088
|
// parse IBM
|
|
2190
|
-
var accessor =
|
|
2191
|
-
var buffer =
|
|
2089
|
+
var accessor = glTF.accessors[inverseBindMatrices];
|
|
2090
|
+
var buffer = GLTFUtils.getAccessorBuffer(context, glTF.bufferViews, accessor).data;
|
|
2192
2091
|
for(var i1 = 0; i1 < jointCount; i1++){
|
|
2193
2092
|
var inverseBindMatrix = new engineMath.Matrix();
|
|
2194
2093
|
inverseBindMatrix.copyFromArray(buffer, i1 * 16);
|
|
@@ -2249,52 +2148,55 @@ var SkinParser = /*#__PURE__*/ function(Parser) {
|
|
|
2249
2148
|
rootNode = entity1;
|
|
2250
2149
|
}
|
|
2251
2150
|
};
|
|
2252
|
-
return
|
|
2253
|
-
}(
|
|
2151
|
+
return GLTFSkinParser;
|
|
2152
|
+
}(GLTFParser);
|
|
2254
2153
|
|
|
2255
|
-
var
|
|
2256
|
-
_inherits(
|
|
2257
|
-
function
|
|
2258
|
-
return
|
|
2154
|
+
var GLTFTextureParser = /*#__PURE__*/ function(GLTFParser) {
|
|
2155
|
+
_inherits(GLTFTextureParser, GLTFParser);
|
|
2156
|
+
function GLTFTextureParser() {
|
|
2157
|
+
return GLTFParser.apply(this, arguments);
|
|
2259
2158
|
}
|
|
2260
|
-
var _proto =
|
|
2159
|
+
var _proto = GLTFTextureParser.prototype;
|
|
2261
2160
|
_proto.parse = function parse(context) {
|
|
2262
2161
|
var _this = this;
|
|
2263
|
-
var glTFResource = context.glTFResource,
|
|
2162
|
+
var glTFResource = context.glTFResource, glTF = context.glTF, buffers = context.buffers;
|
|
2264
2163
|
var engine = glTFResource.engine, url = glTFResource.url;
|
|
2265
|
-
if (
|
|
2164
|
+
if (glTF.textures) {
|
|
2266
2165
|
var texturesPromiseInfo = context.texturesPromiseInfo;
|
|
2267
|
-
engineCore.AssetPromise.all(
|
|
2166
|
+
engineCore.AssetPromise.all(glTF.textures.map(function(param, index) {
|
|
2268
2167
|
var sampler = param.sampler, _param_source = param.source, source = _param_source === void 0 ? 0 : _param_source, textureName = param.name;
|
|
2269
|
-
var
|
|
2168
|
+
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;
|
|
2270
2169
|
if (uri) {
|
|
2271
2170
|
// TODO: support ktx extension https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_texture_basisu/README.md
|
|
2272
2171
|
var index1 = uri.lastIndexOf(".");
|
|
2273
2172
|
var ext = uri.substring(index1 + 1);
|
|
2274
2173
|
var type = ext.startsWith("ktx") ? engineCore.AssetType.KTX : engineCore.AssetType.Texture2D;
|
|
2275
2174
|
return engine.resourceManager.load({
|
|
2276
|
-
url:
|
|
2175
|
+
url: engineCore.Utils.resolveAbsoluteUrl(url, uri),
|
|
2277
2176
|
type: type
|
|
2278
2177
|
}).then(function(texture) {
|
|
2279
2178
|
if (!texture.name) {
|
|
2280
2179
|
texture.name = textureName || imageName || "texture_" + index1;
|
|
2281
2180
|
}
|
|
2282
2181
|
if (sampler !== undefined) {
|
|
2283
|
-
_this._parseSampler(texture,
|
|
2182
|
+
_this._parseSampler(texture, glTF.samplers[sampler]);
|
|
2284
2183
|
}
|
|
2285
2184
|
return texture;
|
|
2286
2185
|
});
|
|
2287
2186
|
} else {
|
|
2288
|
-
var bufferView =
|
|
2289
|
-
var
|
|
2290
|
-
|
|
2187
|
+
var bufferView = glTF.bufferViews[bufferViewIndex];
|
|
2188
|
+
var buffer = buffers[bufferView.buffer];
|
|
2189
|
+
var imageBuffer = new Uint8Array(buffer, bufferView.byteOffset, bufferView.byteLength);
|
|
2190
|
+
return GLTFUtils.loadImageBuffer(imageBuffer, mimeType).then(function(image) {
|
|
2291
2191
|
var texture = new engineCore.Texture2D(engine, image.width, image.height);
|
|
2292
2192
|
texture.setImageSource(image);
|
|
2293
2193
|
texture.generateMipmaps();
|
|
2294
2194
|
texture.name = textureName || imageName || "texture_" + index;
|
|
2295
2195
|
if (sampler !== undefined) {
|
|
2296
|
-
_this._parseSampler(texture,
|
|
2196
|
+
_this._parseSampler(texture, glTF.samplers[sampler]);
|
|
2297
2197
|
}
|
|
2198
|
+
var bufferTextureRestoreInfo = new BufferTextureRestoreInfo(texture, bufferView, mimeType);
|
|
2199
|
+
context.contentRestorer.bufferTextures.push(bufferTextureRestoreInfo);
|
|
2298
2200
|
return texture;
|
|
2299
2201
|
});
|
|
2300
2202
|
}
|
|
@@ -2317,36 +2219,38 @@ var TextureParser = /*#__PURE__*/ function(Parser) {
|
|
|
2317
2219
|
}
|
|
2318
2220
|
}
|
|
2319
2221
|
if (wrapS) {
|
|
2320
|
-
texture.wrapModeU =
|
|
2222
|
+
texture.wrapModeU = GLTFTextureParser._wrapMap[wrapS];
|
|
2321
2223
|
}
|
|
2322
2224
|
if (wrapT) {
|
|
2323
|
-
texture.wrapModeV =
|
|
2225
|
+
texture.wrapModeV = GLTFTextureParser._wrapMap[wrapT];
|
|
2324
2226
|
}
|
|
2325
2227
|
};
|
|
2326
|
-
return
|
|
2327
|
-
}(
|
|
2228
|
+
return GLTFTextureParser;
|
|
2229
|
+
}(GLTFParser);
|
|
2328
2230
|
(function() {
|
|
2329
2231
|
var _obj;
|
|
2330
|
-
|
|
2232
|
+
GLTFTextureParser._wrapMap = (_obj = {}, _obj[TextureWrapMode.CLAMP_TO_EDGE] = engineCore.TextureWrapMode.Clamp, _obj[TextureWrapMode.MIRRORED_REPEAT] = engineCore.TextureWrapMode.Mirror, _obj[TextureWrapMode.REPEAT] = engineCore.TextureWrapMode.Repeat, _obj);
|
|
2331
2233
|
})();
|
|
2332
2234
|
|
|
2333
|
-
var
|
|
2334
|
-
_inherits(
|
|
2335
|
-
function
|
|
2336
|
-
return
|
|
2235
|
+
var GLTFValidator = /*#__PURE__*/ function(GLTFParser1) {
|
|
2236
|
+
_inherits(GLTFValidator, GLTFParser1);
|
|
2237
|
+
function GLTFValidator() {
|
|
2238
|
+
return GLTFParser1.apply(this, arguments);
|
|
2337
2239
|
}
|
|
2338
|
-
var _proto =
|
|
2240
|
+
var _proto = GLTFValidator.prototype;
|
|
2339
2241
|
_proto.parse = function parse(context) {
|
|
2340
|
-
var
|
|
2341
|
-
var
|
|
2342
|
-
if (!(
|
|
2343
|
-
throw "Only support
|
|
2242
|
+
var _context_glTF = context.glTF, version = _context_glTF.asset.version, extensionsUsed = _context_glTF.extensionsUsed, extensionsRequired = _context_glTF.extensionsRequired;
|
|
2243
|
+
var glTFVersion = Number(version);
|
|
2244
|
+
if (!(glTFVersion >= 2 && glTFVersion < 3)) {
|
|
2245
|
+
throw "Only support glTF 2.x.";
|
|
2344
2246
|
}
|
|
2247
|
+
var promises = [];
|
|
2345
2248
|
if (extensionsUsed) {
|
|
2346
2249
|
engineCore.Logger.info("extensionsUsed: ", extensionsUsed);
|
|
2347
2250
|
for(var i = 0; i < extensionsUsed.length; i++){
|
|
2348
|
-
|
|
2349
|
-
|
|
2251
|
+
var extensionUsed = extensionsUsed[i];
|
|
2252
|
+
if (!GLTFParser.hasExtensionParser(extensionUsed)) {
|
|
2253
|
+
engineCore.Logger.warn("Extension " + extensionUsed + " is not implemented, you can customize this extension in gltf.");
|
|
2350
2254
|
}
|
|
2351
2255
|
}
|
|
2352
2256
|
}
|
|
@@ -2354,68 +2258,68 @@ var Validator = /*#__PURE__*/ function(Parser1) {
|
|
|
2354
2258
|
engineCore.Logger.info("extensionsRequired: " + extensionsRequired);
|
|
2355
2259
|
for(var i1 = 0; i1 < extensionsRequired.length; i1++){
|
|
2356
2260
|
var extensionRequired = extensionsRequired[i1];
|
|
2357
|
-
if (!
|
|
2261
|
+
if (!GLTFParser.hasExtensionParser(extensionRequired)) {
|
|
2358
2262
|
engineCore.Logger.error("GLTF parser has not supported required extension " + extensionRequired + ".");
|
|
2359
2263
|
} else {
|
|
2360
|
-
|
|
2264
|
+
promises.push(GLTFParser.executeExtensionsInitialize(extensionRequired));
|
|
2361
2265
|
}
|
|
2362
2266
|
}
|
|
2363
2267
|
}
|
|
2268
|
+
return engineCore.AssetPromise.all(promises).then(null);
|
|
2364
2269
|
};
|
|
2365
|
-
return
|
|
2366
|
-
}(
|
|
2270
|
+
return GLTFValidator;
|
|
2271
|
+
}(GLTFParser);
|
|
2367
2272
|
|
|
2368
|
-
|
|
2369
|
-
|
|
2273
|
+
/**
|
|
2274
|
+
* GLTF pipeline.
|
|
2275
|
+
*/ var GLTFPipeline = /*#__PURE__*/ function() {
|
|
2276
|
+
function GLTFPipeline() {
|
|
2277
|
+
for(var _len = arguments.length, parsers = new Array(_len), _key = 0; _key < _len; _key++){
|
|
2278
|
+
parsers[_key] = arguments[_key];
|
|
2279
|
+
}
|
|
2370
2280
|
var _this = this;
|
|
2371
|
-
this.
|
|
2372
|
-
|
|
2373
|
-
_this.
|
|
2281
|
+
this._parsers = [];
|
|
2282
|
+
parsers.forEach(function(pipe, index) {
|
|
2283
|
+
_this._parsers[index] = new pipe();
|
|
2374
2284
|
});
|
|
2375
2285
|
}
|
|
2376
|
-
var _proto =
|
|
2377
|
-
|
|
2286
|
+
var _proto = GLTFPipeline.prototype;
|
|
2287
|
+
/**
|
|
2288
|
+
* @internal
|
|
2289
|
+
*/ _proto._parse = function _parse(context) {
|
|
2378
2290
|
var _this = this;
|
|
2379
2291
|
var glTFResource = context.glTFResource;
|
|
2380
|
-
var
|
|
2292
|
+
var lastParser;
|
|
2381
2293
|
return new engineCore.AssetPromise(function(resolve, reject) {
|
|
2382
|
-
_this.
|
|
2383
|
-
if (
|
|
2384
|
-
|
|
2294
|
+
_this._parsers.forEach(function(parser) {
|
|
2295
|
+
if (lastParser) {
|
|
2296
|
+
lastParser = lastParser.then(function() {
|
|
2385
2297
|
return parser.parse(context);
|
|
2386
2298
|
});
|
|
2387
|
-
if (
|
|
2388
|
-
context.chainPromises.push(
|
|
2299
|
+
if (lastParser.cancel) {
|
|
2300
|
+
context.chainPromises.push(lastParser);
|
|
2389
2301
|
}
|
|
2390
2302
|
} else {
|
|
2391
|
-
|
|
2303
|
+
lastParser = parser.parse(context);
|
|
2392
2304
|
}
|
|
2393
2305
|
});
|
|
2394
|
-
if (
|
|
2395
|
-
|
|
2306
|
+
if (lastParser) {
|
|
2307
|
+
lastParser.then(function() {
|
|
2396
2308
|
resolve(glTFResource);
|
|
2397
2309
|
}).catch(reject);
|
|
2398
2310
|
}
|
|
2399
2311
|
});
|
|
2400
2312
|
};
|
|
2401
|
-
return
|
|
2313
|
+
return GLTFPipeline;
|
|
2402
2314
|
}();
|
|
2403
2315
|
(function() {
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
TextureParser,
|
|
2408
|
-
MaterialParser,
|
|
2409
|
-
MeshParser,
|
|
2410
|
-
EntityParser,
|
|
2411
|
-
SkinParser,
|
|
2412
|
-
AnimationParser,
|
|
2413
|
-
SceneParser$1
|
|
2414
|
-
]);
|
|
2316
|
+
/**
|
|
2317
|
+
* Default pipeline.
|
|
2318
|
+
*/ GLTFPipeline.defaultPipeline = new GLTFPipeline(GLTFBufferParser, GLTFValidator, GLTFTextureParser, GLTFMaterialParser, GLTFMeshParser, GLTFEntityParser, GLTFSkinParser, GLTFAnimationParser, GLTFSceneParser);
|
|
2415
2319
|
})();
|
|
2416
2320
|
|
|
2417
2321
|
/**
|
|
2418
|
-
* Product after
|
|
2322
|
+
* Product after glTF parser, usually, `defaultSceneRoot` is only needed to use.
|
|
2419
2323
|
*/ var GLTFResource = /*#__PURE__*/ function(EngineObject) {
|
|
2420
2324
|
_inherits(GLTFResource, EngineObject);
|
|
2421
2325
|
function GLTFResource(engine, url) {
|
|
@@ -2427,11 +2331,8 @@ var GLTFParser = /*#__PURE__*/ function() {
|
|
|
2427
2331
|
var _proto = GLTFResource.prototype;
|
|
2428
2332
|
/**
|
|
2429
2333
|
* @override
|
|
2430
|
-
*/ _proto.
|
|
2431
|
-
|
|
2432
|
-
return;
|
|
2433
|
-
}
|
|
2434
|
-
EngineObject.prototype.destroy.call(this);
|
|
2334
|
+
*/ _proto._onDestroy = function _onDestroy() {
|
|
2335
|
+
EngineObject.prototype._onDestroy.call(this);
|
|
2435
2336
|
this.defaultSceneRoot.destroy();
|
|
2436
2337
|
this.textures = null;
|
|
2437
2338
|
this.materials = null;
|
|
@@ -2442,7 +2343,7 @@ var GLTFParser = /*#__PURE__*/ function() {
|
|
|
2442
2343
|
this.cameras = null;
|
|
2443
2344
|
this.lights = null;
|
|
2444
2345
|
this.sceneRoots = null;
|
|
2445
|
-
this.
|
|
2346
|
+
this.extensionsData = null;
|
|
2446
2347
|
};
|
|
2447
2348
|
return GLTFResource;
|
|
2448
2349
|
}(engineCore.EngineObject);
|
|
@@ -2453,15 +2354,19 @@ var GLTFLoader = /*#__PURE__*/ function(Loader) {
|
|
|
2453
2354
|
return Loader.apply(this, arguments);
|
|
2454
2355
|
}
|
|
2455
2356
|
var _proto = GLTFLoader.prototype;
|
|
2456
|
-
|
|
2457
|
-
|
|
2357
|
+
/**
|
|
2358
|
+
* @override
|
|
2359
|
+
*/ _proto.load = function load(item, resourceManager) {
|
|
2458
2360
|
var url = item.url;
|
|
2459
|
-
var
|
|
2361
|
+
var params = item.params;
|
|
2362
|
+
var context = new GLTFParserContext(url);
|
|
2460
2363
|
var glTFResource = new GLTFResource(resourceManager.engine, url);
|
|
2364
|
+
var restorer = new GLTFContentRestorer(glTFResource);
|
|
2461
2365
|
var masterPromiseInfo = context.masterPromiseInfo;
|
|
2366
|
+
context.contentRestorer = restorer;
|
|
2462
2367
|
context.glTFResource = glTFResource;
|
|
2463
|
-
var
|
|
2464
|
-
context.keepMeshData = (
|
|
2368
|
+
var _params_keepMeshData;
|
|
2369
|
+
context.keepMeshData = (_params_keepMeshData = params == null ? void 0 : params.keepMeshData) != null ? _params_keepMeshData : false;
|
|
2465
2370
|
masterPromiseInfo.onCancel(function() {
|
|
2466
2371
|
var chainPromises = context.chainPromises;
|
|
2467
2372
|
for(var _iterator = _create_for_of_iterator_helper_loose(chainPromises), _step; !(_step = _iterator()).done;){
|
|
@@ -2469,7 +2374,10 @@ var GLTFLoader = /*#__PURE__*/ function(Loader) {
|
|
|
2469
2374
|
promise.cancel();
|
|
2470
2375
|
}
|
|
2471
2376
|
});
|
|
2472
|
-
|
|
2377
|
+
((params == null ? void 0 : params.pipeline) || GLTFPipeline.defaultPipeline)._parse(context).then(function(glTFResource) {
|
|
2378
|
+
resourceManager.addContentRestorer(restorer);
|
|
2379
|
+
masterPromiseInfo.resolve(glTFResource);
|
|
2380
|
+
}).catch(function(e) {
|
|
2473
2381
|
console.error(e);
|
|
2474
2382
|
masterPromiseInfo.reject("Error loading glTF model from " + url + " .");
|
|
2475
2383
|
});
|
|
@@ -2478,7 +2386,7 @@ var GLTFLoader = /*#__PURE__*/ function(Loader) {
|
|
|
2478
2386
|
return GLTFLoader;
|
|
2479
2387
|
}(engineCore.Loader);
|
|
2480
2388
|
GLTFLoader = __decorate([
|
|
2481
|
-
engineCore.resourceLoader(engineCore.AssetType.
|
|
2389
|
+
engineCore.resourceLoader(engineCore.AssetType.GLTF, [
|
|
2482
2390
|
"gltf",
|
|
2483
2391
|
"glb"
|
|
2484
2392
|
])
|
|
@@ -2564,7 +2472,7 @@ var HDRLoader = (_HDRLoader = /*#__PURE__*/ function(Loader) {
|
|
|
2564
2472
|
return textureArray;
|
|
2565
2473
|
};
|
|
2566
2474
|
HDRLoader1._calcProjectionSpherical = function _calcProjectionSpherical(vDir, pixels, inputWidth, inputHeight) {
|
|
2567
|
-
var theta = Math.atan2(vDir.z,
|
|
2475
|
+
var theta = Math.atan2(vDir.z, vDir.x);
|
|
2568
2476
|
var phi = Math.acos(vDir.y);
|
|
2569
2477
|
while(theta < -PI){
|
|
2570
2478
|
theta += 2 * PI;
|
|
@@ -3247,7 +3155,7 @@ var BufferReader = /*#__PURE__*/ function() {
|
|
|
3247
3155
|
var strByteLength = this.nextUint16();
|
|
3248
3156
|
var uint8Array = new Uint8Array(this.buffer, this._offset, strByteLength);
|
|
3249
3157
|
this._offset += strByteLength;
|
|
3250
|
-
return
|
|
3158
|
+
return engineCore.Utils.decodeText(uint8Array);
|
|
3251
3159
|
};
|
|
3252
3160
|
/**
|
|
3253
3161
|
* image data 放在最后
|
|
@@ -3332,8 +3240,8 @@ var FileHeader = /*#__PURE__*/ function() {
|
|
|
3332
3240
|
var typeUint8Array = new Uint8Array(arrayBuffer, 7, typeLen);
|
|
3333
3241
|
var nameLen = dataView.getUint16(7 + typeLen, true);
|
|
3334
3242
|
var nameUint8Array = new Uint8Array(arrayBuffer, 9 + typeLen, nameLen);
|
|
3335
|
-
var name =
|
|
3336
|
-
var type =
|
|
3243
|
+
var name = engineCore.Utils.decodeText(nameUint8Array);
|
|
3244
|
+
var type = engineCore.Utils.decodeText(typeUint8Array);
|
|
3337
3245
|
var header = new FileHeader();
|
|
3338
3246
|
header.totalLength = totalLen;
|
|
3339
3247
|
header.name = name;
|
|
@@ -4283,28 +4191,57 @@ SpriteLoader = __decorate([
|
|
|
4283
4191
|
], false)
|
|
4284
4192
|
], SpriteLoader);
|
|
4285
4193
|
|
|
4194
|
+
/**
|
|
4195
|
+
* @internal
|
|
4196
|
+
*/ var Texture2DContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
|
|
4197
|
+
_inherits(Texture2DContentRestorer, ContentRestorer);
|
|
4198
|
+
function Texture2DContentRestorer(resource, url, requestConfig) {
|
|
4199
|
+
var _this;
|
|
4200
|
+
_this = ContentRestorer.call(this, resource) || this;
|
|
4201
|
+
_this.url = url;
|
|
4202
|
+
_this.requestConfig = requestConfig;
|
|
4203
|
+
return _this;
|
|
4204
|
+
}
|
|
4205
|
+
var _proto = Texture2DContentRestorer.prototype;
|
|
4206
|
+
/**
|
|
4207
|
+
* @override
|
|
4208
|
+
*/ _proto.restoreContent = function restoreContent() {
|
|
4209
|
+
var _this = this;
|
|
4210
|
+
return engineCore.request(this.url, this.requestConfig).then(function(image) {
|
|
4211
|
+
var resource = _this.resource;
|
|
4212
|
+
resource.setImageSource(image);
|
|
4213
|
+
resource.generateMipmaps();
|
|
4214
|
+
return resource;
|
|
4215
|
+
});
|
|
4216
|
+
};
|
|
4217
|
+
return Texture2DContentRestorer;
|
|
4218
|
+
}(engineCore.ContentRestorer);
|
|
4219
|
+
|
|
4286
4220
|
var Texture2DLoader = /*#__PURE__*/ function(Loader) {
|
|
4287
4221
|
_inherits(Texture2DLoader, Loader);
|
|
4288
4222
|
function Texture2DLoader() {
|
|
4289
4223
|
return Loader.apply(this, arguments);
|
|
4290
4224
|
}
|
|
4291
4225
|
var _proto = Texture2DLoader.prototype;
|
|
4292
|
-
|
|
4226
|
+
/**
|
|
4227
|
+
* @override
|
|
4228
|
+
*/ _proto.load = function load(item, resourceManager) {
|
|
4293
4229
|
var _this = this;
|
|
4294
4230
|
return new engineCore.AssetPromise(function(resolve, reject) {
|
|
4295
|
-
|
|
4231
|
+
var url = item.url;
|
|
4232
|
+
var requestConfig = _extends({}, item, {
|
|
4296
4233
|
type: "image"
|
|
4297
|
-
})
|
|
4298
|
-
|
|
4299
|
-
var params =
|
|
4300
|
-
var texture = new engineCore.Texture2D(resourceManager.engine, image.width, image.height, params.format, params.mipmap);
|
|
4301
|
-
/** @ts-ignore */ if (!texture._platformTexture) return;
|
|
4234
|
+
});
|
|
4235
|
+
_this.request(url, requestConfig).then(function(image) {
|
|
4236
|
+
var params = item.params;
|
|
4237
|
+
var texture = new engineCore.Texture2D(resourceManager.engine, image.width, image.height, params == null ? void 0 : params.format, params == null ? void 0 : params.mipmap);
|
|
4302
4238
|
texture.setImageSource(image);
|
|
4303
4239
|
texture.generateMipmaps();
|
|
4304
|
-
if (
|
|
4305
|
-
var
|
|
4306
|
-
texture.name =
|
|
4240
|
+
if (url.indexOf("data:") !== 0) {
|
|
4241
|
+
var index = url.lastIndexOf("/");
|
|
4242
|
+
texture.name = url.substring(index + 1);
|
|
4307
4243
|
}
|
|
4244
|
+
resourceManager.addContentRestorer(new Texture2DContentRestorer(texture, url, requestConfig));
|
|
4308
4245
|
resolve(texture);
|
|
4309
4246
|
}).catch(function(e) {
|
|
4310
4247
|
reject(e);
|
|
@@ -4322,32 +4259,70 @@ Texture2DLoader = __decorate([
|
|
|
4322
4259
|
])
|
|
4323
4260
|
], Texture2DLoader);
|
|
4324
4261
|
|
|
4262
|
+
/**
|
|
4263
|
+
* @internal
|
|
4264
|
+
*/ var TextureCubeContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
|
|
4265
|
+
_inherits(TextureCubeContentRestorer, ContentRestorer);
|
|
4266
|
+
function TextureCubeContentRestorer(resource, urls, requestConfig) {
|
|
4267
|
+
var _this;
|
|
4268
|
+
_this = ContentRestorer.call(this, resource) || this;
|
|
4269
|
+
_this.urls = urls;
|
|
4270
|
+
_this.requestConfig = requestConfig;
|
|
4271
|
+
return _this;
|
|
4272
|
+
}
|
|
4273
|
+
var _proto = TextureCubeContentRestorer.prototype;
|
|
4274
|
+
/**
|
|
4275
|
+
* @override
|
|
4276
|
+
*/ _proto.restoreContent = function restoreContent() {
|
|
4277
|
+
var _this = this;
|
|
4278
|
+
return new engineCore.AssetPromise(function(resolve, reject) {
|
|
4279
|
+
Promise.all(_this.urls.map(function(url) {
|
|
4280
|
+
return engineCore.request(url, _this.requestConfig);
|
|
4281
|
+
})).then(function(images) {
|
|
4282
|
+
var resource = _this.resource;
|
|
4283
|
+
for(var faceIndex = 0; faceIndex < 6; faceIndex++){
|
|
4284
|
+
resource.setImageSource(engineCore.TextureCubeFace.PositiveX + faceIndex, images[faceIndex], 0);
|
|
4285
|
+
}
|
|
4286
|
+
resource.generateMipmaps();
|
|
4287
|
+
resolve(resource);
|
|
4288
|
+
}).catch(function(e) {
|
|
4289
|
+
reject(e);
|
|
4290
|
+
});
|
|
4291
|
+
});
|
|
4292
|
+
};
|
|
4293
|
+
return TextureCubeContentRestorer;
|
|
4294
|
+
}(engineCore.ContentRestorer);
|
|
4295
|
+
|
|
4325
4296
|
var TextureCubeLoader = /*#__PURE__*/ function(Loader) {
|
|
4326
4297
|
_inherits(TextureCubeLoader, Loader);
|
|
4327
4298
|
function TextureCubeLoader() {
|
|
4328
4299
|
return Loader.apply(this, arguments);
|
|
4329
4300
|
}
|
|
4330
4301
|
var _proto = TextureCubeLoader.prototype;
|
|
4331
|
-
|
|
4302
|
+
/**
|
|
4303
|
+
* @override
|
|
4304
|
+
*/ _proto.load = function load(item, resourceManager) {
|
|
4332
4305
|
var _this = this;
|
|
4333
4306
|
return new engineCore.AssetPromise(function(resolve, reject) {
|
|
4334
|
-
|
|
4335
|
-
|
|
4336
|
-
|
|
4337
|
-
|
|
4307
|
+
var urls = item.urls;
|
|
4308
|
+
var requestConfig = _extends({}, item, {
|
|
4309
|
+
type: "image"
|
|
4310
|
+
});
|
|
4311
|
+
Promise.all(urls.map(function(url) {
|
|
4312
|
+
return _this.request(url, requestConfig);
|
|
4338
4313
|
})).then(function(images) {
|
|
4339
4314
|
var _images_ = images[0], width = _images_.width, height = _images_.height;
|
|
4340
4315
|
if (width !== height) {
|
|
4341
4316
|
console.error("The cube texture must have the same width and height");
|
|
4342
4317
|
return;
|
|
4343
4318
|
}
|
|
4344
|
-
var
|
|
4345
|
-
/** @ts-ignore */ if (!tex._platformTexture) return;
|
|
4319
|
+
var texture = new engineCore.TextureCube(resourceManager.engine, width);
|
|
4346
4320
|
for(var faceIndex = 0; faceIndex < 6; faceIndex++){
|
|
4347
|
-
|
|
4321
|
+
texture.setImageSource(engineCore.TextureCubeFace.PositiveX + faceIndex, images[faceIndex], 0);
|
|
4348
4322
|
}
|
|
4349
|
-
|
|
4350
|
-
|
|
4323
|
+
texture.generateMipmaps();
|
|
4324
|
+
resourceManager.addContentRestorer(new TextureCubeContentRestorer(texture, urls, requestConfig));
|
|
4325
|
+
resolve(texture);
|
|
4351
4326
|
}).catch(function(e) {
|
|
4352
4327
|
reject(e);
|
|
4353
4328
|
});
|
|
@@ -4361,6 +4336,30 @@ TextureCubeLoader = __decorate([
|
|
|
4361
4336
|
])
|
|
4362
4337
|
], TextureCubeLoader);
|
|
4363
4338
|
|
|
4339
|
+
var AnimationClipLoader = /*#__PURE__*/ function(Loader) {
|
|
4340
|
+
_inherits(AnimationClipLoader, Loader);
|
|
4341
|
+
function AnimationClipLoader() {
|
|
4342
|
+
return Loader.apply(this, arguments);
|
|
4343
|
+
}
|
|
4344
|
+
var _proto = AnimationClipLoader.prototype;
|
|
4345
|
+
_proto.load = function load(item, resourceManager) {
|
|
4346
|
+
var _this = this;
|
|
4347
|
+
return new engineCore.AssetPromise(function(resolve, reject) {
|
|
4348
|
+
_this.request(item.url, _extends({}, item, {
|
|
4349
|
+
type: "arraybuffer"
|
|
4350
|
+
})).then(function(data) {
|
|
4351
|
+
return decode(data, resourceManager.engine);
|
|
4352
|
+
}).catch(reject);
|
|
4353
|
+
});
|
|
4354
|
+
};
|
|
4355
|
+
return AnimationClipLoader;
|
|
4356
|
+
}(engineCore.Loader);
|
|
4357
|
+
AnimationClipLoader = __decorate([
|
|
4358
|
+
engineCore.resourceLoader(engineCore.AssetType.AnimationClip, [
|
|
4359
|
+
"ani"
|
|
4360
|
+
])
|
|
4361
|
+
], AnimationClipLoader);
|
|
4362
|
+
|
|
4364
4363
|
var SceneLoader = /*#__PURE__*/ function(Loader) {
|
|
4365
4364
|
_inherits(SceneLoader, Loader);
|
|
4366
4365
|
function SceneLoader() {
|
|
@@ -4405,7 +4404,7 @@ var SceneLoader = /*#__PURE__*/ function(Loader) {
|
|
|
4405
4404
|
backgroundPromise = resourceManager.getResourceByRef(background.sky).then(function(light) {
|
|
4406
4405
|
var sky = scene.background.sky;
|
|
4407
4406
|
var skyMaterial = new engineCore.SkyBoxMaterial(engine);
|
|
4408
|
-
skyMaterial.
|
|
4407
|
+
skyMaterial.texture = light.specularTexture;
|
|
4409
4408
|
skyMaterial.textureDecodeRGBM = true;
|
|
4410
4409
|
sky.material = skyMaterial;
|
|
4411
4410
|
sky.mesh = engineCore.PrimitiveMesh.createCuboid(engine, 1, 1, 1);
|
|
@@ -4461,11 +4460,411 @@ ReflectionParser.registerCustomParseComponent("TextRenderer", /*#__PURE__*/ _asy
|
|
|
4461
4460
|
});
|
|
4462
4461
|
}));
|
|
4463
4462
|
|
|
4463
|
+
var _KHR_draco_mesh_compression;
|
|
4464
|
+
var KHR_draco_mesh_compression = (_KHR_draco_mesh_compression = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
4465
|
+
_inherits(KHR_draco_mesh_compression1, GLTFExtensionParser);
|
|
4466
|
+
function KHR_draco_mesh_compression1() {
|
|
4467
|
+
return GLTFExtensionParser.apply(this, arguments);
|
|
4468
|
+
}
|
|
4469
|
+
var _proto = KHR_draco_mesh_compression1.prototype;
|
|
4470
|
+
/**
|
|
4471
|
+
* @override
|
|
4472
|
+
*/ _proto.initialize = function initialize() {
|
|
4473
|
+
if (!KHR_draco_mesh_compression._decoder) {
|
|
4474
|
+
KHR_draco_mesh_compression._decoder = new engineDraco.DRACODecoder();
|
|
4475
|
+
}
|
|
4476
|
+
};
|
|
4477
|
+
/**
|
|
4478
|
+
* @override
|
|
4479
|
+
*/ _proto.createAndParse = function createAndParse(context, schema, glTFPrimitive, glTFMesh) {
|
|
4480
|
+
var _this = this;
|
|
4481
|
+
var glTF = context.glTF, buffers = context.buffers, engine = context.glTFResource.engine;
|
|
4482
|
+
var bufferViews = glTF.bufferViews, accessors = glTF.accessors;
|
|
4483
|
+
var bufferViewIndex = schema.bufferView, gltfAttributeMap = schema.attributes;
|
|
4484
|
+
var attributeMap = {};
|
|
4485
|
+
var attributeTypeMap = {};
|
|
4486
|
+
for(var attributeName in gltfAttributeMap){
|
|
4487
|
+
attributeMap[attributeName] = gltfAttributeMap[attributeName];
|
|
4488
|
+
}
|
|
4489
|
+
for(var attributeName1 in glTFPrimitive.attributes){
|
|
4490
|
+
if (gltfAttributeMap[attributeName1] !== undefined) {
|
|
4491
|
+
var accessorDef = accessors[glTFPrimitive.attributes[attributeName1]];
|
|
4492
|
+
attributeTypeMap[attributeName1] = GLTFUtils.getComponentType(accessorDef.componentType).name;
|
|
4493
|
+
}
|
|
4494
|
+
}
|
|
4495
|
+
var indexAccessor = accessors[glTFPrimitive.indices];
|
|
4496
|
+
var indexType = GLTFUtils.getComponentType(indexAccessor.componentType).name;
|
|
4497
|
+
var taskConfig = {
|
|
4498
|
+
attributeIDs: attributeMap,
|
|
4499
|
+
attributeTypes: attributeTypeMap,
|
|
4500
|
+
useUniqueIDs: true,
|
|
4501
|
+
indexType: indexType
|
|
4502
|
+
};
|
|
4503
|
+
var buffer = GLTFUtils.getBufferViewData(bufferViews[bufferViewIndex], buffers);
|
|
4504
|
+
return KHR_draco_mesh_compression._decoder.decode(buffer, taskConfig).then(function(decodedGeometry) {
|
|
4505
|
+
var mesh = new engineCore.ModelMesh(engine, glTFMesh.name);
|
|
4506
|
+
return _this._parseMeshFromGLTFPrimitiveDraco(mesh, glTFMesh, glTFPrimitive, glTF, function(attributeSemantic) {
|
|
4507
|
+
for(var j = 0; j < decodedGeometry.attributes.length; j++){
|
|
4508
|
+
if (decodedGeometry.attributes[j].name === attributeSemantic) {
|
|
4509
|
+
return decodedGeometry.attributes[j].array;
|
|
4510
|
+
}
|
|
4511
|
+
}
|
|
4512
|
+
return null;
|
|
4513
|
+
}, function(attributeSemantic, shapeIndex) {
|
|
4514
|
+
throw "BlendShape animation is not supported when using draco.";
|
|
4515
|
+
}, function() {
|
|
4516
|
+
return decodedGeometry.index.array;
|
|
4517
|
+
}, context.keepMeshData);
|
|
4518
|
+
});
|
|
4519
|
+
};
|
|
4520
|
+
_proto._parseMeshFromGLTFPrimitiveDraco = function _parseMeshFromGLTFPrimitiveDraco(mesh, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
|
|
4521
|
+
var attributes = gltfPrimitive.attributes, targets = gltfPrimitive.targets, indices = gltfPrimitive.indices, mode = gltfPrimitive.mode;
|
|
4522
|
+
var vertexCount;
|
|
4523
|
+
var accessors = gltf.accessors;
|
|
4524
|
+
var accessor = accessors[attributes["POSITION"]];
|
|
4525
|
+
var positionBuffer = getVertexBufferData("POSITION");
|
|
4526
|
+
var positions = GLTFUtils.floatBufferToVector3Array(positionBuffer);
|
|
4527
|
+
mesh.setPositions(positions);
|
|
4528
|
+
var bounds = mesh.bounds;
|
|
4529
|
+
vertexCount = accessor.count;
|
|
4530
|
+
if (accessor.min && accessor.max) {
|
|
4531
|
+
bounds.min.copyFromArray(accessor.min);
|
|
4532
|
+
bounds.max.copyFromArray(accessor.max);
|
|
4533
|
+
} else {
|
|
4534
|
+
var position = KHR_draco_mesh_compression._tempVector3;
|
|
4535
|
+
var min = bounds.min, max = bounds.max;
|
|
4536
|
+
min.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
|
|
4537
|
+
max.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
|
|
4538
|
+
var stride = positionBuffer.length / vertexCount;
|
|
4539
|
+
for(var j = 0; j < vertexCount; j++){
|
|
4540
|
+
var offset = j * stride;
|
|
4541
|
+
position.copyFromArray(positionBuffer, offset);
|
|
4542
|
+
engineMath.Vector3.min(min, position, min);
|
|
4543
|
+
engineMath.Vector3.max(max, position, max);
|
|
4544
|
+
}
|
|
4545
|
+
}
|
|
4546
|
+
for(var attributeSemantic in attributes){
|
|
4547
|
+
if (attributeSemantic === "POSITION") {
|
|
4548
|
+
continue;
|
|
4549
|
+
}
|
|
4550
|
+
var bufferData = getVertexBufferData(attributeSemantic);
|
|
4551
|
+
switch(attributeSemantic){
|
|
4552
|
+
case "NORMAL":
|
|
4553
|
+
var normals = GLTFUtils.floatBufferToVector3Array(bufferData);
|
|
4554
|
+
mesh.setNormals(normals);
|
|
4555
|
+
break;
|
|
4556
|
+
case "TEXCOORD_0":
|
|
4557
|
+
var texturecoords = GLTFUtils.floatBufferToVector2Array(bufferData);
|
|
4558
|
+
mesh.setUVs(texturecoords, 0);
|
|
4559
|
+
break;
|
|
4560
|
+
case "TEXCOORD_1":
|
|
4561
|
+
var texturecoords1 = GLTFUtils.floatBufferToVector2Array(bufferData);
|
|
4562
|
+
mesh.setUVs(texturecoords1, 1);
|
|
4563
|
+
break;
|
|
4564
|
+
case "TEXCOORD_2":
|
|
4565
|
+
var texturecoords2 = GLTFUtils.floatBufferToVector2Array(bufferData);
|
|
4566
|
+
mesh.setUVs(texturecoords2, 2);
|
|
4567
|
+
break;
|
|
4568
|
+
case "TEXCOORD_3":
|
|
4569
|
+
var texturecoords3 = GLTFUtils.floatBufferToVector2Array(bufferData);
|
|
4570
|
+
mesh.setUVs(texturecoords3, 3);
|
|
4571
|
+
break;
|
|
4572
|
+
case "TEXCOORD_4":
|
|
4573
|
+
var texturecoords4 = GLTFUtils.floatBufferToVector2Array(bufferData);
|
|
4574
|
+
mesh.setUVs(texturecoords4, 4);
|
|
4575
|
+
break;
|
|
4576
|
+
case "TEXCOORD_5":
|
|
4577
|
+
var texturecoords5 = GLTFUtils.floatBufferToVector2Array(bufferData);
|
|
4578
|
+
mesh.setUVs(texturecoords5, 5);
|
|
4579
|
+
break;
|
|
4580
|
+
case "TEXCOORD_6":
|
|
4581
|
+
var texturecoords6 = GLTFUtils.floatBufferToVector2Array(bufferData);
|
|
4582
|
+
mesh.setUVs(texturecoords6, 6);
|
|
4583
|
+
break;
|
|
4584
|
+
case "TEXCOORD_7":
|
|
4585
|
+
var texturecoords7 = GLTFUtils.floatBufferToVector2Array(bufferData);
|
|
4586
|
+
mesh.setUVs(texturecoords7, 7);
|
|
4587
|
+
break;
|
|
4588
|
+
case "COLOR_0":
|
|
4589
|
+
var colors = GLTFUtils.floatBufferToColorArray(bufferData, accessors[attributes["COLOR_0"]].type === AccessorType.VEC3);
|
|
4590
|
+
mesh.setColors(colors);
|
|
4591
|
+
break;
|
|
4592
|
+
case "TANGENT":
|
|
4593
|
+
var tangents = GLTFUtils.floatBufferToVector4Array(bufferData);
|
|
4594
|
+
mesh.setTangents(tangents);
|
|
4595
|
+
break;
|
|
4596
|
+
case "JOINTS_0":
|
|
4597
|
+
var joints = GLTFUtils.floatBufferToVector4Array(bufferData);
|
|
4598
|
+
mesh.setBoneIndices(joints);
|
|
4599
|
+
break;
|
|
4600
|
+
case "WEIGHTS_0":
|
|
4601
|
+
var weights = GLTFUtils.floatBufferToVector4Array(bufferData);
|
|
4602
|
+
mesh.setBoneWeights(weights);
|
|
4603
|
+
break;
|
|
4604
|
+
}
|
|
4605
|
+
}
|
|
4606
|
+
// Indices
|
|
4607
|
+
if (indices !== undefined) {
|
|
4608
|
+
var indexAccessor = gltf.accessors[indices];
|
|
4609
|
+
var indexData = getIndexBufferData();
|
|
4610
|
+
mesh.setIndices(indexData);
|
|
4611
|
+
mesh.addSubMesh(0, indexAccessor.count, mode);
|
|
4612
|
+
} else {
|
|
4613
|
+
mesh.addSubMesh(0, vertexCount, mode);
|
|
4614
|
+
}
|
|
4615
|
+
// BlendShapes
|
|
4616
|
+
targets && GLTFMeshParser._createBlendShape(mesh, null, gltfMesh, targets, getBlendShapeData);
|
|
4617
|
+
mesh.uploadData(!keepMeshData);
|
|
4618
|
+
return Promise.resolve(mesh);
|
|
4619
|
+
};
|
|
4620
|
+
return KHR_draco_mesh_compression1;
|
|
4621
|
+
}(GLTFExtensionParser), function() {
|
|
4622
|
+
_KHR_draco_mesh_compression._tempVector3 = new engineMath.Vector3();
|
|
4623
|
+
}(), _KHR_draco_mesh_compression);
|
|
4624
|
+
KHR_draco_mesh_compression = __decorate([
|
|
4625
|
+
registerGLTFExtension("KHR_draco_mesh_compression", exports.GLTFExtensionMode.CreateAndParse)
|
|
4626
|
+
], KHR_draco_mesh_compression);
|
|
4627
|
+
|
|
4628
|
+
var KHR_lights_punctual = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
4629
|
+
_inherits(KHR_lights_punctual, GLTFExtensionParser);
|
|
4630
|
+
function KHR_lights_punctual() {
|
|
4631
|
+
return GLTFExtensionParser.apply(this, arguments);
|
|
4632
|
+
}
|
|
4633
|
+
var _proto = KHR_lights_punctual.prototype;
|
|
4634
|
+
/**
|
|
4635
|
+
* @override
|
|
4636
|
+
*/ _proto.additiveParse = function additiveParse(context, entity, extensionSchema) {
|
|
4637
|
+
var lightsSchema = context.glTF.extensions.KHR_lights_punctual.lights;
|
|
4638
|
+
var lightSchema = lightsSchema[extensionSchema.light];
|
|
4639
|
+
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;
|
|
4640
|
+
var glTFResource = context.glTFResource;
|
|
4641
|
+
var light;
|
|
4642
|
+
if (type === "directional") {
|
|
4643
|
+
light = entity.addComponent(engineCore.DirectLight);
|
|
4644
|
+
} else if (type === "point") {
|
|
4645
|
+
light = entity.addComponent(engineCore.PointLight);
|
|
4646
|
+
} else if (type === "spot") {
|
|
4647
|
+
light = entity.addComponent(engineCore.SpotLight);
|
|
4648
|
+
}
|
|
4649
|
+
if (color) {
|
|
4650
|
+
light.color.set(color[0], color[1], color[2], 1);
|
|
4651
|
+
}
|
|
4652
|
+
light.intensity = intensity;
|
|
4653
|
+
if (range && !_instanceof(light, engineCore.DirectLight)) {
|
|
4654
|
+
light.distance = range;
|
|
4655
|
+
}
|
|
4656
|
+
if (spot && _instanceof(light, engineCore.SpotLight)) {
|
|
4657
|
+
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;
|
|
4658
|
+
light.angle = innerConeAngle;
|
|
4659
|
+
light.penumbra = outerConeAngle - innerConeAngle;
|
|
4660
|
+
}
|
|
4661
|
+
if (!glTFResource.lights) glTFResource.lights = [];
|
|
4662
|
+
glTFResource.lights.push(light);
|
|
4663
|
+
};
|
|
4664
|
+
return KHR_lights_punctual;
|
|
4665
|
+
}(GLTFExtensionParser);
|
|
4666
|
+
KHR_lights_punctual = __decorate([
|
|
4667
|
+
registerGLTFExtension("KHR_lights_punctual", exports.GLTFExtensionMode.AdditiveParse)
|
|
4668
|
+
], KHR_lights_punctual);
|
|
4669
|
+
|
|
4670
|
+
var KHR_materials_clearcoat = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
4671
|
+
_inherits(KHR_materials_clearcoat, GLTFExtensionParser);
|
|
4672
|
+
function KHR_materials_clearcoat() {
|
|
4673
|
+
return GLTFExtensionParser.apply(this, arguments);
|
|
4674
|
+
}
|
|
4675
|
+
var _proto = KHR_materials_clearcoat.prototype;
|
|
4676
|
+
/**
|
|
4677
|
+
* @override
|
|
4678
|
+
*/ _proto.additiveParse = function additiveParse(context, material, schema) {
|
|
4679
|
+
var textures = context.glTFResource.textures;
|
|
4680
|
+
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;
|
|
4681
|
+
material.clearCoat = clearcoatFactor;
|
|
4682
|
+
material.clearCoatRoughness = clearcoatRoughnessFactor;
|
|
4683
|
+
if (clearcoatTexture) {
|
|
4684
|
+
material.clearCoatTexture = textures[clearcoatTexture.index];
|
|
4685
|
+
GLTFMaterialParser._checkOtherTextureTransform(clearcoatTexture, "Clear coat");
|
|
4686
|
+
}
|
|
4687
|
+
if (clearcoatRoughnessTexture) {
|
|
4688
|
+
material.clearCoatRoughnessTexture = textures[clearcoatRoughnessTexture.index];
|
|
4689
|
+
GLTFMaterialParser._checkOtherTextureTransform(clearcoatRoughnessTexture, "Clear coat roughness");
|
|
4690
|
+
}
|
|
4691
|
+
if (clearcoatNormalTexture) {
|
|
4692
|
+
material.clearCoatNormalTexture = textures[clearcoatNormalTexture.index];
|
|
4693
|
+
GLTFMaterialParser._checkOtherTextureTransform(clearcoatNormalTexture, "Clear coat normal");
|
|
4694
|
+
}
|
|
4695
|
+
};
|
|
4696
|
+
return KHR_materials_clearcoat;
|
|
4697
|
+
}(GLTFExtensionParser);
|
|
4698
|
+
KHR_materials_clearcoat = __decorate([
|
|
4699
|
+
registerGLTFExtension("KHR_materials_clearcoat", exports.GLTFExtensionMode.AdditiveParse)
|
|
4700
|
+
], KHR_materials_clearcoat);
|
|
4701
|
+
|
|
4702
|
+
var KHR_materials_pbrSpecularGlossiness = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
4703
|
+
_inherits(KHR_materials_pbrSpecularGlossiness, GLTFExtensionParser);
|
|
4704
|
+
function KHR_materials_pbrSpecularGlossiness() {
|
|
4705
|
+
return GLTFExtensionParser.apply(this, arguments);
|
|
4706
|
+
}
|
|
4707
|
+
var _proto = KHR_materials_pbrSpecularGlossiness.prototype;
|
|
4708
|
+
/**
|
|
4709
|
+
* @override
|
|
4710
|
+
*/ _proto.createAndParse = function createAndParse(context, schema, ownerSchema) {
|
|
4711
|
+
var _context_glTFResource = context.glTFResource, engine = _context_glTFResource.engine, textures = _context_glTFResource.textures;
|
|
4712
|
+
var material = new engineCore.PBRSpecularMaterial(engine);
|
|
4713
|
+
var diffuseFactor = schema.diffuseFactor, diffuseTexture = schema.diffuseTexture, specularFactor = schema.specularFactor, glossinessFactor = schema.glossinessFactor, specularGlossinessTexture = schema.specularGlossinessTexture;
|
|
4714
|
+
if (diffuseFactor) {
|
|
4715
|
+
material.baseColor = new engineMath.Color(engineMath.Color.linearToGammaSpace(diffuseFactor[0]), engineMath.Color.linearToGammaSpace(diffuseFactor[1]), engineMath.Color.linearToGammaSpace(diffuseFactor[2]), diffuseFactor[3]);
|
|
4716
|
+
}
|
|
4717
|
+
if (diffuseTexture) {
|
|
4718
|
+
material.baseTexture = textures[diffuseTexture.index];
|
|
4719
|
+
GLTFParser.executeExtensionsAdditiveAndParse(diffuseTexture.extensions, context, material, diffuseTexture);
|
|
4720
|
+
}
|
|
4721
|
+
if (specularFactor) {
|
|
4722
|
+
material.specularColor = new engineMath.Color(engineMath.Color.linearToGammaSpace(specularFactor[0]), engineMath.Color.linearToGammaSpace(specularFactor[1]), engineMath.Color.linearToGammaSpace(specularFactor[2]));
|
|
4723
|
+
}
|
|
4724
|
+
if (glossinessFactor !== undefined) {
|
|
4725
|
+
material.glossiness = glossinessFactor;
|
|
4726
|
+
}
|
|
4727
|
+
if (specularGlossinessTexture) {
|
|
4728
|
+
material.specularGlossinessTexture = textures[specularGlossinessTexture.index];
|
|
4729
|
+
GLTFMaterialParser._checkOtherTextureTransform(specularGlossinessTexture, "Specular glossiness");
|
|
4730
|
+
}
|
|
4731
|
+
material.name = ownerSchema.name;
|
|
4732
|
+
GLTFMaterialParser._parseStandardProperty(context, material, ownerSchema);
|
|
4733
|
+
return material;
|
|
4734
|
+
};
|
|
4735
|
+
return KHR_materials_pbrSpecularGlossiness;
|
|
4736
|
+
}(GLTFExtensionParser);
|
|
4737
|
+
KHR_materials_pbrSpecularGlossiness = __decorate([
|
|
4738
|
+
registerGLTFExtension("KHR_materials_pbrSpecularGlossiness", exports.GLTFExtensionMode.CreateAndParse)
|
|
4739
|
+
], KHR_materials_pbrSpecularGlossiness);
|
|
4740
|
+
|
|
4741
|
+
var KHR_materials_unlit = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
4742
|
+
_inherits(KHR_materials_unlit, GLTFExtensionParser);
|
|
4743
|
+
function KHR_materials_unlit() {
|
|
4744
|
+
return GLTFExtensionParser.apply(this, arguments);
|
|
4745
|
+
}
|
|
4746
|
+
var _proto = KHR_materials_unlit.prototype;
|
|
4747
|
+
/**
|
|
4748
|
+
* @override
|
|
4749
|
+
*/ _proto.createAndParse = function createAndParse(context, _, ownerSchema) {
|
|
4750
|
+
var engine = context.glTFResource.engine;
|
|
4751
|
+
var material = new engineCore.UnlitMaterial(engine);
|
|
4752
|
+
material.name = ownerSchema.name;
|
|
4753
|
+
GLTFMaterialParser._parseStandardProperty(context, material, ownerSchema);
|
|
4754
|
+
return material;
|
|
4755
|
+
};
|
|
4756
|
+
return KHR_materials_unlit;
|
|
4757
|
+
}(GLTFExtensionParser);
|
|
4758
|
+
KHR_materials_unlit = __decorate([
|
|
4759
|
+
registerGLTFExtension("KHR_materials_unlit", exports.GLTFExtensionMode.CreateAndParse)
|
|
4760
|
+
], KHR_materials_unlit);
|
|
4761
|
+
|
|
4762
|
+
var KHR_mesh_quantization = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
4763
|
+
_inherits(KHR_mesh_quantization, GLTFExtensionParser);
|
|
4764
|
+
function KHR_mesh_quantization() {
|
|
4765
|
+
return GLTFExtensionParser.apply(this, arguments);
|
|
4766
|
+
}
|
|
4767
|
+
return KHR_mesh_quantization;
|
|
4768
|
+
}(GLTFExtensionParser);
|
|
4769
|
+
KHR_mesh_quantization = __decorate([
|
|
4770
|
+
registerGLTFExtension("KHR_mesh_quantization", exports.GLTFExtensionMode.AdditiveParse)
|
|
4771
|
+
], KHR_mesh_quantization);
|
|
4772
|
+
|
|
4773
|
+
var KHR_texture_transform = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
4774
|
+
_inherits(KHR_texture_transform, GLTFExtensionParser);
|
|
4775
|
+
function KHR_texture_transform() {
|
|
4776
|
+
return GLTFExtensionParser.apply(this, arguments);
|
|
4777
|
+
}
|
|
4778
|
+
var _proto = KHR_texture_transform.prototype;
|
|
4779
|
+
/**
|
|
4780
|
+
* @override
|
|
4781
|
+
*/ _proto.additiveParse = function additiveParse(context, material, schema) {
|
|
4782
|
+
var offset = schema.offset, rotation = schema.rotation, scale = schema.scale, texCoord = schema.texCoord;
|
|
4783
|
+
if (offset) {
|
|
4784
|
+
material.tilingOffset.z = offset[0];
|
|
4785
|
+
material.tilingOffset.w = offset[1];
|
|
4786
|
+
}
|
|
4787
|
+
if (scale) {
|
|
4788
|
+
material.tilingOffset.x = scale[0];
|
|
4789
|
+
material.tilingOffset.y = scale[1];
|
|
4790
|
+
}
|
|
4791
|
+
if (rotation) {
|
|
4792
|
+
engineCore.Logger.warn("rotation in KHR_texture_transform is not supported now");
|
|
4793
|
+
}
|
|
4794
|
+
if (texCoord) {
|
|
4795
|
+
engineCore.Logger.warn("texCoord in KHR_texture_transform is not supported now");
|
|
4796
|
+
}
|
|
4797
|
+
};
|
|
4798
|
+
return KHR_texture_transform;
|
|
4799
|
+
}(GLTFExtensionParser);
|
|
4800
|
+
KHR_texture_transform = __decorate([
|
|
4801
|
+
registerGLTFExtension("KHR_texture_transform", exports.GLTFExtensionMode.AdditiveParse)
|
|
4802
|
+
], KHR_texture_transform);
|
|
4803
|
+
|
|
4804
|
+
var GALACEAN_materials_remap = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
4805
|
+
_inherits(GALACEAN_materials_remap, GLTFExtensionParser);
|
|
4806
|
+
function GALACEAN_materials_remap() {
|
|
4807
|
+
return GLTFExtensionParser.apply(this, arguments);
|
|
4808
|
+
}
|
|
4809
|
+
var _proto = GALACEAN_materials_remap.prototype;
|
|
4810
|
+
/**
|
|
4811
|
+
* @override
|
|
4812
|
+
*/ _proto.createAndParse = function createAndParse(context, schema) {
|
|
4813
|
+
var engine = context.glTFResource.engine;
|
|
4814
|
+
// @ts-ignore
|
|
4815
|
+
return engine.resourceManager.getResourceByRef(schema);
|
|
4816
|
+
};
|
|
4817
|
+
return GALACEAN_materials_remap;
|
|
4818
|
+
}(GLTFExtensionParser);
|
|
4819
|
+
GALACEAN_materials_remap = __decorate([
|
|
4820
|
+
registerGLTFExtension("GALACEAN_materials_remap", exports.GLTFExtensionMode.CreateAndParse)
|
|
4821
|
+
], GALACEAN_materials_remap);
|
|
4822
|
+
|
|
4823
|
+
var GALACEAN_animation_event = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
4824
|
+
_inherits(GALACEAN_animation_event, GLTFExtensionParser);
|
|
4825
|
+
function GALACEAN_animation_event() {
|
|
4826
|
+
return GLTFExtensionParser.apply(this, arguments);
|
|
4827
|
+
}
|
|
4828
|
+
var _proto = GALACEAN_animation_event.prototype;
|
|
4829
|
+
/**
|
|
4830
|
+
* @override
|
|
4831
|
+
*/ _proto.additiveParse = function additiveParse(context, animationClip, schema) {
|
|
4832
|
+
context.glTFResource.engine;
|
|
4833
|
+
var events = schema.events;
|
|
4834
|
+
events.map(function(eventData) {
|
|
4835
|
+
var event = new engineCore.AnimationEvent();
|
|
4836
|
+
event.functionName = eventData.functionName;
|
|
4837
|
+
event.time = eventData.time;
|
|
4838
|
+
event.parameter = eventData.parameter;
|
|
4839
|
+
animationClip.addEvent(event);
|
|
4840
|
+
});
|
|
4841
|
+
};
|
|
4842
|
+
return GALACEAN_animation_event;
|
|
4843
|
+
}(GLTFExtensionParser);
|
|
4844
|
+
GALACEAN_animation_event = __decorate([
|
|
4845
|
+
registerGLTFExtension("GALACEAN_animation_event", exports.GLTFExtensionMode.AdditiveParse)
|
|
4846
|
+
], GALACEAN_animation_event);
|
|
4847
|
+
|
|
4464
4848
|
exports.ComponentMap = ComponentMap;
|
|
4849
|
+
exports.GLTFAnimationParser = GLTFAnimationParser;
|
|
4850
|
+
exports.GLTFBufferParser = GLTFBufferParser;
|
|
4851
|
+
exports.GLTFEntityParser = GLTFEntityParser;
|
|
4852
|
+
exports.GLTFExtensionParser = GLTFExtensionParser;
|
|
4853
|
+
exports.GLTFMaterialParser = GLTFMaterialParser;
|
|
4854
|
+
exports.GLTFMeshParser = GLTFMeshParser;
|
|
4855
|
+
exports.GLTFParser = GLTFParser;
|
|
4856
|
+
exports.GLTFParserContext = GLTFParserContext;
|
|
4857
|
+
exports.GLTFPipeline = GLTFPipeline;
|
|
4465
4858
|
exports.GLTFResource = GLTFResource;
|
|
4859
|
+
exports.GLTFSceneParser = GLTFSceneParser;
|
|
4860
|
+
exports.GLTFSkinParser = GLTFSkinParser;
|
|
4861
|
+
exports.GLTFTextureParser = GLTFTextureParser;
|
|
4862
|
+
exports.GLTFUtils = GLTFUtils;
|
|
4863
|
+
exports.GLTFValidator = GLTFValidator;
|
|
4466
4864
|
exports.PrefabParser = PrefabParser;
|
|
4467
4865
|
exports.ReflectionParser = ReflectionParser;
|
|
4468
4866
|
exports.SceneParser = SceneParser;
|
|
4469
4867
|
exports.decode = decode;
|
|
4470
4868
|
exports.parseSingleKTX = parseSingleKTX;
|
|
4869
|
+
exports.registerGLTFExtension = registerGLTFExtension;
|
|
4471
4870
|
//# sourceMappingURL=main.js.map
|