three-player-controller 0.1.1 → 0.1.2

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,22 @@ declare function usePlayer(): {
15
15
  leftWalkAnim?: string;
16
16
  rightWalkAnim?: string;
17
17
  backwardAnim?: string;
18
- scale?: number;
18
+ scale: number;
19
19
  };
20
20
  initPos?: THREE.Vector3;
21
- scale?: number;
21
+ mouseSensity?: number;
22
22
  }, callback?: () => void) => Promise<void>;
23
23
  changeView: () => void;
24
24
  createBVH: (url?: string) => Promise<void>;
25
25
  createPlayer: () => void;
26
26
  reset: (pos?: THREE.Vector3) => void;
27
- updatePlayer: (dt: number) => Promise<void>;
27
+ update: (dt?: number) => Promise<void>;
28
28
  destroy: () => void;
29
+ displayCollider: boolean;
30
+ displayPlayer: boolean;
31
+ displayVisualizer: boolean;
29
32
  };
30
33
  declare function onAllEvent(): void;
31
34
  declare function offAllEvent(): void;
32
35
 
33
- export { offAllEvent, onAllEvent, usePlayer };
36
+ 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,22 @@ declare function usePlayer(): {
15
15
  leftWalkAnim?: string;
16
16
  rightWalkAnim?: string;
17
17
  backwardAnim?: string;
18
- scale?: number;
18
+ scale: number;
19
19
  };
20
20
  initPos?: THREE.Vector3;
21
- scale?: number;
21
+ mouseSensity?: number;
22
22
  }, callback?: () => void) => Promise<void>;
23
23
  changeView: () => void;
24
24
  createBVH: (url?: string) => Promise<void>;
25
25
  createPlayer: () => void;
26
26
  reset: (pos?: THREE.Vector3) => void;
27
- updatePlayer: (dt: number) => Promise<void>;
27
+ update: (dt?: number) => Promise<void>;
28
28
  destroy: () => void;
29
+ displayCollider: boolean;
30
+ displayPlayer: boolean;
31
+ displayVisualizer: boolean;
29
32
  };
30
33
  declare function onAllEvent(): void;
31
34
  declare function offAllEvent(): void;
32
35
 
33
- export { offAllEvent, onAllEvent, usePlayer };
36
+ 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,23 @@ 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);
507
+ console.log("delta * this.gravity", delta * this.gravity);
568
508
  } else {
509
+ console.log("\u5728\u5730\u9762");
510
+ this.playerVelocity.set(0, 0, 0);
569
511
  this.playerIsOnGround = true;
570
512
  }
571
513
  this.player.updateMatrixWorld();
@@ -586,11 +528,7 @@ var PlayerController = class {
586
528
  intersectsTriangle: (tri) => {
587
529
  const triPoint = this.tempVector;
588
530
  const capsulePoint = this.tempVector2;
589
- const distance = tri.closestPointToSegment(
590
- this.tempSegment,
591
- triPoint,
592
- capsulePoint
593
- );
531
+ const distance = tri.closestPointToSegment(this.tempSegment, triPoint, capsulePoint);
594
532
  if (distance < capsuleInfo.radius) {
595
533
  const depth = capsuleInfo.radius - distance;
596
534
  const direction = capsulePoint.sub(triPoint).normalize();
@@ -600,16 +538,12 @@ var PlayerController = class {
600
538
  }
601
539
  });
602
540
  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
- );
541
+ const deltaVector = this.tempVector2.subVectors(newPosition, this.player.position);
607
542
  const len = deltaVector.length();
608
543
  const offset = Math.max(0, len - 1e-5);
609
544
  if (offset > 0 && len > 0) {
610
545
  const n = deltaVector.multiplyScalar(1 / len);
611
546
  this.player.position.addScaledVector(n, offset);
612
- this.playerVelocity.set(0, 0, 0);
613
547
  }
614
548
  if (!this.isFirstPerson && this.moveDir.lengthSq() > 0) {
615
549
  this.camDir.y = 0;
@@ -636,25 +570,16 @@ var PlayerController = class {
636
570
  const desiredDist = this._personToCam.length();
637
571
  this._raycasterPersonToCam.set(origin, direction);
638
572
  this._raycasterPersonToCam.far = desiredDist;
639
- const intersects2 = this._raycasterPersonToCam.intersectObject(
640
- this.collider,
641
- false
642
- );
573
+ const intersects2 = this._raycasterPersonToCam.intersectObject(this.collider, false);
643
574
  if (intersects2.length > 0) {
644
575
  const hit = intersects2[0];
645
- const safeDist = Math.max(
646
- hit.distance - this._camEpsilon,
647
- this._minCamDistance
648
- );
576
+ const safeDist = Math.max(hit.distance - this._camEpsilon, this._minCamDistance);
649
577
  const targetCamPos = origin.clone().add(direction.clone().multiplyScalar(safeDist));
650
578
  this.camera.position.lerp(targetCamPos, this._camCollisionLerp);
651
579
  } else {
652
580
  const dis = this.player.position.distanceTo(this.camera.position);
653
581
  this._raycasterPersonToCam.far = this._maxCamDistance;
654
- const intersectsMaxDis = this._raycasterPersonToCam.intersectObject(
655
- this.collider,
656
- false
657
- );
582
+ const intersectsMaxDis = this._raycasterPersonToCam.intersectObject(this.collider, false);
658
583
  if (dis < this._maxCamDistance) {
659
584
  let safeDist = this._maxCamDistance;
660
585
  if (intersectsMaxDis.length) {
@@ -667,34 +592,15 @@ var PlayerController = class {
667
592
  }
668
593
  }
669
594
  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
- );
595
+ this._originTmp.set(this.player.position.x, 1e4, this.player.position.z);
675
596
  this._raycaster.ray.origin.copy(this._originTmp);
676
- const intersects2 = this._raycaster.intersectObject(
677
- this.collider,
678
- false
679
- );
597
+ const intersects2 = this._raycaster.intersectObject(this.collider, false);
680
598
  if (intersects2.length > 0) {
681
599
  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
- );
600
+ this.reset(new THREE.Vector3(this.player.position.x, intersects2[0].point.y + 5, this.player.position.z));
689
601
  } else {
690
602
  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
- );
603
+ this.reset(new THREE.Vector3(this.player.position.x, this.player.position.y + 15, this.player.position.z));
698
604
  }
699
605
  }
