@galacean/engine-loader 1.1.0-beta.9 → 1.2.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Utils, ModelMesh, BlendShape, Texture2D, Loader, Entity, Transform, Animator, DirectLight, Camera, MeshRenderer, ParticleRenderer, PointLight, SpotLight, Script, SpriteMask, SpriteRenderer, TextRenderer, AnimationClip, AnimationEvent, AnimationRefCurve, Keyframe, AnimationQuaternionCurve, AnimationColorCurve, AnimationVector4Curve, AnimationVector3Curve, AnimationVector2Curve, AnimationFloatArrayCurve, AnimationArrayCurve, AnimationFloatCurve, Scene, resourceLoader, AssetPromise, AssetType, AnimatorController, AnimatorControllerLayer, AnimatorStateMachine, AnimatorStateTransition, TextureCube, TextureFilterMode, TextureCubeFace, AmbientLight, DiffuseMode, Font, ReferResource, IndexFormat, VertexElementFormat, GLCapabilityType, Logger, TextureFormat, request, ContentRestorer, InterpolationType, SkinnedMeshRenderer, PBRMaterial, BlinnPhongMaterial, PBRSpecularMaterial, TextureCoordinate, RenderFace, VertexElement, Buffer, BufferBindFlag, BufferUsage, Skin, TextureWrapMode as TextureWrapMode$1, Material, Shader, SpriteAtlas, Sprite, BackgroundMode, UnlitMaterial } from '@galacean/engine-core';
1
+ import { Utils, ModelMesh, BlendShape, Texture2D, Loader, Entity, Transform, Animator, DirectLight, Camera, MeshRenderer, ParticleRenderer, PointLight, SpotLight, Script, SpriteMask, SpriteRenderer, TextRenderer, AnimationClip, AnimationEvent, AnimationStringCurve, Keyframe, AnimationBoolCurve, AnimationRefCurve, AnimationQuaternionCurve, AnimationColorCurve, AnimationVector4Curve, AnimationVector3Curve, AnimationVector2Curve, AnimationFloatArrayCurve, AnimationArrayCurve, AnimationFloatCurve, Scene, resourceLoader, AssetPromise, AssetType, AnimatorController, AnimatorControllerLayer, AnimatorStateMachine, AnimatorStateTransition, TextureCube, TextureFilterMode, TextureCubeFace, AmbientLight, DiffuseMode, Font, ReferResource, IndexFormat, VertexElementFormat, GLCapabilityType, Logger, TextureFormat, request, ContentRestorer, InterpolationType, SkinnedMeshRenderer, PBRMaterial, BlinnPhongMaterial, PBRSpecularMaterial, TextureCoordinate, RenderFace, VertexElement, Buffer, BufferBindFlag, BufferUsage, Skin, TextureWrapMode as TextureWrapMode$1, Material, Shader, SpriteAtlas, Sprite, BackgroundMode, UnlitMaterial } from '@galacean/engine-core';
2
2
  import { Color, Vector4, Vector3, Vector2, Quaternion, SphericalHarmonics3, MathUtil, BoundingBox, Matrix, Rect } from '@galacean/engine-math';
3
3
  import { GLCompressedTextureInternalFormat } from '@galacean/engine-rhi-webgl';
4
4
  import { DRACODecoder } from '@galacean/engine-draco';
@@ -116,116 +116,116 @@ var BufferReader = /*#__PURE__*/ function() {
116
116
  this.data = data;
117
117
  this._dataView = new DataView(data.buffer, data.byteOffset + byteOffset, byteLength != null ? byteLength : data.byteLength - byteOffset);
118
118
  this._littleEndian = littleEndian;
119
- this._offset = 0;
119
+ this._position = 0;
120
120
  this._baseOffset = byteOffset;
121
121
  }
122
122
  var _proto = BufferReader.prototype;
123
123
  _proto.nextUint8 = function nextUint8() {
124
- var value = this._dataView.getUint8(this._offset);
125
- this._offset += 1;
124
+ var value = this._dataView.getUint8(this._position);
125
+ this._position += 1;
126
126
  return value;
127
127
  };
128
128
  _proto.nextUint16 = function nextUint16() {
129
- var value = this._dataView.getUint16(this._offset, this._littleEndian);
130
- this._offset += 2;
129
+ var value = this._dataView.getUint16(this._position, this._littleEndian);
130
+ this._position += 2;
131
131
  return value;
132
132
  };
133
133
  _proto.nextUint32 = function nextUint32() {
134
- var value = this._dataView.getUint32(this._offset, this._littleEndian);
135
- this._offset += 4;
134
+ var value = this._dataView.getUint32(this._position, this._littleEndian);
135
+ this._position += 4;
136
136
  return value;
137
137
  };
138
138
  _proto.nextInt32 = function nextInt32() {
139
- var value = this._dataView.getInt32(this._offset, this._littleEndian);
140
- this._offset += 4;
139
+ var value = this._dataView.getInt32(this._position, this._littleEndian);
140
+ this._position += 4;
141
141
  return value;
142
142
  };
143
143
  _proto.nextInt32Array = function nextInt32Array(len) {
144
- var value = new Int32Array(this.data.buffer, this._offset + this._dataView.byteOffset, len);
145
- this._offset += 4 * len;
144
+ var value = new Int32Array(this.data.buffer, this._position + this._dataView.byteOffset, len);
145
+ this._position += 4 * len;
146
146
  return value;
147
147
  };
148
148
  _proto.nextFloat32 = function nextFloat32() {
149
- var value = this._dataView.getFloat32(this._offset, this._littleEndian);
150
- this._offset += 4;
149
+ var value = this._dataView.getFloat32(this._position, this._littleEndian);
150
+ this._position += 4;
151
151
  return value;
152
152
  };
153
153
  _proto.nextFloat32Array = function nextFloat32Array(len) {
154
- var value = new Float32Array(this.data.buffer, this._offset + this._dataView.byteOffset, len);
155
- this._offset += 4 * len;
154
+ var value = new Float32Array(this.data.buffer, this._position + this._dataView.byteOffset, len);
155
+ this._position += 4 * len;
156
156
  return value;
157
157
  };
158
158
  _proto.nextUint32Array = function nextUint32Array(len) {
159
- var value = new Uint32Array(this.data.buffer, this._offset + this._dataView.byteOffset, len);
160
- this._offset += 4 * len;
159
+ var value = new Uint32Array(this.data.buffer, this._position + this._dataView.byteOffset, len);
160
+ this._position += 4 * len;
161
161
  return value;
162
162
  };
163
163
  _proto.nextUint8Array = function nextUint8Array(len) {
164
- var value = new Uint8Array(this.data.buffer, this._offset + this._dataView.byteOffset, len);
165
- this._offset += len;
164
+ var value = new Uint8Array(this.data.buffer, this._position + this._dataView.byteOffset, len);
165
+ this._position += len;
166
166
  return value;
167
167
  };
168
168
  _proto.nextUint64 = function nextUint64() {
169
- var left = this._dataView.getUint32(this._offset, this._littleEndian);
170
- var right = this._dataView.getUint32(this._offset + 4, this._littleEndian);
169
+ var left = this._dataView.getUint32(this._position, this._littleEndian);
170
+ var right = this._dataView.getUint32(this._position + 4, this._littleEndian);
171
171
  var value = left + Math.pow(2, 32) * right;
172
- this._offset += 8;
172
+ this._position += 8;
173
173
  return value;
174
174
  };
175
175
  _proto.nextStr = function nextStr() {
176
176
  var strByteLength = this.nextUint16();
177
- var uint8Array = new Uint8Array(this.data.buffer, this._offset + this._dataView.byteOffset, strByteLength);
178
- this._offset += strByteLength;
177
+ var uint8Array = new Uint8Array(this.data.buffer, this._position + this._dataView.byteOffset, strByteLength);
178
+ this._position += strByteLength;
179
179
  return Utils.decodeText(uint8Array);
180
180
  };
181
181
  /**
182
182
  * image data 放在最后
183
183
  */ _proto.nextImageData = function nextImageData(count) {
184
- return new Uint8Array(this.data.buffer, this.data.byteOffset + this._offset);
184
+ return new Uint8Array(this.data.buffer, this.data.byteOffset + this._position);
185
185
  };
186
186
  _proto.nextImagesData = function nextImagesData(count) {
187
187
  var imagesLen = new Array(count);
188
188
  // Start offset of Uint32Array should be a multiple of 4. ref: https://stackoverflow.com/questions/15417310/why-typed-array-constructors-require-offset-to-be-multiple-of-underlying-type-si
189
189
  for(var i = 0; i < count; i++){
190
- var len = this._dataView.getUint32(this._offset, this._littleEndian);
190
+ var len = this._dataView.getUint32(this._position, this._littleEndian);
191
191
  imagesLen[i] = len;
192
- this._offset += 4;
192
+ this._position += 4;
193
193
  }
194
194
  var imagesData = [];
195
195
  for(var i1 = 0; i1 < count; i1++){
196
196
  var len1 = imagesLen[i1];
197
- var buffer = new Uint8Array(this.data.buffer, this._dataView.byteOffset + this._offset, len1);
198
- this._offset += len1;
197
+ var buffer = new Uint8Array(this.data.buffer, this._dataView.byteOffset + this._position, len1);
198
+ this._position += len1;
199
199
  imagesData.push(buffer);
200
200
  }
201
201
  return imagesData;
202
202
  };
203
203
  _proto.skip = function skip(bytes) {
204
- this._offset += bytes;
204
+ this._position += bytes;
205
205
  return this;
206
206
  };
