Skip to content

Commit

Permalink
Merge branch 'feature/filetovoxcore'
Browse files Browse the repository at this point in the history
  • Loading branch information
Zarbuz committed Sep 16, 2021
2 parents 282299a + 9363b11 commit c4a6221
Show file tree
Hide file tree
Showing 77 changed files with 2,947 additions and 2,793 deletions.
26 changes: 14 additions & 12 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
SchematicToVox/bin/
SchematicToVox/obj/
.vs/

Build/

SchematicToVoxCore/bin/
SchematicToVoxCore/obj/
SchematicToVoxCore/Properties/launchSettings.json
FileToVoxCommon/bin/
FileToVoxCommon/obj/
OldBuild/
SchematicToVox/bin/
SchematicToVox/obj/
.vs/

Build/

SchematicToVoxCore/bin/
SchematicToVoxCore/obj/
SchematicToVoxCore/Properties/launchSettings.json
FileToVoxCommon/bin/
FileToVoxCommon/obj/
OldBuild/
FileToVoxCore/obj/
FileToVoxCore/bin/
16 changes: 15 additions & 1 deletion FileToVox.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ VisualStudioVersion = 16.0.29418.71
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FileToVox", "SchematicToVoxCore\FileToVox.csproj", "{F24C61D3-C2D6-4208-BB30-79236DA8019E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FileToVoxCommon", "FileToVoxCommon\FileToVoxCommon.csproj", "{F0315853-7D9C-43CA-90CB-B30F1639F216}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FileToVoxCommon", "FileToVoxCommon\FileToVoxCommon.csproj", "{F0315853-7D9C-43CA-90CB-B30F1639F216}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FileToVoxCore", "FileToVoxCore\FileToVoxCore.csproj", "{8E2410B1-D0C5-458D-82D2-B884D0EF0596}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -41,6 +43,18 @@ Global
{F0315853-7D9C-43CA-90CB-B30F1639F216}.Release|x64.Build.0 = Release|Any CPU
{F0315853-7D9C-43CA-90CB-B30F1639F216}.Release|x86.ActiveCfg = Release|Any CPU
{F0315853-7D9C-43CA-90CB-B30F1639F216}.Release|x86.Build.0 = Release|Any CPU
{8E2410B1-D0C5-458D-82D2-B884D0EF0596}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8E2410B1-D0C5-458D-82D2-B884D0EF0596}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8E2410B1-D0C5-458D-82D2-B884D0EF0596}.Debug|x64.ActiveCfg = Debug|Any CPU
{8E2410B1-D0C5-458D-82D2-B884D0EF0596}.Debug|x64.Build.0 = Debug|Any CPU
{8E2410B1-D0C5-458D-82D2-B884D0EF0596}.Debug|x86.ActiveCfg = Debug|Any CPU
{8E2410B1-D0C5-458D-82D2-B884D0EF0596}.Debug|x86.Build.0 = Debug|Any CPU
{8E2410B1-D0C5-458D-82D2-B884D0EF0596}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8E2410B1-D0C5-458D-82D2-B884D0EF0596}.Release|Any CPU.Build.0 = Release|Any CPU
{8E2410B1-D0C5-458D-82D2-B884D0EF0596}.Release|x64.ActiveCfg = Release|Any CPU
{8E2410B1-D0C5-458D-82D2-B884D0EF0596}.Release|x64.Build.0 = Release|Any CPU
{8E2410B1-D0C5-458D-82D2-B884D0EF0596}.Release|x86.ActiveCfg = Release|Any CPU
{8E2410B1-D0C5-458D-82D2-B884D0EF0596}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
25 changes: 25 additions & 0 deletions FileToVoxCore/Extensions/FctExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Drawing;

