/// <summary>
 ///   Create a copy of an existing class.
 /// </summary>
 /// <param name="toCopy"></param>
 public WalkerMapState(WalkerMapState toCopy)
 {
   this._node = toCopy._node;
   this._nodeKeys = new HashSet<VoxelLocation>(toCopy._nodeKeys);
   this._location = new VoxelLocation(toCopy._location);
   this._lastKey = null;
 }
 /// <summary>
 ///   Create a new walker state.
 /// </summary>
 /// <param name="node"></param>
 public WalkerMapState(IMapVoxelMesh node)
 {
   this._node = node;
   this._nodeKeys = this._node.Keys();
   this._location = VoxelLocation.Zero;
   this._lastKey = null;
 }
    /// <summary>
    ///   Translate an octree node.
    /// </summary>
    /// <param name="root"></param>
    /// <param name="octree"></param>
    public void TranslateTree(VoxelLocation root, IOctreeVoxelMesh octree)
    {
      VoxelLocation nextRoot = new VoxelLocation();
      for (int x = 0; x < 2; ++x)
      {
        for (int y = 0; y < 2; ++y)
        {
          for (int z = 0; z < 2; ++z)
          {
            IVoxelMesh child = octree.GetChild(x, y, z);
            if (child != null)
            {
              nextRoot.Set(root).Add(
                x * octree.Width / 2,
                y * octree.Height / 2,
                z * octree.Depth / 2
              );

              if (child is IOctreeVoxelMesh)
              {
                this.TranslateTree(nextRoot, (IOctreeVoxelMesh)child);
              }
              else
              {
                this.TranslateLeaf(nextRoot, child);
              }
            }
          }
        }
      }
    }
Пример #4
0
    public void Awake()
    {
      this._objectTransform = this.gameObject.transform;

      this._location = new VoxelLocation();
      this._dimensions = new Dimensions3D(1, 1, 1);
    }
Пример #5
0
 public VoxelVolume(VoxelLocation start, VoxelLocation end)
 {
     minx = start.x < end.x ? start.x : end.x;
     miny = start.y < end.y ? start.y : end.y;
     minz = start.z < end.z ? start.z : end.z;
     maxx = start.x > end.x ? start.x : end.x;
     maxy = start.y > end.y ? start.y : end.y;
     maxz = start.z > end.z ? start.z : end.z;
 }