700
606
  }
@@ -729,7 +635,7 @@ var PlayerController = class {
729
635
  }
730
636
  // 事件绑定
731
637
  onAllEvent() {
732
- this.isUpdatePlayer = true;
638
+ this.isupdate = true;
733
639
  document.body.requestPointerLock();
734
640
  window.addEventListener("keydown", this._boundOnKeydown);
735
641
  window.addEventListener("keyup", this._boundOnKeyup);
@@ -738,7 +644,7 @@ var PlayerController = class {
738
644
  }
739
645
  // 事件解绑
740
646
  offAllEvent() {
741
- this.isUpdatePlayer = false;
647
+ this.isupdate = false;
742
648
  document.exitPointerLock();
743
649
  window.removeEventListener("keydown", this._boundOnKeydown);
744
650
  window.removeEventListener("keyup", this._boundOnKeyup);
@@ -773,7 +679,7 @@ var PlayerController = class {
773
679
  }
774
680
  this.scene.traverse((c) => {
775
681
  const mesh = c;
776
- if (mesh?.isMesh && mesh.geometry && c.name !== "\u89D2\u8272\u80F6\u56CA\u4F53") {
682
+ if (mesh?.isMesh && mesh.geometry && c.name !== "capsule") {
777
683
  try {
778
684
  let geom = mesh.geometry.clone();
779
685
  geom.applyMatrix4(mesh.matrixWorld);
@@ -799,8 +705,7 @@ var PlayerController = class {
799
705
  attrMap.set(name, { itemSize, arrayCtor: ctor, examples: 1 });
800
706
  } else {
801
707
  const m = attrMap.get(name);
802
- if (m.itemSize !== itemSize || m.arrayCtor !== ctor)
803
- attrConflict.add(name);
708
+ if (m.itemSize !== itemSize || m.arrayCtor !== ctor) attrConflict.add(name);
804
709
  else m.examples++;
805
710
  }
806
711
  }
@@ -821,10 +726,7 @@ var PlayerController = class {
821
726
  const meta = attrMap.get(name);
822
727
  const len = count * meta.itemSize;
823
728
  const array = new meta.arrayCtor(len);
824
- g.setAttribute(
825
- name,
826
- new THREE.BufferAttribute(array, meta.itemSize)
827
- );
729
+ g.setAttribute(name, new THREE.BufferAttribute(array, meta.itemSize));
828
730
  }
829
731
  }
830
732
  }
@@ -847,11 +749,16 @@ var PlayerController = class {
847
749
  merged.boundsTree = new import_three_mesh_bvh.MeshBVH(merged);
848
750
  this.collider = new THREE.Mesh(
849
751
  merged,
752
+ // new THREE.MeshBasicMaterial({
753
+ // color: "red",
754
+ // opacity: 0.2,
755
+ // transparent: true,
756
+ // wireframe: false,
757
+ // })
850
758
  new THREE.MeshBasicMaterial({
851
- color: "red",
852
- opacity: 0.2,
759
+ opacity: 0.5,
853
760
  transparent: true,
854
- wireframe: false
761
+ wireframe: true
855
762
  })
856
763
  );
857
764
  if (this.displayCollider) this.scene.add(this.collider);
@@ -864,7 +771,7 @@ var PlayerController = class {
864
771
  console.log("bvh\u52A0\u8F7D\u6A21\u578B\u6210\u529F", this.collider);
865
772
  }
866
773
  };
867
- function usePlayer() {
774
+ function playerController() {
868
775
  if (!controllerInstance) controllerInstance = new PlayerController();
869
776
  const c = controllerInstance;
870
777
  return {
@@ -873,8 +780,11 @@ function usePlayer() {
873
780
  createBVH: (url = "") => c.createBVH(url),
874
781
  createPlayer: () => c.createPlayer(),
875
782
  reset: (pos) => c.reset(pos),
876
- updatePlayer: (dt) => c.updatePlayer(dt),
877
- destroy: () => c.destroy()
783
+ update: (dt) => c.update(dt),
784
+ destroy: () => c.destroy(),
785
+ displayCollider: c.displayCollider,
786
+ displayPlayer: c.displayPlayer,
787
+ displayVisualizer: c.displayVisualizer
878
788
  };
879
789
  }
880
790
  function onAllEvent() {
@@ -889,6 +799,6 @@ function offAllEvent() {
889
799
  0 && (module.exports = {
890
800
  offAllEvent,
891
801
  onAllEvent,
892
- usePlayer
802
+ playerController
893
803
  });
894
804
  //# sourceMappingURL=index.js.map