@galacean/engine-loader 1.0.0-alpha.6 → 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 +1278 -1637
- package/dist/main.js.map +1 -1
- package/dist/miniprogram.js +1299 -1658
- package/dist/module.js +1280 -1624
- package/dist/module.js.map +1 -1
- package/package.json +5 -5
- package/types/AnimationClipLoader.d.ts +0 -1
- package/types/GLTFLoader.d.ts +4 -7
- package/types/gltf/GLTFResource.d.ts +11 -7
- package/types/gltf/GLTFUtil.d.ts +8 -8
- package/types/gltf/extensions/KHR_materials_variants.d.ts +1 -6
- package/types/gltf/extensions/index.d.ts +2 -5
- 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/GLTFSchema.d.ts +0 -816
- package/types/gltf/extensions/GLTFExtensionParser.d.ts +0 -52
- package/types/gltf/extensions/GLTFExtensionSchema.d.ts +0 -149
- package/types/gltf/extensions/OASIS_animation_event.d.ts +0 -1
- package/types/gltf/extensions/OASIS_materials_remap.d.ts +0 -1
- 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/GLTFParserContext.d.ts +0 -48
- 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,56 +1,39 @@
|
|
|
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
|
-
function
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
for (var key in source) {
|
|
12
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
13
|
-
target[key] = source[key];
|
|
6
|
+
function _extends() {
|
|
7
|
+
_extends = Object.assign || function assign(target) {
|
|
8
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
9
|
+
var source = arguments[i];
|
|
10
|
+
for (var key in source) if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
|
|
14
11
|
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return target;
|
|
19
|
-
};
|
|
20
12
|
|
|
21
|
-
|
|
22
|
-
}
|
|
13
|
+
return target;
|
|
14
|
+
};
|
|
23
15
|
|
|
24
|
-
|
|
25
|
-
return extends_.apply(this, arguments);
|
|
16
|
+
return _extends.apply(this, arguments);
|
|
26
17
|
}
|
|
27
18
|
|
|
28
|
-
function
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return o;
|
|
32
|
-
};
|
|
19
|
+
function _set_prototype_of(o, p) {
|
|
20
|
+
_set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
|
21
|
+
o.__proto__ = p;
|
|
33
22
|
|
|
34
|
-
|
|
35
|
-
}
|
|
23
|
+
return o;
|
|
24
|
+
};
|
|
36
25
|
|
|
37
|
-
|
|
38
|
-
return setPrototypeOf(o, p);
|
|
26
|
+
return _set_prototype_of(o, p);
|
|
39
27
|
}
|
|
40
28
|
|
|
41
29
|
function _inherits(subClass, superClass) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
47
|
-
constructor: {
|
|
48
|
-
value: subClass,
|
|
49
|
-
writable: true,
|
|
50
|
-
configurable: true
|
|
30
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
31
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
51
32
|
}
|
|
52
|
-
|
|
53
|
-
|
|
33
|
+
|
|
34
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } });
|
|
35
|
+
|
|
36
|
+
if (superClass) _set_prototype_of(subClass, superClass);
|
|
54
37
|
}
|
|
55
38
|
|
|
56
39
|
/******************************************************************************
|
|
@@ -103,10 +86,10 @@ function __generator(thisArg, body) {
|
|
|
103
86
|
}
|
|
104
87
|
}
|
|
105
88
|
|
|
106
|
-
var AnimatorControllerLoader = /*#__PURE__*/ function(
|
|
107
|
-
_inherits(AnimatorControllerLoader,
|
|
89
|
+
var AnimatorControllerLoader = /*#__PURE__*/ function(Loader) {
|
|
90
|
+
_inherits(AnimatorControllerLoader, Loader);
|
|
108
91
|
function AnimatorControllerLoader() {
|
|
109
|
-
return
|
|
92
|
+
return Loader.apply(this, arguments);
|
|
110
93
|
}
|
|
111
94
|
var _proto = AnimatorControllerLoader.prototype;
|
|
112
95
|
_proto.load = function load(item, resourceManager) {
|
|
@@ -127,16 +110,13 @@ var AnimatorControllerLoader = /*#__PURE__*/ function(Loader1) {
|
|
|
127
110
|
var states = stateMachineData.states;
|
|
128
111
|
var stateMachine = layer.stateMachine = new AnimatorStateMachine();
|
|
129
112
|
states.forEach(function(stateData, stateIndex) {
|
|
130
|
-
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;
|
|
131
114
|
var state = stateMachine.addState(name);
|
|
132
115
|
isDefaultState && (stateMachine.defaultState = state);
|
|
133
116
|
state.speed = speed;
|
|
134
117
|
state.wrapMode = wrapMode;
|
|
135
118
|
state.clipStartTime = clipStartNormalizedTime;
|
|
136
119
|
state.clipEndTime = clipEndNormalizedTime;
|
|
137
|
-
scripts == null ? void 0 : scripts.forEach(function(script) {
|
|
138
|
-
state.addStateMachineScript(Loader.getClass(script));
|
|
139
|
-
});
|
|
140
120
|
if (clipData) {
|
|
141
121
|
promises.push(new Promise(function(resolve) {
|
|
142
122
|
//@ts-ignore
|
|
@@ -269,39 +249,34 @@ EnvLoader = __decorate([
|
|
|
269
249
|
], EnvLoader);
|
|
270
250
|
|
|
271
251
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
resolve(value);
|
|
282
|
-
} else {
|
|
283
|
-
Promise.resolve(value).then(_next, _throw);
|
|
284
|
-
}
|
|
252
|
+
try {
|
|
253
|
+
var info = gen[key](arg);
|
|
254
|
+
var value = info.value;
|
|
255
|
+
} catch (error) {
|
|
256
|
+
reject(error);
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
if (info.done) resolve(value);
|
|
260
|
+
else Promise.resolve(value).then(_next, _throw);
|
|
285
261
|
}
|
|
262
|
+
function _async_to_generator(fn) {
|
|
263
|
+
return function() {
|
|
264
|
+
var self = this, args = arguments;
|
|
286
265
|
|
|
287
|
-
function
|
|
288
|
-
|
|
289
|
-
var self = this,
|
|
290
|
-
args = arguments;
|
|
291
|
-
return new Promise(function (resolve, reject) {
|
|
292
|
-
var gen = fn.apply(self, args);
|
|
266
|
+
return new Promise(function(resolve, reject) {
|
|
267
|
+
var gen = fn.apply(self, args);
|
|
293
268
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
269
|
+
function _next(value) {
|
|
270
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
271
|
+
}
|
|
297
272
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
273
|
+
function _throw(err) {
|
|
274
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
275
|
+
}
|
|
301
276
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
277
|
+
_next(undefined);
|
|
278
|
+
});
|
|
279
|
+
};
|
|
305
280
|
}
|
|
306
281
|
|
|
307
282
|
var FontLoader = /*#__PURE__*/ function(Loader) {
|
|
@@ -334,7 +309,7 @@ var FontLoader = /*#__PURE__*/ function(Loader) {
|
|
|
334
309
|
});
|
|
335
310
|
};
|
|
336
311
|
_proto._registerFont = function _registerFont(fontName, fontUrl) {
|
|
337
|
-
return
|
|
312
|
+
return _async_to_generator(function() {
|
|
338
313
|
var fontFace;
|
|
339
314
|
return __generator(this, function(_state) {
|
|
340
315
|
switch(_state.label){
|
|
@@ -362,192 +337,52 @@ FontLoader = __decorate([
|
|
|
362
337
|
], false)
|
|
363
338
|
], FontLoader);
|
|
364
339
|
|
|
365
|
-
function _arrayLikeToArray(arr, len) {
|
|
366
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
367
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
368
|
-
return arr2;
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
function _unsupportedIterableToArray(o, minLen) {
|
|
372
|
-
if (!o) return;
|
|
373
|
-
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
374
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
375
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
376
|
-
if (n === "Map" || n === "Set") return Array.from(n);
|
|
377
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
|
|
378
|
-
return _arrayLikeToArray(o, minLen);
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
function _createForOfIteratorHelperLoose(o, allowArrayLike) {
|
|
382
|
-
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
383
|
-
if (it) return (it = it.call(o)).next.bind(it);
|
|
384
|
-
// Fallback for engines without symbol support
|
|
385
|
-
if (
|
|
386
|
-
Array.isArray(o) ||
|
|
387
|
-
(it = _unsupportedIterableToArray(o)) ||
|
|
388
|
-
(allowArrayLike && o && typeof o.length === "number")
|
|
389
|
-
) {
|
|
390
|
-
if (it) o = it;
|
|
391
|
-
var i = 0;
|
|
392
|
-
return function () {
|
|
393
|
-
if (i >= o.length) return { done: true };
|
|
394
|
-
return { done: false, value: o[i++] };
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
throw new TypeError("Invalid attempt to iterate non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
398
|
-
}
|
|
399
|
-
|
|
400
340
|
/**
|
|
401
341
|
* @internal
|
|
402
|
-
*/ var
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
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);
|
|
412
361
|
}
|
|
413
|
-
var _proto =
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
return request(bufferRequestInfo.url, bufferRequestInfo.config);
|
|
421
|
-
})).then(function(buffers) {
|
|
422
|
-
// Buffer parse
|
|
423
|
-
if (_this.isGLB) {
|
|
424
|
-
var glbBufferSlice = _this.glbBufferSlices;
|
|
425
|
-
var bigBuffer = buffers[0];
|
|
426
|
-
var bufferCount = glbBufferSlice.length;
|
|
427
|
-
buffers.length = bufferCount;
|
|
428
|
-
for(var i = 0; i < bufferCount; i++){
|
|
429
|
-
var slice = glbBufferSlice[i];
|
|
430
|
-
buffers[i] = bigBuffer.slice(slice.x, slice.x + slice.y);
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
// Restore texture
|
|
434
|
-
AssetPromise.all(_this.bufferTextures.map(function(textureRestoreInfo) {
|
|
435
|
-
var bufferView = textureRestoreInfo.bufferView;
|
|
436
|
-
var buffer = buffers[bufferView.buffer];
|
|
437
|
-
var _bufferView_byteOffset;
|
|
438
|
-
var bufferData = new Uint8Array(buffer, (_bufferView_byteOffset = bufferView.byteOffset) != null ? _bufferView_byteOffset : 0, bufferView.byteLength);
|
|
439
|
-
return GLTFUtil.loadImageBuffer(bufferData, textureRestoreInfo.mimeType).then(function(image) {
|
|
440
|
-
textureRestoreInfo.texture.setImageSource(image);
|
|
441
|
-
textureRestoreInfo.texture.generateMipmaps();
|
|
442
|
-
});
|
|
443
|
-
})).then(function() {
|
|
444
|
-
// Restore mesh
|
|
445
|
-
for(var _iterator = _createForOfIteratorHelperLoose(_this.meshes), _step; !(_step = _iterator()).done;){
|
|
446
|
-
var meshInfo = _step.value;
|
|
447
|
-
var mesh = meshInfo.mesh;
|
|
448
|
-
for(var _iterator1 = _createForOfIteratorHelperLoose(meshInfo.vertexBuffers), _step1; !(_step1 = _iterator1()).done;){
|
|
449
|
-
var bufferRestoreInfo = _step1.value;
|
|
450
|
-
var vertexData = _this._getBufferData(buffers, bufferRestoreInfo.data);
|
|
451
|
-
bufferRestoreInfo.buffer.setData(vertexData);
|
|
452
|
-
}
|
|
453
|
-
if (meshInfo.indexBuffer) {
|
|
454
|
-
var indexData = _this._getBufferData(buffers, meshInfo.indexBuffer);
|
|
455
|
-
mesh.setIndices(indexData);
|
|
456
|
-
}
|
|
457
|
-
for(var _iterator2 = _createForOfIteratorHelperLoose(meshInfo.blendShapes), _step2; !(_step2 = _iterator2()).done;){
|
|
458
|
-
var restoreInfo = _step2.value;
|
|
459
|
-
var frame = restoreInfo.blendShape.frames[0];
|
|
460
|
-
var positionData = _this._getBufferData(buffers, restoreInfo.position);
|
|
461
|
-
frame.deltaPositions = GLTFUtil.floatBufferToVector3Array(positionData);
|
|
462
|
-
if (restoreInfo.normal) {
|
|
463
|
-
var normalData = _this._getBufferData(buffers, restoreInfo.normal);
|
|
464
|
-
frame.deltaNormals = GLTFUtil.floatBufferToVector3Array(normalData);
|
|
465
|
-
}
|
|
466
|
-
if (restoreInfo.tangent) {
|
|
467
|
-
var tangentData = _this._getBufferData(buffers, restoreInfo.tangent);
|
|
468
|
-
frame.deltaTangents = GLTFUtil.floatBufferToVector3Array(tangentData);
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
mesh.uploadData(true);
|
|
472
|
-
}
|
|
473
|
-
resolve(_this.resource);
|
|
474
|
-
}).catch(reject);
|
|
475
|
-
}).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;
|
|
476
369
|
});
|
|
370
|
+
promiseInfo.promise = promise;
|
|
371
|
+
return promise;
|
|
477
372
|
};
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
var buffer = buffers[main.bufferIndex];
|
|
481
|
-
var data = new main.TypedArray(buffer, main.byteOffset, main.length);
|
|
482
|
-
var sparseCount = restoreInfo.sparseCount;
|
|
483
|
-
if (sparseCount) {
|
|
484
|
-
var sparseIndex = restoreInfo.sparseIndices;
|
|
485
|
-
var sparseIndexBuffer = buffers[sparseIndex.bufferIndex];
|
|
486
|
-
var sparseIndexData = new sparseIndex.TypedArray(sparseIndexBuffer, sparseIndex.byteOffset, sparseIndex.length);
|
|
487
|
-
var sparseValue = restoreInfo.sparseValues;
|
|
488
|
-
var sparseValueBuffer = buffers[sparseValue.bufferIndex];
|
|
489
|
-
var sparseValueData = new sparseValue.TypedArray(sparseValueBuffer, sparseValue.byteOffset, sparseValue.length);
|
|
490
|
-
var typeSize = restoreInfo.typeSize;
|
|
491
|
-
for(var i = 0; i < sparseCount; i++){
|
|
492
|
-
var replaceIndex = sparseIndexData[i];
|
|
493
|
-
for(var j = 0; j < typeSize; j++){
|
|
494
|
-
data[replaceIndex * typeSize + j] = sparseValueData[i * typeSize + j];
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
return data;
|
|
499
|
-
};
|
|
500
|
-
return GLTFContentRestorer;
|
|
501
|
-
}(ContentRestorer);
|
|
502
|
-
/**
|
|
503
|
-
* @internal
|
|
504
|
-
*/ var BufferRequestInfo = function BufferRequestInfo(url, config) {
|
|
505
|
-
this.url = url;
|
|
506
|
-
this.config = config;
|
|
507
|
-
};
|
|
508
|
-
/**
|
|
509
|
-
* @internal
|
|
510
|
-
*/ var BufferTextureRestoreInfo = function BufferTextureRestoreInfo(texture, bufferView, mimeType) {
|
|
511
|
-
this.texture = texture;
|
|
512
|
-
this.bufferView = bufferView;
|
|
513
|
-
this.mimeType = mimeType;
|
|
514
|
-
};
|
|
515
|
-
/**
|
|
516
|
-
* @internal
|
|
517
|
-
*/ var ModelMeshRestoreInfo = function ModelMeshRestoreInfo() {
|
|
518
|
-
this.vertexBuffers = [];
|
|
519
|
-
this.blendShapes = [];
|
|
520
|
-
};
|
|
373
|
+
return ParserContext;
|
|
374
|
+
}();
|
|
521
375
|
/**
|
|
522
376
|
* @internal
|
|
523
|
-
*/ var
|
|
524
|
-
this.buffer = buffer;
|
|
377
|
+
*/ var BufferInfo = function BufferInfo(data, interleaved, stride) {
|
|
525
378
|
this.data = data;
|
|
379
|
+
this.interleaved = interleaved;
|
|
380
|
+
this.stride = stride;
|
|
381
|
+
this.vertexBindingInfos = {};
|
|
526
382
|
};
|
|
527
383
|
/**
|
|
528
384
|
* @internal
|
|
529
|
-
*/ var
|
|
530
|
-
this.main = main;
|
|
531
|
-
this.typeSize = typeSize;
|
|
532
|
-
this.sparseCount = sparseCount;
|
|
533
|
-
this.sparseIndices = sparseIndices;
|
|
534
|
-
this.sparseValues = sparseValues;
|
|
535
|
-
};
|
|
536
|
-
/**
|
|
537
|
-
* @internal
|
|
538
|
-
*/ var RestoreDataAccessor = function RestoreDataAccessor(bufferIndex, TypedArray, byteOffset, length) {
|
|
539
|
-
this.bufferIndex = bufferIndex;
|
|
540
|
-
this.TypedArray = TypedArray;
|
|
541
|
-
this.byteOffset = byteOffset;
|
|
542
|
-
this.length = length;
|
|
543
|
-
};
|
|
544
|
-
/**
|
|
545
|
-
* @internal
|
|
546
|
-
*/ var BlendShapeRestoreInfo = function BlendShapeRestoreInfo(blendShape, position, normal, tangent) {
|
|
547
|
-
this.blendShape = blendShape;
|
|
548
|
-
this.position = position;
|
|
549
|
-
this.normal = normal;
|
|
550
|
-
this.tangent = tangent;
|
|
385
|
+
*/ var PromiseInfo = function PromiseInfo() {
|
|
551
386
|
};
|
|
552
387
|
|
|
553
388
|
/**
|
|
@@ -697,54 +532,6 @@ var TextureWrapMode;
|
|
|
697
532
|
*/ "REPEAT"] = 10497] = "REPEAT";
|
|
698
533
|
})(TextureWrapMode || (TextureWrapMode = {}));
|
|
699
534
|
|
|
700
|
-
/**
|
|
701
|
-
* @internal
|
|
702
|
-
*/ var GLTFParserContext = /*#__PURE__*/ function() {
|
|
703
|
-
function GLTFParserContext(url) {
|
|
704
|
-
this.hasSkinned = false;
|
|
705
|
-
this.chainPromises = [];
|
|
706
|
-
this.accessorBufferCache = {};
|
|
707
|
-
this.texturesPromiseInfo = new PromiseInfo();
|
|
708
|
-
this.materialsPromiseInfo = new PromiseInfo();
|
|
709
|
-
this.meshesPromiseInfo = new PromiseInfo();
|
|
710
|
-
this.animationClipsPromiseInfo = new PromiseInfo();
|
|
711
|
-
this.defaultSceneRootPromiseInfo = new PromiseInfo();
|
|
712
|
-
this.masterPromiseInfo = new PromiseInfo();
|
|
713
|
-
this.promiseMap = {};
|
|
714
|
-
var promiseMap = this.promiseMap;
|
|
715
|
-
promiseMap["" + url + "?q=textures"] = this._initPromiseInfo(this.texturesPromiseInfo);
|
|
716
|
-
promiseMap["" + url + "?q=materials"] = this._initPromiseInfo(this.materialsPromiseInfo);
|
|
717
|
-
promiseMap["" + url + "?q=meshes"] = this._initPromiseInfo(this.meshesPromiseInfo);
|
|
718
|
-
promiseMap["" + url + "?q=animations"] = this._initPromiseInfo(this.animationClipsPromiseInfo);
|
|
719
|
-
promiseMap["" + url + "?q=defaultSceneRoot"] = this._initPromiseInfo(this.defaultSceneRootPromiseInfo);
|
|
720
|
-
promiseMap["" + url] = this._initPromiseInfo(this.masterPromiseInfo);
|
|
721
|
-
}
|
|
722
|
-
var _proto = GLTFParserContext.prototype;
|
|
723
|
-
_proto._initPromiseInfo = function _initPromiseInfo(promiseInfo) {
|
|
724
|
-
var promise = new AssetPromise(function(resolve, reject, setProgress, onCancel) {
|
|
725
|
-
promiseInfo.resolve = resolve;
|
|
726
|
-
promiseInfo.reject = reject;
|
|
727
|
-
promiseInfo.setProgress = setProgress;
|
|
728
|
-
promiseInfo.onCancel = onCancel;
|
|
729
|
-
});
|
|
730
|
-
promiseInfo.promise = promise;
|
|
731
|
-
return promise;
|
|
732
|
-
};
|
|
733
|
-
return GLTFParserContext;
|
|
734
|
-
}();
|
|
735
|
-
/**
|
|
736
|
-
* @internal
|
|
737
|
-
*/ var BufferInfo = function BufferInfo(data, interleaved, stride) {
|
|
738
|
-
this.data = data;
|
|
739
|
-
this.interleaved = interleaved;
|
|
740
|
-
this.stride = stride;
|
|
741
|
-
this.vertexBindingInfos = {};
|
|
742
|
-
};
|
|
743
|
-
/**
|
|
744
|
-
* @internal
|
|
745
|
-
*/ var PromiseInfo = function PromiseInfo() {
|
|
746
|
-
};
|
|
747
|
-
|
|
748
535
|
/**
|
|
749
536
|
* @internal
|
|
750
537
|
*/ var GLTFUtil = /*#__PURE__*/ function() {
|
|
@@ -853,18 +640,18 @@ var TextureWrapMode;
|
|
|
853
640
|
throw new Error("Galacean.GLTFLoader: Unsupported normalized accessor component type.");
|
|
854
641
|
}
|
|
855
642
|
};
|
|
856
|
-
GLTFUtil.getAccessorBuffer = function getAccessorBuffer(context,
|
|
643
|
+
GLTFUtil.getAccessorBuffer = function getAccessorBuffer(context, gltf, accessor) {
|
|
857
644
|
var buffers = context.buffers;
|
|
645
|
+
var bufferViews = gltf.bufferViews;
|
|
858
646
|
var componentType = accessor.componentType;
|
|
859
647
|
var bufferView = bufferViews[accessor.bufferView];
|
|
860
|
-
var
|
|
861
|
-
var buffer = buffers[bufferIndex];
|
|
648
|
+
var buffer = buffers[bufferView.buffer];
|
|
862
649
|
var bufferByteOffset = bufferView.byteOffset || 0;
|
|
863
650
|
var byteOffset = accessor.byteOffset || 0;
|
|
864
651
|
var TypedArray = GLTFUtil.getComponentType(componentType);
|
|
865
|
-
var
|
|
652
|
+
var dataElmentSize = GLTFUtil.getAccessorTypeSize(accessor.type);
|
|
866
653
|
var dataElementBytes = TypedArray.BYTES_PER_ELEMENT;
|
|
867
|
-
var elementStride =
|
|
654
|
+
var elementStride = dataElmentSize * dataElementBytes;
|
|
868
655
|
var accessorCount = accessor.count;
|
|
869
656
|
var bufferStride = bufferView.byteStride;
|
|
870
657
|
var bufferInfo;
|
|
@@ -879,25 +666,24 @@ var TextureWrapMode;
|
|
|
879
666
|
var count = accessorCount * (bufferStride / dataElementBytes);
|
|
880
667
|
var data = new TypedArray(buffer, offset, count);
|
|
881
668
|
accessorBufferCache[bufferCacheKey] = bufferInfo = new BufferInfo(data, true, bufferStride);
|
|
882
|
-
bufferInfo.restoreInfo = new BufferDataRestoreInfo(new RestoreDataAccessor(bufferIndex, TypedArray, offset, count));
|
|
883
669
|
}
|
|
884
670
|
} else {
|
|
885
671
|
var offset1 = bufferByteOffset + byteOffset;
|
|
886
|
-
var count1 = accessorCount *
|
|
672
|
+
var count1 = accessorCount * dataElmentSize;
|
|
887
673
|
var data1 = new TypedArray(buffer, offset1, count1);
|
|
888
674
|
bufferInfo = new BufferInfo(data1, false, elementStride);
|
|
889
|
-
bufferInfo.restoreInfo = new BufferDataRestoreInfo(new RestoreDataAccessor(bufferIndex, TypedArray, offset1, count1));
|
|
890
675
|
}
|
|
891
676
|
if (accessor.sparse) {
|
|
892
|
-
GLTFUtil.processingSparseData(
|
|
677
|
+
var data2 = GLTFUtil.processingSparseData(gltf, accessor, buffers, bufferInfo.data);
|
|
678
|
+
bufferInfo = new BufferInfo(data2, false, bufferInfo.stride);
|
|
893
679
|
}
|
|
894
680
|
return bufferInfo;
|
|
895
681
|
};
|
|
896
682
|
/**
|
|
897
683
|
* @deprecated
|
|
898
684
|
* Get accessor data.
|
|
899
|
-
*/ GLTFUtil.getAccessorData = function getAccessorData(
|
|
900
|
-
var bufferViews =
|
|
685
|
+
*/ GLTFUtil.getAccessorData = function getAccessorData(gltf, accessor, buffers) {
|
|
686
|
+
var bufferViews = gltf.bufferViews;
|
|
901
687
|
var bufferView = bufferViews[accessor.bufferView];
|
|
902
688
|
var arrayBuffer = buffers[bufferView.buffer];
|
|
903
689
|
var accessorByteOffset = accessor.hasOwnProperty("byteOffset") ? accessor.byteOffset : 0;
|
|
@@ -947,46 +733,38 @@ var TextureWrapMode;
|
|
|
947
733
|
return typedArray;
|
|
948
734
|
};
|
|
949
735
|
GLTFUtil.getBufferViewData = function getBufferViewData(bufferView, buffers) {
|
|
950
|
-
var _bufferView_byteOffset = bufferView.byteOffset, byteOffset = _bufferView_byteOffset === void 0 ? 0 : _bufferView_byteOffset;
|
|
951
|
-
var arrayBuffer = buffers[
|
|
952
|
-
return arrayBuffer.slice(byteOffset, byteOffset +
|
|
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);
|
|
953
739
|
};
|
|
954
740
|
/**
|
|
955
741
|
* Get accessor data.
|
|
956
|
-
*/ GLTFUtil.processingSparseData = function processingSparseData(
|
|
957
|
-
var
|
|
742
|
+
*/ GLTFUtil.processingSparseData = function processingSparseData(gltf, accessor, buffers, originData) {
|
|
743
|
+
var bufferViews = gltf.bufferViews;
|
|
958
744
|
var accessorTypeSize = GLTFUtil.getAccessorTypeSize(accessor.type);
|
|
959
745
|
var TypedArray = GLTFUtil.getComponentType(accessor.componentType);
|
|
960
|
-
var data =
|
|
746
|
+
var data = originData.slice();
|
|
961
747
|
var _accessor_sparse = accessor.sparse, count = _accessor_sparse.count, indices = _accessor_sparse.indices, values = _accessor_sparse.values;
|
|
962
748
|
var indicesBufferView = bufferViews[indices.bufferView];
|
|
963
749
|
var valuesBufferView = bufferViews[values.bufferView];
|
|
964
|
-
var
|
|
965
|
-
var
|
|
966
|
-
var indicesArrayBuffer = buffers[indicesBufferIndex];
|
|
967
|
-
var valuesArrayBuffer = buffers[valuesBufferIndex];
|
|
750
|
+
var indicesArrayBuffer = buffers[indicesBufferView.buffer];
|
|
751
|
+
var valuesArrayBuffer = buffers[valuesBufferView.buffer];
|
|
968
752
|
var _indices_byteOffset, _indicesBufferView_byteOffset;
|
|
969
753
|
var indicesByteOffset = ((_indices_byteOffset = indices.byteOffset) != null ? _indices_byteOffset : 0) + ((_indicesBufferView_byteOffset = indicesBufferView.byteOffset) != null ? _indicesBufferView_byteOffset : 0);
|
|
970
754
|
var indicesByteLength = indicesBufferView.byteLength;
|
|
971
755
|
var _values_byteOffset, _valuesBufferView_byteOffset;
|
|
972
756
|
var valuesByteOffset = ((_values_byteOffset = values.byteOffset) != null ? _values_byteOffset : 0) + ((_valuesBufferView_byteOffset = valuesBufferView.byteOffset) != null ? _valuesBufferView_byteOffset : 0);
|
|
973
757
|
var valuesByteLength = valuesBufferView.byteLength;
|
|
974
|
-
restoreInfo.typeSize = accessorTypeSize;
|
|
975
|
-
restoreInfo.sparseCount = count;
|
|
976
758
|
var IndexTypeArray = GLTFUtil.getComponentType(indices.componentType);
|
|
977
|
-
var
|
|
978
|
-
var
|
|
979
|
-
restoreInfo.sparseIndices = new RestoreDataAccessor(indicesBufferIndex, IndexTypeArray, indicesByteOffset, indexLength);
|
|
980
|
-
var valueLength = valuesByteLength / TypedArray.BYTES_PER_ELEMENT;
|
|
981
|
-
var valuesArray = new TypedArray(valuesArrayBuffer, valuesByteOffset, valueLength);
|
|
982
|
-
restoreInfo.sparseValues = new RestoreDataAccessor(valuesBufferIndex, TypedArray, valuesByteOffset, valueLength);
|
|
759
|
+
var indicesArray = new IndexTypeArray(indicesArrayBuffer, indicesByteOffset, indicesByteLength / IndexTypeArray.BYTES_PER_ELEMENT);
|
|
760
|
+
var valuesArray = new TypedArray(valuesArrayBuffer, valuesByteOffset, valuesByteLength / TypedArray.BYTES_PER_ELEMENT);
|
|
983
761
|
for(var i = 0; i < count; i++){
|
|
984
762
|
var replaceIndex = indicesArray[i];
|
|
985
763
|
for(var j = 0; j < accessorTypeSize; j++){
|
|
986
764
|
data[replaceIndex * accessorTypeSize + j] = valuesArray[i * accessorTypeSize + j];
|
|
987
765
|
}
|
|
988
766
|
}
|
|
989
|
-
|
|
767
|
+
return data;
|
|
990
768
|
};
|
|
991
769
|
GLTFUtil.getIndexFormat = function getIndexFormat(type) {
|
|
992
770
|
switch(type){
|
|
@@ -1084,7 +862,7 @@ var TextureWrapMode;
|
|
|
1084
862
|
};
|
|
1085
863
|
/**
|
|
1086
864
|
* Parse the glb format.
|
|
1087
|
-
*/ GLTFUtil.parseGLB = function parseGLB(
|
|
865
|
+
*/ GLTFUtil.parseGLB = function parseGLB(glb) {
|
|
1088
866
|
var UINT32_LENGTH = 4;
|
|
1089
867
|
var GLB_HEADER_MAGIC = 0x46546c67; // 'glTF'
|
|
1090
868
|
var GLB_HEADER_LENGTH = 12;
|
|
@@ -1112,11 +890,10 @@ var TextureWrapMode;
|
|
|
1112
890
|
return null;
|
|
1113
891
|
}
|
|
1114
892
|
var glTFData = new Uint8Array(glb, GLB_HEADER_LENGTH + 2 * UINT32_LENGTH, chunkLength);
|
|
1115
|
-
var
|
|
893
|
+
var gltf = JSON.parse(GLTFUtil.decodeText(glTFData));
|
|
1116
894
|
// read all buffers
|
|
1117
895
|
var buffers = [];
|
|
1118
896
|
var byteOffset = GLB_HEADER_LENGTH + 2 * UINT32_LENGTH + chunkLength;
|
|
1119
|
-
var restoreGLBBufferSlice = context.contentRestorer.glbBufferSlices;
|
|
1120
897
|
while(byteOffset < header.length){
|
|
1121
898
|
chunkLength = dataView.getUint32(byteOffset, true);
|
|
1122
899
|
chunkType = dataView.getUint32(byteOffset + UINT32_LENGTH, true);
|
|
@@ -1127,11 +904,10 @@ var TextureWrapMode;
|
|
|
1127
904
|
var currentOffset = byteOffset + 2 * UINT32_LENGTH;
|
|
1128
905
|
var buffer = glb.slice(currentOffset, currentOffset + chunkLength);
|
|
1129
906
|
buffers.push(buffer);
|
|
1130
|
-
restoreGLBBufferSlice.push(new Vector2(currentOffset, chunkLength));
|
|
1131
907
|
byteOffset += chunkLength + 2 * UINT32_LENGTH;
|
|
1132
908
|
}
|
|
1133
909
|
return {
|
|
1134
|
-
|
|
910
|
+
gltf: gltf,
|
|
1135
911
|
buffers: buffers
|
|
1136
912
|
};
|
|
1137
913
|
};
|
|
@@ -1146,339 +922,630 @@ var TextureWrapMode;
|
|
|
1146
922
|
return GLTFUtil;
|
|
1147
923
|
}();
|
|
1148
924
|
|
|
1149
|
-
function
|
|
1150
|
-
|
|
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;
|
|
1151
931
|
}
|
|
1152
932
|
|
|
1153
|
-
function
|
|
1154
|
-
|
|
933
|
+
function _array_without_holes(arr) {
|
|
934
|
+
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
1155
935
|
}
|
|
1156
936
|
|
|
1157
|
-
function
|
|
1158
|
-
|
|
937
|
+
function _iterable_to_array(iter) {
|
|
938
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) {
|
|
939
|
+
return Array.from(iter);
|
|
940
|
+
}
|
|
1159
941
|
}
|
|
1160
942
|
|
|
1161
|
-
function
|
|
1162
|
-
|
|
943
|
+
function _non_iterable_spread() {
|
|
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.");
|
|
1163
945
|
}
|
|
1164
946
|
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
var
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
for(var _len = arguments.length, extra = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++){
|
|
1184
|
-
extra[_key - 3] = arguments[_key];
|
|
1185
|
-
}
|
|
1186
|
-
throw "Not implemented.";
|
|
1187
|
-
};
|
|
1188
|
-
/**
|
|
1189
|
-
* Additive parse to the resource.
|
|
1190
|
-
* @param context - The parser context
|
|
1191
|
-
* @param parseResource - The parsed resource
|
|
1192
|
-
* @param extensionSchema - The extension schema
|
|
1193
|
-
* @param extensionOwnerSchema - The extension owner schema
|
|
1194
|
-
* @returns The void or promise
|
|
1195
|
-
*/ _proto.additiveParse = function additiveParse(context, parseResource, extensionSchema, extensionOwnerSchema) {
|
|
947
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
948
|
+
if (!o) return;
|
|
949
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
950
|
+
|
|
951
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
952
|
+
|
|
953
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
954
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
955
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
function _to_consumable_array(arr) {
|
|
959
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
var Parser = /*#__PURE__*/ function() {
|
|
963
|
+
function Parser() {}
|
|
964
|
+
Parser.parseEngineResource = function parseEngineResource(extensionName, extensionSchema, parseResource, context) {
|
|
1196
965
|
for(var _len = arguments.length, extra = new Array(_len > 4 ? _len - 4 : 0), _key = 4; _key < _len; _key++){
|
|
1197
966
|
extra[_key - 4] = arguments[_key];
|
|
1198
967
|
}
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
* If this method is registered, the default pipeline processing will be ignored.
|
|
1210
|
-
*/ "CreateAndParse"] = 0] = "CreateAndParse";
|
|
1211
|
-
GLTFExtensionMode[GLTFExtensionMode[/** Additive parse mode. */ "AdditiveParse"] = 1] = "AdditiveParse";
|
|
1212
|
-
})(GLTFExtensionMode || (GLTFExtensionMode = {}));
|
|
1213
|
-
|
|
1214
|
-
/**
|
|
1215
|
-
* Base class of glTF parser.
|
|
1216
|
-
*/ var GLTFParser = /*#__PURE__*/ function() {
|
|
1217
|
-
function GLTFParser() {}
|
|
1218
|
-
/**
|
|
1219
|
-
* Execute all parses of extension to initialize plugin.
|
|
1220
|
-
* @remarks Some plugins require initialization.
|
|
1221
|
-
* @returns The void or promise
|
|
1222
|
-
*/ GLTFParser.executeExtensionsInitialize = function executeExtensionsInitialize(extensionName) {
|
|
1223
|
-
var parsers = GLTFParser._extensionParsers[extensionName];
|
|
1224
|
-
var length = parsers == null ? void 0 : parsers.length;
|
|
1225
|
-
if (length) {
|
|
1226
|
-
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
|
+
}
|
|
1227
978
|
}
|
|
1228
979
|
};
|
|
1229
|
-
|
|
1230
|
-
* Execute all parses of extension to create resource.
|
|
1231
|
-
* @param extensions - Related extensions field
|
|
1232
|
-
* @param context - The parser context
|
|
1233
|
-
* @param ownerSchema - The extension owner schema
|
|
1234
|
-
* @param extra - Extra params
|
|
1235
|
-
* @returns
|
|
1236
|
-
*/ GLTFParser.executeExtensionsCreateAndParse = function executeExtensionsCreateAndParse(extensions, context, ownerSchema) {
|
|
1237
|
-
if (extensions === void 0) extensions = {};
|
|
980
|
+
Parser.createEngineResource = function createEngineResource(extensionName, extensionSchema, context) {
|
|
1238
981
|
for(var _len = arguments.length, extra = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++){
|
|
1239
982
|
extra[_key - 3] = arguments[_key];
|
|
1240
983
|
}
|
|
1241
|
-
var
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
var extensionName = extensionArray[i];
|
|
1246
|
-
var extensionSchema = extensions[extensionName];
|
|
1247
|
-
resource = (_GLTFParser = GLTFParser)._createAndParse.apply(_GLTFParser, [
|
|
1248
|
-
extensionName,
|
|
1249
|
-
context,
|
|
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_, [
|
|
1250
988
|
extensionSchema,
|
|
1251
|
-
|
|
1252
|
-
].concat(
|
|
1253
|
-
if (resource) {
|
|
1254
|
-
return resource;
|
|
1255
|
-
}
|
|
1256
|
-
}
|
|
1257
|
-
};
|
|
1258
|
-
/**
|
|
1259
|
-
* Execute all parses of extension to parse resource.
|
|
1260
|
-
* @param extensions - Related extensions field
|
|
1261
|
-
* @param context - The parser context
|
|
1262
|
-
* @param parseResource - The parsed resource
|
|
1263
|
-
* @param ownerSchema - The extension owner schema
|
|
1264
|
-
* @param extra - Extra params
|
|
1265
|
-
*/ GLTFParser.executeExtensionsAdditiveAndParse = function executeExtensionsAdditiveAndParse(extensions, context, parseResource, ownerSchema) {
|
|
1266
|
-
for(var _len = arguments.length, extra = new Array(_len > 4 ? _len - 4 : 0), _key = 4; _key < _len; _key++){
|
|
1267
|
-
extra[_key - 4] = arguments[_key];
|
|
1268
|
-
}
|
|
1269
|
-
for(var extensionName in extensions){
|
|
1270
|
-
var _GLTFParser;
|
|
1271
|
-
var extensionSchema = extensions[extensionName];
|
|
1272
|
-
(_GLTFParser = GLTFParser)._additiveParse.apply(_GLTFParser, [
|
|
1273
|
-
extensionName,
|
|
1274
|
-
context,
|
|
1275
|
-
parseResource,
|
|
1276
|
-
extensionSchema,
|
|
1277
|
-
ownerSchema
|
|
1278
|
-
].concat(_toConsumableArray(extra)));
|
|
989
|
+
context
|
|
990
|
+
].concat(_to_consumable_array(extra)));
|
|
1279
991
|
}
|
|
1280
992
|
};
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
* @returns Boolean
|
|
1285
|
-
*/ GLTFParser.hasExtensionParser = function hasExtensionParser(extensionName) {
|
|
1286
|
-
var _GLTFParser__extensionParsers_extensionName;
|
|
1287
|
-
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);
|
|
1288
996
|
};
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
*/ GLTFParser.getExtensionParser = function getExtensionParser(extensionName, mode) {
|
|
1295
|
-
var parsers = GLTFParser._extensionParsers[extensionName];
|
|
1296
|
-
var length = parsers == null ? void 0 : parsers.length;
|
|
1297
|
-
if (length) {
|
|
1298
|
-
// only use the last parser.
|
|
1299
|
-
for(var i = length - 1; i >= 0; --i){
|
|
1300
|
-
var currentParser = parsers[i];
|
|
1301
|
-
if (currentParser._mode === mode) {
|
|
1302
|
-
return currentParser;
|
|
1303
|
-
}
|
|
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();
|
|
1304
1002
|
}
|
|
1305
1003
|
}
|
|
1306
1004
|
};
|
|
1307
1005
|
/**
|
|
1308
1006
|
* @internal
|
|
1309
|
-
*/
|
|
1310
|
-
if (!
|
|
1311
|
-
|
|
1312
|
-
}
|
|
1313
|
-
GLTFParser._extensionParsers[extensionName].push(extensionParser);
|
|
1314
|
-
};
|
|
1315
|
-
GLTFParser._createAndParse = function _createAndParse(extensionName, context, extensionSchema, ownerSchema) {
|
|
1316
|
-
for(var _len = arguments.length, extra = new Array(_len > 4 ? _len - 4 : 0), _key = 4; _key < _len; _key++){
|
|
1317
|
-
extra[_key - 4] = arguments[_key];
|
|
1318
|
-
}
|
|
1319
|
-
var parser = GLTFParser.getExtensionParser(extensionName, GLTFExtensionMode.CreateAndParse);
|
|
1320
|
-
if (parser) {
|
|
1321
|
-
var _parser;
|
|
1322
|
-
return (_parser = parser).createAndParse.apply(_parser, [
|
|
1323
|
-
context,
|
|
1324
|
-
extensionSchema,
|
|
1325
|
-
ownerSchema
|
|
1326
|
-
].concat(_toConsumableArray(extra)));
|
|
1327
|
-
}
|
|
1328
|
-
};
|
|
1329
|
-
GLTFParser._additiveParse = function _additiveParse(extensionName, context, parseResource, extensionSchema, ownerSchema) {
|
|
1330
|
-
for(var _len = arguments.length, extra = new Array(_len > 5 ? _len - 5 : 0), _key = 5; _key < _len; _key++){
|
|
1331
|
-
extra[_key - 5] = arguments[_key];
|
|
1332
|
-
}
|
|
1333
|
-
var parser = GLTFParser.getExtensionParser(extensionName, GLTFExtensionMode.AdditiveParse);
|
|
1334
|
-
if (parser) {
|
|
1335
|
-
var _parser;
|
|
1336
|
-
(_parser = parser).additiveParse.apply(_parser, [
|
|
1337
|
-
context,
|
|
1338
|
-
parseResource,
|
|
1339
|
-
extensionSchema,
|
|
1340
|
-
ownerSchema
|
|
1341
|
-
].concat(_toConsumableArray(extra)));
|
|
1007
|
+
*/ Parser._addExtensionParser = function _addExtensionParser(extensionName, extensionParser) {
|
|
1008
|
+
if (!Parser._extensionParsers[extensionName]) {
|
|
1009
|
+
Parser._extensionParsers[extensionName] = [];
|
|
1342
1010
|
}
|
|
1011
|
+
Parser._extensionParsers[extensionName].push(extensionParser);
|
|
1343
1012
|
};
|
|
1344
|
-
return
|
|
1013
|
+
return Parser;
|
|
1345
1014
|
}();
|
|
1346
|
-
|
|
1015
|
+
(function() {
|
|
1016
|
+
Parser._extensionParsers = {};
|
|
1017
|
+
})();
|
|
1347
1018
|
/**
|
|
1348
1019
|
* Declare ExtensionParser's decorator.
|
|
1349
1020
|
* @param extensionName - Extension name
|
|
1350
|
-
*/ function
|
|
1021
|
+
*/ function registerExtension(extensionName) {
|
|
1351
1022
|
return function(parser) {
|
|
1352
1023
|
var extensionParser = new parser();
|
|
1353
|
-
|
|
1354
|
-
GLTFParser._addExtensionParser(extensionName, extensionParser);
|
|
1024
|
+
Parser._addExtensionParser(extensionName, extensionParser);
|
|
1355
1025
|
};
|
|
1356
1026
|
}
|
|
1357
1027
|
|
|
1358
|
-
var
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
var glTF = context.glTF; context.buffers; var glTFResource = context.glTFResource;
|
|
1366
|
-
glTFResource.entities;
|
|
1367
|
-
var animations = glTF.animations; glTF.accessors; glTF.bufferViews;
|
|
1368
|
-
if (!animations) {
|
|
1369
|
-
return;
|
|
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];
|
|
1370
1035
|
}
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
var
|
|
1374
|
-
|
|
1375
|
-
for(var i = 0; i < animationClipCount; i++){
|
|
1376
|
-
var animationInfo = animations[i];
|
|
1377
|
-
var _animationInfo_name = animationInfo.name, name = _animationInfo_name === void 0 ? "AnimationClip" + i : _animationInfo_name;
|
|
1378
|
-
var animationClip = GLTFParser.executeExtensionsCreateAndParse(animationInfo.extensions, context, animationInfo);
|
|
1379
|
-
if (!animationClip) {
|
|
1380
|
-
animationClip = new AnimationClip(name);
|
|
1381
|
-
GLTFAnimationParser._parseStandardProperty(context, animationClip, animationInfo);
|
|
1382
|
-
}
|
|
1383
|
-
animationClipPromises.push(animationClip);
|
|
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];
|
|
1384
1040
|
}
|
|
1385
|
-
return
|
|
1386
|
-
glTFResource.animations = animationClips;
|
|
1387
|
-
for(var i = 0; i < glTF.animations.length; i++){
|
|
1388
|
-
var animationInfo = glTF.animations[i];
|
|
1389
|
-
GLTFParser.executeExtensionsAdditiveAndParse(animationInfo.extensions, context, animationClips[i], animationInfo);
|
|
1390
|
-
}
|
|
1391
|
-
animationClipsPromiseInfo.resolve(animationClips);
|
|
1392
|
-
return animationClipsPromiseInfo.promise;
|
|
1393
|
-
});
|
|
1041
|
+
return null;
|
|
1394
1042
|
};
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
var outputAccessor = accessors[gltfSampler.output];
|
|
1408
|
-
var input = GLTFUtil.getAccessorBuffer(context, bufferViews, inputAccessor).data;
|
|
1409
|
-
var output = GLTFUtil.getAccessorBuffer(context, bufferViews, outputAccessor).data;
|
|
1410
|
-
if (outputAccessor.normalized) {
|
|
1411
|
-
var scale = GLTFUtil.getNormalizedComponentScale(outputAccessor.componentType);
|
|
1412
|
-
var scaled = new Float32Array(output.length);
|
|
1413
|
-
for(var k = 0, v = output.length; k < v; k++){
|
|
1414
|
-
scaled[k] = output[k] * scale;
|
|
1415
|
-
}
|
|
1416
|
-
output = scaled;
|
|
1417
|
-
}
|
|
1418
|
-
var outputStride = output.length / input.length;
|
|
1419
|
-
var _gltfSampler_interpolation;
|
|
1420
|
-
var interpolation = (_gltfSampler_interpolation = gltfSampler.interpolation) != null ? _gltfSampler_interpolation : AnimationSamplerInterpolation.Linear;
|
|
1421
|
-
var samplerInterpolation = void 0;
|
|
1422
|
-
switch(interpolation){
|
|
1423
|
-
case AnimationSamplerInterpolation.CubicSpine:
|
|
1424
|
-
samplerInterpolation = InterpolationType.CubicSpine;
|
|
1425
|
-
break;
|
|
1426
|
-
case AnimationSamplerInterpolation.Step:
|
|
1427
|
-
samplerInterpolation = InterpolationType.Step;
|
|
1428
|
-
break;
|
|
1429
|
-
case AnimationSamplerInterpolation.Linear:
|
|
1430
|
-
samplerInterpolation = InterpolationType.Linear;
|
|
1431
|
-
break;
|
|
1432
|
-
}
|
|
1433
|
-
input[input.length - 1];
|
|
1434
|
-
sampleDataCollection.push({
|
|
1435
|
-
type: outputAccessor.type,
|
|
1436
|
-
interpolation: samplerInterpolation,
|
|
1437
|
-
input: input,
|
|
1438
|
-
output: output,
|
|
1439
|
-
outputSize: outputStride
|
|
1440
|
-
});
|
|
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);
|
|
1050
|
+
}
|
|
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();
|
|
1441
1055
|
}
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
ComponentType = Transform;
|
|
1457
|
-
propertyName = "position";
|
|
1458
|
-
break;
|
|
1459
|
-
case AnimationChannelTargetPath.ROTATION:
|
|
1460
|
-
ComponentType = Transform;
|
|
1461
|
-
propertyName = "rotationQuaternion";
|
|
1462
|
-
break;
|
|
1463
|
-
case AnimationChannelTargetPath.SCALE:
|
|
1464
|
-
ComponentType = Transform;
|
|
1465
|
-
propertyName = "scale";
|
|
1466
|
-
break;
|
|
1467
|
-
case AnimationChannelTargetPath.WEIGHTS:
|
|
1468
|
-
ComponentType = SkinnedMeshRenderer;
|
|
1469
|
-
propertyName = "blendShapeWeights";
|
|
1470
|
-
break;
|
|
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];
|
|
1065
|
+
}
|
|
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;
|
|
1471
1070
|
}
|
|
1472
|
-
var curve = this._addCurve(target.path, gltfChannel, sampleDataCollection);
|
|
1473
|
-
animationClip.addCurveBinding(relativePath, ComponentType, propertyName, curve);
|
|
1474
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;
|
|
1083
|
+
});
|
|
1475
1084
|
};
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
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
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
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;
|
|
1227
|
+
break;
|
|
1228
|
+
case MaterialAlphaMode.BLEND:
|
|
1229
|
+
material.isTransparent = true;
|
|
1230
|
+
break;
|
|
1231
|
+
case MaterialAlphaMode.MASK:
|
|
1232
|
+
material.alphaCutoff = alphaCutoff != null ? alphaCutoff : 0.5;
|
|
1233
|
+
break;
|
|
1234
|
+
}
|
|
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
|
+
})
|
|
1351
|
+
});
|
|
1352
|
+
}
|
|
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
|
+
});
|
|
1497
|
+
}
|
|
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);
|
|
1530
|
+
}
|
|
1531
|
+
animationClips[i] = animationClip;
|
|
1532
|
+
animationsIndices[i] = {
|
|
1533
|
+
name: name,
|
|
1534
|
+
index: i
|
|
1535
|
+
};
|
|
1536
|
+
}
|
|
1537
|
+
glTFResource.animations = animationClips;
|
|
1538
|
+
// @ts-ignore for editor
|
|
1539
|
+
glTFResource._animationsIndices = animationsIndices;
|
|
1540
|
+
animationClipsPromiseInfo.resolve(animationClips);
|
|
1541
|
+
return animationClipsPromiseInfo.promise;
|
|
1542
|
+
};
|
|
1543
|
+
_proto._addCurve = function _addCurve(animationchannelTargetPath, gltfChannel, sampleDataCollection) {
|
|
1544
|
+
var sampleData = sampleDataCollection[gltfChannel.sampler];
|
|
1545
|
+
var input = sampleData.input, output = sampleData.output, outputSize = sampleData.outputSize;
|
|
1546
|
+
switch(animationchannelTargetPath){
|
|
1547
|
+
case AnimationChannelTargetPath.TRANSLATION:
|
|
1548
|
+
case AnimationChannelTargetPath.SCALE:
|
|
1482
1549
|
{
|
|
1483
1550
|
var curve = new AnimationVector3Curve();
|
|
1484
1551
|
var interpolation = curve.interpolation = sampleData.interpolation;
|
|
@@ -1541,42 +1608,35 @@ var GLTFAnimationParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
1541
1608
|
}
|
|
1542
1609
|
}
|
|
1543
1610
|
};
|
|
1544
|
-
return
|
|
1545
|
-
}(
|
|
1611
|
+
return AnimationParser;
|
|
1612
|
+
}(Parser);
|
|
1546
1613
|
|
|
1547
|
-
var
|
|
1548
|
-
_inherits(
|
|
1549
|
-
function
|
|
1550
|
-
return
|
|
1614
|
+
var BufferParser = /*#__PURE__*/ function(Parser) {
|
|
1615
|
+
_inherits(BufferParser, Parser);
|
|
1616
|
+
function BufferParser() {
|
|
1617
|
+
return Parser.apply(this, arguments);
|
|
1551
1618
|
}
|
|
1552
|
-
var _proto =
|
|
1619
|
+
var _proto = BufferParser.prototype;
|
|
1553
1620
|
_proto.parse = function parse(context) {
|
|
1554
|
-
var glTFResource = context.glTFResource
|
|
1621
|
+
var glTFResource = context.glTFResource;
|
|
1555
1622
|
var url = glTFResource.url;
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
if (isGLB) {
|
|
1563
|
-
return request(url, requestConfig).then(function(glb) {
|
|
1564
|
-
restoreBufferRequests.push(new BufferRequestInfo(url, requestConfig));
|
|
1565
|
-
return GLTFUtil.parseGLB(context, glb);
|
|
1566
|
-
}).then(function(param) {
|
|
1567
|
-
var glTF = param.glTF, buffers = param.buffers;
|
|
1568
|
-
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;
|
|
1569
1629
|
context.buffers = buffers;
|
|
1570
1630
|
});
|
|
1571
1631
|
} else {
|
|
1572
1632
|
return request(url, {
|
|
1573
1633
|
type: "json"
|
|
1574
|
-
}).then(function(
|
|
1575
|
-
context.
|
|
1576
|
-
return Promise.all(
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
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
|
+
});
|
|
1580
1640
|
})).then(function(buffers) {
|
|
1581
1641
|
context.buffers = buffers;
|
|
1582
1642
|
});
|
|
@@ -1587,24 +1647,24 @@ var GLTFBufferParser = /*#__PURE__*/ function(GLTFParser) {
|
|
|
1587
1647
|
var index = url.lastIndexOf(".");
|
|
1588
1648
|
return url.substring(index + 1, index + 4) === "glb";
|
|
1589
1649
|
};
|
|
1590
|
-
return
|
|
1591
|
-
}(
|
|
1650
|
+
return BufferParser;
|
|
1651
|
+
}(Parser);
|
|
1592
1652
|
|
|
1593
|
-
var
|
|
1594
|
-
_inherits(
|
|
1595
|
-
function
|
|
1596
|
-
return
|
|
1653
|
+
var EntityParser = /*#__PURE__*/ function(Parser) {
|
|
1654
|
+
_inherits(EntityParser, Parser);
|
|
1655
|
+
function EntityParser() {
|
|
1656
|
+
return Parser.apply(this, arguments);
|
|
1597
1657
|
}
|
|
1598
|
-
var _proto =
|
|
1658
|
+
var _proto = EntityParser.prototype;
|
|
1599
1659
|
_proto.parse = function parse(context) {
|
|
1600
|
-
var glTFResource = context.glTFResource, nodes = context.
|
|
1660
|
+
var glTFResource = context.glTFResource, nodes = context.gltf.nodes;
|
|
1601
1661
|
var engine = glTFResource.engine;
|
|
1602
1662
|
if (!nodes) return;
|
|
1603
1663
|
var entities = [];
|
|
1604
1664
|
for(var i = 0; i < nodes.length; i++){
|
|
1605
1665
|
var gltfNode = nodes[i];
|
|
1606
1666
|
var matrix = gltfNode.matrix, translation = gltfNode.translation, rotation = gltfNode.rotation, scale = gltfNode.scale;
|
|
1607
|
-
var entity = new Entity(engine, gltfNode.name || "" +
|
|
1667
|
+
var entity = new Entity(engine, gltfNode.name || "" + EntityParser._defaultName + i);
|
|
1608
1668
|
var transform = entity.transform;
|
|
1609
1669
|
if (matrix) {
|
|
1610
1670
|
var localMatrix = transform.localMatrix;
|
|
@@ -1628,7 +1688,7 @@ var GLTFEntityParser = /*#__PURE__*/ function(GLTFParser) {
|
|
|
1628
1688
|
this._createSceneRoots(context, glTFResource);
|
|
1629
1689
|
};
|
|
1630
1690
|
_proto._buildEntityTree = function _buildEntityTree(context, glTFResource) {
|
|
1631
|
-
var nodes = context.
|
|
1691
|
+
var nodes = context.gltf.nodes;
|
|
1632
1692
|
var entities = glTFResource.entities;
|
|
1633
1693
|
for(var i = 0; i < nodes.length; i++){
|
|
1634
1694
|
var children = nodes[i].children;
|
|
@@ -1642,7 +1702,7 @@ var GLTFEntityParser = /*#__PURE__*/ function(GLTFParser) {
|
|
|
1642
1702
|
}
|
|
1643
1703
|
};
|
|
1644
1704
|
_proto._createSceneRoots = function _createSceneRoots(context, glTFResource) {
|
|
1645
|
-
var
|
|
1705
|
+
var _context_gltf = context.gltf, tmp = _context_gltf.scene, sceneID = tmp === void 0 ? 0 : tmp, scenes = _context_gltf.scenes;
|
|
1646
1706
|
var engine = glTFResource.engine, entities = glTFResource.entities;
|
|
1647
1707
|
if (!scenes) return;
|
|
1648
1708
|
var sceneRoots = [];
|
|
@@ -1662,193 +1722,79 @@ var GLTFEntityParser = /*#__PURE__*/ function(GLTFParser) {
|
|
|
1662
1722
|
glTFResource.sceneRoots = sceneRoots;
|
|
1663
1723
|
glTFResource.defaultSceneRoot = sceneRoots[sceneID];
|
|
1664
1724
|
};
|
|
1665
|
-
return
|
|
1666
|
-
}(
|
|
1667
|
-
|
|
1725
|
+
return EntityParser;
|
|
1726
|
+
}(Parser);
|
|
1727
|
+
(function() {
|
|
1728
|
+
/** @internal */ EntityParser._defaultName = "_GLTF_ENTITY_";
|
|
1729
|
+
})();
|
|
1668
1730
|
|
|
1669
|
-
var
|
|
1670
|
-
_inherits(
|
|
1671
|
-
function
|
|
1672
|
-
return
|
|
1731
|
+
var MeshParser = /*#__PURE__*/ function(Parser1) {
|
|
1732
|
+
_inherits(MeshParser, Parser1);
|
|
1733
|
+
function MeshParser() {
|
|
1734
|
+
return Parser1.apply(this, arguments);
|
|
1673
1735
|
}
|
|
1674
|
-
var _proto =
|
|
1736
|
+
var _proto = MeshParser.prototype;
|
|
1675
1737
|
_proto.parse = function parse(context) {
|
|
1676
|
-
var
|
|
1677
|
-
|
|
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;
|
|
1678
1786
|
var engine = glTFResource.engine;
|
|
1679
|
-
|
|
1680
|
-
for(var i = 0; i < glTF.materials.length; i++){
|
|
1681
|
-
var materialInfo = glTF.materials[i];
|
|
1682
|
-
var material = GLTFParser.executeExtensionsCreateAndParse(materialInfo.extensions, context, materialInfo);
|
|
1683
|
-
if (!material) {
|
|
1684
|
-
material = new PBRMaterial(engine);
|
|
1685
|
-
material.name = materialInfo.name;
|
|
1686
|
-
GLTFMaterialParser._parseStandardProperty(context, material, materialInfo);
|
|
1687
|
-
}
|
|
1688
|
-
materialPromises.push(material);
|
|
1689
|
-
}
|
|
1690
|
-
return AssetPromise.all(materialPromises).then(function(materials) {
|
|
1691
|
-
glTFResource.materials = materials;
|
|
1692
|
-
for(var i = 0; i < glTF.materials.length; i++){
|
|
1693
|
-
var materialInfo = glTF.materials[i];
|
|
1694
|
-
GLTFParser.executeExtensionsAdditiveAndParse(materialInfo.extensions, context, materials[i], materialInfo);
|
|
1695
|
-
}
|
|
1696
|
-
materialsPromiseInfo.resolve(materials);
|
|
1697
|
-
return materialsPromiseInfo.promise;
|
|
1698
|
-
});
|
|
1699
|
-
};
|
|
1700
|
-
/**
|
|
1701
|
-
* @internal
|
|
1702
|
-
*/ GLTFMaterialParser._checkOtherTextureTransform = function _checkOtherTextureTransform(texture, textureName) {
|
|
1703
|
-
var _texture_extensions;
|
|
1704
|
-
if ((_texture_extensions = texture.extensions) == null ? void 0 : _texture_extensions.KHR_texture_transform) {
|
|
1705
|
-
Logger.warn("" + textureName + " texture always use the KHR_texture_transform of the base texture.");
|
|
1706
|
-
}
|
|
1707
|
-
};
|
|
1708
|
-
/**
|
|
1709
|
-
* @internal
|
|
1710
|
-
*/ GLTFMaterialParser._parseStandardProperty = function _parseStandardProperty(context, material, materialInfo) {
|
|
1711
|
-
var textures = context.glTFResource.textures;
|
|
1712
|
-
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;
|
|
1713
|
-
if (pbrMetallicRoughness) {
|
|
1714
|
-
var baseColorFactor = pbrMetallicRoughness.baseColorFactor, baseColorTexture = pbrMetallicRoughness.baseColorTexture, metallicFactor = pbrMetallicRoughness.metallicFactor, roughnessFactor = pbrMetallicRoughness.roughnessFactor, metallicRoughnessTexture = pbrMetallicRoughness.metallicRoughnessTexture;
|
|
1715
|
-
if (baseColorFactor) {
|
|
1716
|
-
material.baseColor = new Color(Color.linearToGammaSpace(baseColorFactor[0]), Color.linearToGammaSpace(baseColorFactor[1]), Color.linearToGammaSpace(baseColorFactor[2]), baseColorFactor[3]);
|
|
1717
|
-
}
|
|
1718
|
-
if (baseColorTexture) {
|
|
1719
|
-
material.baseTexture = textures[baseColorTexture.index];
|
|
1720
|
-
GLTFParser.executeExtensionsAdditiveAndParse(baseColorTexture.extensions, context, material, baseColorTexture);
|
|
1721
|
-
}
|
|
1722
|
-
if (material.constructor === PBRMaterial) {
|
|
1723
|
-
material.metallic = metallicFactor != null ? metallicFactor : 1;
|
|
1724
|
-
material.roughness = roughnessFactor != null ? roughnessFactor : 1;
|
|
1725
|
-
if (metallicRoughnessTexture) {
|
|
1726
|
-
material.roughnessMetallicTexture = textures[metallicRoughnessTexture.index];
|
|
1727
|
-
GLTFMaterialParser._checkOtherTextureTransform(metallicRoughnessTexture, "Roughness metallic");
|
|
1728
|
-
}
|
|
1729
|
-
}
|
|
1730
|
-
}
|
|
1731
|
-
if (material.constructor === PBRMaterial || material.constructor === PBRSpecularMaterial) {
|
|
1732
|
-
if (emissiveTexture) {
|
|
1733
|
-
material.emissiveTexture = textures[emissiveTexture.index];
|
|
1734
|
-
GLTFMaterialParser._checkOtherTextureTransform(emissiveTexture, "Emissive");
|
|
1735
|
-
}
|
|
1736
|
-
if (emissiveFactor) {
|
|
1737
|
-
material.emissiveColor = new Color(Color.linearToGammaSpace(emissiveFactor[0]), Color.linearToGammaSpace(emissiveFactor[1]), Color.linearToGammaSpace(emissiveFactor[2]));
|
|
1738
|
-
}
|
|
1739
|
-
if (normalTexture) {
|
|
1740
|
-
var index = normalTexture.index, scale = normalTexture.scale;
|
|
1741
|
-
material.normalTexture = textures[index];
|
|
1742
|
-
GLTFMaterialParser._checkOtherTextureTransform(normalTexture, "Normal");
|
|
1743
|
-
if (scale !== undefined) {
|
|
1744
|
-
material.normalTextureIntensity = scale;
|
|
1745
|
-
}
|
|
1746
|
-
}
|
|
1747
|
-
if (occlusionTexture) {
|
|
1748
|
-
var index1 = occlusionTexture.index, strength = occlusionTexture.strength, texCoord = occlusionTexture.texCoord;
|
|
1749
|
-
material.occlusionTexture = textures[index1];
|
|
1750
|
-
GLTFMaterialParser._checkOtherTextureTransform(occlusionTexture, "Occlusion");
|
|
1751
|
-
if (strength !== undefined) {
|
|
1752
|
-
material.occlusionTextureIntensity = strength;
|
|
1753
|
-
}
|
|
1754
|
-
if (texCoord === TextureCoordinate.UV1) {
|
|
1755
|
-
material.occlusionTextureCoord = TextureCoordinate.UV1;
|
|
1756
|
-
} else if (texCoord > TextureCoordinate.UV1) {
|
|
1757
|
-
Logger.warn("Occlusion texture uv coordinate must be UV0 or UV1.");
|
|
1758
|
-
}
|
|
1759
|
-
}
|
|
1760
|
-
}
|
|
1761
|
-
if (doubleSided) {
|
|
1762
|
-
material.renderFace = RenderFace.Double;
|
|
1763
|
-
} else {
|
|
1764
|
-
material.renderFace = RenderFace.Front;
|
|
1765
|
-
}
|
|
1766
|
-
switch(alphaMode){
|
|
1767
|
-
case MaterialAlphaMode.OPAQUE:
|
|
1768
|
-
material.isTransparent = false;
|
|
1769
|
-
break;
|
|
1770
|
-
case MaterialAlphaMode.BLEND:
|
|
1771
|
-
material.isTransparent = true;
|
|
1772
|
-
break;
|
|
1773
|
-
case MaterialAlphaMode.MASK:
|
|
1774
|
-
material.alphaCutoff = alphaCutoff != null ? alphaCutoff : 0.5;
|
|
1775
|
-
break;
|
|
1776
|
-
}
|
|
1777
|
-
};
|
|
1778
|
-
return GLTFMaterialParser;
|
|
1779
|
-
}(GLTFParser);
|
|
1780
|
-
|
|
1781
|
-
function _instanceof(left, right) {
|
|
1782
|
-
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
1783
|
-
return !!right[Symbol.hasInstance](left);
|
|
1784
|
-
} else {
|
|
1785
|
-
return left instanceof right;
|
|
1786
|
-
}
|
|
1787
|
-
}
|
|
1788
|
-
|
|
1789
|
-
var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
1790
|
-
_inherits(GLTFMeshParser, GLTFParser1);
|
|
1791
|
-
function GLTFMeshParser() {
|
|
1792
|
-
return GLTFParser1.apply(this, arguments);
|
|
1793
|
-
}
|
|
1794
|
-
var _proto = GLTFMeshParser.prototype;
|
|
1795
|
-
_proto.parse = function parse(context) {
|
|
1796
|
-
var _loop = function(i) {
|
|
1797
|
-
var _loop = function(j) {
|
|
1798
|
-
var gltfPrimitive = gltfMesh.primitives[j];
|
|
1799
|
-
primitivePromises[j] = new Promise(function(resolve) {
|
|
1800
|
-
var mesh = GLTFParser.executeExtensionsCreateAndParse(gltfPrimitive.extensions, context, gltfPrimitive, gltfMesh);
|
|
1801
|
-
if (mesh) {
|
|
1802
|
-
if (_instanceof(mesh, ModelMesh)) {
|
|
1803
|
-
resolve(mesh);
|
|
1804
|
-
} else {
|
|
1805
|
-
mesh.then(function(mesh) {
|
|
1806
|
-
return resolve(mesh);
|
|
1807
|
-
});
|
|
1808
|
-
}
|
|
1809
|
-
} else {
|
|
1810
|
-
var mesh1 = new ModelMesh(engine, gltfMesh.name || j + "");
|
|
1811
|
-
var meshRestoreInfo = new ModelMeshRestoreInfo();
|
|
1812
|
-
meshRestoreInfo.mesh = mesh1;
|
|
1813
|
-
context.contentRestorer.meshes.push(meshRestoreInfo);
|
|
1814
|
-
GLTFMeshParser._parseMeshFromGLTFPrimitive(context, mesh1, meshRestoreInfo, gltfMesh, gltfPrimitive, glTF, function(attributeSemantic) {
|
|
1815
|
-
return null;
|
|
1816
|
-
}, function(attributeName, shapeIndex) {
|
|
1817
|
-
var shapeAccessorIdx = gltfPrimitive.targets[shapeIndex];
|
|
1818
|
-
var attributeAccessorIdx = shapeAccessorIdx[attributeName];
|
|
1819
|
-
if (attributeAccessorIdx) {
|
|
1820
|
-
var accessor = glTF.accessors[attributeAccessorIdx];
|
|
1821
|
-
return GLTFUtil.getAccessorBuffer(context, context.glTF.bufferViews, accessor);
|
|
1822
|
-
} else {
|
|
1823
|
-
return null;
|
|
1824
|
-
}
|
|
1825
|
-
}, function() {
|
|
1826
|
-
var indexAccessor = glTF.accessors[gltfPrimitive.indices];
|
|
1827
|
-
return GLTFUtil.getAccessorData(glTF, indexAccessor, buffers);
|
|
1828
|
-
}, context.keepMeshData).then(resolve);
|
|
1829
|
-
}
|
|
1830
|
-
});
|
|
1831
|
-
};
|
|
1832
|
-
var gltfMesh = glTF.meshes[i];
|
|
1833
|
-
var primitivePromises = [];
|
|
1834
|
-
for(var j = 0; j < gltfMesh.primitives.length; j++)_loop(j);
|
|
1835
|
-
meshPromises[i] = Promise.all(primitivePromises);
|
|
1836
|
-
};
|
|
1837
|
-
var glTF = context.glTF, buffers = context.buffers, glTFResource = context.glTFResource;
|
|
1838
|
-
var engine = glTFResource.engine;
|
|
1839
|
-
if (!glTF.meshes) return;
|
|
1787
|
+
if (!gltf.meshes) return;
|
|
1840
1788
|
var meshesPromiseInfo = context.meshesPromiseInfo;
|
|
1841
1789
|
var meshPromises = [];
|
|
1842
|
-
for(var i = 0; i <
|
|
1790
|
+
for(var i = 0; i < gltf.meshes.length; i++)_loop(i);
|
|
1843
1791
|
AssetPromise.all(meshPromises).then(function(meshes) {
|
|
1844
1792
|
glTFResource.meshes = meshes;
|
|
1845
1793
|
meshesPromiseInfo.resolve(meshes);
|
|
1846
1794
|
}).catch(meshesPromiseInfo.reject);
|
|
1847
1795
|
return meshesPromiseInfo.promise;
|
|
1848
1796
|
};
|
|
1849
|
-
|
|
1850
|
-
* @internal
|
|
1851
|
-
*/ 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) {
|
|
1852
1798
|
var accessors = gltf.accessors;
|
|
1853
1799
|
context.buffers;
|
|
1854
1800
|
var attributes = gltfPrimitive.attributes, targets = gltfPrimitive.targets, indices = gltfPrimitive.indices, mode = gltfPrimitive.mode;
|
|
@@ -1856,16 +1802,18 @@ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
1856
1802
|
var vertexElements = new Array();
|
|
1857
1803
|
var vertexCount;
|
|
1858
1804
|
var bufferBindIndex = 0;
|
|
1805
|
+
var positions;
|
|
1806
|
+
keepMeshData && (positions = new Array(vertexCount));
|
|
1859
1807
|
for(var attribute in attributes){
|
|
1860
1808
|
var accessor = accessors[attributes[attribute]];
|
|
1861
|
-
var accessorBuffer = GLTFUtil.getAccessorBuffer(context, gltf
|
|
1862
|
-
var
|
|
1809
|
+
var accessorBuffer = GLTFUtil.getAccessorBuffer(context, gltf, accessor);
|
|
1810
|
+
var dataElmentSize = GLTFUtil.getAccessorTypeSize(accessor.type);
|
|
1863
1811
|
var attributeCount = accessor.count;
|
|
1864
1812
|
var vertices = accessorBuffer.data;
|
|
1865
1813
|
var vertexElement = void 0;
|
|
1866
1814
|
var meshId = mesh.instanceId;
|
|
1867
1815
|
var vertexBindingInfos = accessorBuffer.vertexBindingInfos;
|
|
1868
|
-
var elementFormat = GLTFUtil.getElementFormat(accessor.componentType,
|
|
1816
|
+
var elementFormat = GLTFUtil.getElementFormat(accessor.componentType, dataElmentSize, accessor.normalized);
|
|
1869
1817
|
if (accessorBuffer.interleaved) {
|
|
1870
1818
|
var byteOffset = accessor.byteOffset || 0;
|
|
1871
1819
|
var stride = accessorBuffer.stride;
|
|
@@ -1877,7 +1825,6 @@ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
1877
1825
|
vertexBuffer = new Buffer(engine, BufferBindFlag.VertexBuffer, vertices.byteLength, BufferUsage.Static);
|
|
1878
1826
|
vertexBuffer.setData(vertices);
|
|
1879
1827
|
accessorBuffer.vertexBuffer = vertexBuffer;
|
|
1880
|
-
meshRestoreInfo.vertexBuffers.push(new BufferRestoreInfo(vertexBuffer, accessorBuffer.restoreInfo));
|
|
1881
1828
|
}
|
|
1882
1829
|
mesh.setVertexBufferBinding(vertexBuffer, stride, bufferBindIndex);
|
|
1883
1830
|
vertexBindingInfos[meshId] = bufferBindIndex++;
|
|
@@ -1888,7 +1835,6 @@ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
1888
1835
|
vertexElement = new VertexElement(attribute, 0, elementFormat, bufferBindIndex);
|
|
1889
1836
|
var vertexBuffer1 = new Buffer(engine, BufferBindFlag.VertexBuffer, vertices.byteLength, BufferUsage.Static);
|
|
1890
1837
|
vertexBuffer1.setData(vertices);
|
|
1891
|
-
meshRestoreInfo.vertexBuffers.push(new BufferRestoreInfo(vertexBuffer1, accessorBuffer.restoreInfo));
|
|
1892
1838
|
mesh.setVertexBufferBinding(vertexBuffer1, accessorBuffer.stride, bufferBindIndex);
|
|
1893
1839
|
vertexBindingInfos[meshId] = bufferBindIndex++;
|
|
1894
1840
|
}
|
|
@@ -1899,22 +1845,30 @@ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
1899
1845
|
if (accessor.min && accessor.max) {
|
|
1900
1846
|
min.copyFromArray(accessor.min);
|
|
1901
1847
|
max.copyFromArray(accessor.max);
|
|
1848
|
+
if (keepMeshData) {
|
|
1849
|
+
var stride1 = vertices.length / attributeCount;
|
|
1850
|
+
for(var j = 0; j < attributeCount; j++){
|
|
1851
|
+
var offset = j * stride1;
|
|
1852
|
+
positions[j] = new Vector3(vertices[offset], vertices[offset + 1], vertices[offset + 2]);
|
|
1853
|
+
}
|
|
1854
|
+
}
|
|
1902
1855
|
} else {
|
|
1903
|
-
var position =
|
|
1856
|
+
var position = MeshParser._tempVector3;
|
|
1904
1857
|
min.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
|
|
1905
1858
|
max.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
|
|
1906
|
-
var
|
|
1907
|
-
for(var
|
|
1908
|
-
var
|
|
1909
|
-
position.copyFromArray(vertices,
|
|
1859
|
+
var stride2 = vertices.length / attributeCount;
|
|
1860
|
+
for(var j1 = 0; j1 < attributeCount; j1++){
|
|
1861
|
+
var offset1 = j1 * stride2;
|
|
1862
|
+
position.copyFromArray(vertices, offset1);
|
|
1910
1863
|
Vector3.min(min, position, min);
|
|
1911
1864
|
Vector3.max(max, position, max);
|
|
1865
|
+
keepMeshData && (positions[j1] = position.clone());
|
|
1912
1866
|
}
|
|
1913
1867
|
}
|
|
1914
1868
|
if (accessor.normalized) {
|
|
1915
|
-
var
|
|
1916
|
-
min.scale(
|
|
1917
|
-
max.scale(
|
|
1869
|
+
var sacleFactor = GLTFUtil.getNormalizedComponentScale(accessor.componentType);
|
|
1870
|
+
min.scale(sacleFactor);
|
|
1871
|
+
max.scale(sacleFactor);
|
|
1918
1872
|
}
|
|
1919
1873
|
}
|
|
1920
1874
|
}
|
|
@@ -1922,68 +1876,179 @@ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
1922
1876
|
// Indices
|
|
1923
1877
|
if (indices !== undefined) {
|
|
1924
1878
|
var indexAccessor = gltf.accessors[indices];
|
|
1925
|
-
var
|
|
1926
|
-
mesh.setIndices(
|
|
1879
|
+
var indexData = getIndexBufferData();
|
|
1880
|
+
mesh.setIndices(indexData);
|
|
1927
1881
|
mesh.addSubMesh(0, indexAccessor.count, mode);
|
|
1928
|
-
meshRestoreInfo.indexBuffer = accessorBuffer1.restoreInfo;
|
|
1929
1882
|
} else {
|
|
1930
1883
|
mesh.addSubMesh(0, vertexCount, mode);
|
|
1931
1884
|
}
|
|
1932
1885
|
// BlendShapes
|
|
1933
|
-
targets &&
|
|
1886
|
+
targets && this._createBlendShape(mesh, gltfMesh, targets, getBlendShapeData);
|
|
1934
1887
|
mesh.uploadData(!keepMeshData);
|
|
1888
|
+
//@ts-ignore
|
|
1889
|
+
mesh._positions = positions;
|
|
1935
1890
|
return Promise.resolve(mesh);
|
|
1936
1891
|
};
|
|
1937
|
-
|
|
1938
|
-
* @internal
|
|
1939
|
-
*/ GLTFMeshParser._createBlendShape = function _createBlendShape(mesh, meshRestoreInfo, glTFMesh, glTFTargets, getBlendShapeData) {
|
|
1892
|
+
_proto._createBlendShape = function _createBlendShape(mesh, glTFMesh, glTFTargets, getBlendShapeData) {
|
|
1940
1893
|
var blendShapeNames = glTFMesh.extras ? glTFMesh.extras.targetNames : null;
|
|
1941
1894
|
for(var i = 0, n = glTFTargets.length; i < n; i++){
|
|
1942
1895
|
var name = blendShapeNames ? blendShapeNames[i] : "blendShape" + i;
|
|
1943
|
-
var
|
|
1944
|
-
var
|
|
1945
|
-
var
|
|
1946
|
-
var deltaPositions =
|
|
1947
|
-
var deltaNormals =
|
|
1948
|
-
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;
|
|
1949
1902
|
var blendShape = new BlendShape(name);
|
|
1950
1903
|
blendShape.addFrame(1.0, deltaPositions, deltaNormals, deltaTangents);
|
|
1951
1904
|
mesh.addBlendShape(blendShape);
|
|
1952
|
-
meshRestoreInfo.blendShapes.push(new BlendShapeRestoreInfo(blendShape, deltaPosBufferInfo.restoreInfo, deltaNorBufferInfo == null ? void 0 : deltaNorBufferInfo.restoreInfo, deltaTanBufferInfo == null ? void 0 : deltaTanBufferInfo.restoreInfo));
|
|
1953
1905
|
}
|
|
1954
1906
|
};
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
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);
|
|
2011
|
+
(function() {
|
|
2012
|
+
MeshParser._tempVector3 = new Vector3();
|
|
2013
|
+
})();
|
|
1958
2014
|
|
|
1959
|
-
var
|
|
1960
|
-
_inherits(
|
|
1961
|
-
function
|
|
1962
|
-
return
|
|
2015
|
+
var SceneParser$1 = /*#__PURE__*/ function(Parser1) {
|
|
2016
|
+
_inherits(SceneParser, Parser1);
|
|
2017
|
+
function SceneParser() {
|
|
2018
|
+
return Parser1.apply(this, arguments);
|
|
1963
2019
|
}
|
|
1964
|
-
var _proto =
|
|
2020
|
+
var _proto = SceneParser.prototype;
|
|
1965
2021
|
_proto.parse = function parse(context) {
|
|
1966
|
-
var glTFResource = context.glTFResource,
|
|
2022
|
+
var glTFResource = context.glTFResource, gltf = context.gltf;
|
|
1967
2023
|
var entities = glTFResource.entities;
|
|
1968
|
-
var nodes =
|
|
2024
|
+
var nodes = gltf.nodes, gltfCameras = gltf.cameras;
|
|
1969
2025
|
if (!nodes) return;
|
|
1970
2026
|
var defaultSceneRootPromiseInfo = context.defaultSceneRootPromiseInfo;
|
|
2027
|
+
var promises = [];
|
|
1971
2028
|
for(var i = 0; i < nodes.length; i++){
|
|
1972
|
-
var
|
|
1973
|
-
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;
|
|
1974
2032
|
var entity = entities[i];
|
|
1975
2033
|
if (cameraID !== undefined) {
|
|
1976
|
-
this._createCamera(glTFResource,
|
|
2034
|
+
this._createCamera(glTFResource, gltfCameras[cameraID], entity);
|
|
1977
2035
|
}
|
|
1978
2036
|
if (meshID !== undefined) {
|
|
1979
|
-
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);
|
|
1980
2043
|
}
|
|
1981
|
-
GLTFParser.executeExtensionsAdditiveAndParse(extensions, context, entity, glTFNode);
|
|
1982
2044
|
}
|
|
1983
2045
|
if (glTFResource.defaultSceneRoot) {
|
|
1984
2046
|
this._createAnimator(context);
|
|
1985
2047
|
}
|
|
1986
|
-
|
|
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);
|
|
1987
2052
|
return defaultSceneRootPromiseInfo.promise;
|
|
1988
2053
|
};
|
|
1989
2054
|
_proto._createCamera = function _createCamera(context, cameraSchema, entity) {
|
|
@@ -2019,16 +2084,8 @@ var GLTFSceneParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
2019
2084
|
// @todo: use engine camera by default
|
|
2020
2085
|
camera.enabled = false;
|
|
2021
2086
|
};
|
|
2022
|
-
_proto._createRenderer = function _createRenderer(context,
|
|
2023
|
-
var
|
|
2024
|
-
var glTFMeshes = glTF.meshes;
|
|
2025
|
-
var engine = glTFResource.engine, meshes = glTFResource.meshes, materials = glTFResource.materials, skins = glTFResource.skins;
|
|
2026
|
-
var meshID = glTFNode.mesh, skinID = glTFNode.skin;
|
|
2027
|
-
var glTFMesh = glTFMeshes[meshID];
|
|
2028
|
-
var glTFMeshPrimitives = glTFMesh.primitives;
|
|
2029
|
-
var blendShapeWeights = glTFNode.weights || glTFMesh.weights;
|
|
2030
|
-
for(var i = 0; i < glTFMeshPrimitives.length; i++){
|
|
2031
|
-
var gltfPrimitive = glTFMeshPrimitives[i];
|
|
2087
|
+
_proto._createRenderer = function _createRenderer(context, gltfNode, entity) {
|
|
2088
|
+
var _loop = function(i) {
|
|
2032
2089
|
var mesh = meshes[meshID][i];
|
|
2033
2090
|
var renderer = void 0;
|
|
2034
2091
|
if (skinID !== undefined || blendShapeWeights) {
|
|
@@ -2046,11 +2103,32 @@ var GLTFSceneParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
2046
2103
|
renderer = entity.addComponent(MeshRenderer);
|
|
2047
2104
|
renderer.mesh = mesh;
|
|
2048
2105
|
}
|
|
2049
|
-
var materialIndex =
|
|
2050
|
-
var
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
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);
|
|
2054
2132
|
};
|
|
2055
2133
|
_proto._createAnimator = function _createAnimator(context) {
|
|
2056
2134
|
if (!context.hasSkinned && !context.glTFResource.animations) {
|
|
@@ -2077,25 +2155,25 @@ var GLTFSceneParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
2077
2155
|
}
|
|
2078
2156
|
}
|
|
2079
2157
|
};
|
|
2080
|
-
|
|
2081
|
-
if (!
|
|
2082
|
-
|
|
2158
|
+
SceneParser._getDefaultMaterial = function _getDefaultMaterial(engine) {
|
|
2159
|
+
if (!SceneParser._defaultMaterial) {
|
|
2160
|
+
SceneParser._defaultMaterial = new BlinnPhongMaterial(engine);
|
|
2083
2161
|
}
|
|
2084
|
-
return
|
|
2162
|
+
return SceneParser._defaultMaterial;
|
|
2085
2163
|
};
|
|
2086
|
-
return
|
|
2087
|
-
}(
|
|
2164
|
+
return SceneParser;
|
|
2165
|
+
}(Parser);
|
|
2088
2166
|
|
|
2089
|
-
var
|
|
2090
|
-
_inherits(
|
|
2091
|
-
function
|
|
2092
|
-
return
|
|
2167
|
+
var SkinParser = /*#__PURE__*/ function(Parser) {
|
|
2168
|
+
_inherits(SkinParser, Parser);
|
|
2169
|
+
function SkinParser() {
|
|
2170
|
+
return Parser.apply(this, arguments);
|
|
2093
2171
|
}
|
|
2094
|
-
var _proto =
|
|
2172
|
+
var _proto = SkinParser.prototype;
|
|
2095
2173
|
_proto.parse = function parse(context) {
|
|
2096
|
-
var glTFResource = context.glTFResource,
|
|
2174
|
+
var glTFResource = context.glTFResource, gltf = context.gltf; context.buffers;
|
|
2097
2175
|
var entities = glTFResource.entities;
|
|
2098
|
-
var gltfSkins =
|
|
2176
|
+
var gltfSkins = gltf.skins;
|
|
2099
2177
|
if (!gltfSkins) return;
|
|
2100
2178
|
var count = gltfSkins.length;
|
|
2101
2179
|
var skins = new Array(count);
|
|
@@ -2105,8 +2183,8 @@ var GLTFSkinParser = /*#__PURE__*/ function(GLTFParser) {
|
|
|
2105
2183
|
var skin = new Skin(name);
|
|
2106
2184
|
skin.inverseBindMatrices.length = jointCount;
|
|
2107
2185
|
// parse IBM
|
|
2108
|
-
var accessor =
|
|
2109
|
-
var buffer = GLTFUtil.getAccessorBuffer(context,
|
|
2186
|
+
var accessor = gltf.accessors[inverseBindMatrices];
|
|
2187
|
+
var buffer = GLTFUtil.getAccessorBuffer(context, gltf, accessor).data;
|
|
2110
2188
|
for(var i1 = 0; i1 < jointCount; i1++){
|
|
2111
2189
|
var inverseBindMatrix = new Matrix();
|
|
2112
2190
|
inverseBindMatrix.copyFromArray(buffer, i1 * 16);
|
|
@@ -2141,7 +2219,7 @@ var GLTFSkinParser = /*#__PURE__*/ function(GLTFParser) {
|
|
|
2141
2219
|
};
|
|
2142
2220
|
_proto._findSkeletonRootBone = function _findSkeletonRootBone(joints, entities) {
|
|
2143
2221
|
var paths = {};
|
|
2144
|
-
for(var _iterator =
|
|
2222
|
+
for(var _iterator = _create_for_of_iterator_helper_loose(joints), _step; !(_step = _iterator()).done;){
|
|
2145
2223
|
var index = _step.value;
|
|
2146
2224
|
var path = new Array();
|
|
2147
2225
|
var entity = entities[index];
|
|
@@ -2167,24 +2245,24 @@ var GLTFSkinParser = /*#__PURE__*/ function(GLTFParser) {
|
|
|
2167
2245
|
rootNode = entity1;
|
|
2168
2246
|
}
|
|
2169
2247
|
};
|
|
2170
|
-
return
|
|
2171
|
-
}(
|
|
2248
|
+
return SkinParser;
|
|
2249
|
+
}(Parser);
|
|
2172
2250
|
|
|
2173
|
-
var
|
|
2174
|
-
_inherits(
|
|
2175
|
-
function
|
|
2176
|
-
return
|
|
2251
|
+
var TextureParser = /*#__PURE__*/ function(Parser) {
|
|
2252
|
+
_inherits(TextureParser, Parser);
|
|
2253
|
+
function TextureParser() {
|
|
2254
|
+
return Parser.apply(this, arguments);
|
|
2177
2255
|
}
|
|
2178
|
-
var _proto =
|
|
2256
|
+
var _proto = TextureParser.prototype;
|
|
2179
2257
|
_proto.parse = function parse(context) {
|
|
2180
2258
|
var _this = this;
|
|
2181
|
-
var glTFResource = context.glTFResource,
|
|
2259
|
+
var glTFResource = context.glTFResource, gltf = context.gltf, buffers = context.buffers;
|
|
2182
2260
|
var engine = glTFResource.engine, url = glTFResource.url;
|
|
2183
|
-
if (
|
|
2261
|
+
if (gltf.textures) {
|
|
2184
2262
|
var texturesPromiseInfo = context.texturesPromiseInfo;
|
|
2185
|
-
AssetPromise.all(
|
|
2263
|
+
AssetPromise.all(gltf.textures.map(function(param, index) {
|
|
2186
2264
|
var sampler = param.sampler, _param_source = param.source, source = _param_source === void 0 ? 0 : _param_source, textureName = param.name;
|
|
2187
|
-
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;
|
|
2188
2266
|
if (uri) {
|
|
2189
2267
|
// TODO: support ktx extension https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_texture_basisu/README.md
|
|
2190
2268
|
var index1 = uri.lastIndexOf(".");
|
|
@@ -2198,24 +2276,21 @@ var GLTFTextureParser = /*#__PURE__*/ function(GLTFParser) {
|
|
|
2198
2276
|
texture.name = textureName || imageName || "texture_" + index1;
|
|
2199
2277
|
}
|
|
2200
2278
|
if (sampler !== undefined) {
|
|
2201
|
-
_this._parseSampler(texture,
|
|
2279
|
+
_this._parseSampler(texture, gltf.samplers[sampler]);
|
|
2202
2280
|
}
|
|
2203
2281
|
return texture;
|
|
2204
2282
|
});
|
|
2205
2283
|
} else {
|
|
2206
|
-
var bufferView =
|
|
2207
|
-
var
|
|
2208
|
-
|
|
2209
|
-
return GLTFUtil.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) {
|
|
2210
2287
|
var texture = new Texture2D(engine, image.width, image.height);
|
|
2211
2288
|
texture.setImageSource(image);
|
|
2212
2289
|
texture.generateMipmaps();
|
|
2213
2290
|
texture.name = textureName || imageName || "texture_" + index;
|
|
2214
2291
|
if (sampler !== undefined) {
|
|
2215
|
-
_this._parseSampler(texture,
|
|
2292
|
+
_this._parseSampler(texture, gltf.samplers[sampler]);
|
|
2216
2293
|
}
|
|
2217
|
-
var bufferTextureRestoreInfo = new BufferTextureRestoreInfo(texture, bufferView, mimeType);
|
|
2218
|
-
context.contentRestorer.bufferTextures.push(bufferTextureRestoreInfo);
|
|
2219
2294
|
return texture;
|
|
2220
2295
|
});
|
|
2221
2296
|
}
|
|
@@ -2238,36 +2313,36 @@ var GLTFTextureParser = /*#__PURE__*/ function(GLTFParser) {
|
|
|
2238
2313
|
}
|
|
2239
2314
|
}
|
|
2240
2315
|
if (wrapS) {
|
|
2241
|
-
texture.wrapModeU =
|
|
2316
|
+
texture.wrapModeU = TextureParser._wrapMap[wrapS];
|
|
2242
2317
|
}
|
|
2243
2318
|
if (wrapT) {
|
|
2244
|
-
texture.wrapModeV =
|
|
2319
|
+
texture.wrapModeV = TextureParser._wrapMap[wrapT];
|
|
2245
2320
|
}
|
|
2246
2321
|
};
|
|
2247
|
-
return
|
|
2248
|
-
}(
|
|
2249
|
-
|
|
2250
|
-
|
|
2322
|
+
return TextureParser;
|
|
2323
|
+
}(Parser);
|
|
2324
|
+
(function() {
|
|
2325
|
+
var _obj;
|
|
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);
|
|
2327
|
+
})();
|
|
2251
2328
|
|
|
2252
|
-
var
|
|
2253
|
-
_inherits(
|
|
2254
|
-
function
|
|
2255
|
-
return
|
|
2329
|
+
var Validator = /*#__PURE__*/ function(Parser1) {
|
|
2330
|
+
_inherits(Validator, Parser1);
|
|
2331
|
+
function Validator() {
|
|
2332
|
+
return Parser1.apply(this, arguments);
|
|
2256
2333
|
}
|
|
2257
|
-
var _proto =
|
|
2334
|
+
var _proto = Validator.prototype;
|
|
2258
2335
|
_proto.parse = function parse(context) {
|
|
2259
|
-
var
|
|
2260
|
-
var
|
|
2261
|
-
if (!(
|
|
2262
|
-
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.";
|
|
2263
2340
|
}
|
|
2264
|
-
var promises = [];
|
|
2265
2341
|
if (extensionsUsed) {
|
|
2266
2342
|
Logger.info("extensionsUsed: ", extensionsUsed);
|
|
2267
2343
|
for(var i = 0; i < extensionsUsed.length; i++){
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
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.");
|
|
2271
2346
|
}
|
|
2272
2347
|
}
|
|
2273
2348
|
}
|
|
@@ -2275,66 +2350,68 @@ var GLTFValidator = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
2275
2350
|
Logger.info("extensionsRequired: " + extensionsRequired);
|
|
2276
2351
|
for(var i1 = 0; i1 < extensionsRequired.length; i1++){
|
|
2277
2352
|
var extensionRequired = extensionsRequired[i1];
|
|
2278
|
-
if (!
|
|
2353
|
+
if (!Parser.hasExtensionParser(extensionRequired)) {
|
|
2279
2354
|
Logger.error("GLTF parser has not supported required extension " + extensionRequired + ".");
|
|
2280
2355
|
} else {
|
|
2281
|
-
|
|
2356
|
+
Parser.initialize(extensionRequired);
|
|
2282
2357
|
}
|
|
2283
2358
|
}
|
|
2284
2359
|
}
|
|
2285
|
-
return AssetPromise.all(promises).then(null);
|
|
2286
2360
|
};
|
|
2287
|
-
return
|
|
2288
|
-
}(
|
|
2361
|
+
return Validator;
|
|
2362
|
+
}(Parser);
|
|
2289
2363
|
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
*/ var GLTFPipeline = /*#__PURE__*/ function() {
|
|
2293
|
-
function GLTFPipeline() {
|
|
2294
|
-
for(var _len = arguments.length, parsers = new Array(_len), _key = 0; _key < _len; _key++){
|
|
2295
|
-
parsers[_key] = arguments[_key];
|
|
2296
|
-
}
|
|
2364
|
+
var GLTFParser = /*#__PURE__*/ function() {
|
|
2365
|
+
function GLTFParser(pipes) {
|
|
2297
2366
|
var _this = this;
|
|
2298
|
-
this.
|
|
2299
|
-
|
|
2300
|
-
_this.
|
|
2367
|
+
this._pipes = [];
|
|
2368
|
+
pipes.forEach(function(pipe, index) {
|
|
2369
|
+
_this._pipes[index] = new pipe();
|
|
2301
2370
|
});
|
|
2302
2371
|
}
|
|
2303
|
-
var _proto =
|
|
2304
|
-
|
|
2305
|
-
* @internal
|
|
2306
|
-
*/ _proto._parse = function _parse(context) {
|
|
2372
|
+
var _proto = GLTFParser.prototype;
|
|
2373
|
+
_proto.parse = function parse(context) {
|
|
2307
2374
|
var _this = this;
|
|
2308
2375
|
var glTFResource = context.glTFResource;
|
|
2309
|
-
var
|
|
2376
|
+
var lastPipe;
|
|
2310
2377
|
return new AssetPromise(function(resolve, reject) {
|
|
2311
|
-
_this.
|
|
2312
|
-
if (
|
|
2313
|
-
|
|
2378
|
+
_this._pipes.forEach(function(parser) {
|
|
2379
|
+
if (lastPipe) {
|
|
2380
|
+
lastPipe = lastPipe.then(function() {
|
|
2314
2381
|
return parser.parse(context);
|
|
2315
2382
|
});
|
|
2316
|
-
if (
|
|
2317
|
-
context.chainPromises.push(
|
|
2383
|
+
if (lastPipe.cancel) {
|
|
2384
|
+
context.chainPromises.push(lastPipe);
|
|
2318
2385
|
}
|
|
2319
2386
|
} else {
|
|
2320
|
-
|
|
2387
|
+
lastPipe = parser.parse(context);
|
|
2321
2388
|
}
|
|
2322
2389
|
});
|
|
2323
|
-
if (
|
|
2324
|
-
|
|
2390
|
+
if (lastPipe) {
|
|
2391
|
+
lastPipe.then(function() {
|
|
2325
2392
|
resolve(glTFResource);
|
|
2326
2393
|
}).catch(reject);
|
|
2327
2394
|
}
|
|
2328
2395
|
});
|
|
2329
2396
|
};
|
|
2330
|
-
return
|
|
2397
|
+
return GLTFParser;
|
|
2331
2398
|
}();
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2399
|
+
(function() {
|
|
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
|
+
]);
|
|
2411
|
+
})();
|
|
2335
2412
|
|
|
2336
2413
|
/**
|
|
2337
|
-
* Product after
|
|
2414
|
+
* Product after GLTF parser, usually, `defaultSceneRoot` is only needed to use.
|
|
2338
2415
|
*/ var GLTFResource = /*#__PURE__*/ function(EngineObject) {
|
|
2339
2416
|
_inherits(GLTFResource, EngineObject);
|
|
2340
2417
|
function GLTFResource(engine, url) {
|
|
@@ -2346,8 +2423,11 @@ var GLTFValidator = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
2346
2423
|
var _proto = GLTFResource.prototype;
|
|
2347
2424
|
/**
|
|
2348
2425
|
* @override
|
|
2349
|
-
*/ _proto.
|
|
2350
|
-
|
|
2426
|
+
*/ _proto.destroy = function destroy() {
|
|
2427
|
+
if (this._destroyed) {
|
|
2428
|
+
return;
|
|
2429
|
+
}
|
|
2430
|
+
EngineObject.prototype.destroy.call(this);
|
|
2351
2431
|
this.defaultSceneRoot.destroy();
|
|
2352
2432
|
this.textures = null;
|
|
2353
2433
|
this.materials = null;
|
|
@@ -2358,7 +2438,7 @@ var GLTFValidator = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
2358
2438
|
this.cameras = null;
|
|
2359
2439
|
this.lights = null;
|
|
2360
2440
|
this.sceneRoots = null;
|
|
2361
|
-
this.
|
|
2441
|
+
this.variants = null;
|
|
2362
2442
|
};
|
|
2363
2443
|
return GLTFResource;
|
|
2364
2444
|
}(EngineObject);
|
|
@@ -2369,30 +2449,23 @@ var GLTFLoader = /*#__PURE__*/ function(Loader) {
|
|
|
2369
2449
|
return Loader.apply(this, arguments);
|
|
2370
2450
|
}
|
|
2371
2451
|
var _proto = GLTFLoader.prototype;
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
*/ _proto.load = function load(item, resourceManager) {
|
|
2452
|
+
_proto.load = function load(item, resourceManager) {
|
|
2453
|
+
var _item_params;
|
|
2375
2454
|
var url = item.url;
|
|
2376
|
-
var
|
|
2377
|
-
var context = new GLTFParserContext(url);
|
|
2455
|
+
var context = new ParserContext(url);
|
|
2378
2456
|
var glTFResource = new GLTFResource(resourceManager.engine, url);
|
|
2379
|
-
var restorer = new GLTFContentRestorer(glTFResource);
|
|
2380
2457
|
var masterPromiseInfo = context.masterPromiseInfo;
|
|
2381
|
-
context.contentRestorer = restorer;
|
|
2382
2458
|
context.glTFResource = glTFResource;
|
|
2383
|
-
var
|
|
2384
|
-
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;
|
|
2385
2461
|
masterPromiseInfo.onCancel(function() {
|
|
2386
2462
|
var chainPromises = context.chainPromises;
|
|
2387
|
-
for(var _iterator =
|
|
2463
|
+
for(var _iterator = _create_for_of_iterator_helper_loose(chainPromises), _step; !(_step = _iterator()).done;){
|
|
2388
2464
|
var promise = _step.value;
|
|
2389
2465
|
promise.cancel();
|
|
2390
2466
|
}
|
|
2391
2467
|
});
|
|
2392
|
-
|
|
2393
|
-
resourceManager.addContentRestorer(restorer);
|
|
2394
|
-
masterPromiseInfo.resolve(glTFResource);
|
|
2395
|
-
}).catch(function(e) {
|
|
2468
|
+
GLTFParser.defaultPipeline.parse(context).then(masterPromiseInfo.resolve).catch(function(e) {
|
|
2396
2469
|
console.error(e);
|
|
2397
2470
|
masterPromiseInfo.reject("Error loading glTF model from " + url + " .");
|
|
2398
2471
|
});
|
|
@@ -2401,7 +2474,7 @@ var GLTFLoader = /*#__PURE__*/ function(Loader) {
|
|
|
2401
2474
|
return GLTFLoader;
|
|
2402
2475
|
}(Loader);
|
|
2403
2476
|
GLTFLoader = __decorate([
|
|
2404
|
-
resourceLoader(AssetType.
|
|
2477
|
+
resourceLoader(AssetType.Prefab, [
|
|
2405
2478
|
"gltf",
|
|
2406
2479
|
"glb"
|
|
2407
2480
|
])
|
|
@@ -2648,37 +2721,75 @@ var HDRLoader = (_HDRLoader = /*#__PURE__*/ function(Loader) {
|
|
|
2648
2721
|
color.a *= M;
|
|
2649
2722
|
};
|
|
2650
2723
|
return HDRLoader1;
|
|
2651
|
-
}(Loader),
|
|
2652
|
-
_HDRLoader._rightBottomBack,
|
|
2653
|
-
|
|
2654
|
-
_HDRLoader.
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
_HDRLoader.
|
|
2659
|
-
|
|
2660
|
-
_HDRLoader.
|
|
2661
|
-
|
|
2662
|
-
_HDRLoader._leftBottomFront,
|
|
2663
|
-
|
|
2664
|
-
_HDRLoader.
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
_HDRLoader.
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
_HDRLoader.
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2724
|
+
}(Loader), function() {
|
|
2725
|
+
_HDRLoader._rightBottomBack = new Vector3(1.0, -1.0, -1.0);
|
|
2726
|
+
}(), function() {
|
|
2727
|
+
_HDRLoader._rightBottomFront = new Vector3(1.0, -1.0, 1.0);
|
|
2728
|
+
}(), function() {
|
|
2729
|
+
_HDRLoader._rightUpBack = new Vector3(1.0, 1.0, -1.0);
|
|
2730
|
+
}(), function() {
|
|
2731
|
+
_HDRLoader._rightUpFront = new Vector3(1.0, 1.0, 1.0);
|
|
2732
|
+
}(), function() {
|
|
2733
|
+
_HDRLoader._leftBottomBack = new Vector3(-1.0, -1.0, -1.0);
|
|
2734
|
+
}(), function() {
|
|
2735
|
+
_HDRLoader._leftBottomFront = new Vector3(-1.0, -1.0, 1.0);
|
|
2736
|
+
}(), function() {
|
|
2737
|
+
_HDRLoader._leftUpBack = new Vector3(-1.0, 1.0, -1.0);
|
|
2738
|
+
}(), function() {
|
|
2739
|
+
_HDRLoader._leftUpFront = new Vector3(-1.0, 1.0, 1.0);
|
|
2740
|
+
}(), function() {
|
|
2741
|
+
_HDRLoader._faceRight = [
|
|
2742
|
+
_HDRLoader._rightBottomBack,
|
|
2743
|
+
_HDRLoader._rightBottomFront,
|
|
2744
|
+
_HDRLoader._rightUpBack,
|
|
2745
|
+
_HDRLoader._rightUpFront
|
|
2746
|
+
];
|
|
2747
|
+
}(), function() {
|
|
2748
|
+
_HDRLoader._faceLeft = [
|
|
2749
|
+
_HDRLoader._leftBottomFront,
|
|
2750
|
+
_HDRLoader._leftBottomBack,
|
|
2751
|
+
_HDRLoader._leftUpFront,
|
|
2752
|
+
_HDRLoader._leftUpBack
|
|
2753
|
+
];
|
|
2754
|
+
}(), function() {
|
|
2755
|
+
_HDRLoader._faceUp = [
|
|
2756
|
+
_HDRLoader._leftBottomFront,
|
|
2757
|
+
_HDRLoader._rightBottomFront,
|
|
2758
|
+
_HDRLoader._leftBottomBack,
|
|
2759
|
+
_HDRLoader._rightBottomBack
|
|
2760
|
+
];
|
|
2761
|
+
}(), function() {
|
|
2762
|
+
_HDRLoader._faceBottom = [
|
|
2763
|
+
_HDRLoader._leftUpBack,
|
|
2764
|
+
_HDRLoader._rightUpBack,
|
|
2765
|
+
_HDRLoader._leftUpFront,
|
|
2766
|
+
_HDRLoader._rightUpFront
|
|
2767
|
+
];
|
|
2768
|
+
}(), function() {
|
|
2769
|
+
_HDRLoader._faceFront = [
|
|
2770
|
+
_HDRLoader._leftBottomBack,
|
|
2771
|
+
_HDRLoader._rightBottomBack,
|
|
2772
|
+
_HDRLoader._leftUpBack,
|
|
2773
|
+
_HDRLoader._rightUpBack
|
|
2774
|
+
];
|
|
2775
|
+
}(), function() {
|
|
2776
|
+
_HDRLoader._faceBack = [
|
|
2777
|
+
_HDRLoader._rightBottomFront,
|
|
2778
|
+
_HDRLoader._leftBottomFront,
|
|
2779
|
+
_HDRLoader._rightUpFront,
|
|
2780
|
+
_HDRLoader._leftUpFront
|
|
2781
|
+
];
|
|
2782
|
+
}(), function() {
|
|
2783
|
+
_HDRLoader._tempVector3 = new Vector3();
|
|
2784
|
+
}(), function() {
|
|
2785
|
+
_HDRLoader._temp2Vector3 = new Vector3();
|
|
2786
|
+
}(), function() {
|
|
2787
|
+
_HDRLoader._temp3Vector3 = new Vector3();
|
|
2788
|
+
}(), function() {
|
|
2789
|
+
_HDRLoader._temp4Vector3 = new Vector3();
|
|
2790
|
+
}(), function() {
|
|
2791
|
+
_HDRLoader._temp5Vector3 = new Vector3();
|
|
2792
|
+
}(), _HDRLoader);
|
|
2682
2793
|
HDRLoader = __decorate([
|
|
2683
2794
|
resourceLoader(AssetType.HDR, [
|
|
2684
2795
|
"hdr"
|
|
@@ -3048,19 +3159,21 @@ MaterialLoader = __decorate([
|
|
|
3048
3159
|
], MaterialLoader);
|
|
3049
3160
|
|
|
3050
3161
|
function _defineProperties(target, props) {
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3162
|
+
for (var i = 0; i < props.length; i++) {
|
|
3163
|
+
var descriptor = props[i];
|
|
3164
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
3165
|
+
descriptor.configurable = true;
|
|
3166
|
+
|
|
3167
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
3168
|
+
|
|
3169
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
3170
|
+
}
|
|
3058
3171
|
}
|
|
3172
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
3173
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
3174
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
3059
3175
|
|
|
3060
|
-
|
|
3061
|
-
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
3062
|
-
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
3063
|
-
return Constructor;
|
|
3176
|
+
return Constructor;
|
|
3064
3177
|
}
|
|
3065
3178
|
|
|
3066
3179
|
var BufferReader = /*#__PURE__*/ function() {
|
|
@@ -3169,7 +3282,7 @@ var BufferReader = /*#__PURE__*/ function() {
|
|
|
3169
3282
|
if (byteLength < maxByteLength) this._offset++;
|
|
3170
3283
|
return new Uint8Array(this._dataView.buffer, this._dataView.byteOffset + byteOffset, byteLength);
|
|
3171
3284
|
};
|
|
3172
|
-
|
|
3285
|
+
_create_class(BufferReader, [
|
|
3173
3286
|
{
|
|
3174
3287
|
key: "offset",
|
|
3175
3288
|
get: function get() {
|
|
@@ -3179,12 +3292,14 @@ var BufferReader = /*#__PURE__*/ function() {
|
|
|
3179
3292
|
]);
|
|
3180
3293
|
return BufferReader;
|
|
3181
3294
|
}();
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
|
|
3295
|
+
(function() {
|
|
3296
|
+
BufferReader.imageMapping = {
|
|
3297
|
+
0: "image/png",
|
|
3298
|
+
1: "image/jpg",
|
|
3299
|
+
2: "image/webp",
|
|
3300
|
+
3: "ktx"
|
|
3301
|
+
};
|
|
3302
|
+
})();
|
|
3188
3303
|
|
|
3189
3304
|
var decoderMap = {};
|
|
3190
3305
|
/**
|
|
@@ -3223,7 +3338,7 @@ var FileHeader = /*#__PURE__*/ function() {
|
|
|
3223
3338
|
header.headerLength = nameUint8Array.byteLength + typeUint8Array.byteLength + 9;
|
|
3224
3339
|
return header;
|
|
3225
3340
|
};
|
|
3226
|
-
|
|
3341
|
+
_create_class(FileHeader, [
|
|
3227
3342
|
{
|
|
3228
3343
|
key: "dataLength",
|
|
3229
3344
|
get: function get() {
|
|
@@ -3442,38 +3557,36 @@ Texture2DDecoder = __decorate([
|
|
|
3442
3557
|
decoder("Texture2D")
|
|
3443
3558
|
], Texture2DDecoder);
|
|
3444
3559
|
|
|
3445
|
-
function
|
|
3446
|
-
|
|
3447
|
-
|
|
3448
|
-
|
|
3449
|
-
|
|
3450
|
-
try {
|
|
3451
|
-
Date.prototype.toString.call(Reflect.construct(Date, [], function () { }));
|
|
3452
|
-
return true;
|
|
3453
|
-
} catch (e) {
|
|
3454
|
-
return false;
|
|
3455
|
-
}
|
|
3456
|
-
}
|
|
3560
|
+
function _is_native_reflect_construct() {
|
|
3561
|
+
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
|
3562
|
+
if (Reflect.construct.sham) return false;
|
|
3563
|
+
if (typeof Proxy === "function") return true;
|
|
3457
3564
|
|
|
3458
|
-
|
|
3459
|
-
|
|
3460
|
-
construct = Reflect.construct;
|
|
3461
|
-
} else {
|
|
3462
|
-
construct = function construct(Parent, args, Class) {
|
|
3463
|
-
var a = [null];
|
|
3464
|
-
a.push.apply(a, args);
|
|
3465
|
-
var Constructor = Function.bind.apply(Parent, a);
|
|
3466
|
-
var instance = new Constructor();
|
|
3467
|
-
if (Class) _setPrototypeOf(instance, Class.prototype);
|
|
3468
|
-
return instance;
|
|
3469
|
-
};
|
|
3470
|
-
}
|
|
3565
|
+
try {
|
|
3566
|
+
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
|
3471
3567
|
|
|
3472
|
-
|
|
3568
|
+
return true;
|
|
3569
|
+
} catch (e) {
|
|
3570
|
+
return false;
|
|
3571
|
+
}
|
|
3473
3572
|
}
|
|
3474
3573
|
|
|
3475
3574
|
function _construct(Parent, args, Class) {
|
|
3476
|
-
|
|
3575
|
+
if (_is_native_reflect_construct()) _construct = Reflect.construct;
|
|
3576
|
+
else {
|
|
3577
|
+
_construct = function construct(Parent, args, Class) {
|
|
3578
|
+
var a = [null];
|
|
3579
|
+
a.push.apply(a, args);
|
|
3580
|
+
var Constructor = Function.bind.apply(Parent, a);
|
|
3581
|
+
var instance = new Constructor();
|
|
3582
|
+
|
|
3583
|
+
if (Class) _set_prototype_of(instance, Class.prototype);
|
|
3584
|
+
|
|
3585
|
+
return instance;
|
|
3586
|
+
};
|
|
3587
|
+
}
|
|
3588
|
+
|
|
3589
|
+
return _construct.apply(null, arguments);
|
|
3477
3590
|
}
|
|
3478
3591
|
|
|
3479
3592
|
var ReflectionParser = /*#__PURE__*/ function() {
|
|
@@ -3588,7 +3701,9 @@ var ReflectionParser = /*#__PURE__*/ function() {
|
|
|
3588
3701
|
};
|
|
3589
3702
|
return ReflectionParser;
|
|
3590
3703
|
}();
|
|
3591
|
-
|
|
3704
|
+
(function() {
|
|
3705
|
+
ReflectionParser.customParseComponentHandles = new Map();
|
|
3706
|
+
})();
|
|
3592
3707
|
|
|
3593
3708
|
var PrefabParser = /*#__PURE__*/ function() {
|
|
3594
3709
|
function PrefabParser() {}
|
|
@@ -3842,7 +3957,7 @@ var SceneParserContext = /*#__PURE__*/ function() {
|
|
|
3842
3957
|
};
|
|
3843
3958
|
_proto._organizeEntities = function _organizeEntities() {
|
|
3844
3959
|
var _this_context = this.context, entityConfigMap = _this_context.entityConfigMap, entityMap = _this_context.entityMap, scene = _this_context.scene, rootIds = _this_context.rootIds;
|
|
3845
|
-
for(var _iterator =
|
|
3960
|
+
for(var _iterator = _create_for_of_iterator_helper_loose(rootIds), _step; !(_step = _iterator()).done;){
|
|
3846
3961
|
var rootId = _step.value;
|
|
3847
3962
|
PrefabParser.parseChildren(entityConfigMap, entityMap, rootId);
|
|
3848
3963
|
}
|
|
@@ -4006,7 +4121,7 @@ var SourceFontLoader = /*#__PURE__*/ function(Loader) {
|
|
|
4006
4121
|
});
|
|
4007
4122
|
};
|
|
4008
4123
|
_proto._registerFont = function _registerFont(fontName, fontUrl) {
|
|
4009
|
-
return
|
|
4124
|
+
return _async_to_generator(function() {
|
|
4010
4125
|
var fontFace;
|
|
4011
4126
|
return __generator(this, function(_state) {
|
|
4012
4127
|
switch(_state.label){
|
|
@@ -4043,6 +4158,7 @@ var SpriteAtlasLoader = /*#__PURE__*/ function(Loader) {
|
|
|
4043
4158
|
_this = Loader.apply(this, arguments) || this;
|
|
4044
4159
|
_this._tempRect = new Rect();
|
|
4045
4160
|
_this._tempVec2 = new Vector2();
|
|
4161
|
+
_this._tempVec4 = new Vector4();
|
|
4046
4162
|
return _this;
|
|
4047
4163
|
}
|
|
4048
4164
|
var _proto = SpriteAtlasLoader.prototype;
|
|
@@ -4060,57 +4176,65 @@ var SpriteAtlasLoader = /*#__PURE__*/ function(Loader) {
|
|
|
4060
4176
|
}));
|
|
4061
4177
|
chainPromises.push(configPromise);
|
|
4062
4178
|
configPromise.then(function(atlasData) {
|
|
4063
|
-
var
|
|
4064
|
-
|
|
4065
|
-
|
|
4066
|
-
|
|
4067
|
-
|
|
4068
|
-
|
|
4069
|
-
|
|
4070
|
-
|
|
4071
|
-
|
|
4072
|
-
return imagePromises.then(function(imgs) {
|
|
4073
|
-
var engine = resourceManager.engine;
|
|
4074
|
-
// Generate a SpriteAtlas object.
|
|
4075
|
-
var tempRect = _this._tempRect, tempVec2 = _this._tempVec2;
|
|
4076
|
-
var spriteAtlas = new SpriteAtlas(engine);
|
|
4077
|
-
for(var i = 0; i < atlasItemsLen; i++){
|
|
4078
|
-
// Generate Texture2D according to configuration.
|
|
4079
|
-
var originalImg = imgs[i];
|
|
4080
|
-
var width = originalImg.width, height = originalImg.height;
|
|
4081
|
-
var texture = new Texture2D(engine, width, height, format);
|
|
4082
|
-
texture.setImageSource(originalImg);
|
|
4083
|
-
texture.generateMipmaps();
|
|
4084
|
-
// Generate all the sprites on this texture.
|
|
4085
|
-
var atlasItem = atlasItems[i];
|
|
4086
|
-
var sprites = atlasItem.sprites;
|
|
4087
|
-
var sourceWidthReciprocal = 1.0 / width;
|
|
4088
|
-
var sourceHeightReciprocal = 1.0 / height;
|
|
4089
|
-
for(var j = sprites.length - 1; j >= 0; j--){
|
|
4090
|
-
var atlasSprite = sprites[j];
|
|
4091
|
-
var region = atlasSprite.region, atlasRegionOffset = atlasSprite.atlasRegionOffset, atlasRegion = atlasSprite.atlasRegion, id = atlasSprite.id, pivot = atlasSprite.pivot;
|
|
4092
|
-
var sprite = new Sprite(engine, texture, region ? tempRect.set(region.x, region.y, region.w, region.h) : undefined, pivot ? tempVec2.set(pivot.x, pivot.y) : undefined, undefined, atlasSprite.name);
|
|
4093
|
-
sprite.atlasRegion.set(atlasRegion.x * sourceWidthReciprocal, atlasRegion.y * sourceHeightReciprocal, atlasRegion.w * sourceWidthReciprocal, atlasRegion.h * sourceHeightReciprocal);
|
|
4094
|
-
atlasSprite.atlasRotated && (sprite.atlasRotated = true);
|
|
4095
|
-
if (atlasRegionOffset) {
|
|
4096
|
-
var offsetLeft = atlasRegionOffset.x, offsetTop = atlasRegionOffset.y, offsetRight = atlasRegionOffset.z, offsetBottom = atlasRegionOffset.w;
|
|
4097
|
-
sprite.atlasRegionOffset.set(offsetLeft * sourceWidthReciprocal, offsetTop * sourceHeightReciprocal, offsetRight * sourceWidthReciprocal, offsetBottom * sourceHeightReciprocal);
|
|
4179
|
+
var _loop = function(i) {
|
|
4180
|
+
var atlasItem = atlasItems[i];
|
|
4181
|
+
if (atlasItem.img) {
|
|
4182
|
+
chainPromises.push(resourceManager.load({
|
|
4183
|
+
url: atlasItem.img,
|
|
4184
|
+
type: AssetType.Texture2D,
|
|
4185
|
+
params: {
|
|
4186
|
+
format: format,
|
|
4187
|
+
mipmap: mipmap
|
|
4098
4188
|
}
|
|
4099
|
-
|
|
4189
|
+
}).then(function(texture) {
|
|
4190
|
+
anisoLevel && (texture.anisoLevel = anisoLevel);
|
|
4191
|
+
filterMode !== undefined && (texture.filterMode = filterMode);
|
|
4192
|
+
wrapModeU !== undefined && (texture.wrapModeU = wrapModeU);
|
|
4193
|
+
wrapModeV !== undefined && (texture.wrapModeV = wrapModeV);
|
|
4194
|
+
for(var i = 0; i < atlasItem.sprites.length; i++){
|
|
4100
4195
|
// @ts-ignore
|
|
4101
|
-
|
|
4196
|
+
spriteAtlas._addSprite(_this._makeSprite(engine, atlasItem.sprites[i], texture));
|
|
4102
4197
|
}
|
|
4198
|
+
}).catch(reject));
|
|
4199
|
+
} else {
|
|
4200
|
+
for(var i1 = 0; i1 < atlasItem.sprites.length; i1++){
|
|
4103
4201
|
// @ts-ignore
|
|
4104
|
-
spriteAtlas._addSprite(
|
|
4202
|
+
spriteAtlas._addSprite(_this._makeSprite(engine, atlasItem.sprites[i1]));
|
|
4105
4203
|
}
|
|
4106
4204
|
}
|
|
4205
|
+
};
|
|
4206
|
+
var atlasItems = atlasData.atlasItems, mipmap = atlasData.mipmap, anisoLevel = atlasData.anisoLevel, filterMode = atlasData.filterMode, wrapModeU = atlasData.wrapModeU, wrapModeV = atlasData.wrapModeV, format = atlasData.format;
|
|
4207
|
+
var atlasItemsLen = atlasItems ? atlasItems.length : 0;
|
|
4208
|
+
var engine = resourceManager.engine;
|
|
4209
|
+
var spriteAtlas = new SpriteAtlas(engine);
|
|
4210
|
+
if (atlasItemsLen < 0) {
|
|
4107
4211
|
resolve(spriteAtlas);
|
|
4108
|
-
|
|
4109
|
-
|
|
4110
|
-
|
|
4111
|
-
|
|
4212
|
+
return;
|
|
4213
|
+
}
|
|
4214
|
+
chainPromises.length = 0;
|
|
4215
|
+
for(var i = 0; i < atlasItems.length; i++)_loop(i);
|
|
4216
|
+
AssetPromise.all(chainPromises).then(function() {
|
|
4217
|
+
resolve(spriteAtlas);
|
|
4218
|
+
}).catch(reject);
|
|
4219
|
+
}).catch(reject);
|
|
4112
4220
|
});
|
|
4113
4221
|
};
|
|
4222
|
+
_proto._makeSprite = function _makeSprite(engine, config, texture) {
|
|
4223
|
+
// Generate a SpriteAtlas object.
|
|
4224
|
+
var region = config.region, atlasRegionOffset = config.atlasRegionOffset, atlasRegion = config.atlasRegion, pivot = config.pivot, border = config.border;
|
|
4225
|
+
var sprite = new Sprite(engine, texture, region ? this._tempRect.set(region.x, region.y, region.w, region.h) : undefined, pivot ? this._tempVec2.set(pivot.x, pivot.y) : undefined, border ? this._tempVec4.set(border.x, border.y, border.z, border.w) : undefined, config.name);
|
|
4226
|
+
if (texture) {
|
|
4227
|
+
var invW = 1 / texture.width;
|
|
4228
|
+
var invH = 1 / texture.height;
|
|
4229
|
+
sprite.atlasRegion.set(atlasRegion.x * invW, atlasRegion.y * invH, atlasRegion.w * invW, atlasRegion.h * invH);
|
|
4230
|
+
if (atlasRegionOffset) {
|
|
4231
|
+
var offsetLeft = atlasRegionOffset.x, offsetTop = atlasRegionOffset.y, offsetRight = atlasRegionOffset.z, offsetBottom = atlasRegionOffset.w;
|
|
4232
|
+
sprite.atlasRegionOffset.set(offsetLeft * invW, offsetTop * invH, offsetRight * invW, offsetBottom * invH);
|
|
4233
|
+
}
|
|
4234
|
+
config.atlasRotated && (sprite.atlasRotated = true);
|
|
4235
|
+
}
|
|
4236
|
+
return sprite;
|
|
4237
|
+
};
|
|
4114
4238
|
return SpriteAtlasLoader;
|
|
4115
4239
|
}(Loader);
|
|
4116
4240
|
SpriteAtlasLoader = __decorate([
|
|
@@ -4131,13 +4255,19 @@ var SpriteLoader = /*#__PURE__*/ function(Loader) {
|
|
|
4131
4255
|
_this.request(item.url, _extends({}, item, {
|
|
4132
4256
|
type: "json"
|
|
4133
4257
|
})).then(function(data) {
|
|
4134
|
-
|
|
4135
|
-
|
|
4136
|
-
|
|
4137
|
-
|
|
4138
|
-
|
|
4139
|
-
|
|
4140
|
-
|
|
4258
|
+
if (data.belongToAtlas) {
|
|
4259
|
+
resourceManager// @ts-ignore
|
|
4260
|
+
.getResourceByRef(data.belongToAtlas).then(function(atlas) {
|
|
4261
|
+
resolve(atlas.getSprite(data.fullPath));
|
|
4262
|
+
}).catch(reject);
|
|
4263
|
+
} else if (data.texture) {
|
|
4264
|
+
resourceManager// @ts-ignore
|
|
4265
|
+
.getResourceByRef(data.texture).then(function(texture) {
|
|
4266
|
+
resolve(new Sprite(resourceManager.engine, texture, data.region, data.pivot, data.border));
|
|
4267
|
+
}).catch(reject);
|
|
4268
|
+
} else {
|
|
4269
|
+
resolve(new Sprite(resourceManager.engine, null, data.region, data.pivot, data.border));
|
|
4270
|
+
}
|
|
4141
4271
|
}).catch(reject);
|
|
4142
4272
|
});
|
|
4143
4273
|
};
|
|
@@ -4149,57 +4279,28 @@ SpriteLoader = __decorate([
|
|
|
4149
4279
|
], false)
|
|
4150
4280
|
], SpriteLoader);
|
|
4151
4281
|
|
|
4152
|
-
/**
|
|
4153
|
-
* @internal
|
|
4154
|
-
*/ var Texture2DContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
|
|
4155
|
-
_inherits(Texture2DContentRestorer, ContentRestorer);
|
|
4156
|
-
function Texture2DContentRestorer(resource, url, requestConfig) {
|
|
4157
|
-
var _this;
|
|
4158
|
-
_this = ContentRestorer.call(this, resource) || this;
|
|
4159
|
-
_this.url = url;
|
|
4160
|
-
_this.requestConfig = requestConfig;
|
|
4161
|
-
return _this;
|
|
4162
|
-
}
|
|
4163
|
-
var _proto = Texture2DContentRestorer.prototype;
|
|
4164
|
-
/**
|
|
4165
|
-
* @override
|
|
4166
|
-
*/ _proto.restoreContent = function restoreContent() {
|
|
4167
|
-
var _this = this;
|
|
4168
|
-
return request(this.url, this.requestConfig).then(function(image) {
|
|
4169
|
-
var resource = _this.resource;
|
|
4170
|
-
resource.setImageSource(image);
|
|
4171
|
-
resource.generateMipmaps();
|
|
4172
|
-
return resource;
|
|
4173
|
-
});
|
|
4174
|
-
};
|
|
4175
|
-
return Texture2DContentRestorer;
|
|
4176
|
-
}(ContentRestorer);
|
|
4177
|
-
|
|
4178
4282
|
var Texture2DLoader = /*#__PURE__*/ function(Loader) {
|
|
4179
4283
|
_inherits(Texture2DLoader, Loader);
|
|
4180
4284
|
function Texture2DLoader() {
|
|
4181
4285
|
return Loader.apply(this, arguments);
|
|
4182
4286
|
}
|
|
4183
4287
|
var _proto = Texture2DLoader.prototype;
|
|
4184
|
-
|
|
4185
|
-
* @override
|
|
4186
|
-
*/ _proto.load = function load(item, resourceManager) {
|
|
4288
|
+
_proto.load = function load(item, resourceManager) {
|
|
4187
4289
|
var _this = this;
|
|
4188
4290
|
return new AssetPromise(function(resolve, reject) {
|
|
4189
|
-
|
|
4190
|
-
var requestConfig = _extends({}, item, {
|
|
4291
|
+
_this.request(item.url, _extends({}, item, {
|
|
4191
4292
|
type: "image"
|
|
4192
|
-
})
|
|
4193
|
-
|
|
4194
|
-
var params = item.params;
|
|
4195
|
-
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;
|
|
4196
4298
|
texture.setImageSource(image);
|
|
4197
4299
|
texture.generateMipmaps();
|
|
4198
|
-
if (url.indexOf("data:") !== 0) {
|
|
4199
|
-
var
|
|
4200
|
-
texture.name =
|
|
4300
|
+
if (item.url.indexOf("data:") !== 0) {
|
|
4301
|
+
var splitPath = item.url.split("/");
|
|
4302
|
+
texture.name = splitPath[splitPath.length - 1];
|
|
4201
4303
|
}
|
|
4202
|
-
resourceManager.addContentRestorer(new Texture2DContentRestorer(texture, url, requestConfig));
|
|
4203
4304
|
resolve(texture);
|
|
4204
4305
|
}).catch(function(e) {
|
|
4205
4306
|
reject(e);
|
|
@@ -4217,70 +4318,32 @@ Texture2DLoader = __decorate([
|
|
|
4217
4318
|
])
|
|
4218
4319
|
], Texture2DLoader);
|
|
4219
4320
|
|
|
4220
|
-
/**
|
|
4221
|
-
* @internal
|
|
4222
|
-
*/ var TextureCubeContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
|
|
4223
|
-
_inherits(TextureCubeContentRestorer, ContentRestorer);
|
|
4224
|
-
function TextureCubeContentRestorer(resource, urls, requestConfig) {
|
|
4225
|
-
var _this;
|
|
4226
|
-
_this = ContentRestorer.call(this, resource) || this;
|
|
4227
|
-
_this.urls = urls;
|
|
4228
|
-
_this.requestConfig = requestConfig;
|
|
4229
|
-
return _this;
|
|
4230
|
-
}
|
|
4231
|
-
var _proto = TextureCubeContentRestorer.prototype;
|
|
4232
|
-
/**
|
|
4233
|
-
* @override
|
|
4234
|
-
*/ _proto.restoreContent = function restoreContent() {
|
|
4235
|
-
var _this = this;
|
|
4236
|
-
return new AssetPromise(function(resolve, reject) {
|
|
4237
|
-
Promise.all(_this.urls.map(function(url) {
|
|
4238
|
-
return request(url, _this.requestConfig);
|
|
4239
|
-
})).then(function(images) {
|
|
4240
|
-
var resource = _this.resource;
|
|
4241
|
-
for(var faceIndex = 0; faceIndex < 6; faceIndex++){
|
|
4242
|
-
resource.setImageSource(TextureCubeFace.PositiveX + faceIndex, images[faceIndex], 0);
|
|
4243
|
-
}
|
|
4244
|
-
resource.generateMipmaps();
|
|
4245
|
-
resolve(resource);
|
|
4246
|
-
}).catch(function(e) {
|
|
4247
|
-
reject(e);
|
|
4248
|
-
});
|
|
4249
|
-
});
|
|
4250
|
-
};
|
|
4251
|
-
return TextureCubeContentRestorer;
|
|
4252
|
-
}(ContentRestorer);
|
|
4253
|
-
|
|
4254
4321
|
var TextureCubeLoader = /*#__PURE__*/ function(Loader) {
|
|
4255
4322
|
_inherits(TextureCubeLoader, Loader);
|
|
4256
4323
|
function TextureCubeLoader() {
|
|
4257
4324
|
return Loader.apply(this, arguments);
|
|
4258
4325
|
}
|
|
4259
4326
|
var _proto = TextureCubeLoader.prototype;
|
|
4260
|
-
|
|
4261
|
-
* @override
|
|
4262
|
-
*/ _proto.load = function load(item, resourceManager) {
|
|
4327
|
+
_proto.load = function load(item, resourceManager) {
|
|
4263
4328
|
var _this = this;
|
|
4264
4329
|
return new AssetPromise(function(resolve, reject) {
|
|
4265
|
-
|
|
4266
|
-
|
|
4267
|
-
|
|
4268
|
-
|
|
4269
|
-
Promise.all(urls.map(function(url) {
|
|
4270
|
-
return _this.request(url, requestConfig);
|
|
4330
|
+
Promise.all(item.urls.map(function(url) {
|
|
4331
|
+
return _this.request(url, _extends({}, item, {
|
|
4332
|
+
type: "image"
|
|
4333
|
+
}));
|
|
4271
4334
|
})).then(function(images) {
|
|
4272
4335
|
var _images_ = images[0], width = _images_.width, height = _images_.height;
|
|
4273
4336
|
if (width !== height) {
|
|
4274
4337
|
console.error("The cube texture must have the same width and height");
|
|
4275
4338
|
return;
|
|
4276
4339
|
}
|
|
4277
|
-
var
|
|
4340
|
+
var tex = new TextureCube(resourceManager.engine, width);
|
|
4341
|
+
/** @ts-ignore */ if (!tex._platformTexture) return;
|
|
4278
4342
|
for(var faceIndex = 0; faceIndex < 6; faceIndex++){
|
|
4279
|
-
|
|
4343
|
+
tex.setImageSource(TextureCubeFace.PositiveX + faceIndex, images[faceIndex], 0);
|
|
4280
4344
|
}
|
|
4281
|
-
|
|
4282
|
-
|
|
4283
|
-
resolve(texture);
|
|
4345
|
+
tex.generateMipmaps();
|
|
4346
|
+
resolve(tex);
|
|
4284
4347
|
}).catch(function(e) {
|
|
4285
4348
|
reject(e);
|
|
4286
4349
|
});
|
|
@@ -4294,30 +4357,6 @@ TextureCubeLoader = __decorate([
|
|
|
4294
4357
|
])
|
|
4295
4358
|
], TextureCubeLoader);
|
|
4296
4359
|
|
|
4297
|
-
var AnimationClipLoader = /*#__PURE__*/ function(Loader) {
|
|
4298
|
-
_inherits(AnimationClipLoader, Loader);
|
|
4299
|
-
function AnimationClipLoader() {
|
|
4300
|
-
return Loader.apply(this, arguments);
|
|
4301
|
-
}
|
|
4302
|
-
var _proto = AnimationClipLoader.prototype;
|
|
4303
|
-
_proto.load = function load(item, resourceManager) {
|
|
4304
|
-
var _this = this;
|
|
4305
|
-
return new AssetPromise(function(resolve, reject) {
|
|
4306
|
-
_this.request(item.url, _extends({}, item, {
|
|
4307
|
-
type: "arraybuffer"
|
|
4308
|
-
})).then(function(data) {
|
|
4309
|
-
return decode(data, resourceManager.engine);
|
|
4310
|
-
}).catch(reject);
|
|
4311
|
-
});
|
|
4312
|
-
};
|
|
4313
|
-
return AnimationClipLoader;
|
|
4314
|
-
}(Loader);
|
|
4315
|
-
AnimationClipLoader = __decorate([
|
|
4316
|
-
resourceLoader(AssetType.AnimationClip, [
|
|
4317
|
-
"ani"
|
|
4318
|
-
])
|
|
4319
|
-
], AnimationClipLoader);
|
|
4320
|
-
|
|
4321
4360
|
var SceneLoader = /*#__PURE__*/ function(Loader) {
|
|
4322
4361
|
_inherits(SceneLoader, Loader);
|
|
4323
4362
|
function SceneLoader() {
|
|
@@ -4403,7 +4442,7 @@ SceneLoader = __decorate([
|
|
|
4403
4442
|
"prefab"
|
|
4404
4443
|
], true)
|
|
4405
4444
|
], SceneLoader);
|
|
4406
|
-
ReflectionParser.registerCustomParseComponent("TextRenderer", /*#__PURE__*/
|
|
4445
|
+
ReflectionParser.registerCustomParseComponent("TextRenderer", /*#__PURE__*/ _async_to_generator(function(instance, item, engine) {
|
|
4407
4446
|
var props;
|
|
4408
4447
|
return __generator(this, function(_state) {
|
|
4409
4448
|
props = item.props;
|
|
@@ -4418,388 +4457,5 @@ ReflectionParser.registerCustomParseComponent("TextRenderer", /*#__PURE__*/ _asy
|
|
|
4418
4457
|
});
|
|
4419
4458
|
}));
|
|
4420
4459
|
|
|
4421
|
-
|
|
4422
|
-
var KHR_draco_mesh_compression = (_KHR_draco_mesh_compression = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
4423
|
-
_inherits(KHR_draco_mesh_compression1, GLTFExtensionParser);
|
|
4424
|
-
function KHR_draco_mesh_compression1() {
|
|
4425
|
-
return GLTFExtensionParser.apply(this, arguments);
|
|
4426
|
-
}
|
|
4427
|
-
var _proto = KHR_draco_mesh_compression1.prototype;
|
|
4428
|
-
/**
|
|
4429
|
-
* @override
|
|
4430
|
-
*/ _proto.initialize = function initialize() {
|
|
4431
|
-
if (!KHR_draco_mesh_compression._decoder) {
|
|
4432
|
-
KHR_draco_mesh_compression._decoder = new DRACODecoder();
|
|
4433
|
-
}
|
|
4434
|
-
};
|
|
4435
|
-
/**
|
|
4436
|
-
* @override
|
|
4437
|
-
*/ _proto.createAndParse = function createAndParse(context, schema, glTFPrimitive, glTFMesh) {
|
|
4438
|
-
var _this = this;
|
|
4439
|
-
var glTF = context.glTF, buffers = context.buffers, engine = context.glTFResource.engine;
|
|
4440
|
-
var bufferViews = glTF.bufferViews, accessors = glTF.accessors;
|
|
4441
|
-
var bufferViewIndex = schema.bufferView, gltfAttributeMap = schema.attributes;
|
|
4442
|
-
var attributeMap = {};
|
|
4443
|
-
var attributeTypeMap = {};
|
|
4444
|
-
for(var attributeName in gltfAttributeMap){
|
|
4445
|
-
attributeMap[attributeName] = gltfAttributeMap[attributeName];
|
|
4446
|
-
}
|
|
4447
|
-
for(var attributeName1 in glTFPrimitive.attributes){
|
|
4448
|
-
if (gltfAttributeMap[attributeName1] !== undefined) {
|
|
4449
|
-
var accessorDef = accessors[glTFPrimitive.attributes[attributeName1]];
|
|
4450
|
-
attributeTypeMap[attributeName1] = GLTFUtil.getComponentType(accessorDef.componentType).name;
|
|
4451
|
-
}
|
|
4452
|
-
}
|
|
4453
|
-
var indexAccessor = accessors[glTFPrimitive.indices];
|
|
4454
|
-
var indexType = GLTFUtil.getComponentType(indexAccessor.componentType).name;
|
|
4455
|
-
var taskConfig = {
|
|
4456
|
-
attributeIDs: attributeMap,
|
|
4457
|
-
attributeTypes: attributeTypeMap,
|
|
4458
|
-
useUniqueIDs: true,
|
|
4459
|
-
indexType: indexType
|
|
4460
|
-
};
|
|
4461
|
-
var buffer = GLTFUtil.getBufferViewData(bufferViews[bufferViewIndex], buffers);
|
|
4462
|
-
return KHR_draco_mesh_compression._decoder.decode(buffer, taskConfig).then(function(decodedGeometry) {
|
|
4463
|
-
var mesh = new ModelMesh(engine, glTFMesh.name);
|
|
4464
|
-
return _this._parseMeshFromGLTFPrimitiveDraco(mesh, glTFMesh, glTFPrimitive, glTF, function(attributeSemantic) {
|
|
4465
|
-
for(var j = 0; j < decodedGeometry.attributes.length; j++){
|
|
4466
|
-
if (decodedGeometry.attributes[j].name === attributeSemantic) {
|
|
4467
|
-
return decodedGeometry.attributes[j].array;
|
|
4468
|
-
}
|
|
4469
|
-
}
|
|
4470
|
-
return null;
|
|
4471
|
-
}, function(attributeSemantic, shapeIndex) {
|
|
4472
|
-
throw "BlendShape animation is not supported when using draco.";
|
|
4473
|
-
}, function() {
|
|
4474
|
-
return decodedGeometry.index.array;
|
|
4475
|
-
}, context.keepMeshData);
|
|
4476
|
-
});
|
|
4477
|
-
};
|
|
4478
|
-
_proto._parseMeshFromGLTFPrimitiveDraco = function _parseMeshFromGLTFPrimitiveDraco(mesh, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
|
|
4479
|
-
var attributes = gltfPrimitive.attributes, targets = gltfPrimitive.targets, indices = gltfPrimitive.indices, mode = gltfPrimitive.mode;
|
|
4480
|
-
var vertexCount;
|
|
4481
|
-
var accessors = gltf.accessors;
|
|
4482
|
-
var accessor = accessors[attributes["POSITION"]];
|
|
4483
|
-
var positionBuffer = getVertexBufferData("POSITION");
|
|
4484
|
-
var positions = GLTFUtil.floatBufferToVector3Array(positionBuffer);
|
|
4485
|
-
mesh.setPositions(positions);
|
|
4486
|
-
var bounds = mesh.bounds;
|
|
4487
|
-
vertexCount = accessor.count;
|
|
4488
|
-
if (accessor.min && accessor.max) {
|
|
4489
|
-
bounds.min.copyFromArray(accessor.min);
|
|
4490
|
-
bounds.max.copyFromArray(accessor.max);
|
|
4491
|
-
} else {
|
|
4492
|
-
var position = KHR_draco_mesh_compression._tempVector3;
|
|
4493
|
-
var min = bounds.min, max = bounds.max;
|
|
4494
|
-
min.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
|
|
4495
|
-
max.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
|
|
4496
|
-
var stride = positionBuffer.length / vertexCount;
|
|
4497
|
-
for(var j = 0; j < vertexCount; j++){
|
|
4498
|
-
var offset = j * stride;
|
|
4499
|
-
position.copyFromArray(positionBuffer, offset);
|
|
4500
|
-
Vector3.min(min, position, min);
|
|
4501
|
-
Vector3.max(max, position, max);
|
|
4502
|
-
}
|
|
4503
|
-
}
|
|
4504
|
-
for(var attributeSemantic in attributes){
|
|
4505
|
-
if (attributeSemantic === "POSITION") {
|
|
4506
|
-
continue;
|
|
4507
|
-
}
|
|
4508
|
-
var bufferData = getVertexBufferData(attributeSemantic);
|
|
4509
|
-
switch(attributeSemantic){
|
|
4510
|
-
case "NORMAL":
|
|
4511
|
-
var normals = GLTFUtil.floatBufferToVector3Array(bufferData);
|
|
4512
|
-
mesh.setNormals(normals);
|
|
4513
|
-
break;
|
|
4514
|
-
case "TEXCOORD_0":
|
|
4515
|
-
var texturecoords = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
4516
|
-
mesh.setUVs(texturecoords, 0);
|
|
4517
|
-
break;
|
|
4518
|
-
case "TEXCOORD_1":
|
|
4519
|
-
var texturecoords1 = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
4520
|
-
mesh.setUVs(texturecoords1, 1);
|
|
4521
|
-
break;
|
|
4522
|
-
case "TEXCOORD_2":
|
|
4523
|
-
var texturecoords2 = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
4524
|
-
mesh.setUVs(texturecoords2, 2);
|
|
4525
|
-
break;
|
|
4526
|
-
case "TEXCOORD_3":
|
|
4527
|
-
var texturecoords3 = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
4528
|
-
mesh.setUVs(texturecoords3, 3);
|
|
4529
|
-
break;
|
|
4530
|
-
case "TEXCOORD_4":
|
|
4531
|
-
var texturecoords4 = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
4532
|
-
mesh.setUVs(texturecoords4, 4);
|
|
4533
|
-
break;
|
|
4534
|
-
case "TEXCOORD_5":
|
|
4535
|
-
var texturecoords5 = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
4536
|
-
mesh.setUVs(texturecoords5, 5);
|
|
4537
|
-
break;
|
|
4538
|
-
case "TEXCOORD_6":
|
|
4539
|
-
var texturecoords6 = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
4540
|
-
mesh.setUVs(texturecoords6, 6);
|
|
4541
|
-
break;
|
|
4542
|
-
case "TEXCOORD_7":
|
|
4543
|
-
var texturecoords7 = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
4544
|
-
mesh.setUVs(texturecoords7, 7);
|
|
4545
|
-
break;
|
|
4546
|
-
case "COLOR_0":
|
|
4547
|
-
var colors = GLTFUtil.floatBufferToColorArray(bufferData, accessors[attributes["COLOR_0"]].type === AccessorType.VEC3);
|
|
4548
|
-
mesh.setColors(colors);
|
|
4549
|
-
break;
|
|
4550
|
-
case "TANGENT":
|
|
4551
|
-
var tangents = GLTFUtil.floatBufferToVector4Array(bufferData);
|
|
4552
|
-
mesh.setTangents(tangents);
|
|
4553
|
-
break;
|
|
4554
|
-
case "JOINTS_0":
|
|
4555
|
-
var joints = GLTFUtil.floatBufferToVector4Array(bufferData);
|
|
4556
|
-
mesh.setBoneIndices(joints);
|
|
4557
|
-
break;
|
|
4558
|
-
case "WEIGHTS_0":
|
|
4559
|
-
var weights = GLTFUtil.floatBufferToVector4Array(bufferData);
|
|
4560
|
-
mesh.setBoneWeights(weights);
|
|
4561
|
-
break;
|
|
4562
|
-
}
|
|
4563
|
-
}
|
|
4564
|
-
// Indices
|
|
4565
|
-
if (indices !== undefined) {
|
|
4566
|
-
var indexAccessor = gltf.accessors[indices];
|
|
4567
|
-
var indexData = getIndexBufferData();
|
|
4568
|
-
mesh.setIndices(indexData);
|
|
4569
|
-
mesh.addSubMesh(0, indexAccessor.count, mode);
|
|
4570
|
-
} else {
|
|
4571
|
-
mesh.addSubMesh(0, vertexCount, mode);
|
|
4572
|
-
}
|
|
4573
|
-
// BlendShapes
|
|
4574
|
-
targets && GLTFMeshParser._createBlendShape(mesh, null, gltfMesh, targets, getBlendShapeData);
|
|
4575
|
-
mesh.uploadData(!keepMeshData);
|
|
4576
|
-
return Promise.resolve(mesh);
|
|
4577
|
-
};
|
|
4578
|
-
return KHR_draco_mesh_compression1;
|
|
4579
|
-
}(GLTFExtensionParser), _KHR_draco_mesh_compression._tempVector3 = new Vector3(), _KHR_draco_mesh_compression);
|
|
4580
|
-
KHR_draco_mesh_compression = __decorate([
|
|
4581
|
-
registerGLTFExtension("KHR_draco_mesh_compression", GLTFExtensionMode.CreateAndParse)
|
|
4582
|
-
], KHR_draco_mesh_compression);
|
|
4583
|
-
|
|
4584
|
-
var KHR_lights_punctual = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
4585
|
-
_inherits(KHR_lights_punctual, GLTFExtensionParser);
|
|
4586
|
-
function KHR_lights_punctual() {
|
|
4587
|
-
return GLTFExtensionParser.apply(this, arguments);
|
|
4588
|
-
}
|
|
4589
|
-
var _proto = KHR_lights_punctual.prototype;
|
|
4590
|
-
/**
|
|
4591
|
-
* @override
|
|
4592
|
-
*/ _proto.additiveParse = function additiveParse(context, entity, extensionSchema) {
|
|
4593
|
-
var lightsSchema = context.glTF.extensions.KHR_lights_punctual.lights;
|
|
4594
|
-
var lightSchema = lightsSchema[extensionSchema.light];
|
|
4595
|
-
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;
|
|
4596
|
-
var glTFResource = context.glTFResource;
|
|
4597
|
-
var light;
|
|
4598
|
-
if (type === "directional") {
|
|
4599
|
-
light = entity.addComponent(DirectLight);
|
|
4600
|
-
} else if (type === "point") {
|
|
4601
|
-
light = entity.addComponent(PointLight);
|
|
4602
|
-
} else if (type === "spot") {
|
|
4603
|
-
light = entity.addComponent(SpotLight);
|
|
4604
|
-
}
|
|
4605
|
-
if (color) {
|
|
4606
|
-
light.color.set(color[0], color[1], color[2], 1);
|
|
4607
|
-
}
|
|
4608
|
-
light.intensity = intensity;
|
|
4609
|
-
if (range && !_instanceof(light, DirectLight)) {
|
|
4610
|
-
light.distance = range;
|
|
4611
|
-
}
|
|
4612
|
-
if (spot && _instanceof(light, SpotLight)) {
|
|
4613
|
-
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;
|
|
4614
|
-
light.angle = innerConeAngle;
|
|
4615
|
-
light.penumbra = outerConeAngle - innerConeAngle;
|
|
4616
|
-
}
|
|
4617
|
-
if (!glTFResource.lights) glTFResource.lights = [];
|
|
4618
|
-
glTFResource.lights.push(light);
|
|
4619
|
-
};
|
|
4620
|
-
return KHR_lights_punctual;
|
|
4621
|
-
}(GLTFExtensionParser);
|
|
4622
|
-
KHR_lights_punctual = __decorate([
|
|
4623
|
-
registerGLTFExtension("KHR_lights_punctual", GLTFExtensionMode.AdditiveParse)
|
|
4624
|
-
], KHR_lights_punctual);
|
|
4625
|
-
|
|
4626
|
-
var KHR_materials_clearcoat = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
4627
|
-
_inherits(KHR_materials_clearcoat, GLTFExtensionParser);
|
|
4628
|
-
function KHR_materials_clearcoat() {
|
|
4629
|
-
return GLTFExtensionParser.apply(this, arguments);
|
|
4630
|
-
}
|
|
4631
|
-
var _proto = KHR_materials_clearcoat.prototype;
|
|
4632
|
-
/**
|
|
4633
|
-
* @override
|
|
4634
|
-
*/ _proto.additiveParse = function additiveParse(context, material, schema) {
|
|
4635
|
-
var textures = context.glTFResource.textures;
|
|
4636
|
-
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;
|
|
4637
|
-
material.clearCoat = clearcoatFactor;
|
|
4638
|
-
material.clearCoatRoughness = clearcoatRoughnessFactor;
|
|
4639
|
-
if (clearcoatTexture) {
|
|
4640
|
-
material.clearCoatTexture = textures[clearcoatTexture.index];
|
|
4641
|
-
GLTFMaterialParser._checkOtherTextureTransform(clearcoatTexture, "Clear coat");
|
|
4642
|
-
}
|
|
4643
|
-
if (clearcoatRoughnessTexture) {
|
|
4644
|
-
material.clearCoatRoughnessTexture = textures[clearcoatRoughnessTexture.index];
|
|
4645
|
-
GLTFMaterialParser._checkOtherTextureTransform(clearcoatRoughnessTexture, "Clear coat roughness");
|
|
4646
|
-
}
|
|
4647
|
-
if (clearcoatNormalTexture) {
|
|
4648
|
-
material.clearCoatNormalTexture = textures[clearcoatNormalTexture.index];
|
|
4649
|
-
GLTFMaterialParser._checkOtherTextureTransform(clearcoatNormalTexture, "Clear coat normal");
|
|
4650
|
-
}
|
|
4651
|
-
};
|
|
4652
|
-
return KHR_materials_clearcoat;
|
|
4653
|
-
}(GLTFExtensionParser);
|
|
4654
|
-
KHR_materials_clearcoat = __decorate([
|
|
4655
|
-
registerGLTFExtension("KHR_materials_clearcoat", GLTFExtensionMode.AdditiveParse)
|
|
4656
|
-
], KHR_materials_clearcoat);
|
|
4657
|
-
|
|
4658
|
-
var KHR_materials_pbrSpecularGlossiness = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
4659
|
-
_inherits(KHR_materials_pbrSpecularGlossiness, GLTFExtensionParser);
|
|
4660
|
-
function KHR_materials_pbrSpecularGlossiness() {
|
|
4661
|
-
return GLTFExtensionParser.apply(this, arguments);
|
|
4662
|
-
}
|
|
4663
|
-
var _proto = KHR_materials_pbrSpecularGlossiness.prototype;
|
|
4664
|
-
/**
|
|
4665
|
-
* @override
|
|
4666
|
-
*/ _proto.createAndParse = function createAndParse(context, schema, ownerSchema) {
|
|
4667
|
-
var _context_glTFResource = context.glTFResource, engine = _context_glTFResource.engine, textures = _context_glTFResource.textures;
|
|
4668
|
-
var material = new PBRSpecularMaterial(engine);
|
|
4669
|
-
var diffuseFactor = schema.diffuseFactor, diffuseTexture = schema.diffuseTexture, specularFactor = schema.specularFactor, glossinessFactor = schema.glossinessFactor, specularGlossinessTexture = schema.specularGlossinessTexture;
|
|
4670
|
-
if (diffuseFactor) {
|
|
4671
|
-
material.baseColor = new Color(Color.linearToGammaSpace(diffuseFactor[0]), Color.linearToGammaSpace(diffuseFactor[1]), Color.linearToGammaSpace(diffuseFactor[2]), diffuseFactor[3]);
|
|
4672
|
-
}
|
|
4673
|
-
if (diffuseTexture) {
|
|
4674
|
-
material.baseTexture = textures[diffuseTexture.index];
|
|
4675
|
-
GLTFParser.executeExtensionsAdditiveAndParse(diffuseTexture.extensions, context, material, diffuseTexture);
|
|
4676
|
-
}
|
|
4677
|
-
if (specularFactor) {
|
|
4678
|
-
material.specularColor = new Color(Color.linearToGammaSpace(specularFactor[0]), Color.linearToGammaSpace(specularFactor[1]), Color.linearToGammaSpace(specularFactor[2]));
|
|
4679
|
-
}
|
|
4680
|
-
if (glossinessFactor !== undefined) {
|
|
4681
|
-
material.glossiness = glossinessFactor;
|
|
4682
|
-
}
|
|
4683
|
-
if (specularGlossinessTexture) {
|
|
4684
|
-
material.specularGlossinessTexture = textures[specularGlossinessTexture.index];
|
|
4685
|
-
GLTFMaterialParser._checkOtherTextureTransform(specularGlossinessTexture, "Specular glossiness");
|
|
4686
|
-
}
|
|
4687
|
-
material.name = ownerSchema.name;
|
|
4688
|
-
GLTFMaterialParser._parseStandardProperty(context, material, ownerSchema);
|
|
4689
|
-
return material;
|
|
4690
|
-
};
|
|
4691
|
-
return KHR_materials_pbrSpecularGlossiness;
|
|
4692
|
-
}(GLTFExtensionParser);
|
|
4693
|
-
KHR_materials_pbrSpecularGlossiness = __decorate([
|
|
4694
|
-
registerGLTFExtension("KHR_materials_pbrSpecularGlossiness", GLTFExtensionMode.CreateAndParse)
|
|
4695
|
-
], KHR_materials_pbrSpecularGlossiness);
|
|
4696
|
-
|
|
4697
|
-
var KHR_materials_unlit = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
4698
|
-
_inherits(KHR_materials_unlit, GLTFExtensionParser);
|
|
4699
|
-
function KHR_materials_unlit() {
|
|
4700
|
-
return GLTFExtensionParser.apply(this, arguments);
|
|
4701
|
-
}
|
|
4702
|
-
var _proto = KHR_materials_unlit.prototype;
|
|
4703
|
-
/**
|
|
4704
|
-
* @override
|
|
4705
|
-
*/ _proto.createAndParse = function createAndParse(context, _, ownerSchema) {
|
|
4706
|
-
var engine = context.glTFResource.engine;
|
|
4707
|
-
var material = new UnlitMaterial(engine);
|
|
4708
|
-
material.name = ownerSchema.name;
|
|
4709
|
-
GLTFMaterialParser._parseStandardProperty(context, material, ownerSchema);
|
|
4710
|
-
return material;
|
|
4711
|
-
};
|
|
4712
|
-
return KHR_materials_unlit;
|
|
4713
|
-
}(GLTFExtensionParser);
|
|
4714
|
-
KHR_materials_unlit = __decorate([
|
|
4715
|
-
registerGLTFExtension("KHR_materials_unlit", GLTFExtensionMode.CreateAndParse)
|
|
4716
|
-
], KHR_materials_unlit);
|
|
4717
|
-
|
|
4718
|
-
var KHR_mesh_quantization = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
4719
|
-
_inherits(KHR_mesh_quantization, GLTFExtensionParser);
|
|
4720
|
-
function KHR_mesh_quantization() {
|
|
4721
|
-
return GLTFExtensionParser.apply(this, arguments);
|
|
4722
|
-
}
|
|
4723
|
-
return KHR_mesh_quantization;
|
|
4724
|
-
}(GLTFExtensionParser);
|
|
4725
|
-
KHR_mesh_quantization = __decorate([
|
|
4726
|
-
registerGLTFExtension("KHR_mesh_quantization", GLTFExtensionMode.AdditiveParse)
|
|
4727
|
-
], KHR_mesh_quantization);
|
|
4728
|
-
|
|
4729
|
-
var KHR_texture_transform = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
4730
|
-
_inherits(KHR_texture_transform, GLTFExtensionParser);
|
|
4731
|
-
function KHR_texture_transform() {
|
|
4732
|
-
return GLTFExtensionParser.apply(this, arguments);
|
|
4733
|
-
}
|
|
4734
|
-
var _proto = KHR_texture_transform.prototype;
|
|
4735
|
-
/**
|
|
4736
|
-
* @override
|
|
4737
|
-
*/ _proto.additiveParse = function additiveParse(context, material, schema) {
|
|
4738
|
-
var offset = schema.offset, rotation = schema.rotation, scale = schema.scale, texCoord = schema.texCoord;
|
|
4739
|
-
if (offset) {
|
|
4740
|
-
material.tilingOffset.z = offset[0];
|
|
4741
|
-
material.tilingOffset.w = offset[1];
|
|
4742
|
-
}
|
|
4743
|
-
if (scale) {
|
|
4744
|
-
material.tilingOffset.x = scale[0];
|
|
4745
|
-
material.tilingOffset.y = scale[1];
|
|
4746
|
-
}
|
|
4747
|
-
if (rotation) {
|
|
4748
|
-
Logger.warn("rotation in KHR_texture_transform is not supported now");
|
|
4749
|
-
}
|
|
4750
|
-
if (texCoord) {
|
|
4751
|
-
Logger.warn("texCoord in KHR_texture_transform is not supported now");
|
|
4752
|
-
}
|
|
4753
|
-
};
|
|
4754
|
-
return KHR_texture_transform;
|
|
4755
|
-
}(GLTFExtensionParser);
|
|
4756
|
-
KHR_texture_transform = __decorate([
|
|
4757
|
-
registerGLTFExtension("KHR_texture_transform", GLTFExtensionMode.AdditiveParse)
|
|
4758
|
-
], KHR_texture_transform);
|
|
4759
|
-
|
|
4760
|
-
var GalaceanMaterialsRemap = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
4761
|
-
_inherits(GalaceanMaterialsRemap, GLTFExtensionParser);
|
|
4762
|
-
function GalaceanMaterialsRemap() {
|
|
4763
|
-
return GLTFExtensionParser.apply(this, arguments);
|
|
4764
|
-
}
|
|
4765
|
-
var _proto = GalaceanMaterialsRemap.prototype;
|
|
4766
|
-
/**
|
|
4767
|
-
* @override
|
|
4768
|
-
*/ _proto.createAndParse = function createAndParse(context, schema) {
|
|
4769
|
-
var engine = context.glTFResource.engine;
|
|
4770
|
-
// @ts-ignore
|
|
4771
|
-
return engine.resourceManager.getResourceByRef(schema);
|
|
4772
|
-
};
|
|
4773
|
-
return GalaceanMaterialsRemap;
|
|
4774
|
-
}(GLTFExtensionParser);
|
|
4775
|
-
GalaceanMaterialsRemap = __decorate([
|
|
4776
|
-
registerGLTFExtension("OASIS_materials_remap", GLTFExtensionMode.CreateAndParse)
|
|
4777
|
-
], GalaceanMaterialsRemap);
|
|
4778
|
-
|
|
4779
|
-
var OASIS_animation_event = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
4780
|
-
_inherits(OASIS_animation_event, GLTFExtensionParser);
|
|
4781
|
-
function OASIS_animation_event() {
|
|
4782
|
-
return GLTFExtensionParser.apply(this, arguments);
|
|
4783
|
-
}
|
|
4784
|
-
var _proto = OASIS_animation_event.prototype;
|
|
4785
|
-
/**
|
|
4786
|
-
* @override
|
|
4787
|
-
*/ _proto.additiveParse = function additiveParse(context, animationClip, schema) {
|
|
4788
|
-
context.glTFResource.engine;
|
|
4789
|
-
var events = schema.events;
|
|
4790
|
-
events.map(function(eventData) {
|
|
4791
|
-
var event = new AnimationEvent();
|
|
4792
|
-
event.functionName = eventData.functionName;
|
|
4793
|
-
event.time = eventData.time;
|
|
4794
|
-
event.parameter = eventData.parameter;
|
|
4795
|
-
animationClip.addEvent(event);
|
|
4796
|
-
});
|
|
4797
|
-
};
|
|
4798
|
-
return OASIS_animation_event;
|
|
4799
|
-
}(GLTFExtensionParser);
|
|
4800
|
-
OASIS_animation_event = __decorate([
|
|
4801
|
-
registerGLTFExtension("OASIS_animation_event", GLTFExtensionMode.AdditiveParse)
|
|
4802
|
-
], OASIS_animation_event);
|
|
4803
|
-
|
|
4804
|
-
export { AnimationClipDecoder, ComponentMap, EditorTextureLoader, GLTFAnimationParser, GLTFBufferParser, GLTFEntityParser, GLTFExtensionMode, GLTFExtensionParser, GLTFMaterialParser, GLTFMeshParser, GLTFParser, GLTFParserContext, GLTFPipeline, GLTFResource, GLTFSceneParser, GLTFSkinParser, GLTFTextureParser, GLTFUtil, 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 };
|
|
4805
4461
|
//# sourceMappingURL=module.js.map
|