three-player-controller 0.3.9 → 0.4.0
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 +11 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +24 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +24 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1000,7 +1000,7 @@ var PlayerController = class {
|
|
|
1000
1000
|
}
|
|
1001
1001
|
const w = window.innerWidth;
|
|
1002
1002
|
const h = window.innerHeight;
|
|
1003
|
-
this.camera.setViewOffset(w, h,
|
|
1003
|
+
this.camera.setViewOffset(w, h, w * 0.15, 0, w, h);
|
|
1004
1004
|
}
|
|
1005
1005
|
// 初始化加载器
|
|
1006
1006
|
async initLoader() {
|
|
@@ -1081,7 +1081,7 @@ var PlayerController = class {
|
|
|
1081
1081
|
this.personActions.get("idle")?.setEffectiveWeight(1);
|
|
1082
1082
|
this.personActions.get("idle")?.play();
|
|
1083
1083
|
this.actionState = this.personActions.get("idle");
|
|
1084
|
-
this.
|
|
1084
|
+
this.personMixerFinishedCb = (ev) => {
|
|
1085
1085
|
const done = ev.action;
|
|
1086
1086
|
if (done === this.personActions?.get("jumping")) {
|
|
1087
1087
|
if (this.fwdPressed) {
|
|
@@ -1099,7 +1099,8 @@ var PlayerController = class {
|
|
|
1099
1099
|
this.playPersonAnimationByName("idle");
|
|
1100
1100
|
}
|
|
1101
1101
|
if (done === this.personActions?.get("enterCar")) this.onEnterCarAnimFinished();
|
|
1102
|
-
}
|
|
1102
|
+
};
|
|
1103
|
+
this.personMixer.addEventListener("finished", this.personMixerFinishedCb);
|
|
1103
1104
|
this.personMixer.update(0);
|
|
1104
1105
|
this.person.updateMatrixWorld(true);
|
|
1105
1106
|
const { size } = this.getBbox(this.person);
|
|
@@ -1154,6 +1155,10 @@ var PlayerController = class {
|
|
|
1154
1155
|
this.personHead = null;
|
|
1155
1156
|
}
|
|
1156
1157
|
if (this.personMixer) {
|
|
1158
|
+
if (this.personMixerFinishedCb) {
|
|
1159
|
+
this.personMixer.removeEventListener("finished", this.personMixerFinishedCb);
|
|
1160
|
+
this.personMixerFinishedCb = void 0;
|
|
1161
|
+
}
|
|
1157
1162
|
this.personMixer.stopAllAction();
|
|
1158
1163
|
this.personMixer.uncacheRoot(this.personMixer.getRoot());
|
|
1159
1164
|
this.personMixer = void 0;
|
|
@@ -1608,7 +1613,7 @@ var PlayerController = class {
|
|
|
1608
1613
|
return;
|
|
1609
1614
|
}
|
|
1610
1615
|
merged.boundsTree = new MeshBVH(merged, { maxDepth: 100 });
|
|
1611
|
-
this.collider = new THREE4.Mesh(merged, new THREE4.MeshBasicMaterial({ opacity: 0.5, transparent: true, wireframe: true, depthTest: true }));
|
|
1616
|
+
this.collider = new THREE4.Mesh(merged, new THREE4.MeshBasicMaterial({ opacity: 0.5, transparent: true, wireframe: true, depthTest: true, side: THREE4.DoubleSide }));
|
|
1612
1617
|
if (this.displayCollider) this.scene.add(this.collider);
|
|
1613
1618
|
if (this.displayVisualizer) {
|
|
1614
1619
|
if (this.visualizer) this.scene.remove(this.visualizer);
|
|
@@ -1646,7 +1651,7 @@ var PlayerController = class {
|
|
|
1646
1651
|
return;
|
|
1647
1652
|
}
|
|
1648
1653
|
merged.boundsTree = new MeshBVH(merged);
|
|
1649
|
-
this.dynamicCollider = new THREE4.Mesh(merged, new THREE4.MeshBasicMaterial({ opacity: 0.5, transparent: true, wireframe: true, depthTest: true }));
|
|
1654
|
+
this.dynamicCollider = new THREE4.Mesh(merged, new THREE4.MeshBasicMaterial({ opacity: 0.5, transparent: true, wireframe: true, depthTest: true, side: THREE4.DoubleSide }));
|
|
1650
1655
|
if (this.displayCollider) this.scene.add(this.dynamicCollider);
|
|
1651
1656
|
}
|
|
1652
1657
|
// ==================== 控制器过渡 ====================
|
|
@@ -1881,16 +1886,17 @@ var PlayerController = class {
|
|
|
1881
1886
|
if (!this.spacePressed) {
|
|
1882
1887
|
this.playerVelocity.set(0, 0, 0);
|
|
1883
1888
|
this.playerIsOnGround = true;
|
|
1884
|
-
this.player.position.y = hits[0].point.y + h;
|
|
1889
|
+
this.player.position.y = THREE4.MathUtils.lerp(this.player.position.y, hits[0].point.y + h, Math.min(1, 15 * delta));
|
|
1885
1890
|
}
|
|
1886
1891
|
} else if (dist >= minH) {
|
|
1887
1892
|
this.playerVelocity.set(0, 0, 0);
|
|
1888
1893
|
this.playerIsOnGround = true;
|
|
1889
1894
|
this.player.position.y = hits[0].point.y + h;
|
|
1890
1895
|
} else {
|
|
1896
|
+
const targetY = hits[0].point.y + h;
|
|
1891
1897
|
this.playerVelocity.set(0, 0, 0);
|
|
1892
|
-
this.player.position.y = hits[0].point.y + h;
|
|
1893
1898
|
this.playerIsOnGround = true;
|
|
1899
|
+
this.player.position.y = THREE4.MathUtils.lerp(this.player.position.y, targetY, Math.min(1, 15 * delta));
|
|
1894
1900
|
}
|
|
1895
1901
|
}
|
|
1896
1902
|
this.player.updateMatrixWorld();
|
|
@@ -1911,7 +1917,14 @@ var PlayerController = class {
|
|
|
1911
1917
|
const distance = tri.closestPointToSegment(this.tempSegment, this.tempVector, this.tempVector2);
|
|
1912
1918
|
if (distance < capsuleInfo.radius) {
|
|
1913
1919
|
const normal = tri.getNormal(new THREE4.Vector3());
|
|
1914
|
-
if (normal.y > 0.5
|
|
1920
|
+
if (!this.isFlying && Math.abs(normal.y) > 0.5) return;
|
|
1921
|
+
if (!this.isFlying && Math.abs(normal.y) <= 0.5) {
|
|
1922
|
+
const e = this.collider.matrixWorld.elements;
|
|
1923
|
+
const contactWorldY = e[1] * this.tempVector.x + e[5] * this.tempVector.y + e[9] * this.tempVector.z + e[13];
|
|
1924
|
+
const s = this.playerModel.scale;
|
|
1925
|
+
const feetY = this.player.position.y - this.playerCapsuleHeight * s * 0.75;
|
|
1926
|
+
if (contactWorldY < feetY + this.playerCapsuleHeight * s * 0.25) return;
|
|
1927
|
+
}
|
|
1915
1928
|
const dir = this.tempVector2.sub(this.tempVector).normalize();
|
|
1916
1929
|
const depth = capsuleInfo.radius - distance;
|
|
1917
1930
|
this.tempSegment.start.addScaledVector(dir, depth);
|
|
@@ -2006,13 +2019,14 @@ var PlayerController = class {
|
|
|
2006
2019
|
}
|
|
2007
2020
|
// 屏幕中心射线
|
|
2008
2021
|
getCenterScreenRaycastHit() {
|
|
2022
|
+
if (!this.collider) return void 0;
|
|
2009
2023
|
this.camera.updateMatrixWorld();
|
|
2010
2024
|
this.centerRay.setFromCamera(this.centerMouse, this.camera);
|
|
2011
2025
|
return this.centerRay.intersectObject(this.collider, false)[0];
|
|
2012
2026
|
}
|
|
2013
2027
|
// 获取当前人物动画名称
|
|
2014
2028
|
getCurrentPersonAnimationName() {
|
|
2015
|
-
return this.actionState
|
|
2029
|
+
return this.actionState?.getClip()?.name ?? null;
|
|
2016
2030
|
}
|
|
2017
2031
|
// 更新动画混合器
|
|
2018
2032
|
updateMixers(delta) {
|
|
@@ -2179,6 +2193,7 @@ var PlayerController = class {
|
|
|
2179
2193
|
for (const v of this.vehicles) {
|
|
2180
2194
|
this.scene.remove(v.vehicleGroup);
|
|
2181
2195
|
v.pathPlanner?.dispose();
|
|
2196
|
+
v.vehicleController?.destroy?.();
|
|
2182
2197
|
}
|
|
2183
2198
|
this.vehicles = [];
|
|
2184
2199
|
this.activeVehicle = null;
|