Clean up style of files affected by the last commit.
This commit is contained in:
committed by
RoosterDragon
parent
f0f02dff5c
commit
9cbac2d5e1
@@ -34,14 +34,16 @@ namespace OpenRA.Graphics
|
||||
|
||||
public sealed class VoxelLoader : IDisposable
|
||||
{
|
||||
SheetBuilder sheetBuilder;
|
||||
static readonly float[] ChannelSelect = { 0.75f, 0.25f, -0.25f, -0.75f };
|
||||
|
||||
Cache<Pair<string,string>, Voxel> voxels;
|
||||
readonly List<Vertex[]> vertices = new List<Vertex[]>();
|
||||
readonly Cache<Pair<string, string>, Voxel> voxels;
|
||||
IVertexBuffer<Vertex> vertexBuffer;
|
||||
List<Vertex[]> vertices;
|
||||
int totalVertexCount;
|
||||
int cachedVertexCount;
|
||||
|
||||
SheetBuilder sheetBuilder;
|
||||
|
||||
static SheetBuilder CreateSheetBuilder()
|
||||
{
|
||||
var allocated = false;
|
||||
@@ -58,7 +60,7 @@ namespace OpenRA.Graphics
|
||||
|
||||
public VoxelLoader()
|
||||
{
|
||||
voxels = new Cache<Pair<string,string>, Voxel>(LoadFile);
|
||||
voxels = new Cache<Pair<string, string>, Voxel>(LoadFile);
|
||||
vertices = new List<Vertex[]>();
|
||||
totalVertexCount = 0;
|
||||
cachedVertexCount = 0;
|
||||
@@ -66,29 +68,28 @@ namespace OpenRA.Graphics
|
||||
sheetBuilder = CreateSheetBuilder();
|
||||
}
|
||||
|
||||
static float[] channelSelect = { 0.75f, 0.25f, -0.25f, -0.75f };
|
||||
Vertex[] GenerateSlicePlane(int su, int sv, Func<int,int,VxlElement> first, Func<int,int,VxlElement> second, Func<int, int, float[]> coord)
|
||||
Vertex[] GenerateSlicePlane(int su, int sv, Func<int, int, VxlElement> first, Func<int, int, VxlElement> second, Func<int, int, float[]> coord)
|
||||
{
|
||||
var colors = new byte[su*sv];
|
||||
var normals = new byte[su*sv];
|
||||
var colors = new byte[su * sv];
|
||||
var normals = new byte[su * sv];
|
||||
|
||||
var c = 0;
|
||||
for (var v = 0; v < sv; v++)
|
||||
for (var u = 0; u < su; u++)
|
||||
{
|
||||
var voxel = first(u,v) ?? second(u,v);
|
||||
colors[c] = voxel == null ? (byte)0 : voxel.Color;
|
||||
normals[c] = voxel == null ? (byte)0 : voxel.Normal;
|
||||
c++;
|
||||
}
|
||||
{
|
||||
var voxel = first(u, v) ?? second(u, v);
|
||||
colors[c] = voxel == null ? (byte)0 : voxel.Color;
|
||||
normals[c] = voxel == null ? (byte)0 : voxel.Normal;
|
||||
c++;
|
||||
}
|
||||
|
||||
var s = sheetBuilder.Allocate(new Size(su, sv));
|
||||
Util.FastCopyIntoChannel(s, 0, colors);
|
||||
Util.FastCopyIntoChannel(s, 1, normals);
|
||||
s.sheet.CommitData();
|
||||
|
||||
var channelP =channelSelect[(int)s.channel];
|
||||
var channelC = channelSelect[(int)s.channel + 1];
|
||||
var channelP = ChannelSelect[(int)s.channel];
|
||||
var channelC = ChannelSelect[(int)s.channel + 1];
|
||||
return new Vertex[4]
|
||||
{
|
||||
new Vertex(coord(0, 0), s.left, s.top, channelP, channelC),
|
||||
@@ -100,7 +101,7 @@ namespace OpenRA.Graphics
|
||||
|
||||
IEnumerable<Vertex[]> GenerateSlicePlanes(VxlLimb l)
|
||||
{
|
||||
Func<int,int,int,VxlElement> get = (x,y,z) =>
|
||||
Func<int, int, int, VxlElement> get = (x, y, z) =>
|
||||
{
|
||||
if (x < 0 || y < 0 || z < 0)
|
||||
return null;
|
||||
@@ -108,41 +109,41 @@ namespace OpenRA.Graphics
|
||||
if (x >= l.Size[0] || y >= l.Size[1] || z >= l.Size[2])
|
||||
return null;
|
||||
|
||||
var v = l.VoxelMap[(byte)x,(byte)y];
|
||||
var v = l.VoxelMap[(byte)x, (byte)y];
|
||||
if (v == null || !v.ContainsKey((byte)z))
|
||||
return null;
|
||||
|
||||
return l.VoxelMap[(byte)x,(byte)y][(byte)z];
|
||||
return l.VoxelMap[(byte)x, (byte)y][(byte)z];
|
||||
};
|
||||
|
||||
// Cull slices without any visible faces
|
||||
var xPlanes = new bool[l.Size[0]+1];
|
||||
var yPlanes = new bool[l.Size[1]+1];
|
||||
var zPlanes = new bool[l.Size[2]+1];
|
||||
var xPlanes = new bool[l.Size[0] + 1];
|
||||
var yPlanes = new bool[l.Size[1] + 1];
|
||||
var zPlanes = new bool[l.Size[2] + 1];
|
||||
for (var x = 0; x < l.Size[0]; x++)
|
||||
{
|
||||
for (var y = 0; y < l.Size[1]; y++)
|
||||
{
|
||||
for (var z = 0; z < l.Size[2]; z++)
|
||||
{
|
||||
if (get(x,y,z) == null)
|
||||
if (get(x, y, z) == null)
|
||||
continue;
|
||||
|
||||
// Only generate a plane if it is actually visible
|
||||
if (!xPlanes[x] && get(x-1,y,z) == null)
|
||||
if (!xPlanes[x] && get(x - 1, y, z) == null)
|
||||
xPlanes[x] = true;
|
||||
if (!xPlanes[x+1] && get(x+1,y,z) == null)
|
||||
xPlanes[x+1] = true;
|
||||
if (!xPlanes[x + 1] && get(x + 1, y, z) == null)
|
||||
xPlanes[x + 1] = true;
|
||||
|
||||
if (!yPlanes[y] && get(x,y-1,z) == null)
|
||||
if (!yPlanes[y] && get(x, y - 1, z) == null)
|
||||
yPlanes[y] = true;
|
||||
if (!yPlanes[y+1] && get(x,y+1,z) == null)
|
||||
yPlanes[y+1] = true;
|
||||
if (!yPlanes[y + 1] && get(x, y + 1, z) == null)
|
||||
yPlanes[y + 1] = true;
|
||||
|
||||
if (!zPlanes[z] && get(x,y,z-1) == null)
|
||||
if (!zPlanes[z] && get(x, y, z - 1) == null)
|
||||
zPlanes[z] = true;
|
||||
if (!zPlanes[z+1] && get(x,y,z+1) == null)
|
||||
zPlanes[z+1] = true;
|
||||
if (!zPlanes[z + 1] && get(x, y, z + 1) == null)
|
||||
zPlanes[z + 1] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -150,23 +151,23 @@ namespace OpenRA.Graphics
|
||||
for (var x = 0; x <= l.Size[0]; x++)
|
||||
if (xPlanes[x])
|
||||
yield return GenerateSlicePlane(l.Size[1], l.Size[2],
|
||||
(u,v) => get(x, u, v),
|
||||
(u,v) => get(x - 1, u, v),
|
||||
(u,v) => new float[] {x, u, v});
|
||||
(u, v) => get(x, u, v),
|
||||
(u, v) => get(x - 1, u, v),
|
||||
(u, v) => new float[] { x, u, v });
|
||||
|
||||
for (var y = 0; y <= l.Size[1]; y++)
|
||||
if (yPlanes[y])
|
||||
yield return GenerateSlicePlane(l.Size[0], l.Size[2],
|
||||
(u,v) => get(u, y, v),
|
||||
(u,v) => get(u, y - 1, v),
|
||||
(u,v) => new float[] {u, y, v});
|
||||
(u, v) => get(u, y, v),
|
||||
(u, v) => get(u, y - 1, v),
|
||||
(u, v) => new float[] { u, y, v });
|
||||
|
||||
for (var z = 0; z <= l.Size[2]; z++)
|
||||
if (zPlanes[z])
|
||||
yield return GenerateSlicePlane(l.Size[0], l.Size[1],
|
||||
(u,v) => get(u, v, z),
|
||||
(u,v) => get(u, v, z - 1),
|
||||
(u,v) => new float[] {u, v, z});
|
||||
(u, v) => get(u, v, z),
|
||||
(u, v) => get(u, v, z - 1),
|
||||
(u, v) => new float[] { u, v, z });
|
||||
}
|
||||
|
||||
public VoxelRenderData GenerateRenderData(VxlLimb l)
|
||||
@@ -212,7 +213,7 @@ namespace OpenRA.Graphics
|
||||
}
|
||||
}
|
||||
|
||||
Voxel LoadFile(Pair<string,string> files)
|
||||
Voxel LoadFile(Pair<string, string> files)
|
||||
{
|
||||
VxlReader vxl;
|
||||
HvaReader hva;
|
||||
|
||||
Reference in New Issue
Block a user