Code Monkey home page Code Monkey logo

Comments (2)

mikewesthad avatar mikewesthad commented on August 13, 2024 1

👍 Glad you got it working via reading the x/y and dropping the z coord

from navmesh.

Wenish avatar Wenish commented on August 13, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.