namespace FileToVoxCore.Extensions
{
public static class FctExtensions
{
public static Color UIntToColor(this uint color)
{
byte a = (byte)(color >> 24);
byte r = (byte)(color >> 16);
byte g = (byte)(color >> 8);
byte b = (byte)(color >> 0);
return Color.FromArgb(a, r, g, b);
}

public static uint ColorToUInt(this Color color)
{
return (uint)((color.A << 24) | (color.R << 16) |
(color.G << 8) | (color.B << 0));
}

}


}
25 changes: 25 additions & 0 deletions FileToVoxCore/FileToVoxCore.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>net5.0</TargetFramework>
<AssemblyName>FileToVoxCore</AssemblyName>
<RootNamespace>FileToVoxCore</RootNamespace>
<Version>1.0.2</Version>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.Drawing.Common" Version="5.0.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\FileToVoxCommon\FileToVoxCommon.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="Schematics\config.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions FileToVoxCore/FileToVoxCore.csproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<_LastSelectedProfileId>E:\Documents\FileToVox\FileToVoxCore\Properties\PublishProfiles\FolderProfile.pubxml</_LastSelectedProfileId>
</PropertyGroup>
</Project>
14 changes: 14 additions & 0 deletions FileToVoxCore/Properties/PublishProfiles/FolderProfile.pubxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<PublishDir>bin\Release\net5.0\publish\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<TargetFramework>net5.0</TargetFramework>
<SelfContained>false</SelfContained>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using FileToVox.Utils;
using SchematicToVoxCore.Extensions;
using FileToVoxCore.Extensions;
using FileToVoxCore.Utils;

