@galacean/engine-loader 0.0.0-experimental-2.0-game.12 → 0.0.0-experimental-2.0-game.14

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 CHANGED
@@ -4907,32 +4907,10 @@ exports.GLTFSceneParser = /*#__PURE__*/ function(GLTFParser1) {
4907
4907
  if (rootBoneIndex !== -1) {
4908
4908
  engineMath.BoundingBox.transform(mesh.bounds, inverseBindMatrices[rootBoneIndex], skinnedMeshRenderer.localBounds);
4909
4909
  } else {
4910
- // Root bone is not in joints list, we can only compute approximate inverse bind matrix
4911
- // Average all root bone's children inverse bind matrix
4912
- var approximateBindMatrix = new engineMath.Matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
4913
- var subRootBoneCount = this._computeApproximateBindMatrix(bones, inverseBindMatrices, rootBone, approximateBindMatrix);
4914
- if (subRootBoneCount !== 0) {
4915
- engineMath.Matrix.multiplyScalar(approximateBindMatrix, 1.0 / subRootBoneCount, approximateBindMatrix);
4916
- engineMath.BoundingBox.transform(mesh.bounds, approximateBindMatrix, skinnedMeshRenderer.localBounds);
4917
- } else {
4918
- skinnedMeshRenderer.localBounds.copyFrom(mesh.bounds);
4919
- }
4920
- }
4921
- };
4922
- _proto._computeApproximateBindMatrix = function _computeApproximateBindMatrix(jointEntities, inverseBindMatrices, rootEntity, approximateBindMatrix) {
4923
- var subRootBoneCount = 0;
4924
- var children = rootEntity.children;
4925
- for(var i = 0, n = children.length; i < n; i++){
4926
- var rootChild = children[i];
4927
- var index = jointEntities.indexOf(rootChild);
4928
- if (index !== -1) {
4929
- engineMath.Matrix.add(approximateBindMatrix, inverseBindMatrices[index], approximateBindMatrix);
4930
- subRootBoneCount++;
4931
- } else {
4932
- subRootBoneCount += this._computeApproximateBindMatrix(jointEntities, inverseBindMatrices, rootChild, approximateBindMatrix);
4933
- }
4910
+ var inverseRootBoneWorld = new engineMath.Matrix();
4911
+ engineMath.Matrix.invert(rootBone.transform.worldMatrix, inverseRootBoneWorld);
4912
+ engineMath.BoundingBox.transform(mesh.bounds, inverseRootBoneWorld, skinnedMeshRenderer.localBounds);
4934
4913
  }
4935
- return subRootBoneCount;
4936
4914
  };
4937
4915
  return GLTFSceneParser;
4938
4916
  }(GLTFParser);
@@ -4975,8 +4953,7 @@ exports.GLTFSkinParser = /*#__PURE__*/ function(GLTFParser) {
4975
4953
  var rootBone = entities[skeleton];
4976
4954
  skin.rootBone = rootBone;
4977
4955
  } else {
4978
- var _this__findSceneRootBone;
4979
- var rootBone1 = (_this__findSceneRootBone = _this._findSceneRootBone(context, joints, entities)) != null ? _this__findSceneRootBone : _this._findSkeletonRootBone(joints, entities);
4956
+ var rootBone1 = _this._findSkinRootBoneByLCA(index, joints, entities, glTF.nodes);
4980
4957
  if (rootBone1) {
4981
4958
  skin.rootBone = rootBone1;
4982
4959
  } else {
@@ -4987,46 +4964,20 @@ exports.GLTFSkinParser = /*#__PURE__*/ function(GLTFParser) {
4987
4964
  });
4988
4965
  return engineCore.AssetPromise.resolve(skinPromise);
4989
4966
  };
