コード例 #1
0
 /// <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);
       }
     }
   }
 }
コード例 #2
0
        static public void Save(IVoxelMesh vm, string path)
        {
            if (string.IsNullOrEmpty(path)) return;

            path = FileUtil.GetProjectRelativePath(path);

            // Create a file to write to.
            using (BinaryWriter bw = new BinaryWriter(File.Open(path, FileMode.Create)))
            {
                bw.Write(vm.Width);
                bw.Write(vm.Height);
                bw.Write(vm.Depth);

                IVoxelLocation Start = vm.Start;
                IVoxelLocation End = vm.End;

                for (int w = Start.X; w < End.X; w++)
                {
                    for (int h = Start.Y; h < End.Y; h++)
                    {
                        for (int d = Start.Z; d < End.Z; d++)
                        {
                            bw.Write(w);
                            bw.Write(h);
                            bw.Write(d);
                            bw.Write(vm[w, h, d].r);
                            bw.Write(vm[w, h, d].g);
                            bw.Write(vm[w, h, d].b);
                            bw.Write(vm[w, h, d].a);
                        }
                    }
                }

                bw.Close();
            }

        } 
コード例 #3
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;
 }
コード例 #4
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);
 }
コード例 #5
0
 /// <summary>
 ///   Copy an existing voxel mesh.
 /// </summary>
 /// <param name="toCopy"></param>
 public ArrayVoxelMesh(IVoxelMesh toCopy) : base()
 {
   this._dimensions = new Dimensions3D(toCopy.Width, toCopy.Height, toCopy.Depth);
   this._datas = new Color32[
     this.Width,
     this.Height,
     this.Depth
   ];
   this.emptyVoxels = this.Width * this.Height * this.Depth;
   this.Copy(toCopy.Start, toCopy.End, VoxelLocation.Zero, toCopy);
 }
コード例 #6
0
 /// <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);
 }
コード例 #7
0
 /// <summary>
 ///   Translate a voxel of the mesh.
 /// </summary>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <param name="z"></param>
 protected void Translate(VoxelLocation finalLocation, IVoxelMesh mesh, VoxelLocation voxelLocation)
 {
   if (!mesh.IsEmpty(voxelLocation))
   {
     if (mesh.IsEmpty(voxelLocation.X, voxelLocation.Y + 1, voxelLocation.Z))
     {
       this.TranslateUp(finalLocation, mesh[voxelLocation]);
     }
     if (mesh.IsEmpty(voxelLocation.X, voxelLocation.Y - 1, voxelLocation.Z))
     {
       this.TranslateDown(finalLocation, mesh[voxelLocation]);
     }
     if (mesh.IsEmpty(voxelLocation.X - 1, voxelLocation.Y, voxelLocation.Z))
     {
       this.TranslateLeft(finalLocation, mesh[voxelLocation]);
     }
     if (mesh.IsEmpty(voxelLocation.X + 1, voxelLocation.Y, voxelLocation.Z))
     {
       this.TranslateRight(finalLocation, mesh[voxelLocation]);
     }
     if (mesh.IsEmpty(voxelLocation.X, voxelLocation.Y, voxelLocation.Z + 1))
     {
       this.TranslateFront(finalLocation, mesh[voxelLocation]);
     }
     if (mesh.IsEmpty(voxelLocation.X, voxelLocation.Y, voxelLocation.Z - 1))
     {
       this.TranslateBack(finalLocation, mesh[voxelLocation]);
     }
   }
 }
コード例 #8
0
    /// <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);
    }
コード例 #9
0
    /// <summary>
    ///   Copy an existing voxel mesh.
    /// </summary>
    /// <param name="toCopy"></param>
    public OctreeVoxelMesh(IVoxelMesh toCopy)
      : base()
    {
      this._childs = new IVoxelMesh[2, 2, 2];
      this._format = OctreeVoxelMeshFormat.GetFormat(toCopy.Width, toCopy.Height, toCopy.Depth);
      this._builder = new OctreeNodeBuilder();

      this.Copy(toCopy.Start, toCopy.End, VoxelLocation.Zero, toCopy);
    }
コード例 #10
0
    /// <summary>
    ///   Copy an existing VoxelMesh with a custom chunck configuration.
    /// </summary>
    /// <param name="toCopy"></param>
    /// <param name="builder"></param>
    public MapVoxelMesh(IVoxelMesh toCopy, IChunckBuilder builder)
    {
      this._chunks = new Dictionary<VoxelLocation, IVoxelMesh>();
      this._chunkBuilder = builder;

      this.Copy(toCopy.Start, toCopy.End, toCopy.Start, toCopy);
      this.EvaluateSize();
    }
コード例 #11
0
    /// <summary>
    ///   Debug a tree leaf.
    /// </summary>
    /// <param name="root"></param>
    /// <param name="mesh"></param>
    public void DebugLeaf(VoxelLocation root, IVoxelMesh mesh, int minDeep, int maxDeep)
    {
      if (maxDeep <= 0) return;

      if (minDeep <= 0)
      {
        this.DrawCube(root, mesh);
      }
    }
コード例 #12
0
    /// <summary>
    ///   Draw a debug cube.
    /// </summary>
    /// <param name="root"></param>
    /// <param name="dimensions"></param>
    private void DrawCube(VoxelLocation root, IVoxelMesh dimensions)
    {
      Vector3 toMid = new Vector3(
        dimensions.Width / 2f,
        dimensions.Height / 2f,
        dimensions.Depth / 2f
      );

      Gizmos.DrawWireCube(
        root + toMid,
        new Vector3(
          dimensions.Width,
          dimensions.Height,
          dimensions.Depth
        )  
      );
    }
コード例 #13
0
    protected void CreateBoxColliderFor(IVoxelMesh mesh)
    {
      BoxCollider collider = this.GetCollider();

      Vector3 start = mesh.Start;
      Vector3 end = mesh.End;

      collider.center = (start + end) / 2;
      collider.size = (end - start);

      this._colliders.Add(collider);
    }
コード例 #14
0
 /// <summary>
 ///   Create a copy of an existing class.
 /// </summary>
 /// <param name="toCopy"></param>
 public WalkerAsOctreeState(WalkerAsOctreeState toCopy)
 {
   this._node = toCopy._node;
   this._cursor = toCopy._cursor;
   this._location = new VoxelLocation(toCopy._location);
 }
コード例 #15
0
 /// <summary>
 ///   Create a new walker state.
 /// </summary>
 /// <param name="node"></param>
 public WalkerAsOctreeState(IVoxelMesh node)
 {
   this._node = node;
   this._cursor = -1;
   this._location = VoxelLocation.Zero;
 }
コード例 #16
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);
 }
コード例 #17
0
 /// <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);
 }
コード例 #18
0
 /// <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);
 }
コード例 #19
0
 /// <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];
       }
     }
   }
 }
コード例 #20
0
 /// <summary>
 ///   Create a new UnmodifiableVoxelMesh exception.
 /// </summary>
 /// <param name="UnmodifiableMesh"></param>
 public UnmodifiableVoxelMeshException(IVoxelMesh UnmodifiableMesh)
   : base("Trying to modify a ReadOnly voxel mesh.") 
 {
   this.UnmodifiableMesh = UnmodifiableMesh;
 }