Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set the nav mesh visibility when a nav mesh is loaded #6320

Merged
merged 3 commits into from
Oct 13, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does removeDebugMaterial really need to be called here? Does it mean there is a chance that debug material is already added?

}
});
keianhzo marked this conversation as resolved.
Show resolved Hide resolved
if (isEnabled && uniforms) {
navMeshEnterQuery(world).forEach(navEid => {
isEnabled && addDebugMaterial(world, navEid);
Expand Down
Loading