spoint 0.1.39 → 0.1.41
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/client/app.js +5 -1
- package/client/camera.js +26 -34
- package/client/index.html +1 -0
- package/package.json +1 -1
package/client/app.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import * as THREE from 'three'
|
|
2
|
+
import { computeBoundsTree, disposeBoundsTree, acceleratedRaycast } from 'three-mesh-bvh'
|
|
3
|
+
THREE.BufferGeometry.prototype.computeBoundsTree = computeBoundsTree
|
|
4
|
+
THREE.BufferGeometry.prototype.disposeBoundsTree = disposeBoundsTree
|
|
5
|
+
THREE.Mesh.prototype.raycast = acceleratedRaycast
|
|
2
6
|
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js'
|
|
3
7
|
import { DRACOLoader } from 'three/addons/loaders/DRACOLoader.js'
|
|
4
8
|
import { VRMLoaderPlugin, VRMUtils } from '@pixiv/three-vrm'
|
|
@@ -953,7 +957,7 @@ function loadEntityModel(entityId, entityState) {
|
|
|
953
957
|
if (c.isMesh) {
|
|
954
958
|
c.castShadow = true
|
|
955
959
|
c.receiveShadow = true
|
|
956
|
-
if (!c.isSkinnedMesh) { c.matrixAutoUpdate = false; colliders.push(c) }
|
|
960
|
+
if (!c.isSkinnedMesh) { c.matrixAutoUpdate = false; c.geometry.computeBoundsTree(); colliders.push(c) }
|
|
957
961
|
if (c.material) { c.material.shadowSide = THREE.DoubleSide; c.material.roughness = 1; c.material.metalness = 0; if (c.material.specularIntensity !== undefined) c.material.specularIntensity = 0 }
|
|
958
962
|
}
|
|
959
963
|
})
|
package/client/camera.js
CHANGED
|
@@ -27,6 +27,7 @@ function isDescendant(obj, ancestor) {
|
|
|
27
27
|
const _boneWorldPos = new THREE.Vector3()
|
|
28
28
|
const _boneForward = new THREE.Vector3()
|
|
29
29
|
const _fpsRayOrigin = new THREE.Vector3()
|
|
30
|
+
const _fpsRayDir = new THREE.Vector3()
|
|
30
31
|
|
|
31
32
|
export function createCameraController(camera, scene) {
|
|
32
33
|
let yaw = 0, pitch = 0, zoomIndex = 2, camInitialized = false
|
|
@@ -35,9 +36,10 @@ export function createCameraController(camera, scene) {
|
|
|
35
36
|
let editCamPos = new THREE.Vector3(0, 5, 10)
|
|
36
37
|
let editCamSpeed = 8
|
|
37
38
|
const envMeshes = []
|
|
38
|
-
let
|
|
39
|
+
let fpsRayTimer = 0, tpsRayTimer = 0, cachedClipDist = 10, cachedAimPoint = null
|
|
39
40
|
let cameraBone = null
|
|
40
41
|
let headBone = null
|
|
42
|
+
let headBoneHidden = false
|
|
41
43
|
let fpsForwardOffset = 0.7
|
|
42
44
|
let fpsHeadDownOffset = 0.2
|
|
43
45
|
camRaycaster.firstHitOnly = true
|
|
@@ -53,10 +55,12 @@ export function createCameraController(camera, scene) {
|
|
|
53
55
|
if (m === 'fps' && headBone) {
|
|
54
56
|
headBone.scale.set(0, 0, 0)
|
|
55
57
|
headBone.position.y -= fpsHeadDownOffset
|
|
58
|
+
headBoneHidden = true
|
|
56
59
|
}
|
|
57
60
|
if (prev === 'fps' && m !== 'fps' && headBone) {
|
|
58
61
|
headBone.scale.set(1, 1, 1)
|
|
59
62
|
headBone.position.y += fpsHeadDownOffset
|
|
63
|
+
headBoneHidden = false
|
|
60
64
|
}
|
|
61
65
|
}
|
|
62
66
|
function getMode() { return mode }
|
|
@@ -139,7 +143,6 @@ export function createCameraController(camera, scene) {
|
|
|
139
143
|
const rightX = -cy, rightZ = sy
|
|
140
144
|
if (dist < 0.01) {
|
|
141
145
|
if (cameraBone && localMesh) {
|
|
142
|
-
localMesh.updateMatrixWorld(true)
|
|
143
146
|
cameraBone.getWorldPosition(_boneWorldPos)
|
|
144
147
|
_boneForward.set(fwdX, 0, fwdZ).normalize()
|
|
145
148
|
camera.position.copy(_boneWorldPos).addScaledVector(_boneForward, fpsForwardOffset)
|
|
@@ -147,42 +150,31 @@ export function createCameraController(camera, scene) {
|
|
|
147
150
|
} else {
|
|
148
151
|
camera.position.copy(camTarget)
|
|
149
152
|
}
|
|
150
|
-
if (headBone) headBone.scale.set(0, 0, 0)
|
|
151
|
-
const rayTargets = envMeshes
|
|
153
|
+
if (headBone && !headBoneHidden) { headBone.scale.set(0, 0, 0); headBoneHidden = true }
|
|
152
154
|
const wallDist = 0.35
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
rayTimer = 0
|
|
155
|
+
fpsRayTimer += frameDt
|
|
156
|
+
if (fpsRayTimer >= 0.05 && envMeshes.length) {
|
|
157
|
+
fpsRayTimer = 0
|
|
157
158
|
_fpsRayOrigin.copy(camera.position)
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
const hits = camRaycaster.intersectObjects(rayTargets, true)
|
|
171
|
-
for (const hit of hits) {
|
|
172
|
-
if (localMesh && isDescendant(hit.object, localMesh)) continue
|
|
173
|
-
const push = wallDist - hit.distance
|
|
174
|
-
if (push > 0) {
|
|
175
|
-
camera.position.x += d[0] * push
|
|
176
|
-
camera.position.y += d[1] * push
|
|
177
|
-
camera.position.z += d[2] * push
|
|
178
|
-
}
|
|
179
|
-
break
|
|
159
|
+
_fpsRayDir.set(-fwdX, -fwdY, -fwdZ)
|
|
160
|
+
camRaycaster.set(_fpsRayOrigin, _fpsRayDir)
|
|
161
|
+
camRaycaster.far = wallDist
|
|
162
|
+
camRaycaster.near = 0
|
|
163
|
+
const hits = camRaycaster.intersectObjects(envMeshes, true)
|
|
164
|
+
for (const hit of hits) {
|
|
165
|
+
if (localMesh && isDescendant(hit.object, localMesh)) continue
|
|
166
|
+
const push = wallDist - hit.distance
|
|
167
|
+
if (push > 0) {
|
|
168
|
+
camera.position.x += fwdX * push
|
|
169
|
+
camera.position.y += fwdY * push
|
|
170
|
+
camera.position.z += fwdZ * push
|
|
180
171
|
}
|
|
172
|
+
break
|
|
181
173
|
}
|
|
182
174
|
}
|
|
183
175
|
camera.lookAt(camera.position.x + fwdX, camera.position.y + fwdY, camera.position.z + fwdZ)
|
|
184
176
|
} else {
|
|
185
|
-
if (headBone) headBone.scale.set(1, 1, 1)
|
|
177
|
+
if (headBone && headBoneHidden) { headBone.scale.set(1, 1, 1); headBoneHidden = false }
|
|
186
178
|
camDesired.set(
|
|
187
179
|
camTarget.x - fwdX * dist + rightX * shoulderOffset,
|
|
188
180
|
camTarget.y - fwdY * dist + 0.2,
|
|
@@ -190,10 +182,10 @@ export function createCameraController(camera, scene) {
|
|
|
190
182
|
)
|
|
191
183
|
camDir.subVectors(camDesired, camTarget).normalize()
|
|
192
184
|
const fullDist = camTarget.distanceTo(camDesired)
|
|
193
|
-
|
|
194
|
-
const doRaycast =
|
|
185
|
+
tpsRayTimer += frameDt
|
|
186
|
+
const doRaycast = tpsRayTimer >= 0.05
|
|
195
187
|
if (doRaycast) {
|
|
196
|
-
|
|
188
|
+
tpsRayTimer = 0
|
|
197
189
|
camRaycaster.set(camTarget, camDir)
|
|
198
190
|
camRaycaster.far = fullDist
|
|
199
191
|
camRaycaster.near = 0
|
package/client/index.html
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"three": "https://esm.sh/three@0.171.0",
|
|
14
14
|
"three/addons/": "https://esm.sh/three@0.171.0/examples/jsm/",
|
|
15
15
|
"@pixiv/three-vrm": "https://esm.sh/@pixiv/three-vrm@3?external=three",
|
|
16
|
+
"three-mesh-bvh": "https://esm.sh/three-mesh-bvh@0.8.4?external=three",
|
|
16
17
|
"webjsx": "https://esm.sh/webjsx@0.0.73",
|
|
17
18
|
"webjsx/jsx-runtime": "https://esm.sh/webjsx@0.0.73/jsx-runtime"
|
|
18
19
|
}
|