@galacean/engine-loader 2.0.0-alpha.33 → 2.0.0-alpha.35

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,5 +1,5 @@
1
1
  import { Utils, AssetPromise, AnimationClip, AnimationEvent, Loader, AnimationStringCurve, Keyframe, AnimationBoolCurve, AnimationRefCurve, AnimationQuaternionCurve, AnimationColorCurve, AnimationVector4Curve, AnimationVector3Curve, AnimationVector2Curve, AnimationFloatArrayCurve, AnimationArrayCurve, AnimationFloatCurve, ModelMesh, BlendShape, TextureFormat, Texture2D, TextureCube, TextureCubeFace, ReferResource, Entity, resourceLoader, AssetType, AnimatorController, AnimatorControllerLayer, AnimatorStateTransition, BufferAsset, GLCapabilityType, Logger, ContentRestorer, AmbientLight, DiffuseMode, TextureFilterMode, Font, SystemInfo, Animator, IndexFormat, VertexElementFormat, request, InterpolationType, SkinnedMeshRenderer, Transform, PBRMaterial, TextureCoordinate, RenderFace, VertexElement, Buffer, BufferBindFlag, BufferUsage, Camera, MeshRenderer, Skin, TextureWrapMode as TextureWrapMode$1, TextureUtils, AnimatorStateMachine, JSONAsset, Shader, Material, PrimitiveMesh, SpriteAtlas, Sprite, TextAsset, AudioClip, AudioManager, PhysicsMaterial, RenderTarget, Scene, BackgroundMode, DirectLight, PointLight, SpotLight, UnlitMaterial } from '@galacean/engine-core';
2
- import { Quaternion, Vector4, Color, Vector3, Vector2, MathUtil, SphericalHarmonics3, BoundingBox, Matrix, Rect } from '@galacean/engine-math';
2
+ import { Quaternion, Vector4, Color, Vector3, Vector2, MathUtil, SphericalHarmonics3, Matrix, BoundingBox, Rect } from '@galacean/engine-math';
3
3
  import { GLCompressedTextureInternalFormat } from '@galacean/engine-rhi-webgl';
4
4
 
5
5
  function _extends() {
@@ -3314,13 +3314,13 @@ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
3314
3314
  _this.needAnimatorController = !!(json.skins || json.animations);
3315
3315
  return AssetPromise.all([
3316
3316
  _this.get(1),
3317
+ _this.get(2),
3317
3318
  _this.get(5),
3318
3319
  _this.get(6),
3319
3320
  _this.get(7),
3320
3321
  _this.get(9),
3321
3322
  _this.get(10),
3322
- _this.get(11),
3323
- _this.get(2)
3323
+ _this.get(11)
3324
3324
  ]).then(function() {
3325
3325
  var glTFResource = _this.glTFResource;
3326
3326
  var animatorController = glTFResource.animatorController;
@@ -4970,35 +4970,15 @@ var GLTFSceneParser = /*#__PURE__*/ function(GLTFParser1) {
4970
4970
  if (rootBoneIndex !== -1) {
4971
4971
  BoundingBox.transform(mesh.bounds, inverseBindMatrices[rootBoneIndex], skinnedMeshRenderer.localBounds);
4972
4972
  } else {
4973
- // Root bone is not in joints list, we can only compute approximate inverse bind matrix
4974
- // Average all root bone's children inverse bind matrix
4975
- var approximateBindMatrix = new Matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
4976
- var subRootBoneCount = this._computeApproximateBindMatrix(bones, inverseBindMatrices, rootBone, approximateBindMatrix);
4977
- if (subRootBoneCount !== 0) {
4978
- Matrix.multiplyScalar(approximateBindMatrix, 1.0 / subRootBoneCount, approximateBindMatrix);
4979
- BoundingBox.transform(mesh.bounds, approximateBindMatrix, skinnedMeshRenderer.localBounds);
4980
- } else {
4981
- skinnedMeshRenderer.localBounds.copyFrom(mesh.bounds);
4982
- }
4983
- }
4984
- };
4985
- _proto._computeApproximateBindMatrix = function _computeApproximateBindMatrix(jointEntities, inverseBindMatrices, rootEntity, approximateBindMatrix) {
4986
- var subRootBoneCount = 0;
4987
- var children = rootEntity.children;
4988
- for(var i = 0, n = children.length; i < n; i++){
4989
- var rootChild = children[i];
4990
- var index = jointEntities.indexOf(rootChild);
4991
- if (index !== -1) {
4992
- Matrix.add(approximateBindMatrix, inverseBindMatrices[index], approximateBindMatrix);
4993
- subRootBoneCount++;
4994
- } else {
4995
- subRootBoneCount += this._computeApproximateBindMatrix(jointEntities, inverseBindMatrices, rootChild, approximateBindMatrix);
4996
- }
4973
+ // rootBone can be outside skin.joints, so it has no inverse bind matrix
4974
+ var inverseRootBoneWorld = GLTFSceneParser._tempMatrix;
4975
+ Matrix.invert(rootBone.transform.worldMatrix, inverseRootBoneWorld);
4976
+ BoundingBox.transform(mesh.bounds, inverseRootBoneWorld, skinnedMeshRenderer.localBounds);
4997
4977
  }
4998
- return subRootBoneCount;
4999
4978
  };
5000
4979
  return GLTFSceneParser;
5001
4980
  }(GLTFParser);
4981
+ GLTFSceneParser._tempMatrix = new Matrix();
5002
4982
  GLTFSceneParser = __decorate([
5003
4983
  registerGLTFParser(GLTFParserType.Scene)
5004
4984
  ], GLTFSceneParser);
@@ -5033,23 +5013,29 @@ var GLTFSkinParser = /*#__PURE__*/ function(GLTFParser) {
5033
5013
  skin.joints[i] = bone.name;
5034
5014
  }
5035
5015
  skin.bones = bones;
5036
- // Get skeleton
5016
+ // Get skeleton — when `skin.skeleton` is absent, resolve via joints' LCA
5017
+ // LCA falls back to the GLTF_ROOT wrapper only when joints span multiple top-level scene nodes
5037
5018
  if (skeleton !== undefined) {
5038
5019
  var rootBone = entities[skeleton];
5020
+ if (!rootBone) {
5021
+ throw "Skin skeleton index " + skeleton + " is out of range.";
5022
+ }
5039
5023
  skin.rootBone = rootBone;
5040
5024
  } else {
5041
5025
  var rootBone1 = _this._findSkeletonRootBone(joints, entities);
5042
- if (rootBone1) {
5043
- skin.rootBone = rootBone1;
5044
- } else {
5026
+ if (!rootBone1) {
5045
5027
  throw "Failed to find skeleton root bone.";
5046
5028
  }
5029
+ skin.rootBone = rootBone1;
5047
5030
  }
5048
5031
  return skin;
5049
5032
  });
5050
5033
  return AssetPromise.resolve(skinPromise);
5051
5034
  };
