Export a Navmesh with Blender

There is extra processing needed to change the End-Of-Line from UNIX format to CR/LF format, plus some editing to get the syntax changed so that the .obj files will work properly with "Fixnavmesh.bat".

**EXPORT**

Make sure the navmesh is still selected.
In the bottom left corner of the work window is the file name of the current "object."
(if there is no name listed Right click anywhere on the mesh.)

At the top menu bar (above the work window)
Click:
File - Export - Wavefront (.obj)

[3\_Export.jpg]

There are some options that have to be set to give the correct output.

On Lower Left of the display (Left of the work window) is a panel titled:

"Export OBJ"

In the menu set the options:

(Note: the Forward and Up Must be set to the same options they were at Import.)

```
Forward: -Z Forward
Up: Y Up
[v] Selection Only
[ ] Animation
[ ] Apply Modifiers
[ ] Include Edges
[ ] Smooth Groups
[ ] Bitflag Smooth Groups
[ ] Write Normals
[ ] Include UVs
[v] Write Materials
[v] Triangulate Faces
[ ] Write Nurbs
[ ] PolyGroups
[ ] Objects as OBJ Objects
[ ] Objects as OBJ Groups
[ ] Material Groups
[v] Keep Vertex Order
Scale: 1.00

```

Above the directory/file list is the name for the saved file. The default is "untitled.obj".
I usually change that to: untitled\_Infantry.obj (untitled\_Vehicle.obj)
So I can identify what file I have worked on. Use any file name(s) that you choose.

At the top right click the button [Export OBJ]

The file will be an .obj file where ever you save it.

When you export your file Blender will create a materials file with it. Using my file names the navmesh will be: untitled\_Infantry.obj (untitled\_Vehicle.obj) and the material file will be: untitled\_Infantry.mtl (untitled\_Vehicle.mtl). When you have finished editing your navmesh this Blender material file can be abandoned and deleted. To create the Quadtree files Fixnavmesh.bat will only work using the "materials.mtl" that BF2Editor created when it made the navmesh file set.

A navmesh is a single object made up of four materials: ground, water, deepwater, and ladder. Think of it as a "blanket" that covers the "Terrain" where the bots are allowed to go. The materials.mtl file gives the color of each material and the bots do different things according to the color that they "see". When a navmesh is inside a map only the bots "see" the navmesh and what color it is.

A navmesh has to be treated as a single object. Which is why we use the "Keep Vertex Order" option in the export. If a navmesh
is broken into parts you can get gaps between the triangles. And if you have gaps, even ones too small for you to see in Blender, the bots won't move across them.

--> End Of Line CORRECTION

Plus a little text editing.

If you try to run Fixnavmesh.bat on an .obj file straight out of Blender 2.76 it won't work properly.
(Blender 2.5x and 2.6x have the same problem.)
If you looked at the original ".obj" file from BF2Editor with Windows Notepad you saw it was (mostly) 3 columns of numbers.
Like this:

```
mtllib materials.mtl
v -980.250000 156.614441 -676.459412
v -332.796265 25.200001 109.453667
v 20.711723 25.200001 118.385040
v 989.750000 151.412704 -152.103546
v 991.000000 146.921814 -178.646454
v 690.250000 121.565498 -491.174316
v -346.500000 158.516769 959.289001
v -599.059021 20.975830 -339.750000
v 988.287048 158.669373 -942.729187
v -688.175903 46.527637 -425.824127
v -32.103554 24.424219 205.750000
v 835.750000 19.990000 282.250000
v -220.780014 25.200001 -87.943855
v 757.712891 25.615700 107.263229
... (ETC)
... (ETC)
... (ETC)

```

BUT, when you use Windows Notepad to open the .obj file "Exported" from Blender the text just fills the display.
Left to right and top to bottom.
Like this:

> # Blender v2.76 (sub 0) OBJ File: ''# www.blender.orgmtllib untitled\_Blender276\_NoMaterialGroups.mtlv -980.250000 156.614548 -676.459412v -332.796265 25.199984 109.453674v 20.711723 25.199982 118.385048v 989.750000 151.412735 -152.103516v 991.000000 146.921844 -178.646423v 690.250000 121.565575 -491.174286v -346.500000 158.516617 959.289001v -599.059021 20.975885 -339.750000v 988.287048 158.669525 -942.729187v -688.175903 46.527706 -425.824127v -32.103554 24.424185 205.750000v 835.750000 19.989954 282.250000v -220.780014 25.200016 -87.943848v 757.712891 25.615683 107.263237v 992.235901 131.367371 50.454277v 822.211243 124.983833 -997.435181v -30.250000 20.764994 208.603546v 375.184998 120.700340 580.461426v 332.101501 32.400227 190.987396v 797.666870 96.353333 -573.504639v 282.534637 56.494576 89.088196v 855.013245 129.682632 -997.805969v -940.250000 119.463676 -759.595520v 763.623169 96.342567 -447.901825v 782.226562 96.342606
>
>
>
> ... (ETC)
>
> ... (ETC)
>
>
>
>
> ... (ETC)
>
>

It doesn't look like the original file from BF2Editor at all.
Well... The reason for this is that starting with Blender version 2.5 (2.50?) the Export Wavefront (.obj) function
used the UNIX End Of Line (EOL) format instead of the old Carriage Return/Line Feed (CR/LF) format.
Fixnavmesh.bat doesn't understand the UNIX EOL and can't process the "weird" .obj files properly.
So, you don't get the Quadtree files you need for a final map.