4990
- _proto._findSceneRootBone = function _findSceneRootBone(context, joints, entities) {
4991
- var glTF = context.glTF, glTFResource = context.glTFResource;
4992
- var scenes = glTF.scenes;
4993
- var sceneRoots = glTFResource._sceneRoots;
4994
- if (!(scenes == null ? void 0 : scenes.length) || !(sceneRoots == null ? void 0 : sceneRoots.length)) {
4995
- return null;
4996
- }
4997
- for(var i = 0, n = scenes.length; i < n; i++){
4998
- var _scenes_i_nodes;
4999
- var sceneNodes = (_scenes_i_nodes = scenes[i].nodes) != null ? _scenes_i_nodes : [];
5000
- if (sceneNodes.length <= 1) {
5001
- continue;
5002
- }
5003
- var sceneRoot = sceneRoots[i];
5004
- if (!sceneRoot) {
5005
- continue;
5006
- }
5007
- var sceneRootChildren = new Set(sceneNodes.map(function(nodeIndex) {
5008
- return entities[nodeIndex];
5009
- }));
5010
- var allJointsUnderSceneRoot = true;
5011
- for(var j = 0, m = joints.length; j < m; j++){
5012
- var entity = entities[joints[j]];
5013
- while(entity == null ? void 0 : entity.parent){
5014
- entity = entity.parent;
5015
- }
5016
- if (!sceneRootChildren.has(entity)) {
5017
- allJointsUnderSceneRoot = false;
5018
- break;
5019
- }
5020
- }
5021
- if (allJointsUnderSceneRoot) {
5022
- return sceneRoot;
4967
+ _proto._findSkinRootBoneByLCA = function _findSkinRootBoneByLCA(skinIndex, joints, entities, nodes) {
4968
+ if (nodes === void 0) nodes = [];
4969
+ var nodeIndices = joints.slice();
4970
+ for(var i = 0, n = nodes.length; i < n; i++){
4971
+ var _nodes_i;
4972
+ if (((_nodes_i = nodes[i]) == null ? void 0 : _nodes_i.skin) === skinIndex) {
4973
+ nodeIndices.push(i);
5023
4974
  }
5024
4975
  }
5025
- return null;
4976
+ return this._findRootBoneByLCA(nodeIndices, entities);
5026
4977
  };
5027
- _proto._findSkeletonRootBone = function _findSkeletonRootBone(joints, entities) {
5028
- var paths = {};
5029
- for(var _iterator = _create_for_of_iterator_helper_loose(joints), _step; !(_step = _iterator()).done;){
4978
+ _proto._findRootBoneByLCA = function _findRootBoneByLCA(nodeIndices, entities) {
4979
+ var paths = [];
4980
+ for(var _iterator = _create_for_of_iterator_helper_loose(nodeIndices), _step; !(_step = _iterator()).done;){
5030
4981
  var index = _step.value;
5031
4982
  var path = new Array();
5032
4983
  var entity = entities[index];
@@ -5034,17 +4985,22 @@ exports.GLTFSkinParser = /*#__PURE__*/ function(GLTFParser) {
5034
4985
  path.unshift(entity);
5035
4986
  entity = entity.parent;
5036
4987
  }
5037
- paths[index] = path;
4988
+ if (path.length) {
4989
+ paths.push(path);
4990
+ }
4991
+ }
4992
+ if (!paths.length) {
4993
+ return null;
5038
4994
  }
5039
4995
  var rootNode = null;
5040
4996
  for(var i = 0;; i++){
5041
- var path1 = paths[joints[0]];
4997
+ var path1 = paths[0];
5042
4998
  if (i >= path1.length) {
5043
4999
  return rootNode;
5044
5000
  }
5045
5001
  var entity1 = path1[i];
5046
- for(var j = 1, m = joints.length; j < m; j++){
5047
- path1 = paths[joints[j]];
5002
+ for(var j = 1, m = paths.length; j < m; j++){
5003
+ path1 = paths[j];
5048
5004
  if (i >= path1.length || entity1 !== path1[i]) {
5049
5005
  return rootNode;
5050
5006
  }
@@ -6615,7 +6571,10 @@ AudioLoader = __decorate([
6615
6571
  "mp3",
6616
6572
  "ogg",
6617
6573
  "wav",
6618
- "audio"
6574
+ "audio",
6575
+ "m4a",
6576
+ "aac",
6577
+ "flac"
6619
6578
  ])
6620
6579
  ], AudioLoader);
6621
6580
 
@@ -6886,6 +6845,14 @@ var SceneLoader = /*#__PURE__*/ function(Loader) {
6886
6845
  if (fog.fogDensity != undefined) scene.fogDensity = fog.fogDensity;
6887
6846
  if (fog.fogColor != undefined) scene.fogColor.copyFrom(fog.fogColor);
6888
6847
  }
6848
+ // parse physics
6849
+ var physics = data.scene.physics;
6850
+ // PhysicsScene has a native backing only when the engine was created with a physics backend.
6851
+ // Keep scene files loadable for render-only engines by ignoring serialized physics settings there.
6852
+ if (physics && engine._physicsInitialized) {
6853
+ if (physics.gravity != undefined) scene.physics.gravity.copyFrom(physics.gravity);
6854
+ if (physics.fixedTimeStep != undefined) scene.physics.fixedTimeStep = physics.fixedTimeStep;
6855
+ }
6889
6856
  // Post Process
6890
6857
  var postProcessData = data.scene.postProcess;
6891
6858
  if (postProcessData) {