three-player-controller 0.1.1 → 0.1.3

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.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as THREE from 'three';
2
2
  import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';
3
3
 
4
- declare function usePlayer(): {
4
+ declare function playerController(): {
5
5
  init: (opts: {
6
6
  scene: THREE.Scene;
7
7
  camera: THREE.PerspectiveCamera;
@@ -15,19 +15,26 @@ declare function usePlayer(): {
15
15
  leftWalkAnim?: string;
16
16
  rightWalkAnim?: string;
17
17
  backwardAnim?: string;
18
- scale?: number;
18
+ scale: number;
19
+ gravity?: number;
20
+ jumpHeight?: number;
21
+ highJumpHeight?: number;
22
+ speed?: number;
19
23
  };
20
24
  initPos?: THREE.Vector3;
21
- scale?: number;
25
+ mouseSensity?: number;
22
26
  }, callback?: () => void) => Promise<void>;
23
27
  changeView: () => void;
24
28
  createBVH: (url?: string) => Promise<void>;
25
29
  createPlayer: () => void;
26
30
  reset: (pos?: THREE.Vector3) => void;
27
- updatePlayer: (dt: number) => Promise<void>;
31
+ update: (dt?: number) => Promise<void>;
28
32
  destroy: () => void;
33
+ displayCollider: boolean;
34
+ displayPlayer: boolean;
35
+ displayVisualizer: boolean;
29
36
  };
30
37
  declare function onAllEvent(): void;
31
38
  declare function offAllEvent(): void;
32
39
 
33
- export { offAllEvent, onAllEvent, usePlayer };
40
+ export { offAllEvent, onAllEvent, playerController };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as THREE from 'three';
2
2
  import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';
3
3
 
4
- declare function usePlayer(): {
4
+ declare function playerController(): {
5
5
  init: (opts: {
6
6
  scene: THREE.Scene;
7
7
  camera: THREE.PerspectiveCamera;
@@ -15,19 +15,26 @@ declare function usePlayer(): {
15
15
  leftWalkAnim?: string;
16
16
  rightWalkAnim?: string;
17
17
  backwardAnim?: string;
18
- scale?: number;
18
+ scale: number;
19
+ gravity?: number;
20
+ jumpHeight?: number;
21
+ highJumpHeight?: number;
22
+ speed?: number;
19
23
  };
20
24
  initPos?: THREE.Vector3;
21
- scale?: number;
25
+ mouseSensity?: number;
22
26
  }, callback?: () => void) => Promise<void>;
23
27
  changeView: () => void;
24
28
  createBVH: (url?: string) => Promise<void>;
25
29
  createPlayer: () => void;
26
30
  reset: (pos?: THREE.Vector3) => void;
27
- updatePlayer: (dt: number) => Promise<void>;
31
+ update: (dt?: number) => Promise<void>;
28
32
  destroy: () => void;
33
+ displayCollider: boolean;
34
+ displayPlayer: boolean;
35
+ displayVisualizer: boolean;
29
36
  };
30
37
  declare function onAllEvent(): void;
31
38
  declare function offAllEvent(): void;
32
39
 
33
- export { offAllEvent, onAllEvent, usePlayer };
40
+ export { offAllEvent, onAllEvent, playerController };
package/dist/index.js CHANGED
@@ -31,7 +31,7 @@ var index_exports = {};
31
31
  __export(index_exports, {
32
32
  offAllEvent: () => offAllEvent,
33
33
  onAllEvent: () => onAllEvent,
34
- usePlayer: () => usePlayer
34
+ playerController: () => playerController
35
35
  });
36
36
  module.exports = __toCommonJS(index_exports);
37
37
 
@@ -43,12 +43,14 @@ var import_DRACOLoader = require("three/examples/jsm/loaders/DRACOLoader.js");
43
43
  var import_GLTFLoader = require("three/examples/jsm/loaders/GLTFLoader.js");
44
44
  var BufferGeometryUtils = __toESM(require("three/examples/jsm/utils/BufferGeometryUtils.js"));
45
45
  var controllerInstance = null;
46
+ var clock = new THREE.Clock();
46
47
  var PlayerController = class {
47
48
  // 射线检测时只返回第一个碰撞
48
49
  constructor() {
49
50
  this.loader = new import_GLTFLoader.GLTFLoader();
51
+ this.playerRadius = 45;
52
+ this.playerHeight = 180;
50
53
  this.isFirstPerson = false;
51
- this.mouseSensity = 5;
52
54
  this.boundingBoxMinY = 0;
53
55
  // 测试参数
54
56
  this.displayPlayer = false;
@@ -60,24 +62,16 @@ var PlayerController = class {
60
62
  this.person = null;
61
63
  // 状态开关
62
64
  this.playerIsOnGround = false;
63
- this.isUpdatePlayer = true;
65
+ this.isupdate = true;
64
66
  // 输入状态
65
67
  this.fwdPressed = false;
66
- // w
67
68
  this.bkdPressed = false;
68
- // s
69
69
  this.lftPressed = false;
70
- // a
71
70
  this.rgtPressed = false;
72
- // d
73
71
  this.spacePressed = false;
74
- // 空格
75
72
  this.ctPressed = false;
76
- // ctrl
77
73
  this.shiftPressed = false;
78
- // shift
79
74
  this.sustainSpacePressed = false;
80
- // 空格键是否持续按下
81
75
  this.spaceLongPressTimer = null;
82
76
  // 第三人称
83
77
  this._camCollisionLerp = 0.18;
@@ -110,14 +104,8 @@ var PlayerController = class {
110
104
  this.DIR_RGT = new THREE.Vector3(1, 0, 0);
111
105
  this._personToCam = new THREE.Vector3();
112
106
  this._originTmp = new THREE.Vector3();
113
- this._raycaster = new THREE.Raycaster(
114
- new THREE.Vector3(),
115
- new THREE.Vector3(0, -1, 0)
116
- );
117
- this._raycasterPersonToCam = new THREE.Raycaster(
118
- new THREE.Vector3(),
119
- new THREE.Vector3()
120
- );
107
+ this._raycaster = new THREE.Raycaster(new THREE.Vector3(), new THREE.Vector3(0, -1, 0));
108
+ this._raycasterPersonToCam = new THREE.Raycaster(new THREE.Vector3(), new THREE.Vector3());
121
109
  // 键盘按下事件
122
110
  this._boundOnKeydown = async (e) => {
123
111
  if (e.ctrlKey && (e.code === "KeyW" || e.code === "KeyA" || e.code === "KeyS" || e.code === "KeyD")) {
@@ -240,11 +228,7 @@ var PlayerController = class {
240
228
  const yaw = -e.movementX * 1e-4 * this.mouseSensity;
241
229
  const pitch = -e.movementY * 1e-4 * this.mouseSensity;
242
230
  this.player.rotateY(yaw);
243
- this.camera.rotation.x = THREE.MathUtils.clamp(
244
- this.camera.rotation.x + pitch,
245
- -1.3,
246
- 1.4
247
- );
231
+ this.camera.rotation.x = THREE.MathUtils.clamp(this.camera.rotation.x + pitch, -1.3, 1.4);
248
232
  } else {
249
233
  const sensitivity = 1e-4 * this.mouseSensity;
250
234
  const deltaX = -e.movementX * sensitivity;
@@ -260,17 +244,12 @@ var PlayerController = class {
260
244
  const newX = distance * Math.sin(phi) * Math.sin(theta);
261
245
  const newY = distance * Math.cos(phi);
262
246
  const newZ = distance * Math.sin(phi) * Math.cos(theta);
263
- this.camera.position.set(
264
- target.x + newX,
265
- target.y + newY,
266
- target.z + newZ
267
- );
247
+ this.camera.position.set(target.x + newX, target.y + newY, target.z + newZ);
268
248
  this.camera.lookAt(target);
269
249
  }
270
250
  };
271
251
  this._mouseClick = (e) => {
272
- if (document.pointerLockElement !== document.body)
273
- document.body.requestPointerLock();
252
+ if (document.pointerLockElement !== document.body) document.body.requestPointerLock();
274
253
  };
275
254
  this._raycaster.firstHitOnly = true;
276
255
  this._raycasterPersonToCam.firstHitOnly = true;
@@ -281,13 +260,18 @@ var PlayerController = class {
281
260
  this.camera = opts.camera;
282
261
  this.controls = opts.controls;
283
262
  this.playerModel = opts.playerModel;
284
- this.playerModel.scale = opts.playerModel.scale ? opts.playerModel.scale : 1;
285
263
  this.initPos = opts.initPos ? opts.initPos : new THREE.Vector3(0, 0, 0);
286
- this.visualizeDepth = 0 * this.playerModel.scale;
287
- this.gravity = -2400 * this.playerModel.scale;
288
- this.jumpHeight = 300 * this.playerModel.scale;
289
- this.highJumpHeight = 1e3 * this.playerModel.scale;
290
- this.playerSpeed = 400 * this.playerModel.scale;
264
+ this.mouseSensity = opts.mouseSensity ? opts.mouseSensity : 5;
265
+ const s = this.playerModel.scale;
266
+ this.visualizeDepth = 0 * s;
267
+ this.gravity = opts.playerModel.gravity ? opts.playerModel.gravity * s : -2400 * s;
268
+ this.jumpHeight = opts.playerModel.jumpHeight ? opts.playerModel.jumpHeight * s : 300 * s;
269
+ this.highJumpHeight = opts.playerModel.highJumpHeight ? opts.playerModel.highJumpHeight * s : 1e3 * s;
270
+ this.playerSpeed = opts.playerModel.speed ? opts.playerModel.speed * s : 400 * s;
271
+ this._camCollisionLerp = 0.18;
272
+ this._camEpsilon = 35 * s;
273
+ this._minCamDistance = 100 * s;
274
+ this._maxCamDistance = 440 * s;
291
275
  await this.createBVH();
292
276
  this.createPlayer();
293
277
  await this.loadPersonGLB();
@@ -304,25 +288,15 @@ var PlayerController = class {
304
288
  this.isFirstPerson = !this.isFirstPerson;
305
289
  if (this.isFirstPerson) {
306
290
  this.player.attach(this.camera);
307
- this.camera.position.set(
308
- 0,
309
- 40 * this.playerModel.scale,
310
- 30 * this.playerModel.scale
311
- );
291
+ this.camera.position.set(0, 40 * this.playerModel.scale, 30 * this.playerModel.scale);
312
292
  this.camera.rotation.set(0, Math.PI, 0);
313
293
  document.body.requestPointerLock();
314
294
  } else {
315
295
  this.scene.attach(this.camera);
316
296
  const worldPos = this.player.position.clone();
317
- const dir = new THREE.Vector3(0, 0, -1).applyQuaternion(
318
- this.player.quaternion
319
- );
297
+ const dir = new THREE.Vector3(0, 0, -1).applyQuaternion(this.player.quaternion);
320
298
  const angle = Math.atan2(dir.z, dir.x);
321
- const offset = new THREE.Vector3(
322
- Math.cos(angle) * 400 * this.playerModel.scale,
323
- 200 * this.playerModel.scale,
324
- Math.sin(angle) * 400 * this.playerModel.scale
325
- );
299
+ const offset = new THREE.Vector3(Math.cos(angle) * 400 * this.playerModel.scale, 200 * this.playerModel.scale, Math.sin(angle) * 400 * this.playerModel.scale);
326
300
  this.camera.position.copy(worldPos).add(offset);
327
301
  this.controls.target.copy(worldPos);
328
302
  document.body.requestPointerLock();
@@ -334,15 +308,9 @@ var PlayerController = class {
334
308
  this.camera.position.set(0, 40 * this.playerModel.scale, 30 * this.playerModel.scale);
335
309
  } else {
336
310
  const worldPos = this.player.position.clone();
337
- const dir = new THREE.Vector3(0, 0, -1).applyQuaternion(
338
- this.player.quaternion
339
- );
311
+ const dir = new THREE.Vector3(0, 0, -1).applyQuaternion(this.player.quaternion);
340
312
  const angle = Math.atan2(dir.z, dir.x);
341
- const offset = new THREE.Vector3(
342
- Math.cos(angle) * 400 * this.playerModel.scale,
343
- 200 * this.playerModel.scale,
344
- Math.sin(angle) * 400 * this.playerModel.scale
345
- );
313
+ const offset = new THREE.Vector3(Math.cos(angle) * 400 * this.playerModel.scale, 200 * this.playerModel.scale, Math.sin(angle) * 400 * this.playerModel.scale);
346
314
  this.camera.position.copy(worldPos).add(offset);
347
315
  }
348
316
  this.camera.updateProjectionMatrix();
@@ -368,28 +336,19 @@ var PlayerController = class {
368
336
  // 初始化加载器
369
337
  async initLoader() {
370
338
  const dracoLoader = new import_DRACOLoader.DRACOLoader();
371
- dracoLoader.setDecoderPath(
372
- "https://unpkg.com/three@0.180.0/examples/jsm/libs/draco/gltf/"
373
- );
339
+ dracoLoader.setDecoderPath("https://unpkg.com/three@0.180.0/examples/jsm/libs/draco/gltf/");
374
340
  dracoLoader.setDecoderConfig({ type: "js" });
375
341
  this.loader.setDRACOLoader(dracoLoader);
376
342
  }
377
343
  // 人物与动画加载
378
344
  async loadPersonGLB() {
379
345
  try {
380
- const gltf = await this.loader.loadAsync(
381
- this.playerModel.url,
382
- (xhr) => {
383
- }
384
- );
346
+ const gltf = await this.loader.loadAsync(this.playerModel.url);
385
347
  this.person = gltf.scene;
386
- this.person.name = "\u89D2\u8272";
387
- this.person.scale.set(
388
- 0.9 * this.playerModel.scale,
389
- 0.9 * this.playerModel.scale,
390
- 0.9 * this.playerModel.scale
391
- );
392
- this.person.position.set(0, -125 * this.playerModel.scale, 0);
348
+ const sc = this.playerModel.scale;
349
+ const h = this.playerHeight * sc;
350
+ this.person.scale.set(sc, sc, sc);
351
+ this.person.position.set(0, -h * 0.75, 0);
393
352
  this.player.add(this.person);
394
353
  this.reset();
395
354
  this.personMixer = new THREE.AnimationMixer(this.person);
@@ -483,32 +442,21 @@ var PlayerController = class {
483
442
  material.transparent = true;
484
443
  material.opacity = this.displayPlayer ? 0.5 : 0;
485
444
  material.wireframe = true;
486
- this.player = new THREE.Mesh(
487
- new import_RoundedBoxGeometry.RoundedBoxGeometry(
488
- 75 * this.playerModel.scale,
489
- 180 * this.playerModel.scale,
490
- 75 * this.playerModel.scale,
491
- 100 * this.playerModel.scale,
492
- 75 * this.playerModel.scale
493
- ),
494
- material
495
- );
496
- this.player.geometry.translate(0, -30 * this.playerModel.scale, 0);
445
+ const r = this.playerRadius * this.playerModel.scale;
446
+ const h = this.playerHeight * this.playerModel.scale;
447
+ this.player = new THREE.Mesh(new import_RoundedBoxGeometry.RoundedBoxGeometry(r * 2, h, r * 2, 1, 75), material);
448
+ this.player.geometry.translate(0, -h * 0.25, 0);
497
449
  this.player.capsuleInfo = {
498
- radius: 25 * this.playerModel.scale,
499
- segment: new THREE.Line3(
500
- new THREE.Vector3(),
501
- new THREE.Vector3(0, -1, 0)
502
- )
450
+ radius: r,
451
+ segment: new THREE.Line3(new THREE.Vector3(), new THREE.Vector3(0, -h * 0.5, 0))
503
452
  };
504
- this.player.name = "\u89D2\u8272\u80F6\u56CA\u4F53";
505
- this.player.rotateY(Math.PI / 2);
453
+ this.player.name = "capsule";
506
454
  this.scene.add(this.player);
507
455
  this.reset();
508
456
  }
509
457
  // 每帧更新
510
- async updatePlayer(delta) {
511
- if (!this.isUpdatePlayer || !this.player) return;
458
+ async update(delta = clock.getDelta()) {
459
+ if (!this.isupdate || !this.player) return;
512
460
  delta = Math.min(delta, 1 / 30);
513
461
  this.updateMixers(delta);
514
462
  if (!this.collider) return;
@@ -543,29 +491,21 @@ var PlayerController = class {
543
491
  this.playerSpeed = this.shiftPressed ? 900 * this.playerModel.scale : 400 * this.playerModel.scale;
544
492
  if (this.moveDir.lengthSq() > 1e-6) {
545
493
  this.moveDir.normalize().applyAxisAngle(this.upVector, angle);
546
- this.player.position.addScaledVector(
547
- this.moveDir,
548
- this.playerSpeed * delta
549
- );
494
+ this.player.position.addScaledVector(this.moveDir, this.playerSpeed * delta);
550
495
  }
551
496
  let playerDistanceFromGround = Infinity;
552
- this._originTmp.set(
553
- this.player.position.x,
554
- this.player.position.y,
555
- this.player.position.z
556
- );
497
+ this._originTmp.set(this.player.position.x, this.player.position.y, this.player.position.z);
557
498
  this._raycaster.ray.origin.copy(this._originTmp);
558
- const intersects = this._raycaster.intersectObject(
559
- this.collider,
560
- false
561
- );
499
+ const intersects = this._raycaster.intersectObject(this.collider, false);
562
500
  if (intersects.length > 0) {
563
501
  playerDistanceFromGround = this.player.position.y - intersects[0].point.y;
564
502
  }
565
- if (playerDistanceFromGround > 130 * this.playerModel.scale) {
503
+ const h = this.playerHeight * this.playerModel.scale * 0.75;
504
+ if (playerDistanceFromGround > h) {
566
505
  this.playerVelocity.y += delta * this.gravity;
567
506
  this.player.position.addScaledVector(this.playerVelocity, delta);
568
507
  } else {
508
+ this.playerVelocity.set(0, 0, 0);
569
509
  this.playerIsOnGround = true;
570
510
  }
571
511
  this.player.updateMatrixWorld();
@@ -586,11 +526,7 @@ var PlayerController = class {
586
526
  intersectsTriangle: (tri) => {
587
527
  const triPoint = this.tempVector;
588
528
  const capsulePoint = this.tempVector2;
589
- const distance = tri.closestPointToSegment(
590
- this.tempSegment,
591
- triPoint,
592
- capsulePoint
593
- );
529
+ const distance = tri.closestPointToSegment(this.tempSegment, triPoint, capsulePoint);
594
530
  if (distance < capsuleInfo.radius) {
595
531
  const depth = capsuleInfo.radius - distance;
596
532
  const direction = capsulePoint.sub(triPoint).normalize();
@@ -600,16 +536,12 @@ var PlayerController = class {
600
536
  }
601
537
  });
602
538
  const newPosition = this.tempVector.copy(this.tempSegment.start).applyMatrix4(this.collider.matrixWorld);
603
- const deltaVector = this.tempVector2.subVectors(
604
- newPosition,
605
- this.player.position
606
- );
539
+ const deltaVector = this.tempVector2.subVectors(newPosition, this.player.position);
607
540
  const len = deltaVector.length();
608
541
  const offset = Math.max(0, len - 1e-5);
609
542
  if (offset > 0 && len > 0) {
610
543
  const n = deltaVector.multiplyScalar(1 / len);
611
544
  this.player.position.addScaledVector(n, offset);
612
- this.playerVelocity.set(0, 0, 0);
613
545
  }
614
546
  if (!this.isFirstPerson && this.moveDir.lengthSq() > 0) {
615
547
  this.camDir.y = 0;
@@ -636,25 +568,16 @@ var PlayerController = class {
636
568
  const desiredDist = this._personToCam.length();
637
569
  this._raycasterPersonToCam.set(origin, direction);
638
570
  this._raycasterPersonToCam.far = desiredDist;
639
- const intersects2 = this._raycasterPersonToCam.intersectObject(
640
- this.collider,
641
- false
642
- );
571
+ const intersects2 = this._raycasterPersonToCam.intersectObject(this.collider, false);
643
572
  if (intersects2.length > 0) {
644
573
  const hit = intersects2[0];
645
- const safeDist = Math.max(
646
- hit.distance - this._camEpsilon,
647
- this._minCamDistance
648
- );
574
+ const safeDist = Math.max(hit.distance - this._camEpsilon, this._minCamDistance);
649
575
  const targetCamPos = origin.clone().add(direction.clone().multiplyScalar(safeDist));
650
576
  this.camera.position.lerp(targetCamPos, this._camCollisionLerp);
651
577
  } else {
652
578
  const dis = this.player.position.distanceTo(this.camera.position);
653
579
  this._raycasterPersonToCam.far = this._maxCamDistance;
654
- const intersectsMaxDis = this._raycasterPersonToCam.intersectObject(
655
- this.collider,
656
- false
657
- );
580
+ const intersectsMaxDis = this._raycasterPersonToCam.intersectObject(this.collider, false);
658
581
  if (dis < this._maxCamDistance) {
659
582
  let safeDist = this._maxCamDistance;
660
583
  if (intersectsMaxDis.length) {
@@ -667,34 +590,15 @@ var PlayerController = class {
667
590
  }
668
591
  }
669
592
  if (this.player.position.y < this.boundingBoxMinY - 1) {
670
- this._originTmp.set(
671
- this.player.position.x,
672
- 1e4,
673
- this.player.position.z
674
- );
593
+ this._originTmp.set(this.player.position.x, 1e4, this.player.position.z);
675
594
  this._raycaster.ray.origin.copy(this._originTmp);
676
- const intersects2 = this._raycaster.intersectObject(
677
- this.collider,
678
- false
679
- );
595
+ const intersects2 = this._raycaster.intersectObject(this.collider, false);
680
596
  if (intersects2.length > 0) {
681
597
  console.log("\u73A9\u5BB6\u4E3Abug\u610F\u5916\u6389\u843D");
682
- this.reset(
683
- new THREE.Vector3(
684
- this.player.position.x,
685
- intersects2[0].point.y + 5,
686
- this.player.position.z
687
- )
688
- );
598
+ this.reset(new THREE.Vector3(this.player.position.x, intersects2[0].point.y + 5, this.player.position.z));
689
599
  } else {
690
600
  console.log("\u73A9\u5BB6\u6B63\u5E38\u6389\u843D");
691
- this.reset(
692
- new THREE.Vector3(
693
- this.player.position.x,
694
- this.player.position.y + 15,
695
- this.player.position.z
696
- )
697
- );
601
+ this.reset(new THREE.Vector3(this.player.position.x, this.player.position.y + 15, this.player.position.z));
698
602
  }
699
603
  }
700
604
  }
@@ -729,7 +633,7 @@ var PlayerController = class {
729
633
  }
730
634
  // 事件绑定
731
635
  onAllEvent() {
732
- this.isUpdatePlayer = true;
636
+ this.isupdate = true;
733
637
  document.body.requestPointerLock();
734
638
  window.addEventListener("keydown", this._boundOnKeydown);
735
639
  window.addEventListener("keyup", this._boundOnKeyup);
@@ -738,7 +642,7 @@ var PlayerController = class {
738
642
  }
739
643
  // 事件解绑
740
644
  offAllEvent() {
741
- this.isUpdatePlayer = false;
645
+ this.isupdate = false;
742
646
  document.exitPointerLock();
743
647
  window.removeEventListener("keydown", this._boundOnKeydown);
744
648
  window.removeEventListener("keyup", this._boundOnKeyup);
@@ -773,7 +677,7 @@ var PlayerController = class {
773
677
  }
774
678
  this.scene.traverse((c) => {
775
679
  const mesh = c;
776
- if (mesh?.isMesh && mesh.geometry && c.name !== "\u89D2\u8272\u80F6\u56CA\u4F53") {
680
+ if (mesh?.isMesh && mesh.geometry && c.name !== "capsule") {
777
681
  try {
778
682
  let geom = mesh.geometry.clone();
779
683
  geom.applyMatrix4(mesh.matrixWorld);
@@ -799,8 +703,7 @@ var PlayerController = class {
799
703
  attrMap.set(name, { itemSize, arrayCtor: ctor, examples: 1 });
800
704
  } else {
801
705
  const m = attrMap.get(name);
802
- if (m.itemSize !== itemSize || m.arrayCtor !== ctor)
803
- attrConflict.add(name);
706
+ if (m.itemSize !== itemSize || m.arrayCtor !== ctor) attrConflict.add(name);
804
707
  else m.examples++;
805
708
  }
806
709
  }
@@ -821,10 +724,7 @@ var PlayerController = class {
821
724
  const meta = attrMap.get(name);
822
725
  const len = count * meta.itemSize;
823
726
  const array = new meta.arrayCtor(len);
824
- g.setAttribute(
825
- name,
826
- new THREE.BufferAttribute(array, meta.itemSize)
827
- );
727
+ g.setAttribute(name, new THREE.BufferAttribute(array, meta.itemSize));
828
728
  }
829
729
  }
830
730
  }
@@ -847,11 +747,16 @@ var PlayerController = class {
847
747
  merged.boundsTree = new import_three_mesh_bvh.MeshBVH(merged);
848
748
  this.collider = new THREE.Mesh(
849
749
  merged,
750
+ // new THREE.MeshBasicMaterial({
751
+ // color: "red",
752
+ // opacity: 0.2,
753
+ // transparent: true,
754
+ // wireframe: false,
755
+ // })
850
756
  new THREE.MeshBasicMaterial({
851
- color: "red",
852
- opacity: 0.2,
757
+ opacity: 0.5,
853
758
  transparent: true,
854
- wireframe: false
759
+ wireframe: true
855
760
  })
856
761
  );
857
762
  if (this.displayCollider) this.scene.add(this.collider);
@@ -864,7 +769,7 @@ var PlayerController = class {
864
769
  console.log("bvh\u52A0\u8F7D\u6A21\u578B\u6210\u529F", this.collider);
865
770
  }
866
771
  };
867
- function usePlayer() {
772
+ function playerController() {
868
773
  if (!controllerInstance) controllerInstance = new PlayerController();
869
774
  const c = controllerInstance;
870
775
  return {
@@ -873,8 +778,11 @@ function usePlayer() {
873
778
  createBVH: (url = "") => c.createBVH(url),
874
779
  createPlayer: () => c.createPlayer(),
875
780
  reset: (pos) => c.reset(pos),
876
- updatePlayer: (dt) => c.updatePlayer(dt),
877
- destroy: () => c.destroy()
781
+ update: (dt) => c.update(dt),
782
+ destroy: () => c.destroy(),
783
+ displayCollider: c.displayCollider,
784
+ displayPlayer: c.displayPlayer,
785
+ displayVisualizer: c.displayVisualizer
878
786
  };
879
787
  }
880
788
  function onAllEvent() {
@@ -889,6 +797,6 @@ function offAllEvent() {
889
797
  0 && (module.exports = {
890
798
  offAllEvent,
891
799
  onAllEvent,
892
- usePlayer
800
+ playerController
893
801
  });
894
802
  //# sourceMappingURL=index.js.map