npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

navmesh-generator

v1.0.3

Published

A JS library for generating navigation meshes from obstacles

Downloads

10

Readme

NavMesh Generator

This JavaScript library allows to generate 2D navigation meshes for pathfinding.

It can be used, for instance, with this pathfinding implementation: mikewesthad/navmesh.

Used work

This implementation is strongly inspired from NMGen Study a Java one by Stephen A. Pratt.

This implementation differs a bit from the original:

  • It's only 2D instead of 3D
  • It uses objects for points instead of pointer-like in arrays of numbers
  • The rasterization comes from other sources because of the 2d focus
  • The partialFloodRegion function was rewritten to fix an issue
  • An algorithm to filter vertices that are not on a border was added

The original Java implementation was also inspired from Recast itself.

A scan-line polygon fill algorithm

The original implementation was done by Darel Rex Finley.

The implementation used in this library differs with the following:

  • It handles float vertices so it focusses on pixels center
  • It is conservative to thin vertical or horizontal polygons

Demonstrations

An isometric example

This is a modified version of an official example of GDevelop where a character moves to the pointer with a left click. The art was done by Mickael Hoarau.

Try it on itch.io

GDevelopNavMeshTiny

An AI example

This is a modified version of an official example of GDevelop where enemies follow the player.

Try it on itch.io

Squares at random positions

Try it on itch.io

Two sizes of moving objects and obstacle dragging

Try it on itch.io

How to use it

The algorithm builds a mesh from a given area and a list of polygon obstacles.

import { NavMeshGenerator } from "NavMeshGenerator";

const areaLeftBound = 0;
const areaTopBound = 0;
const areaRightBound = 800;
const areaBottomBound = 600;
const rasterizationCellSize = 10;
const navMeshGenerator = new NavMeshGenerator(
  areaLeftBound,
  areaTopBound,
  areaRightBound,
  areaBottomBound,
  rasterizationCellSize
);

const obstacles = [[
  { x: 300, y: 200 },
  { x: 500, y: 200 },
  { x: 500, y: 400 },
  { x: 300, y: 400 },
]];
const obstacleCellPadding = 0;
const navMeshPolygons = navMeshGenerator.buildNavMesh(
  obstacles,
  obstacleCellPadding
);

If you are using mikewesthad/navmesh, you can directly use the mesh to find paths.

const navMesh = new NavMesh(navMeshPolygons);
const path = navMesh.findPath({ x: 100, y: 300 }, { x: 700, y: 300 });

In this case, you need this additional import.

import { NavMesh } from "navmesh";

Changelog

Version 1.0.3

  • ES5 compatibility

Version 1.0.0

  • First version