namespace FileToVox.Schematics
namespace FileToVoxCore.Schematics
{
public class PaletteSchematicConverter
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
namespace FileToVox.Schematics
{
public class RawSchematic
{
public short Width;
public short Heigth;
public short Length;
public byte[] Blocks;
public byte[] Data;
}
}
namespace FileToVoxCore.Schematics
{
public class RawSchematic
{
public short Width;
public short Heigth;
public short Length;
public byte[] Blocks;
public byte[] Data;
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using FileToVox.Generator.Terrain.Utility;
using FileToVox.Schematics.Tools;
using SchematicToVoxCore.Extensions;
using System;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Runtime.CompilerServices;
using FileToVoxCommon.Generator.Heightmap.Data;
using FileToVoxCore.Extensions;
using FileToVoxCore.Schematics.Tools;
using FileToVoxCore.Utils;

namespace FileToVox.Schematics
namespace FileToVoxCore.Schematics
{
public class Region
{
Expand Down Expand Up @@ -53,6 +53,8 @@ public class Schematic
public const int MAX_WORLD_HEIGHT = 1000;
public const int MAX_WORLD_LENGTH = 2000;
public const int MAX_COLORS_IN_PALETTE = 256;
public static int CHUNK_SIZE = 128;
public static bool DEBUG;

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static long GetVoxelIndex(int x, int y, int z)
Expand Down Expand Up @@ -249,7 +251,7 @@ public bool ContainsVoxel(int x, int y, int z)

public bool GetVoxel(int x, int y, int z, out Voxel voxel)
{
FastMath.FloorToInt(x / Program.CHUNK_SIZE, y / Program.CHUNK_SIZE, z / Program.CHUNK_SIZE, out int chunkX, out int chunkY, out int chunkZ);
FastMath.FloorToInt(x / CHUNK_SIZE, y / CHUNK_SIZE, z / CHUNK_SIZE, out int chunkX, out int chunkY, out int chunkZ);

long chunkIndex = GetVoxelIndex(chunkX, chunkY, chunkZ);
long voxelIndex = GetVoxelIndex(x, y, z);
Expand Down Expand Up @@ -299,9 +301,9 @@ private void CreateAllRegions()
{
RegionDict = new Dictionary<long, Region>();

int worldRegionX = (int)Math.Ceiling((decimal)MAX_WORLD_WIDTH / Program.CHUNK_SIZE);
int worldRegionY = (int)Math.Ceiling((decimal)MAX_WORLD_HEIGHT / Program.CHUNK_SIZE);
int worldRegionZ =(int)Math.Ceiling((decimal)MAX_WORLD_LENGTH / Program.CHUNK_SIZE);
int worldRegionX = (int)Math.Ceiling((decimal)MAX_WORLD_WIDTH / CHUNK_SIZE);
int worldRegionY = (int)Math.Ceiling((decimal)MAX_WORLD_HEIGHT / CHUNK_SIZE);
int worldRegionZ =(int)Math.Ceiling((decimal)MAX_WORLD_LENGTH / CHUNK_SIZE);

int countSize = worldRegionX * worldRegionY * worldRegionZ;

Expand All @@ -311,13 +313,13 @@ private void CreateAllRegions()
int y = (i / worldRegionX) % worldRegionY;
int z = i / (worldRegionX * worldRegionY);

RegionDict[GetVoxelIndex(x, y, z)] = new Region(x * Program.CHUNK_SIZE, y * Program.CHUNK_SIZE, z * Program.CHUNK_SIZE);
RegionDict[GetVoxelIndex(x, y, z)] = new Region(x * CHUNK_SIZE, y * CHUNK_SIZE, z * CHUNK_SIZE);
}
}

private void AddUsageForRegion(int x, int y, int z, uint color)
{
FastMath.FloorToInt(x / Program.CHUNK_SIZE, y / Program.CHUNK_SIZE, z / Program.CHUNK_SIZE, out int chunkX, out int chunkY, out int chunkZ);
FastMath.FloorToInt(x / CHUNK_SIZE, y / CHUNK_SIZE, z / CHUNK_SIZE, out int chunkX, out int chunkY, out int chunkZ);

long chunkIndex = GetVoxelIndex(chunkX, chunkY, chunkZ);
long voxelIndex = GetVoxelIndex(x, y, z);
Expand All @@ -327,7 +329,7 @@ private void AddUsageForRegion(int x, int y, int z, uint color)

private void ReplaceUsageForRegion(int x, int y, int z, uint color)
{
FastMath.FloorToInt(x / Program.CHUNK_SIZE, y / Program.CHUNK_SIZE, z / Program.CHUNK_SIZE, out int chunkX, out int chunkY, out int chunkZ);
FastMath.FloorToInt(x / CHUNK_SIZE, y / CHUNK_SIZE, z / CHUNK_SIZE, out int chunkX, out int chunkY, out int chunkZ);

long chunkIndex = GetVoxelIndex(chunkX, chunkY, chunkZ);
long voxelIndex = GetVoxelIndex(x, y, z);
Expand All @@ -340,9 +342,9 @@ private void ReplaceUsageForRegion(int x, int y, int z, uint color)

private void RemoveUsageForRegion(int x, int y, int z)
{
int chunkX = x / Program.CHUNK_SIZE;
int chunkY = y / Program.CHUNK_SIZE;
int chunkZ = z / Program.CHUNK_SIZE;
int chunkX = x / CHUNK_SIZE;
int chunkY = y / CHUNK_SIZE;
int chunkZ = z / CHUNK_SIZE;
long chunkIndex = GetVoxelIndex(chunkX, chunkY, chunkZ);
long voxelIndex = GetVoxelIndex(x, y, z);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using FileToVox.Utils;

namespace FileToVox.Schematics.Tools
namespace FileToVoxCore.Schematics.Tools
{
public struct Vector3 : IEquatable<Vector3>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,59 +1,58 @@
using System;
using System.Collections.Generic;

namespace FileToVox.Schematics.Tools
{
public struct Vector3Int : IEquatable<Vector3Int>
{
public int X;
public int Y;
public int Z;

// Creates a new vector with given x, y, z components.
public Vector3Int(int x, int y, int z) { this.X = x; this.Y = y; this.Z = z; }
// Creates a new vector with given x, y components and sets /z/ to zero.
public Vector3Int(int x, int y) { this.X = x; this.Y = y; Z = 0; }

public static Vector3Int zero { get; } = new Vector3Int(0, 0, 0);
public int magnitude => (int)Math.Sqrt(X * X + Y * Y + Z * Z);
public static int SqrMagnitude(Vector3Int vector) { return vector.X * vector.X + vector.Y * vector.Y + vector.Z * vector.Z; }

// Subtracts one vector from another.
public static Vector3Int operator -(Vector3Int a, Vector3Int b) { return new Vector3Int(a.X - b.X, a.Y - b.Y, a.Z - b.Z); }
// Adds two vectors.
public static Vector3Int operator +(Vector3Int a, Vector3Int b) { return new Vector3Int(a.X + b.X, a.Y + b.Y, a.Z + b.Z); }
// Subtracts one vector from another.
// Negates a vector.
public static Vector3Int operator -(Vector3Int a) { return new Vector3Int(-a.X, -a.X, -a.Z); }
// Multiplies a vector by a number.
public static Vector3Int operator *(Vector3Int a, int d) { return new Vector3Int(a.X * d, a.Y * d, a.Z * d); }
// Multiplies a vector by a number.
public static Vector3Int operator *(int d, Vector3Int a) { return new Vector3Int(a.X * d, a.Y * d, a.Z * d); }
// Divides a vector by a number.
public static Vector3Int operator /(Vector3Int a, int d) { return new Vector3Int(a.X / d, a.Y / d, a.Z / d); }

public override string ToString()
{
return string.Format("({0:F1}, {1:F1}, {2:F1})", X, Y, Z);
}

public bool Equals(Vector3Int other)
{
return X.Equals(other.X) && Y.Equals(other.Y) && Z.Equals(other.Z);
}

public override bool Equals(object other)
{
if (!(other is Vector3Int)) return false;

return Equals((Vector3Int)other);
}

public override int GetHashCode()
{
return X.GetHashCode() ^ (Y.GetHashCode() << 2) ^ (Z.GetHashCode() >> 2);
}

}

}
using System;

namespace FileToVoxCore.Schematics.Tools
{
public struct Vector3Int : IEquatable<Vector3Int>
{
public int X;
public int Y;
public int Z;

// Creates a new vector with given x, y, z components.
public Vector3Int(int x, int y, int z) { this.X = x; this.Y = y; this.Z = z; }
// Creates a new vector with given x, y components and sets /z/ to zero.
public Vector3Int(int x, int y) { this.X = x; this.Y = y; Z = 0; }

public static Vector3Int zero { get; } = new Vector3Int(0, 0, 0);
public int magnitude => (int)Math.Sqrt(X * X + Y * Y + Z * Z);
public static int SqrMagnitude(Vector3Int vector) { return vector.X * vector.X + vector.Y * vector.Y + vector.Z * vector.Z; }

// Subtracts one vector from another.
public static Vector3Int operator -(Vector3Int a, Vector3Int b) { return new Vector3Int(a.X - b.X, a.Y - b.Y, a.Z - b.Z); }
// Adds two vectors.
public static Vector3Int operator +(Vector3Int a, Vector3Int b) { return new Vector3Int(a.X + b.X, a.Y + b.Y, a.Z + b.Z); }
// Subtracts one vector from another.
// Negates a vector.
public static Vector3Int operator -(Vector3Int a) { return new Vector3Int(-a.X, -a.X, -a.Z); }
// Multiplies a vector by a number.
public static Vector3Int operator *(Vector3Int a, int d) { return new Vector3Int(a.X * d, a.Y * d, a.Z * d); }
// Multiplies a vector by a number.
public static Vector3Int operator *(int d, Vector3Int a) { return new Vector3Int(a.X * d, a.Y * d, a.Z * d); }
// Divides a vector by a number.
public static Vector3Int operator /(Vector3Int a, int d) { return new Vector3Int(a.X / d, a.Y / d, a.Z / d); }

public override string ToString()
{
return string.Format("({0:F1}, {1:F1}, {2:F1})", X, Y, Z);
}

public bool Equals(Vector3Int other)
{
return X.Equals(other.X) && Y.Equals(other.Y) && Z.Equals(other.Z);
}

public override bool Equals(object other)
{
if (!(other is Vector3Int)) return false;

return Equals((Vector3Int)other);
}

public override int GetHashCode()
{
return X.GetHashCode() ^ (Y.GetHashCode() << 2) ^ (Z.GetHashCode() >> 2);
}

}

}

0 comments on commit c4a6221

Please sign in to comment.