-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Zone now detects when MainCamera is within it's bounds
-detections for when a camera exists or enters a zone.
- Loading branch information
Showing
3 changed files
with
68 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { Scene, Vector3 } from "@babylonjs/core"; | ||
import { ZoneEntityController } from "../entity/components/controllers/ZoneEntityController"; | ||
import Log from "@Modules/debugging/log"; | ||
|
||
export class ZoneManager { | ||
private _scene: Scene; | ||
private _currentZone: ZoneEntityController | null = null; | ||
|
||
constructor(scene: Scene) { | ||
this._scene = scene; | ||
} | ||
|
||
public update(): void { | ||
const camera = this._scene.activeCamera; | ||
if (!camera) return; | ||
|
||
const cameraPosition = camera.position; | ||
let newZone: ZoneEntityController | null = null; | ||
|
||
this._scene.meshes.forEach(mesh => { | ||
const zoneController = mesh.metadata?.zoneController as ZoneEntityController | undefined; | ||
if (zoneController && this.isPointInside(cameraPosition, zoneController)) { | ||
newZone = zoneController; | ||
} | ||
}); | ||
|
||
if (newZone !== this._currentZone) { | ||
if (this._currentZone) { | ||
Log.debug(Log.types.ENTITIES, `Exiting zone: ${this._currentZone.id}`); | ||
} | ||
if (newZone) { | ||
Log.debug(Log.types.ENTITIES, `Entering zone: ${newZone.id}`); | ||
} else { | ||
Log.debug(Log.types.ENTITIES, "Not in any zone"); | ||
} | ||
this._currentZone = newZone; | ||
} | ||
} | ||
|
||
private isPointInside(point: Vector3, zoneController: ZoneEntityController): boolean { | ||
const zoneMesh = zoneController.zoneMesh; | ||
if (!zoneMesh) return false; | ||
return zoneMesh.intersectsPoint(point); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters