three-player-controller 0.3.6 → 0.3.7

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/index.mjs CHANGED
@@ -300,8 +300,9 @@ var PlayerController = class {
300
300
  this.enableOverShoulderView = false;
301
301
  this.isChangeControllerTransitionTimer = null;
302
302
  // ==================== 玩家基本属性 ====================
303
- this.playerRadius = 45;
304
- this.playerHeight = 180;
303
+ this.playerCapsuleRadius = 45;
304
+ this.playerCapsuleRadiusRatio = 1;
305
+ this.playerCapsuleHeight = 180;
305
306
  // 玩家参考身高
306
307
  this.isFirstPerson = false;
307
308
  this.boundingBoxMinY = 0;
@@ -331,7 +332,7 @@ var PlayerController = class {
331
332
  // 全局车辆共享参数
332
333
  this.vehicleParams = {
333
334
  debug: {
334
- showPhysicsBox: true
335
+ showPhysicsBox: false
335
336
  },
336
337
  chassis: {
337
338
  linearDamping: 0.5,
@@ -677,7 +678,7 @@ var PlayerController = class {
677
678
  this.gravity = (opts.playerModel.gravity ?? -2400) * s;
678
679
  this.jumpHeight = (opts.playerModel.jumpHeight ?? 600) * s;
679
680
  this.playerSpeed = (opts.playerModel.speed ?? 300) * s;
680
- this.playerFlySpeed = (opts.playerModel.playerFlySpeed ?? 2100) * s;
681
+ this.playerFlySpeed = (opts.playerModel.flySpeed ?? 2100) * s;
681
682
  this.curPlayerSpeed = this.playerSpeed;
682
683
  this.playerModel.rotateY = opts.playerModel.rotateY ?? 0;
683
684
  this.playerFlyEnabled = opts.playerModel.flyEnabled ?? true;
@@ -688,6 +689,7 @@ var PlayerController = class {
688
689
  this.orginMaxCamDistance = this.maxCamDistance;
689
690
  this.thirdMouseMode = opts.thirdMouseMode ?? 1;
690
691
  this.enableZoom = opts.enableZoom ?? false;
692
+ this.playerCapsuleRadiusRatio = opts.playerModel.capsuleRadiusRatio ?? 1;
691
693
  const isMobileDevice = () => navigator.maxTouchPoints && navigator.maxTouchPoints > 0 || "ontouchstart" in window || /Mobi|Android|iPhone|iPad|iPod/i.test(navigator.userAgent);
692
694
  this.isShowMobileControls = (opts.isShowMobileControls ?? true) && isMobileDevice();
693
695
  if (this.isShowMobileControls) {
@@ -768,11 +770,10 @@ var PlayerController = class {
768
770
  );
769
771
  this.person = gltf.scene;
770
772
  const { size } = this.getBbox(this.person);
771
- const ratio = this.playerHeight / size.y;
772
- const power = Math.round(Math.log10(ratio));
773
- const modelScale = Math.pow(10, power);
774
- this.playerRadius = Number(Math.min(size.x, size.z).toFixed(0)) * modelScale;
775
- this.playerHeight = Number(size.y.toFixed(0)) * modelScale;
773
+ const ratio = this.playerCapsuleHeight / size.y;
774
+ const modelScale = ratio;
775
+ this.playerCapsuleRadius = Number(Math.min(size.x, size.z).toFixed(0)) * modelScale * this.playerCapsuleRadiusRatio;
776
+ this.playerCapsuleHeight = Number(size.y.toFixed(0)) * modelScale;
776
777
  const scale = this.playerModel.scale;
777
778
  const material = new THREE3.MeshStandardMaterial({
778
779
  color: new THREE3.Color(1, 0, 0),
@@ -783,8 +784,8 @@ var PlayerController = class {
783
784
  wireframe: true,
784
785
  depthWrite: false
785
786
  });
786
- const r = this.playerRadius * scale;
787
- const h = this.playerHeight * scale;
787
+ const r = this.playerCapsuleRadius * scale;
788
+ const h = this.playerCapsuleHeight * scale;
788
789
  this.player = new THREE3.Mesh(
789
790
  new RoundedBoxGeometry(r * 2, h, r * 2, 1, 75),
790
791
  material
@@ -972,8 +973,7 @@ var PlayerController = class {
972
973
  const vehicleModel = await this.loader.loadAsync(opts.url);
973
974
  const { size: originalSize } = this.getBbox(vehicleModel.scene);
974
975
  const ratio = this.vehicleLength / Math.max(originalSize.x, originalSize.y, originalSize.z);
975
- const power = Math.round(Math.log10(ratio));
976
- const modelScale = Math.pow(10, power);
976
+ const modelScale = ratio;
977
977
  const vehicleMixer = new THREE3.AnimationMixer(vehicleModel.scene);
978
978
  const animations = vehicleModel.animations ?? [];
979
979
  const vehicleActions = /* @__PURE__ */ new Map();
@@ -2129,9 +2129,9 @@ var PlayerController = class {
2129
2129
  );
2130
2130
  if (intersects.length > 0) {
2131
2131
  playerDistanceFromGround = this.player.position.y - intersects[0].point.y;
2132
- const maxH = this.playerHeight * this.playerModel.scale * 0.9;
2133
- const h = this.playerHeight * this.playerModel.scale * 0.75;
2134
- const minH = this.playerHeight * this.playerModel.scale * 0.7;
2132
+ const maxH = this.playerCapsuleHeight * this.playerModel.scale * 0.9;
2133
+ const h = this.playerCapsuleHeight * this.playerModel.scale * 0.75;
2134
+ const minH = this.playerCapsuleHeight * this.playerModel.scale * 0.7;
2135
2135
  if (!this.isFlying) {
2136
2136
  if (playerDistanceFromGround >= maxH) {
2137
2137
  this.playerVelocity.y += delta * this.gravity;
@@ -2279,7 +2279,7 @@ var PlayerController = class {
2279
2279
  }
2280
2280
  if (!this.isFirstPerson) {
2281
2281
  const lookTarget = this.player.position.clone();
2282
- lookTarget.y += this.playerHeight / 8 * this.playerModel.scale;
2282
+ lookTarget.y += this.playerCapsuleHeight / 8 * this.playerModel.scale;
2283
2283
  this.camera.position.sub(this.controls.target);
2284
2284
  this.controls.target.copy(lookTarget);
2285
2285
  this.camera.position.add(lookTarget);