spoint 0.1.25 → 0.1.27
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 +2 -2
- package/client/camera.js +41 -31
- package/package.json +1 -1
package/client/app.js
CHANGED
|
@@ -938,8 +938,8 @@ function loadEntityModel(entityId, entityState) {
|
|
|
938
938
|
scene.add(model)
|
|
939
939
|
entityMeshes.set(entityId, model)
|
|
940
940
|
const colliders = []
|
|
941
|
-
model.traverse(c => { if (c.isMesh && c.
|
|
942
|
-
|
|
941
|
+
model.traverse(c => { if (c.isMesh && !c.isSkinnedMesh) colliders.push(c) })
|
|
942
|
+
cam.setEnvironment(colliders)
|
|
943
943
|
scene.remove(ground)
|
|
944
944
|
fitShadowFrustum()
|
|
945
945
|
pendingLoads.delete(entityId)
|
package/client/camera.js
CHANGED
|
@@ -26,6 +26,7 @@ function isDescendant(obj, ancestor) {
|
|
|
26
26
|
|
|
27
27
|
const _boneWorldPos = new THREE.Vector3()
|
|
28
28
|
const _boneForward = new THREE.Vector3()
|
|
29
|
+
const _fpsRayOrigin = new THREE.Vector3()
|
|
29
30
|
|
|
30
31
|
export function createCameraController(camera, scene) {
|
|
31
32
|
let yaw = 0, pitch = 0, zoomIndex = 2, camInitialized = false
|
|
@@ -147,31 +148,36 @@ export function createCameraController(camera, scene) {
|
|
|
147
148
|
camera.position.copy(camTarget)
|
|
148
149
|
}
|
|
149
150
|
if (headBone) headBone.scale.set(0, 0, 0)
|
|
150
|
-
const rayTargets = envMeshes
|
|
151
|
+
const rayTargets = envMeshes
|
|
151
152
|
const wallDist = 0.35
|
|
152
|
-
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
153
|
+
rayTimer += frameDt
|
|
154
|
+
const doFpsRaycast = rayTimer >= 0.05
|
|
155
|
+
if (doFpsRaycast && rayTargets.length) {
|
|
156
|
+
rayTimer = 0
|
|
157
|
+
_fpsRayOrigin.copy(camera.position)
|
|
158
|
+
const rayDirs = [
|
|
159
|
+
[fwdX, fwdY, fwdZ],
|
|
160
|
+
[rightX, 0, rightZ],
|
|
161
|
+
[-rightX, 0, -rightZ],
|
|
162
|
+
[0, 1, 0],
|
|
163
|
+
[0, -1, 0]
|
|
164
|
+
]
|
|
165
|
+
for (const d of rayDirs) {
|
|
166
|
+
camDir.set(-d[0], -d[1], -d[2])
|
|
167
|
+
camRaycaster.set(_fpsRayOrigin, camDir)
|
|
168
|
+
camRaycaster.far = wallDist
|
|
169
|
+
camRaycaster.near = 0
|
|
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
|
|
173
180
|
}
|
|
174
|
-
break
|
|
175
181
|
}
|
|
176
182
|
}
|
|
177
183
|
camera.lookAt(camera.position.x + fwdX, camera.position.y + fwdY, camera.position.z + fwdZ)
|
|
@@ -191,13 +197,17 @@ export function createCameraController(camera, scene) {
|
|
|
191
197
|
camRaycaster.set(camTarget, camDir)
|
|
192
198
|
camRaycaster.far = fullDist
|
|
193
199
|
camRaycaster.near = 0
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
200
|
+
if (envMeshes.length) {
|
|
201
|
+
const hits = camRaycaster.intersectObjects(envMeshes, true)
|
|
202
|
+
cachedClipDist = fullDist
|
|
203
|
+
for (const hit of hits) {
|
|
204
|
+
if (localMesh && isDescendant(hit.object, localMesh)) continue
|
|
205
|
+
if (hit.distance < cachedClipDist) cachedClipDist = hit.distance - 0.2
|
|
206
|
+
}
|
|
207
|
+
if (cachedClipDist < 0.3) cachedClipDist = 0.3
|
|
208
|
+
} else {
|
|
209
|
+
cachedClipDist = fullDist
|
|
199
210
|
}
|
|
200
|
-
if (cachedClipDist < 0.3) cachedClipDist = 0.3
|
|
201
211
|
}
|
|
202
212
|
const clippedDist = Math.min(cachedClipDist, fullDist)
|
|
203
213
|
camDesired.set(
|
|
@@ -212,11 +222,11 @@ export function createCameraController(camera, scene) {
|
|
|
212
222
|
camera.position.lerp(camDesired, 1.0 - Math.exp(-speed * frameDt))
|
|
213
223
|
}
|
|
214
224
|
aimDir.set(fwdX, fwdY, fwdZ)
|
|
215
|
-
if (doRaycast) {
|
|
225
|
+
if (doRaycast && envMeshes.length) {
|
|
216
226
|
aimRaycaster.set(camera.position, aimDir)
|
|
217
227
|
aimRaycaster.far = 500
|
|
218
228
|
aimRaycaster.near = 0.5
|
|
219
|
-
const aimHits = aimRaycaster.intersectObjects(envMeshes
|
|
229
|
+
const aimHits = aimRaycaster.intersectObjects(envMeshes, true)
|
|
220
230
|
cachedAimPoint = null
|
|
221
231
|
for (const ah of aimHits) {
|
|
222
232
|
if (localMesh && isDescendant(ah.object, localMesh)) continue
|