Mugen87 / yuka

JavaScript library for developing Game AI.

Home Page:https://mugen87.github.io/yuka/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to correctly export a NavMesh from Blender 2.8

Coder2012 opened this issue · comments

I am interested in how the NavMesh example works. I decided to import the mesh into Blender 2.8 (I’m a very proficient Blender user), and after adding a couple of extra triangles to form another poligon I exported this using .gltf + .bin combined.

When loading this back into the demo, I get the following error:

YUKA.NavMeshLoader: Unable to load navigation mesh. Error: YUKA.NavMeshLoader: Invalid geometry format. Please ensure to represent your geometry as triangles.

Can anyone share their export settings as there’s quite a few, maybe my export settings are incorrect.

The error means that your glTF asset contains rendering primitives other than TRIANGLES (.e.g. POINTS, LINES etc.). NavMeshLoader makes the assumption that its geometry data are only defined with triangles.

Can you please share the resulting gltf + bin file for debugging?

BTW: We used to create NavMeshes with Blender < 2.8. The new version has dropped its game engine and thus all NavMesh tools. Another reason for our plan to write an own NavMesh generator in JavaScript.

Ah so I loaded up 2.7 and saw that there was this navigation mesh creation panel. As you pointed out the game engine has been deprecated in 2.8.

I created a simple mesh with 4 polys, triangulated it and then exported from 2.8 using the defaults of the Khronos glTF exporter, but I get the same error.

Maybe my understanding of a navmesh is lacking, as long as I have a mesh that co-planar and made of triangles, I'm good to go?

I've attached the export in zip here for you to inspect.

navmesh2.zip

This was actually a little bug in NavMeshLoader 😇

Fixed via 426e4dc

Maybe my understanding of a navmesh is lacking, as long as I have a mesh that co-planar and made of triangles, I'm good to go?

The navmesh does not have to be coplanar as demonstrated by this example:

https://mugen87.github.io/yuka/examples/navigation/navmeshPerformance/

But yes, a navmesh is made up of triangles and the mesh itself is not extruded (meaning it has no volume).

commented

Hi there, could you guys please tell me why this navmesh does not work?

lh_dungeon_01.zip

const data = fs.readFileSync("./public/models/navmesh/lh_dungeon_01.glb"); const loader = new YUKA.NavMeshLoader(); let test = await loader.parse( data.buffer );

ERROR:

SyntaxError: Unexpected token ; in JSON at position 12
at JSON.parse ()
at NavMeshLoader.parse (D:\xampp\htdocs\orbiter-colyseus\node_modules\yuka\build\yuka.js:19036:22)
at D:\xampp\htdocs\orbiter-colyseus\src\shared\Utils\loadNavMeshFromFile.ts:7:29
at Generator.next ()
at D:\xampp\htdocs\orbiter-colyseus\src\shared\Utils\loadNavMeshFromFile.ts:31:71
at new Promise ()
at __awaiter (D:\xampp\htdocs\orbiter-colyseus\src\shared\Utils\loadNavMeshFromFile.ts:27:12)
at loadNavMeshFromFile (D:\xampp\htdocs\orbiter-colyseus\src\shared\Utils\loadNavMeshFromFile.ts:41:12)
at GameRoom. (D:\xampp\htdocs\orbiter-colyseus\src\server\rooms\GameRoom.ts:32:50)
at Generator.next ()

I can load the nav mesh when importing it in the basic nav mesh demo. Because of its special geometry, I just had to set the mergeConvexRegions option to false so the loader does not trigger the merge. It looks like so then:

image

So the nav mesh itself looks fine. Seems there is an issue in your node environment.

commented

you're right, I've managed to load both in my node.js server and my babylon client, and using the createConvexRegionHelper function to display it, but results looks weird, looks like it's rotated ? Maybe there is something obvious I'm doing wronmg? code is here: https://github.com/oriongunning/t5c
image

EDIT 1: using the option mergeConvexRegions confirms the navmesh is in the crong orientation.
image

