Search in sources :

Example 1 with VoxelTextureAtlased

use of io.xol.chunkstories.voxel.VoxelTextureAtlased in project chunkstories by Hugobros3.

the class FarTerrainMeshRenderer method getBlocksTexturesSummary.

/**
 * Dirty and stupid
 */
public Texture1D getBlocksTexturesSummary() {
    if (!blocksTexturesSummaryDone) {
        int size = 512;
        ByteBuffer bb = ByteBuffer.allocateDirect(size * 4);
        bb.order(ByteOrder.LITTLE_ENDIAN);
        int counter = 0;
        Iterator<VoxelTexture> i = world.getContent().voxels().textures().all();
        while (i.hasNext() && counter < size) {
            VoxelTextureAtlased voxelTexture = (VoxelTextureAtlased) i.next();
            bb.put((byte) (voxelTexture.getColor().x() * 255));
            bb.put((byte) (voxelTexture.getColor().y() * 255));
            bb.put((byte) (voxelTexture.getColor().z() * 255));
            bb.put((byte) (voxelTexture.getColor().w() * 255));
            voxelTexture.positionInColorIndex = counter;
            counter++;
        }
        // Padding
        while (counter < size) {
            bb.put((byte) (0));
            bb.put((byte) (0));
            bb.put((byte) (0));
            bb.put((byte) (0));
            counter++;
        }
        bb.flip();
        blockTexturesSummary.uploadTextureData(size, bb);
        blockTexturesSummary.setLinearFiltering(false);
        blocksTexturesSummaryDone = true;
    }
    return blockTexturesSummary;
}
Also used : VoxelTextureAtlased(io.xol.chunkstories.voxel.VoxelTextureAtlased) VoxelTexture(io.xol.chunkstories.api.voxel.textures.VoxelTexture) ByteBuffer(java.nio.ByteBuffer)

Example 2 with VoxelTextureAtlased

use of io.xol.chunkstories.voxel.VoxelTextureAtlased in project chunkstories by Hugobros3.

the class HeightmapArrayTexture method loadTopVoxels.

private void loadTopVoxels(HeightmapImplementation sum, ByteBuffer bb, int lod) {
    bb.clear();
    int[] data = sum.getVoxelData();
    ScratchCell cell = new ScratchCell(world);
    cell.sunlight = 15;
    for (int i = 0; i < size[lod] * size[lod]; i++) {
        int j = HeightmapImplementation.mainMimpmapOffsets[lod] + i;
        int raw_data = data[j];
        Voxel v = world.getContentTranslator().getVoxelForId(VoxelFormat.id(raw_data));
        cell.voxel = v;
        if (v.getDefinition().isLiquid())
            bb.putInt(512);
        else
            bb.putInt(((VoxelTextureAtlased) v.getVoxelTexture(VoxelSide.TOP, cell)).positionInColorIndex);
    }
    bb.flip();
}
Also used : VoxelTextureAtlased(io.xol.chunkstories.voxel.VoxelTextureAtlased) Voxel(io.xol.chunkstories.api.voxel.Voxel) ScratchCell(io.xol.chunkstories.world.cell.ScratchCell)

Aggregations

VoxelTextureAtlased (io.xol.chunkstories.voxel.VoxelTextureAtlased)2 Voxel (io.xol.chunkstories.api.voxel.Voxel)1 VoxelTexture (io.xol.chunkstories.api.voxel.textures.VoxelTexture)1 ScratchCell (io.xol.chunkstories.world.cell.ScratchCell)1 ByteBuffer (java.nio.ByteBuffer)1