(Windows Notepad doesn't understand the UNIX EOL either. Which is why you have a screen full of text instead of the columns.)

This can be fixed with a third party utility.
Go on-line and find the open source text editor called: Notepad ++ (Notepad Plus Plus).
Download a copy.
Run Notepad ++ then find and open the exported .obj file(s).
(Remember you have two .obj files, Infantry and Vehicle to "correct".)
In Notepad ++ the file looks like the original columns of numbers.
BUT, It's not fixed just yet.
Notepad ++ is smart enough to recognise the UNIX EOL format. Which is why the exported .obj file now looks correct.
To get the edited .obj to work with Fixnavmesh.bat the file has to have the EOL as CR/LF.
AND Notepad ++ can do the conversion.

In Notepad ++
From the top menu select:
Edit -> EOL Conversion -> Windows Format
Then save the converted file.
File -> Save as...
(you should give it a different name to show the EOL conversion is done.)

Close Notepad++ and then open the recently converted .obj file with Windows Notepad.
It now looks the way it should.

Well... that's not everything.

Blender has it's own way of doing things when it comes to the syntax of an .obj file.
Some of the syntax doesn't matter. Fixnavmesh.bat can work around it.
But, there are a few things that are important.

Blender will add "title" entries at the start of the file,. i.e:

```

# www.blender.org

```

These "titles" are not a problem for Fixnavmesh.bat. In fact, these titles can be ignored.

Fixnavmesh.bat will delete these lines when it processes the two .obj files and creates the quadtree files.

This next part is important.

Fixnavmesh.bat requires the names for the Materials Library, Material Groups and Materials to be very specific.

They must be:

```
- Materials Library:

mtllib materials.mtl

- Material Groups:

g ground

g ladder

g water

g deepwater

- Materials:

usemtl ground

usemtl ladder

usemtl water

usemtl deepwater

```

When it created the navmeshes BF2Editor listed each Material Group and placed the use material command directly under it. It also "gathered up" the faces using a given material, and placed them in the correct Material Group.

So, in the original Infantry.obj (Vehicle.obj), each Material Group will have the "usemtl" entry directly under it and all the faces for that material directly under the "usemtl" like this:

>
>
>

 g ground

```
usemtl ground

f 58729 60969 58731

f 70492 38518 49302

f 77590 73201 73199

f 5805 76355 52638

... etc

g ladder

usemtl ladder

g water

usemtl water

f 18410 8453 48225

f 36638 57162 43018

f 66055 66053 52832

f 61861 61860 24432

... etc

g deepwater

usemtl deepwater

f 70415 68484 47032

f 71978 49194 71979

f 66178 5844 57656

f 53534 53532 46172

...etc

```

(Again, the ladder group will not have any faces which is why it's "touching" the water group.)
Blender doesn't follow the syntax that Fixnavmesh.bat needs.
BUT, it's fairly easy to fix.

Using the file name I use, untitled\_Infantry.obj (untitled\_Vehicle.obj), the materials library entry will be:

```
mtllib untitled_Infantry.mtl (mtllib untitled_Vehicle.mtl)

```

Change this to the default:

```
mtllib materials.mtl

```

Using the "Export" options I have given, Blender will NOT create any Material Groups in the .obj file(s).

This is not a problem.

When Fixnavmesh.bat runs it will create all four of the default Material Groups and put the "usemtl" entries in the proper group. Also, it will gather every face entry of a given material and put it into the correct material group.

Blender is very economical in the file it creates. If there are no faces listed for a given material Blender will remove the Material Group and the "usemtl" entries.

(So, in most cases, unless you add a "ladder face" to the navmesh the Material Group and usemtl for ladder will be gone. And, if your map doesn't have any water, then the water and deepwater entries will also be gone.)

This is not a problem.

Fixnavmesh.bat will always create the Material Groups for all four of the materials.

If you edit where two materials meet... like the shore where ground and water touch you might end up with several "usemtl" entries that have only a few triangles under it before switching to a different material.

This is not a problem.

Fixnavmesh.bat will always gather the faces (triangles) of the same material together before it creates the Quadtree output.

BLENDER will create a strange entry

"s off"

normally just below "usemtl ground"

I am not certain what it's for but this is not a problem.

Fixnavmesh.bat will delete the line.

(If you want to you can delete the line when you edit the .obj files. But it's not required.)

# ```

=

= ** As a point of information **

=

= If you turn on the "Material Groups" option at export the Material Groups will be in the .obj file(s).

= But the names for the Material Groups and the names in the "usemtl" entries will be a little strange.

= The materials file defines 4 materials: ground, ladder, water, and deepwater.

= But if you have Blender create the Material Groups it will add an extra material.

=

= So for the Infantry.obj file you will get:

=

= g Infantry_Infantry_ground.005

= usemtl ground.005

= g Infantry_Infantry_water.005

= usemtl water.005

= g Infantry_Infantry_deepwater.005

= usemtl deepwater.005

=

=

= For the Vehicle.obj you will get:

=

= g Vehicle_Vehicle_ground.005

= usemtl ground.005

= g Vehicle_Vehicle_water.005

= usemtl water.005

= g Vehicle_Vehicle_deepwater.005

= usemtl deepwater.005

=

= These have to be changed to the "normal" names before you run Fixnavmesh.bat.

=

```

**Additional Information:**

* **Understanding Navmesh Materials**
* Understanding the Obj format of a Navmesh