EDIT 2
if i untick the Y axis checkbox when exporting with blender, it seem to display correcty on the client, but the server must be loading it in a different orientation as I cannot go any more south in the picture. How would you debug on the server as you cannot see display it to debug it?....
image

I have no idea why it is not in right orientation? Any ideas?

commented

i have tried rotating in every possible way, doesnt seem to chnage anyhting. the only things that does is the Y+ checbox. when is unticked i cannot go right, when ticked i cannot south... man this is painful. Not your fault @Mugen87 I'm just doing obviously wrong somewhere

Can you try it with an older Blender version like 2.8?

commented

Sure, ill give that a try, i'm using 3.3.1

commented

same behaviour in 2.8.3.

@Mugen87 I've added a fair amount of tests to try and debug this

----------- TEST 1---------------
let test = this._gameroom.navMesh.getRandomRegion(); console.log(test);

gives more sensible results, but the Y axis should not be higher than 1?:

centroid: Vector3 {
x: -11.88888963063558,
y: 5.9604641222676946e-8,
z: 0.8888889948527018
},
centroid: Vector3 {
x: 7.222222328186035,
y: 5.9604641222676946e-8,
z: -9.777779261271158
},

-------------- TEST 2 -------------
Another debug test, after creating a vehicule on the server
`
this.entityManager = new EntityManager();
this.time = new Time()

let id = nanoid();
const vehicle = new Vehicle()
vehicle._uuid = id;
vehicle.name = "rat";
vehicle.rotation.fromEuler(0, 2 * Math.PI * Math.random(), 0);
vehicle.position.x = 1;
vehicle.position.y = 1;
vehicle.position.z = 1;
const wanderBehavior = new WanderBehavior()
vehicle.steering.add(wanderBehavior)
this.entityManager.add(vehicle)`

and then in my update function
const delta = this.time.update().getDelta(); this.entityManager.update(delta);

with a console.log, my vehicle position is way out of the bounds.
position: Vector3 { x: -1647608072.1801252, y: 1, z: 277497351.3185711 }, rotation: Quaternion { x: 0, y: 0.4561747218779746, z: 0, w: 0.8898902309383739 },

----------TEST 3--------------
console log results of navmesh.regions[x].centroid

