/**
  * Insert new voxel with hashkey into the hashtree
  * @param voxel voxel to be inserted
  * @param hashkey hashkey of the voxel
  */
 public void Insert(Voxel voxel, int hashkey)
 {
     if (m_hashKey == int.MinValue)
     {
         m_hashKey    = hashkey;
         this.m_voxel = voxel;
         return;
     }
     if (m_hashKey == hashkey)
     {
         this.m_voxel = voxel;
         return;
     }
     if (hashkey < m_hashKey)
     {
         if (m_leftHashTree == null)
         {
             m_leftHashTree = new VoxelHashTree();
             m_leftHashTree.m_parentHashTree = this;
         }
         m_leftHashTree.Insert(voxel, hashkey);
     }
     else
     {
         if (m_rightHashTree == null)
         {
             m_rightHashTree = new VoxelHashTree();
             m_rightHashTree.m_parentHashTree = this;
         }
         m_rightHashTree.Insert(voxel, hashkey);
     }
 }
Example #2
0
    /// <summary>
    /// Query if a voxel exists at the query location.  If it does not exist, create it.
    /// </summary>
    /// <returns>The created voxel.</returns>
    /// <param name="x">X query index.</param>
    /// <param name="y">Y query index.</param>
    /// <param name="z">Z query index.</param>
    public Voxel QueryCreateVoxel(int x, int y, int z)
    {
        int   hashKey = ComputeVoxelHashKey(x, y, z);
        Voxel v       = voxelStorage.Query(hashKey);

        if (v == null)
        {
            v = InitializeVoxel(x, y, z, m_voxelSize, m_initialVoxelValue, 0);
            voxelStorage.Insert(v, hashKey);
        }
        return(v);
    }