Comments (2)
👍 Glad you got it working via reading the x/y and dropping the z coord
from navmesh.
i have managed to make it work
import fs from 'fs-extra'
import wavefrontObjParser from 'wavefront-obj-parser'
import NavMesh from "navmesh";
fs.readFile('./src/map.obj', 'utf8', function(err, data) {
if (err) throw err;
console.log(data);
var parsedJSON = wavefrontObjParser(data)
console.log(parsedJSON)
fs.writeJson('./src/map.json', parsedJSON, {
spaces: 2
})
/*
const meshPolygonPoints = [
[{ x: 0, y: 0 }, { x: 10, y: 0 }, { x: 10, y: 10 }, { x: 0, y: 10 }], // Polygon 1
[{ x: 10, y: 0 }, { x: 20, y: 0 }, { x: 20, y: 10 }, { x: 10, y: 10 }], // Polygon 2
[{ x: 10, y: 10 }, { x: 20, y: 10 }, { x: 20, y: 20 }, { x: 10, y: 20 }] // Polygon 3
];
*/
const meshPolygonPoints = []
const vertexPositions = parsedJSON.vertexPositions
const array = parsedJSON.vertexPositionIndices
for (let index = 0; index < array.length; index += 4) {
const aIndex = array[index];
const bIndex = array[index + 1]
const cIndex = array[index + 2]
meshPolygonPoints.push([
{
x: vertexPositions[aIndex * 3],
y: vertexPositions[(aIndex * 3) + 2]
},
{
x: vertexPositions[bIndex * 3],
y: vertexPositions[(bIndex * 3) + 2]
},
{
x: vertexPositions[cIndex * 3],
y: vertexPositions[(cIndex * 3) + 2]
}
])
}
fs.writeJson('./src/meshPolygonPoints.json', meshPolygonPoints, {
spaces: 2
})
const navMesh = new NavMesh(meshPolygonPoints);
console.log(navMesh)
console.time('pathfinding')
const path = navMesh.findPath({ x: 3, y: 2 }, { x: 8, y: 8 });
console.timeEnd('pathfinding')
console.log(path)
fs.writeJson('./src/path.json', path, {
spaces: 2
})
});
from navmesh.
Related Issues (20)
- Destroying a Phaser game instance with noReturn true causes undefined error in navmesh destroy HOT 2
- Navmesh interactive demo example (non phaser) HOT 8
- restricted movement HOT 1
- Shortest Path HOT 4
- Can not install navmesh using npm HOT 4
- Any plans on adding tools for dynamic meshes? HOT 9
- Double boot call for phaser plugin HOT 3
- TypeError: NavMesh.buildPolysFromGridMap is not a function HOT 5
- Defining Navmesh from List of Unwalkable Areas HOT 4
- add a shrink param to builMeshFromTilemap HOT 2
- Unexpected token when trying to use phaser 3 plugin HOT 3
- Unexpected token; when import phaser-navmesh HOT 8
- Get all crossed polygons
- Navmesh plugin is not defined
- how to get a random point on navmesh HOT 1
- Project dead? HOT 1
- Tile scale doesn't affect polygon size unless offset is also set
- error on update to phaser 3.6
- NavMesh breaks when run on server due to umd target HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from navmesh.