Creating waypoints for meshed map (f1_tesstrack) with Blender

only_a_ptr

Lead Developer
Administrator
Developer
Joined
Jan 31, 2018
Messages
133
Location
Prague, CZ
Hello.

Tritonas was wandering if AI waypoints could be somehow generated for a meshed track (not using procedural_roads). I figured it would be easiest to import the terrain to Blender and copy the vertices of the roads to create a "navigation mesh" of sorts where individual verts would be like the waypoints. Then, the mesh could be exported to OGRE's .mesh.xml format and the waypoints could be generated from the verts. I made the following screens as I went and figured I'd make a tutorial out of them. If anything is unclear, ask for help below.

Step 1: Download blender2ogre Blender addon. Download from https://github.com/OGRECave/blender2ogre/releases . More info https://github.com/OGRECave/blender2ogre#importing-meshes
Step 2: Install the addon, see below screenshot.
Step3: enable the addon in Blender, see below screenshot.
blender2ogre-0.8.3.zip-setup.png

Step4: import the *f1_track.mesh (tip: sort files by size, it's the biggest, around 3MB). For some reason, the mesh arrives rotated 90 degrees to the side. To fix it:
  1. go to Right Orthographics view using Numpad-3 key. You may need to activate Ortho view by Numpad-5 key.
  2. activate edit mode (tab)
  3. select rotation center to be the 3D cursor (UI box on top of 3d viewport panel)
  4. press R key for rotate mode and hold Ctrl to constraint the rotation to big steps.
Step5: in the materials tab, select by material *testtrack_tarmac01, see below screenshot.
Step6: Shift+D to duplicate the vertices, then "Z" to restrain grab mode to Z axis and pull the verts up. Finally press P to separate the verts to new object. See screenshot below.
blender f1 track.png

Step 7: use the "edge select" feature (Shift+leftclick) to select and delete one side of each road. We'll use the other side as the navmesh.
Step 8: Set up the "vertex snapping" (magnet icon on top of 3d viewport) as seen on screenshot below. Then, switch to top-down view mode using Numpad-7 key. Then manually move verts to the middle of the roads. TIP: use C hotkey for circle-select, B hotkey for box-select and proportional edit (UI selector on top of 3D Viewport).
blender vert snap.png


I haven't figured how to export the verts as waypoints, though. Blender2Ogre failed me, it only exports verts which are part of a triangle. I'll have to hack ulteq's truck export scripts to export angelscript waypoints instead. For now, I'll just attach the created Blender file.
 

Attachments

  • AI_navmesh.blend
    4.2 MB · Views: 32

rents1977

Member
Joined
Jan 31, 2018
Messages
30
Its probably easy to export a list of the vertices using python and the blender console.

I was using that method to get x,y,z positions of objects. Based on using this:


I can't program and I managed to get the required info to copy and paste in to notepad.
 
OP
OP
only_a_ptr

only_a_ptr

Lead Developer
Administrator
Developer
Joined
Jan 31, 2018
Messages
133
Location
Prague, CZ
Thanks for the advice @rents1977, I googled some more and now I have a functional export to a JSON-based waypoint format which Tritonas just announced in Discord/#development.
Source and instructions to use: https://blender.stackexchange.com/a/120595

Code:
import bpy
import bmesh

# header
print ("--------------BEGIN JSON WAYPOINTS---------------")
print ("[")

# Get the active mesh
obj = bpy.context.edit_object
me = obj.data


# Get a BMesh representation
bm = bmesh.from_edit_mesh(me)

bm.faces.active = None

# Modify the BMesh, can do anything here...
sep=""
for v in bm.verts:
    if v.select:
        print("[", v.co.x, ",", v.co.y, ",", v.co.z, "]", sep )
        sep = ","
        
# footer
print ("]")
print ("--------------END JSON WAYPOINTS---------------")
 
Top