Add wheat and farmland renderers
This commit is contained in:
parent
939a6dc79c
commit
8697994737
44
TrueCraft.Client/Rendering/Blocks/FarmlandRenderer.cs
Normal file
44
TrueCraft.Client/Rendering/Blocks/FarmlandRenderer.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework;
|
||||
using TrueCraft.Core.Logic.Blocks;
|
||||
using TrueCraft.API.Logic;
|
||||
|
||||
namespace TrueCraft.Client.Rendering.Blocks
|
||||
{
|
||||
public class FarmlandRenderer : BlockRenderer
|
||||
{
|
||||
static FarmlandRenderer()
|
||||
{
|
||||
BlockRenderer.RegisterRenderer(FarmlandBlock.BlockID, new FarmlandRenderer());
|
||||
for (int i = 0; i < Texture.Length; i++)
|
||||
Texture[i] *= new Vector2(16f / 256f);
|
||||
}
|
||||
|
||||
private static Vector2 TextureMap = new Vector2(7, 5);
|
||||
private static Vector2[] Texture =
|
||||
{
|
||||
TextureMap + Vector2.UnitX + Vector2.UnitY,
|
||||
TextureMap + Vector2.UnitY,
|
||||
TextureMap,
|
||||
TextureMap + Vector2.UnitX,
|
||||
};
|
||||
|
||||
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, Color.White);
|
||||
for (int i = 0; i < cube.Length; i++)
|
||||
{
|
||||
if (cube[i].Position.Y > 0)
|
||||
{
|
||||
cube[i].Position.Y *= 15f / 16f;
|
||||
}
|
||||
cube[i].Position += offset;
|
||||
cube[i].Position -= overhead;
|
||||
}
|
||||
return cube;
|
||||
}
|
||||
}
|
||||
}
|
46
TrueCraft.Client/Rendering/Blocks/WaterRenderer.cs
Normal file
46
TrueCraft.Client/Rendering/Blocks/WaterRenderer.cs
Normal file
@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework;
|
||||
using TrueCraft.Core.Logic.Blocks;
|
||||
using TrueCraft.API.Logic;
|
||||
|
||||
namespace TrueCraft.Client.Rendering.Blocks
|
||||
{
|
||||
public class WaterRenderer : BlockRenderer
|
||||
{
|
||||
static WaterRenderer()
|
||||
{
|
||||
BlockRenderer.RegisterRenderer(WaterBlock.BlockID, new WaterRenderer());
|
||||
BlockRenderer.RegisterRenderer(StationaryWaterBlock.BlockID, new WaterRenderer());
|
||||
for (int i = 0; i < Texture.Length; i++)
|
||||
Texture[i] *= new Vector2(16f / 256f);
|
||||
}
|
||||
|
||||
private static Vector2 TextureMap = new Vector2(13, 12);
|
||||
private static Vector2[] Texture =
|
||||
{
|
||||
TextureMap + Vector2.UnitX + Vector2.UnitY,
|
||||
TextureMap + Vector2.UnitY,
|
||||
TextureMap,
|
||||
TextureMap + Vector2.UnitX,
|
||||
};
|
||||
|
||||
public override VertexPositionNormalColorTexture[] Render(BlockDescriptor descriptor, Vector3 offset,
|
||||
Tuple<int, int> textureMap, int indiciesOffset, out int[] indicies)
|
||||
{
|
||||
// TODO: Rest of water rendering (shape and level and so on)
|
||||
var overhead = new Vector3(0.5f, 0.5f, 0.5f);
|
||||
var cube = CreateUniformCube(overhead, Texture, indiciesOffset, out indicies, Color.White);
|
||||
for (int i = 0; i < cube.Length; i++)
|
||||
{
|
||||
if (cube[i].Position.Y > 0)
|
||||
{
|
||||
cube[i].Position.Y *= 15f / 16f;
|
||||
}
|
||||
cube[i].Position += offset;
|
||||
cube[i].Position -= overhead;
|
||||
}
|
||||
return cube;
|
||||
}
|
||||
}
|
||||
}
|
105
TrueCraft.Client/Rendering/Blocks/WheatRenderer.cs
Normal file
105
TrueCraft.Client/Rendering/Blocks/WheatRenderer.cs
Normal file
@ -0,0 +1,105 @@
|
||||
using System;
|
||||
using TrueCraft.API.Logic;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework;
|
||||
using TrueCraft.Core.Logic.Blocks;
|
||||
|
||||
namespace TrueCraft.Client.Rendering
|
||||
{
|
||||
public class WheatRenderer : BlockRenderer
|
||||
{
|
||||
static WheatRenderer()
|
||||
{
|
||||
BlockRenderer.RegisterRenderer(CropsBlock.BlockID, new WheatRenderer());
|
||||
}
|
||||
|
||||
private Vector2[][] Textures;
|
||||
|
||||
public WheatRenderer()
|
||||
{
|
||||
var textureMap = new Vector2(8, 5);
|
||||
Textures = new Vector2[8][];
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
Textures[i] = new[]
|
||||
{
|
||||
textureMap + Vector2.UnitX + Vector2.UnitY,
|
||||
textureMap + Vector2.UnitY,
|
||||
textureMap,
|
||||
textureMap + Vector2.UnitX,
|
||||
};
|
||||
for (int j = 0; j < Textures[i].Length; j++)
|
||||
Textures[i][j] *= new Vector2(16f / 256f);
|
||||
textureMap += new Vector2(1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public override VertexPositionNormalColorTexture[] Render(BlockDescriptor descriptor, Vector3 offset,
|
||||
Tuple<int, int> textureMap, int indiciesOffset, out int[] indicies)
|
||||
{
|
||||
// Wheat is rendered by rendering the four vertical faces of a cube, then moving them
|
||||
// towards the middle. We also render a second set of four faces so that you can see
|
||||
// each face from the opposite side (to avoid culling)
|
||||
var texture = Textures[0];
|
||||
if (descriptor.Metadata < Textures.Length)
|
||||
texture = Textures[descriptor.Metadata];
|
||||
indicies = new int[4 * 2 * 6];
|
||||
var verticies = new VertexPositionNormalColorTexture[4 * 2 * 6];
|
||||
int[] _indicies;
|
||||
for (int _side = 0; _side < 4; _side++) // Y faces are the last two in the CubeFace enum, so we can just iterate to 4
|
||||
{
|
||||
var side = (CubeFace)_side;
|
||||
var quad = CreateQuad(side, Vector3.Zero, texture, 0, indiciesOffset, out _indicies, Color.White);
|
||||
if (side == CubeFace.NegativeX || side == CubeFace.PositiveX)
|
||||
{
|
||||
for (int i = 0; i < quad.Length; i++)
|
||||
{
|
||||
quad[i].Position.X *= 0.5f;
|
||||
quad[i].Position += offset;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < quad.Length; i++)
|
||||
{
|
||||
quad[i].Position.Z *= 0.5f;
|
||||
quad[i].Position += offset;
|
||||
}
|
||||
}
|
||||
Array.Copy(quad, 0, verticies, _side * 4, 4);
|
||||
Array.Copy(_indicies, 0, indicies, _side * 6, 6);
|
||||
}
|
||||
indiciesOffset += 4 * 6;
|
||||
for (int _side = 0; _side < 4; _side++)
|
||||
{
|
||||
var side = (CubeFace)_side;
|
||||
var quad = CreateQuad(side, Vector3.Zero, texture, 0, indiciesOffset, out _indicies, Color.White);
|
||||
if (side == CubeFace.NegativeX || side == CubeFace.PositiveX)
|
||||
{
|
||||
for (int i = 0; i < quad.Length; i++)
|
||||
{
|
||||
quad[i].Position.X *= 0.5f;
|
||||
quad[i].Position.X = -quad[i].Position.X;
|
||||
quad[i].Position += offset;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < quad.Length; i++)
|
||||
{
|
||||
quad[i].Position.Z *= 0.5f;
|
||||
quad[i].Position.Z = -quad[i].Position.Z;
|
||||
quad[i].Position += offset;
|
||||
}
|
||||
}
|
||||
Array.Copy(quad, 0, verticies, _side * 4 + 4 * 4, 4);
|
||||
Array.Copy(_indicies, 0, indicies, _side * 6 + 6 * 4, 6);
|
||||
}
|
||||
for (int i = 0; i < verticies.Length; i++)
|
||||
{
|
||||
verticies[i].Position.Y -= 1 / 16f;
|
||||
}
|
||||
return verticies;
|
||||
}
|
||||
}
|
||||
}
|
@ -102,6 +102,8 @@
|
||||
<Compile Include="Rendering\Blocks\VegitationRenderer.cs" />
|
||||
<Compile Include="Rendering\VertexPositionNormalColorTexture.cs" />
|
||||
<Compile Include="Rendering\Blocks\WheatRenderer.cs" />
|
||||
<Compile Include="Rendering\Blocks\WaterRenderer.cs" />
|
||||
<Compile Include="Rendering\Blocks\FarmlandRenderer.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
|
@ -78,7 +78,7 @@ namespace TrueCraft.Client
|
||||
base.Initialize(); // (calls LoadContent)
|
||||
ChunkConverter = new ChunkRenderer(this, Client.World.World.BlockRepository);
|
||||
Client.ChunkLoaded += (sender, e) => ChunkConverter.Enqueue(e.Chunk);
|
||||
Client.ChunkModified += (sender, e) => ChunkConverter.Enqueue(e.Chunk, true);
|
||||
//Client.ChunkModified += (sender, e) => ChunkConverter.Enqueue(e.Chunk, true);
|
||||
ChunkConverter.MeshCompleted += ChunkConverter_MeshGenerated;
|
||||
ChunkConverter.Start();
|
||||
Client.PropertyChanged += HandleClientPropertyChanged;
|
||||
|
@ -24,6 +24,8 @@ namespace TrueCraft.Core.Logic.Blocks
|
||||
|
||||
public override string DisplayName { get { return "Crops"; } }
|
||||
|
||||
public override TrueCraft.API.BoundingBox? BoundingBox { get { return null; } }
|
||||
|
||||
public override Tuple<int, int> GetTextureMap(byte metadata)
|
||||
{
|
||||
return new Tuple<int, int>(8, 5);
|
||||
|
@ -51,7 +51,7 @@ namespace TrueCraft
|
||||
}
|
||||
catch
|
||||
{
|
||||
world = new World("default", new StandardGenerator());
|
||||
world = new World("default", new FlatlandGenerator());
|
||||
world.BlockRepository = Server.BlockRepository;
|
||||
world.Save("world");
|
||||
Server.AddWorld(world);
|
||||
|
Reference in New Issue
Block a user