Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Visualising an octree

Discussion in 'General Graphics' started by MasterReDWinD, Mar 22, 2019.

  1. MasterReDWinD

    MasterReDWinD

    Joined:
    Mar 26, 2018
    Posts:
    9
    Hi,

    I am trying to visualise an octree for debugging purposes. I would like to be able to see each of the nodes and to colour leaf nodes and interior nodes differently.

    I started off using Debug.DrawLine but have now moved to using LineRenderer. In both cases I create a box surrounding the node, connecting the node corners to form 12 lines. The rendering was initially taking place during construction of the node object but I am now adding nodes to a list and creating all the `boxes' at the end of the recursive octree creation.

    Ideally I would like to see the node subdivision as it is happening rather than just at the end. I also need to be able to remove some of the lines I have drawn if I choose to collapse multiple nodes into one larger one (a condition of the algorithm I am implementing).

    Has anyone tried to visualise an octree in this manner? Is my current approach along the right lines?

    Thanks
     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,594
    Use Gizomos, or use Boxes.
     
  3. MasterReDWinD

    MasterReDWinD

    Joined:
    Mar 26, 2018
    Posts:
    9
    Thanks for the suggestions. I had previously looked into Gizmos but disregarded it as my class doesn't extend from MonoBehaviour.

    Are you using a class which does inherit from MonoBehaviour to invoke OnDrawGizmos() and then pulling the draw position data from your octree class within that function? Something like the solution hinted to in this answer: https://answers.unity.com/questions/1079933/how-to-draw-gizmos-without-using-a-monobehaviour.html ?

    Also, by Boxes do you mean GUI.Box?
     
  4. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,594
    By boxes I mean simply GameObject cubes.

    I suggest look into
    Unity-Technologies/UnityOctree
    where yes, it uses MonoBehaviour class as a base, to draw octree gizmos.

    I have also discussed ECS based Octree, but this may not necessary be of your interest.
    [WIP] Hovercrafts Sandbox Prototype [ECS based]
     
    MasterReDWinD likes this.
  5. MasterReDWinD

    MasterReDWinD

    Joined:
    Mar 26, 2018
    Posts:
    9
    I'll take a look into those two projects. Thanks for your help.