Exemplo n.º 1
0
        public static void CreateBlocks(TrueCraftGame game, IBlockRepository repository)
        {
            for (var i = 0; i < 0x100; i++)
            {
                var provider = repository.GetBlockProvider((byte)i);
                if (provider == null || provider.GetIconTexture(0) != null)
                {
                    continue;
                }
                int[] indicies;
                var   verticies = BlockRenderer.RenderBlock(provider,
                                                            new BlockDescriptor {
                    Id = provider.Id
                }, VisibleFaces.All, new Vector3(-0.5f),
                                                            0, out indicies);
                var mesh = new Mesh(game, verticies, indicies);
                BlockMeshes[provider.Id] = mesh;
            }

            PrepareEffects(game);
        }
Exemplo n.º 2
0
 public static void RegisterRenderer(byte id, BlockRenderer renderer)
 {
     Renderers[id] = renderer;
 }
Exemplo n.º 3
0
 public static void RegisterRenderer(byte Id, BlockRenderer renderer)
 {
     Renderers[Id] = renderer;
 }
Exemplo n.º 4
0
 static WheatRenderer()
 {
     BlockRenderer.RegisterRenderer(CropsBlock.BlockID, new WheatRenderer());
 }
Exemplo n.º 5
0
        private void ProcessChunk(ReadOnlyWorld world, ReadOnlyChunk chunk, RenderState state)
        {
            state.Verticies.Clear();
            state.OpaqueIndicies.Clear();
            state.TransparentIndicies.Clear();
            state.DrawableCoordinates.Clear();

            for (byte x = 0; x < Chunk.Width; x++)
            {
                for (byte z = 0; z < Chunk.Depth; z++)
                {
                    for (byte y = 0; y < Chunk.Height; y++)
                    {
                        var coords   = new Coordinates3D(x, y, z);
                        var id       = chunk.GetBlockId(coords);
                        var provider = BlockRepository.GetBlockProvider(id);
                        if (id != 0 && coords.Y == 0)
                        {
                            AddBottomBlock(coords, state, chunk);
                        }
                        if (!provider.Opaque)
                        {
                            AddAdjacentBlocks(coords, state, chunk);
                            if (id != 0)
                            {
                                AddTransparentBlock(coords, state, chunk);
                            }
                        }
                        else
                        {
                            if (coords.X == 0 || coords.X == Chunk.Width - 1 ||
                                coords.Z == 0 || coords.Z == Chunk.Depth - 1)
                            {
                                AddChunkBoundaryBlocks(coords, state, chunk);
                            }
                        }
                    }
                }
            }
            var enumerator = state.DrawableCoordinates.GetEnumerator();

            for (int j = 0; j <= state.DrawableCoordinates.Count; j++)
            {
                var coords = enumerator.Current;
                enumerator.MoveNext();
                var c          = coords.Key;
                var descriptor = new BlockDescriptor
                {
                    ID          = chunk.GetBlockId(coords.Key),
                    Metadata    = chunk.GetMetadata(coords.Key),
                    BlockLight  = chunk.GetBlockLight(coords.Key),
                    SkyLight    = chunk.GetSkyLight(coords.Key),
                    Coordinates = coords.Key,
                    Chunk       = chunk.Chunk
                };
                var provider = BlockRepository.GetBlockProvider(descriptor.ID);
                if (provider.RenderOpaque)
                {
                    int[] i;
                    var   v = BlockRenderer.RenderBlock(provider, descriptor, coords.Value,
                                                        new Vector3(chunk.X * Chunk.Width + c.X, c.Y, chunk.Z * Chunk.Depth + c.Z),
                                                        state.Verticies.Count, out i);
                    state.Verticies.AddRange(v);
                    state.OpaqueIndicies.AddRange(i);
                }
                else
                {
                    int[] i;
                    var   v = BlockRenderer.RenderBlock(provider, descriptor, coords.Value,
                                                        new Vector3(chunk.X * Chunk.Width + c.X, c.Y, chunk.Z * Chunk.Depth + c.Z),
                                                        state.Verticies.Count, out i);
                    state.Verticies.AddRange(v);
                    state.TransparentIndicies.AddRange(i);
                }
            }
        }
Exemplo n.º 6
0
        private void ProcessChunk(ReadOnlyChunk chunk, RenderState state)
        {
            state.Verticies.Clear();
            state.OpaqueIndicies.Clear();
            state.TransparentIndicies.Clear();
            state.DrawableCoordinates.Clear();

            for (byte x = 0; x < Chunk.Width; x++)
            {
                for (byte z = 0; z < Chunk.Depth; z++)
                {
                    for (byte y = 0; y < Chunk.Height; y++)
                    {
                        var coords   = new Coordinates3D(x, y, z);
                        var id       = chunk.GetBlockId(coords);
                        var provider = BlockRepository.GetBlockProvider(id);
                        if (id != 0 && (coords.X == 0 || coords.X == Chunk.Width - 1 ||
                                        coords.Y == 0 || coords.Y == Chunk.Height - 1 ||
                                        coords.Z == 0 || coords.Z == Chunk.Depth - 1))
                        {
                            state.DrawableCoordinates.Add(coords);
                        }
                        if (!provider.Opaque)
                        {
                            // Add adjacent blocks
                            foreach (var a in AdjacentCoordinates)
                            {
                                var next = coords + a;
                                if (next.X < 0 || next.X >= Chunk.Width ||
                                    next.Y < 0 || next.Y >= Chunk.Height ||
                                    next.Z < 0 || next.Z >= Chunk.Depth)
                                {
                                    continue;
                                }
                                if (chunk.GetBlockId(next) != 0)
                                {
                                    state.DrawableCoordinates.Add(next);
                                }
                            }
                        }
                    }
                }
            }
            var enumerator = state.DrawableCoordinates.GetEnumerator();

            for (int j = 0; j <= state.DrawableCoordinates.Count; j++)
            {
                var coords = enumerator.Current;
                enumerator.MoveNext();
                var descriptor = new BlockDescriptor
                {
                    ID          = chunk.GetBlockId(coords),
                    Metadata    = chunk.GetMetadata(coords),
                    BlockLight  = chunk.GetBlockLight(coords),
                    SkyLight    = chunk.GetSkyLight(coords),
                    Coordinates = coords,
                    Chunk       = chunk.Chunk
                };
                var provider = BlockRepository.GetBlockProvider(descriptor.ID);
                if (provider.RenderOpaque)
                {
                    int[] i;
                    var   v = BlockRenderer.RenderBlock(provider, descriptor,
                                                        new Vector3(chunk.X * Chunk.Width + coords.X, coords.Y, chunk.Z * Chunk.Depth + coords.Z),
                                                        state.Verticies.Count, out i);
                    state.Verticies.AddRange(v);
                    state.OpaqueIndicies.AddRange(i);
                }
                else
                {
                    int[] i;
                    var   v = BlockRenderer.RenderBlock(provider, descriptor,
                                                        new Vector3(chunk.X * Chunk.Width + coords.X, coords.Y, chunk.Z * Chunk.Depth + coords.Z),
                                                        state.Verticies.Count, out i);
                    state.Verticies.AddRange(v);
                    state.TransparentIndicies.AddRange(i);
                }
            }
        }