Posted on

Navigation meshes, crowds, agents and obstacles

Added componentised (as in Entity Component System based) navigation mesh support via a new Navigation plugin (available for download here) that uses Mikko Mononen’s Recast library. The key components are; TiledNavMeshComponent, NavMeshCrowdComponent, NavMeshObstacle and NavMeshAgent. As can be seen from the video in the editor you can now import models then generate navigable areas for agents to move around. Within the editor you can then wire up input devices to scripts that then perform ray -> mesh intersection to move your agents. The entire scene (models, nav mesh, agents, scripts and input handling) can then be saved to file or published as a code project from within the editor. A typical script (that is saved into the scene file) is included below. You would typically trigger this script in response to an event (i.e. an input device event – by adding a Mouse input device to the scene and wiring up its onMouseButtonDown event to the script’s execute method or in response to an object entering a collision volume. (see the collision volume support in the video log).

require('fireflyscript')
require('ext_NavigationScript')

-- find the agent, nav mesh and crowd
scene            = sdk:GetScene()
agent            = scene:Find('Agent')
navMesh          = scene:Find('NavMesh')
agentComponent   = ext_NavigationScript.GetComponent_Navigation_NavMeshAgentComponent(agent)
crowdComponent   = ext_NavigationScript.GetComponent_Navigation_NavMeshCrowdComponent(navMesh)
navMeshComponent = ext_NavigationScript.GetComponent_Navigation_TiledNavMeshComponent(navMesh)

-- unproject the current mouse pos at both near / far clip planes
mousePos     = sdk:GetMousePosition()
pickRayNear  = fireflyscript.vec3()
pickRayFar   = fireflyscript.vec3()
sdk:UnprojectNearFar(mousePos:GetX(), mousePos:GetY(), pickRayNear, pickRayFar)

-- obtain navigation mesh transform
navMesh      = fireflyscript.CastSceneItemToPickableSceneItem(navMesh)
worldToLocal = navMesh:GetWorldMatrixInverse()
localToWorld = navMesh:GetWorldMatrix()

-- test pick ray against nav mesh geometry
geom                   = navMeshComponent:GetMesh()
localPickRayNear       = worldToLocal * fireflyscript.vec4(pickRayNear, 1)
localPickRayFar        = worldToLocal * fireflyscript.vec4(pickRayFar, 1)
localIntersectionPoint = fireflyscript.vec3()
geom:LineTest(fireflyscript.vec3(localPickRayNear), fireflyscript.vec3(localPickRayFar), localIntersectionPoint)

-- move the agent(s)
crowdComponent:SetTargetPoint(fireflyscript.vec3(localToWorld * fireflyscript.vec4(localIntersectionPoint,1)))
Posted on

Cross compiling C/C++ libraries for Android (updated)

There are a few forms a C/C++ library that you want to cross compile to Android might come in.

For instance:

  • An Autotools project
  • A CMake project

To get started let’s make a standalone Android toolchain (a toolchain being compilers, libraries and headers for cross compiling our source code to a specific target architecture and platform ABI) . Continue reading Cross compiling C/C++ libraries for Android (updated)