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