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