Skip to content

Commit

Permalink
Initial support for multiple zones added
Browse files Browse the repository at this point in the history
-you can now have multiple zones that will switch skybox backgrounds and settings depending on which zone's bounding box/shape the camera within at the time.
  • Loading branch information
Aitolda committed Oct 10, 2024
1 parent 8ab678f commit 768f762
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/modules/entity/builders/ZoneEntityBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,15 @@ export class ZoneEntityBuilder {
const controller = new ZoneEntityController(zoneEntity);
gameObject.addComponent(controller);

// Explicitly create the zone mesh after adding the controller
controller.createZoneMesh();
// Log the zone entity properties before creating the mesh
console.log(`Building zone entity ${zoneEntity.id}`);
console.log(`Shape type: ${zoneEntity.shapeType}`);
console.log(`Compound shape URL: ${zoneEntity.compoundShapeURL}`);

// Delay the mesh creation to ensure all properties are set
setTimeout(() => {
controller.createZoneMesh();
}, 0);

console.log(`Zone entity built for zone ${zoneEntity.id}`);
console.log(`GameObject name: ${gameObject.name}`);
Expand Down
26 changes: 26 additions & 0 deletions src/modules/entity/components/controllers/ZoneEntityController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,4 +419,30 @@ export class ZoneEntityController extends EntityController {
public get zoneMesh(): Mesh | null {
return this._zoneMesh;
}

public activateZoneSettings(): void {
this._updateSkybox();
this.updateAmbientLight();
this.updateKeyLight();
this.updateHaze();
this._updateUserData();
console.log(`Activated settings for zone ${this._zoneEntity.id}`);
}

public deactivateZoneSettings(): void {
if (this._skybox) {
this._skybox.enable = false;
}
if (this._ambientLight) {
this._ambientLight.light?.setEnabled(false);
}
if (this._keyLight) {
this._keyLight.enable = false;
}
if (this._haze) {
this._haze.enable = false;
}
// Revert any user data changes if necessary
console.log(`Deactivated settings for zone ${this._zoneEntity.id}`);
}
}
5 changes: 4 additions & 1 deletion src/modules/scene/ZoneManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export class ZoneManager {
private _scene: Scene;
private _currentZone: ZoneEntityController | null = null;
private _lastUpdateTime: number = 0;
private _updateInterval: number = 200; // Update every 500ms
private _updateInterval: number = 200; // Update every 200ms

constructor(scene: Scene) {
this._scene = scene;
Expand Down Expand Up @@ -37,11 +37,14 @@ export class ZoneManager {
if (newZone !== this._currentZone) {
if (this._currentZone) {
Log.debug(Log.types.ENTITIES, `Exiting zone: ${this._currentZone.id}`);
this._currentZone.deactivateZoneSettings();
}
if (newZone) {
Log.debug(Log.types.ENTITIES, `Entering zone: ${newZone.id}`);
newZone.activateZoneSettings();
} else {
Log.debug(Log.types.ENTITIES, "Not in any zone");
// Optionally, activate default scene settings here
}
this._currentZone = newZone;
}
Expand Down

0 comments on commit 768f762

Please sign in to comment.