I’ve been using local space pathfinding as described here:
This works great but the debugging gizmo (Show Graphs Option) renders in a place that is not visually aligned with the entities. This makes it hard for my LD workflow and also for debug pathfinding, etc. In this screen shot you can see the local space grid graphs (there are 5 of them) at the very bottom, but the actual entities are at the top of the image.
Please ignore the large pink grid graph at the top as s that is the pathfinding structure the exterior entities use to navigate.
I would like to render the local space graphs seen at the bottom of the image over top of their corresponding entity transform.
I believe I need to modify the OnDrawGizmo of the GridGraph class. However, I’m struggling to get the math in the correct number space as well as understanding how the gizmo rendering works.
I’ve injected a local space transform into their corresponding grid graph instances, but I’m struggling to render the pathfinding debug (Show Graphs) in the local space of the object. It might be my transform order or perhaps my assumptions on how the debug rendering code works.
Can I just wrap the entire rendering code with a push/pop transform? Is this the correct approach/actually achievable? Any help would be greatly appreciated or if you could point me to some sample code.
Everything seems to be working great as seen in the video:
My only issue is that I have to press the ‘eye’ button on/off on the NavGraph widget in the inspector when my container entities move to regenerate the geometry. Is there a way to force the generated geometry to update? I’m looking through the code and I dont see any obvious way to force the buffer to reset. It should be easy to find, but for some reason I can’t seem to see how the geometry is dirtied. I’ve probably overlooked it but it seems to escape me.
Also here are the specific steps to get GridGraph Gizmo rendering in a local space:
As you mentioned GraphGizmoHelper needs to be piped the _transformSequence. DrawLine, DrawMesh and DrawTriange need to be updated so the vertices are multiplied by the _transformSequence
public void DrawMesh (RetainedGizmos gizmos, Vector3[] vertices, List<int> triangles, Color[] colors) {
var mesh = gizmos.GetMesh();
// Set all data on the mesh
if ( m_UseTransform )
{
for ( var i = 0; i < vertices.Length; i++ )
{
vertices[ i ] = m_Transform.MultiplyPoint ( vertices[ i ] );
}
mesh.vertices = vertices;
}
else
{
mesh.vertices = vertices;
}
...
}
public void DrawLine (Vector3 start, Vector3 end, Color color) {
if ( m_UseTransform )
{
lines.Add ( m_Transform.MultiplyPoint(start) );
lines.Add ( m_Transform.MultiplyPoint(end) );
}
else
{
lines.Add ( start );
lines.Add ( end );
}
var col32 = (Color32)color;
lineColors.Add ( col32 );
lineColors.Add ( col32 );
}
Gizmo rendering code inside the DrawUnwalkableNodes method needs to have Gizmos.matrix set to _transform
Seeker::OnDrawGizmo needs to be updated to have the Gizmos.matrix set to _transform
I’m sure there are other aspects of the gizmo rendering that probably still need to be rendered but this is enough for my purposes. This changes can probably be replicated in other types of NavGraph.
The DrawGizmos method uses caching to reduce CPU-load. To ensure it is re-rendered every time something moves, you can add the current position/matrix you are using to the hasher.