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