Skip to content

Commit

Permalink
Fixed small bugs to reduce start warnings
Browse files Browse the repository at this point in the history
-minor bugfixes
-some defined but unused elements commented out with TODO
  • Loading branch information
Aitolda committed Oct 10, 2024
1 parent faadb15 commit 4f6a595
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
8 changes: 6 additions & 2 deletions src/modules/entity/components/components/SkyboxComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@



import { MeshComponent, DEFAULT_MESH_RENDER_GROUP_ID } from "@Modules/object";
import { MeshComponent } from "@Modules/object";
// TODO: Uncomment and use or remove the following import
// import { DEFAULT_MESH_RENDER_GROUP_ID } from "@Modules/object";
import { Scene, MeshBuilder, StandardMaterial, Texture, CubeTexture, EquiRectangularCubeTexture, BaseTexture, Camera } from "@babylonjs/core";
import { ISkyboxProperty, IVector3Property } from "../../EntityProperties";
import { ISkyboxProperty } from "../../EntityProperties";
// TODO: Uncomment and use or remove the following import
// import { IVector3Property } from "../../EntityProperties";
import { EntityMapper } from "../../package";
import { AssetUrl } from "../../builders/asset";

Expand Down
23 changes: 16 additions & 7 deletions src/modules/scene/ZoneManager.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { Scene, Vector3 } from "@babylonjs/core";
import { Scene, Vector3, AbstractMesh } from "@babylonjs/core";
import { ZoneEntityController } from "../entity/components/controllers/ZoneEntityController";
import Log from "@Modules/debugging/log";

interface ZoneMeshMetadata {
zoneController?: ZoneEntityController;
}

export class ZoneManager {
private _scene: Scene;
private _currentZone: ZoneEntityController | null = null;
private _lastUpdateTime: number = 0;
private _updateInterval: number = 200; // Update every 500ms
private _lastUpdateTime = 0;
private _updateInterval = 200; // Update every 200ms

constructor(scene: Scene) {
this._scene = scene;
Expand All @@ -22,13 +26,16 @@ export class ZoneManager {
this._lastUpdateTime = currentTime;

const camera = this._scene.activeCamera;
if (!camera) return;
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;
this._scene.meshes.forEach((mesh: AbstractMesh) => {
const metadata = mesh.metadata as ZoneMeshMetadata | undefined;
const zoneController = metadata?.zoneController;
if (zoneController && this.isPointInside(cameraPosition, zoneController)) {
newZone = zoneController;
}
Expand All @@ -49,7 +56,9 @@ export class ZoneManager {

private isPointInside(point: Vector3, zoneController: ZoneEntityController): boolean {
const zoneMesh = zoneController.zoneMesh;
if (!zoneMesh) return false;
if (!zoneMesh) {
return false;
}
return zoneMesh.intersectsPoint(point);
}
}
8 changes: 2 additions & 6 deletions src/modules/scene/controllers/sceneController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { ScriptComponent } from "@Modules/script";
import type { VScene } from "@Modules/scene/vscene";
import Log from "@Modules/debugging/log";
import { ZoneManager } from "../ZoneManager";
import { ZoneEntityController } from '../../entity/components/controllers/ZoneEntityController';

const DEFAULT_GRAVITY = 9.81;
const GROUND_DETECTION_LENGTH = 5; // FIXME: This is not a good system for detecting the ground.
Expand Down Expand Up @@ -127,12 +128,7 @@ export class SceneController extends ScriptComponent {
const avatarPosition = avatar.position;
console.log(`Checking zones for avatar at position: ${avatarPosition.toString()}`);
this._scene.meshes.forEach(mesh => {
const zoneController = mesh.getComponent(ZoneEntityController);
if (zoneController && zoneController.isInside(avatarPosition)) {
console.log(`Avatar is inside zone: ${zoneController.zoneEntity.id}`);
// Apply zone properties
this._applyZoneProperties(zoneController.zoneEntity);
}
// Consider adding "is avatar in zone?" check later if needed
});
}
}
Expand Down

0 comments on commit 4f6a595

Please sign in to comment.