Search Unity

Octree update

Discussion in 'Scripting' started by acropole, Dec 10, 2019.

  1. acropole

    acropole

    Joined:
    Aug 13, 2009
    Posts:
    171
    Hi,

    What's the correct way to update PointOctree and BoundsOctree when changing objects position, rotation and scale ?

    I remove objects, apply changes then reinsert but it break the whole tree after a few iterations. I do it in OnSceneGUI.
    Some obects are lost, others looks duplicated and bounds are not updated correctly.

    Like this :
    Code (CSharp):
    1.  
    2.  for (int i = 0; i < count; i++)
    3.   {
    4.                         v = selectedVertices[i];
    5.                         if (!myMonoBehaviour.PointOctree.Remove(v))
    6.                             Debug.Log("Vector not found");
    7.   }
    8.  
    9.    for (int i = 0; i < count; i++)
    10.      {
    11.                         v = selectedVertices[i];
    12.                         v.Translate(delta);
    13.                         myMonoBehaviour.PointOctree.Add(v, v);
    14.   }
    15.  
    Green vertices are translated ones :

    octree-bug.jpg
    I use this code : https://github.com/Unity-Technologies/UnityOctree

    Thanks.