Code Monkey home page Code Monkey logo

go-detour's Introduction

go.dev reference Test Actions Status Go Report Card codecov

go-detour - port of recast/detour in Go

Recast library

Recast is state of the art navigation mesh construction toolset for games.

  • It is automatic, which means that you can throw any level geometry at it and you will get robust mesh out
  • It is fast which means swift turnaround times for level designers
  • It is open source so it comes with full source and you can customize it to your heart's content.

The Recast process starts with constructing a voxel mold from a level geometry and then casting a navigation mesh over it. The process consists of three steps, building the voxel mold, partitioning the mold into simple regions, peeling off the regions as simple polygons.

  1. The voxel mold is build from the input triangle mesh by rasterizing the triangles into a multi-layer heightfield. Some simple filters are then applied to the mold to prune out locations where the character would not be able to move.
  2. The walkable areas described by the mold are divided into simple overlayed 2D regions. The resulting regions have only one non-overlapping contour, which simplifies the final step of the process tremendously.
  3. The navigation polygons are peeled off from the regions by first tracing the boundaries and then simplifying them. The resulting polygons are finally converted to convex polygons which makes them perfect for pathfinding and spatial reasoning about the level.

Recast command line interface

This package embeds a command line interface tool named recast to build navigation meshes:

$ recast -h
This is the command-line application accompanying go-detour:
        - build navigation meshes from any level geometry,
        - save them to binary files (usable in 'go-detour')
        - easily tweak build settings (YAML files),
        - check or show info about generated navmesh binaries.

Usage:
  recast [command]

Available Commands:
  build       build navigation mesh from input geometry
  config      generate a config file with default build settings
  infos       show infos about a navmesh

Use "recast [command] --help" for more information about a command.

Installation of the cli tool:

go get -u github.com/arl/go-detour/cmd/recast

Detour library

Recast is accompanied with Detour, path-finding and spatial reasoning toolkit. You can use any navigation mesh with Detour, but of course the data generated with Recast fits perfectly.

Detour offers simple static navigation mesh which is suitable for many simple cases, as well as tiled navigation mesh which allows you to plug in and out pieces of the mesh. The tiled mesh allows you to create systems where you stream new navigation data in and out as the player progresses the level, or you may regenerate tiles as the world changes.

Compatibility with original Detour & Recast

The Go version and the original works both with the same binary format to save navmeshes, that means:

  • you can use in the original Detour the navmeshes built in Go.
  • you can use in Go the navmeshes built with the original Recast.

In other words, you can visualize and tweak your navmeshes with the handy GUI tool RecastDemo. Once you are satisfied with the navmesh of your geometry, use the same build settings with either the recast Go package or the cli tool in order to have identical results.

Samples

todo

... speak about the implemented sample from RecastDemo ...

Package structure

todo: ... speak about the package structure or at least explain the big idea ...

Minimum Go Version

Go 1.8+ is required

Credits

go-detour has been ported to the Go language. As such, it's not an original work.

The Detour & Recast libraries (which go-detour is port of) is an original work from, and has been written by, Mikko Mononen, and released under the following:

copyright (c) 2009 Mikko Mononen [email protected].

License

go-detour is licensed under ZLib license, see LICENSE for more information.

go-detour's People

Contributors

arl avatar chenshungen avatar codespartan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-detour's Issues

Load navmesh from .bin?

Hello!! And Thanks for this awesome library. I hope I can implement this in my project!

Is there any way to load a Recast Navmesh from a .bin file?
I want to use detour to get some walkable paths for my game.

Thanks!!

Add new obstacles

Hello!! And thanks for porting this library!! I'm starting to implement this in my project.

