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

NavMesh generation at runtime? #85

Open
jameskane05 opened this issue Oct 5, 2024 · 0 comments
Open

NavMesh generation at runtime? #85

jameskane05 opened this issue Oct 5, 2024 · 0 comments

Comments

@jameskane05
Copy link

Consider this example of a Minecraft-like experience:

https://github.com/pmndrs/xr/tree/main/examples/minecraft

Every time a Cube is added, I would like to generate a navmesh from all the top faces (with normals pointing along the up axis) for agents to navigate. Assume there will only be a few dozen cubes on average, or 100 max, so it's practical to just loop through them every time one is added. Cubes are just boxGeometry.

Forgive me if this should be obvious, but is this possible? In all the examples I'm seeing, people are loading in a NavMesh from a .glb, but I'm trying to design agents to move over a landscape that the user will build out. My best attempt so far:

  const face1 = new YUKA.Polygon()
  const face2 = new YUKA.Polygon()
  const faces = []

  cubes.forEach((cube) => {
    const [x, y, z] = cube
    const halfSize = CUBE_SIZE / 2

    // Top face of the cube
    const v1 = new YUKA.Vector3(x - halfSize, y + halfSize, z - halfSize)
    const v2 = new YUKA.Vector3(x + halfSize, y + halfSize, z - halfSize)
    const v3 = new YUKA.Vector3(x + halfSize, y + halfSize, z + halfSize)
    const v4 = new YUKA.Vector3(x - halfSize, y + halfSize, z + halfSize)

    console.log("v1", v1)
    console.log("v2", v2)
    console.log("v3", v3)
    console.log("v4", v4)

    face1.fromContour([v1, v2, v3])
    face2.fromContour([v1, v3, v4])
    faces.push(face1) 
    faces.push(face2)
  })

  let newNavMesh = new YUKA.NavMesh()
  newNavMesh.fromPolygons(faces)
  navMesh = newNavMesh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant