@galacean/engine 0.0.0-experimental-2.0-game.11 → 0.0.0-experimental-2.0-game.13

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/browser.js CHANGED
@@ -10787,8 +10787,13 @@
10787
10787
  rotation._onValueChanged = target._onRotationChanged;
10788
10788
  // @ts-ignore
10789
10789
  scale._onValueChanged = target._onScaleChanged;
10790
- // When cloning, other components may obtain properties such as `rotationQuaternion` in the constructor, local related dirty flags need to be corrected
10790
+ // When cloning, other components may obtain properties such as `rotationQuaternion` in the constructor, local related dirty flags need to be corrected.
10791
+ // Earlier in this Entity's construction other components (e.g. DynamicCollider) may have queried
10792
+ // `worldPosition`, which clears the WorldPosition / WorldMatrix dirty flags as a side effect of caching
10793
+ // the computed value. After this _cloneTo writes new local values, those world-derived caches are stale,
10794
+ // so re-dirty them and notify listeners (Collider._updateFlag etc.) so subsequent reads recompute correctly.
10791
10795
  target._setDirtyFlagTrue(2 | 64);
10796
+ target._worldAssociatedChange(444);
10792
10797
  };
10793
10798
  _proto._onLocalMatrixChanging = function _onLocalMatrixChanging() {
10794
10799
  this._setDirtyFlagFalse(64);
@@ -12739,7 +12744,13 @@
12739
12744
  };
12740
12745
  ShaderFactory._has300OutInFragReg = /\bout\s+(?:\w+\s+)?vec4\s+\w+\s*;/;
12741
12746
  ShaderFactory._precisionStr = "\n#ifdef GL_FRAGMENT_PRECISION_HIGH\n precision highp float;\n precision highp int;\n#else\n precision mediump float;\n precision mediump int;\n#endif\n";
12742
- ShaderFactory._derivedDefines = "#define renderer_MVMat (camera_ViewMat * renderer_ModelMat)\n#define renderer_MVPMat (camera_VPMat * renderer_ModelMat)\n#define renderer_NormalMat mat4(transpose(inverse(mat3(renderer_ModelMat))))";
12747
+ // Derived built-ins re-exposed on top of `renderer_ModelMat`.
12748
+ // `renderer_NormalMat` uses the cofactor (cross-product) form, which algebraically equals
12749
+ // `det(M) · transpose(inverse(M))`. After `normalize()` it's directionally identical to the
12750
+ // classic `transpose(inverse(M))`, but stays NaN-free when `M` is singular (e.g. any scale
12751
+ // axis is 0 — common in animations that pop / hide via scale). `sign(det)` (`s` below)
12752
+ // keeps mirrored matrices facing the right way
12753
+ ShaderFactory._derivedDefines = "mat3 _normalMatFromModel(mat3 m) {\n vec3 c0 = cross(m[1], m[2]);\n vec3 c1 = cross(m[2], m[0]);\n vec3 c2 = cross(m[0], m[1]);\n float s = (dot(m[0], c0) < 0.0) ? -1.0 : 1.0;\n return mat3(c0 * s, c1 * s, c2 * s);\n}\n#define renderer_MVMat (camera_ViewMat * renderer_ModelMat)\n#define renderer_MVPMat (camera_VPMat * renderer_ModelMat)\n#define renderer_NormalMat mat4(_normalMatFromModel(mat3(renderer_ModelMat)))";
12743
12754
  // Built-in renderer uniforms. value=true means derived (remove but not added to UBO)