it's weird, I would have assumed only two axis would be used....?
Vector3 {
x: 12.055556615193685,
y: 5.9604641222676946e-8,
z: 3.888888676961263
}
Vector3 {
x: 11.277779897054037,
y: 5.9604641222676946e-8,
z: 3.888888676961263
}
Vector3 {
x: 12.055553436279297,
y: 5.9604641222676946e-8,
z: 7.277777671813965
}
Vector3 {
x: 12.277776718139648,
y: 5.9604641222676946e-8,
z: 6.722222010294597
}
Vector3 {
x: 6.44444465637207,
y: 5.9604641222676946e-8,
z: 7.722222010294597
}
Vector3 {
x: 11.833333333333334,
y: 5.9604641222676946e-8,
z: 6.05555534362793
}
Vector3 {
x: 11.944443384806315,
y: 5.9604641222676946e-8,
z: 7.722222010294597
}
Vector3 {
x: 10.722223281860352,
y: 5.9604641222676946e-8,
z: 4.05555534362793
}
Vector3 {
x: 7.333333333333333,
y: 5.9604641222676946e-8,
z: 2.1111110051472983
}
Vector3 {
x: 3.1666666666666665,
y: 5.9604641222676946e-8,
z: 4.722222010294597
}
Vector3 {
x: 6.333333333333333,
y: 5.9604641222676946e-8,
z: 7.222222010294597
}
Vector3 {
x: -16.722222646077473,
y: 5.9604641222676946e-8,
z: 0.5555556615193685
}
Vector3 {
x: -11.88888963063558,
y: 5.9604641222676946e-8,
z: 0.8888889948527018
}
Vector3 {
x: -11.555556297302246,
y: 5.9604641222676946e-8,
z: 1.4444446563720703
}
Vector3 {
x: -16.38888931274414,
y: 5.9604641222676946e-8,
z: 3.722222328186035
}
Vector3 {
x: -9.222222646077475,
y: 5.9604641222676946e-8,
z: 5.777777671813965
}
Vector3 {
x: -3.722222646077474,
y: 5.9604641222676946e-8,
z: 3.722222328186035
}
Vector3 {
x: -2.722222646077474,
y: 5.9604641222676946e-8,
z: 0.3333333333333333
}
Vector3 {
x: -3.055555979410807,
y: 5.9604641222676946e-8,
z: 0.8888889948527018
}
Vector3 {
x: -1.6666666666666667,
y: 5.9604641222676946e-8,
z: 3.1666666666666665
}
Vector3 {
x: 11.388888994852701,
y: 5.9604641222676946e-8,
z: -4.333334287007649
}
Vector3 {
x: 10.166666984558105,
y: 5.9604641222676946e-8,
z: -4.444445292154948
}
Vector3 {
x: 7.111111323038737,
y: 5.9604641222676946e-8,
z: -5.555556615193685
}
Vector3 {
x: 4.166666666666667,
y: 5.9604641222676946e-8,
z: -3.27777894337972
}
Vector3 {
x: 7.222222328186035,
y: 5.9604641222676946e-8,
z: -9.777779261271158
}
Vector3 {
x: 6.0000003178914385,
y: 5.9604641222676946e-8,
z: -9.611112594604492
}
Vector3 {
x: 5.888889312744141,
y: 5.9604641222676946e-8,
z: -8.666667938232422
}
Vector3 {
x: -12.333333333333334,
y: 5.9604641222676946e-8,
z: -9.666668256123861
}
Vector3 {
x: -3.722222646077474,
y: 5.9604641222676946e-8,
z: -4.27777894337972
}
Vector3 {
x: -8.111112594604492,
y: 5.9604641222676946e-8,
z: -6.888890266418457
}
Vector3 {
x: -14.166669209798178,
y: 5.9604641222676946e-8,
z: -5.944445610046387
}
Vector3 {
x: -19.444446563720703,
y: 5.9604641222676946e-8,
z: -4.944445292154948
}
Vector3 {
x: -15.277779261271158,
y: 5.9604641222676946e-8,
z: -3.33333428700765
}
Vector3 {
x: -11.555556297302246,
y: 5.9604641222676946e-8,
z: -1.277778645356496
}
Vector3 {
x: -21.22222328186035,
y: 5.9604641222676946e-8,
z: -4.611112276713054
}
Vector3 {
x: -20.72222328186035,
y: 5.9604641222676946e-8,
z: -4.611112276713054
}
Vector3 {
x: -16.722222646077473,
y: 5.9604641222676946e-8,
z: -0.5000009536743164
}
Vector3 {
x: -11.88888963063558,
y: 5.9604641222676946e-8,
z: -0.7777786453564962
}
Vector3 {
x: -20.055556615193684,
y: 5.9604641222676946e-8,
z: -4.666667620340983
}
Vector3 {
x: -2.722222646077474,
y: 5.9604641222676946e-8,
z: -0.27777864535649616
}
Vector3 {
x: -3.055555979410807,
y: 5.9604641222676946e-8,
z: -0.7777786453564962
}
Vector3 {
x: -1.6666666666666667,
y: 5.9604641222676946e-8,
z: -3.77777894337972
}

commented

@Mugen87 hi mate, do those test above help you in any way to identify the issue i'm having on my node server? (all code is here: https://github.com/oriongunning/t5c/tree/main/src/server)

started an issue here also: https://forum.babylonjs.com/t/how-to-get-yuka-js-working-in-node-environment/36510

I have a (I think) simple navmesh but get the same error:

  • mesh was initially created with blender 2.79 game engine
  • edited mesh in newer version of blender (was experimenting with it)
  • it works in three-pathfinding but want get the error with loading model with new NavMeshLoader()
  • checked if the mesh is only triangled faces, no other objects

navmesh.gltf.zip

Any help is appreciated! :)

Edit:
corrected-navmesh-gltf.zip

I missed the part where it should be loose triangles. I fixed and simplified my navmesh and created loose triangles, this does work. Links for anyone who has the same issue.