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