Пример #6
0
 public VoxelVolume(VoxelLocation start, VoxelLocation end)
 {
     minx = start.x < end.x ? start.x : end.x;
     miny = start.y < end.y ? start.y : end.y;
     minz = start.z < end.z ? start.z : end.z;
     maxx = start.x > end.x ? start.x : end.x;
     maxy = start.y > end.y ? start.y : end.y;
     maxz = start.z > end.z ? start.z : end.z;
 }
 /// <see cref="org.rnp.voxel.mesh.IVoxelMesh"/>
 public Color32 this[VoxelLocation location]
 {
   get 
   {
     return this[location.X, location.Y, location.Z];
   }
   set 
   {
     this[location.X, location.Y, location.Z] = value;
   }
 }
    /// <see cref="org.rnp.voxel.walker.IWalkerState"/>
    public IVoxelMesh Next()
    {
      if (this._nodeKeys.Count <= 0)
      {
        this._lastKey = null;
        return null;
      }

      this._lastKey = this._nodeKeys.ElementAt(0);
      this._nodeKeys.Remove(this._lastKey);

      return this._node.GetChild(this._lastKey.X, this._lastKey.Y, this._lastKey.Z);
    }
 /// <summary>
 ///   Translate an octree leaf.
 /// </summary>
 /// <param name="root"></param>
 /// <param name="mesh"></param>
 public void TranslateLeaf(VoxelLocation root, IVoxelMesh mesh)
 {
   VoxelLocation start = mesh.Start;
   VoxelLocation end = mesh.End;
   VoxelLocation finalLocation = new VoxelLocation();
   
   for (int x = start.X; x < end.X; ++x)
   {
     for (int y = start.Y; y < end.Y; ++y)
     {
       for (int z = start.Z; z < end.Z; ++z)
       {
         finalLocation.Set(root).Add(x,y,z);
         this.Translate(finalLocation, this.VoxelMesh.Mesh, finalLocation);
       }
     }
   }
 }
    public void TranslateMap(VoxelLocation start, IMapVoxelMesh map)
    {

      VoxelLocation chunckStart = new VoxelLocation();
      foreach (VoxelLocation chunckLocation in map.Keys())
      {
        IVoxelMesh chunck = map.GetChild(chunckLocation);
        chunckStart.Set(chunckLocation).Mul(map.ChildWidth, map.ChildHeight, map.ChildDepth);
        
        if (chunck is IOctreeVoxelMesh)
        {
          this.TranslateTree(chunckStart, (IOctreeVoxelMesh)chunck);
        }
        else
        {
          this.TranslateLeaf(chunckStart, chunck);
        }
      }
    }
    private void Initialize(RaycastHit result)
    {
      GameObject hittedObject = result.collider.gameObject;
      VoxelMesh mesh = hittedObject.GetComponent<VoxelMesh>(); // maybe use an interface and search the collider ?

      this._isVoxelMesh = mesh != null;
      this._hittedMesh = null;
      this._hittedInnerVoxel = null;
      this._hittedOutVoxel = null;

      if(mesh != null)
      {
        this._hittedMesh = mesh;
        Vector3 localized = hittedObject.transform.worldToLocalMatrix.MultiplyPoint3x4(result.point);
        this._hittedInnerVoxel = new VoxelLocation(localized - (result.normal / 2));
        this._hittedOutVoxel = new VoxelLocation(localized + (result.normal / 2));
      }

      this._hittedCollider = hittedObject.GetComponent<VoxelMeshCollider>();
    }
Пример #12
0
    public void DebugMap(VoxelLocation start, IMapVoxelMesh map, int startDeep, int endDeep)
    {
      this.DebugLeaf(start, map, startDeep, endDeep);

      VoxelLocation chunckStart = new VoxelLocation();
      foreach (VoxelLocation chunckLocation in map.Keys())
      {
        IVoxelMesh chunck = map.GetChild(chunckLocation);
        chunckStart.Set(chunckLocation).Mul(map.ChildWidth, map.ChildHeight, map.ChildDepth);

        if (chunck is IOctreeVoxelMesh)
        {
          this.DebugTree(chunckStart, (IOctreeVoxelMesh)chunck, startDeep - 1, endDeep - 1);
        }
        else
        {
          this.DebugLeaf(chunckStart, chunck, startDeep - 1, endDeep - 1);
        }
      }
    }
    /// <summary>
    ///   Debug a tree node.
    /// </summary>
    /// <param name="root"></param>
    /// <param name="octree"></param>
    public void DebugTree(VoxelLocation root, IOctreeVoxelMesh octree, int minDeep, int maxDeep)
    {
      if (maxDeep <= 0) return;

      if (minDeep <= 0)
      {
        this.DrawCube(root, octree);
      }

      VoxelLocation nextRoot = new VoxelLocation();
      for (int i = 0; i < 2; ++i)
      {
        for (int j = 0; j < 2; ++j)
        {
          for (int k = 0; k < 2; ++k)
          {
            IVoxelMesh child = octree.GetChild(i, j, k);
            if (child != null)
            {
              nextRoot.X = root.X + i * octree.Width / 2;
              nextRoot.Y = root.Y + j * octree.Height / 2;
              nextRoot.Z = root.Z + k * octree.Depth / 2;

              if (child is IOctreeVoxelMesh)
              {
                this.DebugTree(nextRoot, (IOctreeVoxelMesh) child, minDeep - 1, maxDeep - 1);
              }
              else
              {
                this.DebugLeaf(nextRoot, child, minDeep - 1, maxDeep - 1);
              }
            }
          }
        }
      }
    }
