Skip to content

Commit

Permalink
Set the nav mesh visibility when a nav mesh is loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo committed Oct 12, 2023
1 parent 484a3fb commit 80ae75d
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/bit-systems/audio-debug-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ getScene().then(() => {
});

const addDebugMaterial = (world: HubsWorld, navEid: number) => {
if (nav2mat.has(navEid)) return;
const obj = world.eid2obj.get(navEid);
if (obj) {
const navMesh = obj as Mesh;
navMesh.visible = isEnabled;
if (nav2mat.has(navEid)) return;
nav2mat.set(navEid, navMesh.material);
navMesh.material = debugMaterial!;
navMesh.material.needsUpdate = true;
Expand All @@ -130,11 +130,11 @@ const addDebugMaterial = (world: HubsWorld, navEid: number) => {
};

const removeDebugMaterial = (world: HubsWorld, navEid: number) => {
if (!nav2mat.has(navEid)) return;
const obj = world.eid2obj.get(navEid);
if (obj) {
const navMesh = obj as Mesh;
navMesh.visible = false;
if (!nav2mat.has(navEid)) return;
navMesh.material = nav2mat.get(navEid)!;
nav2mat.delete(navEid);
(navMesh.material as Material).needsUpdate = true;
Expand All @@ -154,6 +154,13 @@ export function audioDebugSystem(world: HubsWorld) {
navMeshExitQuery(world).forEach(navEid => {
removeDebugMaterial(world, navEid);
});
navMeshEnterQuery(world).forEach(navEid => {
if (isEnabled) {
addDebugMaterial(world, navEid);
} else {
removeDebugMaterial(world, navEid);
}
});
if (isEnabled && uniforms) {
navMeshEnterQuery(world).forEach(navEid => {
isEnabled && addDebugMaterial(world, navEid);
Expand Down

0 comments on commit 80ae75d

Please sign in to comment.