Search in sources :

Example 1 with ChunkMeshImpl

use of org.terasology.engine.rendering.primitives.ChunkMeshImpl in project Terasology by MovingBlocks.

the class ChunkMeshTypeHandler method deserialize.

@Override
public Optional<ChunkMesh> deserialize(PersistedData data) {
    List<ByteBuffer> asBuffers = new ArrayList<>();
    for (PersistedData datum : data.getAsArray()) {
        ByteBuffer buffer = datum.getAsByteBuffer();
        ByteBuffer directBuffer = BufferUtils.createByteBuffer(buffer.limit());
        directBuffer.put(buffer);
        directBuffer.rewind();
        asBuffers.add(directBuffer);
    }
    ChunkMesh result = new ChunkMeshImpl();
    for (ChunkMesh.RenderType renderType : ChunkMesh.RenderType.values()) {
        result.getVertexElements(renderType).buffer.replace(asBuffers.remove(0));
        result.getVertexElements(renderType).indices.replace(asBuffers.remove(0));
    }
    result.updateMesh();
    return Optional.of(result);
}
Also used : ChunkMesh(org.terasology.engine.rendering.primitives.ChunkMesh) ChunkMeshImpl(org.terasology.engine.rendering.primitives.ChunkMeshImpl) ArrayList(java.util.ArrayList) PersistedData(org.terasology.persistence.typeHandling.PersistedData) ByteBuffer(java.nio.ByteBuffer)

Aggregations

ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 ChunkMesh (org.terasology.engine.rendering.primitives.ChunkMesh)1 ChunkMeshImpl (org.terasology.engine.rendering.primitives.ChunkMeshImpl)1 PersistedData (org.terasology.persistence.typeHandling.PersistedData)1