5052
- _proto._findSkeletonRootBone = function _findSkeletonRootBone(joints, entities) {
5035
+ /**
5036
+ * Resolve the skeleton rootBone as the lowest common ancestor of the joints' parent chains.
5037
+ * Returns null when joints share no common ancestor.
5038
+ */ _proto._findSkeletonRootBone = function _findSkeletonRootBone(joints, entities) {
5053
5039
  var paths = {};
5054
5040
  for(var _iterator = _create_for_of_iterator_helper_loose(joints), _step; !(_step = _iterator()).done;){
5055
5041
  var index = _step.value;
@@ -6321,7 +6307,10 @@ AudioLoader = __decorate([
6321
6307
  resourceLoader(AssetType.Audio, [
6322
6308
  "mp3",
6323
6309
  "ogg",
6324
- "wav"
6310
+ "wav",
6311
+ "m4a",
6312
+ "aac",
6313
+ "flac"
6325
6314
  ])
6326
6315
  ], AudioLoader);
6327
6316
 
@@ -6332,7 +6321,6 @@ var ShaderLoader = /*#__PURE__*/ function(Loader) {
6332
6321
  }
6333
6322
  var _proto = ShaderLoader.prototype;
6334
6323
  _proto.load = function load(item, resourceManager) {
6335
- var _this = this;
6336
6324
  var url = item.url;
6337
6325
  if (url.endsWith(".shaderc")) {
6338
6326
  // @ts-ignore
@@ -6347,20 +6335,11 @@ var ShaderLoader = /*#__PURE__*/ function(Loader) {
6347
6335
  return resourceManager._request(url, _extends({}, item, {
6348
6336
  type: "text"
6349
6337
  })).then(function(code) {
6350
- var builtinShader = _this._getBuiltinShader(code);
6351
- if (builtinShader) {
6352
- return Shader.find(builtinShader);
6353
- }
6354
6338
  return Shader.create(code, undefined, url);
6355
6339
  });
6356
6340
  };
6357
- _proto._getBuiltinShader = function _getBuiltinShader(code) {
6358
- var match = code.match(ShaderLoader._builtinRegex);
6359
- if (match && match[1]) return match[1];
6360
- };
6361
6341
  return ShaderLoader;
6362
6342
  }(Loader);
6363
- ShaderLoader._builtinRegex = /^\s*\/\/\s*@builtin\s+(\w+)/;
6364
6343
  ShaderLoader = __decorate([
6365
6344
  resourceLoader(AssetType.Shader, [
6366
6345
  "shader",