Пример #14
0
 /// <summary>
 ///   Keep a submesh of an existing mesh.
 /// </summary>
 /// <param name="parent"></param>
 /// <param name="start"></param>
 /// <param name="dimensions"></param>
 public SubMesh(IVoxelMesh parent, VoxelLocation start, IDimensions3D dimensions) : base()
 {
   this._dimensions = dimensions.Copy();
   this._parentMesh = parent;
   this._start = new VoxelLocation(start);
 }
 /// <see cref="org.rnp.voxel.mesh.IVoxelMesh"/>
 public virtual void Copy(VoxelLocation start, IDimensions3D size, VoxelLocation where, IVoxelMesh toCopy)
 {
   for (int x = 0; x < size.Width; ++x)
   {
     for (int y = 0; y < size.Height; ++y)
     {
       for (int z = 0; z < size.Depth; ++z)
       {
         this[where.X + x, where.Y + y, where.Z + z] = toCopy[start.X + x, start.Y + y, start.Z + z];
       }
     }
   }
 }
 /// <see cref="org.rnp.voxel.mesh.IVoxelMesh"/>
 public virtual void Fill(VoxelLocation start, IDimensions3D size, Color color)
 {
   for (int x = 0; x < size.Width; ++x)
   {
     for(int y = 0; y < size.Height; ++y)
     {
       for(int z = 0; z < size.Depth; ++z)
       {
         this[x + start.X, y + start.Y, z + start.Z] = color;
       }
     }
   }
 }
 /// <see cref="org.rnp.voxel.mesh.IVoxelMesh"/>
 public virtual bool IsEmpty(VoxelLocation location)
 {
   return !this.Contains(location) || this[location].a == 255;
 }
    /// <see cref="org.rnp.voxel.mesh.IVoxelMesh"/>
    public virtual void Copy(VoxelLocation from, VoxelLocation to, VoxelLocation where, IVoxelMesh toCopy)
    {
      Dimensions3D size = new Dimensions3D(
        to.X - from.X, to.Y - from.Y, to.Z - from.Z
      );

      this.Copy(from, size, where, toCopy);
    }
 /// <summary>
 ///   Create a copy of an existing class.
 /// </summary>
 /// <param name="toCopy"></param>
 public WalkerOctreeState(WalkerOctreeState toCopy)
 {
   this._node = toCopy._node;
   this._cursor = toCopy._cursor;
   this._location = new VoxelLocation(toCopy._location);
 }
 /// <summary>
 ///   Copy an existing voxel mesh.
 /// </summary>
 /// <param name="toCopy"></param>
 public AbsoluteVoxelMesh(IAbsoluteVoxelMesh toCopy)
   : base()
 {
   this._parentMesh = toCopy.RelativeMesh;
   this._start = new VoxelLocation(toCopy.Start);
 }
Пример #21
0
 /// <summary>
 ///   Copy an existing voxel mesh.
 /// </summary>
 /// <param name="toCopy"></param>
 public SubMesh(ISubMesh toCopy)
   : base()
 {
   this._dimensions = new Dimensions3D(toCopy.Width, toCopy.Height, toCopy.Depth);
   this._parentMesh = toCopy.ParentMesh;
   this._start = new VoxelLocation(toCopy.Offset);
 }
 /// <summary>
 ///   Create a new walker state.
 /// </summary>
 /// <param name="node"></param>
 public WalkerOctreeState(IOctreeVoxelMesh node)
 {
   this._node = node;
   this._cursor = -1;
   this._location = VoxelLocation.Zero;
 }
 /// <see cref="org.rnp.voxel.mesh.IVoxelMesh"/>
 public virtual bool Contains(VoxelLocation location)
 {
   return this.Contains(location.X, location.Y, location.Z);
 }
Пример #24
0
    /// <see cref="org.rnp.voxel.mesh.map.IMapVoxelMesh"/>
    public VoxelLocation ToLocale(int x, int y, int z)
    {
      VoxelLocation location = new VoxelLocation(
        x % this.ChildWidth, y % this.ChildHeight, z % this.ChildDepth
      );

      if (location.X < 0) location.X += this.ChildWidth;
      if (location.Y < 0) location.Y += this.ChildHeight;
      if (location.Z < 0) location.Z += this.ChildDepth;

      return location;
    }
 /// <summary>
 ///   Locate a voxel mesh.
 /// </summary>
 /// <param name="parent"></param>
 /// <param name="start"></param>
 public AbsoluteVoxelMesh(IVoxelMesh parent, VoxelLocation start) : base()
 {
   this._parentMesh = parent;
   this._start = new VoxelLocation(start);
 }
