parent
0775244adf
commit
f3fc43fbf9
Binary file not shown.
Before Width: | Height: | Size: 62 KiB After Width: | Height: | Size: 62 KiB |
@ -17,7 +17,7 @@ namespace TrueCraft.Client.Rendering
|
||||
Renderers[id] = renderer;
|
||||
}
|
||||
|
||||
public static VertexPositionNormalTexture[] RenderBlock(IBlockProvider provider, BlockDescriptor descriptor,
|
||||
public static VertexPositionNormalColorTexture[] RenderBlock(IBlockProvider provider, BlockDescriptor descriptor,
|
||||
Vector3 offset, int indiciesOffset, out int[] indicies)
|
||||
{
|
||||
var textureMap = provider.GetTextureMap(descriptor.Metadata);
|
||||
@ -26,7 +26,7 @@ namespace TrueCraft.Client.Rendering
|
||||
return Renderers[descriptor.ID].Render(descriptor, offset, textureMap, indiciesOffset, out indicies);
|
||||
}
|
||||
|
||||
public virtual VertexPositionNormalTexture[] Render(BlockDescriptor descriptor, Vector3 offset,
|
||||
public virtual VertexPositionNormalColorTexture[] Render(BlockDescriptor descriptor, Vector3 offset,
|
||||
Tuple<int, int> textureMap, int indiciesOffset, out int[] indicies)
|
||||
{
|
||||
var texCoords = new Vector2(textureMap.Item1, textureMap.Item2);
|
||||
@ -39,19 +39,19 @@ namespace TrueCraft.Client.Rendering
|
||||
};
|
||||
for (int i = 0; i < texture.Length; i++)
|
||||
texture[i] *= new Vector2(16f / 256f);
|
||||
return CreateUniformCube(offset, texture, indiciesOffset, out indicies);
|
||||
return CreateUniformCube(offset, texture, indiciesOffset, out indicies, Color.White);
|
||||
}
|
||||
|
||||
protected VertexPositionNormalTexture[] CreateUniformCube(Vector3 offset, Vector2[] texture, int indiciesOffset, out int[] indicies)
|
||||
protected VertexPositionNormalColorTexture[] CreateUniformCube(Vector3 offset, Vector2[] texture, int indiciesOffset, out int[] indicies, Color color)
|
||||
{
|
||||
indicies = new int[6 * 6];
|
||||
var verticies = new VertexPositionNormalTexture[4 * 6];
|
||||
var verticies = new VertexPositionNormalColorTexture[4 * 6];
|
||||
int[] _indicies;
|
||||
int textureIndex = 0;
|
||||
for (int _side = 0; _side < 6; _side++)
|
||||
{
|
||||
var side = (CubeFace)_side;
|
||||
var quad = CreateQuad(side, offset, texture, textureIndex % texture.Length, indiciesOffset, out _indicies);
|
||||
var quad = CreateQuad(side, offset, texture, textureIndex % texture.Length, indiciesOffset, out _indicies, color);
|
||||
Array.Copy(quad, 0, verticies, _side * 4, 4);
|
||||
Array.Copy(_indicies, 0, indicies, _side * 6, 6);
|
||||
textureIndex += 4;
|
||||
@ -59,18 +59,18 @@ namespace TrueCraft.Client.Rendering
|
||||
return verticies;
|
||||
}
|
||||
|
||||
protected static VertexPositionNormalTexture[] CreateQuad(CubeFace face, Vector3 offset, Vector2[] texture, int textureOffset,
|
||||
int indiciesOffset, out int[] indicies)
|
||||
protected static VertexPositionNormalColorTexture[] CreateQuad(CubeFace face, Vector3 offset, Vector2[] texture, int textureOffset,
|
||||
int indiciesOffset, out int[] indicies, Color color)
|
||||
{
|
||||
indicies = new[] { 0, 1, 3, 1, 2, 3 };
|
||||
for (int i = 0; i < indicies.Length; i++)
|
||||
indicies[i] += ((int)face * 4) + indiciesOffset;
|
||||
var quad = new VertexPositionNormalTexture[4];
|
||||
var quad = new VertexPositionNormalColorTexture[4];
|
||||
var unit = CubeMesh[(int)face];
|
||||
var normal = CubeNormals[(int)face];
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
quad[i] = new VertexPositionNormalTexture(offset + unit[i], normal, texture[textureOffset + i]);
|
||||
quad[i] = new VertexPositionNormalColorTexture(offset + unit[i], normal, color, texture[textureOffset + i]);
|
||||
}
|
||||
return quad;
|
||||
}
|
||||
|
@ -53,10 +53,10 @@ namespace TrueCraft.Client.Rendering.Blocks
|
||||
BottomTexture + Vector2.UnitX,
|
||||
};
|
||||
|
||||
public override VertexPositionNormalTexture[] Render(BlockDescriptor descriptor, Vector3 offset,
|
||||
public override VertexPositionNormalColorTexture[] Render(BlockDescriptor descriptor, Vector3 offset,
|
||||
Tuple<int, int> textureMap, int indiciesOffset, out int[] indicies)
|
||||
{
|
||||
return CreateUniformCube(offset, Texture, indiciesOffset, out indicies);
|
||||
return CreateUniformCube(offset, Texture, indiciesOffset, out indicies, Color.White);
|
||||
}
|
||||
}
|
||||
}
|
@ -52,10 +52,18 @@ namespace TrueCraft.Client.Rendering.Blocks
|
||||
EndsTexture + Vector2.UnitX,
|
||||
};
|
||||
|
||||
public override VertexPositionNormalTexture[] Render(BlockDescriptor descriptor, Vector3 offset,
|
||||
public static readonly Color BiomeColor = new Color(105, 169, 63);
|
||||
|
||||
public override VertexPositionNormalColorTexture[] Render(BlockDescriptor descriptor, Vector3 offset,
|
||||
Tuple<int, int> textureMap, int indiciesOffset, out int[] indicies)
|
||||
{
|
||||
return CreateUniformCube(offset, Texture, indiciesOffset, out indicies);
|
||||
var cube = CreateUniformCube(offset, Texture, indiciesOffset, out indicies, Color.White);
|
||||
// Apply biome colors to top of cube
|
||||
for (int i = (int)(CubeFace.PositiveY) * 4; i < (int)(CubeFace.PositiveY) * 4 + 4; i++)
|
||||
{
|
||||
cube[i].Color = BiomeColor; // TODO: Take this from biome
|
||||
}
|
||||
return cube;
|
||||
}
|
||||
}
|
||||
}
|
@ -24,37 +24,37 @@ namespace TrueCraft.Client.Rendering.Blocks
|
||||
TextureMap + Vector2.UnitX
|
||||
};
|
||||
|
||||
public override VertexPositionNormalTexture[] Render(BlockDescriptor descriptor, Vector3 offset,
|
||||
public override VertexPositionNormalColorTexture[] Render(BlockDescriptor descriptor, Vector3 offset,
|
||||
Tuple<int, int> textureMap, int indiciesOffset, out int[] indicies)
|
||||
{
|
||||
VertexPositionNormalTexture[] verticies;
|
||||
VertexPositionNormalColorTexture[] verticies;
|
||||
Vector3 correction;
|
||||
int faceCorrection = 0;
|
||||
switch ((LadderBlock.LadderDirection)descriptor.Metadata)
|
||||
{
|
||||
case LadderBlock.LadderDirection.North:
|
||||
verticies = CreateQuad(CubeFace.PositiveZ, offset, Texture, 0, indiciesOffset, out indicies);
|
||||
verticies = CreateQuad(CubeFace.PositiveZ, offset, Texture, 0, indiciesOffset, out indicies, Color.White);
|
||||
correction = Vector3.Forward;
|
||||
faceCorrection = (int)CubeFace.PositiveZ * 4;
|
||||
break;
|
||||
case LadderBlock.LadderDirection.South:
|
||||
verticies = CreateQuad(CubeFace.NegativeZ, offset, Texture, 0, indiciesOffset, out indicies);
|
||||
verticies = CreateQuad(CubeFace.NegativeZ, offset, Texture, 0, indiciesOffset, out indicies, Color.White);
|
||||
correction = Vector3.Backward;
|
||||
faceCorrection = (int)CubeFace.NegativeZ * 4;
|
||||
break;
|
||||
case LadderBlock.LadderDirection.East:
|
||||
verticies = CreateQuad(CubeFace.NegativeX, offset, Texture, 0, indiciesOffset, out indicies);
|
||||
verticies = CreateQuad(CubeFace.NegativeX, offset, Texture, 0, indiciesOffset, out indicies, Color.White);
|
||||
correction = Vector3.Right;
|
||||
faceCorrection = (int)CubeFace.NegativeX * 4;
|
||||
break;
|
||||
case LadderBlock.LadderDirection.West:
|
||||
verticies = CreateQuad(CubeFace.PositiveX, offset, Texture, 0, indiciesOffset, out indicies);
|
||||
verticies = CreateQuad(CubeFace.PositiveX, offset, Texture, 0, indiciesOffset, out indicies, Color.White);
|
||||
correction = Vector3.Left;
|
||||
faceCorrection = (int)CubeFace.PositiveX * 4;
|
||||
break;
|
||||
default:
|
||||
// Should never happen
|
||||
verticies = CreateUniformCube(offset, Texture, indiciesOffset, out indicies);
|
||||
verticies = CreateUniformCube(offset, Texture, indiciesOffset, out indicies, Color.White);
|
||||
correction = Vector3.Zero;
|
||||
break;
|
||||
}
|
||||
|
@ -35,18 +35,18 @@ namespace TrueCraft.Client.Rendering.Blocks
|
||||
SpruceTexture + Vector2.UnitX
|
||||
};
|
||||
|
||||
public override VertexPositionNormalTexture[] Render(BlockDescriptor descriptor, Vector3 offset,
|
||||
public override VertexPositionNormalColorTexture[] Render(BlockDescriptor descriptor, Vector3 offset,
|
||||
Tuple<int, int> textureMap, int indiciesOffset, out int[] indicies)
|
||||
{
|
||||
switch ((WoodBlock.WoodType)descriptor.Metadata)
|
||||
{
|
||||
case WoodBlock.WoodType.Spruce:
|
||||
return CreateUniformCube(offset, SpruceTextures, indiciesOffset, out indicies);
|
||||
return CreateUniformCube(offset, SpruceTextures, indiciesOffset, out indicies, GrassRenderer.BiomeColor);
|
||||
case WoodBlock.WoodType.Birch:
|
||||
return CreateUniformCube(offset, BaseTextures, indiciesOffset, out indicies); // NOTE: Minecraft adjusts the hue a bit
|
||||
return CreateUniformCube(offset, BaseTextures, indiciesOffset, out indicies, GrassRenderer.BiomeColor);
|
||||
case WoodBlock.WoodType.Oak:
|
||||
default:
|
||||
return CreateUniformCube(offset, BaseTextures, indiciesOffset, out indicies);
|
||||
return CreateUniformCube(offset, BaseTextures, indiciesOffset, out indicies, GrassRenderer.BiomeColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -123,18 +123,18 @@ namespace TrueCraft.Client.Rendering.Blocks
|
||||
BaseEndsTexture + Vector2.UnitX,
|
||||
};
|
||||
|
||||
public override VertexPositionNormalTexture[] Render(BlockDescriptor descriptor, Vector3 offset,
|
||||
public override VertexPositionNormalColorTexture[] Render(BlockDescriptor descriptor, Vector3 offset,
|
||||
Tuple<int, int> textureMap, int indiciesOffset, out int[] indicies)
|
||||
{
|
||||
switch ((WoodBlock.WoodType)descriptor.Metadata)
|
||||
{
|
||||
case WoodBlock.WoodType.Spruce:
|
||||
return CreateUniformCube(offset, SpruceTexture, indiciesOffset, out indicies);
|
||||
return CreateUniformCube(offset, SpruceTexture, indiciesOffset, out indicies, Color.White);
|
||||
case WoodBlock.WoodType.Birch:
|
||||
return CreateUniformCube(offset, BirchTexture, indiciesOffset, out indicies);
|
||||
return CreateUniformCube(offset, BirchTexture, indiciesOffset, out indicies, Color.White);
|
||||
case WoodBlock.WoodType.Oak:
|
||||
default:
|
||||
return CreateUniformCube(offset, BaseTexture, indiciesOffset, out indicies);
|
||||
return CreateUniformCube(offset, BaseTexture, indiciesOffset, out indicies, Color.White);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,11 +24,11 @@ namespace TrueCraft.Client.Rendering.Blocks
|
||||
TextureMap + Vector2.UnitX,
|
||||
};
|
||||
|
||||
public override VertexPositionNormalTexture[] Render(BlockDescriptor descriptor, Vector3 offset,
|
||||
public override VertexPositionNormalColorTexture[] Render(BlockDescriptor descriptor, Vector3 offset,
|
||||
Tuple<int, int> textureMap, int indiciesOffset, out int[] indicies)
|
||||
{
|
||||
var overhead = new Vector3(0.5f, 0.5f, 0.5f);
|
||||
var cube = CreateUniformCube(overhead, Texture, indiciesOffset, out indicies);
|
||||
var cube = CreateUniformCube(overhead, Texture, indiciesOffset, out indicies, Color.White);
|
||||
var heightMultiplier = new Vector3(1, ((descriptor.Metadata + 1) / 16f), 1);
|
||||
for (int i = 0; i < cube.Length; i++)
|
||||
{
|
||||
|
@ -52,10 +52,10 @@ namespace TrueCraft.Client.Rendering.Blocks
|
||||
BottomTexture + Vector2.UnitX,
|
||||
};
|
||||
|
||||
public override VertexPositionNormalTexture[] Render(BlockDescriptor descriptor, Vector3 offset,
|
||||
public override VertexPositionNormalColorTexture[] Render(BlockDescriptor descriptor, Vector3 offset,
|
||||
Tuple<int, int> textureMap, int indiciesOffset, out int[] indicies)
|
||||
{
|
||||
return CreateUniformCube(offset, Texture, indiciesOffset, out indicies);
|
||||
return CreateUniformCube(offset, Texture, indiciesOffset, out indicies, Color.White);
|
||||
}
|
||||
}
|
||||
}
|
@ -50,12 +50,12 @@ namespace TrueCraft.Client.Rendering.Blocks
|
||||
TextureMap + new Vector2(2, 2),
|
||||
};
|
||||
|
||||
public override VertexPositionNormalTexture[] Render(BlockDescriptor descriptor, Vector3 offset,
|
||||
public override VertexPositionNormalColorTexture[] Render(BlockDescriptor descriptor, Vector3 offset,
|
||||
Tuple<int, int> textureMap, int indiciesOffset, out int[] indicies)
|
||||
{
|
||||
var overhead = new Vector3(0.5f, 0.5f, 0.5f);
|
||||
var centerized = new Vector3(7f / 16f, 0, 7f / 16f);
|
||||
var cube = CreateUniformCube(overhead, Texture, indiciesOffset, out indicies);
|
||||
var cube = CreateUniformCube(overhead, Texture, indiciesOffset, out indicies, Color.White);
|
||||
for (int i = 0; i < cube.Length; i++)
|
||||
{
|
||||
cube[i].Position.X *= 1f / 8f;
|
||||
|
@ -71,24 +71,24 @@ namespace TrueCraft.Client.Rendering.Blocks
|
||||
}
|
||||
}
|
||||
|
||||
public override VertexPositionNormalTexture[] Render(BlockDescriptor descriptor, Vector3 offset,
|
||||
public override VertexPositionNormalColorTexture[] Render(BlockDescriptor descriptor, Vector3 offset,
|
||||
Tuple<int, int> textureMap, int indiciesOffset, out int[] indicies)
|
||||
{
|
||||
if (descriptor.ID == RoseBlock.BlockID)
|
||||
return RenderQuads(descriptor, offset, RoseTexture, indiciesOffset, out indicies);
|
||||
return RenderQuads(descriptor, offset, RoseTexture, indiciesOffset, out indicies, Color.White);
|
||||
else if (descriptor.ID == DandelionBlock.BlockID)
|
||||
return RenderQuads(descriptor, offset, DandelionTexture, indiciesOffset, out indicies);
|
||||
return RenderQuads(descriptor, offset, DandelionTexture, indiciesOffset, out indicies, Color.White);
|
||||
else
|
||||
{
|
||||
switch ((TallGrassBlock.TallGrassType)descriptor.Metadata)
|
||||
{
|
||||
case TallGrassBlock.TallGrassType.DeadBush:
|
||||
return RenderQuads(descriptor, offset, DeadBushTexture, indiciesOffset, out indicies);
|
||||
return RenderQuads(descriptor, offset, DeadBushTexture, indiciesOffset, out indicies, Color.White);
|
||||
case TallGrassBlock.TallGrassType.Fern:
|
||||
return RenderQuads(descriptor, offset, FernTexture, indiciesOffset, out indicies);
|
||||
return RenderQuads(descriptor, offset, FernTexture, indiciesOffset, out indicies, GrassRenderer.BiomeColor);
|
||||
case TallGrassBlock.TallGrassType.TallGrass:
|
||||
default:
|
||||
return RenderQuads(descriptor, offset, TallGrassTexture, indiciesOffset, out indicies);
|
||||
return RenderQuads(descriptor, offset, TallGrassTexture, indiciesOffset, out indicies, GrassRenderer.BiomeColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ namespace TrueCraft.Client.Rendering
|
||||
/// <param name="device"></param>
|
||||
/// <param name="vertices"></param>
|
||||
/// <param name="indices"></param>
|
||||
public ChunkMesh(ReadOnlyChunk chunk, TrueCraftGame game, VertexPositionNormalTexture[] vertices, int[] indices)
|
||||
public ChunkMesh(ReadOnlyChunk chunk, TrueCraftGame game, VertexPositionNormalColorTexture[] vertices, int[] indices)
|
||||
: base(game, 1, true)
|
||||
{
|
||||
Chunk = chunk;
|
||||
@ -38,7 +38,7 @@ namespace TrueCraft.Client.Rendering
|
||||
/// <param name="vertices"></param>
|
||||
/// <param name="opaqueIndices"></param>
|
||||
/// <param name="transparentIndices"></param>
|
||||
public ChunkMesh(ReadOnlyChunk chunk, TrueCraftGame game, VertexPositionNormalTexture[] vertices, int[] opaqueIndices, int[] transparentIndices)
|
||||
public ChunkMesh(ReadOnlyChunk chunk, TrueCraftGame game, VertexPositionNormalColorTexture[] vertices, int[] opaqueIndices, int[] transparentIndices)
|
||||
: base(game, 2, true)
|
||||
{
|
||||
Chunk = chunk;
|
||||
@ -52,7 +52,7 @@ namespace TrueCraft.Client.Rendering
|
||||
/// </summary>
|
||||
/// <param name="vertices"></param>
|
||||
/// <returns></returns>
|
||||
protected override BoundingBox RecalculateBounds(VertexPositionNormalTexture[] vertices)
|
||||
protected override BoundingBox RecalculateBounds(VertexPositionNormalColorTexture[] vertices)
|
||||
{
|
||||
return new BoundingBox(
|
||||
new Vector3(Chunk.X * TrueCraft.Core.World.Chunk.Width, 0, Chunk.Z * TrueCraft.Core.World.Chunk.Depth),
|
||||
|
@ -73,7 +73,7 @@ namespace TrueCraft.Client.Rendering
|
||||
|
||||
private class RenderState
|
||||
{
|
||||
public readonly List<VertexPositionNormalTexture> Verticies = new List<VertexPositionNormalTexture>();
|
||||
public readonly List<VertexPositionNormalColorTexture> Verticies = new List<VertexPositionNormalColorTexture>();
|
||||
public readonly List<int> OpaqueIndicies = new List<int>();
|
||||
public readonly List<int> TransparentIndicies = new List<int>();
|
||||
public readonly HashSet<Coordinates3D> DrawableCoordinates = new HashSet<Coordinates3D>();
|
||||
|
@ -23,22 +23,22 @@ namespace TrueCraft.Client.Rendering
|
||||
Texture[i] *= new Vector2(16f / 256f);
|
||||
}
|
||||
|
||||
public override VertexPositionNormalTexture[] Render(BlockDescriptor descriptor, Vector3 offset,
|
||||
public override VertexPositionNormalColorTexture[] Render(BlockDescriptor descriptor, Vector3 offset,
|
||||
Tuple<int, int> textureMap, int indiciesOffset, out int[] indicies)
|
||||
{
|
||||
return RenderQuads(descriptor, offset, Texture, indiciesOffset, out indicies);
|
||||
return RenderQuads(descriptor, offset, Texture, indiciesOffset, out indicies, Color.White);
|
||||
}
|
||||
|
||||
protected VertexPositionNormalTexture[] RenderQuads(BlockDescriptor descriptor, Vector3 offset,
|
||||
Vector2[] textureMap, int indiciesOffset, out int[] indicies)
|
||||
protected VertexPositionNormalColorTexture[] RenderQuads(BlockDescriptor descriptor, Vector3 offset,
|
||||
Vector2[] textureMap, int indiciesOffset, out int[] indicies, Color color)
|
||||
{
|
||||
indicies = new int[6 * 4];
|
||||
var verticies = new VertexPositionNormalTexture[4 * 4];
|
||||
var verticies = new VertexPositionNormalColorTexture[4 * 4];
|
||||
int[] _indicies;
|
||||
int textureIndex = 0;
|
||||
for (int side = 0; side < 4; side++)
|
||||
{
|
||||
var quad = CreateAngledQuad(side, offset, textureMap, textureIndex % textureMap.Length, indiciesOffset, out _indicies);
|
||||
var quad = CreateAngledQuad(side, offset, textureMap, textureIndex % textureMap.Length, indiciesOffset, out _indicies, color);
|
||||
Array.Copy(quad, 0, verticies, side * 4, 4);
|
||||
Array.Copy(_indicies, 0, indicies, side * 6, 6);
|
||||
textureIndex += 4;
|
||||
@ -46,18 +46,18 @@ namespace TrueCraft.Client.Rendering
|
||||
return verticies;
|
||||
}
|
||||
|
||||
protected static VertexPositionNormalTexture[] CreateAngledQuad(int face, Vector3 offset, Vector2[] texture, int textureOffset,
|
||||
int indiciesOffset, out int[] indicies)
|
||||
protected static VertexPositionNormalColorTexture[] CreateAngledQuad(int face, Vector3 offset, Vector2[] texture, int textureOffset,
|
||||
int indiciesOffset, out int[] indicies, Color color)
|
||||
{
|
||||
indicies = new[] { 0, 1, 3, 1, 2, 3 };
|
||||
for (int i = 0; i < indicies.Length; i++)
|
||||
indicies[i] += (face * 4) + indiciesOffset;
|
||||
var quad = new VertexPositionNormalTexture[4];
|
||||
var quad = new VertexPositionNormalColorTexture[4];
|
||||
var unit = QuadMesh[face];
|
||||
var normal = CubeNormals[face];
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
quad[i] = new VertexPositionNormalTexture(offset + unit[i], normal, texture[textureOffset + i]);
|
||||
quad[i] = new VertexPositionNormalColorTexture(offset + unit[i], normal, color, texture[textureOffset + i]);
|
||||
}
|
||||
return quad;
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ namespace TrueCraft.Client.Rendering
|
||||
/// <summary>
|
||||
/// Gets or sets the vertices in this mesh.
|
||||
/// </summary>
|
||||
public VertexPositionNormalTexture[] Vertices
|
||||
public VertexPositionNormalColorTexture[] Vertices
|
||||
{
|
||||
set
|
||||
{
|
||||
@ -38,7 +38,7 @@ namespace TrueCraft.Client.Rendering
|
||||
|
||||
_game.PendingMainThreadActions.Add(() =>
|
||||
{
|
||||
_vertices = new VertexBuffer(_graphicsDevice, VertexPositionNormalTexture.VertexDeclaration,
|
||||
_vertices = new VertexBuffer(_graphicsDevice, VertexPositionNormalColorTexture.VertexDeclaration,
|
||||
(value.Length + 1), BufferUsage.WriteOnly);
|
||||
_vertices.SetData(value);
|
||||
});
|
||||
@ -82,7 +82,7 @@ namespace TrueCraft.Client.Rendering
|
||||
/// <param name="vertices">The vertices in the mesh.</param>
|
||||
/// <param name="submeshes">The number of submeshes in the mesh.</param>
|
||||
/// <param name="recalculateBounds">Whether the mesh should recalculate its bounding box when changed.</param>
|
||||
public Mesh(TrueCraftGame game, VertexPositionNormalTexture[] vertices, int submeshes = 1, bool recalculateBounds = true)
|
||||
public Mesh(TrueCraftGame game, VertexPositionNormalColorTexture[] vertices, int submeshes = 1, bool recalculateBounds = true)
|
||||
: this(game, submeshes, recalculateBounds)
|
||||
{
|
||||
Vertices = vertices;
|
||||
@ -95,7 +95,7 @@ namespace TrueCraft.Client.Rendering
|
||||
/// <param name="vertices">The vertices in the mesh.</param>
|
||||
/// <param name="indices">The first (and only) submesh in the mesh.</param>
|
||||
/// <param name="recalculateBounds">Whether the mesh should recalculate its bounding box when changed.</param>
|
||||
public Mesh(TrueCraftGame game, VertexPositionNormalTexture[] vertices, int[] indices, bool recalculateBounds = true)
|
||||
public Mesh(TrueCraftGame game, VertexPositionNormalColorTexture[] vertices, int[] indices, bool recalculateBounds = true)
|
||||
: this(game, 1, recalculateBounds)
|
||||
{
|
||||
Vertices = vertices;
|
||||
@ -198,7 +198,7 @@ namespace TrueCraft.Client.Rendering
|
||||
/// </summary>
|
||||
/// <param name="vertices">The vertices in this mesh.</param>
|
||||
/// <returns></returns>
|
||||
protected virtual BoundingBox RecalculateBounds(VertexPositionNormalTexture[] vertices)
|
||||
protected virtual BoundingBox RecalculateBounds(VertexPositionNormalColorTexture[] vertices)
|
||||
{
|
||||
return new BoundingBox(
|
||||
vertices.Select(v => v.Position).OrderBy(v => v.Length()).First(),
|
||||
|
@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace TrueCraft.Client.Rendering
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
public struct VertexPositionNormalColorTexture : IVertexType
|
||||
{
|
||||
public Vector3 Position, Normal;
|
||||
public Color Color;
|
||||
public Vector2 Texture;
|
||||
|
||||
public static readonly VertexDeclaration VertexDeclaration = new VertexDeclaration(
|
||||
new[]
|
||||
{
|
||||
new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0),
|
||||
new VertexElement(12, VertexElementFormat.Vector3, VertexElementUsage.Normal, 0),
|
||||
new VertexElement(24, VertexElementFormat.Color, VertexElementUsage.Color, 0),
|
||||
new VertexElement(28, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0)
|
||||
}
|
||||
);
|
||||
|
||||
VertexDeclaration IVertexType.VertexDeclaration
|
||||
{
|
||||
get { return VertexDeclaration; }
|
||||
}
|
||||
|
||||
public VertexPositionNormalColorTexture(Vector3 position, Vector3 normal, Color color, Vector2 texture)
|
||||
{
|
||||
Position = position;
|
||||
Normal = normal;
|
||||
Color = color;
|
||||
Texture = texture;
|
||||
}
|
||||
|
||||
public static bool operator ==(VertexPositionNormalColorTexture value1, VertexPositionNormalColorTexture value2)
|
||||
{
|
||||
return value1.Equals(value2);
|
||||
}
|
||||
|
||||
public static bool operator !=(VertexPositionNormalColorTexture value1, VertexPositionNormalColorTexture value2)
|
||||
{
|
||||
return !value1.Equals(value2);
|
||||
}
|
||||
|
||||
public bool Equals(VertexPositionNormalColorTexture other)
|
||||
{
|
||||
return Position == other.Position && Normal == other.Normal &&
|
||||
Color == other.Color && Texture == other.Texture;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj == null || GetType() != obj.GetType()) return false;
|
||||
|
||||
return Equals((VertexPositionNormalColorTexture)obj);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Position.GetHashCode() ^ Normal.GetHashCode() ^
|
||||
Color.GetHashCode() ^ Texture.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
@ -100,6 +100,7 @@
|
||||
<Compile Include="Rendering\Blocks\LadderRenderer.cs" />
|
||||
<Compile Include="Rendering\Blocks\SugarcaneRenderer.cs" />
|
||||
<Compile Include="Rendering\Blocks\VegitationRenderer.cs" />
|
||||
<Compile Include="Rendering\VertexPositionNormalColorTexture.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
|
@ -148,11 +148,13 @@ namespace TrueCraft.Client
|
||||
OpaqueEffect.FogStart = 512f;
|
||||
OpaqueEffect.FogEnd = 1000f;
|
||||
OpaqueEffect.FogColor = Color.CornflowerBlue.ToVector3();
|
||||
OpaqueEffect.VertexColorEnabled = true;
|
||||
|
||||
TransparentEffect = new AlphaTestEffect(GraphicsDevice);
|
||||
TransparentEffect.AlphaFunction = CompareFunction.Greater;
|
||||
TransparentEffect.ReferenceAlpha = 127;
|
||||
TransparentEffect.Texture = TextureMapper.GetTexture("terrain.png");
|
||||
TransparentEffect.VertexColorEnabled = true;
|
||||
|
||||
base.LoadContent();
|
||||
}
|
||||
|
Reference in New Issue
Block a user