Search in sources :

Example 1 with DummyChunk

use of io.xol.chunkstories.api.world.chunk.DummyChunk in project chunkstories-api by Hugobros3.

the class VoxelItemRenderer method bakeVoxelRenderer.

/**
 * Bake a single cell's content into a buffer
 */
private void bakeVoxelRenderer(CellData cell, VertexBuffer mesh) {
    ByteBuffer buffer = ByteBuffer.allocateDirect(16384).order(ByteOrder.nativeOrder());
    VoxelInHandLayoutBaker specialSauce = new VoxelInHandLayoutBaker(this.content, buffer);
    // Dummy objects that point to our special sauce
    ChunkRenderer chunkRenderer = new ChunkRenderer() {

        @Override
        public VoxelBakerHighPoly getHighpolyBakerFor(LodLevel lodLevel, ShadingType renderPass) {
            return specialSauce;
        }

        @Override
        public VoxelBakerCubic getLowpolyBakerFor(LodLevel lodLevel, ShadingType renderPass) {
            return specialSauce;
        }
    };
    VoxelRenderer voxelRenderer = cell.getVoxelRenderer();
    if (voxelRenderer == null) {
        voxelRenderer = cell.getVoxel().store().models().getVoxelModel("default");
    }
    // Render into a dummy chunk ( containing only that one voxel we want )
    voxelRenderer.bakeInto(chunkRenderer, bakingContext, new DummyChunk() {

        @Override
        public int peekRaw(int x, int y, int z) {
            // return bri.getData();
            return 0;
        }
    }, cell);
    // Flip the buffer and upload it
    buffer.flip();
    mesh.uploadData(buffer);
}
Also used : ChunkRenderer(io.xol.chunkstories.api.rendering.world.chunk.ChunkRenderer) ShadingType(io.xol.chunkstories.api.rendering.world.chunk.ChunkMeshDataSubtypes.ShadingType) LodLevel(io.xol.chunkstories.api.rendering.world.chunk.ChunkMeshDataSubtypes.LodLevel) VoxelRenderer(io.xol.chunkstories.api.rendering.voxel.VoxelRenderer) ByteBuffer(java.nio.ByteBuffer) DummyChunk(io.xol.chunkstories.api.world.chunk.DummyChunk)

Aggregations

VoxelRenderer (io.xol.chunkstories.api.rendering.voxel.VoxelRenderer)1 LodLevel (io.xol.chunkstories.api.rendering.world.chunk.ChunkMeshDataSubtypes.LodLevel)1 ShadingType (io.xol.chunkstories.api.rendering.world.chunk.ChunkMeshDataSubtypes.ShadingType)1 ChunkRenderer (io.xol.chunkstories.api.rendering.world.chunk.ChunkRenderer)1 DummyChunk (io.xol.chunkstories.api.world.chunk.DummyChunk)1 ByteBuffer (java.nio.ByteBuffer)1