Пример #26
0
    /// <summary>
    ///   Get the chunck that contains the specified location.
    /// </summary>
    /// <param name="x"></param>
    /// <param name="y"></param>
    /// <param name="z"></param>
    /// <returns></returns>
    private void DeleteChunckAt(int x, int y, int z)
    {
      VoxelLocation chunckLocation = this.ToChunckLocation(x, y, z);

      this._chunks.Remove(chunckLocation);

      VoxelLocation max = new VoxelLocation(chunckLocation);
      VoxelLocation min = new VoxelLocation(chunckLocation);
      max.Add(1, 1, 1).Mul(this.ChildWidth, this.ChildHeight, this.ChildDepth);
      min.Mul(this.ChildWidth, this.ChildHeight, this.ChildDepth);

      if(min.X == this._min.X || min.Y == this._min.Y || min.Z == this._min.Z ||
         max.X == this._max.X || max.Y == this._max.Y || max.Z == this._max.Z)
      {
        this.EvaluateSize();
      }
    }
 /// <summary>
 ///   Locate a voxel mesh.
 /// </summary>
 /// <param name="parent"></param>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <param name="z"></param>
 public AbsoluteVoxelMesh(IVoxelMesh parent, int x, int y, int z)
   : base()
 {
   this._parentMesh = parent;
   this._start = new VoxelLocation(x, y, z);
 }
Пример #28
0
    /// <summary>
    ///   Create a chunck at a specified location.
    /// </summary>
    /// <param name="chunckLocation"></param>
    /// <returns></returns>
    private IVoxelMesh CreateChunck(VoxelLocation chunckLocation)
    {
      IVoxelMesh chunck = this._chunkBuilder.Build();
      this._chunks[chunckLocation] = chunck;

      VoxelLocation max = new VoxelLocation(chunckLocation);
      VoxelLocation min = new VoxelLocation(chunckLocation);
      max.Add(1, 1, 1).Mul(this.ChildWidth, this.ChildHeight, this.ChildDepth);
      min.Mul(this.ChildWidth, this.ChildHeight, this.ChildDepth);

      if (min.X < this._min.X) this._min.X = min.X;
      if (min.Y < this._min.Y) this._min.Y = min.Y;
      if (min.Z < this._min.Z) this._min.Z = min.Z;

      if (max.X > this._max.X) this._max.X = max.X;
      if (max.Y > this._max.Y) this._max.Y = max.Y;
      if (max.Z > this._max.Z) this._max.Z = max.Z;

      return chunck;
    }
Пример #29
0
 /// <see cref="org.rnp.voxel.mesh.map.IMapVoxelMesh"/>
 public IReadonlyVoxelMesh GetChild(VoxelLocation location)
 {
   if (this._chunks.ContainsKey(location))
   {
     return this._chunks[location].ReadOnly();
   }
   else
   {
     return null;
   }
 }
Пример #30
0
 /// <summary>
 ///   Create a custom voxel mesh.
 /// </summary>
 /// 
 /// <param name="width"></param>
 /// <param name="height"></param>
 /// <param name="depth"></param>
 public SubMesh(IVoxelMesh parent, IDimensions3D dimensions) : base()
 {
   this._dimensions = dimensions.Copy();
   this._parentMesh = parent;
   this._start = VoxelLocation.Zero;
 }
Пример #31
0
 /// <summary>
 ///   An empty default MapVoxelMesh.
 /// </summary>
 public MapVoxelMesh()
 {
   this._chunks = new Dictionary<VoxelLocation, IVoxelMesh>();
   this._chunkBuilder = new OctreeChunckBuilder();
   this._max = new VoxelLocation();
   this._min = new VoxelLocation();
 }