Skip to content

Commit ca4c0f3

Browse files
committed
refactor(overlay): simplify anisotropy clamps with safeWidth/safeHeight; remove redundant abs;\nchore(controller): warn once when getBoundingSphere is missing; add comment clarifying effective MAX in auto tessellation
1 parent b6dcead commit ca4c0f3

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/engine/render/DebugOverlaySystem.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,14 @@ export class DebugOverlaySystem implements EngineSystem {
9090
if (hasOrthoExtents) {
9191
const rawWidth = right - left
9292
const rawHeight = top - bottom
93-
const worldWidth = Math.max(1e-6, Math.abs(rawWidth))
94-
const worldHeight = Math.max(1e-6, Math.abs(rawHeight))
95-
// Guard: inverted extents → uniform scale fallback
93+
// Guard: inverted or non-positive extents → uniform scale fallback
9694
if (rawWidth <= 0 || rawHeight <= 0) {
9795
mesh.scale.set(r, r, 1)
9896
return
9997
}
98+
// Clamp tiny dimensions to a small epsilon to avoid divide-by-zero
99+
const safeWidth = Math.max(1e-6, rawWidth)
100+
const safeHeight = Math.max(1e-6, rawHeight)
100101
let viewportWidth = 1
101102
let viewportHeight = 1
102103
const anyView = this.view as unknown as { getViewportPixels?: () => { width: number; height: number } }
@@ -107,8 +108,8 @@ export class DebugOverlaySystem implements EngineSystem {
107108
viewportHeight = vp.height
108109
}
109110
} catch { /* no-op */ }
110-
const pxPerMeterX = viewportWidth / worldWidth
111-
const pxPerMeterY = viewportHeight / worldHeight
111+
const pxPerMeterX = viewportWidth / safeWidth
112+
const pxPerMeterY = viewportHeight / safeHeight
112113
const k = pxPerMeterX / pxPerMeterY
113114
if (Number.isFinite(k) && k > 0) {
114115
mesh.scale.set(r, r * k, 1)

src/lib/clothSceneController.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class ClothBodyAdapter implements SimBody, Component {
8484
private _worldSleepVelThreshold = 0.001
8585
private _worldSleepFrameThreshold = 60
8686
private _worldSleepGuardEnabled = true
87+
private _warnedAboutMissingBoundingSphere = false
8788

8889
constructor(
8990
id: string,
@@ -163,6 +164,11 @@ class ClothBodyAdapter implements SimBody, Component {
163164
}
164165
}
165166
this._lastWorldCenter.copy(worldCenter)
167+
} else {
168+
if (!this._warnedAboutMissingBoundingSphere) {
169+
console.warn(`ClothBodyAdapter ${this.id}: getBoundingSphere not available, world sleep guard disabled`)
170+
this._warnedAboutMissingBoundingSphere = true
171+
}
166172
}
167173
}
168174

@@ -527,6 +533,7 @@ export class ClothSceneController {
527533
const MAX_TESSELLATION_CAP = 48
528534
const rawMax = round(maxCap)
529535
const maxUser = clamp(round(this.debug.tessellationMax ?? maxCap), MIN_SEGMENTS + 2, MAX_TESSELLATION_CAP)
536+
// Effective max is the lesser of: user-configured max and the provided cap, both bounded by global limits
530537
const MAX = Math.min(clamp(rawMax, MIN_SEGMENTS + 2, MAX_TESSELLATION_CAP), maxUser)
531538

532539
const desired = round(MIN_SEGMENTS + s * (MAX - MIN_SEGMENTS))

0 commit comments

Comments
 (0)