1- import { BackSide , Raycaster , Vector2 , Vector3 } from 'three'
1+ import { Raycaster , Vector2 , Vector3 } from 'three'
22import { SoundManager } from '../../audio/SoundManager'
33import { DeselectAll , SelectionChanged , UpdateRadarSurface , UpdateRadarTerrain } from '../../event/LocalEvents'
44import { CavernDiscovered , JobCreateEvent , OreFoundEvent , WorldLocationEvent } from '../../event/WorldEvents'
@@ -13,7 +13,7 @@ import { DrillJob } from '../model/job/surface/DrillJob'
1313import { ReinforceJob } from '../model/job/surface/ReinforceJob'
1414import { GameEntity } from '../ECS'
1515import { SurfaceVertex } from './SurfaceGeometry'
16- import { SurfaceMesh } from './SurfaceMesh'
16+ import { RoofMesh , SurfaceMesh } from './SurfaceMesh'
1717import { SurfaceType } from './SurfaceType'
1818import { Terrain } from './Terrain'
1919import { WALL_TYPE , WallType } from './WallType'
@@ -34,6 +34,8 @@ import { PRNG } from '../factory/PRNG'
3434import { GameState } from '../model/GameState'
3535import { CompleteSurfaceJob } from '../model/job/surface/CompleteSurfaceJob'
3636import { MaterialEntity } from '../model/material/MaterialEntity'
37+ import { ResourceManager } from '../../resource/ResourceManager'
38+ import { SaveGameManager } from '../../resource/SaveGameManager'
3739
3840export class Surface {
3941 readonly worldMgr : WorldManager
@@ -53,7 +55,7 @@ export class Surface {
5355 drillProgress : number = 0
5456
5557 readonly mesh : SurfaceMesh
56- readonly roofMesh : SurfaceMesh
58+ readonly roofMesh : RoofMesh
5759 wallType : WallType = WALL_TYPE . floor
5860 needsMeshUpdate : boolean = false
5961
@@ -83,15 +85,10 @@ export class Surface {
8385 this . rubblePositions = [ this . getRandomPosition ( ) , this . getRandomPosition ( ) , this . getRandomPosition ( ) , this . getRandomPosition ( ) ]
8486 break
8587 }
86- // TODO Use pro meshes for high wall details in FPV
87- // const proMesh = ResourceManager.getLwoModel(this.terrain.textureSet.meshBasename + '01b.lwo')
88- // proMesh.position.copy(this.mesh.position)
89- // proMesh.scale.setScalar(1 / TILESIZE)
90- // this.terrain.floorGroup.add(proMesh)
9188 this . mesh = new SurfaceMesh ( x , y , { selectable : this , surface : this } )
92- this . roofMesh = new SurfaceMesh ( x , y , { } )
93- this . roofMesh . material . side = BackSide
94- this . roofMesh . position . y = 3
89+ this . mesh . setProMeshEnabled ( SaveGameManager . preferences . wallDetails )
90+ const roofTexture = ResourceManager . getSurfaceTexture ( this . terrain . levelConf . roofTexture , 0 ) ?? null // TODO Move to config handling
91+ this . roofMesh = new RoofMesh ( x , y , roofTexture )
9592 }
9693
9794 private updateObjectName ( ) {
@@ -143,7 +140,7 @@ export class Surface {
143140 case SurfaceType . LAVA5 :
144141 // fallthrough
145142 case SurfaceType . WATER :
146- this . worldMgr . ecs . addComponent ( this . entity , new FluidSurfaceComponent ( this . x , this . y , this . mesh . geometry . attributes . uv ) )
143+ this . worldMgr . ecs . addComponent ( this . entity , new FluidSurfaceComponent ( this . x , this . y , this . mesh . lowMesh . geometry . attributes . uv ) )
147144 break
148145 case SurfaceType . HIDDEN_CAVERN :
149146 this . surfaceType = SurfaceType . GROUND
@@ -351,7 +348,7 @@ export class Surface {
351348 this . terrain . pathFinder . updateSurface ( this )
352349 }
353350
354- private getVertex ( x : number , y : number , s1 : Surface , s2 : Surface , s3 : Surface ) : SurfaceVertex {
351+ getVertex ( x : number , y : number , s1 : Surface , s2 : Surface , s3 : Surface ) : SurfaceVertex {
355352 const high = [ this , s1 , s2 , s3 ] . some ( ( s ) => ! s . discovered ) || ! [ this , s1 , s2 , s3 ] . some ( ( s ) => s . surfaceType . floor )
356353 const minSeamProgress = Math . min ( this . getSeamProgress ( ) , s1 . getSeamProgress ( ) , s2 . getSeamProgress ( ) , s3 . getSeamProgress ( ) )
357354 const offset = this . terrain . getHeightOffset ( x , y )
@@ -365,9 +362,9 @@ export class Surface {
365362 private updateWallType ( topLeft : SurfaceVertex , topRight : SurfaceVertex , bottomRight : SurfaceVertex , bottomLeft : SurfaceVertex ) {
366363 let wallType : WallType = Surface . getWallType ( topLeft . high , topRight . high , bottomRight . high , bottomLeft . high )
367364 if ( wallType === WALL_TYPE . wall && topLeft . high === bottomRight . high ) wallType = WALL_TYPE . weirdCrevice
368- this . wallType = wallType
365+ this . wallType = wallType // TODO Update wall type only when necessary
369366 this . mesh . setHeights ( wallType , topLeft , topRight , bottomRight , bottomLeft )
370- this . roofMesh . setHeights ( wallType , topLeft . flipY ( ) , topRight . flipY ( ) , bottomRight . flipY ( ) , bottomLeft . flipY ( ) )
367+ this . roofMesh . setHeights ( wallType , topLeft , topRight , bottomRight , bottomLeft )
371368 if ( this . wallType !== WALL_TYPE . wall ) this . cancelReinforceJobs ( )
372369 if ( this . wallType < WALL_TYPE . wall ) this . worldMgr . ecs . removeComponent ( this . entity , EmergeComponent )
373370 }
@@ -426,8 +423,9 @@ export class Surface {
426423 suffix = this . surfaceType . shaping ? '0' + this . surfaceType . matIndex : this . surfaceType . matIndex
427424 }
428425 const textureFilepath = this . terrain . levelConf . textureBasename + suffix + '.bmp'
429- this . mesh . setTexture ( textureFilepath , rotation )
430- this . roofMesh . setTexture ( this . terrain . levelConf . roofTexture , rotation )
426+ const proMeshSuffix = suffix . startsWith ( '1' ) ? '10' : suffix
427+ const proMeshFilepath = ( this . terrain . levelConf . meshBasename + proMeshSuffix ) . toLowerCase ( )
428+ this . mesh . setTexture ( textureFilepath , rotation , proMeshFilepath )
431429 }
432430
433431 private determinePowerPathTextureNameSuffixAndRotation ( rotation : number , suffix : string ) {
@@ -480,7 +478,7 @@ export class Surface {
480478 select ( ) : boolean {
481479 if ( ! this . isSelectable ( ) ) return false
482480 this . selected = true
483- this . mesh . setHighlightColor ( 0x6060a0 )
481+ this . setHighlightColor ( 0x6060a0 )
484482 if ( this . surfaceType . floor ) SoundManager . playSfxSound ( 'SFX_Floor' )
485483 else if ( this . surfaceType . shaping ) SoundManager . playSfxSound ( 'SFX_Wall' )
486484 if ( DEV_MODE ) console . log ( `Surface selected ${ this . x } /${ this . y } ` , this )
@@ -502,7 +500,11 @@ export class Surface {
502500 } else if ( this . drillJob ) {
503501 color = 0xa0a0a0
504502 }
505- this . mesh . setHighlightColor ( color )
503+ this . setHighlightColor ( color )
504+ }
505+
506+ setHighlightColor ( hex : number ) {
507+ this . mesh . setHighlightColor ( hex )
506508 }
507509
508510 hasRubble ( ) : boolean {
@@ -595,7 +597,7 @@ export class Surface {
595597 const wasPath = this . surfaceType === SurfaceType . POWER_PATH || this . surfaceType === SurfaceType . POWER_PATH_BUILDING
596598 this . surfaceType = surfaceType
597599 if ( this . surfaceType === SurfaceType . WATER || this . surfaceType === SurfaceType . LAVA5 ) {
598- this . worldMgr . ecs . addComponent ( this . entity , new FluidSurfaceComponent ( this . x , this . y , this . mesh . geometry . attributes . uv ) )
600+ this . worldMgr . ecs . addComponent ( this . entity , new FluidSurfaceComponent ( this . x , this . y , this . mesh . lowMesh . geometry . attributes . uv ) )
599601 } else {
600602 this . worldMgr . ecs . removeComponent ( this . entity , FluidSurfaceComponent )
601603 }
0 commit comments