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