I've got a Recast Navmesh in .bin format and I've already loaded it inside my .go project without issues!
I need now to add to this navmesh some spheres and cylinders by code (i've got the orientation vectors, radius and center coordinates). Is there any way to do this with this library?

Again, THANK you very much!!

Nice project!

Hi! This code looks very elegant and I hope I'll be able to follow. My goal right now is to get the idea of the internals of navmeshing and the original Recast is perhaps more towards performance than education. So thanks a lot for the tool! Do you have any idea how it compares against Recast performance? Performance is not that crucial in my project, but I am curious.

FindNearestPoly returns and invalid polygon reference

Hello! Me again! I think i'm close to finish implementing this on my server! So excited.

I'm having problems finding the nearest polygon to a point.
The point is (-113.73, -167.78, 240) and the navmesh data is this one Mundo.zip

I'm using this code:

var Query *detour.NavMeshQuery var Filter detour.QueryFilter var Polygon detour.PolyRef var ProjectedPoint d3.Vec3 var Status detour.Status Extent := d3.NewVec3XYZ(5,5,5) Point := d3.NewVec3XYZ(-113.73,-167.78,240) Status, Query = detour.NewNavMeshQuery(NavMesh, 1000) Filter = detour.NewStandardQueryFilter() Status, Polygon, ProjectedPoint = Query.FindNearestPoly(Point, Extent, Filter)

Then when I try NavMesh.IsValidPolyRef(Polygon) it always throws false.
I tried with different Extent values (like really big ones) and the result is always the same.

Any clues on what I might be doing wrong?
Thankss

Almost there!

Heyy me again! I think I'm almost there but still struggling with some thingies!

I'm using an Unreal Engine 4 plugin to extract the navmesh from my game.
The output navmesh file is this one: Mundo.zip.

I used this other command line application that verifies the recast navigation data exported from UE: https://github.com/hxhb/ue4-recast-detour and everything with the navmesh is fine.
This app tries to project the points you give it into the navmesh with an extent of (10,10,10) and gives you the result (valid or invalid).

You can verify yourself using this commands
ue4-detour.exe Mundo.bin -113.72 -167.78 170.00
ue4-detour.exe Mundo.bin 27.69 -26.35 170

The path I'm trying to find is between this points:
Origin = (-113.72, -167.78, 170)
Destination = (27.69, -26.35, 170)

The projected points are the same to the ones I get when projecting them directly inside the game client, so I was thinking maybe I'm doing something wrong on the server side, because when I try to do the same in the server, It fails when executing the function FindNearestPoly in the Origin point. The status code is success but the point isn't valid (it didn't find any). I tried using an extent of like (10000,10000,10000) and it never finds any polygon.

The only new thing I just found out is that the verification app does convert the points from unreal 2 recast system and viceversa so I did the same on my server:
Sin título

And this is the code i'm using to find the straight path (the same as you used in the tests, but in spanish lol):
Sin título2
(it never goes past that if statement, because NavMesh.IsValidPolyRef returns false)

I'll keep investigating about this but I wanted to show you because maybe there's something I'm missing out and you could point me in the right direction.

Thanksss again!

Problem installing recast

go get -u github.com/arl/go-detour/cmd/recast

github.com/arl/math32

go/src/github.com/arl/math32/fma.go:8:17: undefined: math.FMA

Ubuntu 18.04.4 LTS

Building with CLI tool doesn't work.

Trying to build a navmesh from an .OBJ file with ./recast build file.bin --input file.obj runs for a little bit and then fails, with this output:

panic: untested

goroutine 1 [running]:
github.com/arl/go-detour/recast.delaunayHull(0xc00016a000, 0x1c, 0xc00018e498, 0x300, 0x300, 0x13, 0xc00018e034, 0x7f, 0x7f, 0xc00018f0d8, ...)
	/home/user/go/src/github.com/arl/go-detour/recast/meshdetail.go:704 +0x826
github.com/arl/go-detour/recast.buildPolyDetail(0xc00016a000, 0xc000270000, 0x12, 0x12, 0x3fc0000000000006, 0x23dcccccd, 0xc00018f400, 0xc00018f138, 0xc00018e498, 0x300, ...)
	/home/user/go/src/github.com/arl/go-detour/recast/meshdetail.go:1030 +0x1a2a
github.com/arl/go-detour/recast.BuildPolyMeshDetail(0xc00016a000, 0xc000764000, 0xc00018f400, 0x3dcccccd3fc00000, 0x0, 0xc0032f6000)
	/home/user/go/src/github.com/arl/go-detour/recast/meshdetail.go:447 +0xbbb
github.com/arl/go-detour/sample/solomesh.(*SoloMesh).Build(0xc00018f848, 0x6dc380, 0xc0000100a8)
	/home/user/go/src/github.com/arl/go-detour/sample/solomesh/builder.go:281 +0xb90
github.com/arl/go-detour/cmd/recast/cmd.doBuild(0x81f220, 0xc00007ad50, 0x1, 0x3)
	/home/user/go/src/github.com/arl/go-detour/cmd/recast/cmd/build.go:72 +0xc65
github.com/spf13/cobra.(*Command).execute(0x81f220, 0xc00007acf0, 0x3, 0x3, 0x81f220, 0xc00007acf0)
	/home/user/go/src/github.com/spf13/cobra/command.go:860 +0x2c2
github.com/spf13/cobra.(*Command).ExecuteC(0x81efa0, 0x4456ca, 0x808c00, 0xc000000180)
	/home/user/go/src/github.com/spf13/cobra/command.go:974 +0x375
github.com/spf13/cobra.(*Command).Execute(...)
	/home/user/go/src/github.com/spf13/cobra/command.go:902
github.com/arl/go-detour/cmd/recast/cmd.Execute()
	/home/user/go/src/github.com/arl/go-detour/cmd/recast/cmd/root.go:26 +0x31
main.main()
	/home/user/go/src/github.com/arl/go-detour/cmd/recast/main.go:6 +0x25

doesn't work

I can not find:
"github.com/arl/gogeo/f32"
"github.com/arl/gogeo/f32/d3"
"github.com/arl/math32"

Very nice project!

My game client use unity3D to make game.I need use Navmesh from unity3D, I can?

How to use offmesh connections?

Hi,

I've tested building NavMesh from a obj file which is exported from UE4.25. It works very well.

But I didn't pass the test for offmesh connections.

My test septs are:

  1. add an off mesh connection to input geometry.
  2. build nav mesh
  3. find path

My test codes for adding off mesh as below:

func (ig *InputGeom) AddOffMeshConnection(spos [3]float32, epos [3]float32, rad float32, bidir uint8, area uint8, flags uint16) {

if ig.offMeshConCount >= 256 {
	return
}

ig.OffMeshConnectionVerts()[ig.offMeshConCount*3*2] = spos[0]
ig.OffMeshConnectionVerts()[ig.offMeshConCount*3*2 + 1] = spos[1]
ig.OffMeshConnectionVerts()[ig.offMeshConCount*3*2 + 2] = spos[2]

ig.OffMeshConnectionVerts()[ig.offMeshConCount*3*2 + 3] = epos[0]
ig.OffMeshConnectionVerts()[ig.offMeshConCount*3*2 + 4] = epos[1]
ig.OffMeshConnectionVerts()[ig.offMeshConCount*3*2 + 5] = epos[2]



//fmt.Printf("OffMeshConnectionVerts: %v\n",soloMesh.geom.OffMeshConnectionVerts())

ig.OffMeshConnectionRads()[ig.offMeshConCount] = rad
ig.OffMeshConnectionDirs()[ig.offMeshConCount] = bidir
ig.OffMeshConnectionAreas()[ig.offMeshConCount] = area
ig.OffMeshConnectionFlags()[ig.offMeshConCount] = flags
ig.OffMeshConnectionId()[ig.offMeshConCount] = uint32(1000 + ig.offMeshConCount)


//m_offMeshConRads[m_offMeshConCount] = rad;
//m_offMeshConDirs[m_offMeshConCount] = bidir;
//m_offMeshConAreas[m_offMeshConCount] = area;
//m_offMeshConFlags[m_offMeshConCount] = flags;
//m_offMeshConId[m_offMeshConCount] = 1000 + m_offMeshConCount;

ig.offMeshConCount ++

}

please correct me.

Thanks

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.