@@ -9,6 +9,13 @@ import { Theme, ThemeTokens } from '/src/engine/theme/index.js';
99import { drawFrame , drawPanel } from '/src/engine/debug/index.js' ;
1010import { World } from '/src/engine/ecs/index.js' ;
1111import { stepWorldPhysics3D } from '/src/engine/systems/index.js' ;
12+ import {
13+ applyPhase16CameraMode ,
14+ createPhase16ViewState ,
15+ drawDepthBackdrop ,
16+ drawPhase16DebugOverlay ,
17+ stepPhase16ViewToggles ,
18+ } from '../shared/threeDWireframe.js' ;
1219
1320const theme = new Theme ( ThemeTokens ) ;
1421const BOX_EDGES = [
@@ -91,7 +98,10 @@ function drawWireBox(renderer, transform3D, size3D, cameraState, viewport, color
9198 if ( ! start || ! end ) {
9299 continue ;
93100 }
94- renderer . drawLine ( start . x , start . y , end . x , end . y , color , 2 ) ;
101+ const edgeDepth = ( start . depth + end . depth ) * 0.5 ;
102+ const depthT = clamp ( ( edgeDepth - 3 ) / 40 , 0 , 1 ) ;
103+ const edgeWidth = 2.2 - depthT * 1.1 ;
104+ renderer . drawLine ( start . x , start . y , end . x , end . y , color , Math . max ( 1 , edgeWidth ) ) ;
95105 }
96106}
97107
@@ -120,6 +130,7 @@ export default class CubeExplorer3DScene extends Scene {
120130 depth : 22 ,
121131 } ;
122132 this . lastPhysicsSummary = { movedEntities : 0 , collisionCount : 0 } ;
133+ this . viewState = createPhase16ViewState ( ) ;
123134
124135 this . playerId = this . world . createEntity ( ) ;
125136 this . world . addComponent ( this . playerId , 'transform3D' , {
@@ -175,21 +186,29 @@ export default class CubeExplorer3DScene extends Scene {
175186 const cameraZ = playerTransform . z - Math . cos ( this . cameraYaw ) * orbitDistance ;
176187 const cameraY = playerTransform . y + 4.8 ;
177188
178- this . camera3D . setPosition ( {
179- x : cameraX ,
180- y : cameraY ,
181- z : cameraZ ,
182- } ) ;
183- this . camera3D . setRotation ( {
184- x : this . cameraPitch ,
185- y : this . cameraYaw ,
186- z : 0 ,
189+ const basePose = {
190+ position : {
191+ x : cameraX ,
192+ y : cameraY ,
193+ z : cameraZ ,
194+ } ,
195+ rotation : {
196+ x : this . cameraPitch ,
197+ y : this . cameraYaw ,
198+ z : 0 ,
199+ } ,
200+ } ;
201+ applyPhase16CameraMode ( this . camera3D , this . viewState , basePose , {
202+ x : playerTransform . x + 0.8 ,
203+ y : playerTransform . y + 0.8 ,
204+ z : playerTransform . z + 0.8 ,
187205 } ) ;
188206 }
189207
190208 step3DPhysics ( dt , engine ) {
191209 const velocity = this . world . requireComponent ( this . playerId , 'velocity3D' ) ;
192210 const input = engine . input ;
211+ stepPhase16ViewToggles ( this . viewState , input ) ;
193212
194213 velocity . x = 0 ;
195214 velocity . y = 0 ;
@@ -217,7 +236,7 @@ export default class CubeExplorer3DScene extends Scene {
217236 drawFrame ( renderer , theme , [
218237 'Sample 1601 - 3D Cube Explorer' ,
219238 'Minimal 3D movement + AABB collision using an isolated physics loop' ,
220- 'Move: W A S D | Vertical: R/F | Camera orbit: Arrow keys' ,
239+ 'Move: W A S D | Vertical: R/F | Camera orbit: Arrow keys | Camera: C | Debug: V ' ,
221240 'Goal: navigate around blocking boxes while remaining inside world bounds' ,
222241 ] ) ;
223242
@@ -229,6 +248,7 @@ export default class CubeExplorer3DScene extends Scene {
229248 '#d8d5ff' ,
230249 2 ,
231250 ) ;
251+ drawDepthBackdrop ( renderer , this . viewport ) ;
232252
233253 const cameraState = this . camera3D ?. getState ?. ( ) ?? {
234254 position : { x : 0 , y : 3 , z : - 8 } ,
@@ -277,12 +297,17 @@ export default class CubeExplorer3DScene extends Scene {
277297 } ) ;
278298
279299 const player = this . world . requireComponent ( this . playerId , 'transform3D' ) ;
280- drawPanel ( renderer , 620 , 34 , 300 , 126 , '3D Runtime' , [
300+ drawPanel ( renderer , 620 , 34 , 300 , 156 , '3D Runtime' , [
281301 `Cube: x=${ player . x . toFixed ( 2 ) } y=${ player . y . toFixed ( 2 ) } z=${ player . z . toFixed ( 2 ) } ` ,
282302 `Camera yaw: ${ this . cameraYaw . toFixed ( 2 ) } pitch: ${ this . cameraPitch . toFixed ( 2 ) } ` ,
283303 `Moved entities: ${ this . lastPhysicsSummary . movedEntities } ` ,
284304 `Resolved collisions: ${ this . lastPhysicsSummary . collisionCount } ` ,
285305 'Physics loop: stepWorldPhysics3D (MovementSystem + AABB)' ,
286306 ] ) ;
307+
308+ drawPhase16DebugOverlay ( renderer , this . viewport , this . viewState , [
309+ `Yaw: ${ this . cameraYaw . toFixed ( 2 ) } | Pitch: ${ this . cameraPitch . toFixed ( 2 ) } ` ,
310+ `Collisions/frame: ${ this . lastPhysicsSummary . collisionCount } ` ,
311+ ] ) ;
287312 }
288313}
0 commit comments