Search in sources :

Example 6 with ChunkMesh

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

the class BlockMeshPart method appendTo.

public void appendTo(ChunkMesh chunk, ChunkView chunkView, int offsetX, int offsetY, int offsetZ, ChunkMesh.RenderType renderType, Colorc colorOffset, ChunkVertexFlag flags) {
    ChunkMesh.VertexElements elements = chunk.getVertexElements(renderType);
    for (Vector2f texCoord : texCoords) {
        elements.uv0.put(texCoord);
    }
    int nextIndex = elements.vertexCount;
    elements.buffer.reserveElements(nextIndex + vertices.length);
    Vector3f pos = new Vector3f();
    for (int vIdx = 0; vIdx < vertices.length; ++vIdx) {
        elements.color.put(colorOffset);
        elements.position.put(pos.set(vertices[vIdx]).add(offsetX, offsetY, offsetZ));
        elements.normals.put(normals[vIdx]);
        elements.flags.put((byte) (flags.getValue()));
        elements.frames.put((byte) (texFrames - 1));
        float[] lightingData = calcLightingValuesForVertexPos(chunkView, vertices[vIdx].add(offsetX, offsetY, offsetZ, new Vector3f()), normals[vIdx]);
        elements.sunlight.put(lightingData[0]);
        elements.blockLight.put(lightingData[1]);
        elements.ambientOcclusion.put(lightingData[2]);
    }
    elements.vertexCount += vertices.length;
    for (int index : indices) {
        elements.indices.put(index + nextIndex);
    }
}
Also used : ChunkMesh(org.terasology.engine.rendering.primitives.ChunkMesh) Vector2f(org.joml.Vector2f) Vector3f(org.joml.Vector3f)

Aggregations

ChunkMesh (org.terasology.engine.rendering.primitives.ChunkMesh)6 Chunk (org.terasology.engine.world.chunks.Chunk)3 RenderableChunk (org.terasology.engine.world.chunks.RenderableChunk)3 ArrayList (java.util.ArrayList)2 Vector3ic (org.joml.Vector3ic)2 ChunkView (org.terasology.engine.world.ChunkView)2 ByteBuffer (java.nio.ByteBuffer)1 Vector2f (org.joml.Vector2f)1 Vector3f (org.joml.Vector3f)1 Vector3i (org.joml.Vector3i)1 ChunkMeshImpl (org.terasology.engine.rendering.primitives.ChunkMeshImpl)1 Block (org.terasology.engine.world.block.Block)1 BlockRegion (org.terasology.engine.world.block.BlockRegion)1 PreLodChunk (org.terasology.engine.world.chunks.internal.PreLodChunk)1 ChunkViewCoreImpl (org.terasology.engine.world.internal.ChunkViewCoreImpl)1 PersistedData (org.terasology.persistence.typeHandling.PersistedData)1