207
207
  _proto.scan = function scan(maxByteLength, term) {
208
208
  if (term === void 0) term = 0x00;
209
- var byteOffset = this._offset;
209
+ var byteOffset = this._position;
210
210
  var byteLength = 0;
211
- while(this._dataView.getUint8(this._offset) !== term && byteLength < maxByteLength){
211
+ while(this._dataView.getUint8(this._position) !== term && byteLength < maxByteLength){
212
212
  byteLength++;
213
- this._offset++;
213
+ this._position++;
214
214
  }
215
- if (byteLength < maxByteLength) this._offset++;
215
+ if (byteLength < maxByteLength) this._position++;
216
216
  return new Uint8Array(this._dataView.buffer, this._dataView.byteOffset + byteOffset, byteLength);
217
217
  };
218
218
  _create_class(BufferReader, [
219
219
  {
220
220
  key: "position",
221
221
  get: function get() {
222
- return this._offset;
222
+ return this._position;
223
223
  }
224
224
  },
225
225
  {
226
226
  key: "offset",
227
227
  get: function get() {
228
- return this._offset + this._baseOffset;
228
+ return this._position + this._baseOffset;
229
229
  }
230
230
  }
231
231
  ]);
@@ -289,75 +289,74 @@ var MeshDecoder = /*#__PURE__*/ function() {
289
289
  var encodedMeshData = JSON.parse(jsonDataString);
290
290
  // @ts-ignore Vector3 is not compatible with {x: number, y: number, z: number}.
291
291
  encodedMeshData.bounds && modelMesh.bounds.copyFrom(encodedMeshData.bounds);
292
- var offset = Math.ceil(bufferReader.offset / 4) * 4;
292
+ var offset = Math.ceil(bufferReader.offset / 4) * 4 + bufferReader.data.byteOffset;
293
293
  var buffer = bufferReader.data.buffer;
294
- var byteOffset = bufferReader.data.byteOffset;
295
- var float32Array = new Float32Array(buffer, encodedMeshData.positions.start + offset + byteOffset, (encodedMeshData.positions.end - encodedMeshData.positions.start) / 4);
294
+ var float32Array = new Float32Array(buffer, encodedMeshData.positions.start + offset, (encodedMeshData.positions.end - encodedMeshData.positions.start) / 4);
296
295
  var vertexCount = float32Array.length / 3;
297
296
  var positions = float32ArrayToVector3(float32Array, vertexCount);
298
297
  modelMesh.setPositions(positions);
299
298
  if (encodedMeshData.normals) {
300
- var float32Array1 = new Float32Array(buffer, encodedMeshData.normals.start + offset + byteOffset, (encodedMeshData.normals.end - encodedMeshData.normals.start) / 4);
299
+ var float32Array1 = new Float32Array(buffer, encodedMeshData.normals.start + offset, (encodedMeshData.normals.end - encodedMeshData.normals.start) / 4);
301
300
  var normals = float32ArrayToVector3(float32Array1, vertexCount);
302
301
  modelMesh.setNormals(normals);
303
302
  }
304
303
  if (encodedMeshData.uvs) {
305
- var float32Array2 = new Float32Array(buffer, encodedMeshData.uvs.start + offset + byteOffset, (encodedMeshData.uvs.end - encodedMeshData.uvs.start) / 4);
304
+ var float32Array2 = new Float32Array(buffer, encodedMeshData.uvs.start + offset, (encodedMeshData.uvs.end - encodedMeshData.uvs.start) / 4);
306
305
  modelMesh.setUVs(float32ArrayToVector2(float32Array2, vertexCount));
307
306
  }
308
307
  if (encodedMeshData.uv1) {
309
- var float32Array3 = new Float32Array(buffer, encodedMeshData.uv1.start + offset + byteOffset, (encodedMeshData.uv1.end - encodedMeshData.uv1.start) / 4);
308
+ var float32Array3 = new Float32Array(buffer, encodedMeshData.uv1.start + offset, (encodedMeshData.uv1.end - encodedMeshData.uv1.start) / 4);
310
309
  modelMesh.setUVs(float32ArrayToVector2(float32Array3, vertexCount), 1);
311
310
  }
312
311
  if (encodedMeshData.uv2) {
313
- var float32Array4 = new Float32Array(buffer, encodedMeshData.uv2.start + offset + byteOffset, (encodedMeshData.uv2.end - encodedMeshData.uv2.start) / 4);
312
+ var float32Array4 = new Float32Array(buffer, encodedMeshData.uv2.start + offset, (encodedMeshData.uv2.end - encodedMeshData.uv2.start) / 4);
314
313
  modelMesh.setUVs(float32ArrayToVector2(float32Array4, vertexCount), 2);
315
314
  }
316
315
  if (encodedMeshData.uv3) {
317
- var float32Array5 = new Float32Array(buffer, encodedMeshData.uv3.start + offset + byteOffset, (encodedMeshData.uv3.end - encodedMeshData.uv3.start) / 4);
316
+ var float32Array5 = new Float32Array(buffer, encodedMeshData.uv3.start + offset, (encodedMeshData.uv3.end - encodedMeshData.uv3.start) / 4);
318
317
  modelMesh.setUVs(float32ArrayToVector2(float32Array5, vertexCount), 3);
319
318
  }
320
319
  if (encodedMeshData.uv4) {
321
- var float32Array6 = new Float32Array(buffer, encodedMeshData.uv4.start + offset + byteOffset, (encodedMeshData.uv4.end - encodedMeshData.uv4.start) / 4);
320
+ var float32Array6 = new Float32Array(buffer, encodedMeshData.uv4.start + offset, (encodedMeshData.uv4.end - encodedMeshData.uv4.start) / 4);
322
321
  modelMesh.setUVs(float32ArrayToVector2(float32Array6, vertexCount), 4);
323
322
  }
324
323
  if (encodedMeshData.uv5) {
325
- var float32Array7 = new Float32Array(buffer, encodedMeshData.uv5.start + offset + byteOffset, (encodedMeshData.uv5.end - encodedMeshData.uv5.start) / 4);
324
+ var float32Array7 = new Float32Array(buffer, encodedMeshData.uv5.start + offset, (encodedMeshData.uv5.end - encodedMeshData.uv5.start) / 4);
326
325
  modelMesh.setUVs(float32ArrayToVector2(float32Array7, vertexCount), 5);
327
326
  }
328
327
  if (encodedMeshData.uv6) {
329
- var float32Array8 = new Float32Array(buffer, encodedMeshData.uv6.start + offset + byteOffset, (encodedMeshData.uv6.end - encodedMeshData.uv6.start) / 4);
328
+ var float32Array8 = new Float32Array(buffer, encodedMeshData.uv6.start + offset, (encodedMeshData.uv6.end - encodedMeshData.uv6.start) / 4);
330
329
  modelMesh.setUVs(float32ArrayToVector2(float32Array8, vertexCount), 6);
331
330
  }
332
331
  if (encodedMeshData.uv7) {
333
- var float32Array9 = new Float32Array(buffer, encodedMeshData.uv7.start + offset + byteOffset, (encodedMeshData.uv7.end - encodedMeshData.uv7.start) / 4);
332
+ var float32Array9 = new Float32Array(buffer, encodedMeshData.uv7.start + offset, (encodedMeshData.uv7.end - encodedMeshData.uv7.start) / 4);
334
333
  modelMesh.setUVs(float32ArrayToVector2(float32Array9, vertexCount), 7);
335
334
  }
336
335
  if (encodedMeshData.colors) {
337
- var float32Array10 = new Float32Array(buffer, encodedMeshData.colors.start + offset + byteOffset, (encodedMeshData.colors.end - encodedMeshData.colors.start) / 4);
336
+ var float32Array10 = new Float32Array(buffer, encodedMeshData.colors.start + offset, (encodedMeshData.colors.end - encodedMeshData.colors.start) / 4);
338
337
  modelMesh.setColors(float32ArrayToVColor(float32Array10, vertexCount));
339
338
  }
340
339
  if (encodedMeshData.boneWeights) {
341
- var float32Array11 = new Float32Array(buffer, encodedMeshData.boneWeights.start + offset + byteOffset, (encodedMeshData.boneWeights.end - encodedMeshData.boneWeights.start) / 4);
340
+ var float32Array11 = new Float32Array(buffer, encodedMeshData.boneWeights.start + offset, (encodedMeshData.boneWeights.end - encodedMeshData.boneWeights.start) / 4);
342
341
  modelMesh.setBoneWeights(float32ArrayToVector4(float32Array11, vertexCount));
343
342
  }
344
343
  if (encodedMeshData.boneIndices) {
345
- var float32Array12 = new Float32Array(buffer, encodedMeshData.boneIndices.start + offset + byteOffset, (encodedMeshData.boneIndices.end - encodedMeshData.boneIndices.start) / 4);
344
+ var float32Array12 = new Float32Array(buffer, encodedMeshData.boneIndices.start + offset, (encodedMeshData.boneIndices.end - encodedMeshData.boneIndices.start) / 4);
346
345
  modelMesh.setBoneIndices(float32ArrayToVector4(float32Array12, vertexCount));
347
346
  }
348
347
  if (encodedMeshData.blendShapes) {
349
348
  encodedMeshData.blendShapes.forEach(function(blendShapeData) {
350
349
  var blendShape = new BlendShape(blendShapeData.name);
351
350
  blendShapeData.frames.forEach(function(frameData) {
352
- var positionArray = new Float32Array(buffer, frameData.deltaPosition.start + offset + byteOffset, (frameData.deltaPosition.end - frameData.deltaPosition.start) / 4);
351
+ var positionArray = new Float32Array(buffer, frameData.deltaPosition.start + offset, (frameData.deltaPosition.end - frameData.deltaPosition.start) / 4);
353
352
  var count = positionArray.length / 3;
354
353
  var deltaPosition = float32ArrayToVector3(positionArray, count);
355
354
  if (frameData.deltaNormals) {
356
- var normalsArray = new Float32Array(buffer, frameData.deltaNormals.start + offset + byteOffset, (frameData.deltaNormals.end - frameData.deltaNormals.start) / 4);
355
+ var normalsArray = new Float32Array(buffer, frameData.deltaNormals.start + offset, (frameData.deltaNormals.end - frameData.deltaNormals.start) / 4);
357
356
  float32ArrayToVector3(normalsArray, count);
358
357
  }
359
358
  if (frameData.deltaTangents) {
360
- var tangentsArray = new Float32Array(buffer, frameData.deltaTangents.start + offset + byteOffset, (frameData.deltaTangents.end - frameData.deltaTangents.start) / 4);
359
+ var tangentsArray = new Float32Array(buffer, frameData.deltaTangents.start + offset, (frameData.deltaTangents.end - frameData.deltaTangents.start) / 4);
361
360
  float32ArrayToVector4(tangentsArray, count);
362
361
  }
363
362
  blendShape.addFrame(frameData.weight, deltaPosition);
@@ -368,9 +367,9 @@ var MeshDecoder = /*#__PURE__*/ function() {
368
367
  if (encodedMeshData.indices) {
369
368
  var indices = null;
370
369
  if (encodedMeshData.indices.type === 0) {
371
- indices = new Uint16Array(buffer, encodedMeshData.indices.start + offset + byteOffset, (encodedMeshData.indices.end - encodedMeshData.indices.start) / 2);
370
+ indices = new Uint16Array(buffer, encodedMeshData.indices.start + offset, (encodedMeshData.indices.end - encodedMeshData.indices.start) / 2);
372
371
  } else {
373
- indices = new Uint32Array(buffer, encodedMeshData.indices.start + offset + byteOffset, (encodedMeshData.indices.end - encodedMeshData.indices.start) / 4);
372
+ indices = new Uint32Array(buffer, encodedMeshData.indices.start + offset, (encodedMeshData.indices.end - encodedMeshData.indices.start) / 4);
374
373
  }
375
374
  modelMesh.setIndices(indices);
376
375
  }
@@ -539,11 +538,17 @@ var ReflectionParser = /*#__PURE__*/ function() {
539
538
  });
540
539
  };
541
540
  _proto.parseClassObject = function parseClassObject(item) {
541
+ var _this = this;
542
542
  var Class = Loader.getClass(item.class);
543
543
  var _item_constructParams;
544
544
  var params = (_item_constructParams = item.constructParams) != null ? _item_constructParams : [];
545
- var instance = _construct(Class, [].concat(params));
546
- return this.parsePropsAndMethods(instance, item);
545
+ return Promise.all(params.map(function(param) {
546
+ return _this.parseBasicType(param);
547
+ })).then(function(resultParams) {
548
+ return _construct(Class, [].concat(resultParams));
549
+ }).then(function(instance) {
550
+ return _this.parsePropsAndMethods(instance, item);
551
+ });
547
552
  };
548
553
  _proto.parsePropsAndMethods = function parsePropsAndMethods(instance, item) {
549
554
  var promises = [];
@@ -551,16 +556,14 @@ var ReflectionParser = /*#__PURE__*/ function() {
551
556
  for(var methodName in item.methods){
552
557
  var methodParams = item.methods[methodName];
553
558
  for(var i = 0, count = methodParams.length; i < count; i++){
554
- var params = methodParams[i];
555
- var promise = this.parseMethod(instance, methodName, params);
556
- promises.push(promise);
559
+ promises.push(this.parseMethod(instance, methodName, methodParams[i]));
557
560
  }
558
561
  }
559
562
  }
560
563
  if (item.props) {
561
564
  var _this = this, _loop = function(key) {
562
565
  var value = item.props[key];
563
- var promise = _this.parseBasicType(value).then(function(v) {
566
+ var promise = _this.parseBasicType(value, instance[key]).then(function(v) {
564
567
  return instance[key] = v;
565
568
  });
566
569
  promises.push(promise);
@@ -582,7 +585,7 @@ var ReflectionParser = /*#__PURE__*/ function() {
582
585
  return (_instance = instance)[methodName].apply(_instance, [].concat(result));
583
586
  });
584
587
  };
585
- _proto.parseBasicType = function parseBasicType(value) {
588
+ _proto.parseBasicType = function parseBasicType(value, originValue) {
586
589
  var _this = this;
587
590
  if (Array.isArray(value)) {
588
591
  return Promise.all(value.map(function(item) {
@@ -599,13 +602,33 @@ var ReflectionParser = /*#__PURE__*/ function() {
599
602
  } else if (ReflectionParser._isEntityRef(value)) {
600
603
  // entity reference
601
604
  return Promise.resolve(this._context.entityMap.get(value.entityId));
602
- } else {
603
- // basic type
604
- return Promise.resolve(value);
605
+ } else if (originValue) {
606
+ var _this1 = this, _loop = function(key) {
607
+ if (key === "methods") {
608
+ var methods = value[key];
609
+ for(var methodName in methods){
610
+ var methodParams = methods[methodName];
611
+ for(var i = 0, count = methodParams.length; i < count; i++){
612
+ var params = methodParams[i];
613
+ var promise = _this1.parseMethod(originValue, methodName, params);
614
+ promises.push(promise);
615
+ }
616
+ }
617
+ } else {
618
+ promises.push(_this1.parseBasicType(value[key], originValue[key]).then(function(v) {
619
+ return originValue[key] = v;
620
+ }));
621
+ }
622
+ };
623
+ var promises = [];
624
+ for(var key in value)_loop(key);
625
+ return Promise.all(promises).then(function() {
626
+ return originValue;
627
+ });
605
628
  }
606
- } else {
607
- return Promise.resolve(value);
608
629
  }
630
+ // primitive type
631
+ return Promise.resolve(value);
609
632
  };
610
633
  _proto._getEntityByConfig = function _getEntityByConfig(entityConfig) {
611
634
  // @ts-ignore
@@ -710,6 +733,7 @@ var AnimationClipDecoder = /*#__PURE__*/ function() {
710
733
  var componentStr = bufferReader.nextStr();
711
734
  var componentType = ComponentMap[componentStr];
712
735
  var property = bufferReader.nextStr();
736
+ var getProperty = bufferReader.nextStr();
713
737
  var curve = void 0;
714
738
  var interpolation = bufferReader.nextUint8();
715
739
  var keysLen = bufferReader.nextUint16();
@@ -834,13 +858,42 @@ var AnimationClipDecoder = /*#__PURE__*/ function() {
834
858
  for(var j7 = 0; j7 < keysLen; ++j7){
835
859
  var keyframe8 = new Keyframe();
836
860
  keyframe8.time = bufferReader.nextFloat32();
837
- keyframe8.value = JSON.parse(bufferReader.nextStr());
861
+ var str = bufferReader.nextStr();
862
+ if (str) {
863
+ keyframe8.value = JSON.parse(str);
864
+ } else {
865
+ keyframe8.value = null;
866
+ }
838
867
  curve.addKey(keyframe8);
839
868
  }
840
869
  break;
841
870
  }
871
+ case "AnimationBoolCurve":
872
+ {
873
+ curve = new AnimationBoolCurve();
874
+ curve.interpolation = interpolation;
875
+ for(var j8 = 0; j8 < keysLen; ++j8){
876
+ var keyframe9 = new Keyframe();
877
+ keyframe9.time = bufferReader.nextFloat32();
878
+ keyframe9.value = bufferReader.nextUint8() === 1;
879
+ curve.addKey(keyframe9);
880
+ }
881
+ break;
882
+ }
883
+ case "AnimationStringCurve":
884
+ {
885
+ curve = new AnimationStringCurve();
886
+ curve.interpolation = interpolation;
887
+ for(var j9 = 0; j9 < keysLen; ++j9){
888
+ var keyframe10 = new Keyframe();
889
+ keyframe10.time = bufferReader.nextFloat32();
890
+ keyframe10.value = bufferReader.nextStr();
891
+ curve.addKey(keyframe10);
892
+ }
893
+ break;
894
+ }
842
895
  }
843
- clip.addCurveBinding(relativePath, componentType, property, curve);
896
+ clip.addCurveBinding(relativePath, componentType, property, getProperty, curve);
844
897
  }
845
898
  resolve(clip);
846
899
  });
@@ -1094,26 +1147,34 @@ var AnimationClipLoader = /*#__PURE__*/ function(Loader1) {
1094
1147
  var curveBindingPromises = clip.curveBindings.map(function(curveBinding) {
1095
1148
  var curve = curveBinding.curve;
1096
1149
  var promises = curve.keys.map(function(key) {
1097
- var value = key.value;
1098
- if (typeof value === "object" && value.refId) {
1099
- return new Promise(function(resolve) {
1100
- resourceManager// @ts-ignore
1101
- .getResourceByRef(value).then(function(asset) {
1102
- key.value = asset;
1103
- resolve(key);
1104
- }).catch(reject);
1105
- });
1106
- }
1150
+ return _this._parseKeyframeValue(key, resourceManager).then(function(actualValue) {
1151
+ key.value = actualValue;
1152
+ });
1107
1153
  });
1108
1154
  return Promise.all(promises);
1109
1155
  });
1110
1156
  return Promise.all(curveBindingPromises).then(function() {
1111
1157
  resolve(clip);
1112
1158
  });
1113
- });
1159
+ }).catch(reject);
1114
1160
  }).catch(reject);
1115
1161
  });
1116
1162
  };
1163
+ _proto._parseKeyframeValue = function _parseKeyframeValue(keyframe, resourceManager) {
1164
+ var _value;
1165
+ var value = keyframe.value;
1166
+ if (typeof value === "object" && ((_value = value) == null ? void 0 : _value.refId)) {
1167
+ return new Promise(function(resolve) {
1168
+ resourceManager// @ts-ignore
1169
+ .getResourceByRef(value).then(function(asset) {
1170
+ keyframe.value = asset;
1171
+ resolve(keyframe);
1172
+ });
1173
+ });
1174
+ } else {
1175
+ return Promise.resolve(keyframe.value);
1176
+ }
1177
+ };
1117
1178
  return AnimationClipLoader;
1118
1179
  }(Loader);
1119
1180
  AnimationClipLoader = __decorate([
@@ -1389,6 +1450,60 @@ FontLoader = __decorate([
1389
1450
  _this.url = url;
1390
1451
  return _this;
1391
1452
  }
1453
+ var _proto = GLTFResource.prototype;
1454
+ /**
1455
+ * Instantiate scene root entity.
1456
+ * @param sceneIndex - Scene index
1457
+ * @returns Root entity
1458
+ */ _proto.instantiateSceneRoot = function instantiateSceneRoot(sceneIndex) {
1459
+ var sceneRoot = sceneIndex === undefined ? this._defaultSceneRoot : this._sceneRoots[sceneIndex];
1460
+ return sceneRoot.clone();
1461
+ };
1462
+ _proto._onDestroy = function _onDestroy() {
1463
+ ReferResource1.prototype._onDestroy.call(this);
1464
+ var _this = this, textures = _this.textures, materials = _this.materials, meshes = _this.meshes;
1465
+ textures && this._disassociationSuperResource(textures);
1466
+ materials && this._disassociationSuperResource(materials);
1467
+ if (meshes) {
1468
+ for(var i = 0, n = meshes.length; i < n; i++){
1469
+ this._disassociationSuperResource(meshes[i]);
1470
+ }
1471
+ }
1472
+ };
1473
+ _proto._disassociationSuperResource = function _disassociationSuperResource(resources) {
1474
+ for(var i = 0, n = resources.length; i < n; i++){
1475
+ // @ts-ignore
1476
+ resources[i]._disassociationSuperResource(this);
1477
+ }
1478
+ };
1479
+ _create_class(GLTFResource, [
1480
+ {
1481
+ key: "extensionsData",
1482
+ get: /**
1483
+ * Extensions data.
1484
+ */ function get() {
1485
+ return this._extensionsData;
1486
+ }
1487
+ },
1488
+ {
1489
+ key: "sceneRoots",
1490
+ get: /**
1491
+ * @deprecated Please use `instantiateSceneRoot` instead.
1492
+ * RootEntities after SceneParser.
1493
+ */ function get() {
1494
+ return this._sceneRoots;
1495
+ }
1496
+ },
1497
+ {
1498
+ key: "defaultSceneRoot",
1499
+ get: /**
1500
+ * @deprecated Please use `instantiateSceneRoot` instead.
1501
+ * RootEntity after SceneParser.
1502
+ */ function get() {
1503
+ return this._defaultSceneRoot;
1504
+ }
1505
+ }
1506
+ ]);
1392
1507
  return GLTFResource;
1393
1508
  }(ReferResource);
1394
1509
 
@@ -1542,12 +1657,29 @@ var TextureWrapMode;
1542
1657
  /**
1543
1658
  * @internal
1544
1659
  */ var GLTFParserContext = /*#__PURE__*/ function() {
1545
- function GLTFParserContext(glTFResource, resourceManager, keepMeshData) {
1660
+ function GLTFParserContext(glTFResource, resourceManager, params) {
1661
+ var _this = this;
1546
1662
  this.glTFResource = glTFResource;
1547
1663
  this.resourceManager = resourceManager;
1548
- this.keepMeshData = keepMeshData;
1664
+ this.params = params;
1549
1665
  this.accessorBufferCache = {};
1550
1666
  this._resourceCache = new Map();
1667
+ this._progress = {
1668
+ taskDetail: {},
1669
+ taskComplete: {
1670
+ loaded: 0,
1671
+ total: 0
1672
+ }
1673
+ };
1674
+ this./**
1675
+ * @internal
1676
+ */ _onTaskDetail = function(url, loaded, total) {
1677
+ var _this__progress_taskDetail, _url;
1678
+ var detail = (_this__progress_taskDetail = _this._progress.taskDetail)[_url = url] || (_this__progress_taskDetail[_url] = {});
1679
+ detail.loaded = loaded;
1680
+ detail.total = total;
1681
+ _this._setTaskDetailProgress(url, loaded, total);
1682
+ };
1551
1683
  this.contentRestorer = new GLTFContentRestorer(glTFResource);
1552
1684
  }
1553
1685
  var _proto = GLTFParserContext.prototype;
@@ -1588,7 +1720,7 @@ var TextureWrapMode;
1588
1720
  };
1589
1721
  _proto.parse = function parse() {
1590
1722
  var _this = this;
1591
- return this.get(0).then(function(json) {
1723
+ var promise = this.get(0).then(function(json) {
1592
1724
  _this.glTF = json;
1593
1725
  return Promise.all([
1594
1726
  _this.get(1),
@@ -1599,10 +1731,48 @@ var TextureWrapMode;
1599
1731
  _this.get(9),
1600
1732
  _this.get(2)
1601
1733
  ]).then(function() {
1734
+ var glTFResource = _this.glTFResource;
1735
+ if (glTFResource.skins || glTFResource.animations) {
1736
+ _this._createAnimator(_this, glTFResource.animations);
1737
+ }
1602
1738
  _this.resourceManager.addContentRestorer(_this.contentRestorer);
1603
- return _this.glTFResource;
1739
+ return glTFResource;
1604
1740
  });
1605
1741
  });
1742
+ this._addTaskCompletePromise(promise);
1743
+ return promise;
1744
+ };
1745
+ /**
1746
+ * @internal
1747
+ */ _proto._addTaskCompletePromise = function _addTaskCompletePromise(taskPromise) {
1748
+ var _this = this;
1749
+ var task = this._progress.taskComplete;
1750
+ task.total += 1;
1751
+ taskPromise.then(function() {
1752
+ _this._setTaskCompleteProgress(++task.loaded, task.total);
1753
+ });
1754
+ };
1755
+ _proto._createAnimator = function _createAnimator(context, animations) {
1756
+ var defaultSceneRoot = context.glTFResource.defaultSceneRoot;
1757
+ var animator = defaultSceneRoot.addComponent(Animator);
1758
+ var animatorController = new AnimatorController();
1759
+ var layer = new AnimatorControllerLayer("layer");
1760
+ var animatorStateMachine = new AnimatorStateMachine();
1761
+ animatorController.addLayer(layer);
1762
+ animator.animatorController = animatorController;
1763
+ layer.stateMachine = animatorStateMachine;
1764
+ if (animations) {
1765
+ for(var i = 0; i < animations.length; i++){
1766
+ var animationClip = animations[i];
1767
+ var name = animationClip.name;
1768
+ var uniqueName = animatorStateMachine.makeUniqueStateName(name);
1769
+ if (uniqueName !== name) {
1770
+ console.warn("AnimatorState name is existed, name: " + name + " reset to " + uniqueName);
1771
+ }
1772
+ var animatorState = animatorStateMachine.addState(uniqueName);
1773
+ animatorState.clip = animationClip;
1774
+ }
1775
+ }
1606
1776
  };
1607
1777
  _proto._handleSubAsset = function _handleSubAsset(resource, type, index) {
1608
1778
  var _this = this;
@@ -1666,7 +1836,7 @@ var GLTFParserType;
1666
1836
  var _obj;
1667
1837
  var glTFSchemaMap = (_obj = {}, _obj[2] = "scenes", _obj[3] = "buffers", _obj[4] = "textures", _obj[5] = "materials", _obj[6] = "meshes", _obj[7] = "nodes", _obj[8] = "skins", _obj[9] = "animations", _obj);
1668
1838
  var _obj1;
1669
- var glTFResourceMap = (_obj1 = {}, _obj1[2] = "sceneRoots", _obj1[4] = "textures", _obj1[5] = "materials", _obj1[6] = "meshes", _obj1[7] = "entities", _obj1[8] = "skins", _obj1[9] = "animations", _obj1);
1839
+ var glTFResourceMap = (_obj1 = {}, _obj1[2] = "_sceneRoots", _obj1[4] = "textures", _obj1[5] = "materials", _obj1[6] = "meshes", _obj1[7] = "entities", _obj1[8] = "skins", _obj1[9] = "animations", _obj1);
1670
1840
  function registerGLTFParser(pipeline) {
1671
1841
  return function(Parser) {
1672
1842
  var parser = new Parser();
@@ -2243,7 +2413,7 @@ var SupercompressionScheme;
2243
2413
  alphaSliceByteLength: sgdReader.nextUint32()
2244
2414
  };
2245
2415
  }
2246
- var endpointsByteOffset = sgdByteOffset + sgdReader.offset;
2416
+ var endpointsByteOffset = sgdByteOffset + sgdReader.position;
2247
2417
  var selectorsByteOffset = endpointsByteOffset + endpointsByteLength;
2248
2418
  var tablesByteOffset = selectorsByteOffset + selectorsByteLength;
2249
2419
  var extendedByteOffset = tablesByteOffset + tablesByteLength;
@@ -2435,6 +2605,25 @@ var AbstractTranscoder = /*#__PURE__*/ function() {
2435
2605
  }();
2436
2606
 
2437
2607
  /** @internal */ function TranscodeWorkerCode$1() {
2608
+ var initPromise;
2609
+ var init = function init(wasmBinary) {
2610
+ if (!initPromise) {
2611
+ initPromise = new Promise(function(resolve, reject) {
2612
+ var BasisModule = {
2613
+ wasmBinary: wasmBinary,
2614
+ onRuntimeInitialized: function() {
2615
+ return resolve(BasisModule);
2616
+ },
2617
+ onAbort: reject
2618
+ };
2619
+ self["BASIS"](BasisModule);
2620
+ }).then(function(BasisModule) {
2621
+ BasisModule.initializeBasis();
2622
+ return BasisModule.KTX2File;
2623
+ });
2624
+ }
2625
+ return initPromise;
2626
+ };
2438
2627
  self.onmessage = function onmessage(event) {
2439
2628
  var message = event.data;
2440
2629
  switch(message.type){
@@ -2561,6 +2750,7 @@ function transcode(buffer, targetFormat, KTX2File) {
2561
2750
  var faceCount = ktx2File.getFaces();
2562
2751
  var format = getTranscodeFormatFromTarget(targetFormat, hasAlpha);
2563
2752
  var faces = new Array(faceCount);
2753
+ var isBC = format === 2 || format === 3 || format === 7;
2564
2754
  for(var face = 0; face < faceCount; face++){
2565
2755
  var mipmaps = new Array(levelCount);
2566
2756
  for(var mip = 0; mip < levelCount; mip++){
@@ -2568,8 +2758,15 @@ function transcode(buffer, targetFormat, KTX2File) {
2568
2758
  var mipWidth = void 0, mipHeight = void 0;
2569
2759
  for(var layer = 0; layer < layerCount; layer++){
2570
2760
  var levelInfo = ktx2File.getImageLevelInfo(mip, layer, face);
2571
- mipWidth = levelInfo.origWidth;
2572
- mipHeight = levelInfo.origHeight;
2761
+ // see: https://github.com/KhronosGroup/KTX-Software/issues/254
2762
+ if (isBC && mip === 0 && (width !== levelInfo.width || height !== levelInfo.height)) {
2763
+ width = mipWidth = levelInfo.width;
2764
+ height = mipHeight = levelInfo.height;
2765
+ console.warn("KTX2 transcode to BC will resize to width: " + width + ", height: " + height + ". You'd better use an image whose size if multiple of 4.");
2766
+ } else {
2767
+ mipWidth = levelInfo.origWidth;
2768
+ mipHeight = levelInfo.origHeight;
2769
+ }
2573
2770
  var dst = new Uint8Array(ktx2File.getImageTranscodedSizeInBytes(mip, layer, 0, format));
2574
2771
  var status = ktx2File.transcodeImage(dst, mip, layer, face, format, 0, -1, -1);
2575
2772
  if (!status) {
@@ -2635,7 +2832,7 @@ function transcode(buffer, targetFormat, KTX2File) {
2635
2832
  } else {
2636
2833
  var funcCode = TranscodeWorkerCode$1.toString();
2637
2834
  var transcodeString = funcCode.substring(funcCode.indexOf("{"), funcCode.lastIndexOf("}") + 1);
2638
- var workerCode = "\n " + jsCode + "\n var init = (" + _init.toString() + ")();\n " + transcode.toString() + "\n " + transcodeString + "\n ";
2835
+ var workerCode = "\n " + jsCode + "\n " + transcode.toString() + "\n " + transcodeString + "\n ";
2639
2836
  var workerURL = URL.createObjectURL(new Blob([
2640
2837
  workerCode
2641
2838
  ], {
@@ -2881,10 +3078,14 @@ var KTX2Loader = (_KTX2Loader = /*#__PURE__*/ function(Loader1) {
2881
3078
  return Loader1.apply(this, arguments);
2882
3079
  }
2883
3080
  var _proto = KTX2Loader1.prototype;
2884
- _proto.initialize = function initialize(engine, configuration) {
3081
+ _proto.initialize = function initialize(_, configuration) {
2885
3082
  if (configuration.ktx2Loader) {
2886
3083
  var options = configuration.ktx2Loader;
2887
- if (this._isKhronosSupported(options.priorityFormats, engine) && options.workerCount !== 0) {
3084
+ if (options.priorityFormats) {
3085
+ KTX2Loader._priorityFormats["etc1s"] = options.priorityFormats;
3086
+ KTX2Loader._priorityFormats["uastc"] = options.priorityFormats;
3087
+ }
3088
+ if (options.transcoder === /** Khronos transcoder. */ 1) {
2888
3089
  return KTX2Loader._getKhronosTranscoder(options.workerCount).init();
2889
3090
  } else {
2890
3091
  return KTX2Loader._getBinomialLLCTranscoder(options.workerCount).init();
@@ -2894,34 +3095,16 @@ var KTX2Loader = (_KTX2Loader = /*#__PURE__*/ function(Loader1) {
2894
3095
  /**
2895
3096
  * @internal
2896
3097
  */ _proto.load = function load(item, resourceManager) {
2897
- return this.request(item.url, {
2898
- type: "arraybuffer"
2899
- }).then(function(buffer) {
2900
- return KTX2Loader._parseBuffer(new Uint8Array(buffer), resourceManager.engine, item.params).then(function(param) {
2901
- var engine = param.engine, result = param.result, targetFormat = param.targetFormat, params = param.params;
2902
- return KTX2Loader._createTextureByBuffer(engine, result, targetFormat, params);
2903
- });
2904
- });
2905
- };
2906
- _proto._isKhronosSupported = function _isKhronosSupported(priorityFormats, engine) {
2907
- if (priorityFormats === void 0) priorityFormats = [
2908
- KTX2TargetFormat.ASTC,
2909
- KTX2TargetFormat.ETC,
2910
- KTX2TargetFormat.BC7,
2911
- KTX2TargetFormat.BC1_BC3,
2912
- KTX2TargetFormat.PVRTC,
2913
- KTX2TargetFormat.R8G8B8A8
2914
- ];
2915
- var supportedList = new Array();
2916
- if (Array.isArray(priorityFormats[0])) {
2917
- for(var i = 0; i < priorityFormats.length; i++){
2918
- supportedList.push(KTX2Loader._detectSupportedFormat(engine._hardwareRenderer, priorityFormats[i]));
2919
- }
2920
- } else {
2921
- supportedList.push(KTX2Loader._detectSupportedFormat(engine._hardwareRenderer, priorityFormats));
2922
- }
2923
- return supportedList.every(function(format) {
2924
- return KhronosTranscoder.transcoderMap[format];
3098
+ var _this = this;
3099
+ return new AssetPromise(function(resolve, reject, setTaskCompleteProgress, setTaskDetailProgress) {
3100
+ _this.request(item.url, {
3101
+ type: "arraybuffer"
3102
+ }).onProgress(setTaskCompleteProgress, setTaskDetailProgress).then(function(buffer) {
3103
+ return KTX2Loader._parseBuffer(new Uint8Array(buffer), resourceManager.engine, item.params).then(function(param) {
3104
+ var engine = param.engine, result = param.result, targetFormat = param.targetFormat, params = param.params;
3105
+ return KTX2Loader._createTextureByBuffer(engine, result, targetFormat, params);
3106
+ });
3107
+ }).then(resolve).catch(reject);
2925
3108
  });
2926
3109
  };
2927
3110
  /**
@@ -2936,7 +3119,8 @@ var KTX2Loader = (_KTX2Loader = /*#__PURE__*/ function(Loader1) {
2936
3119
  /** @internal */ KTX2Loader1._parseBuffer = function _parseBuffer(buffer, engine, params) {
2937
3120
  var _params;
2938
3121
  var ktx2Container = new KTX2Container(buffer);
2939
- var formatPriorities = (_params = params) == null ? void 0 : _params.priorityFormats;
3122
+ var _params_priorityFormats;
3123
+ var formatPriorities = (_params_priorityFormats = (_params = params) == null ? void 0 : _params.priorityFormats) != null ? _params_priorityFormats : KTX2Loader._priorityFormats[ktx2Container.isUASTC ? "uastc" : "etc1s"];
2940
3124
  var targetFormat = KTX2Loader._decideTargetFormat(engine, ktx2Container, formatPriorities);
2941
3125
  var transcodeResultPromise;
2942
3126
  if (KTX2Loader._isBinomialInit || !KhronosTranscoder.transcoderMap[targetFormat] || !ktx2Container.isUASTC) {
@@ -3003,18 +3187,22 @@ var KTX2Loader = (_KTX2Loader = /*#__PURE__*/ function(Loader1) {
3003
3187
  return targetFormat;
3004
3188
  };
3005
3189
  KTX2Loader1._detectSupportedFormat = function _detectSupportedFormat(renderer, priorityFormats) {
3006
- if (priorityFormats === void 0) priorityFormats = [
3007
- KTX2TargetFormat.ASTC,
3008
- KTX2TargetFormat.ETC,
3009
- KTX2TargetFormat.BC7,
3010
- KTX2TargetFormat.BC1_BC3,
3011
- KTX2TargetFormat.PVRTC
3012
- ];
3013
3190
  for(var i = 0; i < priorityFormats.length; i++){
3014
- var capabilities = this._supportedMap[priorityFormats[i]];
3015
- for(var j = 0; j < capabilities.length; j++){
3016
- if (renderer.canIUse(capabilities[j])) {
3017
- return priorityFormats[i];
3191
+ var format = priorityFormats[i];
3192
+ var capabilities = this._supportedMap[format];
3193
+ if (capabilities) {
3194
+ for(var j = 0; j < capabilities.length; j++){
3195
+ if (renderer.canIUse(capabilities[j])) {
3196
+ return format;
3197
+ }
3198
+ }
3199
+ } else {
3200
+ switch(priorityFormats[i]){
3201
+ case KTX2TargetFormat.R8G8B8A8:
3202
+ return format;
3203
+ case KTX2TargetFormat.R8:
3204
+ case KTX2TargetFormat.R8G8:
3205
+ if (renderer.isWebGL2) return format;
3018
3206
  }
3019
3207
  }
3020
3208
  }
@@ -3051,6 +3239,23 @@ var KTX2Loader = (_KTX2Loader = /*#__PURE__*/ function(Loader1) {
3051
3239
  return KTX2Loader1;
3052
3240
  }(Loader), function() {
3053
3241
  _KTX2Loader._isBinomialInit = false;
3242
+ }(), function() {
3243
+ _KTX2Loader._priorityFormats = {
3244
+ etc1s: [
3245
+ KTX2TargetFormat.ETC,
3246
+ KTX2TargetFormat.BC7,
3247
+ KTX2TargetFormat.ASTC,
3248
+ KTX2TargetFormat.BC1_BC3,
3249
+ KTX2TargetFormat.PVRTC
3250
+ ],
3251
+ uastc: [
3252
+ KTX2TargetFormat.ASTC,
3253
+ KTX2TargetFormat.BC7,
3254
+ KTX2TargetFormat.ETC,
3255
+ KTX2TargetFormat.BC1_BC3,
3256
+ KTX2TargetFormat.PVRTC
3257
+ ]
3258
+ };
3054
3259
  }(), function() {
3055
3260
  var _obj;
3056
3261
  _KTX2Loader._supportedMap = (_obj = {}, _obj[KTX2TargetFormat.ASTC] = [
@@ -3071,6 +3276,11 @@ KTX2Loader = __decorate([
3071
3276
  "ktx2"
3072
3277
  ])
3073
3278
  ], KTX2Loader);
3279
+ var KTX2Transcoder;
3280
+ (function(KTX2Transcoder) {
3281
+ KTX2Transcoder[KTX2Transcoder[/** BinomialLLC transcoder. */ "BinomialLLC"] = 0] = "BinomialLLC";
3282
+ KTX2Transcoder[KTX2Transcoder["Khronos"] = 1] = "Khronos";
3283
+ })(KTX2Transcoder || (KTX2Transcoder = {}));
3074
3284
 
3075
3285
  /**
3076
3286
  * @internal
@@ -3421,7 +3631,7 @@ var GLTFSchemaParser = /*#__PURE__*/ function(GLTFParser1) {
3421
3631
  };
3422
3632
  var isGLB = this._isGLB(url);
3423
3633
  contentRestorer.isGLB = isGLB;
3424
- var promise = isGLB ? request(url, requestConfig).then(function(glb) {
3634
+ var promise = isGLB ? request(url, requestConfig).onProgress(undefined, context._onTaskDetail).then(function(glb) {
3425
3635
  restoreBufferRequests.push(new BufferRequestInfo(url, requestConfig));
3426
3636
  return GLTFUtils.parseGLB(context, glb);
3427
3637
  }).then(function(param) {
@@ -3430,7 +3640,7 @@ var GLTFSchemaParser = /*#__PURE__*/ function(GLTFParser1) {
3430
3640
  return glTF;
3431
3641
  }) : request(url, {
3432
3642
  type: "json"
3433
- });
3643
+ }).onProgress(undefined, context._onTaskDetail);
3434
3644
  return promise;
3435
3645
  };
3436
3646
  _proto._isGLB = function _isGLB(url) {
@@ -3462,9 +3672,9 @@ var GLTFAnimationParser = /*#__PURE__*/ function(GLTFParser1) {
3462
3672
  * @internal
3463
3673
  */ GLTFAnimationParser1._parseStandardProperty = function _parseStandardProperty(context, animationClip, animationInfo) {
3464
3674
  var _loop = function(j, m) {
3465
- var gltfSampler = samplers[j];
3466
- var inputAccessor = accessors[gltfSampler.input];
3467
- var outputAccessor = accessors[gltfSampler.output];
3675
+ var glTFSampler = samplers[j];
3676
+ var inputAccessor = accessors[glTFSampler.input];
3677
+ var outputAccessor = accessors[glTFSampler.output];
3468
3678
  var promise = Promise.all([
3469
3679
  GLTFUtils.getAccessorBuffer(context, bufferViews, inputAccessor),
3470
3680
  GLTFUtils.getAccessorBuffer(context, bufferViews, outputAccessor)
@@ -3480,8 +3690,8 @@ var GLTFAnimationParser = /*#__PURE__*/ function(GLTFParser1) {
3480
3690
  output = scaled;
3481
3691
  }
3482
3692
  var outputStride = output.length / input.length;
3483
- var _gltfSampler_interpolation;
3484
- var interpolation = (_gltfSampler_interpolation = gltfSampler.interpolation) != null ? _gltfSampler_interpolation : AnimationSamplerInterpolation.Linear;
3693
+ var _glTFSampler_interpolation;
3694
+ var interpolation = (_glTFSampler_interpolation = glTFSampler.interpolation) != null ? _glTFSampler_interpolation : AnimationSamplerInterpolation.Linear;
3485
3695
  var samplerInterpolation;
3486
3696
  switch(interpolation){
3487
3697
  case AnimationSamplerInterpolation.CubicSpine:
@@ -3514,10 +3724,11 @@ var GLTFAnimationParser = /*#__PURE__*/ function(GLTFParser1) {
3514
3724
  var promises = new Array();
3515
3725
  // parse samplers
3516
3726
  for(var j = 0, m = samplers.length; j < m; j++)_loop(j);
3727
+ promises.push(context.get(GLTFParserType.Scene));
3517
3728
  return Promise.all(promises).then(function() {
3518
3729
  for(var j = 0, m = channels.length; j < m; j++){
3519
- var gltfChannel = channels[j];
3520
- var target = gltfChannel.target;
3730
+ var glTFChannel = channels[j];
3731
+ var target = glTFChannel.target;
3521
3732
  var channelTargetEntity = entities[target.node];
3522
3733
  var relativePath = "";
3523
3734
  var entity = channelTargetEntity;
@@ -3525,6 +3736,10 @@ var GLTFAnimationParser = /*#__PURE__*/ function(GLTFParser1) {
3525
3736
  relativePath = relativePath === "" ? "" + entity.name : entity.name + "/" + relativePath;
3526
3737
  entity = entity.parent;
3527
3738
  }
3739
+ // If the target node is in the default scene, relativePath will be empty
3740
+ if (context.glTFResource.sceneRoots.indexOf(entity) === -1) {
3741
+ continue;
3742
+ }
3528
3743
  var ComponentType = void 0;
3529
3744
  var propertyName = void 0;
3530
3745
  switch(target.path){
@@ -3545,14 +3760,21 @@ var GLTFAnimationParser = /*#__PURE__*/ function(GLTFParser1) {
3545
3760
  propertyName = "blendShapeWeights";
3546
3761
  break;
3547
3762
  }
3548
- var curve = _this._addCurve(target.path, gltfChannel, sampleDataCollection);
3549
- animationClip.addCurveBinding(relativePath, ComponentType, propertyName, curve);
3763
+ var curve = _this._addCurve(target.path, glTFChannel, sampleDataCollection);
3764
+ if (target.path === AnimationChannelTargetPath.WEIGHTS) {
3765
+ var mesh = glTF.nodes[target.node].mesh;
3766
+ for(var i = 0, n = glTF.meshes[mesh].primitives.length; i < n; i++){
3767
+ animationClip.addCurveBinding(relativePath, ComponentType, i, propertyName, curve);
3768
+ }
3769
+ } else {
3770
+ animationClip.addCurveBinding(relativePath, ComponentType, propertyName, curve);
3771
+ }
3550
3772
  }
3551
3773
  return animationClip;
3552
3774
  });
3553
3775
  };
3554
- GLTFAnimationParser1._addCurve = function _addCurve(animationChannelTargetPath, gltfChannel, sampleDataCollection) {
3555
- var sampleData = sampleDataCollection[gltfChannel.sampler];
3776
+ GLTFAnimationParser1._addCurve = function _addCurve(animationChannelTargetPath, glTFChannel, sampleDataCollection) {
3777
+ var sampleData = sampleDataCollection[glTFChannel.sampler];
3556
3778
  var input = sampleData.input, output = sampleData.output, outputSize = sampleData.outputSize;
3557
3779
  switch(animationChannelTargetPath){
3558
3780
  case AnimationChannelTargetPath.TRANSLATION:
@@ -3644,7 +3866,9 @@ var GLTFBufferParser = /*#__PURE__*/ function(GLTFParser1) {
3644
3866
  };
3645
3867
  var absoluteUrl = Utils.resolveAbsoluteUrl(url, bufferInfo.uri);
3646
3868
  restoreBufferRequests.push(new BufferRequestInfo(absoluteUrl, requestConfig));
3647
- return request(absoluteUrl, requestConfig);
3869
+ var promise = request(absoluteUrl, requestConfig).onProgress(undefined, context._onTaskDetail);
3870
+ context._addTaskCompletePromise(promise);
3871
+ return promise;
3648
3872
  };
3649
3873
  return GLTFBufferParser;
3650
3874
  }(GLTFParser);
@@ -3659,10 +3883,13 @@ var GLTFEntityParser = /*#__PURE__*/ function(GLTFParser1) {
3659
3883
  }
3660
3884
  var _proto = GLTFEntityParser.prototype;
3661
3885
  _proto.parse = function parse(context, index) {
3886
+ var glTFResource = context.glTFResource;
3662
3887
  var entityInfo = context.glTF.nodes[index];
3663
- var engine = context.glTFResource.engine;
3888
+ var engine = glTFResource.engine;
3664
3889
  var matrix = entityInfo.matrix, translation = entityInfo.translation, rotation = entityInfo.rotation, scale = entityInfo.scale, extensions = entityInfo.extensions;
3665
3890
  var entity = new Entity(engine, entityInfo.name || "_GLTF_ENTITY_" + index);
3891
+ // @ts-ignore
3892
+ entity._markAsTemplate(glTFResource);
3666
3893
  var transform = entity.transform;
3667
3894
  if (matrix) {
3668
3895
  var localMatrix = transform.localMatrix;
@@ -3704,7 +3931,8 @@ var GLTFMaterialParser = /*#__PURE__*/ function(GLTFParser1) {
3704
3931
  var _proto = GLTFMaterialParser1.prototype;
3705
3932
  _proto.parse = function parse(context, index) {
3706
3933
  var materialInfo = context.glTF.materials[index];
3707
- var engine = context.glTFResource.engine;
3934
+ var glTFResource = context.glTFResource;
3935
+ var engine = glTFResource.engine;
3708
3936
  var material = GLTFParser.executeExtensionsCreateAndParse(materialInfo.extensions, context, materialInfo);
3709
3937
  if (!material) {
3710
3938
  material = new PBRMaterial(engine);
@@ -3712,8 +3940,10 @@ var GLTFMaterialParser = /*#__PURE__*/ function(GLTFParser1) {
3712
3940
  GLTFMaterialParser._parseStandardProperty(context, material, materialInfo);
3713
3941
  }
3714
3942
  return Promise.resolve(material).then(function(material) {
3715
- material || (material = GLTFMaterialParser._getDefaultMaterial(context.glTFResource.engine));
3943
+ material || (material = GLTFMaterialParser._getDefaultMaterial(engine));
3716
3944
  GLTFParser.executeExtensionsAdditiveAndParse(materialInfo.extensions, context, material, materialInfo);
3945
+ // @ts-ignore
3946
+ material._associationSuperResource(glTFResource);
3717
3947
  return material;
3718
3948
  });
3719
3949
  };
@@ -3834,14 +4064,20 @@ var GLTFMeshParser = (_GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
3834
4064
  var mesh = GLTFParser.executeExtensionsCreateAndParse(gltfPrimitive.extensions, context, gltfPrimitive, meshInfo);
3835
4065
  if (mesh) {
3836
4066
  if (_instanceof(mesh, ModelMesh)) {
4067
+ // @ts-ignore
4068
+ mesh._associationSuperResource(glTFResource);
3837
4069
  resolve(mesh);
3838
4070
  } else {
3839
4071
  mesh.then(function(mesh) {
3840
- return resolve(mesh);
4072
+ // @ts-ignore
4073
+ mesh._associationSuperResource(glTFResource);
4074
+ resolve(mesh);
3841
4075
  });
3842
4076
  }
3843
4077
  } else {
3844
4078
  var mesh1 = new ModelMesh(engine, meshInfo.name || i + "");
4079
+ // @ts-ignore
4080
+ mesh1._associationSuperResource(glTFResource);
3845
4081
  var meshRestoreInfo = new ModelMeshRestoreInfo();
3846
4082
  meshRestoreInfo.mesh = mesh1;
3847
4083
  context.contentRestorer.meshes.push(meshRestoreInfo);
@@ -3861,12 +4097,13 @@ var GLTFMeshParser = (_GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
3861
4097
  return context.get(GLTFParserType.Buffer).then(function(buffers) {
3862
4098
  return GLTFUtils.getAccessorData(glTF, indexAccessor, buffers);
3863
4099
  });
3864
- }, context.keepMeshData).then(resolve);
4100
+ }, context.params.keepMeshData).then(resolve);
3865
4101
  }
3866
4102
  });
3867
4103
  };
3868
4104
  var meshInfo = context.glTF.meshes[index];
3869
- var glTF = context.glTF, engine = context.glTFResource.engine;
4105
+ var glTF = context.glTF, glTFResource = context.glTFResource;
4106
+ var engine = glTFResource.engine;
3870
4107
  var primitivePromises = new Array();
3871
4108
  for(var i = 0, length = meshInfo.primitives.length; i < length; i++)_loop(i);
3872
4109
  return Promise.all(primitivePromises);
@@ -4039,9 +4276,9 @@ var GLTFSceneParser = /*#__PURE__*/ function(GLTFParser1) {
4039
4276
  }
4040
4277
  var _proto = GLTFSceneParser.prototype;
4041
4278
  _proto.parse = function parse(context, index) {
4042
- var _this = this;
4043
4279
  var _context_glTF = context.glTF, scenes = _context_glTF.scenes, _context_glTF_scene = _context_glTF.scene, scene = _context_glTF_scene === void 0 ? 0 : _context_glTF_scene, glTFResource = context.glTFResource;
4044
4280
  var sceneInfo = scenes[index];
4281
+ var sceneExtensions = sceneInfo.extensions;
4045
4282
  var engine = glTFResource.engine;
4046
4283
  var isDefaultScene = scene === index;
4047
4284
  var sceneNodes = sceneInfo.nodes;
@@ -4055,30 +4292,15 @@ var GLTFSceneParser = /*#__PURE__*/ function(GLTFParser1) {
4055
4292
  sceneRoot.addChild(childEntity);
4056
4293
  }
4057
4294
  }
4058
- // @ts-ignore
4059
- sceneRoot._hookResource = glTFResource;
4060
- // @ts-ignore
4061
- glTFResource._addReferCount(1);
4062
4295
  if (isDefaultScene) {
4063
- glTFResource.defaultSceneRoot = sceneRoot;
4296
+ glTFResource._defaultSceneRoot = sceneRoot;
4064
4297
  }
4065
4298
  var promises = new Array();
4066
4299
  for(var i1 = 0; i1 < sceneNodes.length; i1++){
4067
4300
  promises.push(this._parseEntityComponent(context, sceneNodes[i1]));
4068
4301
  }
4069
4302
  return Promise.all(promises).then(function() {
4070
- if (isDefaultScene) {
4071
- return Promise.all([
4072
- context.get(GLTFParserType.Skin),
4073
- context.get(GLTFParserType.Animation)
4074
- ]).then(function(param) {
4075
- var skins = param[0], animations = param[1];
4076
- if (skins || animations) {
4077
- _this._createAnimator(context, animations);
4078
- }
4079
- return sceneRoot;
4080
- });
4081
- }
4303
+ GLTFParser.executeExtensionsAdditiveAndParse(sceneExtensions, context, sceneRoot, sceneInfo);
4082
4304
  return sceneRoot;
4083
4305
  });
4084
4306
  };
@@ -4190,28 +4412,6 @@ var GLTFSceneParser = /*#__PURE__*/ function(GLTFParser1) {
4190
4412
  for(var i = 0; i < glTFMeshPrimitives.length; i++)_loop(i);
4191
4413
  return Promise.all(promises);
4192
4414
  };
4193
- _proto._createAnimator = function _createAnimator(context, animations) {
4194
- var defaultSceneRoot = context.glTFResource.defaultSceneRoot;
4195
- var animator = defaultSceneRoot.addComponent(Animator);
4196
- var animatorController = new AnimatorController();
4197
- var layer = new AnimatorControllerLayer("layer");
4198
- var animatorStateMachine = new AnimatorStateMachine();
4199
- animatorController.addLayer(layer);
4200
- animator.animatorController = animatorController;
4201
- layer.stateMachine = animatorStateMachine;
4202
- if (animations) {
4203
- for(var i = 0; i < animations.length; i++){
4204
- var animationClip = animations[i];
4205
- var name = animationClip.name;
4206
- var uniqueName = animatorStateMachine.makeUniqueStateName(name);
4207
- if (uniqueName !== name) {
4208
- console.warn("AnimatorState name is existed, name: " + name + " reset to " + uniqueName);
4209
- }
4210
- var animatorState = animatorStateMachine.addState(uniqueName);
4211
- animatorState.clip = animationClip;
4212
- }
4213
- }
4214
- };
4215
4415
  _proto._computeLocalBounds = function _computeLocalBounds(skinnedMeshRenderer, mesh, bones, rootBone, inverseBindMatrices) {
4216
4416
  var rootBoneIndex = bones.indexOf(rootBone);
4217
4417
  if (rootBoneIndex !== -1) {
@@ -4360,11 +4560,12 @@ var GLTFTextureParser = (_GLTFTextureParser = /*#__PURE__*/ function(GLTFParser1
4360
4560
  params: {
4361
4561
  mipmap: (_samplerInfo = samplerInfo) == null ? void 0 : _samplerInfo.mipmap
4362
4562
  }
4363
- }).then(function(texture) {
4563
+ }).onProgress(undefined, context._onTaskDetail).then(function(texture) {
4364
4564
  texture.name = textureName || imageName || texture.name || "texture_" + index;
4365
4565
  useSampler && GLTFUtils.parseSampler(texture, samplerInfo);
4366
4566
  return texture;
4367
4567
  });
4568
+ context._addTaskCompletePromise(texture);
4368
4569
  } else {
4369
4570
  var bufferView = glTF.bufferViews[bufferViewIndex];
4370
4571
  texture = context.get(GLTFParserType.Buffer).then(function(buffers) {
@@ -4386,6 +4587,8 @@ var GLTFTextureParser = (_GLTFTextureParser = /*#__PURE__*/ function(GLTFParser1
4386
4587
  }
4387
4588
  return Promise.resolve(texture).then(function(texture) {
4388
4589
  GLTFParser.executeExtensionsAdditiveAndParse(extensions, context, texture, textureInfo);
4590
+ // @ts-ignore
4591
+ texture._associationSuperResource(glTFResource);
4389
4592
  return texture;
4390
4593
  });
4391
4594
  };
@@ -4443,12 +4646,17 @@ var GLTFLoader = /*#__PURE__*/ function(Loader1) {
4443
4646
  }
4444
4647
  var _proto = GLTFLoader.prototype;
4445
4648
  _proto.load = function load(item, resourceManager) {
4446
- var _params;
4447
4649
  var url = item.url;
4448
4650
  var params = item.params;
4449
4651
  var glTFResource = new GLTFResource(resourceManager.engine, url);
4450
- var context = new GLTFParserContext(glTFResource, resourceManager, !!((_params = params) == null ? void 0 : _params.keepMeshData));
4451
- return context.parse();
4652
+ var context = new GLTFParserContext(glTFResource, resourceManager, _extends({
4653
+ keepMeshData: false
4654
+ }, params));
4655
+ return new AssetPromise(function(resolve, reject, setTaskCompleteProgress, setTaskDetailProgress) {
4656
+ context._setTaskCompleteProgress = setTaskCompleteProgress;
4657
+ context._setTaskDetailProgress = setTaskDetailProgress;
4658
+ context.parse().then(resolve).catch(reject);
4659
+ });
4452
4660
  };
4453
4661
  return GLTFLoader;
4454
4662
  }(Loader);
@@ -5095,6 +5303,12 @@ var MaterialLoader = /*#__PURE__*/ function(Loader1) {
5095
5303
  materialShaderData.setTexture(key, texture);
5096
5304
  }));
5097
5305
  break;
5306
+ case "Boolean":
5307
+ materialShaderData.setInt(key, value ? 1 : 0);
5308
+ break;
5309
+ case "Integer":
5310
+ materialShaderData.setInt(key, Number(value));
5311
+ break;
5098
5312
  }
5099
5313
  };
5100
5314
  var engine = resourceManager.engine;
@@ -5215,7 +5429,7 @@ var SpriteAtlasLoader = /*#__PURE__*/ function(Loader1) {
5215
5429
  var _proto = SpriteAtlasLoader.prototype;
5216
5430
  _proto.load = function load(item, resourceManager) {
5217
5431
  var _this = this;
5218
- return new AssetPromise(function(resolve, reject, _, onCancel) {
5432
+ return new AssetPromise(function(resolve, reject, _, __, onCancel) {
5219
5433
  var chainPromises = [];
5220
5434
  onCancel(function() {
5221
5435
  for(var i = 0; i < chainPromises.length; i++){
@@ -5230,9 +5444,10 @@ var SpriteAtlasLoader = /*#__PURE__*/ function(Loader1) {
5230
5444
  var _loop = function(i) {
5231
5445
  var atlasItem = atlasItems[i];
5232
5446
  if (atlasItem.img) {
5447
+ var _atlasItem_type;
5233
5448
  chainPromises.push(resourceManager.load({
5234
5449
  url: Utils.resolveAbsoluteUrl(item.url, atlasItem.img),
5235
- type: AssetType.Texture2D,
5450
+ type: (_atlasItem_type = atlasItem.type) != null ? _atlasItem_type : AssetType.Texture2D,
5236
5451
  params: {
5237
5452
  format: format,
5238
5453
  mipmap: mipmap
@@ -5362,15 +5577,19 @@ var Texture2DLoader = /*#__PURE__*/ function(Loader1) {
5362
5577
  var _proto = Texture2DLoader.prototype;
5363
5578
  _proto.load = function load(item, resourceManager) {
5364
5579
  var _this = this;
5365
- return new AssetPromise(function(resolve, reject) {
5580
+ return new AssetPromise(function(resolve, reject, setTaskCompleteProgress, setTaskDetailProgress) {
5366
5581
  var url = item.url;
5367
5582
  var requestConfig = _extends({}, item, {
5368
5583
  type: "image"
5369
5584
  });
5370
- _this.request(url, requestConfig).then(function(image) {
5371
- var _params, _params1;
5372
- var params = item.params;
5373
- var texture = new Texture2D(resourceManager.engine, image.width, image.height, (_params = params) == null ? void 0 : _params.format, (_params1 = params) == null ? void 0 : _params1.mipmap);
5585
+ _this.request(url, requestConfig).onProgress(setTaskCompleteProgress, setTaskDetailProgress).then(function(image) {
5586
+ var _item_params;
5587
+ var _ref = (_item_params = item.params) != null ? _item_params : {}, format = _ref.format, mipmap = _ref.mipmap, anisoLevel = _ref.anisoLevel, wrapModeU = _ref.wrapModeU, wrapModeV = _ref.wrapModeV, filterMode = _ref.filterMode;
5588
+ var texture = new Texture2D(resourceManager.engine, image.width, image.height, format, mipmap);
5589
+ texture.anisoLevel = anisoLevel != null ? anisoLevel : texture.anisoLevel;
5590
+ texture.filterMode = filterMode != null ? filterMode : texture.filterMode;
5591
+ texture.wrapModeU = wrapModeU != null ? wrapModeU : texture.wrapModeU;
5592
+ texture.wrapModeV = wrapModeV != null ? wrapModeV : texture.wrapModeV;
5374
5593
  texture.setImageSource(image);
5375
5594
  texture.generateMipmaps();
5376
5595
  if (url.indexOf("data:") !== 0) {
@@ -5518,33 +5737,34 @@ var SceneLoader = /*#__PURE__*/ function(Loader1) {
5518
5737
  var promises = [];
5519
5738
  // parse ambient light
5520
5739
  var ambient = data.scene.ambient;
5521
- var useCustomAmbient = ambient.specularMode === "Custom";
5522
- if (useCustomAmbient && ambient.customAmbientLight) {
5523
- // @ts-ignore
5524
- // prettier-ignore
5525
- var customAmbientPromise = resourceManager.getResourceByRef(ambient.customAmbientLight).then(function(ambientLight) {
5526
- scene.ambientLight = ambientLight;
5527
- scene.ambientLight.diffuseIntensity = ambient.diffuseIntensity;
5528
- scene.ambientLight.specularIntensity = ambient.specularIntensity;
5529
- scene.ambientLight.diffuseMode = ambient.diffuseMode;
5530
- scene.ambientLight.diffuseSolidColor.copyFrom(ambient.diffuseSolidColor);
5531
- });
5532
- promises.push(customAmbientPromise);
5533
- } else if (!useCustomAmbient && ambient.ambientLight) {
5534
- // @ts-ignore
5535
- // prettier-ignore
5536
- var ambientLightPromise = resourceManager.getResourceByRef(ambient.ambientLight).then(function(ambientLight) {
5537
- scene.ambientLight = ambientLight;
5538
- scene.ambientLight.diffuseIntensity = ambient.diffuseIntensity;
5539
- scene.ambientLight.specularIntensity = ambient.specularIntensity;
5540
- scene.ambientLight.diffuseMode = ambient.diffuseMode;
5541
- scene.ambientLight.diffuseSolidColor.copyFrom(ambient.diffuseSolidColor);
5542
- });
5543
- promises.push(ambientLightPromise);
5544
- } else {
5740
+ if (ambient) {
5741
+ var useCustomAmbient = ambient.specularMode === "Custom";
5742
+ var useSH = ambient.diffuseMode === DiffuseMode.SphericalHarmonics;
5545
5743
  scene.ambientLight.diffuseIntensity = ambient.diffuseIntensity;
5546
5744
  scene.ambientLight.specularIntensity = ambient.specularIntensity;
5745
+ scene.ambientLight.diffuseMode = ambient.diffuseMode;
5547
5746
  scene.ambientLight.diffuseSolidColor.copyFrom(ambient.diffuseSolidColor);
5747
+ scene.ambientLight.specularTextureDecodeRGBM = true;
5748
+ if (useCustomAmbient && ambient.customAmbientLight) {
5749
+ promises.push(// @ts-ignore
5750
+ resourceManager.getResourceByRef(ambient.customAmbientLight).then(function(ambientLight) {
5751
+ var _ambientLight;
5752
+ scene.ambientLight.specularTexture = (_ambientLight = ambientLight) == null ? void 0 : _ambientLight.specularTexture;
5753
+ }));
5754
+ }
5755
+ if (ambient.ambientLight && (!useCustomAmbient || useSH)) {
5756
+ promises.push(// @ts-ignore
5757
+ resourceManager.getResourceByRef(ambient.ambientLight).then(function(ambientLight) {
5758
+ if (!useCustomAmbient) {
5759
+ var _ambientLight;
5760
+ scene.ambientLight.specularTexture = (_ambientLight = ambientLight) == null ? void 0 : _ambientLight.specularTexture;
5761
+ }
5762
+ if (useSH) {
5763
+ var _ambientLight1;
5764
+ scene.ambientLight.diffuseSphericalHarmonics = (_ambientLight1 = ambientLight) == null ? void 0 : _ambientLight1.diffuseSphericalHarmonics;
5765
+ }
5766
+ }));
5767
+ }
5548
5768
  }
5549
5769
  var background = data.scene.background;
5550
5770
  scene.background.mode = background.mode;
@@ -5586,6 +5806,9 @@ var SceneLoader = /*#__PURE__*/ function(Loader1) {
5586
5806
  if (shadow.shadowResolution != undefined) scene.shadowResolution = shadow.shadowResolution;
5587
5807
  if (shadow.shadowDistance != undefined) scene.shadowDistance = shadow.shadowDistance;
5588
5808
  if (shadow.shadowCascades != undefined) scene.shadowCascades = shadow.shadowCascades;
5809
+ var _shadow_shadowTwoCascadeSplits;
5810
+ scene.shadowTwoCascadeSplits = (_shadow_shadowTwoCascadeSplits = shadow.shadowTwoCascadeSplits) != null ? _shadow_shadowTwoCascadeSplits : scene.shadowTwoCascadeSplits;
5811
+ shadow.shadowFourCascadeSplits && scene.shadowFourCascadeSplits.copyFrom(shadow.shadowFourCascadeSplits);
5589
5812
  }
5590
5813
  return Promise.all(promises).then(function() {
5591
5814
  resolve(scene);
@@ -5601,13 +5824,13 @@ SceneLoader = __decorate([
5601
5824
  "scene"
5602
5825
  ], true)
5603
5826
  ], SceneLoader);
5604
- ReflectionParser.registerCustomParseComponent("TextRenderer", /*#__PURE__*/ _async_to_generator(function(instance, item, engine) {
5827
+ ReflectionParser.registerCustomParseComponent("TextRenderer", /*#__PURE__*/ _async_to_generator(function(instance, item) {
5605
5828
  var props;
5606
5829
  return __generator(this, function(_state) {
5607
5830
  props = item.props;
5608
5831
  if (!props.font) {
5609
5832
  // @ts-ignore
5610
- instance.font = Font.createFromOS(engine, props.fontFamily || "Arial");
5833
+ instance.font = Font.createFromOS(instance.engine, props.fontFamily || "Arial");
5611
5834
  }
5612
5835
  return [
5613
5836
  2,
@@ -5663,7 +5886,7 @@ var KHR_draco_mesh_compression = (_KHR_draco_mesh_compression = /*#__PURE__*/ fu
5663
5886
  throw "BlendShape animation is not supported when using draco.";
5664
5887
  }, function() {
5665
5888
  return decodedGeometry.index.array;
5666
- }, context.keepMeshData);
5889
+ }, context.params.keepMeshData);
5667
5890
  });
5668
5891
  });
5669
5892
  };
@@ -5954,7 +6177,7 @@ var KHR_materials_variants = /*#__PURE__*/ function(GLTFExtensionParser1) {
5954
6177
  var _glTFResource;
5955
6178
  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;
5956
6179
  var mappings = schema.mappings;
5957
- (_glTFResource = glTFResource).extensionsData || (_glTFResource.extensionsData = {});
6180
+ (_glTFResource = glTFResource)._extensionsData || (_glTFResource._extensionsData = {});
5958
6181
  var extensionData = [];
5959
6182
  glTFResource.extensionsData.variants = extensionData;
5960
6183
  for(var i = 0; i < mappings.length; i++)_loop(i);
@@ -5984,7 +6207,7 @@ var KHR_texture_basisu = /*#__PURE__*/ function(GLTFExtensionParser1) {
5984
6207
  var _proto = KHR_texture_basisu.prototype;
5985
6208
  _proto.createAndParse = function createAndParse(context, schema, textureInfo) {
5986
6209
  return _async_to_generator(function() {
5987
- var glTF, glTFResource, engine, url, sampler, textureName, source, _glTF_images_source, uri, bufferViewIndex, mimeType, imageName, samplerInfo, index, bufferView;
6210
+ var glTF, glTFResource, engine, url, sampler, textureName, source, _glTF_images_source, uri, bufferViewIndex, mimeType, imageName, samplerInfo, index, promise, bufferView;
5988
6211
  return __generator(this, function(_state) {
5989
6212
  glTF = context.glTF, glTFResource = context.glTFResource;
5990
6213
  engine = glTFResource.engine, url = glTFResource.url;
@@ -5994,20 +6217,22 @@ var KHR_texture_basisu = /*#__PURE__*/ function(GLTFExtensionParser1) {
5994
6217
  samplerInfo = sampler !== undefined && GLTFUtils.getSamplerInfo(glTF.samplers[sampler]);
5995
6218
  if (uri) {
5996
6219
  index = uri.lastIndexOf(".");
6220
+ promise = engine.resourceManager.load({
6221
+ url: Utils.resolveAbsoluteUrl(url, uri),
6222
+ type: AssetType.KTX2
6223
+ }).onProgress(undefined, context._onTaskDetail).then(function(texture) {
6224
+ if (!texture.name) {
6225
+ texture.name = textureName || imageName || "texture_" + index;
6226
+ }
6227
+ if (sampler !== undefined) {
6228
+ GLTFUtils.parseSampler(texture, samplerInfo);
6229
+ }
6230
+ return texture;
6231
+ });
6232
+ context._addTaskCompletePromise(promise);
5997
6233
  return [
5998
6234
  2,
5999
- engine.resourceManager.load({
6000
- url: Utils.resolveAbsoluteUrl(url, uri),
6001
- type: AssetType.KTX2
6002
- }).then(function(texture) {
6003
- if (!texture.name) {
6004
- texture.name = textureName || imageName || "texture_" + index;
6005
- }
6006
- if (sampler !== undefined) {
6007
- GLTFUtils.parseSampler(texture, samplerInfo);
6008
- }
6009
- return texture;
6010
- })
6235
+ promise
6011
6236
  ];
6012
6237
  } else {
6013
6238
  bufferView = glTF.bufferViews[bufferViewIndex];
@@ -6077,7 +6302,9 @@ var GALACEAN_materials_remap = /*#__PURE__*/ function(GLTFExtensionParser1) {
6077
6302
  _proto.createAndParse = function createAndParse(context, schema) {
6078
6303
  var engine = context.glTFResource.engine;
6079
6304
  // @ts-ignore
6080
- return engine.resourceManager.getResourceByRef(schema);
6305
+ var promise = engine.resourceManager.getResourceByRef(schema);
6306
+ context._addTaskCompletePromise(promise);
6307
+ return promise;
6081
6308
  };
6082
6309
  return GALACEAN_materials_remap;
6083
6310
  }(GLTFExtensionParser);
@@ -6108,5 +6335,28 @@ GALACEAN_animation_event = __decorate([
6108
6335
  registerGLTFExtension("GALACEAN_animation_event", GLTFExtensionMode.AdditiveParse)
6109
6336
  ], GALACEAN_animation_event);
6110
6337
 
6111
- export { AnimationClipDecoder, ComponentMap, EditorTextureLoader, GLTFAnimationParser, GLTFBufferParser, GLTFEntityParser, GLTFExtensionMode, GLTFExtensionParser, GLTFMaterialParser, GLTFMeshParser, GLTFParser, GLTFParserContext, GLTFParserType, GLTFResource, GLTFSceneParser, GLTFSchemaParser, GLTFSkinParser, GLTFTextureParser, GLTFUtils, GLTFValidator, InterpolableValueType, KTX2Loader, KTX2TargetFormat, MeshDecoder, MeshLoader$1 as MeshLoader, PrefabParser, ReflectionParser, SceneParser, SpecularMode, Texture2DDecoder, decode, parseSingleKTX, registerGLTFExtension, registerGLTFParser };
6338
+ var KHR_materials_anisotropy = /*#__PURE__*/ function(GLTFExtensionParser1) {
6339
+ _inherits(KHR_materials_anisotropy, GLTFExtensionParser1);
6340
+ function KHR_materials_anisotropy() {
6341
+ return GLTFExtensionParser1.apply(this, arguments);
6342
+ }
6343
+ var _proto = KHR_materials_anisotropy.prototype;
6344
+ _proto.additiveParse = function additiveParse(context, material, schema) {
6345
+ var _schema_anisotropyStrength = schema.anisotropyStrength, anisotropyStrength = _schema_anisotropyStrength === void 0 ? 0 : _schema_anisotropyStrength, _schema_anisotropyRotation = schema.anisotropyRotation, anisotropyRotation = _schema_anisotropyRotation === void 0 ? 0 : _schema_anisotropyRotation, anisotropyTexture = schema.anisotropyTexture;
6346
+ material.anisotropy = anisotropyStrength;
6347
+ material.anisotropyRotation = anisotropyRotation;
6348
+ if (anisotropyTexture) {
6349
+ GLTFMaterialParser._checkOtherTextureTransform(anisotropyTexture, "Anisotropy texture");
6350
+ context.get(GLTFParserType.Texture, anisotropyTexture.index).then(function(texture) {
6351
+ material.anisotropyTexture = texture;
6352
+ });
6353
+ }
6354
+ };
6355
+ return KHR_materials_anisotropy;
6356
+ }(GLTFExtensionParser);
6357
+ KHR_materials_anisotropy = __decorate([
6358
+ registerGLTFExtension("KHR_materials_anisotropy", GLTFExtensionMode.AdditiveParse)
6359
+ ], KHR_materials_anisotropy);
6360
+
6361
+ export { AnimationClipDecoder, ComponentMap, EditorTextureLoader, GLTFAnimationParser, GLTFBufferParser, GLTFEntityParser, GLTFExtensionMode, GLTFExtensionParser, GLTFMaterialParser, GLTFMeshParser, GLTFParser, GLTFParserContext, GLTFParserType, GLTFResource, GLTFSceneParser, GLTFSchemaParser, GLTFSkinParser, GLTFTextureParser, GLTFUtils, GLTFValidator, InterpolableValueType, KTX2Loader, KTX2TargetFormat, KTX2Transcoder, MeshDecoder, MeshLoader$1 as MeshLoader, PrefabParser, ReflectionParser, SceneParser, SpecularMode, Texture2DDecoder, decode, parseSingleKTX, registerGLTFExtension, registerGLTFParser };
6112
6362
  //# sourceMappingURL=module.js.map