spoint 0.1.38 → 0.1.40

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 CHANGED
@@ -1096,6 +1096,13 @@ async function warmupShaders() {
1096
1096
  renderer.compile(scene, camera)
1097
1097
  console.log('[shader] warmup compile done (fallback)')
1098
1098
  }
1099
+ const culled = []
1100
+ scene.traverse(obj => { if (obj.frustumCulled) { culled.push(obj); obj.frustumCulled = false } })
1101
+ renderer.render(scene, camera)
1102
+ await new Promise(r => requestAnimationFrame(r))
1103
+ renderer.render(scene, camera)
1104
+ for (const obj of culled) obj.frustumCulled = true
1105
+ console.log('[shader] GPU upload render done, culled restored:', culled.length)
1099
1106
  }
1100
1107
 
1101
1108
  function checkAllLoaded() {
@@ -1105,8 +1112,8 @@ function checkAllLoaded() {
1105
1112
  if (!firstSnapshotReceived) return
1106
1113
  loadingMgr.setStage('INIT')
1107
1114
  loadingMgr.complete()
1108
- loadingScreen.hide().then(() => warmupShaders()).catch(() => warmupShaders())
1109
1115
  loadingScreenHidden = true
1116
+ warmupShaders().then(() => loadingScreen.hide()).catch(() => loadingScreen.hide())
1110
1117
  }
1111
1118
 
1112
1119
  function initInputHandler() {
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 _fpsRayDirs = [[0,0,0],[0,0,0],[0,0,0],[0,1,0],[0,-1,0]]
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 rayTimer = 0, cachedClipDist = 10, cachedAimPoint = null
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,27 +150,22 @@ 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
- rayTimer += frameDt
154
- const doFpsRaycast = rayTimer >= 0.05
155
- if (doFpsRaycast && rayTargets.length) {
156
- rayTimer = 0
155
+ fpsRayTimer += frameDt
156
+ const doFpsRaycast = fpsRayTimer >= 0.05
157
+ if (doFpsRaycast && envMeshes.length) {
158
+ fpsRayTimer = 0
157
159
  _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) {
160
+ _fpsRayDirs[0][0] = fwdX; _fpsRayDirs[0][1] = fwdY; _fpsRayDirs[0][2] = fwdZ
161
+ _fpsRayDirs[1][0] = rightX; _fpsRayDirs[1][1] = 0; _fpsRayDirs[1][2] = rightZ
162
+ _fpsRayDirs[2][0] = -rightX; _fpsRayDirs[2][1] = 0; _fpsRayDirs[2][2] = -rightZ
163
+ for (const d of _fpsRayDirs) {
166
164
  camDir.set(-d[0], -d[1], -d[2])
167
165
  camRaycaster.set(_fpsRayOrigin, camDir)
168
166
  camRaycaster.far = wallDist
169
167
  camRaycaster.near = 0
170
- const hits = camRaycaster.intersectObjects(rayTargets, true)
168
+ const hits = camRaycaster.intersectObjects(envMeshes, true)
171
169
  for (const hit of hits) {
172
170
  if (localMesh && isDescendant(hit.object, localMesh)) continue
173
171
  const push = wallDist - hit.distance
@@ -182,7 +180,7 @@ export function createCameraController(camera, scene) {
182
180
  }
183
181
  camera.lookAt(camera.position.x + fwdX, camera.position.y + fwdY, camera.position.z + fwdZ)
184
182
  } else {
185
- if (headBone) headBone.scale.set(1, 1, 1)
183
+ if (headBone && headBoneHidden) { headBone.scale.set(1, 1, 1); headBoneHidden = false }
186
184
  camDesired.set(
187
185
  camTarget.x - fwdX * dist + rightX * shoulderOffset,
188
186
  camTarget.y - fwdY * dist + 0.2,
@@ -190,10 +188,10 @@ export function createCameraController(camera, scene) {
190
188
  )
191
189
  camDir.subVectors(camDesired, camTarget).normalize()
192
190
  const fullDist = camTarget.distanceTo(camDesired)
193
- rayTimer += frameDt
194
- const doRaycast = rayTimer >= 0.05
191
+ tpsRayTimer += frameDt
192
+ const doRaycast = tpsRayTimer >= 0.05
195
193
  if (doRaycast) {
196
- rayTimer = 0
194
+ tpsRayTimer = 0
197
195
  camRaycaster.set(camTarget, camDir)
198
196
  camRaycaster.far = fullDist
199
197
  camRaycaster.near = 0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spoint",
3
- "version": "0.1.38",
3
+ "version": "0.1.40",
4
4
  "description": "Physics and netcode SDK for multiplayer game servers",
5
5
  "type": "module",
6
6
  "main": "src/index.js",