12744
12755
  ShaderFactory._builtinRendererUniforms = {
12745
12756
  renderer_ModelMat: false,
@@ -23975,7 +23986,7 @@
23975
23986
  /** Scene. */ AssetType["Scene"] = "Scene";
23976
23987
  /** Font. */ AssetType["Font"] = "Font";
23977
23988
  /** Source Font, include ttf, otf and woff. */ AssetType["SourceFont"] = "SourceFont";
23978
- /** AudioClip, include ogg, wav and mp3. */ AssetType["Audio"] = "Audio";
23989
+ /** AudioClip, include ogg, wav, mp3, m4a, aac and flac. */ AssetType["Audio"] = "Audio";
23979
23990
  /** Project asset. */ AssetType["Project"] = "project";
23980
23991
  /** PhysicsMaterial. */ AssetType["PhysicsMaterial"] = "PhysicsMaterial";
23981
23992
  /** RenderTarget. */ AssetType["RenderTarget"] = "RenderTarget";
@@ -25433,17 +25444,23 @@
25433
25444
  /**
25434
25445
  * @internal
25435
25446
  */ _proto._onUpdate = function _onUpdate() {
25447
+ var shapes = this._shapes;
25436
25448
  if (this._updateFlag.flag) {
25437
25449
  var transform = this.entity.transform;
25438
- this._nativeCollider.setWorldTransform(transform.worldPosition, transform.worldRotationQuaternion);
25450
+ this._syncEntityTransformToNative(transform.worldPosition, transform.worldRotationQuaternion);
25439
25451
  var worldScale = transform.lossyWorldScale;
25440
- var shapes = this._shapes;
25441
25452
  for(var i = 0, n = shapes.length; i < n; i++){
25442
25453
  var _shapes_i__nativeShape;
25443
25454
  (_shapes_i__nativeShape = shapes[i]._nativeShape) == null ? void 0 : _shapes_i__nativeShape.setWorldScale(worldScale);
25444
25455
  }
25445
25456
  this._updateFlag.flag = false;
25446
25457
  }
25458
+ // Drive per-shape physics update (e.g. MeshColliderShape retries pending
25459
+ // native shape creation when mesh data becomes accessible asynchronously).
25460
+ // No-op for shape types that don't override `_onPhysicsUpdate`.
25461
+ for(var i1 = 0, n1 = shapes.length; i1 < n1; i1++){
25462
+ shapes[i1]._onPhysicsUpdate();
25463
+ }
25447
25464
  };
25448
25465
  /**
25449
25466
  * @internal
@@ -25475,6 +25492,28 @@
25475
25492
  this._addNativeShape(this.shapes[i]);
25476
25493
  }
25477
25494
  this._setCollisionLayer();
25495
+ // Teleport native actor to entity's current world pose.
25496
+ // The native actor was created in constructor() with the entity's then-current
25497
+ // worldPosition/Rotation. On clone, the entity's transform fields are deep-cloned
25498
+ // AFTER the Component (and its native actor) are constructed, so the native actor's
25499
+ // pose lags behind the cloned entity transform until this sync.
25500
+ var transform = this.entity.transform;
25501
+ this._teleportToEntityTransform(transform.worldPosition, transform.worldRotationQuaternion);
25502
+ };
25503
+ /**
25504
+ * Teleport native actor to a world pose (instant, no implied velocity).
25505
+ * Used during initialization paths (clone) where the native actor must be re-aligned
25506
+ * with the entity transform after construction-time pose was based on stale defaults.
25507
+ */ _proto._teleportToEntityTransform = function _teleportToEntityTransform(worldPosition, worldRotation) {
25508
+ this._nativeCollider.setWorldTransform(worldPosition, worldRotation);
25509
+ };
25510
+ /**
25511
+ * Sync entity world transform to native actor for per-frame updates.
25512
+ * Default semantics: teleport (setGlobalPose). Subclasses override to express
25513
+ * physics-aware movement (e.g. DynamicCollider routes kinematic actors through
25514
+ * setKinematicTarget to generate contact events on swept motion).
25515
+ */ _proto._syncEntityTransformToNative = function _syncEntityTransformToNative(worldPosition, worldRotation) {
25516
+ this._nativeCollider.setWorldTransform(worldPosition, worldRotation);
25478
25517
  };
25479
25518
  /**
25480
25519
  * @internal
@@ -25632,6 +25671,9 @@
25632
25671
  this._nativeCollider.setUpDirection(this._upDirection);
25633
25672
  this._nativeCollider.setSlopeLimit(this._slopeLimit);
25634
25673
  };
25674
+ _proto._teleportToEntityTransform = function _teleportToEntityTransform(worldPosition, _worldRotation) {
25675
+ this._nativeCollider.setWorldPosition(worldPosition);
25676
+ };
25635
25677
  _proto._syncWorldPositionFromPhysicalSpace = function _syncWorldPositionFromPhysicalSpace() {
25636
25678
  this._nativeCollider.getWorldPosition(this.entity.transform.worldPosition);
25637
25679
  };
@@ -25731,7 +25773,7 @@
25731
25773
  this._staticFriction = 0.6;
25732
25774
  this._bounceCombine = PhysicsMaterialCombineMode.Average;
25733
25775
  this._frictionCombine = PhysicsMaterialCombineMode.Average;
25734
- this._nativeMaterial = Engine._nativePhysics.createPhysicsMaterial(this._staticFriction, this._dynamicFriction, this._bounciness, this._bounceCombine, this._frictionCombine);
25776
+ this._nativeMaterial = Engine._nativePhysics.createPhysicsMaterial(this._staticFriction, this._dynamicFriction, this._bounciness, this._frictionCombine, this._bounceCombine);
25735
25777
  }
25736
25778
  var _proto = PhysicsMaterial.prototype;
25737
25779
  /**
@@ -25740,6 +25782,21 @@
25740
25782
  !this._destroyed && this._nativeMaterial.destroy();
25741
25783
  this._destroyed = true;
25742
25784
  };
25785
+ /**
25786
+ * @internal
25787
+ */ _proto._cloneTo = function _cloneTo(target) {
25788
+ target._syncNative();
25789
+ };
25790
+ /**
25791
+ * @internal
25792
+ */ _proto._syncNative = function _syncNative() {
25793
+ var nativeMaterial = this._nativeMaterial;
25794
+ nativeMaterial.setStaticFriction(this._staticFriction);
25795
+ nativeMaterial.setDynamicFriction(this._dynamicFriction);
25796
+ nativeMaterial.setBounciness(this._bounciness);
25797
+ nativeMaterial.setFrictionCombine(this._frictionCombine);
25798
+ nativeMaterial.setBounceCombine(this._bounceCombine);
25799
+ };
25743
25800
  _create_class$2(PhysicsMaterial, [
25744
25801
  {
25745
25802
  key: "bounciness",
@@ -25814,6 +25871,9 @@
25814
25871
  ]);
25815
25872
  return PhysicsMaterial;
25816
25873
  }();
25874
+ __decorate$1([
25875
+ ignoreClone
25876
+ ], PhysicsMaterial.prototype, "_nativeMaterial", void 0);
25817
25877
  /**
25818
25878
  * Abstract class for collider shapes.
25819
25879
  */ var ColliderShape = /*#__PURE__*/ function() {
@@ -25865,6 +25925,16 @@
25865
25925
  };
25866
25926
  /**
25867
25927
  * @internal
25928
+ *
25929
+ * Called once per physics update tick by `Collider._onUpdate`. Base no-op.
25930
+ *
25931
+ * Subclasses can override for frame-driven maintenance. Currently used by
25932
+ * `MeshColliderShape` to retry native shape creation when mesh data becomes
25933
+ * accessible later or PhysX cooking previously failed due to transient state
25934
+ * (async resource loading, cook pipeline warmup, etc.).
25935
+ */ _proto._onPhysicsUpdate = function _onPhysicsUpdate() {};
25936
+ /**
25937
+ * @internal
25868
25938
  */ _proto._destroy = function _destroy() {
25869
25939
  if (this._nativeShape) {
25870
25940
  this._nativeShape.destroy();
@@ -26013,7 +26083,11 @@
26013
26083
  _inherits$2(MeshColliderShape, ColliderShape);
26014
26084
  function MeshColliderShape() {
26015
26085
  var _this;
26016
- _this = ColliderShape.apply(this, arguments) || this, _this._mesh = null, _this._isConvex = false, _this._positions = null, _this._indices = null, _this._cookingFlags = MeshColliderShapeCookingFlag.Cleaning | MeshColliderShapeCookingFlag.VertexWelding, _this._isShapeAttached = false;
26086
+ _this = ColliderShape.apply(this, arguments) || this, _this._mesh = null, _this._isConvex = false, _this._positions = null, _this._indices = null, _this._cookingFlags = MeshColliderShapeCookingFlag.Cleaning | MeshColliderShapeCookingFlag.VertexWelding, _this._isShapeAttached = false, /**
26087
+ * `true` if a native shape creation was attempted but failed (mesh data not yet
26088
+ * accessible, PhysX cooking transient failure, etc.). The `_onPhysicsUpdate` hook
26089
+ * will keep retrying every frame until creation succeeds.
26090
+ */ _this._pendingNativeShapeCreation = false;
26017
26091
  return _this;
26018
26092
  }
26019
26093
  var _proto = MeshColliderShape.prototype;
@@ -26097,9 +26171,12 @@
26097
26171
  }
26098
26172
  var nativeShape = Engine._nativePhysics.createMeshColliderShape(this._id, this._positions, this._indices, this._isConvex, this._material._nativeMaterial, this._cookingFlags);
26099
26173
  if (!nativeShape) {
26174
+ // Cook failed — `_onPhysicsUpdate` will retry next frame
26175
+ this._pendingNativeShapeCreation = true;
26100
26176
  return;
26101
26177
  }
26102
26178
  this._nativeShape = nativeShape;
26179
+ this._pendingNativeShapeCreation = false;
26103
26180
  // Sync base class properties (position, rotation, contactOffset, isTrigger, material)
26104
26181
  ColliderShape.prototype._syncNative.call(this);
26105
26182
  // If already attached to a collider, add the newly created native shape to it
@@ -26108,6 +26185,36 @@
26108
26185
  this._attachToCollider();
26109
26186
  }
26110
26187
  };
26188
+ /**
26189
+ * @internal
26190
+ * Retry hook: keep attempting `_createNativeShape` until it succeeds.
26191
+ *
26192
+ * Triggered every physics update tick by `Collider._onUpdate`. Handles the case
26193
+ * where `_cookMesh` fails on first attempt due to PhysX cooking pipeline timing
26194
+ * (the mesh data was extracted successfully at `set mesh` time, but the native
26195
+ * cook call returned null). No-op once a valid native shape exists.
26196
+ *
26197
+ * We DO NOT re-call `_extractMeshData` here — once `set mesh` finished, either:
26198
+ * - extraction succeeded → `_positions` is populated and we reuse it
26199
+ * - extraction failed → `_clearMeshData` cleared `_positions`, and `mesh.accessible`
26200
+ * won't recover (GPU upload is one-way), so re-extracting would fail again
26201
+ */ _proto._onPhysicsUpdate = function _onPhysicsUpdate() {
26202
+ if (!this._pendingNativeShapeCreation || !this._mesh || !this._positions) return;
26203
+ this._createNativeShape();
26204
+ };
26205
+ /**
26206
+ * @internal
26207
+ * After CloneManager deep-copies `_positions` / `_indices` / `_mesh` and remaps `_collider`,
26208
+ * the cloned shape still has no native PhysX shape because `_nativeShape` is `@ignoreClone`.
26209
+ * Cook a fresh native shape now using the already-cloned vertex/index buffers; on transient
26210
+ * cook failure `_createNativeShape` sets `_pendingNativeShapeCreation = true` and
26211
+ * `_onPhysicsUpdate` will retry next tick.
26212
+ */ _proto._cloneTo = function _cloneTo(target) {
26213
+ ColliderShape.prototype._cloneTo.call(this, target);
26214
+ if (target._positions) {
26215
+ target._createNativeShape();
26216
+ }
26217
+ };
26111
26218
  _create_class$2(MeshColliderShape, [
26112
26219
  {
26113
26220
  key: "cookingFlags",
@@ -26167,15 +26274,25 @@
26167
26274
  (_this__mesh = this._mesh) == null ? void 0 : _this__mesh._addReferCount(-1);
26168
26275
  value == null ? void 0 : value._addReferCount(1);
26169
26276
  this._mesh = value;
26170
- if (value && this._extractMeshData(value)) {
26171
- if (this._nativeShape) {
26172
- this._updateNativeShapeData();
26277
+ if (value) {
26278
+ if (this._extractMeshData(value)) {
26279
+ if (this._nativeShape) {
26280
+ this._updateNativeShapeData();
26281
+ } else {
26282
+ this._createNativeShape();
26283
+ }
26284
+ // _createNativeShape can fail silently (cookMesh transient failure); mark pending if so
26285
+ this._pendingNativeShapeCreation = !this._nativeShape;
26173
26286
  } else {
26174
- this._createNativeShape();
26287
+ // Mesh not yet accessible — keep pending so `_onPhysicsUpdate` retries later
26288
+ this._destroyNativeShape();
26289
+ this._clearMeshData();
26290
+ this._pendingNativeShapeCreation = true;
26175
26291
  }
26176
26292
  } else {
26177
26293
  this._destroyNativeShape();
26178
26294
  this._clearMeshData();
26295
+ this._pendingNativeShapeCreation = false;
26179
26296
  }
26180
26297
  }
26181
26298
  }
@@ -26219,6 +26336,27 @@
26219
26336
  */ _proto.applyTorque = function applyTorque(torque) {
26220
26337
  this._phasedActiveInScene && this._nativeCollider.addTorque(torque);
26221
26338
  };
26339
+ /**
26340
+ * Apply a force to the DynamicCollider at a given position in world space.
26341
+ * The force generates both linear acceleration through the center of mass and angular
26342
+ * acceleration about it (torque = (position - centerOfMass) × force).
26343
+ * @param force - The force to apply, in world space
26344
+ * @param position - The position where the force is applied, in world space
26345
+ */ _proto.applyForceAtPosition = function applyForceAtPosition(force, position) {
26346
+ if (!this._phasedActiveInScene) return;
26347
+ var nativeCollider = this._nativeCollider;
26348
+ var localCoM = DynamicCollider._tempVector3;
26349
+ nativeCollider.getCenterOfMass(localCoM);
26350
+ var transform = this.entity.transform;
26351
+ var worldCoM = DynamicCollider._tempVector3_1;
26352
+ Vector3.transformByQuat(localCoM, transform.worldRotationQuaternion, worldCoM);
26353
+ worldCoM.add(transform.worldPosition);
26354
+ var torque = DynamicCollider._tempVector3_2;
26355
+ Vector3.subtract(position, worldCoM, torque);
26356
+ Vector3.cross(torque, force, torque);
26357
+ nativeCollider.addForce(force);
26358
+ nativeCollider.addTorque(torque);
26359
+ };
26222
26360
  _proto.move = function move(positionOrRotation, rotation) {
26223
26361
  if (!this._isKinematic) {
26224
26362
  console.warn("DynamicCollider: move() is only supported when isKinematic is true.");
@@ -26252,6 +26390,31 @@
26252
26390
  Collider.prototype.addShape.call(this, shape);
26253
26391
  };
26254
26392
  /**
26393
+ * Route per-frame entity → native transform sync to the correct physics API based
26394
+ * on kinematic state.
26395
+ *
26396
+ * PhysX 4.x docs (PxRigidDynamic):
26397
+ * "If you intend to move a kinematic actor with [setGlobalPose] and want
26398
+ * collision detection, use setKinematicTarget() instead."
26399
+ *
26400
+ * setGlobalPose is a teleport: PhysX skips contact detection between the old
26401
+ * and new pose, so two kinematic actors moved onto each other via entity.transform
26402
+ * mutation would NOT produce onCollisionEnter / onCollisionStay events even when
26403
+ * scene.kineKineFilteringMode = eKEEP. Routing the per-frame sync through
26404
+ * IDynamicCollider.move() (which the PhysX backend implements as
26405
+ * setKinematicTarget) tells PhysX the actor is animating to the target during the
26406
+ * next simulate(), enabling sweep contact detection for kine-kine and kine-dynamic
26407
+ * pairs alike.
26408
+ *
26409
+ * @internal
26410
+ */ _proto._syncEntityTransformToNative = function _syncEntityTransformToNative(worldPosition, worldRotation) {
26411
+ if (this._isKinematic) {
26412
+ this._nativeCollider.move(worldPosition, worldRotation);
26413
+ } else {
26414
+ Collider.prototype._syncEntityTransformToNative.call(this, worldPosition, worldRotation);
26415
+ }
26416
+ };
26417
+ /**
26255
26418
  * @internal
26256
26419
  */ _proto._onLateUpdate = function _onLateUpdate() {
26257
26420
  var transform = this.entity.transform;
@@ -26625,6 +26788,8 @@
26625
26788
  return DynamicCollider;
26626
26789
  }(exports.Collider);
26627
26790
  DynamicCollider._tempVector3 = new Vector3();
26791
+ DynamicCollider._tempVector3_1 = new Vector3();
26792
+ DynamicCollider._tempVector3_2 = new Vector3();
26628
26793
  DynamicCollider._tempQuat = new Quaternion();
26629
26794
  __decorate$1([
26630
26795
  ignoreClone
@@ -26701,8 +26866,7 @@
26701
26866
  * You need to obtain the actual number of contact points from the function's return value.
26702
26867
  */ _proto.getContacts = function getContacts(outContacts) {
26703
26868
  var nativeCollision = this._nativeCollision;
26704
- var smallerShapeId = Math.min(nativeCollision.shape0Id, nativeCollision.shape1Id);
26705
- var factor = this.shape.id === smallerShapeId ? 1 : -1;
26869
+ var factor = this.shape.id === nativeCollision.shape1Id ? 1 : -1;
26706
26870
  var nativeContactPoints = nativeCollision.getContacts();
26707
26871
  var length = nativeContactPoints.size();
26708
26872
  for(var i = 0; i < length; i++){
@@ -38182,8 +38346,8 @@
38182
38346
  if (this._tryCrossFadeInterrupt(layerData, transitionDuration, destState, deltaTime, aniUpdate)) {
38183
38347
  return;
38184
38348
  }
38185
- var srcPlaySpeed = srcState.speed * speed;
38186
- var dstPlaySpeed = destState.speed * speed;
38349
+ var srcPlaySpeed = srcPlayData.speed * speed;
38350
+ var dstPlaySpeed = destPlayData.speed * speed;
38187
38351
  var dstPlayDeltaTime = dstPlaySpeed * deltaTime;
38188
38352
  srcPlayData && srcPlayData.updateOrientation(srcPlaySpeed * deltaTime);
38189
38353
  destPlayData && destPlayData.updateOrientation(dstPlayDeltaTime);
@@ -53700,32 +53864,10 @@
53700
53864
  if (rootBoneIndex !== -1) {
53701
53865
  BoundingBox.transform(mesh.bounds, inverseBindMatrices[rootBoneIndex], skinnedMeshRenderer.localBounds);
53702
53866
  } else {
53703
- // Root bone is not in joints list, we can only compute approximate inverse bind matrix
53704
- // Average all root bone's children inverse bind matrix
53705
- var approximateBindMatrix = new Matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
53706
- var subRootBoneCount = this._computeApproximateBindMatrix(bones, inverseBindMatrices, rootBone, approximateBindMatrix);
53707
- if (subRootBoneCount !== 0) {
53708
- Matrix.multiplyScalar(approximateBindMatrix, 1.0 / subRootBoneCount, approximateBindMatrix);
53709
- BoundingBox.transform(mesh.bounds, approximateBindMatrix, skinnedMeshRenderer.localBounds);
53710
- } else {
53711
- skinnedMeshRenderer.localBounds.copyFrom(mesh.bounds);
53712
- }
53713
- }
53714
- };
53715
- _proto._computeApproximateBindMatrix = function _computeApproximateBindMatrix(jointEntities, inverseBindMatrices, rootEntity, approximateBindMatrix) {
53716
- var subRootBoneCount = 0;
53717
- var children = rootEntity.children;
53718
- for(var i = 0, n = children.length; i < n; i++){
53719
- var rootChild = children[i];
53720
- var index = jointEntities.indexOf(rootChild);
53721
- if (index !== -1) {
53722
- Matrix.add(approximateBindMatrix, inverseBindMatrices[index], approximateBindMatrix);
53723
- subRootBoneCount++;
53724
- } else {
53725
- subRootBoneCount += this._computeApproximateBindMatrix(jointEntities, inverseBindMatrices, rootChild, approximateBindMatrix);
53726
- }
53867
+ var inverseRootBoneWorld = new Matrix();
53868
+ Matrix.invert(rootBone.transform.worldMatrix, inverseRootBoneWorld);
53869
+ BoundingBox.transform(mesh.bounds, inverseRootBoneWorld, skinnedMeshRenderer.localBounds);
53727
53870
  }
53728
- return subRootBoneCount;
53729
53871
  };
53730
53872
  return GLTFSceneParser;
53731
53873
  }(GLTFParser);
@@ -53767,8 +53909,7 @@
53767
53909
  var rootBone = entities[skeleton];
53768
53910
  skin.rootBone = rootBone;
53769
53911
  } else {
53770
- var _this__findSceneRootBone;
53771
- var rootBone1 = (_this__findSceneRootBone = _this._findSceneRootBone(context, joints, entities)) != null ? _this__findSceneRootBone : _this._findSkeletonRootBone(joints, entities);
53912
+ var rootBone1 = _this._findSkinRootBoneByLCA(index, joints, entities, glTF.nodes);
53772
53913
  if (rootBone1) {
53773
53914
  skin.rootBone = rootBone1;
53774
53915
  } else {
@@ -53779,46 +53920,20 @@
53779
53920
  });
53780
53921
  return AssetPromise.resolve(skinPromise);
53781
53922
  };
53782
- _proto._findSceneRootBone = function _findSceneRootBone(context, joints, entities) {
53783
- var glTF = context.glTF, glTFResource = context.glTFResource;
53784
- var scenes = glTF.scenes;
53785
- var sceneRoots = glTFResource._sceneRoots;
53786
- if (!(scenes == null ? void 0 : scenes.length) || !(sceneRoots == null ? void 0 : sceneRoots.length)) {
53787
- return null;
53788
- }
53789
- for(var i = 0, n = scenes.length; i < n; i++){
53790
- var _scenes_i_nodes;
53791
- var sceneNodes = (_scenes_i_nodes = scenes[i].nodes) != null ? _scenes_i_nodes : [];
53792
- if (sceneNodes.length <= 1) {
53793
- continue;
53794
- }
53795
- var sceneRoot = sceneRoots[i];
53796
- if (!sceneRoot) {
53797
- continue;
53798
- }
53799
- var sceneRootChildren = new Set(sceneNodes.map(function(nodeIndex) {
53800
- return entities[nodeIndex];
53801
- }));
53802
- var allJointsUnderSceneRoot = true;
53803
- for(var j = 0, m = joints.length; j < m; j++){
53804
- var entity = entities[joints[j]];
53805
- while(entity == null ? void 0 : entity.parent){
53806
- entity = entity.parent;
53807
- }
53808
- if (!sceneRootChildren.has(entity)) {
53809
- allJointsUnderSceneRoot = false;
53810
- break;
53811
- }
53812
- }
53813
- if (allJointsUnderSceneRoot) {
53814
- return sceneRoot;
53923
+ _proto._findSkinRootBoneByLCA = function _findSkinRootBoneByLCA(skinIndex, joints, entities, nodes) {
53924
+ if (nodes === void 0) nodes = [];
53925
+ var nodeIndices = joints.slice();
53926
+ for(var i = 0, n = nodes.length; i < n; i++){
53927
+ var _nodes_i;
53928
+ if (((_nodes_i = nodes[i]) == null ? void 0 : _nodes_i.skin) === skinIndex) {
53929
+ nodeIndices.push(i);
53815
53930
  }
53816
53931
  }
53817
- return null;
53932
+ return this._findRootBoneByLCA(nodeIndices, entities);
53818
53933
  };
53819
- _proto._findSkeletonRootBone = function _findSkeletonRootBone(joints, entities) {
53820
- var paths = {};
53821
- for(var _iterator = _create_for_of_iterator_helper_loose(joints), _step; !(_step = _iterator()).done;){
53934
+ _proto._findRootBoneByLCA = function _findRootBoneByLCA(nodeIndices, entities) {
53935
+ var paths = [];
53936
+ for(var _iterator = _create_for_of_iterator_helper_loose(nodeIndices), _step; !(_step = _iterator()).done;){
53822
53937
  var index = _step.value;
53823
53938
  var path = new Array();
53824
53939
  var entity = entities[index];
@@ -53826,17 +53941,22 @@
53826
53941
  path.unshift(entity);
53827
53942
  entity = entity.parent;
53828
53943
  }
53829
- paths[index] = path;
53944
+ if (path.length) {
53945
+ paths.push(path);
53946
+ }
53947
+ }
53948
+ if (!paths.length) {
53949
+ return null;
53830
53950
  }
53831
53951
  var rootNode = null;
53832
53952
  for(var i = 0;; i++){
53833
- var path1 = paths[joints[0]];
53953
+ var path1 = paths[0];
53834
53954
  if (i >= path1.length) {
53835
53955
  return rootNode;
53836
53956
  }
53837
53957
  var entity1 = path1[i];
53838
- for(var j = 1, m = joints.length; j < m; j++){
53839
- path1 = paths[joints[j]];
53958
+ for(var j = 1, m = paths.length; j < m; j++){
53959
+ path1 = paths[j];
53840
53960
  if (i >= path1.length || entity1 !== path1[i]) {
53841
53961
  return rootNode;
53842
53962
  }
@@ -55381,7 +55501,10 @@
55381
55501
  "mp3",
55382
55502
  "ogg",
55383
55503
  "wav",
55384
- "audio"
55504
+ "audio",
55505
+ "m4a",
55506
+ "aac",
55507
+ "flac"
55385
55508
  ])
55386
55509
  ], AudioLoader);
55387
55510
  var ShaderChunkLoader = /*#__PURE__*/ function(Loader) {
@@ -56171,7 +56294,7 @@
56171
56294
  ], EXT_texture_webp);
56172
56295
 
56173
56296
  //@ts-ignore
56174
- var version = "0.0.0-experimental-2.0-game.11";
56297
+ var version = "0.0.0-experimental-2.0-game.13";
56175
56298
  console.log("Galacean Engine Version: " + version);
56176
56299
  for(var key in CoreObjects){
56177
56300
  Loader.registerClass(key, CoreObjects[key]);