@series-inc/rundot-3d-engine 0.5.13 → 0.5.15

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.
@@ -245,11 +245,15 @@ var PhysicsSystem = class _PhysicsSystem {
245
245
  /**
246
246
  * Sync Three.js object position with physics body
247
247
  */
248
- static syncObjectToPhysics(object, rigidBody) {
248
+ static syncObjectToPhysics(object, rigidBody, collider) {
249
249
  const translation = rigidBody.translation();
250
250
  const rotation = rigidBody.rotation();
251
251
  object.position.set(translation.x, translation.y, translation.z);
252
252
  object.quaternion.set(rotation.x, rotation.y, rotation.z, rotation.w);
253
+ if (collider) {
254
+ const ct = collider.translation();
255
+ object.position.set(ct.x, ct.y, ct.z);
256
+ }
253
257
  }
254
258
  /**
255
259
  * Sync physics body position to Three.js object
@@ -382,7 +386,7 @@ var PhysicsSystem = class _PhysicsSystem {
382
386
  debugMesh.name = `debug_${id}`;
383
387
  const rigidBody = _PhysicsSystem.rigidBodies.get(id);
384
388
  if (rigidBody) {
385
- _PhysicsSystem.syncObjectToPhysics(debugMesh, rigidBody);
389
+ _PhysicsSystem.syncObjectToPhysics(debugMesh, rigidBody, collider);
386
390
  }
387
391
  return debugMesh;
388
392
  }
@@ -442,7 +446,8 @@ var PhysicsSystem = class _PhysicsSystem {
442
446
  if (rigidBody) {
443
447
  const isEnabled = rigidBody.isEnabled();
444
448
  if (isEnabled) {
445
- _PhysicsSystem.syncObjectToPhysics(mesh, rigidBody);
449
+ const collider = _PhysicsSystem.colliders.get(id);
450
+ _PhysicsSystem.syncObjectToPhysics(mesh, rigidBody, collider ?? void 0);
446
451
  if (!_PhysicsSystem.debugScene.children.includes(mesh)) {
447
452
  _PhysicsSystem.debugScene.add(mesh);
448
453
  }
@@ -4675,19 +4680,7 @@ var RigidBodyComponentThree = class _RigidBodyComponentThree extends Component {
4675
4680
  }
4676
4681
  this.gameObject.updateMatrixWorld(true);
4677
4682
  const pos = this.gameObject.getWorldPosition(new THREE10.Vector3());
4678
- const offset = new THREE10.Vector3(0, 0, 0);
4679
- if (this.options.centerOffset) {
4680
- offset.copy(this.options.centerOffset);
4681
- } else {
4682
- if (this.options.shape === "box" /* BOX */) {
4683
- offset.y = this.options.size.y / 2;
4684
- } else if (this.options.shape === "capsule" /* CAPSULE */) {
4685
- offset.y = this.options.height / 2;
4686
- } else if (this.options.shape === "sphere" /* SPHERE */) {
4687
- offset.y = this.options.radius;
4688
- }
4689
- }
4690
- bodyDesc.setTranslation(pos.x + offset.x, pos.y + offset.y, pos.z + offset.z);
4683
+ bodyDesc.setTranslation(pos.x, pos.y, pos.z);
4691
4684
  const worldQuat = this.gameObject.getWorldQuaternion(new THREE10.Quaternion());
4692
4685
  bodyDesc.setRotation({
4693
4686
  x: worldQuat.x,
@@ -4735,6 +4728,19 @@ var RigidBodyComponentThree = class _RigidBodyComponentThree extends Component {
4735
4728
  colliderDesc = ColliderDesc2.cuboid(size.x / 2, size.y / 2, size.z / 2);
4736
4729
  break;
4737
4730
  }
4731
+ const colliderOffset = new THREE10.Vector3(0, 0, 0);
4732
+ if (this.options.centerOffset) {
4733
+ colliderOffset.copy(this.options.centerOffset);
4734
+ } else {
4735
+ if (this.options.shape === "box" /* BOX */) {
4736
+ colliderOffset.y = this.options.size.y / 2;
4737
+ } else if (this.options.shape === "capsule" /* CAPSULE */) {
4738
+ colliderOffset.y = this.options.height / 2;
4739
+ } else if (this.options.shape === "sphere" /* SPHERE */) {
4740
+ colliderOffset.y = this.options.radius;
4741
+ }
4742
+ }
4743
+ colliderDesc.setTranslation(colliderOffset.x, colliderOffset.y, colliderOffset.z);
4738
4744
  colliderDesc.setRestitution(this.options.restitution);
4739
4745
  colliderDesc.setFriction(this.options.friction);
4740
4746
  colliderDesc.setSensor(this.options.isSensor);
@@ -4797,40 +4803,14 @@ var RigidBodyComponentThree = class _RigidBodyComponentThree extends Component {
4797
4803
  }
4798
4804
  const lerpPos = new THREE10.Vector3(curPos.x, curPos.y, curPos.z).lerp(nextPos, alpha);
4799
4805
  const slerpQuat = curQuat.clone().slerp(nextQuat, alpha);
4800
- if (this.options.centerOffset) {
4801
- lerpPos.sub(this.options.centerOffset);
4802
- } else {
4803
- let defaultYOffset = 0;
4804
- if (this.options.shape === "box" /* BOX */) {
4805
- defaultYOffset = this.options.size.y / 2;
4806
- } else if (this.options.shape === "capsule" /* CAPSULE */) {
4807
- defaultYOffset = this.options.height / 2;
4808
- } else if (this.options.shape === "sphere" /* SPHERE */) {
4809
- defaultYOffset = this.options.radius;
4810
- }
4811
- lerpPos.y -= defaultYOffset;
4812
- }
4813
4806
  this.gameObject.position.copy(lerpPos);
4814
4807
  this.gameObject.quaternion.copy(slerpQuat);
4815
4808
  } else if (this.options.type === "kinematic" /* KINEMATIC */) {
4816
4809
  this.gameObject.updateMatrixWorld(true);
4817
4810
  const worldPos = this.gameObject.getWorldPosition(_RigidBodyComponentThree._tempVec3);
4818
4811
  const worldQuat = this.gameObject.getWorldQuaternion(_RigidBodyComponentThree._tempQuat);
4819
- const offset = new THREE10.Vector3(0, 0, 0);
4820
- if (this.options.centerOffset) {
4821
- offset.copy(this.options.centerOffset);
4822
- } else {
4823
- if (this.options.shape === "capsule" /* CAPSULE */ || this.options.shape === "box" /* BOX */) {
4824
- const height = this.options.height || this.options.size?.y || 3;
4825
- offset.y = height / 2;
4826
- }
4827
- }
4828
4812
  this.rigidBody.setTranslation(
4829
- {
4830
- x: worldPos.x + offset.x,
4831
- y: worldPos.y + offset.y,
4832
- z: worldPos.z + offset.z
4833
- },
4813
+ { x: worldPos.x, y: worldPos.y, z: worldPos.z },
4834
4814
  true
4835
4815
  );
4836
4816
  this.rigidBody.setRotation(
@@ -6135,4 +6115,4 @@ export {
6135
6115
  PrefabLoader,
6136
6116
  StowKitSystem
6137
6117
  };
6138
- //# sourceMappingURL=chunk-ETKDCGQV.js.map
6118
+ //# sourceMappingURL=chunk-JD4M2BHR.js.map