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

Load nav-mesh only once #6326

Merged
merged 1 commit into from
Oct 19, 2023
Merged

Load nav-mesh only once #6326

merged 1 commit into from
Oct 19, 2023

Conversation

keianhzo
Copy link
Contributor

Addresses #6316 (comment)

In AFrame the nav mesh load was happening only once for the first found nav-mesh component:
https://github.com/mozilla/hubs/blob/f15d84aa019c0b2dfa34be8c91c9b82a6bad1c58/src/systems/environment-system.js#L137-L140
For the new loader we were loading the nav-mesh while traversing the scene so if multiple nav meshes were found we were effectively using the last traversed one.

This PR changes that behavior so we only process the nav-mesh once.

if (navMeshEid) {
inflatePhysicsShape(world, navMeshEid, {
if (isHighDensity && navMesh) {
inflatePhysicsShape(world, navMesh.eid!, {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

Can't navMeshEid be used here instead of navMesh and navMesh.eid!?

      if (isHighDensity && navMeshEid) {
        inflatePhysicsShape(world, navMeshEid, {

If it can be, navMesh can be scoped into the if block above.

    if (navMeshEid) {
      const navMeshObj = world.eid2obj.get(navMeshEid);
      // TODO the "as any" here is because of incorrect type definition for getObjectByProperty. It was fixed in r145
      const navMesh = navMeshObj?.getObjectByProperty("isMesh", true as any) as Mesh;
      // Some older scenes have the nav-mesh component as an ancestor of the mesh itself
      if (navMesh !== navMeshObj) {
        console.warn("The `nav-mesh` component should be placed directly on a mesh.");
      }
      sceneEl.systems.nav.loadMesh(navMesh, "character");
    }

@takahirox
Copy link
Contributor

I think it's ok to load nav mesh only once per a scene, especially if the behavior is same as the one with the A-Frame based implementation.

I want to make clear one thing. Is having multiple nav meshes in a scene valid? If invalid, the blender add-on may need to be updated to block to export, too (I assumes they are set up with the blender add-on). If valid, we may need inline TODO comment about supporting multiple nav meshes in the future and console warning that we ignore other nav meshes for now.

@keianhzo
Copy link
Contributor Author

No, it's not, we only support one nav mesh per scene. I've opened an issues to show a warning when there is more than one object with a nav-mesh component: Hubs-Foundation/hubs-blender-exporter#245

@keianhzo keianhzo merged commit 3b6d99a into master Oct 19, 2023
10 of 12 checks passed
@keianhzo keianhzo deleted the bitecs-nav-mesh-update branch October 19, 2023 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-loader P1 Address as quickly as possible
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants