@galacean/engine-loader 0.9.0-beta.80 → 1.0.0-alpha.6
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 +1423 -1003
- package/dist/main.js.map +1 -1
- package/dist/miniprogram.js +1457 -1037
- package/dist/module.js +1410 -1005
- package/dist/module.js.map +1 -1
- package/package.json +5 -5
- package/types/AnimationClipLoader.d.ts +1 -0
- package/types/GLTFContentRestorer.d.ts +3 -3
- package/types/GLTFLoader.d.ts +6 -0
- package/types/Texture2DContentRestorer.d.ts +2 -2
- package/types/TextureCubeContentRestorer.d.ts +2 -2
- package/types/gltf/GLTFPipeline.d.ts +1 -1
- package/types/gltf/GLTFResource.d.ts +7 -11
- package/types/gltf/GLTFSchema.d.ts +1 -1
- package/types/gltf/GLTFUtil.d.ts +8 -8
- package/types/gltf/extensions/GLTFExtensionParser.d.ts +1 -1
- package/types/gltf/extensions/GLTFExtensionSchema.d.ts +1 -1
- package/types/gltf/extensions/KHR_materials_variants.d.ts +6 -1
- package/types/gltf/extensions/index.d.ts +5 -2
- package/types/gltf/parser/GLTFAnimationParser.d.ts +1 -1
- package/types/gltf/parser/GLTFBufferParser.d.ts +1 -1
- package/types/gltf/parser/GLTFMaterialParser.d.ts +1 -1
- package/types/gltf/parser/GLTFMeshParser.d.ts +1 -1
- package/types/gltf/parser/GLTFParser.d.ts +1 -1
- package/types/gltf/parser/GLTFParserContext.d.ts +1 -1
- package/types/gltf/parser/GLTFSceneParser.d.ts +2 -2
- package/types/gltf/parser/GLTFTextureParser.d.ts +1 -1
- package/types/gltf/parser/GLTFValidator.d.ts +1 -1
- package/types/index.d.ts +2 -2
- package/types/resource-deserialize/resources/prefab/PrefabDesign.d.ts +4 -4
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 (target) {
|
|
@@ -107,10 +107,10 @@ function __generator(thisArg, body) {
|
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
var AnimatorControllerLoader = /*#__PURE__*/ function(
|
|
111
|
-
_inherits(AnimatorControllerLoader,
|
|
110
|
+
var AnimatorControllerLoader = /*#__PURE__*/ function(Loader1) {
|
|
111
|
+
_inherits(AnimatorControllerLoader, Loader1);
|
|
112
112
|
function AnimatorControllerLoader() {
|
|
113
|
-
return
|
|
113
|
+
return Loader1.apply(this, arguments);
|
|
114
114
|
}
|
|
115
115
|
var _proto = AnimatorControllerLoader.prototype;
|
|
116
116
|
_proto.load = function load(item, resourceManager) {
|
|
@@ -131,13 +131,16 @@ var AnimatorControllerLoader = /*#__PURE__*/ function(Loader) {
|
|
|
131
131
|
var states = stateMachineData.states;
|
|
132
132
|
var stateMachine = layer.stateMachine = new engineCore.AnimatorStateMachine();
|
|
133
133
|
states.forEach(function(stateData, stateIndex) {
|
|
134
|
-
var name = stateData.name, speed = stateData.speed, wrapMode = stateData.wrapMode, clipStartNormalizedTime = stateData.clipStartNormalizedTime, clipEndNormalizedTime = stateData.clipEndNormalizedTime, isDefaultState = stateData.isDefaultState, clipData = stateData.clip;
|
|
134
|
+
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;
|
|
135
135
|
var state = stateMachine.addState(name);
|
|
136
136
|
isDefaultState && (stateMachine.defaultState = state);
|
|
137
137
|
state.speed = speed;
|
|
138
138
|
state.wrapMode = wrapMode;
|
|
139
139
|
state.clipStartTime = clipStartNormalizedTime;
|
|
140
140
|
state.clipEndTime = clipEndNormalizedTime;
|
|
141
|
+
scripts == null ? void 0 : scripts.forEach(function(script) {
|
|
142
|
+
state.addStateMachineScript(engineCore.Loader.getClass(script));
|
|
143
|
+
});
|
|
141
144
|
if (clipData) {
|
|
142
145
|
promises.push(new Promise(function(resolve) {
|
|
143
146
|
//@ts-ignore
|
|
@@ -363,52 +366,192 @@ FontLoader = __decorate([
|
|
|
363
366
|
], false)
|
|
364
367
|
], FontLoader);
|
|
365
368
|
|
|
369
|
+
function _arrayLikeToArray(arr, len) {
|
|
370
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
371
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
372
|
+
return arr2;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
376
|
+
if (!o) return;
|
|
377
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
378
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
379
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
380
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
381
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
|
|
382
|
+
return _arrayLikeToArray(o, minLen);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
function _createForOfIteratorHelperLoose(o, allowArrayLike) {
|
|
386
|
+
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
387
|
+
if (it) return (it = it.call(o)).next.bind(it);
|
|
388
|
+
// Fallback for engines without symbol support
|
|
389
|
+
if (
|
|
390
|
+
Array.isArray(o) ||
|
|
391
|
+
(it = _unsupportedIterableToArray(o)) ||
|
|
392
|
+
(allowArrayLike && o && typeof o.length === "number")
|
|
393
|
+
) {
|
|
394
|
+
if (it) o = it;
|
|
395
|
+
var i = 0;
|
|
396
|
+
return function () {
|
|
397
|
+
if (i >= o.length) return { done: true };
|
|
398
|
+
return { done: false, value: o[i++] };
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
402
|
+
}
|
|
403
|
+
|
|
366
404
|
/**
|
|
367
405
|
* @internal
|
|
368
|
-
*/ var
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
this.masterPromiseInfo = new PromiseInfo();
|
|
379
|
-
this.promiseMap = {};
|
|
380
|
-
var promiseMap = this.promiseMap;
|
|
381
|
-
promiseMap["" + url + "?q=textures"] = this._initPromiseInfo(this.texturesPromiseInfo);
|
|
382
|
-
promiseMap["" + url + "?q=materials"] = this._initPromiseInfo(this.materialsPromiseInfo);
|
|
383
|
-
promiseMap["" + url + "?q=meshes"] = this._initPromiseInfo(this.meshesPromiseInfo);
|
|
384
|
-
promiseMap["" + url + "?q=animations"] = this._initPromiseInfo(this.animationClipsPromiseInfo);
|
|
385
|
-
promiseMap["" + url + "?q=defaultSceneRoot"] = this._initPromiseInfo(this.defaultSceneRootPromiseInfo);
|
|
386
|
-
promiseMap["" + url] = this._initPromiseInfo(this.masterPromiseInfo);
|
|
406
|
+
*/ var GLTFContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
|
|
407
|
+
_inherits(GLTFContentRestorer, ContentRestorer);
|
|
408
|
+
function GLTFContentRestorer() {
|
|
409
|
+
var _this;
|
|
410
|
+
_this = ContentRestorer.apply(this, arguments) || this;
|
|
411
|
+
_this.bufferRequests = [];
|
|
412
|
+
_this.glbBufferSlices = [];
|
|
413
|
+
_this.bufferTextures = [];
|
|
414
|
+
_this.meshes = [];
|
|
415
|
+
return _this;
|
|
387
416
|
}
|
|
388
|
-
var _proto =
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
417
|
+
var _proto = GLTFContentRestorer.prototype;
|
|
418
|
+
/**
|
|
419
|
+
* @override
|
|
420
|
+
*/ _proto.restoreContent = function restoreContent() {
|
|
421
|
+
var _this = this;
|
|
422
|
+
return new engineCore.AssetPromise(function(resolve, reject) {
|
|
423
|
+
Promise.all(_this.bufferRequests.map(function(bufferRequestInfo) {
|
|
424
|
+
return engineCore.request(bufferRequestInfo.url, bufferRequestInfo.config);
|
|
425
|
+
})).then(function(buffers) {
|
|
426
|
+
// Buffer parse
|
|
427
|
+
if (_this.isGLB) {
|
|
428
|
+
var glbBufferSlice = _this.glbBufferSlices;
|
|
429
|
+
var bigBuffer = buffers[0];
|
|
430
|
+
var bufferCount = glbBufferSlice.length;
|
|
431
|
+
buffers.length = bufferCount;
|
|
432
|
+
for(var i = 0; i < bufferCount; i++){
|
|
433
|
+
var slice = glbBufferSlice[i];
|
|
434
|
+
buffers[i] = bigBuffer.slice(slice.x, slice.x + slice.y);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
// Restore texture
|
|
438
|
+
engineCore.AssetPromise.all(_this.bufferTextures.map(function(textureRestoreInfo) {
|
|
439
|
+
var bufferView = textureRestoreInfo.bufferView;
|
|
440
|
+
var buffer = buffers[bufferView.buffer];
|
|
441
|
+
var _bufferView_byteOffset;
|
|
442
|
+
var bufferData = new Uint8Array(buffer, (_bufferView_byteOffset = bufferView.byteOffset) != null ? _bufferView_byteOffset : 0, bufferView.byteLength);
|
|
443
|
+
return GLTFUtil.loadImageBuffer(bufferData, textureRestoreInfo.mimeType).then(function(image) {
|
|
444
|
+
textureRestoreInfo.texture.setImageSource(image);
|
|
445
|
+
textureRestoreInfo.texture.generateMipmaps();
|
|
446
|
+
});
|
|
447
|
+
})).then(function() {
|
|
448
|
+
// Restore mesh
|
|
449
|
+
for(var _iterator = _createForOfIteratorHelperLoose(_this.meshes), _step; !(_step = _iterator()).done;){
|
|
450
|
+
var meshInfo = _step.value;
|
|
451
|
+
var mesh = meshInfo.mesh;
|
|
452
|
+
for(var _iterator1 = _createForOfIteratorHelperLoose(meshInfo.vertexBuffers), _step1; !(_step1 = _iterator1()).done;){
|
|
453
|
+
var bufferRestoreInfo = _step1.value;
|
|
454
|
+
var vertexData = _this._getBufferData(buffers, bufferRestoreInfo.data);
|
|
455
|
+
bufferRestoreInfo.buffer.setData(vertexData);
|
|
456
|
+
}
|
|
457
|
+
if (meshInfo.indexBuffer) {
|
|
458
|
+
var indexData = _this._getBufferData(buffers, meshInfo.indexBuffer);
|
|
459
|
+
mesh.setIndices(indexData);
|
|
460
|
+
}
|
|
461
|
+
for(var _iterator2 = _createForOfIteratorHelperLoose(meshInfo.blendShapes), _step2; !(_step2 = _iterator2()).done;){
|
|
462
|
+
var restoreInfo = _step2.value;
|
|
463
|
+
var frame = restoreInfo.blendShape.frames[0];
|
|
464
|
+
var positionData = _this._getBufferData(buffers, restoreInfo.position);
|
|
465
|
+
frame.deltaPositions = GLTFUtil.floatBufferToVector3Array(positionData);
|
|
466
|
+
if (restoreInfo.normal) {
|
|
467
|
+
var normalData = _this._getBufferData(buffers, restoreInfo.normal);
|
|
468
|
+
frame.deltaNormals = GLTFUtil.floatBufferToVector3Array(normalData);
|
|
469
|
+
}
|
|
470
|
+
if (restoreInfo.tangent) {
|
|
471
|
+
var tangentData = _this._getBufferData(buffers, restoreInfo.tangent);
|
|
472
|
+
frame.deltaTangents = GLTFUtil.floatBufferToVector3Array(tangentData);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
mesh.uploadData(true);
|
|
476
|
+
}
|
|
477
|
+
resolve(_this.resource);
|
|
478
|
+
}).catch(reject);
|
|
479
|
+
}).catch(reject);
|
|
395
480
|
});
|
|
396
|
-
promiseInfo.promise = promise;
|
|
397
|
-
return promise;
|
|
398
481
|
};
|
|
399
|
-
|
|
400
|
-
|
|
482
|
+
_proto._getBufferData = function _getBufferData(buffers, restoreInfo) {
|
|
483
|
+
var main = restoreInfo.main;
|
|
484
|
+
var buffer = buffers[main.bufferIndex];
|
|
485
|
+
var data = new main.TypedArray(buffer, main.byteOffset, main.length);
|
|
486
|
+
var sparseCount = restoreInfo.sparseCount;
|
|
487
|
+
if (sparseCount) {
|
|
488
|
+
var sparseIndex = restoreInfo.sparseIndices;
|
|
489
|
+
var sparseIndexBuffer = buffers[sparseIndex.bufferIndex];
|
|
490
|
+
var sparseIndexData = new sparseIndex.TypedArray(sparseIndexBuffer, sparseIndex.byteOffset, sparseIndex.length);
|
|
491
|
+
var sparseValue = restoreInfo.sparseValues;
|
|
492
|
+
var sparseValueBuffer = buffers[sparseValue.bufferIndex];
|
|
493
|
+
var sparseValueData = new sparseValue.TypedArray(sparseValueBuffer, sparseValue.byteOffset, sparseValue.length);
|
|
494
|
+
var typeSize = restoreInfo.typeSize;
|
|
495
|
+
for(var i = 0; i < sparseCount; i++){
|
|
496
|
+
var replaceIndex = sparseIndexData[i];
|
|
497
|
+
for(var j = 0; j < typeSize; j++){
|
|
498
|
+
data[replaceIndex * typeSize + j] = sparseValueData[i * typeSize + j];
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
return data;
|
|
503
|
+
};
|
|
504
|
+
return GLTFContentRestorer;
|
|
505
|
+
}(engineCore.ContentRestorer);
|
|
401
506
|
/**
|
|
402
507
|
* @internal
|
|
403
|
-
*/ var
|
|
508
|
+
*/ var BufferRequestInfo = function BufferRequestInfo(url, config) {
|
|
509
|
+
this.url = url;
|
|
510
|
+
this.config = config;
|
|
511
|
+
};
|
|
512
|
+
/**
|
|
513
|
+
* @internal
|
|
514
|
+
*/ var BufferTextureRestoreInfo = function BufferTextureRestoreInfo(texture, bufferView, mimeType) {
|
|
515
|
+
this.texture = texture;
|
|
516
|
+
this.bufferView = bufferView;
|
|
517
|
+
this.mimeType = mimeType;
|
|
518
|
+
};
|
|
519
|
+
/**
|
|
520
|
+
* @internal
|
|
521
|
+
*/ var ModelMeshRestoreInfo = function ModelMeshRestoreInfo() {
|
|
522
|
+
this.vertexBuffers = [];
|
|
523
|
+
this.blendShapes = [];
|
|
524
|
+
};
|
|
525
|
+
/**
|
|
526
|
+
* @internal
|
|
527
|
+
*/ var BufferRestoreInfo = function BufferRestoreInfo(buffer, data) {
|
|
528
|
+
this.buffer = buffer;
|
|
404
529
|
this.data = data;
|
|
405
|
-
this.interleaved = interleaved;
|
|
406
|
-
this.stride = stride;
|
|
407
|
-
this.vertexBindingInfos = {};
|
|
408
530
|
};
|
|
409
531
|
/**
|
|
410
532
|
* @internal
|
|
411
|
-
*/ var
|
|
533
|
+
*/ var BufferDataRestoreInfo = function BufferDataRestoreInfo(main, typeSize, sparseCount, sparseIndices, sparseValues) {
|
|
534
|
+
this.main = main;
|
|
535
|
+
this.typeSize = typeSize;
|
|
536
|
+
this.sparseCount = sparseCount;
|
|
537
|
+
this.sparseIndices = sparseIndices;
|
|
538
|
+
this.sparseValues = sparseValues;
|
|
539
|
+
};
|
|
540
|
+
/**
|
|
541
|
+
* @internal
|
|
542
|
+
*/ var RestoreDataAccessor = function RestoreDataAccessor(bufferIndex, TypedArray, byteOffset, length) {
|
|
543
|
+
this.bufferIndex = bufferIndex;
|
|
544
|
+
this.TypedArray = TypedArray;
|
|
545
|
+
this.byteOffset = byteOffset;
|
|
546
|
+
this.length = length;
|
|
547
|
+
};
|
|
548
|
+
/**
|
|
549
|
+
* @internal
|
|
550
|
+
*/ var BlendShapeRestoreInfo = function BlendShapeRestoreInfo(blendShape, position, normal, tangent) {
|
|
551
|
+
this.blendShape = blendShape;
|
|
552
|
+
this.position = position;
|
|
553
|
+
this.normal = normal;
|
|
554
|
+
this.tangent = tangent;
|
|
412
555
|
};
|
|
413
556
|
|
|
414
557
|
/**
|
|
@@ -558,6 +701,54 @@ var TextureWrapMode;
|
|
|
558
701
|
*/ "REPEAT"] = 10497] = "REPEAT";
|
|
559
702
|
})(TextureWrapMode || (TextureWrapMode = {}));
|
|
560
703
|
|
|
704
|
+
/**
|
|
705
|
+
* @internal
|
|
706
|
+
*/ var GLTFParserContext = /*#__PURE__*/ function() {
|
|
707
|
+
function GLTFParserContext(url) {
|
|
708
|
+
this.hasSkinned = false;
|
|
709
|
+
this.chainPromises = [];
|
|
710
|
+
this.accessorBufferCache = {};
|
|
711
|
+
this.texturesPromiseInfo = new PromiseInfo();
|
|
712
|
+
this.materialsPromiseInfo = new PromiseInfo();
|
|
713
|
+
this.meshesPromiseInfo = new PromiseInfo();
|
|
714
|
+
this.animationClipsPromiseInfo = new PromiseInfo();
|
|
715
|
+
this.defaultSceneRootPromiseInfo = new PromiseInfo();
|
|
716
|
+
this.masterPromiseInfo = new PromiseInfo();
|
|
717
|
+
this.promiseMap = {};
|
|
718
|
+
var promiseMap = this.promiseMap;
|
|
719
|
+
promiseMap["" + url + "?q=textures"] = this._initPromiseInfo(this.texturesPromiseInfo);
|
|
720
|
+
promiseMap["" + url + "?q=materials"] = this._initPromiseInfo(this.materialsPromiseInfo);
|
|
721
|
+
promiseMap["" + url + "?q=meshes"] = this._initPromiseInfo(this.meshesPromiseInfo);
|
|
722
|
+
promiseMap["" + url + "?q=animations"] = this._initPromiseInfo(this.animationClipsPromiseInfo);
|
|
723
|
+
promiseMap["" + url + "?q=defaultSceneRoot"] = this._initPromiseInfo(this.defaultSceneRootPromiseInfo);
|
|
724
|
+
promiseMap["" + url] = this._initPromiseInfo(this.masterPromiseInfo);
|
|
725
|
+
}
|
|
726
|
+
var _proto = GLTFParserContext.prototype;
|
|
727
|
+
_proto._initPromiseInfo = function _initPromiseInfo(promiseInfo) {
|
|
728
|
+
var promise = new engineCore.AssetPromise(function(resolve, reject, setProgress, onCancel) {
|
|
729
|
+
promiseInfo.resolve = resolve;
|
|
730
|
+
promiseInfo.reject = reject;
|
|
731
|
+
promiseInfo.setProgress = setProgress;
|
|
732
|
+
promiseInfo.onCancel = onCancel;
|
|
733
|
+
});
|
|
734
|
+
promiseInfo.promise = promise;
|
|
735
|
+
return promise;
|
|
736
|
+
};
|
|
737
|
+
return GLTFParserContext;
|
|
738
|
+
}();
|
|
739
|
+
/**
|
|
740
|
+
* @internal
|
|
741
|
+
*/ var BufferInfo = function BufferInfo(data, interleaved, stride) {
|
|
742
|
+
this.data = data;
|
|
743
|
+
this.interleaved = interleaved;
|
|
744
|
+
this.stride = stride;
|
|
745
|
+
this.vertexBindingInfos = {};
|
|
746
|
+
};
|
|
747
|
+
/**
|
|
748
|
+
* @internal
|
|
749
|
+
*/ var PromiseInfo = function PromiseInfo() {
|
|
750
|
+
};
|
|
751
|
+
|
|
561
752
|
/**
|
|
562
753
|
* @internal
|
|
563
754
|
*/ var GLTFUtil = /*#__PURE__*/ function() {
|
|
@@ -666,18 +857,18 @@ var TextureWrapMode;
|
|
|
666
857
|
throw new Error("Galacean.GLTFLoader: Unsupported normalized accessor component type.");
|
|
667
858
|
}
|
|
668
859
|
};
|
|
669
|
-
GLTFUtil.getAccessorBuffer = function getAccessorBuffer(context,
|
|
860
|
+
GLTFUtil.getAccessorBuffer = function getAccessorBuffer(context, bufferViews, accessor) {
|
|
670
861
|
var buffers = context.buffers;
|
|
671
|
-
var bufferViews = gltf.bufferViews;
|
|
672
862
|
var componentType = accessor.componentType;
|
|
673
863
|
var bufferView = bufferViews[accessor.bufferView];
|
|
674
|
-
var
|
|
864
|
+
var bufferIndex = bufferView.buffer;
|
|
865
|
+
var buffer = buffers[bufferIndex];
|
|
675
866
|
var bufferByteOffset = bufferView.byteOffset || 0;
|
|
676
867
|
var byteOffset = accessor.byteOffset || 0;
|
|
677
868
|
var TypedArray = GLTFUtil.getComponentType(componentType);
|
|
678
|
-
var
|
|
869
|
+
var dataElementSize = GLTFUtil.getAccessorTypeSize(accessor.type);
|
|
679
870
|
var dataElementBytes = TypedArray.BYTES_PER_ELEMENT;
|
|
680
|
-
var elementStride =
|
|
871
|
+
var elementStride = dataElementSize * dataElementBytes;
|
|
681
872
|
var accessorCount = accessor.count;
|
|
682
873
|
var bufferStride = bufferView.byteStride;
|
|
683
874
|
var bufferInfo;
|
|
@@ -692,24 +883,25 @@ var TextureWrapMode;
|
|
|
692
883
|
var count = accessorCount * (bufferStride / dataElementBytes);
|
|
693
884
|
var data = new TypedArray(buffer, offset, count);
|
|
694
885
|
accessorBufferCache[bufferCacheKey] = bufferInfo = new BufferInfo(data, true, bufferStride);
|
|
886
|
+
bufferInfo.restoreInfo = new BufferDataRestoreInfo(new RestoreDataAccessor(bufferIndex, TypedArray, offset, count));
|
|
695
887
|
}
|
|
696
888
|
} else {
|
|
697
889
|
var offset1 = bufferByteOffset + byteOffset;
|
|
698
|
-
var count1 = accessorCount *
|
|
890
|
+
var count1 = accessorCount * dataElementSize;
|
|
699
891
|
var data1 = new TypedArray(buffer, offset1, count1);
|
|
700
892
|
bufferInfo = new BufferInfo(data1, false, elementStride);
|
|
893
|
+
bufferInfo.restoreInfo = new BufferDataRestoreInfo(new RestoreDataAccessor(bufferIndex, TypedArray, offset1, count1));
|
|
701
894
|
}
|
|
702
895
|
if (accessor.sparse) {
|
|
703
|
-
|
|
704
|
-
bufferInfo = new BufferInfo(data2, false, bufferInfo.stride);
|
|
896
|
+
GLTFUtil.processingSparseData(bufferViews, accessor, buffers, bufferInfo);
|
|
705
897
|
}
|
|
706
898
|
return bufferInfo;
|
|
707
899
|
};
|
|
708
900
|
/**
|
|
709
901
|
* @deprecated
|
|
710
902
|
* Get accessor data.
|
|
711
|
-
*/ GLTFUtil.getAccessorData = function getAccessorData(
|
|
712
|
-
var bufferViews =
|
|
903
|
+
*/ GLTFUtil.getAccessorData = function getAccessorData(glTF, accessor, buffers) {
|
|
904
|
+
var bufferViews = glTF.bufferViews;
|
|
713
905
|
var bufferView = bufferViews[accessor.bufferView];
|
|
714
906
|
var arrayBuffer = buffers[bufferView.buffer];
|
|
715
907
|
var accessorByteOffset = accessor.hasOwnProperty("byteOffset") ? accessor.byteOffset : 0;
|
|
@@ -759,38 +951,46 @@ var TextureWrapMode;
|
|
|
759
951
|
return typedArray;
|
|
760
952
|
};
|
|
761
953
|
GLTFUtil.getBufferViewData = function getBufferViewData(bufferView, buffers) {
|
|
762
|
-
var
|
|
763
|
-
var arrayBuffer = buffers[buffer];
|
|
764
|
-
return arrayBuffer.slice(byteOffset, byteOffset + byteLength);
|
|
954
|
+
var _bufferView_byteOffset = bufferView.byteOffset, byteOffset = _bufferView_byteOffset === void 0 ? 0 : _bufferView_byteOffset;
|
|
955
|
+
var arrayBuffer = buffers[bufferView.buffer];
|
|
956
|
+
return arrayBuffer.slice(byteOffset, byteOffset + bufferView.byteLength);
|
|
765
957
|
};
|
|
766
958
|
/**
|
|
767
959
|
* Get accessor data.
|
|
768
|
-
*/ GLTFUtil.processingSparseData = function processingSparseData(
|
|
769
|
-
var
|
|
960
|
+
*/ GLTFUtil.processingSparseData = function processingSparseData(bufferViews, accessor, buffers, bufferInfo) {
|
|
961
|
+
var restoreInfo = bufferInfo.restoreInfo;
|
|
770
962
|
var accessorTypeSize = GLTFUtil.getAccessorTypeSize(accessor.type);
|
|
771
963
|
var TypedArray = GLTFUtil.getComponentType(accessor.componentType);
|
|
772
|
-
var data =
|
|
964
|
+
var data = bufferInfo.data.slice();
|
|
773
965
|
var _accessor_sparse = accessor.sparse, count = _accessor_sparse.count, indices = _accessor_sparse.indices, values = _accessor_sparse.values;
|
|
774
966
|
var indicesBufferView = bufferViews[indices.bufferView];
|
|
775
967
|
var valuesBufferView = bufferViews[values.bufferView];
|
|
776
|
-
var
|
|
777
|
-
var
|
|
968
|
+
var indicesBufferIndex = indicesBufferView.buffer;
|
|
969
|
+
var valuesBufferIndex = valuesBufferView.buffer;
|
|
970
|
+
var indicesArrayBuffer = buffers[indicesBufferIndex];
|
|
971
|
+
var valuesArrayBuffer = buffers[valuesBufferIndex];
|
|
778
972
|
var _indices_byteOffset, _indicesBufferView_byteOffset;
|
|
779
973
|
var indicesByteOffset = ((_indices_byteOffset = indices.byteOffset) != null ? _indices_byteOffset : 0) + ((_indicesBufferView_byteOffset = indicesBufferView.byteOffset) != null ? _indicesBufferView_byteOffset : 0);
|
|
780
974
|
var indicesByteLength = indicesBufferView.byteLength;
|
|
781
975
|
var _values_byteOffset, _valuesBufferView_byteOffset;
|
|
782
976
|
var valuesByteOffset = ((_values_byteOffset = values.byteOffset) != null ? _values_byteOffset : 0) + ((_valuesBufferView_byteOffset = valuesBufferView.byteOffset) != null ? _valuesBufferView_byteOffset : 0);
|
|
783
977
|
var valuesByteLength = valuesBufferView.byteLength;
|
|
978
|
+
restoreInfo.typeSize = accessorTypeSize;
|
|
979
|
+
restoreInfo.sparseCount = count;
|
|
784
980
|
var IndexTypeArray = GLTFUtil.getComponentType(indices.componentType);
|
|
785
|
-
var
|
|
786
|
-
var
|
|
981
|
+
var indexLength = indicesByteLength / IndexTypeArray.BYTES_PER_ELEMENT;
|
|
982
|
+
var indicesArray = new IndexTypeArray(indicesArrayBuffer, indicesByteOffset, indexLength);
|
|
983
|
+
restoreInfo.sparseIndices = new RestoreDataAccessor(indicesBufferIndex, IndexTypeArray, indicesByteOffset, indexLength);
|
|
984
|
+
var valueLength = valuesByteLength / TypedArray.BYTES_PER_ELEMENT;
|
|
985
|
+
var valuesArray = new TypedArray(valuesArrayBuffer, valuesByteOffset, valueLength);
|
|
986
|
+
restoreInfo.sparseValues = new RestoreDataAccessor(valuesBufferIndex, TypedArray, valuesByteOffset, valueLength);
|
|
787
987
|
for(var i = 0; i < count; i++){
|
|
788
988
|
var replaceIndex = indicesArray[i];
|
|
789
989
|
for(var j = 0; j < accessorTypeSize; j++){
|
|
790
990
|
data[replaceIndex * accessorTypeSize + j] = valuesArray[i * accessorTypeSize + j];
|
|
791
991
|
}
|
|
792
992
|
}
|
|
793
|
-
|
|
993
|
+
bufferInfo.data = data;
|
|
794
994
|
};
|
|
795
995
|
GLTFUtil.getIndexFormat = function getIndexFormat(type) {
|
|
796
996
|
switch(type){
|
|
@@ -888,7 +1088,7 @@ var TextureWrapMode;
|
|
|
888
1088
|
};
|
|
889
1089
|
/**
|
|
890
1090
|
* Parse the glb format.
|
|
891
|
-
*/ GLTFUtil.parseGLB = function parseGLB(glb) {
|
|
1091
|
+
*/ GLTFUtil.parseGLB = function parseGLB(context, glb) {
|
|
892
1092
|
var UINT32_LENGTH = 4;
|
|
893
1093
|
var GLB_HEADER_MAGIC = 0x46546c67; // 'glTF'
|
|
894
1094
|
var GLB_HEADER_LENGTH = 12;
|
|
@@ -916,10 +1116,11 @@ var TextureWrapMode;
|
|
|
916
1116
|
return null;
|
|
917
1117
|
}
|
|
918
1118
|
var glTFData = new Uint8Array(glb, GLB_HEADER_LENGTH + 2 * UINT32_LENGTH, chunkLength);
|
|
919
|
-
var
|
|
1119
|
+
var glTF = JSON.parse(GLTFUtil.decodeText(glTFData));
|
|
920
1120
|
// read all buffers
|
|
921
1121
|
var buffers = [];
|
|
922
1122
|
var byteOffset = GLB_HEADER_LENGTH + 2 * UINT32_LENGTH + chunkLength;
|
|
1123
|
+
var restoreGLBBufferSlice = context.contentRestorer.glbBufferSlices;
|
|
923
1124
|
while(byteOffset < header.length){
|
|
924
1125
|
chunkLength = dataView.getUint32(byteOffset, true);
|
|
925
1126
|
chunkType = dataView.getUint32(byteOffset + UINT32_LENGTH, true);
|
|
@@ -930,10 +1131,11 @@ var TextureWrapMode;
|
|
|
930
1131
|
var currentOffset = byteOffset + 2 * UINT32_LENGTH;
|
|
931
1132
|
var buffer = glb.slice(currentOffset, currentOffset + chunkLength);
|
|
932
1133
|
buffers.push(buffer);
|
|
1134
|
+
restoreGLBBufferSlice.push(new engineMath.Vector2(currentOffset, chunkLength));
|
|
933
1135
|
byteOffset += chunkLength + 2 * UINT32_LENGTH;
|
|
934
1136
|
}
|
|
935
1137
|
return {
|
|
936
|
-
|
|
1138
|
+
glTF: glTF,
|
|
937
1139
|
buffers: buffers
|
|
938
1140
|
};
|
|
939
1141
|
};
|
|
@@ -948,12 +1150,6 @@ var TextureWrapMode;
|
|
|
948
1150
|
return GLTFUtil;
|
|
949
1151
|
}();
|
|
950
1152
|
|
|
951
|
-
function _arrayLikeToArray(arr, len) {
|
|
952
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
953
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
954
|
-
return arr2;
|
|
955
|
-
}
|
|
956
|
-
|
|
957
1153
|
function _arrayWithoutHoles(arr) {
|
|
958
1154
|
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
|
959
1155
|
}
|
|
@@ -966,604 +1162,325 @@ function _nonIterableSpread() {
|
|
|
966
1162
|
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
967
1163
|
}
|
|
968
1164
|
|
|
969
|
-
function _unsupportedIterableToArray(o, minLen) {
|
|
970
|
-
if (!o) return;
|
|
971
|
-
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
972
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
973
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
974
|
-
if (n === "Map" || n === "Set") return Array.from(n);
|
|
975
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
|
|
976
|
-
return _arrayLikeToArray(o, minLen);
|
|
977
|
-
}
|
|
978
|
-
|
|
979
1165
|
function _toConsumableArray(arr) {
|
|
980
1166
|
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
|
981
1167
|
}
|
|
982
1168
|
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
1169
|
+
/**
|
|
1170
|
+
* Base class of glTF extension parser.
|
|
1171
|
+
*/ var GLTFExtensionParser = /*#__PURE__*/ function() {
|
|
1172
|
+
function GLTFExtensionParser() {}
|
|
1173
|
+
var _proto = GLTFExtensionParser.prototype;
|
|
1174
|
+
/**
|
|
1175
|
+
* Initialize the parser.
|
|
1176
|
+
* @remarks Some plugins require initialization.
|
|
1177
|
+
* @returns The void or promise
|
|
1178
|
+
*/ _proto.initialize = function initialize() {};
|
|
1179
|
+
/**
|
|
1180
|
+
* Create and parse the resource.
|
|
1181
|
+
* @remarks This method overrides the default resource creation.
|
|
1182
|
+
* @param context - The parser context
|
|
1183
|
+
* @param extensionSchema - The extension schema
|
|
1184
|
+
* @param extensionOwnerSchema - The extension owner schema
|
|
1185
|
+
* @returns The resource or promise
|
|
1186
|
+
*/ _proto.createAndParse = function createAndParse(context, extensionSchema, extensionOwnerSchema) {
|
|
1187
|
+
for(var _len = arguments.length, extra = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++){
|
|
1188
|
+
extra[_key - 3] = arguments[_key];
|
|
1189
|
+
}
|
|
1190
|
+
throw "Not implemented.";
|
|
1191
|
+
};
|
|
1192
|
+
/**
|
|
1193
|
+
* Additive parse to the resource.
|
|
1194
|
+
* @param context - The parser context
|
|
1195
|
+
* @param parseResource - The parsed resource
|
|
1196
|
+
* @param extensionSchema - The extension schema
|
|
1197
|
+
* @param extensionOwnerSchema - The extension owner schema
|
|
1198
|
+
* @returns The void or promise
|
|
1199
|
+
*/ _proto.additiveParse = function additiveParse(context, parseResource, extensionSchema, extensionOwnerSchema) {
|
|
986
1200
|
for(var _len = arguments.length, extra = new Array(_len > 4 ? _len - 4 : 0), _key = 4; _key < _len; _key++){
|
|
987
1201
|
extra[_key - 4] = arguments[_key];
|
|
988
1202
|
}
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
1203
|
+
throw "Not implemented.";
|
|
1204
|
+
};
|
|
1205
|
+
return GLTFExtensionParser;
|
|
1206
|
+
}();
|
|
1207
|
+
exports.GLTFExtensionMode = void 0;
|
|
1208
|
+
(function(GLTFExtensionMode) {
|
|
1209
|
+
GLTFExtensionMode[GLTFExtensionMode[/**
|
|
1210
|
+
* Cerate instance and parse mode.
|
|
1211
|
+
* @remarks
|
|
1212
|
+
* If the glTF property has multiple extensions of `CreateAndParse` mode, only execute the last one.
|
|
1213
|
+
* If this method is registered, the default pipeline processing will be ignored.
|
|
1214
|
+
*/ "CreateAndParse"] = 0] = "CreateAndParse";
|
|
1215
|
+
GLTFExtensionMode[GLTFExtensionMode[/** Additive parse mode. */ "AdditiveParse"] = 1] = "AdditiveParse";
|
|
1216
|
+
})(exports.GLTFExtensionMode || (exports.GLTFExtensionMode = {}));
|
|
1217
|
+
|
|
1218
|
+
/**
|
|
1219
|
+
* Base class of glTF parser.
|
|
1220
|
+
*/ var GLTFParser = /*#__PURE__*/ function() {
|
|
1221
|
+
function GLTFParser() {}
|
|
1222
|
+
/**
|
|
1223
|
+
* Execute all parses of extension to initialize plugin.
|
|
1224
|
+
* @remarks Some plugins require initialization.
|
|
1225
|
+
* @returns The void or promise
|
|
1226
|
+
*/ GLTFParser.executeExtensionsInitialize = function executeExtensionsInitialize(extensionName) {
|
|
1227
|
+
var parsers = GLTFParser._extensionParsers[extensionName];
|
|
1228
|
+
var length = parsers == null ? void 0 : parsers.length;
|
|
1229
|
+
if (length) {
|
|
1230
|
+
return parsers[length - 1].initialize();
|
|
999
1231
|
}
|
|
1000
1232
|
};
|
|
1001
|
-
|
|
1233
|
+
/**
|
|
1234
|
+
* Execute all parses of extension to create resource.
|
|
1235
|
+
* @param extensions - Related extensions field
|
|
1236
|
+
* @param context - The parser context
|
|
1237
|
+
* @param ownerSchema - The extension owner schema
|
|
1238
|
+
* @param extra - Extra params
|
|
1239
|
+
* @returns
|
|
1240
|
+
*/ GLTFParser.executeExtensionsCreateAndParse = function executeExtensionsCreateAndParse(extensions, context, ownerSchema) {
|
|
1241
|
+
if (extensions === void 0) extensions = {};
|
|
1002
1242
|
for(var _len = arguments.length, extra = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++){
|
|
1003
1243
|
extra[_key - 3] = arguments[_key];
|
|
1004
1244
|
}
|
|
1005
|
-
var
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1245
|
+
var resource = null;
|
|
1246
|
+
var extensionArray = Object.keys(extensions);
|
|
1247
|
+
for(var i = extensionArray.length - 1; i >= 0; --i){
|
|
1248
|
+
var _GLTFParser;
|
|
1249
|
+
var extensionName = extensionArray[i];
|
|
1250
|
+
var extensionSchema = extensions[extensionName];
|
|
1251
|
+
resource = (_GLTFParser = GLTFParser)._createAndParse.apply(_GLTFParser, [
|
|
1252
|
+
extensionName,
|
|
1253
|
+
context,
|
|
1254
|
+
extensionSchema,
|
|
1255
|
+
ownerSchema
|
|
1256
|
+
].concat(_toConsumableArray(extra)));
|
|
1257
|
+
if (resource) {
|
|
1258
|
+
return resource;
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
};
|
|
1262
|
+
/**
|
|
1263
|
+
* Execute all parses of extension to parse resource.
|
|
1264
|
+
* @param extensions - Related extensions field
|
|
1265
|
+
* @param context - The parser context
|
|
1266
|
+
* @param parseResource - The parsed resource
|
|
1267
|
+
* @param ownerSchema - The extension owner schema
|
|
1268
|
+
* @param extra - Extra params
|
|
1269
|
+
*/ GLTFParser.executeExtensionsAdditiveAndParse = function executeExtensionsAdditiveAndParse(extensions, context, parseResource, ownerSchema) {
|
|
1270
|
+
for(var _len = arguments.length, extra = new Array(_len > 4 ? _len - 4 : 0), _key = 4; _key < _len; _key++){
|
|
1271
|
+
extra[_key - 4] = arguments[_key];
|
|
1272
|
+
}
|
|
1273
|
+
for(var extensionName in extensions){
|
|
1274
|
+
var _GLTFParser;
|
|
1275
|
+
var extensionSchema = extensions[extensionName];
|
|
1276
|
+
(_GLTFParser = GLTFParser)._additiveParse.apply(_GLTFParser, [
|
|
1277
|
+
extensionName,
|
|
1278
|
+
context,
|
|
1279
|
+
parseResource,
|
|
1009
1280
|
extensionSchema,
|
|
1010
|
-
|
|
1281
|
+
ownerSchema
|
|
1011
1282
|
].concat(_toConsumableArray(extra)));
|
|
1012
1283
|
}
|
|
1013
1284
|
};
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1285
|
+
/**
|
|
1286
|
+
* Whether the plugin is registered.
|
|
1287
|
+
* @param extensionName - Extension name
|
|
1288
|
+
* @returns Boolean
|
|
1289
|
+
*/ GLTFParser.hasExtensionParser = function hasExtensionParser(extensionName) {
|
|
1290
|
+
var _GLTFParser__extensionParsers_extensionName;
|
|
1291
|
+
return !!((_GLTFParser__extensionParsers_extensionName = GLTFParser._extensionParsers[extensionName]) == null ? void 0 : _GLTFParser__extensionParsers_extensionName.length);
|
|
1017
1292
|
};
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1293
|
+
/**
|
|
1294
|
+
* Get the last plugin by glTF extension mode.
|
|
1295
|
+
* @param extensionName - Extension name
|
|
1296
|
+
* @param mode - GLTF extension mode
|
|
1297
|
+
* @returns GLTF extension parser
|
|
1298
|
+
*/ GLTFParser.getExtensionParser = function getExtensionParser(extensionName, mode) {
|
|
1299
|
+
var parsers = GLTFParser._extensionParsers[extensionName];
|
|
1300
|
+
var length = parsers == null ? void 0 : parsers.length;
|
|
1301
|
+
if (length) {
|
|
1302
|
+
// only use the last parser.
|
|
1303
|
+
for(var i = length - 1; i >= 0; --i){
|
|
1304
|
+
var currentParser = parsers[i];
|
|
1305
|
+
if (currentParser._mode === mode) {
|
|
1306
|
+
return currentParser;
|
|
1307
|
+
}
|
|
1023
1308
|
}
|
|
1024
1309
|
}
|
|
1025
1310
|
};
|
|
1026
1311
|
/**
|
|
1027
1312
|
* @internal
|
|
1028
|
-
*/
|
|
1029
|
-
if (!
|
|
1030
|
-
|
|
1313
|
+
*/ GLTFParser._addExtensionParser = function _addExtensionParser(extensionName, extensionParser) {
|
|
1314
|
+
if (!GLTFParser._extensionParsers[extensionName]) {
|
|
1315
|
+
GLTFParser._extensionParsers[extensionName] = [];
|
|
1316
|
+
}
|
|
1317
|
+
GLTFParser._extensionParsers[extensionName].push(extensionParser);
|
|
1318
|
+
};
|
|
1319
|
+
GLTFParser._createAndParse = function _createAndParse(extensionName, context, extensionSchema, ownerSchema) {
|
|
1320
|
+
for(var _len = arguments.length, extra = new Array(_len > 4 ? _len - 4 : 0), _key = 4; _key < _len; _key++){
|
|
1321
|
+
extra[_key - 4] = arguments[_key];
|
|
1322
|
+
}
|
|
1323
|
+
var parser = GLTFParser.getExtensionParser(extensionName, exports.GLTFExtensionMode.CreateAndParse);
|
|
1324
|
+
if (parser) {
|
|
1325
|
+
var _parser;
|
|
1326
|
+
return (_parser = parser).createAndParse.apply(_parser, [
|
|
1327
|
+
context,
|
|
1328
|
+
extensionSchema,
|
|
1329
|
+
ownerSchema
|
|
1330
|
+
].concat(_toConsumableArray(extra)));
|
|
1331
|
+
}
|
|
1332
|
+
};
|
|
1333
|
+
GLTFParser._additiveParse = function _additiveParse(extensionName, context, parseResource, extensionSchema, ownerSchema) {
|
|
1334
|
+
for(var _len = arguments.length, extra = new Array(_len > 5 ? _len - 5 : 0), _key = 5; _key < _len; _key++){
|
|
1335
|
+
extra[_key - 5] = arguments[_key];
|
|
1336
|
+
}
|
|
1337
|
+
var parser = GLTFParser.getExtensionParser(extensionName, exports.GLTFExtensionMode.AdditiveParse);
|
|
1338
|
+
if (parser) {
|
|
1339
|
+
var _parser;
|
|
1340
|
+
(_parser = parser).additiveParse.apply(_parser, [
|
|
1341
|
+
context,
|
|
1342
|
+
parseResource,
|
|
1343
|
+
extensionSchema,
|
|
1344
|
+
ownerSchema
|
|
1345
|
+
].concat(_toConsumableArray(extra)));
|
|
1031
1346
|
}
|
|
1032
|
-
Parser._extensionParsers[extensionName].push(extensionParser);
|
|
1033
1347
|
};
|
|
1034
|
-
return
|
|
1348
|
+
return GLTFParser;
|
|
1035
1349
|
}();
|
|
1036
|
-
|
|
1350
|
+
GLTFParser._extensionParsers = {};
|
|
1037
1351
|
/**
|
|
1038
1352
|
* Declare ExtensionParser's decorator.
|
|
1039
1353
|
* @param extensionName - Extension name
|
|
1040
|
-
*/ function
|
|
1354
|
+
*/ function registerGLTFExtension(extensionName, mode) {
|
|
1041
1355
|
return function(parser) {
|
|
1042
1356
|
var extensionParser = new parser();
|
|
1043
|
-
|
|
1357
|
+
extensionParser._mode = mode;
|
|
1358
|
+
GLTFParser._addExtensionParser(extensionName, extensionParser);
|
|
1044
1359
|
};
|
|
1045
1360
|
}
|
|
1046
1361
|
|
|
1047
|
-
var
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
_proto.parseEngineResource = function parseEngineResource(schema, parseResource, context) {
|
|
1052
|
-
for(var _len = arguments.length, extra = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++){
|
|
1053
|
-
extra[_key - 3] = arguments[_key];
|
|
1054
|
-
}
|
|
1055
|
-
};
|
|
1056
|
-
_proto.createEngineResource = function createEngineResource(schema, context) {
|
|
1057
|
-
for(var _len = arguments.length, extra = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++){
|
|
1058
|
-
extra[_key - 2] = arguments[_key];
|
|
1059
|
-
}
|
|
1060
|
-
return null;
|
|
1061
|
-
};
|
|
1062
|
-
return ExtensionParser;
|
|
1063
|
-
}();
|
|
1064
|
-
|
|
1065
|
-
var KHR_draco_mesh_compression = /*#__PURE__*/ function(ExtensionParser) {
|
|
1066
|
-
_inherits(KHR_draco_mesh_compression1, ExtensionParser);
|
|
1067
|
-
function KHR_draco_mesh_compression1() {
|
|
1068
|
-
return ExtensionParser.apply(this, arguments);
|
|
1362
|
+
var GLTFAnimationParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
1363
|
+
_inherits(GLTFAnimationParser, GLTFParser1);
|
|
1364
|
+
function GLTFAnimationParser() {
|
|
1365
|
+
return GLTFParser1.apply(this, arguments);
|
|
1069
1366
|
}
|
|
1070
|
-
var _proto =
|
|
1071
|
-
_proto.
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
var gltf = context.gltf, buffers = context.buffers;
|
|
1078
|
-
var bufferViews = gltf.bufferViews, accessors = gltf.accessors;
|
|
1079
|
-
var bufferViewIndex = schema.bufferView, gltfAttributeMap = schema.attributes;
|
|
1080
|
-
var attributeMap = {};
|
|
1081
|
-
var attributeTypeMap = {};
|
|
1082
|
-
for(var attributeName in gltfAttributeMap){
|
|
1083
|
-
attributeMap[attributeName] = gltfAttributeMap[attributeName];
|
|
1367
|
+
var _proto = GLTFAnimationParser.prototype;
|
|
1368
|
+
_proto.parse = function parse(context) {
|
|
1369
|
+
var glTF = context.glTF; context.buffers; var glTFResource = context.glTFResource;
|
|
1370
|
+
glTFResource.entities;
|
|
1371
|
+
var animations = glTF.animations; glTF.accessors; glTF.bufferViews;
|
|
1372
|
+
if (!animations) {
|
|
1373
|
+
return;
|
|
1084
1374
|
}
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1375
|
+
var animationClipsPromiseInfo = context.animationClipsPromiseInfo;
|
|
1376
|
+
var animationClipCount = animations.length;
|
|
1377
|
+
var animationClipPromises = [];
|
|
1378
|
+
new Array(animationClipCount);
|
|
1379
|
+
for(var i = 0; i < animationClipCount; i++){
|
|
1380
|
+
var animationInfo = animations[i];
|
|
1381
|
+
var _animationInfo_name = animationInfo.name, name = _animationInfo_name === void 0 ? "AnimationClip" + i : _animationInfo_name;
|
|
1382
|
+
var animationClip = GLTFParser.executeExtensionsCreateAndParse(animationInfo.extensions, context, animationInfo);
|
|
1383
|
+
if (!animationClip) {
|
|
1384
|
+
animationClip = new engineCore.AnimationClip(name);
|
|
1385
|
+
GLTFAnimationParser._parseStandardProperty(context, animationClip, animationInfo);
|
|
1089
1386
|
}
|
|
1387
|
+
animationClipPromises.push(animationClip);
|
|
1090
1388
|
}
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
var buffer = GLTFUtil.getBufferViewData(bufferViews[bufferViewIndex], buffers);
|
|
1100
|
-
return KHR_draco_mesh_compression._decoder.decode(buffer, taskConfig).then(function(parsedGeometry) {
|
|
1101
|
-
return parsedGeometry;
|
|
1389
|
+
return engineCore.AssetPromise.all(animationClipPromises).then(function(animationClips) {
|
|
1390
|
+
glTFResource.animations = animationClips;
|
|
1391
|
+
for(var i = 0; i < glTF.animations.length; i++){
|
|
1392
|
+
var animationInfo = glTF.animations[i];
|
|
1393
|
+
GLTFParser.executeExtensionsAdditiveAndParse(animationInfo.extensions, context, animationClips[i], animationInfo);
|
|
1394
|
+
}
|
|
1395
|
+
animationClipsPromiseInfo.resolve(animationClips);
|
|
1396
|
+
return animationClipsPromiseInfo.promise;
|
|
1102
1397
|
});
|
|
1103
1398
|
};
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
var
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
_proto.parseEngineResource = function parseEngineResource(schema, entity, context) {
|
|
1125
|
-
var color = schema.color, _schema_intensity = schema.intensity, intensity = _schema_intensity === void 0 ? 1 : _schema_intensity, type = schema.type, range = schema.range, spot = schema.spot;
|
|
1126
|
-
var glTFResource = context.glTFResource;
|
|
1127
|
-
var light;
|
|
1128
|
-
if (type === "directional") {
|
|
1129
|
-
light = entity.addComponent(engineCore.DirectLight);
|
|
1130
|
-
} else if (type === "point") {
|
|
1131
|
-
light = entity.addComponent(engineCore.PointLight);
|
|
1132
|
-
} else if (type === "spot") {
|
|
1133
|
-
light = entity.addComponent(engineCore.SpotLight);
|
|
1134
|
-
}
|
|
1135
|
-
if (color) {
|
|
1136
|
-
light.color.set(color[0], color[1], color[2], 1);
|
|
1137
|
-
}
|
|
1138
|
-
light.intensity = intensity;
|
|
1139
|
-
if (range && !_instanceof(light, engineCore.DirectLight)) {
|
|
1140
|
-
light.distance = range;
|
|
1141
|
-
}
|
|
1142
|
-
if (spot && _instanceof(light, engineCore.SpotLight)) {
|
|
1143
|
-
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;
|
|
1144
|
-
light.angle = innerConeAngle;
|
|
1145
|
-
light.penumbra = outerConeAngle - innerConeAngle;
|
|
1146
|
-
}
|
|
1147
|
-
if (!glTFResource.lights) glTFResource.lights = [];
|
|
1148
|
-
glTFResource.lights.push(light);
|
|
1149
|
-
};
|
|
1150
|
-
return KHR_lights_punctual;
|
|
1151
|
-
}(ExtensionParser);
|
|
1152
|
-
KHR_lights_punctual = __decorate([
|
|
1153
|
-
registerExtension("KHR_lights_punctual")
|
|
1154
|
-
], KHR_lights_punctual);
|
|
1155
|
-
|
|
1156
|
-
var MaterialParser = /*#__PURE__*/ function(Parser1) {
|
|
1157
|
-
_inherits(MaterialParser, Parser1);
|
|
1158
|
-
function MaterialParser() {
|
|
1159
|
-
return Parser1.apply(this, arguments);
|
|
1160
|
-
}
|
|
1161
|
-
var _proto = MaterialParser.prototype;
|
|
1162
|
-
_proto.parse = function parse(context) {
|
|
1163
|
-
var gltf = context.gltf, glTFResource = context.glTFResource;
|
|
1164
|
-
var engine = glTFResource.engine, textures = glTFResource.textures;
|
|
1165
|
-
if (!gltf.materials) return;
|
|
1166
|
-
var materialsPromiseInfo = context.materialsPromiseInfo;
|
|
1167
|
-
var materials = [];
|
|
1168
|
-
for(var i = 0; i < gltf.materials.length; i++){
|
|
1169
|
-
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;
|
|
1170
|
-
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;
|
|
1171
|
-
var material = null;
|
|
1172
|
-
if (KHR_materials_unlit) {
|
|
1173
|
-
material = Parser.createEngineResource("KHR_materials_unlit", KHR_materials_unlit, context);
|
|
1174
|
-
} else if (KHR_materials_pbrSpecularGlossiness) {
|
|
1175
|
-
material = Parser.createEngineResource("KHR_materials_pbrSpecularGlossiness", KHR_materials_pbrSpecularGlossiness, context);
|
|
1176
|
-
} else {
|
|
1177
|
-
material = new engineCore.PBRMaterial(engine);
|
|
1178
|
-
}
|
|
1179
|
-
material.name = name;
|
|
1180
|
-
if (KHR_materials_clearcoat) {
|
|
1181
|
-
Parser.parseEngineResource("KHR_materials_clearcoat", KHR_materials_clearcoat, material, context);
|
|
1182
|
-
}
|
|
1183
|
-
if (pbrMetallicRoughness) {
|
|
1184
|
-
var baseColorFactor = pbrMetallicRoughness.baseColorFactor, baseColorTexture = pbrMetallicRoughness.baseColorTexture, metallicFactor = pbrMetallicRoughness.metallicFactor, roughnessFactor = pbrMetallicRoughness.roughnessFactor, metallicRoughnessTexture = pbrMetallicRoughness.metallicRoughnessTexture;
|
|
1185
|
-
if (baseColorFactor) {
|
|
1186
|
-
material.baseColor = new engineMath.Color(engineMath.Color.linearToGammaSpace(baseColorFactor[0]), engineMath.Color.linearToGammaSpace(baseColorFactor[1]), engineMath.Color.linearToGammaSpace(baseColorFactor[2]), baseColorFactor[3]);
|
|
1187
|
-
}
|
|
1188
|
-
if (baseColorTexture) {
|
|
1189
|
-
material.baseTexture = textures[baseColorTexture.index];
|
|
1190
|
-
MaterialParser._parseTextureTransform(material, baseColorTexture.extensions, context);
|
|
1191
|
-
}
|
|
1192
|
-
if (!KHR_materials_unlit && !KHR_materials_pbrSpecularGlossiness) {
|
|
1193
|
-
var m = material;
|
|
1194
|
-
m.metallic = metallicFactor != null ? metallicFactor : 1;
|
|
1195
|
-
m.roughness = roughnessFactor != null ? roughnessFactor : 1;
|
|
1196
|
-
if (metallicRoughnessTexture) {
|
|
1197
|
-
m.roughnessMetallicTexture = textures[metallicRoughnessTexture.index];
|
|
1198
|
-
MaterialParser._parseTextureTransform(material, metallicRoughnessTexture.extensions, context);
|
|
1199
|
-
}
|
|
1200
|
-
}
|
|
1201
|
-
}
|
|
1202
|
-
if (!KHR_materials_unlit) {
|
|
1203
|
-
var m1 = material;
|
|
1204
|
-
if (emissiveTexture) {
|
|
1205
|
-
m1.emissiveTexture = textures[emissiveTexture.index];
|
|
1206
|
-
MaterialParser._parseTextureTransform(material, emissiveTexture.extensions, context);
|
|
1207
|
-
}
|
|
1208
|
-
if (emissiveFactor) {
|
|
1209
|
-
m1.emissiveColor = new engineMath.Color(engineMath.Color.linearToGammaSpace(emissiveFactor[0]), engineMath.Color.linearToGammaSpace(emissiveFactor[1]), engineMath.Color.linearToGammaSpace(emissiveFactor[2]));
|
|
1210
|
-
}
|
|
1211
|
-
if (normalTexture) {
|
|
1212
|
-
var index = normalTexture.index, scale = normalTexture.scale;
|
|
1213
|
-
m1.normalTexture = textures[index];
|
|
1214
|
-
MaterialParser._parseTextureTransform(material, normalTexture.extensions, context);
|
|
1215
|
-
if (scale !== undefined) {
|
|
1216
|
-
m1.normalTextureIntensity = scale;
|
|
1217
|
-
}
|
|
1218
|
-
}
|
|
1219
|
-
if (occlusionTexture) {
|
|
1220
|
-
var index1 = occlusionTexture.index, strength = occlusionTexture.strength, texCoord = occlusionTexture.texCoord;
|
|
1221
|
-
m1.occlusionTexture = textures[index1];
|
|
1222
|
-
MaterialParser._parseTextureTransform(material, occlusionTexture.extensions, context);
|
|
1223
|
-
if (strength !== undefined) {
|
|
1224
|
-
m1.occlusionTextureIntensity = strength;
|
|
1225
|
-
}
|
|
1226
|
-
if (texCoord === engineCore.TextureCoordinate.UV1) {
|
|
1227
|
-
m1.occlusionTextureCoord = engineCore.TextureCoordinate.UV1;
|
|
1228
|
-
} else if (texCoord > engineCore.TextureCoordinate.UV1) {
|
|
1229
|
-
engineCore.Logger.warn("Occlusion texture uv coordinate must be UV0 or UV1.");
|
|
1230
|
-
}
|
|
1399
|
+
/**
|
|
1400
|
+
* @internal
|
|
1401
|
+
*/ GLTFAnimationParser._parseStandardProperty = function _parseStandardProperty(context, animationClip, animationInfo) {
|
|
1402
|
+
var glTF = context.glTF, glTFResource = context.glTFResource;
|
|
1403
|
+
var entities = glTFResource.entities;
|
|
1404
|
+
var accessors = glTF.accessors, bufferViews = glTF.bufferViews;
|
|
1405
|
+
var channels = animationInfo.channels, samplers = animationInfo.samplers;
|
|
1406
|
+
var sampleDataCollection = new Array();
|
|
1407
|
+
// parse samplers
|
|
1408
|
+
for(var j = 0, m = samplers.length; j < m; j++){
|
|
1409
|
+
var gltfSampler = samplers[j];
|
|
1410
|
+
var inputAccessor = accessors[gltfSampler.input];
|
|
1411
|
+
var outputAccessor = accessors[gltfSampler.output];
|
|
1412
|
+
var input = GLTFUtil.getAccessorBuffer(context, bufferViews, inputAccessor).data;
|
|
1413
|
+
var output = GLTFUtil.getAccessorBuffer(context, bufferViews, outputAccessor).data;
|
|
1414
|
+
if (outputAccessor.normalized) {
|
|
1415
|
+
var scale = GLTFUtil.getNormalizedComponentScale(outputAccessor.componentType);
|
|
1416
|
+
var scaled = new Float32Array(output.length);
|
|
1417
|
+
for(var k = 0, v = output.length; k < v; k++){
|
|
1418
|
+
scaled[k] = output[k] * scale;
|
|
1231
1419
|
}
|
|
1420
|
+
output = scaled;
|
|
1232
1421
|
}
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
if (doubleSided) {
|
|
1241
|
-
material.renderFace = engineCore.RenderFace.Double;
|
|
1242
|
-
} else {
|
|
1243
|
-
material.renderFace = engineCore.RenderFace.Front;
|
|
1244
|
-
}
|
|
1245
|
-
switch(alphaMode){
|
|
1246
|
-
case MaterialAlphaMode.OPAQUE:
|
|
1247
|
-
material.isTransparent = false;
|
|
1422
|
+
var outputStride = output.length / input.length;
|
|
1423
|
+
var _gltfSampler_interpolation;
|
|
1424
|
+
var interpolation = (_gltfSampler_interpolation = gltfSampler.interpolation) != null ? _gltfSampler_interpolation : AnimationSamplerInterpolation.Linear;
|
|
1425
|
+
var samplerInterpolation = void 0;
|
|
1426
|
+
switch(interpolation){
|
|
1427
|
+
case AnimationSamplerInterpolation.CubicSpine:
|
|
1428
|
+
samplerInterpolation = engineCore.InterpolationType.CubicSpine;
|
|
1248
1429
|
break;
|
|
1249
|
-
case
|
|
1250
|
-
|
|
1430
|
+
case AnimationSamplerInterpolation.Step:
|
|
1431
|
+
samplerInterpolation = engineCore.InterpolationType.Step;
|
|
1251
1432
|
break;
|
|
1252
|
-
case
|
|
1253
|
-
|
|
1433
|
+
case AnimationSamplerInterpolation.Linear:
|
|
1434
|
+
samplerInterpolation = engineCore.InterpolationType.Linear;
|
|
1254
1435
|
break;
|
|
1255
1436
|
}
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
if (extensions === void 0) extensions = {};
|
|
1264
|
-
var schema = extensions.KHR_texture_transform;
|
|
1265
|
-
if (schema) {
|
|
1266
|
-
Parser.parseEngineResource("KHR_texture_transform", schema, material, context);
|
|
1267
|
-
}
|
|
1268
|
-
};
|
|
1269
|
-
return MaterialParser;
|
|
1270
|
-
}(Parser);
|
|
1271
|
-
|
|
1272
|
-
var KHR_materials_clearcoat = /*#__PURE__*/ function(ExtensionParser) {
|
|
1273
|
-
_inherits(KHR_materials_clearcoat, ExtensionParser);
|
|
1274
|
-
function KHR_materials_clearcoat() {
|
|
1275
|
-
return ExtensionParser.apply(this, arguments);
|
|
1276
|
-
}
|
|
1277
|
-
var _proto = KHR_materials_clearcoat.prototype;
|
|
1278
|
-
_proto.parseEngineResource = function parseEngineResource(schema, material, context) {
|
|
1279
|
-
var textures = context.glTFResource.textures;
|
|
1280
|
-
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;
|
|
1281
|
-
material.clearCoat = clearcoatFactor;
|
|
1282
|
-
material.clearCoatRoughness = clearcoatRoughnessFactor;
|
|
1283
|
-
if (clearcoatTexture) {
|
|
1284
|
-
material.clearCoatTexture = textures[clearcoatTexture.index];
|
|
1285
|
-
MaterialParser._parseTextureTransform(material, clearcoatTexture.extensions, context);
|
|
1286
|
-
}
|
|
1287
|
-
if (clearcoatRoughnessTexture) {
|
|
1288
|
-
material.clearCoatRoughnessTexture = textures[clearcoatRoughnessTexture.index];
|
|
1289
|
-
MaterialParser._parseTextureTransform(material, clearcoatRoughnessTexture.extensions, context);
|
|
1290
|
-
}
|
|
1291
|
-
if (clearcoatNormalTexture) {
|
|
1292
|
-
material.clearCoatNormalTexture = textures[clearcoatNormalTexture.index];
|
|
1293
|
-
MaterialParser._parseTextureTransform(material, clearcoatNormalTexture.extensions, context);
|
|
1294
|
-
}
|
|
1295
|
-
};
|
|
1296
|
-
return KHR_materials_clearcoat;
|
|
1297
|
-
}(ExtensionParser);
|
|
1298
|
-
KHR_materials_clearcoat = __decorate([
|
|
1299
|
-
registerExtension("KHR_materials_clearcoat")
|
|
1300
|
-
], KHR_materials_clearcoat);
|
|
1301
|
-
|
|
1302
|
-
var KHR_materials_pbrSpecularGlossiness = /*#__PURE__*/ function(ExtensionParser) {
|
|
1303
|
-
_inherits(KHR_materials_pbrSpecularGlossiness, ExtensionParser);
|
|
1304
|
-
function KHR_materials_pbrSpecularGlossiness() {
|
|
1305
|
-
return ExtensionParser.apply(this, arguments);
|
|
1306
|
-
}
|
|
1307
|
-
var _proto = KHR_materials_pbrSpecularGlossiness.prototype;
|
|
1308
|
-
_proto.createEngineResource = function createEngineResource(schema, context) {
|
|
1309
|
-
var _context_glTFResource = context.glTFResource, engine = _context_glTFResource.engine, textures = _context_glTFResource.textures;
|
|
1310
|
-
var material = new engineCore.PBRSpecularMaterial(engine);
|
|
1311
|
-
var diffuseFactor = schema.diffuseFactor, diffuseTexture = schema.diffuseTexture, specularFactor = schema.specularFactor, glossinessFactor = schema.glossinessFactor, specularGlossinessTexture = schema.specularGlossinessTexture;
|
|
1312
|
-
if (diffuseFactor) {
|
|
1313
|
-
material.baseColor = new engineMath.Color(engineMath.Color.linearToGammaSpace(diffuseFactor[0]), engineMath.Color.linearToGammaSpace(diffuseFactor[1]), engineMath.Color.linearToGammaSpace(diffuseFactor[2]), diffuseFactor[3]);
|
|
1314
|
-
}
|
|
1315
|
-
if (diffuseTexture) {
|
|
1316
|
-
material.baseTexture = textures[diffuseTexture.index];
|
|
1317
|
-
MaterialParser._parseTextureTransform(material, diffuseTexture.extensions, context);
|
|
1318
|
-
}
|
|
1319
|
-
if (specularFactor) {
|
|
1320
|
-
material.specularColor = new engineMath.Color(engineMath.Color.linearToGammaSpace(specularFactor[0]), engineMath.Color.linearToGammaSpace(specularFactor[1]), engineMath.Color.linearToGammaSpace(specularFactor[2]));
|
|
1321
|
-
}
|
|
1322
|
-
if (glossinessFactor !== undefined) {
|
|
1323
|
-
material.glossiness = glossinessFactor;
|
|
1324
|
-
}
|
|
1325
|
-
if (specularGlossinessTexture) {
|
|
1326
|
-
material.specularGlossinessTexture = textures[specularGlossinessTexture.index];
|
|
1327
|
-
MaterialParser._parseTextureTransform(material, specularGlossinessTexture.extensions, context);
|
|
1328
|
-
}
|
|
1329
|
-
return material;
|
|
1330
|
-
};
|
|
1331
|
-
return KHR_materials_pbrSpecularGlossiness;
|
|
1332
|
-
}(ExtensionParser);
|
|
1333
|
-
KHR_materials_pbrSpecularGlossiness = __decorate([
|
|
1334
|
-
registerExtension("KHR_materials_pbrSpecularGlossiness")
|
|
1335
|
-
], KHR_materials_pbrSpecularGlossiness);
|
|
1336
|
-
|
|
1337
|
-
var KHR_materials_unlit = /*#__PURE__*/ function(ExtensionParser) {
|
|
1338
|
-
_inherits(KHR_materials_unlit, ExtensionParser);
|
|
1339
|
-
function KHR_materials_unlit() {
|
|
1340
|
-
return ExtensionParser.apply(this, arguments);
|
|
1341
|
-
}
|
|
1342
|
-
var _proto = KHR_materials_unlit.prototype;
|
|
1343
|
-
_proto.createEngineResource = function createEngineResource(schema, context) {
|
|
1344
|
-
var engine = context.glTFResource.engine;
|
|
1345
|
-
var material = new engineCore.UnlitMaterial(engine);
|
|
1346
|
-
return material;
|
|
1347
|
-
};
|
|
1348
|
-
return KHR_materials_unlit;
|
|
1349
|
-
}(ExtensionParser);
|
|
1350
|
-
KHR_materials_unlit = __decorate([
|
|
1351
|
-
registerExtension("KHR_materials_unlit")
|
|
1352
|
-
], KHR_materials_unlit);
|
|
1353
|
-
|
|
1354
|
-
var KHR_materials_variants = /*#__PURE__*/ function(ExtensionParser) {
|
|
1355
|
-
_inherits(KHR_materials_variants, ExtensionParser);
|
|
1356
|
-
function KHR_materials_variants() {
|
|
1357
|
-
return ExtensionParser.apply(this, arguments);
|
|
1358
|
-
}
|
|
1359
|
-
var _proto = KHR_materials_variants.prototype;
|
|
1360
|
-
_proto.parseEngineResource = function parseEngineResource(schema, renderer, context) {
|
|
1361
|
-
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;
|
|
1362
|
-
var mappings = schema.mappings;
|
|
1363
|
-
for(var i = 0; i < mappings.length; i++){
|
|
1364
|
-
var _mappings_i = mappings[i], material = _mappings_i.material, variants = _mappings_i.variants;
|
|
1365
|
-
if (!glTFResource.variants) glTFResource.variants = [];
|
|
1366
|
-
glTFResource.variants.push({
|
|
1367
|
-
renderer: renderer,
|
|
1368
|
-
material: glTFResource.materials[material],
|
|
1369
|
-
variants: variants.map(function(index) {
|
|
1370
|
-
return variantNames[index].name;
|
|
1371
|
-
})
|
|
1437
|
+
input[input.length - 1];
|
|
1438
|
+
sampleDataCollection.push({
|
|
1439
|
+
type: outputAccessor.type,
|
|
1440
|
+
interpolation: samplerInterpolation,
|
|
1441
|
+
input: input,
|
|
1442
|
+
output: output,
|
|
1443
|
+
outputSize: outputStride
|
|
1372
1444
|
});
|
|
1373
1445
|
}
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
function KHR_mesh_quantization() {
|
|
1384
|
-
return ExtensionParser.apply(this, arguments);
|
|
1385
|
-
}
|
|
1386
|
-
return KHR_mesh_quantization;
|
|
1387
|
-
}(ExtensionParser);
|
|
1388
|
-
KHR_mesh_quantization = __decorate([
|
|
1389
|
-
registerExtension("KHR_mesh_quantization")
|
|
1390
|
-
], KHR_mesh_quantization);
|
|
1391
|
-
|
|
1392
|
-
var KHR_texture_transform = /*#__PURE__*/ function(ExtensionParser) {
|
|
1393
|
-
_inherits(KHR_texture_transform, ExtensionParser);
|
|
1394
|
-
function KHR_texture_transform() {
|
|
1395
|
-
return ExtensionParser.apply(this, arguments);
|
|
1396
|
-
}
|
|
1397
|
-
var _proto = KHR_texture_transform.prototype;
|
|
1398
|
-
_proto.parseEngineResource = function parseEngineResource(schema, material, context) {
|
|
1399
|
-
var offset = schema.offset, rotation = schema.rotation, scale = schema.scale, texCoord = schema.texCoord;
|
|
1400
|
-
if (offset) {
|
|
1401
|
-
material.tilingOffset.z = offset[0];
|
|
1402
|
-
material.tilingOffset.w = offset[1];
|
|
1403
|
-
}
|
|
1404
|
-
if (scale) {
|
|
1405
|
-
material.tilingOffset.x = scale[0];
|
|
1406
|
-
material.tilingOffset.y = scale[1];
|
|
1407
|
-
}
|
|
1408
|
-
if (rotation) {
|
|
1409
|
-
engineCore.Logger.warn("rotation in KHR_texture_transform is not supported now");
|
|
1410
|
-
}
|
|
1411
|
-
if (texCoord) {
|
|
1412
|
-
engineCore.Logger.warn("texCoord in KHR_texture_transform is not supported now");
|
|
1413
|
-
}
|
|
1414
|
-
};
|
|
1415
|
-
return KHR_texture_transform;
|
|
1416
|
-
}(ExtensionParser);
|
|
1417
|
-
KHR_texture_transform = __decorate([
|
|
1418
|
-
registerExtension("KHR_texture_transform")
|
|
1419
|
-
], KHR_texture_transform);
|
|
1420
|
-
|
|
1421
|
-
var GalaceanMaterialsRemap = /*#__PURE__*/ function(ExtensionParser) {
|
|
1422
|
-
_inherits(GalaceanMaterialsRemap, ExtensionParser);
|
|
1423
|
-
function GalaceanMaterialsRemap() {
|
|
1424
|
-
return ExtensionParser.apply(this, arguments);
|
|
1425
|
-
}
|
|
1426
|
-
var _proto = GalaceanMaterialsRemap.prototype;
|
|
1427
|
-
_proto.createEngineResource = function createEngineResource(schema, context) {
|
|
1428
|
-
var engine = context.glTFResource.engine;
|
|
1429
|
-
// @ts-ignore
|
|
1430
|
-
return engine.resourceManager.getResourceByRef(schema);
|
|
1431
|
-
};
|
|
1432
|
-
return GalaceanMaterialsRemap;
|
|
1433
|
-
}(ExtensionParser);
|
|
1434
|
-
GalaceanMaterialsRemap = __decorate([
|
|
1435
|
-
registerExtension("OASIS_materials_remap")
|
|
1436
|
-
], GalaceanMaterialsRemap);
|
|
1437
|
-
|
|
1438
|
-
function _createForOfIteratorHelperLoose(o, allowArrayLike) {
|
|
1439
|
-
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
1440
|
-
if (it) return (it = it.call(o)).next.bind(it);
|
|
1441
|
-
// Fallback for engines without symbol support
|
|
1442
|
-
if (
|
|
1443
|
-
Array.isArray(o) ||
|
|
1444
|
-
(it = _unsupportedIterableToArray(o)) ||
|
|
1445
|
-
(allowArrayLike && o && typeof o.length === "number")
|
|
1446
|
-
) {
|
|
1447
|
-
if (it) o = it;
|
|
1448
|
-
var i = 0;
|
|
1449
|
-
return function () {
|
|
1450
|
-
if (i >= o.length) return { done: true };
|
|
1451
|
-
return { done: false, value: o[i++] };
|
|
1452
|
-
}
|
|
1453
|
-
}
|
|
1454
|
-
throw new TypeError("Invalid attempt to iterate non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
1455
|
-
}
|
|
1456
|
-
|
|
1457
|
-
var AnimationParser = /*#__PURE__*/ function(Parser) {
|
|
1458
|
-
_inherits(AnimationParser, Parser);
|
|
1459
|
-
function AnimationParser() {
|
|
1460
|
-
return Parser.apply(this, arguments);
|
|
1461
|
-
}
|
|
1462
|
-
var _proto = AnimationParser.prototype;
|
|
1463
|
-
_proto.parse = function parse(context) {
|
|
1464
|
-
var gltf = context.gltf; context.buffers; var glTFResource = context.glTFResource;
|
|
1465
|
-
var entities = glTFResource.entities;
|
|
1466
|
-
var animations = gltf.animations, accessors = gltf.accessors;
|
|
1467
|
-
if (!animations) {
|
|
1468
|
-
return;
|
|
1469
|
-
}
|
|
1470
|
-
var animationClipsPromiseInfo = context.animationClipsPromiseInfo;
|
|
1471
|
-
var animationClipCount = animations.length;
|
|
1472
|
-
var animationClips = new Array(animationClipCount);
|
|
1473
|
-
var animationsIndices = new Array(animationClipCount);
|
|
1474
|
-
for(var i = 0; i < animationClipCount; i++){
|
|
1475
|
-
var gltfAnimation = animations[i];
|
|
1476
|
-
var channels = gltfAnimation.channels, samplers = gltfAnimation.samplers, _gltfAnimation_name = gltfAnimation.name, name = _gltfAnimation_name === void 0 ? "AnimationClip" + i : _gltfAnimation_name;
|
|
1477
|
-
var animationClip = new engineCore.AnimationClip(name);
|
|
1478
|
-
var sampleDataCollection = new Array();
|
|
1479
|
-
// parse samplers
|
|
1480
|
-
for(var j = 0, m = samplers.length; j < m; j++){
|
|
1481
|
-
var gltfSampler = samplers[j];
|
|
1482
|
-
var inputAccessor = accessors[gltfSampler.input];
|
|
1483
|
-
var outputAccessor = accessors[gltfSampler.output];
|
|
1484
|
-
var input = GLTFUtil.getAccessorBuffer(context, gltf, inputAccessor).data;
|
|
1485
|
-
var output = GLTFUtil.getAccessorBuffer(context, gltf, outputAccessor).data;
|
|
1486
|
-
if (outputAccessor.normalized) {
|
|
1487
|
-
var scale = GLTFUtil.getNormalizedComponentScale(outputAccessor.componentType);
|
|
1488
|
-
var scaled = new Float32Array(output.length);
|
|
1489
|
-
for(var k = 0, v = output.length; k < v; k++){
|
|
1490
|
-
scaled[k] = output[k] * scale;
|
|
1491
|
-
}
|
|
1492
|
-
output = scaled;
|
|
1493
|
-
}
|
|
1494
|
-
var outputStride = output.length / input.length;
|
|
1495
|
-
var _gltfSampler_interpolation;
|
|
1496
|
-
var interpolation = (_gltfSampler_interpolation = gltfSampler.interpolation) != null ? _gltfSampler_interpolation : AnimationSamplerInterpolation.Linear;
|
|
1497
|
-
var samplerInterpolation = void 0;
|
|
1498
|
-
switch(interpolation){
|
|
1499
|
-
case AnimationSamplerInterpolation.CubicSpine:
|
|
1500
|
-
samplerInterpolation = engineCore.InterpolationType.CubicSpine;
|
|
1501
|
-
break;
|
|
1502
|
-
case AnimationSamplerInterpolation.Step:
|
|
1503
|
-
samplerInterpolation = engineCore.InterpolationType.Step;
|
|
1504
|
-
break;
|
|
1505
|
-
case AnimationSamplerInterpolation.Linear:
|
|
1506
|
-
samplerInterpolation = engineCore.InterpolationType.Linear;
|
|
1507
|
-
break;
|
|
1508
|
-
}
|
|
1509
|
-
input[input.length - 1];
|
|
1510
|
-
sampleDataCollection.push({
|
|
1511
|
-
type: outputAccessor.type,
|
|
1512
|
-
interpolation: samplerInterpolation,
|
|
1513
|
-
input: input,
|
|
1514
|
-
output: output,
|
|
1515
|
-
outputSize: outputStride
|
|
1516
|
-
});
|
|
1446
|
+
for(var j1 = 0, m1 = channels.length; j1 < m1; j1++){
|
|
1447
|
+
var gltfChannel = channels[j1];
|
|
1448
|
+
var target = gltfChannel.target;
|
|
1449
|
+
var channelTargetEntity = entities[target.node];
|
|
1450
|
+
var relativePath = "";
|
|
1451
|
+
var entity = channelTargetEntity;
|
|
1452
|
+
while(entity.parent){
|
|
1453
|
+
relativePath = relativePath === "" ? "" + entity.name : entity.name + "/" + relativePath;
|
|
1454
|
+
entity = entity.parent;
|
|
1517
1455
|
}
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
propertyName = "rotationQuaternion";
|
|
1538
|
-
break;
|
|
1539
|
-
case AnimationChannelTargetPath.SCALE:
|
|
1540
|
-
ComponentType = engineCore.Transform;
|
|
1541
|
-
propertyName = "scale";
|
|
1542
|
-
break;
|
|
1543
|
-
case AnimationChannelTargetPath.WEIGHTS:
|
|
1544
|
-
ComponentType = engineCore.SkinnedMeshRenderer;
|
|
1545
|
-
propertyName = "blendShapeWeights";
|
|
1546
|
-
break;
|
|
1547
|
-
}
|
|
1548
|
-
var curve = this._addCurve(target.path, gltfChannel, sampleDataCollection);
|
|
1549
|
-
animationClip.addCurveBinding(relativePath, ComponentType, propertyName, curve);
|
|
1456
|
+
var ComponentType = void 0;
|
|
1457
|
+
var propertyName = void 0;
|
|
1458
|
+
switch(target.path){
|
|
1459
|
+
case AnimationChannelTargetPath.TRANSLATION:
|
|
1460
|
+
ComponentType = engineCore.Transform;
|
|
1461
|
+
propertyName = "position";
|
|
1462
|
+
break;
|
|
1463
|
+
case AnimationChannelTargetPath.ROTATION:
|
|
1464
|
+
ComponentType = engineCore.Transform;
|
|
1465
|
+
propertyName = "rotationQuaternion";
|
|
1466
|
+
break;
|
|
1467
|
+
case AnimationChannelTargetPath.SCALE:
|
|
1468
|
+
ComponentType = engineCore.Transform;
|
|
1469
|
+
propertyName = "scale";
|
|
1470
|
+
break;
|
|
1471
|
+
case AnimationChannelTargetPath.WEIGHTS:
|
|
1472
|
+
ComponentType = engineCore.SkinnedMeshRenderer;
|
|
1473
|
+
propertyName = "blendShapeWeights";
|
|
1474
|
+
break;
|
|
1550
1475
|
}
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
name: name,
|
|
1554
|
-
index: i
|
|
1555
|
-
};
|
|
1476
|
+
var curve = this._addCurve(target.path, gltfChannel, sampleDataCollection);
|
|
1477
|
+
animationClip.addCurveBinding(relativePath, ComponentType, propertyName, curve);
|
|
1556
1478
|
}
|
|
1557
|
-
glTFResource.animations = animationClips;
|
|
1558
|
-
// @ts-ignore for editor
|
|
1559
|
-
glTFResource._animationsIndices = animationsIndices;
|
|
1560
|
-
animationClipsPromiseInfo.resolve(animationClips);
|
|
1561
|
-
return animationClipsPromiseInfo.promise;
|
|
1562
1479
|
};
|
|
1563
|
-
|
|
1480
|
+
GLTFAnimationParser._addCurve = function _addCurve(animationChannelTargetPath, gltfChannel, sampleDataCollection) {
|
|
1564
1481
|
var sampleData = sampleDataCollection[gltfChannel.sampler];
|
|
1565
1482
|
var input = sampleData.input, output = sampleData.output, outputSize = sampleData.outputSize;
|
|
1566
|
-
switch(
|
|
1483
|
+
switch(animationChannelTargetPath){
|
|
1567
1484
|
case AnimationChannelTargetPath.TRANSLATION:
|
|
1568
1485
|
case AnimationChannelTargetPath.SCALE:
|
|
1569
1486
|
{
|
|
@@ -1628,35 +1545,42 @@ var AnimationParser = /*#__PURE__*/ function(Parser) {
|
|
|
1628
1545
|
}
|
|
1629
1546
|
}
|
|
1630
1547
|
};
|
|
1631
|
-
return
|
|
1632
|
-
}(
|
|
1548
|
+
return GLTFAnimationParser;
|
|
1549
|
+
}(GLTFParser);
|
|
1633
1550
|
|
|
1634
|
-
var
|
|
1635
|
-
_inherits(
|
|
1636
|
-
function
|
|
1637
|
-
return
|
|
1551
|
+
var GLTFBufferParser = /*#__PURE__*/ function(GLTFParser) {
|
|
1552
|
+
_inherits(GLTFBufferParser, GLTFParser);
|
|
1553
|
+
function GLTFBufferParser() {
|
|
1554
|
+
return GLTFParser.apply(this, arguments);
|
|
1638
1555
|
}
|
|
1639
|
-
var _proto =
|
|
1556
|
+
var _proto = GLTFBufferParser.prototype;
|
|
1640
1557
|
_proto.parse = function parse(context) {
|
|
1641
|
-
var glTFResource = context.glTFResource;
|
|
1558
|
+
var glTFResource = context.glTFResource, contentRestorer = context.contentRestorer;
|
|
1642
1559
|
var url = glTFResource.url;
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1560
|
+
var restoreBufferRequests = contentRestorer.bufferRequests;
|
|
1561
|
+
var requestConfig = {
|
|
1562
|
+
type: "arraybuffer"
|
|
1563
|
+
};
|
|
1564
|
+
var isGLB = this._isGLB(url);
|
|
1565
|
+
contentRestorer.isGLB = isGLB;
|
|
1566
|
+
if (isGLB) {
|
|
1567
|
+
return engineCore.request(url, requestConfig).then(function(glb) {
|
|
1568
|
+
restoreBufferRequests.push(new BufferRequestInfo(url, requestConfig));
|
|
1569
|
+
return GLTFUtil.parseGLB(context, glb);
|
|
1570
|
+
}).then(function(param) {
|
|
1571
|
+
var glTF = param.glTF, buffers = param.buffers;
|
|
1572
|
+
context.glTF = glTF;
|
|
1649
1573
|
context.buffers = buffers;
|
|
1650
1574
|
});
|
|
1651
1575
|
} else {
|
|
1652
1576
|
return engineCore.request(url, {
|
|
1653
1577
|
type: "json"
|
|
1654
|
-
}).then(function(
|
|
1655
|
-
context.
|
|
1656
|
-
return Promise.all(
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1578
|
+
}).then(function(glTF) {
|
|
1579
|
+
context.glTF = glTF;
|
|
1580
|
+
return Promise.all(glTF.buffers.map(function(buffer) {
|
|
1581
|
+
var absoluteUrl = GLTFUtil.parseRelativeUrl(url, buffer.uri);
|
|
1582
|
+
restoreBufferRequests.push(new BufferRequestInfo(absoluteUrl, requestConfig));
|
|
1583
|
+
return engineCore.request(absoluteUrl, requestConfig);
|
|
1660
1584
|
})).then(function(buffers) {
|
|
1661
1585
|
context.buffers = buffers;
|
|
1662
1586
|
});
|
|
@@ -1667,24 +1591,24 @@ var BufferParser = /*#__PURE__*/ function(Parser) {
|
|
|
1667
1591
|
var index = url.lastIndexOf(".");
|
|
1668
1592
|
return url.substring(index + 1, index + 4) === "glb";
|
|
1669
1593
|
};
|
|
1670
|
-
return
|
|
1671
|
-
}(
|
|
1594
|
+
return GLTFBufferParser;
|
|
1595
|
+
}(GLTFParser);
|
|
1672
1596
|
|
|
1673
|
-
var
|
|
1674
|
-
_inherits(
|
|
1675
|
-
function
|
|
1676
|
-
return
|
|
1597
|
+
var GLTFEntityParser = /*#__PURE__*/ function(GLTFParser) {
|
|
1598
|
+
_inherits(GLTFEntityParser, GLTFParser);
|
|
1599
|
+
function GLTFEntityParser() {
|
|
1600
|
+
return GLTFParser.apply(this, arguments);
|
|
1677
1601
|
}
|
|
1678
|
-
var _proto =
|
|
1602
|
+
var _proto = GLTFEntityParser.prototype;
|
|
1679
1603
|
_proto.parse = function parse(context) {
|
|
1680
|
-
var glTFResource = context.glTFResource, nodes = context.
|
|
1604
|
+
var glTFResource = context.glTFResource, nodes = context.glTF.nodes;
|
|
1681
1605
|
var engine = glTFResource.engine;
|
|
1682
1606
|
if (!nodes) return;
|
|
1683
1607
|
var entities = [];
|
|
1684
1608
|
for(var i = 0; i < nodes.length; i++){
|
|
1685
1609
|
var gltfNode = nodes[i];
|
|
1686
1610
|
var matrix = gltfNode.matrix, translation = gltfNode.translation, rotation = gltfNode.rotation, scale = gltfNode.scale;
|
|
1687
|
-
var entity = new engineCore.Entity(engine, gltfNode.name || "" +
|
|
1611
|
+
var entity = new engineCore.Entity(engine, gltfNode.name || "" + GLTFEntityParser._defaultName + i);
|
|
1688
1612
|
var transform = entity.transform;
|
|
1689
1613
|
if (matrix) {
|
|
1690
1614
|
var localMatrix = transform.localMatrix;
|
|
@@ -1708,7 +1632,7 @@ var EntityParser = /*#__PURE__*/ function(Parser) {
|
|
|
1708
1632
|
this._createSceneRoots(context, glTFResource);
|
|
1709
1633
|
};
|
|
1710
1634
|
_proto._buildEntityTree = function _buildEntityTree(context, glTFResource) {
|
|
1711
|
-
var nodes = context.
|
|
1635
|
+
var nodes = context.glTF.nodes;
|
|
1712
1636
|
var entities = glTFResource.entities;
|
|
1713
1637
|
for(var i = 0; i < nodes.length; i++){
|
|
1714
1638
|
var children = nodes[i].children;
|
|
@@ -1722,7 +1646,7 @@ var EntityParser = /*#__PURE__*/ function(Parser) {
|
|
|
1722
1646
|
}
|
|
1723
1647
|
};
|
|
1724
1648
|
_proto._createSceneRoots = function _createSceneRoots(context, glTFResource) {
|
|
1725
|
-
var
|
|
1649
|
+
var _context_glTF = context.glTF, tmp = _context_glTF.scene, sceneID = tmp === void 0 ? 0 : tmp, scenes = _context_glTF.scenes;
|
|
1726
1650
|
var engine = glTFResource.engine, entities = glTFResource.entities;
|
|
1727
1651
|
if (!scenes) return;
|
|
1728
1652
|
var sceneRoots = [];
|
|
@@ -1742,94 +1666,210 @@ var EntityParser = /*#__PURE__*/ function(Parser) {
|
|
|
1742
1666
|
glTFResource.sceneRoots = sceneRoots;
|
|
1743
1667
|
glTFResource.defaultSceneRoot = sceneRoots[sceneID];
|
|
1744
1668
|
};
|
|
1745
|
-
return
|
|
1746
|
-
}(
|
|
1747
|
-
/** @internal */
|
|
1669
|
+
return GLTFEntityParser;
|
|
1670
|
+
}(GLTFParser);
|
|
1671
|
+
/** @internal */ GLTFEntityParser._defaultName = "_GLTF_ENTITY_";
|
|
1748
1672
|
|
|
1749
|
-
var
|
|
1750
|
-
_inherits(
|
|
1751
|
-
function
|
|
1752
|
-
return
|
|
1673
|
+
var GLTFMaterialParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
1674
|
+
_inherits(GLTFMaterialParser, GLTFParser1);
|
|
1675
|
+
function GLTFMaterialParser() {
|
|
1676
|
+
return GLTFParser1.apply(this, arguments);
|
|
1753
1677
|
}
|
|
1754
|
-
var _proto =
|
|
1678
|
+
var _proto = GLTFMaterialParser.prototype;
|
|
1755
1679
|
_proto.parse = function parse(context) {
|
|
1756
|
-
var
|
|
1757
|
-
|
|
1758
|
-
var gltfPrimitive = gltfMesh.primitives[j];
|
|
1759
|
-
var _gltfPrimitive_extensions = gltfPrimitive.extensions, extensions = _gltfPrimitive_extensions === void 0 ? {} : _gltfPrimitive_extensions;
|
|
1760
|
-
var KHR_draco_mesh_compression = extensions.KHR_draco_mesh_compression;
|
|
1761
|
-
primitivePromises[j] = new Promise(function(resolve) {
|
|
1762
|
-
var mesh = new engineCore.ModelMesh(engine, gltfMesh.name || j + "");
|
|
1763
|
-
if (KHR_draco_mesh_compression) {
|
|
1764
|
-
Parser.createEngineResource("KHR_draco_mesh_compression", KHR_draco_mesh_compression, context, gltfPrimitive).then(function(decodedGeometry) {
|
|
1765
|
-
return _this._parseMeshFromGLTFPrimitiveDraco(mesh, gltfMesh, gltfPrimitive, gltf, function(attributeSemantic) {
|
|
1766
|
-
for(var j = 0; j < decodedGeometry.attributes.length; j++){
|
|
1767
|
-
if (decodedGeometry.attributes[j].name === attributeSemantic) {
|
|
1768
|
-
return decodedGeometry.attributes[j].array;
|
|
1769
|
-
}
|
|
1770
|
-
}
|
|
1771
|
-
return null;
|
|
1772
|
-
}, function(attributeSemantic, shapeIndex) {
|
|
1773
|
-
throw "BlendShape animation is not supported when using draco.";
|
|
1774
|
-
}, function() {
|
|
1775
|
-
return decodedGeometry.index.array;
|
|
1776
|
-
}, context.keepMeshData);
|
|
1777
|
-
}).then(resolve);
|
|
1778
|
-
} else {
|
|
1779
|
-
_this._parseMeshFromGLTFPrimitive(context, mesh, gltfMesh, gltfPrimitive, gltf, function(attributeSemantic) {
|
|
1780
|
-
return null;
|
|
1781
|
-
}, function(attributeName, shapeIndex) {
|
|
1782
|
-
var shapeAccessorIdx = gltfPrimitive.targets[shapeIndex];
|
|
1783
|
-
var attributeAccessorIdx = shapeAccessorIdx[attributeName];
|
|
1784
|
-
if (attributeAccessorIdx) {
|
|
1785
|
-
var accessor = gltf.accessors[attributeAccessorIdx];
|
|
1786
|
-
return GLTFUtil.getAccessorData(gltf, accessor, buffers);
|
|
1787
|
-
} else {
|
|
1788
|
-
return null;
|
|
1789
|
-
}
|
|
1790
|
-
}, function() {
|
|
1791
|
-
var indexAccessor = gltf.accessors[gltfPrimitive.indices];
|
|
1792
|
-
return GLTFUtil.getAccessorData(gltf, indexAccessor, buffers);
|
|
1793
|
-
}, context.keepMeshData).then(resolve);
|
|
1794
|
-
}
|
|
1795
|
-
});
|
|
1796
|
-
};
|
|
1797
|
-
var gltfMesh = gltf.meshes[i];
|
|
1798
|
-
var primitivePromises = [];
|
|
1799
|
-
for(var j = 0; j < gltfMesh.primitives.length; j++)_loop(j);
|
|
1800
|
-
meshPromises[i] = Promise.all(primitivePromises);
|
|
1801
|
-
};
|
|
1802
|
-
var _this = this;
|
|
1803
|
-
var gltf = context.gltf, buffers = context.buffers, glTFResource = context.glTFResource;
|
|
1680
|
+
var glTF = context.glTF, glTFResource = context.glTFResource, materialsPromiseInfo = context.materialsPromiseInfo;
|
|
1681
|
+
if (!glTF.materials) return;
|
|
1804
1682
|
var engine = glTFResource.engine;
|
|
1805
|
-
|
|
1806
|
-
var
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1683
|
+
var materialPromises = [];
|
|
1684
|
+
for(var i = 0; i < glTF.materials.length; i++){
|
|
1685
|
+
var materialInfo = glTF.materials[i];
|
|
1686
|
+
var material = GLTFParser.executeExtensionsCreateAndParse(materialInfo.extensions, context, materialInfo);
|
|
1687
|
+
if (!material) {
|
|
1688
|
+
material = new engineCore.PBRMaterial(engine);
|
|
1689
|
+
material.name = materialInfo.name;
|
|
1690
|
+
GLTFMaterialParser._parseStandardProperty(context, material, materialInfo);
|
|
1691
|
+
}
|
|
1692
|
+
materialPromises.push(material);
|
|
1693
|
+
}
|
|
1694
|
+
return engineCore.AssetPromise.all(materialPromises).then(function(materials) {
|
|
1695
|
+
glTFResource.materials = materials;
|
|
1696
|
+
for(var i = 0; i < glTF.materials.length; i++){
|
|
1697
|
+
var materialInfo = glTF.materials[i];
|
|
1698
|
+
GLTFParser.executeExtensionsAdditiveAndParse(materialInfo.extensions, context, materials[i], materialInfo);
|
|
1699
|
+
}
|
|
1700
|
+
materialsPromiseInfo.resolve(materials);
|
|
1701
|
+
return materialsPromiseInfo.promise;
|
|
1702
|
+
});
|
|
1814
1703
|
};
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
var
|
|
1819
|
-
|
|
1820
|
-
|
|
1704
|
+
/**
|
|
1705
|
+
* @internal
|
|
1706
|
+
*/ GLTFMaterialParser._checkOtherTextureTransform = function _checkOtherTextureTransform(texture, textureName) {
|
|
1707
|
+
var _texture_extensions;
|
|
1708
|
+
if ((_texture_extensions = texture.extensions) == null ? void 0 : _texture_extensions.KHR_texture_transform) {
|
|
1709
|
+
engineCore.Logger.warn("" + textureName + " texture always use the KHR_texture_transform of the base texture.");
|
|
1710
|
+
}
|
|
1711
|
+
};
|
|
1712
|
+
/**
|
|
1713
|
+
* @internal
|
|
1714
|
+
*/ GLTFMaterialParser._parseStandardProperty = function _parseStandardProperty(context, material, materialInfo) {
|
|
1715
|
+
var textures = context.glTFResource.textures;
|
|
1716
|
+
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;
|
|
1717
|
+
if (pbrMetallicRoughness) {
|
|
1718
|
+
var baseColorFactor = pbrMetallicRoughness.baseColorFactor, baseColorTexture = pbrMetallicRoughness.baseColorTexture, metallicFactor = pbrMetallicRoughness.metallicFactor, roughnessFactor = pbrMetallicRoughness.roughnessFactor, metallicRoughnessTexture = pbrMetallicRoughness.metallicRoughnessTexture;
|
|
1719
|
+
if (baseColorFactor) {
|
|
1720
|
+
material.baseColor = new engineMath.Color(engineMath.Color.linearToGammaSpace(baseColorFactor[0]), engineMath.Color.linearToGammaSpace(baseColorFactor[1]), engineMath.Color.linearToGammaSpace(baseColorFactor[2]), baseColorFactor[3]);
|
|
1721
|
+
}
|
|
1722
|
+
if (baseColorTexture) {
|
|
1723
|
+
material.baseTexture = textures[baseColorTexture.index];
|
|
1724
|
+
GLTFParser.executeExtensionsAdditiveAndParse(baseColorTexture.extensions, context, material, baseColorTexture);
|
|
1725
|
+
}
|
|
1726
|
+
if (material.constructor === engineCore.PBRMaterial) {
|
|
1727
|
+
material.metallic = metallicFactor != null ? metallicFactor : 1;
|
|
1728
|
+
material.roughness = roughnessFactor != null ? roughnessFactor : 1;
|
|
1729
|
+
if (metallicRoughnessTexture) {
|
|
1730
|
+
material.roughnessMetallicTexture = textures[metallicRoughnessTexture.index];
|
|
1731
|
+
GLTFMaterialParser._checkOtherTextureTransform(metallicRoughnessTexture, "Roughness metallic");
|
|
1732
|
+
}
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1735
|
+
if (material.constructor === engineCore.PBRMaterial || material.constructor === engineCore.PBRSpecularMaterial) {
|
|
1736
|
+
if (emissiveTexture) {
|
|
1737
|
+
material.emissiveTexture = textures[emissiveTexture.index];
|
|
1738
|
+
GLTFMaterialParser._checkOtherTextureTransform(emissiveTexture, "Emissive");
|
|
1739
|
+
}
|
|
1740
|
+
if (emissiveFactor) {
|
|
1741
|
+
material.emissiveColor = new engineMath.Color(engineMath.Color.linearToGammaSpace(emissiveFactor[0]), engineMath.Color.linearToGammaSpace(emissiveFactor[1]), engineMath.Color.linearToGammaSpace(emissiveFactor[2]));
|
|
1742
|
+
}
|
|
1743
|
+
if (normalTexture) {
|
|
1744
|
+
var index = normalTexture.index, scale = normalTexture.scale;
|
|
1745
|
+
material.normalTexture = textures[index];
|
|
1746
|
+
GLTFMaterialParser._checkOtherTextureTransform(normalTexture, "Normal");
|
|
1747
|
+
if (scale !== undefined) {
|
|
1748
|
+
material.normalTextureIntensity = scale;
|
|
1749
|
+
}
|
|
1750
|
+
}
|
|
1751
|
+
if (occlusionTexture) {
|
|
1752
|
+
var index1 = occlusionTexture.index, strength = occlusionTexture.strength, texCoord = occlusionTexture.texCoord;
|
|
1753
|
+
material.occlusionTexture = textures[index1];
|
|
1754
|
+
GLTFMaterialParser._checkOtherTextureTransform(occlusionTexture, "Occlusion");
|
|
1755
|
+
if (strength !== undefined) {
|
|
1756
|
+
material.occlusionTextureIntensity = strength;
|
|
1757
|
+
}
|
|
1758
|
+
if (texCoord === engineCore.TextureCoordinate.UV1) {
|
|
1759
|
+
material.occlusionTextureCoord = engineCore.TextureCoordinate.UV1;
|
|
1760
|
+
} else if (texCoord > engineCore.TextureCoordinate.UV1) {
|
|
1761
|
+
engineCore.Logger.warn("Occlusion texture uv coordinate must be UV0 or UV1.");
|
|
1762
|
+
}
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
if (doubleSided) {
|
|
1766
|
+
material.renderFace = engineCore.RenderFace.Double;
|
|
1767
|
+
} else {
|
|
1768
|
+
material.renderFace = engineCore.RenderFace.Front;
|
|
1769
|
+
}
|
|
1770
|
+
switch(alphaMode){
|
|
1771
|
+
case MaterialAlphaMode.OPAQUE:
|
|
1772
|
+
material.isTransparent = false;
|
|
1773
|
+
break;
|
|
1774
|
+
case MaterialAlphaMode.BLEND:
|
|
1775
|
+
material.isTransparent = true;
|
|
1776
|
+
break;
|
|
1777
|
+
case MaterialAlphaMode.MASK:
|
|
1778
|
+
material.alphaCutoff = alphaCutoff != null ? alphaCutoff : 0.5;
|
|
1779
|
+
break;
|
|
1780
|
+
}
|
|
1781
|
+
};
|
|
1782
|
+
return GLTFMaterialParser;
|
|
1783
|
+
}(GLTFParser);
|
|
1784
|
+
|
|
1785
|
+
function _instanceof(left, right) {
|
|
1786
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
1787
|
+
return !!right[Symbol.hasInstance](left);
|
|
1788
|
+
} else {
|
|
1789
|
+
return left instanceof right;
|
|
1790
|
+
}
|
|
1791
|
+
}
|
|
1792
|
+
|
|
1793
|
+
var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
1794
|
+
_inherits(GLTFMeshParser, GLTFParser1);
|
|
1795
|
+
function GLTFMeshParser() {
|
|
1796
|
+
return GLTFParser1.apply(this, arguments);
|
|
1797
|
+
}
|
|
1798
|
+
var _proto = GLTFMeshParser.prototype;
|
|
1799
|
+
_proto.parse = function parse(context) {
|
|
1800
|
+
var _loop = function(i) {
|
|
1801
|
+
var _loop = function(j) {
|
|
1802
|
+
var gltfPrimitive = gltfMesh.primitives[j];
|
|
1803
|
+
primitivePromises[j] = new Promise(function(resolve) {
|
|
1804
|
+
var mesh = GLTFParser.executeExtensionsCreateAndParse(gltfPrimitive.extensions, context, gltfPrimitive, gltfMesh);
|
|
1805
|
+
if (mesh) {
|
|
1806
|
+
if (_instanceof(mesh, engineCore.ModelMesh)) {
|
|
1807
|
+
resolve(mesh);
|
|
1808
|
+
} else {
|
|
1809
|
+
mesh.then(function(mesh) {
|
|
1810
|
+
return resolve(mesh);
|
|
1811
|
+
});
|
|
1812
|
+
}
|
|
1813
|
+
} else {
|
|
1814
|
+
var mesh1 = new engineCore.ModelMesh(engine, gltfMesh.name || j + "");
|
|
1815
|
+
var meshRestoreInfo = new ModelMeshRestoreInfo();
|
|
1816
|
+
meshRestoreInfo.mesh = mesh1;
|
|
1817
|
+
context.contentRestorer.meshes.push(meshRestoreInfo);
|
|
1818
|
+
GLTFMeshParser._parseMeshFromGLTFPrimitive(context, mesh1, meshRestoreInfo, gltfMesh, gltfPrimitive, glTF, function(attributeSemantic) {
|
|
1819
|
+
return null;
|
|
1820
|
+
}, function(attributeName, shapeIndex) {
|
|
1821
|
+
var shapeAccessorIdx = gltfPrimitive.targets[shapeIndex];
|
|
1822
|
+
var attributeAccessorIdx = shapeAccessorIdx[attributeName];
|
|
1823
|
+
if (attributeAccessorIdx) {
|
|
1824
|
+
var accessor = glTF.accessors[attributeAccessorIdx];
|
|
1825
|
+
return GLTFUtil.getAccessorBuffer(context, context.glTF.bufferViews, accessor);
|
|
1826
|
+
} else {
|
|
1827
|
+
return null;
|
|
1828
|
+
}
|
|
1829
|
+
}, function() {
|
|
1830
|
+
var indexAccessor = glTF.accessors[gltfPrimitive.indices];
|
|
1831
|
+
return GLTFUtil.getAccessorData(glTF, indexAccessor, buffers);
|
|
1832
|
+
}, context.keepMeshData).then(resolve);
|
|
1833
|
+
}
|
|
1834
|
+
});
|
|
1835
|
+
};
|
|
1836
|
+
var gltfMesh = glTF.meshes[i];
|
|
1837
|
+
var primitivePromises = [];
|
|
1838
|
+
for(var j = 0; j < gltfMesh.primitives.length; j++)_loop(j);
|
|
1839
|
+
meshPromises[i] = Promise.all(primitivePromises);
|
|
1840
|
+
};
|
|
1841
|
+
var glTF = context.glTF, buffers = context.buffers, glTFResource = context.glTFResource;
|
|
1842
|
+
var engine = glTFResource.engine;
|
|
1843
|
+
if (!glTF.meshes) return;
|
|
1844
|
+
var meshesPromiseInfo = context.meshesPromiseInfo;
|
|
1845
|
+
var meshPromises = [];
|
|
1846
|
+
for(var i = 0; i < glTF.meshes.length; i++)_loop(i);
|
|
1847
|
+
engineCore.AssetPromise.all(meshPromises).then(function(meshes) {
|
|
1848
|
+
glTFResource.meshes = meshes;
|
|
1849
|
+
meshesPromiseInfo.resolve(meshes);
|
|
1850
|
+
}).catch(meshesPromiseInfo.reject);
|
|
1851
|
+
return meshesPromiseInfo.promise;
|
|
1852
|
+
};
|
|
1853
|
+
/**
|
|
1854
|
+
* @internal
|
|
1855
|
+
*/ GLTFMeshParser._parseMeshFromGLTFPrimitive = function _parseMeshFromGLTFPrimitive(context, mesh, meshRestoreInfo, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
|
|
1856
|
+
var accessors = gltf.accessors;
|
|
1857
|
+
context.buffers;
|
|
1858
|
+
var attributes = gltfPrimitive.attributes, targets = gltfPrimitive.targets, indices = gltfPrimitive.indices, mode = gltfPrimitive.mode;
|
|
1859
|
+
var engine = mesh.engine;
|
|
1860
|
+
var vertexElements = new Array();
|
|
1821
1861
|
var vertexCount;
|
|
1822
1862
|
var bufferBindIndex = 0;
|
|
1823
1863
|
for(var attribute in attributes){
|
|
1824
1864
|
var accessor = accessors[attributes[attribute]];
|
|
1825
|
-
var accessorBuffer = GLTFUtil.getAccessorBuffer(context, gltf, accessor);
|
|
1826
|
-
var
|
|
1865
|
+
var accessorBuffer = GLTFUtil.getAccessorBuffer(context, gltf.bufferViews, accessor);
|
|
1866
|
+
var dataElementSize = GLTFUtil.getAccessorTypeSize(accessor.type);
|
|
1827
1867
|
var attributeCount = accessor.count;
|
|
1828
1868
|
var vertices = accessorBuffer.data;
|
|
1829
1869
|
var vertexElement = void 0;
|
|
1830
1870
|
var meshId = mesh.instanceId;
|
|
1831
1871
|
var vertexBindingInfos = accessorBuffer.vertexBindingInfos;
|
|
1832
|
-
var elementFormat = GLTFUtil.getElementFormat(accessor.componentType,
|
|
1872
|
+
var elementFormat = GLTFUtil.getElementFormat(accessor.componentType, dataElementSize, accessor.normalized);
|
|
1833
1873
|
if (accessorBuffer.interleaved) {
|
|
1834
1874
|
var byteOffset = accessor.byteOffset || 0;
|
|
1835
1875
|
var stride = accessorBuffer.stride;
|
|
@@ -1841,6 +1881,7 @@ var MeshParser = /*#__PURE__*/ function(Parser1) {
|
|
|
1841
1881
|
vertexBuffer = new engineCore.Buffer(engine, engineCore.BufferBindFlag.VertexBuffer, vertices.byteLength, engineCore.BufferUsage.Static);
|
|
1842
1882
|
vertexBuffer.setData(vertices);
|
|
1843
1883
|
accessorBuffer.vertexBuffer = vertexBuffer;
|
|
1884
|
+
meshRestoreInfo.vertexBuffers.push(new BufferRestoreInfo(vertexBuffer, accessorBuffer.restoreInfo));
|
|
1844
1885
|
}
|
|
1845
1886
|
mesh.setVertexBufferBinding(vertexBuffer, stride, bufferBindIndex);
|
|
1846
1887
|
vertexBindingInfos[meshId] = bufferBindIndex++;
|
|
@@ -1851,6 +1892,7 @@ var MeshParser = /*#__PURE__*/ function(Parser1) {
|
|
|
1851
1892
|
vertexElement = new engineCore.VertexElement(attribute, 0, elementFormat, bufferBindIndex);
|
|
1852
1893
|
var vertexBuffer1 = new engineCore.Buffer(engine, engineCore.BufferBindFlag.VertexBuffer, vertices.byteLength, engineCore.BufferUsage.Static);
|
|
1853
1894
|
vertexBuffer1.setData(vertices);
|
|
1895
|
+
meshRestoreInfo.vertexBuffers.push(new BufferRestoreInfo(vertexBuffer1, accessorBuffer.restoreInfo));
|
|
1854
1896
|
mesh.setVertexBufferBinding(vertexBuffer1, accessorBuffer.stride, bufferBindIndex);
|
|
1855
1897
|
vertexBindingInfos[meshId] = bufferBindIndex++;
|
|
1856
1898
|
}
|
|
@@ -1862,7 +1904,7 @@ var MeshParser = /*#__PURE__*/ function(Parser1) {
|
|
|
1862
1904
|
min.copyFromArray(accessor.min);
|
|
1863
1905
|
max.copyFromArray(accessor.max);
|
|
1864
1906
|
} else {
|
|
1865
|
-
var position =
|
|
1907
|
+
var position = GLTFMeshParser._tempVector3;
|
|
1866
1908
|
min.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
|
|
1867
1909
|
max.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
|
|
1868
1910
|
var stride1 = vertices.length / attributeCount;
|
|
@@ -1874,9 +1916,9 @@ var MeshParser = /*#__PURE__*/ function(Parser1) {
|
|
|
1874
1916
|
}
|
|
1875
1917
|
}
|
|
1876
1918
|
if (accessor.normalized) {
|
|
1877
|
-
var
|
|
1878
|
-
min.scale(
|
|
1879
|
-
max.scale(
|
|
1919
|
+
var scaleFactor = GLTFUtil.getNormalizedComponentScale(accessor.componentType);
|
|
1920
|
+
min.scale(scaleFactor);
|
|
1921
|
+
max.scale(scaleFactor);
|
|
1880
1922
|
}
|
|
1881
1923
|
}
|
|
1882
1924
|
}
|
|
@@ -1884,175 +1926,68 @@ var MeshParser = /*#__PURE__*/ function(Parser1) {
|
|
|
1884
1926
|
// Indices
|
|
1885
1927
|
if (indices !== undefined) {
|
|
1886
1928
|
var indexAccessor = gltf.accessors[indices];
|
|
1887
|
-
var
|
|
1888
|
-
mesh.setIndices(
|
|
1929
|
+
var accessorBuffer1 = GLTFUtil.getAccessorBuffer(context, gltf.bufferViews, indexAccessor);
|
|
1930
|
+
mesh.setIndices(accessorBuffer1.data);
|
|
1889
1931
|
mesh.addSubMesh(0, indexAccessor.count, mode);
|
|
1932
|
+
meshRestoreInfo.indexBuffer = accessorBuffer1.restoreInfo;
|
|
1890
1933
|
} else {
|
|
1891
1934
|
mesh.addSubMesh(0, vertexCount, mode);
|
|
1892
1935
|
}
|
|
1893
1936
|
// BlendShapes
|
|
1894
|
-
targets &&
|
|
1937
|
+
targets && GLTFMeshParser._createBlendShape(mesh, meshRestoreInfo, gltfMesh, targets, getBlendShapeData);
|
|
1895
1938
|
mesh.uploadData(!keepMeshData);
|
|
1896
1939
|
return Promise.resolve(mesh);
|
|
1897
1940
|
};
|
|
1898
|
-
|
|
1941
|
+
/**
|
|
1942
|
+
* @internal
|
|
1943
|
+
*/ GLTFMeshParser._createBlendShape = function _createBlendShape(mesh, meshRestoreInfo, glTFMesh, glTFTargets, getBlendShapeData) {
|
|
1899
1944
|
var blendShapeNames = glTFMesh.extras ? glTFMesh.extras.targetNames : null;
|
|
1900
1945
|
for(var i = 0, n = glTFTargets.length; i < n; i++){
|
|
1901
1946
|
var name = blendShapeNames ? blendShapeNames[i] : "blendShape" + i;
|
|
1902
|
-
var
|
|
1903
|
-
var
|
|
1904
|
-
var
|
|
1905
|
-
var deltaPositions =
|
|
1906
|
-
var deltaNormals =
|
|
1907
|
-
var deltaTangents =
|
|
1947
|
+
var deltaPosBufferInfo = getBlendShapeData("POSITION", i);
|
|
1948
|
+
var deltaNorBufferInfo = getBlendShapeData("NORMAL", i);
|
|
1949
|
+
var deltaTanBufferInfo = getBlendShapeData("TANGENT", i);
|
|
1950
|
+
var deltaPositions = deltaPosBufferInfo.data ? GLTFUtil.floatBufferToVector3Array(deltaPosBufferInfo.data) : null;
|
|
1951
|
+
var deltaNormals = (deltaNorBufferInfo == null ? void 0 : deltaNorBufferInfo.data) ? GLTFUtil.floatBufferToVector3Array(deltaNorBufferInfo == null ? void 0 : deltaNorBufferInfo.data) : null;
|
|
1952
|
+
var deltaTangents = (deltaTanBufferInfo == null ? void 0 : deltaTanBufferInfo.data) ? GLTFUtil.floatBufferToVector3Array(deltaTanBufferInfo == null ? void 0 : deltaTanBufferInfo.data) : null;
|
|
1908
1953
|
var blendShape = new engineCore.BlendShape(name);
|
|
1909
1954
|
blendShape.addFrame(1.0, deltaPositions, deltaNormals, deltaTangents);
|
|
1910
1955
|
mesh.addBlendShape(blendShape);
|
|
1956
|
+
meshRestoreInfo.blendShapes.push(new BlendShapeRestoreInfo(blendShape, deltaPosBufferInfo.restoreInfo, deltaNorBufferInfo == null ? void 0 : deltaNorBufferInfo.restoreInfo, deltaTanBufferInfo == null ? void 0 : deltaTanBufferInfo.restoreInfo));
|
|
1911
1957
|
}
|
|
1912
1958
|
};
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
var attributes = gltfPrimitive.attributes, targets = gltfPrimitive.targets, indices = gltfPrimitive.indices, mode = gltfPrimitive.mode;
|
|
1917
|
-
var vertexCount;
|
|
1918
|
-
var accessors = gltf.accessors;
|
|
1919
|
-
var accessor = accessors[attributes["POSITION"]];
|
|
1920
|
-
var positionBuffer = getVertexBufferData("POSITION");
|
|
1921
|
-
var positions = GLTFUtil.floatBufferToVector3Array(positionBuffer);
|
|
1922
|
-
mesh.setPositions(positions);
|
|
1923
|
-
var bounds = mesh.bounds;
|
|
1924
|
-
vertexCount = accessor.count;
|
|
1925
|
-
if (accessor.min && accessor.max) {
|
|
1926
|
-
bounds.min.copyFromArray(accessor.min);
|
|
1927
|
-
bounds.max.copyFromArray(accessor.max);
|
|
1928
|
-
} else {
|
|
1929
|
-
var position = MeshParser._tempVector3;
|
|
1930
|
-
var min = bounds.min, max = bounds.max;
|
|
1931
|
-
min.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
|
|
1932
|
-
max.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
|
|
1933
|
-
var stride = positionBuffer.length / vertexCount;
|
|
1934
|
-
for(var j = 0; j < vertexCount; j++){
|
|
1935
|
-
var offset = j * stride;
|
|
1936
|
-
position.copyFromArray(positionBuffer, offset);
|
|
1937
|
-
engineMath.Vector3.min(min, position, min);
|
|
1938
|
-
engineMath.Vector3.max(max, position, max);
|
|
1939
|
-
}
|
|
1940
|
-
}
|
|
1941
|
-
for(var attributeSemantic in attributes){
|
|
1942
|
-
if (attributeSemantic === "POSITION") {
|
|
1943
|
-
continue;
|
|
1944
|
-
}
|
|
1945
|
-
var bufferData = getVertexBufferData(attributeSemantic);
|
|
1946
|
-
switch(attributeSemantic){
|
|
1947
|
-
case "NORMAL":
|
|
1948
|
-
var normals = GLTFUtil.floatBufferToVector3Array(bufferData);
|
|
1949
|
-
mesh.setNormals(normals);
|
|
1950
|
-
break;
|
|
1951
|
-
case "TEXCOORD_0":
|
|
1952
|
-
var texturecoords = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
1953
|
-
mesh.setUVs(texturecoords, 0);
|
|
1954
|
-
break;
|
|
1955
|
-
case "TEXCOORD_1":
|
|
1956
|
-
var texturecoords1 = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
1957
|
-
mesh.setUVs(texturecoords1, 1);
|
|
1958
|
-
break;
|
|
1959
|
-
case "TEXCOORD_2":
|
|
1960
|
-
var texturecoords2 = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
1961
|
-
mesh.setUVs(texturecoords2, 2);
|
|
1962
|
-
break;
|
|
1963
|
-
case "TEXCOORD_3":
|
|
1964
|
-
var texturecoords3 = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
1965
|
-
mesh.setUVs(texturecoords3, 3);
|
|
1966
|
-
break;
|
|
1967
|
-
case "TEXCOORD_4":
|
|
1968
|
-
var texturecoords4 = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
1969
|
-
mesh.setUVs(texturecoords4, 4);
|
|
1970
|
-
break;
|
|
1971
|
-
case "TEXCOORD_5":
|
|
1972
|
-
var texturecoords5 = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
1973
|
-
mesh.setUVs(texturecoords5, 5);
|
|
1974
|
-
break;
|
|
1975
|
-
case "TEXCOORD_6":
|
|
1976
|
-
var texturecoords6 = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
1977
|
-
mesh.setUVs(texturecoords6, 6);
|
|
1978
|
-
break;
|
|
1979
|
-
case "TEXCOORD_7":
|
|
1980
|
-
var texturecoords7 = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
1981
|
-
mesh.setUVs(texturecoords7, 7);
|
|
1982
|
-
break;
|
|
1983
|
-
case "COLOR_0":
|
|
1984
|
-
var colors = GLTFUtil.floatBufferToColorArray(bufferData, accessors[attributes["COLOR_0"]].type === AccessorType.VEC3);
|
|
1985
|
-
mesh.setColors(colors);
|
|
1986
|
-
break;
|
|
1987
|
-
case "TANGENT":
|
|
1988
|
-
var tangents = GLTFUtil.floatBufferToVector4Array(bufferData);
|
|
1989
|
-
mesh.setTangents(tangents);
|
|
1990
|
-
break;
|
|
1991
|
-
case "JOINTS_0":
|
|
1992
|
-
var joints = GLTFUtil.floatBufferToVector4Array(bufferData);
|
|
1993
|
-
mesh.setBoneIndices(joints);
|
|
1994
|
-
break;
|
|
1995
|
-
case "WEIGHTS_0":
|
|
1996
|
-
var weights = GLTFUtil.floatBufferToVector4Array(bufferData);
|
|
1997
|
-
mesh.setBoneWeights(weights);
|
|
1998
|
-
break;
|
|
1999
|
-
}
|
|
2000
|
-
}
|
|
2001
|
-
// Indices
|
|
2002
|
-
if (indices !== undefined) {
|
|
2003
|
-
var indexAccessor = gltf.accessors[indices];
|
|
2004
|
-
var indexData = getIndexBufferData();
|
|
2005
|
-
mesh.setIndices(indexData);
|
|
2006
|
-
mesh.addSubMesh(0, indexAccessor.count, mode);
|
|
2007
|
-
} else {
|
|
2008
|
-
mesh.addSubMesh(0, vertexCount, mode);
|
|
2009
|
-
}
|
|
2010
|
-
// BlendShapes
|
|
2011
|
-
targets && this._createBlendShape(mesh, gltfMesh, targets, getBlendShapeData);
|
|
2012
|
-
mesh.uploadData(!keepMeshData);
|
|
2013
|
-
return Promise.resolve(mesh);
|
|
2014
|
-
};
|
|
2015
|
-
return MeshParser;
|
|
2016
|
-
}(Parser);
|
|
2017
|
-
MeshParser._tempVector3 = new engineMath.Vector3();
|
|
1959
|
+
return GLTFMeshParser;
|
|
1960
|
+
}(GLTFParser);
|
|
1961
|
+
GLTFMeshParser._tempVector3 = new engineMath.Vector3();
|
|
2018
1962
|
|
|
2019
|
-
var
|
|
2020
|
-
_inherits(
|
|
2021
|
-
function
|
|
2022
|
-
return
|
|
1963
|
+
var GLTFSceneParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
1964
|
+
_inherits(GLTFSceneParser, GLTFParser1);
|
|
1965
|
+
function GLTFSceneParser() {
|
|
1966
|
+
return GLTFParser1.apply(this, arguments);
|
|
2023
1967
|
}
|
|
2024
|
-
var _proto =
|
|
1968
|
+
var _proto = GLTFSceneParser.prototype;
|
|
2025
1969
|
_proto.parse = function parse(context) {
|
|
2026
|
-
var glTFResource = context.glTFResource,
|
|
1970
|
+
var glTFResource = context.glTFResource, glTF = context.glTF;
|
|
2027
1971
|
var entities = glTFResource.entities;
|
|
2028
|
-
var nodes =
|
|
1972
|
+
var nodes = glTF.nodes, cameras = glTF.cameras;
|
|
2029
1973
|
if (!nodes) return;
|
|
2030
1974
|
var defaultSceneRootPromiseInfo = context.defaultSceneRootPromiseInfo;
|
|
2031
|
-
var promises = [];
|
|
2032
1975
|
for(var i = 0; i < nodes.length; i++){
|
|
2033
|
-
var
|
|
2034
|
-
var cameraID =
|
|
2035
|
-
var KHR_lights_punctual = extensions.KHR_lights_punctual;
|
|
1976
|
+
var glTFNode = nodes[i];
|
|
1977
|
+
var cameraID = glTFNode.camera, meshID = glTFNode.mesh, extensions = glTFNode.extensions;
|
|
2036
1978
|
var entity = entities[i];
|
|
2037
1979
|
if (cameraID !== undefined) {
|
|
2038
|
-
this._createCamera(glTFResource,
|
|
1980
|
+
this._createCamera(glTFResource, cameras[cameraID], entity);
|
|
2039
1981
|
}
|
|
2040
1982
|
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);
|
|
1983
|
+
this._createRenderer(context, glTFNode, entity);
|
|
2047
1984
|
}
|
|
1985
|
+
GLTFParser.executeExtensionsAdditiveAndParse(extensions, context, entity, glTFNode);
|
|
2048
1986
|
}
|
|
2049
1987
|
if (glTFResource.defaultSceneRoot) {
|
|
2050
1988
|
this._createAnimator(context);
|
|
2051
1989
|
}
|
|
2052
|
-
|
|
2053
|
-
engineCore.AssetPromise.all(promises).then(function() {
|
|
2054
|
-
return defaultSceneRootPromiseInfo.resolve(glTFResource.defaultSceneRoot);
|
|
2055
|
-
}).catch(defaultSceneRootPromiseInfo.reject);
|
|
1990
|
+
defaultSceneRootPromiseInfo.resolve(glTFResource.defaultSceneRoot);
|
|
2056
1991
|
return defaultSceneRootPromiseInfo.promise;
|
|
2057
1992
|
};
|
|
2058
1993
|
_proto._createCamera = function _createCamera(context, cameraSchema, entity) {
|
|
@@ -2088,8 +2023,16 @@ var SceneParser$1 = /*#__PURE__*/ function(Parser1) {
|
|
|
2088
2023
|
// @todo: use engine camera by default
|
|
2089
2024
|
camera.enabled = false;
|
|
2090
2025
|
};
|
|
2091
|
-
_proto._createRenderer = function _createRenderer(context,
|
|
2092
|
-
var
|
|
2026
|
+
_proto._createRenderer = function _createRenderer(context, glTFNode, entity) {
|
|
2027
|
+
var glTFResource = context.glTFResource, glTF = context.glTF;
|
|
2028
|
+
var glTFMeshes = glTF.meshes;
|
|
2029
|
+
var engine = glTFResource.engine, meshes = glTFResource.meshes, materials = glTFResource.materials, skins = glTFResource.skins;
|
|
2030
|
+
var meshID = glTFNode.mesh, skinID = glTFNode.skin;
|
|
2031
|
+
var glTFMesh = glTFMeshes[meshID];
|
|
2032
|
+
var glTFMeshPrimitives = glTFMesh.primitives;
|
|
2033
|
+
var blendShapeWeights = glTFNode.weights || glTFMesh.weights;
|
|
2034
|
+
for(var i = 0; i < glTFMeshPrimitives.length; i++){
|
|
2035
|
+
var gltfPrimitive = glTFMeshPrimitives[i];
|
|
2093
2036
|
var mesh = meshes[meshID][i];
|
|
2094
2037
|
var renderer = void 0;
|
|
2095
2038
|
if (skinID !== undefined || blendShapeWeights) {
|
|
@@ -2107,32 +2050,11 @@ var SceneParser$1 = /*#__PURE__*/ function(Parser1) {
|
|
|
2107
2050
|
renderer = entity.addComponent(engineCore.MeshRenderer);
|
|
2108
2051
|
renderer.mesh = mesh;
|
|
2109
2052
|
}
|
|
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);
|
|
2053
|
+
var materialIndex = gltfPrimitive.material;
|
|
2054
|
+
var material = (materials == null ? void 0 : materials[materialIndex]) || GLTFSceneParser._getDefaultMaterial(engine);
|
|
2055
|
+
renderer.setMaterial(material);
|
|
2056
|
+
GLTFParser.executeExtensionsAdditiveAndParse(gltfPrimitive.extensions, context, renderer, gltfPrimitive);
|
|
2057
|
+
}
|
|
2136
2058
|
};
|
|
2137
2059
|
_proto._createAnimator = function _createAnimator(context) {
|
|
2138
2060
|
if (!context.hasSkinned && !context.glTFResource.animations) {
|
|
@@ -2159,25 +2081,25 @@ var SceneParser$1 = /*#__PURE__*/ function(Parser1) {
|
|
|
2159
2081
|
}
|
|
2160
2082
|
}
|
|
2161
2083
|
};
|
|
2162
|
-
|
|
2163
|
-
if (!
|
|
2164
|
-
|
|
2084
|
+
GLTFSceneParser._getDefaultMaterial = function _getDefaultMaterial(engine) {
|
|
2085
|
+
if (!GLTFSceneParser._defaultMaterial) {
|
|
2086
|
+
GLTFSceneParser._defaultMaterial = new engineCore.BlinnPhongMaterial(engine);
|
|
2165
2087
|
}
|
|
2166
|
-
return
|
|
2088
|
+
return GLTFSceneParser._defaultMaterial;
|
|
2167
2089
|
};
|
|
2168
|
-
return
|
|
2169
|
-
}(
|
|
2090
|
+
return GLTFSceneParser;
|
|
2091
|
+
}(GLTFParser);
|
|
2170
2092
|
|
|
2171
|
-
var
|
|
2172
|
-
_inherits(
|
|
2173
|
-
function
|
|
2174
|
-
return
|
|
2093
|
+
var GLTFSkinParser = /*#__PURE__*/ function(GLTFParser) {
|
|
2094
|
+
_inherits(GLTFSkinParser, GLTFParser);
|
|
2095
|
+
function GLTFSkinParser() {
|
|
2096
|
+
return GLTFParser.apply(this, arguments);
|
|
2175
2097
|
}
|
|
2176
|
-
var _proto =
|
|
2098
|
+
var _proto = GLTFSkinParser.prototype;
|
|
2177
2099
|
_proto.parse = function parse(context) {
|
|
2178
|
-
var glTFResource = context.glTFResource,
|
|
2100
|
+
var glTFResource = context.glTFResource, glTF = context.glTF; context.buffers;
|
|
2179
2101
|
var entities = glTFResource.entities;
|
|
2180
|
-
var gltfSkins =
|
|
2102
|
+
var gltfSkins = glTF.skins;
|
|
2181
2103
|
if (!gltfSkins) return;
|
|
2182
2104
|
var count = gltfSkins.length;
|
|
2183
2105
|
var skins = new Array(count);
|
|
@@ -2187,8 +2109,8 @@ var SkinParser = /*#__PURE__*/ function(Parser) {
|
|
|
2187
2109
|
var skin = new engineCore.Skin(name);
|
|
2188
2110
|
skin.inverseBindMatrices.length = jointCount;
|
|
2189
2111
|
// parse IBM
|
|
2190
|
-
var accessor =
|
|
2191
|
-
var buffer = GLTFUtil.getAccessorBuffer(context,
|
|
2112
|
+
var accessor = glTF.accessors[inverseBindMatrices];
|
|
2113
|
+
var buffer = GLTFUtil.getAccessorBuffer(context, glTF.bufferViews, accessor).data;
|
|
2192
2114
|
for(var i1 = 0; i1 < jointCount; i1++){
|
|
2193
2115
|
var inverseBindMatrix = new engineMath.Matrix();
|
|
2194
2116
|
inverseBindMatrix.copyFromArray(buffer, i1 * 16);
|
|
@@ -2249,24 +2171,24 @@ var SkinParser = /*#__PURE__*/ function(Parser) {
|
|
|
2249
2171
|
rootNode = entity1;
|
|
2250
2172
|
}
|
|
2251
2173
|
};
|
|
2252
|
-
return
|
|
2253
|
-
}(
|
|
2174
|
+
return GLTFSkinParser;
|
|
2175
|
+
}(GLTFParser);
|
|
2254
2176
|
|
|
2255
|
-
var
|
|
2256
|
-
_inherits(
|
|
2257
|
-
function
|
|
2258
|
-
return
|
|
2177
|
+
var GLTFTextureParser = /*#__PURE__*/ function(GLTFParser) {
|
|
2178
|
+
_inherits(GLTFTextureParser, GLTFParser);
|
|
2179
|
+
function GLTFTextureParser() {
|
|
2180
|
+
return GLTFParser.apply(this, arguments);
|
|
2259
2181
|
}
|
|
2260
|
-
var _proto =
|
|
2182
|
+
var _proto = GLTFTextureParser.prototype;
|
|
2261
2183
|
_proto.parse = function parse(context) {
|
|
2262
2184
|
var _this = this;
|
|
2263
|
-
var glTFResource = context.glTFResource,
|
|
2185
|
+
var glTFResource = context.glTFResource, glTF = context.glTF, buffers = context.buffers;
|
|
2264
2186
|
var engine = glTFResource.engine, url = glTFResource.url;
|
|
2265
|
-
if (
|
|
2187
|
+
if (glTF.textures) {
|
|
2266
2188
|
var texturesPromiseInfo = context.texturesPromiseInfo;
|
|
2267
|
-
engineCore.AssetPromise.all(
|
|
2189
|
+
engineCore.AssetPromise.all(glTF.textures.map(function(param, index) {
|
|
2268
2190
|
var sampler = param.sampler, _param_source = param.source, source = _param_source === void 0 ? 0 : _param_source, textureName = param.name;
|
|
2269
|
-
var
|
|
2191
|
+
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
2192
|
if (uri) {
|
|
2271
2193
|
// TODO: support ktx extension https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_texture_basisu/README.md
|
|
2272
2194
|
var index1 = uri.lastIndexOf(".");
|
|
@@ -2280,21 +2202,24 @@ var TextureParser = /*#__PURE__*/ function(Parser) {
|
|
|
2280
2202
|
texture.name = textureName || imageName || "texture_" + index1;
|
|
2281
2203
|
}
|
|
2282
2204
|
if (sampler !== undefined) {
|
|
2283
|
-
_this._parseSampler(texture,
|
|
2205
|
+
_this._parseSampler(texture, glTF.samplers[sampler]);
|
|
2284
2206
|
}
|
|
2285
2207
|
return texture;
|
|
2286
2208
|
});
|
|
2287
2209
|
} else {
|
|
2288
|
-
var bufferView =
|
|
2289
|
-
var
|
|
2290
|
-
|
|
2210
|
+
var bufferView = glTF.bufferViews[bufferViewIndex];
|
|
2211
|
+
var buffer = buffers[bufferView.buffer];
|
|
2212
|
+
var imageBuffer = new Uint8Array(buffer, bufferView.byteOffset, bufferView.byteLength);
|
|
2213
|
+
return GLTFUtil.loadImageBuffer(imageBuffer, mimeType).then(function(image) {
|
|
2291
2214
|
var texture = new engineCore.Texture2D(engine, image.width, image.height);
|
|
2292
2215
|
texture.setImageSource(image);
|
|
2293
2216
|
texture.generateMipmaps();
|
|
2294
2217
|
texture.name = textureName || imageName || "texture_" + index;
|
|
2295
2218
|
if (sampler !== undefined) {
|
|
2296
|
-
_this._parseSampler(texture,
|
|
2219
|
+
_this._parseSampler(texture, glTF.samplers[sampler]);
|
|
2297
2220
|
}
|
|
2221
|
+
var bufferTextureRestoreInfo = new BufferTextureRestoreInfo(texture, bufferView, mimeType);
|
|
2222
|
+
context.contentRestorer.bufferTextures.push(bufferTextureRestoreInfo);
|
|
2298
2223
|
return texture;
|
|
2299
2224
|
});
|
|
2300
2225
|
}
|
|
@@ -2317,34 +2242,36 @@ var TextureParser = /*#__PURE__*/ function(Parser) {
|
|
|
2317
2242
|
}
|
|
2318
2243
|
}
|
|
2319
2244
|
if (wrapS) {
|
|
2320
|
-
texture.wrapModeU =
|
|
2245
|
+
texture.wrapModeU = GLTFTextureParser._wrapMap[wrapS];
|
|
2321
2246
|
}
|
|
2322
2247
|
if (wrapT) {
|
|
2323
|
-
texture.wrapModeV =
|
|
2248
|
+
texture.wrapModeV = GLTFTextureParser._wrapMap[wrapT];
|
|
2324
2249
|
}
|
|
2325
2250
|
};
|
|
2326
|
-
return
|
|
2327
|
-
}(
|
|
2251
|
+
return GLTFTextureParser;
|
|
2252
|
+
}(GLTFParser);
|
|
2328
2253
|
var _obj;
|
|
2329
|
-
|
|
2254
|
+
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);
|
|
2330
2255
|
|
|
2331
|
-
var
|
|
2332
|
-
_inherits(
|
|
2333
|
-
function
|
|
2334
|
-
return
|
|
2256
|
+
var GLTFValidator = /*#__PURE__*/ function(GLTFParser1) {
|
|
2257
|
+
_inherits(GLTFValidator, GLTFParser1);
|
|
2258
|
+
function GLTFValidator() {
|
|
2259
|
+
return GLTFParser1.apply(this, arguments);
|
|
2335
2260
|
}
|
|
2336
|
-
var _proto =
|
|
2261
|
+
var _proto = GLTFValidator.prototype;
|
|
2337
2262
|
_proto.parse = function parse(context) {
|
|
2338
|
-
var
|
|
2339
|
-
var
|
|
2340
|
-
if (!(
|
|
2341
|
-
throw "Only support
|
|
2263
|
+
var _context_glTF = context.glTF, version = _context_glTF.asset.version, extensionsUsed = _context_glTF.extensionsUsed, extensionsRequired = _context_glTF.extensionsRequired;
|
|
2264
|
+
var glTFVersion = Number(version);
|
|
2265
|
+
if (!(glTFVersion >= 2 && glTFVersion < 3)) {
|
|
2266
|
+
throw "Only support glTF 2.x.";
|
|
2342
2267
|
}
|
|
2268
|
+
var promises = [];
|
|
2343
2269
|
if (extensionsUsed) {
|
|
2344
2270
|
engineCore.Logger.info("extensionsUsed: ", extensionsUsed);
|
|
2345
2271
|
for(var i = 0; i < extensionsUsed.length; i++){
|
|
2346
|
-
|
|
2347
|
-
|
|
2272
|
+
var extensionUsed = extensionsUsed[i];
|
|
2273
|
+
if (!GLTFParser.hasExtensionParser(extensionUsed)) {
|
|
2274
|
+
engineCore.Logger.warn("Extension " + extensionUsed + " is not implemented, you can customize this extension in gltf.");
|
|
2348
2275
|
}
|
|
2349
2276
|
}
|
|
2350
2277
|
}
|
|
@@ -2352,66 +2279,66 @@ var Validator = /*#__PURE__*/ function(Parser1) {
|
|
|
2352
2279
|
engineCore.Logger.info("extensionsRequired: " + extensionsRequired);
|
|
2353
2280
|
for(var i1 = 0; i1 < extensionsRequired.length; i1++){
|
|
2354
2281
|
var extensionRequired = extensionsRequired[i1];
|
|
2355
|
-
if (!
|
|
2282
|
+
if (!GLTFParser.hasExtensionParser(extensionRequired)) {
|
|
2356
2283
|
engineCore.Logger.error("GLTF parser has not supported required extension " + extensionRequired + ".");
|
|
2357
2284
|
} else {
|
|
2358
|
-
|
|
2285
|
+
promises.push(GLTFParser.executeExtensionsInitialize(extensionRequired));
|
|
2359
2286
|
}
|
|
2360
2287
|
}
|
|
2361
2288
|
}
|
|
2289
|
+
return engineCore.AssetPromise.all(promises).then(null);
|
|
2362
2290
|
};
|
|
2363
|
-
return
|
|
2364
|
-
}(
|
|
2291
|
+
return GLTFValidator;
|
|
2292
|
+
}(GLTFParser);
|
|
2365
2293
|
|
|
2366
|
-
|
|
2367
|
-
|
|
2294
|
+
/**
|
|
2295
|
+
* GLTF pipeline.
|
|
2296
|
+
*/ var GLTFPipeline = /*#__PURE__*/ function() {
|
|
2297
|
+
function GLTFPipeline() {
|
|
2298
|
+
for(var _len = arguments.length, parsers = new Array(_len), _key = 0; _key < _len; _key++){
|
|
2299
|
+
parsers[_key] = arguments[_key];
|
|
2300
|
+
}
|
|
2368
2301
|
var _this = this;
|
|
2369
|
-
this.
|
|
2370
|
-
|
|
2371
|
-
_this.
|
|
2302
|
+
this._parsers = [];
|
|
2303
|
+
parsers.forEach(function(pipe, index) {
|
|
2304
|
+
_this._parsers[index] = new pipe();
|
|
2372
2305
|
});
|
|
2373
2306
|
}
|
|
2374
|
-
var _proto =
|
|
2375
|
-
|
|
2307
|
+
var _proto = GLTFPipeline.prototype;
|
|
2308
|
+
/**
|
|
2309
|
+
* @internal
|
|
2310
|
+
*/ _proto._parse = function _parse(context) {
|
|
2376
2311
|
var _this = this;
|
|
2377
2312
|
var glTFResource = context.glTFResource;
|
|
2378
|
-
var
|
|
2313
|
+
var lastParser;
|
|
2379
2314
|
return new engineCore.AssetPromise(function(resolve, reject) {
|
|
2380
|
-
_this.
|
|
2381
|
-
if (
|
|
2382
|
-
|
|
2315
|
+
_this._parsers.forEach(function(parser) {
|
|
2316
|
+
if (lastParser) {
|
|
2317
|
+
lastParser = lastParser.then(function() {
|
|
2383
2318
|
return parser.parse(context);
|
|
2384
2319
|
});
|
|
2385
|
-
if (
|
|
2386
|
-
context.chainPromises.push(
|
|
2320
|
+
if (lastParser.cancel) {
|
|
2321
|
+
context.chainPromises.push(lastParser);
|
|
2387
2322
|
}
|
|
2388
2323
|
} else {
|
|
2389
|
-
|
|
2324
|
+
lastParser = parser.parse(context);
|
|
2390
2325
|
}
|
|
2391
2326
|
});
|
|
2392
|
-
if (
|
|
2393
|
-
|
|
2327
|
+
if (lastParser) {
|
|
2328
|
+
lastParser.then(function() {
|
|
2394
2329
|
resolve(glTFResource);
|
|
2395
2330
|
}).catch(reject);
|
|
2396
2331
|
}
|
|
2397
2332
|
});
|
|
2398
2333
|
};
|
|
2399
|
-
return
|
|
2334
|
+
return GLTFPipeline;
|
|
2400
2335
|
}();
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
TextureParser,
|
|
2405
|
-
MaterialParser,
|
|
2406
|
-
MeshParser,
|
|
2407
|
-
EntityParser,
|
|
2408
|
-
SkinParser,
|
|
2409
|
-
AnimationParser,
|
|
2410
|
-
SceneParser$1
|
|
2411
|
-
]);
|
|
2336
|
+
/**
|
|
2337
|
+
* Default pipeline.
|
|
2338
|
+
*/ GLTFPipeline.defaultPipeline = new GLTFPipeline(GLTFBufferParser, GLTFValidator, GLTFTextureParser, GLTFMaterialParser, GLTFMeshParser, GLTFEntityParser, GLTFSkinParser, GLTFAnimationParser, GLTFSceneParser);
|
|
2412
2339
|
|
|
2413
2340
|
/**
|
|
2414
|
-
* Product after
|
|
2341
|
+
* Product after glTF parser, usually, `defaultSceneRoot` is only needed to use.
|
|
2415
2342
|
*/ var GLTFResource = /*#__PURE__*/ function(EngineObject) {
|
|
2416
2343
|
_inherits(GLTFResource, EngineObject);
|
|
2417
2344
|
function GLTFResource(engine, url) {
|
|
@@ -2423,11 +2350,8 @@ GLTFParser.defaultPipeline = new GLTFParser([
|
|
|
2423
2350
|
var _proto = GLTFResource.prototype;
|
|
2424
2351
|
/**
|
|
2425
2352
|
* @override
|
|
2426
|
-
*/ _proto.
|
|
2427
|
-
|
|
2428
|
-
return;
|
|
2429
|
-
}
|
|
2430
|
-
EngineObject.prototype.destroy.call(this);
|
|
2353
|
+
*/ _proto._onDestroy = function _onDestroy() {
|
|
2354
|
+
EngineObject.prototype._onDestroy.call(this);
|
|
2431
2355
|
this.defaultSceneRoot.destroy();
|
|
2432
2356
|
this.textures = null;
|
|
2433
2357
|
this.materials = null;
|
|
@@ -2438,7 +2362,7 @@ GLTFParser.defaultPipeline = new GLTFParser([
|
|
|
2438
2362
|
this.cameras = null;
|
|
2439
2363
|
this.lights = null;
|
|
2440
2364
|
this.sceneRoots = null;
|
|
2441
|
-
this.
|
|
2365
|
+
this.extensionsData = null;
|
|
2442
2366
|
};
|
|
2443
2367
|
return GLTFResource;
|
|
2444
2368
|
}(engineCore.EngineObject);
|
|
@@ -2449,15 +2373,19 @@ var GLTFLoader = /*#__PURE__*/ function(Loader) {
|
|
|
2449
2373
|
return Loader.apply(this, arguments);
|
|
2450
2374
|
}
|
|
2451
2375
|
var _proto = GLTFLoader.prototype;
|
|
2452
|
-
|
|
2453
|
-
|
|
2376
|
+
/**
|
|
2377
|
+
* @override
|
|
2378
|
+
*/ _proto.load = function load(item, resourceManager) {
|
|
2454
2379
|
var url = item.url;
|
|
2455
|
-
var
|
|
2380
|
+
var params = item.params;
|
|
2381
|
+
var context = new GLTFParserContext(url);
|
|
2456
2382
|
var glTFResource = new GLTFResource(resourceManager.engine, url);
|
|
2383
|
+
var restorer = new GLTFContentRestorer(glTFResource);
|
|
2457
2384
|
var masterPromiseInfo = context.masterPromiseInfo;
|
|
2385
|
+
context.contentRestorer = restorer;
|
|
2458
2386
|
context.glTFResource = glTFResource;
|
|
2459
|
-
var
|
|
2460
|
-
context.keepMeshData = (
|
|
2387
|
+
var _params_keepMeshData;
|
|
2388
|
+
context.keepMeshData = (_params_keepMeshData = params == null ? void 0 : params.keepMeshData) != null ? _params_keepMeshData : false;
|
|
2461
2389
|
masterPromiseInfo.onCancel(function() {
|
|
2462
2390
|
var chainPromises = context.chainPromises;
|
|
2463
2391
|
for(var _iterator = _createForOfIteratorHelperLoose(chainPromises), _step; !(_step = _iterator()).done;){
|
|
@@ -2465,7 +2393,10 @@ var GLTFLoader = /*#__PURE__*/ function(Loader) {
|
|
|
2465
2393
|
promise.cancel();
|
|
2466
2394
|
}
|
|
2467
2395
|
});
|
|
2468
|
-
|
|
2396
|
+
((params == null ? void 0 : params.pipeline) || GLTFPipeline.defaultPipeline)._parse(context).then(function(glTFResource) {
|
|
2397
|
+
resourceManager.addContentRestorer(restorer);
|
|
2398
|
+
masterPromiseInfo.resolve(glTFResource);
|
|
2399
|
+
}).catch(function(e) {
|
|
2469
2400
|
console.error(e);
|
|
2470
2401
|
masterPromiseInfo.reject("Error loading glTF model from " + url + " .");
|
|
2471
2402
|
});
|
|
@@ -2474,7 +2405,7 @@ var GLTFLoader = /*#__PURE__*/ function(Loader) {
|
|
|
2474
2405
|
return GLTFLoader;
|
|
2475
2406
|
}(engineCore.Loader);
|
|
2476
2407
|
GLTFLoader = __decorate([
|
|
2477
|
-
engineCore.resourceLoader(engineCore.AssetType.
|
|
2408
|
+
engineCore.resourceLoader(engineCore.AssetType.GLTF, [
|
|
2478
2409
|
"gltf",
|
|
2479
2410
|
"glb"
|
|
2480
2411
|
])
|
|
@@ -4222,28 +4153,57 @@ SpriteLoader = __decorate([
|
|
|
4222
4153
|
], false)
|
|
4223
4154
|
], SpriteLoader);
|
|
4224
4155
|
|
|
4156
|
+
/**
|
|
4157
|
+
* @internal
|
|
4158
|
+
*/ var Texture2DContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
|
|
4159
|
+
_inherits(Texture2DContentRestorer, ContentRestorer);
|
|
4160
|
+
function Texture2DContentRestorer(resource, url, requestConfig) {
|
|
4161
|
+
var _this;
|
|
4162
|
+
_this = ContentRestorer.call(this, resource) || this;
|
|
4163
|
+
_this.url = url;
|
|
4164
|
+
_this.requestConfig = requestConfig;
|
|
4165
|
+
return _this;
|
|
4166
|
+
}
|
|
4167
|
+
var _proto = Texture2DContentRestorer.prototype;
|
|
4168
|
+
/**
|
|
4169
|
+
* @override
|
|
4170
|
+
*/ _proto.restoreContent = function restoreContent() {
|
|
4171
|
+
var _this = this;
|
|
4172
|
+
return engineCore.request(this.url, this.requestConfig).then(function(image) {
|
|
4173
|
+
var resource = _this.resource;
|
|
4174
|
+
resource.setImageSource(image);
|
|
4175
|
+
resource.generateMipmaps();
|
|
4176
|
+
return resource;
|
|
4177
|
+
});
|
|
4178
|
+
};
|
|
4179
|
+
return Texture2DContentRestorer;
|
|
4180
|
+
}(engineCore.ContentRestorer);
|
|
4181
|
+
|
|
4225
4182
|
var Texture2DLoader = /*#__PURE__*/ function(Loader) {
|
|
4226
4183
|
_inherits(Texture2DLoader, Loader);
|
|
4227
4184
|
function Texture2DLoader() {
|
|
4228
4185
|
return Loader.apply(this, arguments);
|
|
4229
4186
|
}
|
|
4230
4187
|
var _proto = Texture2DLoader.prototype;
|
|
4231
|
-
|
|
4188
|
+
/**
|
|
4189
|
+
* @override
|
|
4190
|
+
*/ _proto.load = function load(item, resourceManager) {
|
|
4232
4191
|
var _this = this;
|
|
4233
4192
|
return new engineCore.AssetPromise(function(resolve, reject) {
|
|
4234
|
-
|
|
4193
|
+
var url = item.url;
|
|
4194
|
+
var requestConfig = _extends({}, item, {
|
|
4235
4195
|
type: "image"
|
|
4236
|
-
})
|
|
4237
|
-
|
|
4238
|
-
var params =
|
|
4239
|
-
var texture = new engineCore.Texture2D(resourceManager.engine, image.width, image.height, params.format, params.mipmap);
|
|
4240
|
-
/** @ts-ignore */ if (!texture._platformTexture) return;
|
|
4196
|
+
});
|
|
4197
|
+
_this.request(url, requestConfig).then(function(image) {
|
|
4198
|
+
var params = item.params;
|
|
4199
|
+
var texture = new engineCore.Texture2D(resourceManager.engine, image.width, image.height, params == null ? void 0 : params.format, params == null ? void 0 : params.mipmap);
|
|
4241
4200
|
texture.setImageSource(image);
|
|
4242
4201
|
texture.generateMipmaps();
|
|
4243
|
-
if (
|
|
4244
|
-
var
|
|
4245
|
-
texture.name =
|
|
4202
|
+
if (url.indexOf("data:") !== 0) {
|
|
4203
|
+
var index = url.lastIndexOf("/");
|
|
4204
|
+
texture.name = url.substring(index + 1);
|
|
4246
4205
|
}
|
|
4206
|
+
resourceManager.addContentRestorer(new Texture2DContentRestorer(texture, url, requestConfig));
|
|
4247
4207
|
resolve(texture);
|
|
4248
4208
|
}).catch(function(e) {
|
|
4249
4209
|
reject(e);
|
|
@@ -4261,33 +4221,71 @@ Texture2DLoader = __decorate([
|
|
|
4261
4221
|
])
|
|
4262
4222
|
], Texture2DLoader);
|
|
4263
4223
|
|
|
4224
|
+
/**
|
|
4225
|
+
* @internal
|
|
4226
|
+
*/ var TextureCubeContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
|
|
4227
|
+
_inherits(TextureCubeContentRestorer, ContentRestorer);
|
|
4228
|
+
function TextureCubeContentRestorer(resource, urls, requestConfig) {
|
|
4229
|
+
var _this;
|
|
4230
|
+
_this = ContentRestorer.call(this, resource) || this;
|
|
4231
|
+
_this.urls = urls;
|
|
4232
|
+
_this.requestConfig = requestConfig;
|
|
4233
|
+
return _this;
|
|
4234
|
+
}
|
|
4235
|
+
var _proto = TextureCubeContentRestorer.prototype;
|
|
4236
|
+
/**
|
|
4237
|
+
* @override
|
|
4238
|
+
*/ _proto.restoreContent = function restoreContent() {
|
|
4239
|
+
var _this = this;
|
|
4240
|
+
return new engineCore.AssetPromise(function(resolve, reject) {
|
|
4241
|
+
Promise.all(_this.urls.map(function(url) {
|
|
4242
|
+
return engineCore.request(url, _this.requestConfig);
|
|
4243
|
+
})).then(function(images) {
|
|
4244
|
+
var resource = _this.resource;
|
|
4245
|
+
for(var faceIndex = 0; faceIndex < 6; faceIndex++){
|
|
4246
|
+
resource.setImageSource(engineCore.TextureCubeFace.PositiveX + faceIndex, images[faceIndex], 0);
|
|
4247
|
+
}
|
|
4248
|
+
resource.generateMipmaps();
|
|
4249
|
+
resolve(resource);
|
|
4250
|
+
}).catch(function(e) {
|
|
4251
|
+
reject(e);
|
|
4252
|
+
});
|
|
4253
|
+
});
|
|
4254
|
+
};
|
|
4255
|
+
return TextureCubeContentRestorer;
|
|
4256
|
+
}(engineCore.ContentRestorer);
|
|
4257
|
+
|
|
4264
4258
|
var TextureCubeLoader = /*#__PURE__*/ function(Loader) {
|
|
4265
4259
|
_inherits(TextureCubeLoader, Loader);
|
|
4266
4260
|
function TextureCubeLoader() {
|
|
4267
4261
|
return Loader.apply(this, arguments);
|
|
4268
4262
|
}
|
|
4269
4263
|
var _proto = TextureCubeLoader.prototype;
|
|
4270
|
-
|
|
4264
|
+
/**
|
|
4265
|
+
* @override
|
|
4266
|
+
*/ _proto.load = function load(item, resourceManager) {
|
|
4271
4267
|
var _this = this;
|
|
4272
4268
|
return new engineCore.AssetPromise(function(resolve, reject) {
|
|
4273
|
-
|
|
4274
|
-
|
|
4275
|
-
|
|
4276
|
-
|
|
4269
|
+
var urls = item.urls;
|
|
4270
|
+
var requestConfig = _extends({}, item, {
|
|
4271
|
+
type: "image"
|
|
4272
|
+
});
|
|
4273
|
+
Promise.all(urls.map(function(url) {
|
|
4274
|
+
return _this.request(url, requestConfig);
|
|
4277
4275
|
})).then(function(images) {
|
|
4278
4276
|
var _images_ = images[0], width = _images_.width, height = _images_.height;
|
|
4279
4277
|
if (width !== height) {
|
|
4280
4278
|
console.error("The cube texture must have the same width and height");
|
|
4281
4279
|
return;
|
|
4282
4280
|
}
|
|
4283
|
-
var
|
|
4284
|
-
/** @ts-ignore */ if (!tex._platformTexture) return;
|
|
4281
|
+
var texture = new engineCore.TextureCube(resourceManager.engine, width);
|
|
4285
4282
|
for(var faceIndex = 0; faceIndex < 6; faceIndex++){
|
|
4286
|
-
|
|
4283
|
+
texture.setImageSource(engineCore.TextureCubeFace.PositiveX + faceIndex, images[faceIndex], 0);
|
|
4287
4284
|
}
|
|
4288
|
-
|
|
4289
|
-
|
|
4290
|
-
|
|
4285
|
+
texture.generateMipmaps();
|
|
4286
|
+
resourceManager.addContentRestorer(new TextureCubeContentRestorer(texture, urls, requestConfig));
|
|
4287
|
+
resolve(texture);
|
|
4288
|
+
}).catch(function(e) {
|
|
4291
4289
|
reject(e);
|
|
4292
4290
|
});
|
|
4293
4291
|
});
|
|
@@ -4300,6 +4298,30 @@ TextureCubeLoader = __decorate([
|
|
|
4300
4298
|
])
|
|
4301
4299
|
], TextureCubeLoader);
|
|
4302
4300
|
|
|
4301
|
+
var AnimationClipLoader = /*#__PURE__*/ function(Loader) {
|
|
4302
|
+
_inherits(AnimationClipLoader, Loader);
|
|
4303
|
+
function AnimationClipLoader() {
|
|
4304
|
+
return Loader.apply(this, arguments);
|
|
4305
|
+
}
|
|
4306
|
+
var _proto = AnimationClipLoader.prototype;
|
|
4307
|
+
_proto.load = function load(item, resourceManager) {
|
|
4308
|
+
var _this = this;
|
|
4309
|
+
return new engineCore.AssetPromise(function(resolve, reject) {
|
|
4310
|
+
_this.request(item.url, _extends({}, item, {
|
|
4311
|
+
type: "arraybuffer"
|
|
4312
|
+
})).then(function(data) {
|
|
4313
|
+
return decode(data, resourceManager.engine);
|
|
4314
|
+
}).catch(reject);
|
|
4315
|
+
});
|
|
4316
|
+
};
|
|
4317
|
+
return AnimationClipLoader;
|
|
4318
|
+
}(engineCore.Loader);
|
|
4319
|
+
AnimationClipLoader = __decorate([
|
|
4320
|
+
engineCore.resourceLoader(engineCore.AssetType.AnimationClip, [
|
|
4321
|
+
"ani"
|
|
4322
|
+
])
|
|
4323
|
+
], AnimationClipLoader);
|
|
4324
|
+
|
|
4303
4325
|
var SceneLoader = /*#__PURE__*/ function(Loader) {
|
|
4304
4326
|
_inherits(SceneLoader, Loader);
|
|
4305
4327
|
function SceneLoader() {
|
|
@@ -4400,11 +4422,409 @@ ReflectionParser.registerCustomParseComponent("TextRenderer", /*#__PURE__*/ _asy
|
|
|
4400
4422
|
});
|
|
4401
4423
|
}));
|
|
4402
4424
|
|
|
4425
|
+
var _KHR_draco_mesh_compression;
|
|
4426
|
+
var KHR_draco_mesh_compression = (_KHR_draco_mesh_compression = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
4427
|
+
_inherits(KHR_draco_mesh_compression1, GLTFExtensionParser);
|
|
4428
|
+
function KHR_draco_mesh_compression1() {
|
|
4429
|
+
return GLTFExtensionParser.apply(this, arguments);
|
|
4430
|
+
}
|
|
4431
|
+
var _proto = KHR_draco_mesh_compression1.prototype;
|
|
4432
|
+
/**
|
|
4433
|
+
* @override
|
|
4434
|
+
*/ _proto.initialize = function initialize() {
|
|
4435
|
+
if (!KHR_draco_mesh_compression._decoder) {
|
|
4436
|
+
KHR_draco_mesh_compression._decoder = new engineDraco.DRACODecoder();
|
|
4437
|
+
}
|
|
4438
|
+
};
|
|
4439
|
+
/**
|
|
4440
|
+
* @override
|
|
4441
|
+
*/ _proto.createAndParse = function createAndParse(context, schema, glTFPrimitive, glTFMesh) {
|
|
4442
|
+
var _this = this;
|
|
4443
|
+
var glTF = context.glTF, buffers = context.buffers, engine = context.glTFResource.engine;
|
|
4444
|
+
var bufferViews = glTF.bufferViews, accessors = glTF.accessors;
|
|
4445
|
+
var bufferViewIndex = schema.bufferView, gltfAttributeMap = schema.attributes;
|
|
4446
|
+
var attributeMap = {};
|
|
4447
|
+
var attributeTypeMap = {};
|
|
4448
|
+
for(var attributeName in gltfAttributeMap){
|
|
4449
|
+
attributeMap[attributeName] = gltfAttributeMap[attributeName];
|
|
4450
|
+
}
|
|
4451
|
+
for(var attributeName1 in glTFPrimitive.attributes){
|
|
4452
|
+
if (gltfAttributeMap[attributeName1] !== undefined) {
|
|
4453
|
+
var accessorDef = accessors[glTFPrimitive.attributes[attributeName1]];
|
|
4454
|
+
attributeTypeMap[attributeName1] = GLTFUtil.getComponentType(accessorDef.componentType).name;
|
|
4455
|
+
}
|
|
4456
|
+
}
|
|
4457
|
+
var indexAccessor = accessors[glTFPrimitive.indices];
|
|
4458
|
+
var indexType = GLTFUtil.getComponentType(indexAccessor.componentType).name;
|
|
4459
|
+
var taskConfig = {
|
|
4460
|
+
attributeIDs: attributeMap,
|
|
4461
|
+
attributeTypes: attributeTypeMap,
|
|
4462
|
+
useUniqueIDs: true,
|
|
4463
|
+
indexType: indexType
|
|
4464
|
+
};
|
|
4465
|
+
var buffer = GLTFUtil.getBufferViewData(bufferViews[bufferViewIndex], buffers);
|
|
4466
|
+
return KHR_draco_mesh_compression._decoder.decode(buffer, taskConfig).then(function(decodedGeometry) {
|
|
4467
|
+
var mesh = new engineCore.ModelMesh(engine, glTFMesh.name);
|
|
4468
|
+
return _this._parseMeshFromGLTFPrimitiveDraco(mesh, glTFMesh, glTFPrimitive, glTF, function(attributeSemantic) {
|
|
4469
|
+
for(var j = 0; j < decodedGeometry.attributes.length; j++){
|
|
4470
|
+
if (decodedGeometry.attributes[j].name === attributeSemantic) {
|
|
4471
|
+
return decodedGeometry.attributes[j].array;
|
|
4472
|
+
}
|
|
4473
|
+
}
|
|
4474
|
+
return null;
|
|
4475
|
+
}, function(attributeSemantic, shapeIndex) {
|
|
4476
|
+
throw "BlendShape animation is not supported when using draco.";
|
|
4477
|
+
}, function() {
|
|
4478
|
+
return decodedGeometry.index.array;
|
|
4479
|
+
}, context.keepMeshData);
|
|
4480
|
+
});
|
|
4481
|
+
};
|
|
4482
|
+
_proto._parseMeshFromGLTFPrimitiveDraco = function _parseMeshFromGLTFPrimitiveDraco(mesh, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
|
|
4483
|
+
var attributes = gltfPrimitive.attributes, targets = gltfPrimitive.targets, indices = gltfPrimitive.indices, mode = gltfPrimitive.mode;
|
|
4484
|
+
var vertexCount;
|
|
4485
|
+
var accessors = gltf.accessors;
|
|
4486
|
+
var accessor = accessors[attributes["POSITION"]];
|
|
4487
|
+
var positionBuffer = getVertexBufferData("POSITION");
|
|
4488
|
+
var positions = GLTFUtil.floatBufferToVector3Array(positionBuffer);
|
|
4489
|
+
mesh.setPositions(positions);
|
|
4490
|
+
var bounds = mesh.bounds;
|
|
4491
|
+
vertexCount = accessor.count;
|
|
4492
|
+
if (accessor.min && accessor.max) {
|
|
4493
|
+
bounds.min.copyFromArray(accessor.min);
|
|
4494
|
+
bounds.max.copyFromArray(accessor.max);
|
|
4495
|
+
} else {
|
|
4496
|
+
var position = KHR_draco_mesh_compression._tempVector3;
|
|
4497
|
+
var min = bounds.min, max = bounds.max;
|
|
4498
|
+
min.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
|
|
4499
|
+
max.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
|
|
4500
|
+
var stride = positionBuffer.length / vertexCount;
|
|
4501
|
+
for(var j = 0; j < vertexCount; j++){
|
|
4502
|
+
var offset = j * stride;
|
|
4503
|
+
position.copyFromArray(positionBuffer, offset);
|
|
4504
|
+
engineMath.Vector3.min(min, position, min);
|
|
4505
|
+
engineMath.Vector3.max(max, position, max);
|
|
4506
|
+
}
|
|
4507
|
+
}
|
|
4508
|
+
for(var attributeSemantic in attributes){
|
|
4509
|
+
if (attributeSemantic === "POSITION") {
|
|
4510
|
+
continue;
|
|
4511
|
+
}
|
|
4512
|
+
var bufferData = getVertexBufferData(attributeSemantic);
|
|
4513
|
+
switch(attributeSemantic){
|
|
4514
|
+
case "NORMAL":
|
|
4515
|
+
var normals = GLTFUtil.floatBufferToVector3Array(bufferData);
|
|
4516
|
+
mesh.setNormals(normals);
|
|
4517
|
+
break;
|
|
4518
|
+
case "TEXCOORD_0":
|
|
4519
|
+
var texturecoords = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
4520
|
+
mesh.setUVs(texturecoords, 0);
|
|
4521
|
+
break;
|
|
4522
|
+
case "TEXCOORD_1":
|
|
4523
|
+
var texturecoords1 = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
4524
|
+
mesh.setUVs(texturecoords1, 1);
|
|
4525
|
+
break;
|
|
4526
|
+
case "TEXCOORD_2":
|
|
4527
|
+
var texturecoords2 = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
4528
|
+
mesh.setUVs(texturecoords2, 2);
|
|
4529
|
+
break;
|
|
4530
|
+
case "TEXCOORD_3":
|
|
4531
|
+
var texturecoords3 = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
4532
|
+
mesh.setUVs(texturecoords3, 3);
|
|
4533
|
+
break;
|
|
4534
|
+
case "TEXCOORD_4":
|
|
4535
|
+
var texturecoords4 = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
4536
|
+
mesh.setUVs(texturecoords4, 4);
|
|
4537
|
+
break;
|
|
4538
|
+
case "TEXCOORD_5":
|
|
4539
|
+
var texturecoords5 = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
4540
|
+
mesh.setUVs(texturecoords5, 5);
|
|
4541
|
+
break;
|
|
4542
|
+
case "TEXCOORD_6":
|
|
4543
|
+
var texturecoords6 = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
4544
|
+
mesh.setUVs(texturecoords6, 6);
|
|
4545
|
+
break;
|
|
4546
|
+
case "TEXCOORD_7":
|
|
4547
|
+
var texturecoords7 = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
4548
|
+
mesh.setUVs(texturecoords7, 7);
|
|
4549
|
+
break;
|
|
4550
|
+
case "COLOR_0":
|
|
4551
|
+
var colors = GLTFUtil.floatBufferToColorArray(bufferData, accessors[attributes["COLOR_0"]].type === AccessorType.VEC3);
|
|
4552
|
+
mesh.setColors(colors);
|
|
4553
|
+
break;
|
|
4554
|
+
case "TANGENT":
|
|
4555
|
+
var tangents = GLTFUtil.floatBufferToVector4Array(bufferData);
|
|
4556
|
+
mesh.setTangents(tangents);
|
|
4557
|
+
break;
|
|
4558
|
+
case "JOINTS_0":
|
|
4559
|
+
var joints = GLTFUtil.floatBufferToVector4Array(bufferData);
|
|
4560
|
+
mesh.setBoneIndices(joints);
|
|
4561
|
+
break;
|
|
4562
|
+
case "WEIGHTS_0":
|
|
4563
|
+
var weights = GLTFUtil.floatBufferToVector4Array(bufferData);
|
|
4564
|
+
mesh.setBoneWeights(weights);
|
|
4565
|
+
break;
|
|
4566
|
+
}
|
|
4567
|
+
}
|
|
4568
|
+
// Indices
|
|
4569
|
+
if (indices !== undefined) {
|
|
4570
|
+
var indexAccessor = gltf.accessors[indices];
|
|
4571
|
+
var indexData = getIndexBufferData();
|
|
4572
|
+
mesh.setIndices(indexData);
|
|
4573
|
+
mesh.addSubMesh(0, indexAccessor.count, mode);
|
|
4574
|
+
} else {
|
|
4575
|
+
mesh.addSubMesh(0, vertexCount, mode);
|
|
4576
|
+
}
|
|
4577
|
+
// BlendShapes
|
|
4578
|
+
targets && GLTFMeshParser._createBlendShape(mesh, null, gltfMesh, targets, getBlendShapeData);
|
|
4579
|
+
mesh.uploadData(!keepMeshData);
|
|
4580
|
+
return Promise.resolve(mesh);
|
|
4581
|
+
};
|
|
4582
|
+
return KHR_draco_mesh_compression1;
|
|
4583
|
+
}(GLTFExtensionParser), _KHR_draco_mesh_compression._tempVector3 = new engineMath.Vector3(), _KHR_draco_mesh_compression);
|
|
4584
|
+
KHR_draco_mesh_compression = __decorate([
|
|
4585
|
+
registerGLTFExtension("KHR_draco_mesh_compression", exports.GLTFExtensionMode.CreateAndParse)
|
|
4586
|
+
], KHR_draco_mesh_compression);
|
|
4587
|
+
|
|
4588
|
+
var KHR_lights_punctual = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
4589
|
+
_inherits(KHR_lights_punctual, GLTFExtensionParser);
|
|
4590
|
+
function KHR_lights_punctual() {
|
|
4591
|
+
return GLTFExtensionParser.apply(this, arguments);
|
|
4592
|
+
}
|
|
4593
|
+
var _proto = KHR_lights_punctual.prototype;
|
|
4594
|
+
/**
|
|
4595
|
+
* @override
|
|
4596
|
+
*/ _proto.additiveParse = function additiveParse(context, entity, extensionSchema) {
|
|
4597
|
+
var lightsSchema = context.glTF.extensions.KHR_lights_punctual.lights;
|
|
4598
|
+
var lightSchema = lightsSchema[extensionSchema.light];
|
|
4599
|
+
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;
|
|
4600
|
+
var glTFResource = context.glTFResource;
|
|
4601
|
+
var light;
|
|
4602
|
+
if (type === "directional") {
|
|
4603
|
+
light = entity.addComponent(engineCore.DirectLight);
|
|
4604
|
+
} else if (type === "point") {
|
|
4605
|
+
light = entity.addComponent(engineCore.PointLight);
|
|
4606
|
+
} else if (type === "spot") {
|
|
4607
|
+
light = entity.addComponent(engineCore.SpotLight);
|
|
4608
|
+
}
|
|
4609
|
+
if (color) {
|
|
4610
|
+
light.color.set(color[0], color[1], color[2], 1);
|
|
4611
|
+
}
|
|
4612
|
+
light.intensity = intensity;
|
|
4613
|
+
if (range && !_instanceof(light, engineCore.DirectLight)) {
|
|
4614
|
+
light.distance = range;
|
|
4615
|
+
}
|
|
4616
|
+
if (spot && _instanceof(light, engineCore.SpotLight)) {
|
|
4617
|
+
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;
|
|
4618
|
+
light.angle = innerConeAngle;
|
|
4619
|
+
light.penumbra = outerConeAngle - innerConeAngle;
|
|
4620
|
+
}
|
|
4621
|
+
if (!glTFResource.lights) glTFResource.lights = [];
|
|
4622
|
+
glTFResource.lights.push(light);
|
|
4623
|
+
};
|
|
4624
|
+
return KHR_lights_punctual;
|
|
4625
|
+
}(GLTFExtensionParser);
|
|
4626
|
+
KHR_lights_punctual = __decorate([
|
|
4627
|
+
registerGLTFExtension("KHR_lights_punctual", exports.GLTFExtensionMode.AdditiveParse)
|
|
4628
|
+
], KHR_lights_punctual);
|
|
4629
|
+
|
|
4630
|
+
var KHR_materials_clearcoat = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
4631
|
+
_inherits(KHR_materials_clearcoat, GLTFExtensionParser);
|
|
4632
|
+
function KHR_materials_clearcoat() {
|
|
4633
|
+
return GLTFExtensionParser.apply(this, arguments);
|
|
4634
|
+
}
|
|
4635
|
+
var _proto = KHR_materials_clearcoat.prototype;
|
|
4636
|
+
/**
|
|
4637
|
+
* @override
|
|
4638
|
+
*/ _proto.additiveParse = function additiveParse(context, material, schema) {
|
|
4639
|
+
var textures = context.glTFResource.textures;
|
|
4640
|
+
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;
|
|
4641
|
+
material.clearCoat = clearcoatFactor;
|
|
4642
|
+
material.clearCoatRoughness = clearcoatRoughnessFactor;
|
|
4643
|
+
if (clearcoatTexture) {
|
|
4644
|
+
material.clearCoatTexture = textures[clearcoatTexture.index];
|
|
4645
|
+
GLTFMaterialParser._checkOtherTextureTransform(clearcoatTexture, "Clear coat");
|
|
4646
|
+
}
|
|
4647
|
+
if (clearcoatRoughnessTexture) {
|
|
4648
|
+
material.clearCoatRoughnessTexture = textures[clearcoatRoughnessTexture.index];
|
|
4649
|
+
GLTFMaterialParser._checkOtherTextureTransform(clearcoatRoughnessTexture, "Clear coat roughness");
|
|
4650
|
+
}
|
|
4651
|
+
if (clearcoatNormalTexture) {
|
|
4652
|
+
material.clearCoatNormalTexture = textures[clearcoatNormalTexture.index];
|
|
4653
|
+
GLTFMaterialParser._checkOtherTextureTransform(clearcoatNormalTexture, "Clear coat normal");
|
|
4654
|
+
}
|
|
4655
|
+
};
|
|
4656
|
+
return KHR_materials_clearcoat;
|
|
4657
|
+
}(GLTFExtensionParser);
|
|
4658
|
+
KHR_materials_clearcoat = __decorate([
|
|
4659
|
+
registerGLTFExtension("KHR_materials_clearcoat", exports.GLTFExtensionMode.AdditiveParse)
|
|
4660
|
+
], KHR_materials_clearcoat);
|
|
4661
|
+
|
|
4662
|
+
var KHR_materials_pbrSpecularGlossiness = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
4663
|
+
_inherits(KHR_materials_pbrSpecularGlossiness, GLTFExtensionParser);
|
|
4664
|
+
function KHR_materials_pbrSpecularGlossiness() {
|
|
4665
|
+
return GLTFExtensionParser.apply(this, arguments);
|
|
4666
|
+
}
|
|
4667
|
+
var _proto = KHR_materials_pbrSpecularGlossiness.prototype;
|
|
4668
|
+
/**
|
|
4669
|
+
* @override
|
|
4670
|
+
*/ _proto.createAndParse = function createAndParse(context, schema, ownerSchema) {
|
|
4671
|
+
var _context_glTFResource = context.glTFResource, engine = _context_glTFResource.engine, textures = _context_glTFResource.textures;
|
|
4672
|
+
var material = new engineCore.PBRSpecularMaterial(engine);
|
|
4673
|
+
var diffuseFactor = schema.diffuseFactor, diffuseTexture = schema.diffuseTexture, specularFactor = schema.specularFactor, glossinessFactor = schema.glossinessFactor, specularGlossinessTexture = schema.specularGlossinessTexture;
|
|
4674
|
+
if (diffuseFactor) {
|
|
4675
|
+
material.baseColor = new engineMath.Color(engineMath.Color.linearToGammaSpace(diffuseFactor[0]), engineMath.Color.linearToGammaSpace(diffuseFactor[1]), engineMath.Color.linearToGammaSpace(diffuseFactor[2]), diffuseFactor[3]);
|
|
4676
|
+
}
|
|
4677
|
+
if (diffuseTexture) {
|
|
4678
|
+
material.baseTexture = textures[diffuseTexture.index];
|
|
4679
|
+
GLTFParser.executeExtensionsAdditiveAndParse(diffuseTexture.extensions, context, material, diffuseTexture);
|
|
4680
|
+
}
|
|
4681
|
+
if (specularFactor) {
|
|
4682
|
+
material.specularColor = new engineMath.Color(engineMath.Color.linearToGammaSpace(specularFactor[0]), engineMath.Color.linearToGammaSpace(specularFactor[1]), engineMath.Color.linearToGammaSpace(specularFactor[2]));
|
|
4683
|
+
}
|
|
4684
|
+
if (glossinessFactor !== undefined) {
|
|
4685
|
+
material.glossiness = glossinessFactor;
|
|
4686
|
+
}
|
|
4687
|
+
if (specularGlossinessTexture) {
|
|
4688
|
+
material.specularGlossinessTexture = textures[specularGlossinessTexture.index];
|
|
4689
|
+
GLTFMaterialParser._checkOtherTextureTransform(specularGlossinessTexture, "Specular glossiness");
|
|
4690
|
+
}
|
|
4691
|
+
material.name = ownerSchema.name;
|
|
4692
|
+
GLTFMaterialParser._parseStandardProperty(context, material, ownerSchema);
|
|
4693
|
+
return material;
|
|
4694
|
+
};
|
|
4695
|
+
return KHR_materials_pbrSpecularGlossiness;
|
|
4696
|
+
}(GLTFExtensionParser);
|
|
4697
|
+
KHR_materials_pbrSpecularGlossiness = __decorate([
|
|
4698
|
+
registerGLTFExtension("KHR_materials_pbrSpecularGlossiness", exports.GLTFExtensionMode.CreateAndParse)
|
|
4699
|
+
], KHR_materials_pbrSpecularGlossiness);
|
|
4700
|
+
|
|
4701
|
+
var KHR_materials_unlit = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
4702
|
+
_inherits(KHR_materials_unlit, GLTFExtensionParser);
|
|
4703
|
+
function KHR_materials_unlit() {
|
|
4704
|
+
return GLTFExtensionParser.apply(this, arguments);
|
|
4705
|
+
}
|
|
4706
|
+
var _proto = KHR_materials_unlit.prototype;
|
|
4707
|
+
/**
|
|
4708
|
+
* @override
|
|
4709
|
+
*/ _proto.createAndParse = function createAndParse(context, _, ownerSchema) {
|
|
4710
|
+
var engine = context.glTFResource.engine;
|
|
4711
|
+
var material = new engineCore.UnlitMaterial(engine);
|
|
4712
|
+
material.name = ownerSchema.name;
|
|
4713
|
+
GLTFMaterialParser._parseStandardProperty(context, material, ownerSchema);
|
|
4714
|
+
return material;
|
|
4715
|
+
};
|
|
4716
|
+
return KHR_materials_unlit;
|
|
4717
|
+
}(GLTFExtensionParser);
|
|
4718
|
+
KHR_materials_unlit = __decorate([
|
|
4719
|
+
registerGLTFExtension("KHR_materials_unlit", exports.GLTFExtensionMode.CreateAndParse)
|
|
4720
|
+
], KHR_materials_unlit);
|
|
4721
|
+
|
|
4722
|
+
var KHR_mesh_quantization = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
4723
|
+
_inherits(KHR_mesh_quantization, GLTFExtensionParser);
|
|
4724
|
+
function KHR_mesh_quantization() {
|
|
4725
|
+
return GLTFExtensionParser.apply(this, arguments);
|
|
4726
|
+
}
|
|
4727
|
+
return KHR_mesh_quantization;
|
|
4728
|
+
}(GLTFExtensionParser);
|
|
4729
|
+
KHR_mesh_quantization = __decorate([
|
|
4730
|
+
registerGLTFExtension("KHR_mesh_quantization", exports.GLTFExtensionMode.AdditiveParse)
|
|
4731
|
+
], KHR_mesh_quantization);
|
|
4732
|
+
|
|
4733
|
+
var KHR_texture_transform = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
4734
|
+
_inherits(KHR_texture_transform, GLTFExtensionParser);
|
|
4735
|
+
function KHR_texture_transform() {
|
|
4736
|
+
return GLTFExtensionParser.apply(this, arguments);
|
|
4737
|
+
}
|
|
4738
|
+
var _proto = KHR_texture_transform.prototype;
|
|
4739
|
+
/**
|
|
4740
|
+
* @override
|
|
4741
|
+
*/ _proto.additiveParse = function additiveParse(context, material, schema) {
|
|
4742
|
+
var offset = schema.offset, rotation = schema.rotation, scale = schema.scale, texCoord = schema.texCoord;
|
|
4743
|
+
if (offset) {
|
|
4744
|
+
material.tilingOffset.z = offset[0];
|
|
4745
|
+
material.tilingOffset.w = offset[1];
|
|
4746
|
+
}
|
|
4747
|
+
if (scale) {
|
|
4748
|
+
material.tilingOffset.x = scale[0];
|
|
4749
|
+
material.tilingOffset.y = scale[1];
|
|
4750
|
+
}
|
|
4751
|
+
if (rotation) {
|
|
4752
|
+
engineCore.Logger.warn("rotation in KHR_texture_transform is not supported now");
|
|
4753
|
+
}
|
|
4754
|
+
if (texCoord) {
|
|
4755
|
+
engineCore.Logger.warn("texCoord in KHR_texture_transform is not supported now");
|
|
4756
|
+
}
|
|
4757
|
+
};
|
|
4758
|
+
return KHR_texture_transform;
|
|
4759
|
+
}(GLTFExtensionParser);
|
|
4760
|
+
KHR_texture_transform = __decorate([
|
|
4761
|
+
registerGLTFExtension("KHR_texture_transform", exports.GLTFExtensionMode.AdditiveParse)
|
|
4762
|
+
], KHR_texture_transform);
|
|
4763
|
+
|
|
4764
|
+
var GalaceanMaterialsRemap = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
4765
|
+
_inherits(GalaceanMaterialsRemap, GLTFExtensionParser);
|
|
4766
|
+
function GalaceanMaterialsRemap() {
|
|
4767
|
+
return GLTFExtensionParser.apply(this, arguments);
|
|
4768
|
+
}
|
|
4769
|
+
var _proto = GalaceanMaterialsRemap.prototype;
|
|
4770
|
+
/**
|
|
4771
|
+
* @override
|
|
4772
|
+
*/ _proto.createAndParse = function createAndParse(context, schema) {
|
|
4773
|
+
var engine = context.glTFResource.engine;
|
|
4774
|
+
// @ts-ignore
|
|
4775
|
+
return engine.resourceManager.getResourceByRef(schema);
|
|
4776
|
+
};
|
|
4777
|
+
return GalaceanMaterialsRemap;
|
|
4778
|
+
}(GLTFExtensionParser);
|
|
4779
|
+
GalaceanMaterialsRemap = __decorate([
|
|
4780
|
+
registerGLTFExtension("OASIS_materials_remap", exports.GLTFExtensionMode.CreateAndParse)
|
|
4781
|
+
], GalaceanMaterialsRemap);
|
|
4782
|
+
|
|
4783
|
+
var OASIS_animation_event = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
4784
|
+
_inherits(OASIS_animation_event, GLTFExtensionParser);
|
|
4785
|
+
function OASIS_animation_event() {
|
|
4786
|
+
return GLTFExtensionParser.apply(this, arguments);
|
|
4787
|
+
}
|
|
4788
|
+
var _proto = OASIS_animation_event.prototype;
|
|
4789
|
+
/**
|
|
4790
|
+
* @override
|
|
4791
|
+
*/ _proto.additiveParse = function additiveParse(context, animationClip, schema) {
|
|
4792
|
+
context.glTFResource.engine;
|
|
4793
|
+
var events = schema.events;
|
|
4794
|
+
events.map(function(eventData) {
|
|
4795
|
+
var event = new engineCore.AnimationEvent();
|
|
4796
|
+
event.functionName = eventData.functionName;
|
|
4797
|
+
event.time = eventData.time;
|
|
4798
|
+
event.parameter = eventData.parameter;
|
|
4799
|
+
animationClip.addEvent(event);
|
|
4800
|
+
});
|
|
4801
|
+
};
|
|
4802
|
+
return OASIS_animation_event;
|
|
4803
|
+
}(GLTFExtensionParser);
|
|
4804
|
+
OASIS_animation_event = __decorate([
|
|
4805
|
+
registerGLTFExtension("OASIS_animation_event", exports.GLTFExtensionMode.AdditiveParse)
|
|
4806
|
+
], OASIS_animation_event);
|
|
4807
|
+
|
|
4403
4808
|
exports.ComponentMap = ComponentMap;
|
|
4809
|
+
exports.GLTFAnimationParser = GLTFAnimationParser;
|
|
4810
|
+
exports.GLTFBufferParser = GLTFBufferParser;
|
|
4811
|
+
exports.GLTFEntityParser = GLTFEntityParser;
|
|
4812
|
+
exports.GLTFExtensionParser = GLTFExtensionParser;
|
|
4813
|
+
exports.GLTFMaterialParser = GLTFMaterialParser;
|
|
4814
|
+
exports.GLTFMeshParser = GLTFMeshParser;
|
|
4815
|
+
exports.GLTFParser = GLTFParser;
|
|
4816
|
+
exports.GLTFParserContext = GLTFParserContext;
|
|
4817
|
+
exports.GLTFPipeline = GLTFPipeline;
|
|
4404
4818
|
exports.GLTFResource = GLTFResource;
|
|
4819
|
+
exports.GLTFSceneParser = GLTFSceneParser;
|
|
4820
|
+
exports.GLTFSkinParser = GLTFSkinParser;
|
|
4821
|
+
exports.GLTFTextureParser = GLTFTextureParser;
|
|
4822
|
+
exports.GLTFUtil = GLTFUtil;
|
|
4823
|
+
exports.GLTFValidator = GLTFValidator;
|
|
4405
4824
|
exports.PrefabParser = PrefabParser;
|
|
4406
4825
|
exports.ReflectionParser = ReflectionParser;
|
|
4407
4826
|
exports.SceneParser = SceneParser;
|
|
4408
4827
|
exports.decode = decode;
|
|
4409
4828
|
exports.parseSingleKTX = parseSingleKTX;
|
|
4829
|
+
exports.registerGLTFExtension = registerGLTFExtension;
|
|
4410
4830
|
//# sourceMappingURL=main.js.map
|