Search in sources :

Example 46 with Vector2f

use of org.joml.Vector2f 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)

Example 47 with Vector2f

use of org.joml.Vector2f in project Terasology by MovingBlocks.

the class BlockMeshPart method mapTexCoords.

public BlockMeshPart mapTexCoords(Vector2f offset, float width, int frames) {
    float normalisedBorder = BORDER * width;
    Vector2f[] newTexCoords = new Vector2f[texCoords.length];
    for (int i = 0; i < newTexCoords.length; ++i) {
        newTexCoords[i] = new Vector2f(offset.x + normalisedBorder + texCoords[i].x * (width - 2 * normalisedBorder), offset.y + normalisedBorder + texCoords[i].y * (width - 2 * normalisedBorder));
    }
    return new BlockMeshPart(vertices, normals, newTexCoords, indices, frames);
}
Also used : Vector2f(org.joml.Vector2f)

Aggregations

Vector2f (org.joml.Vector2f)47 Vector3f (org.joml.Vector3f)13 Test (org.junit.jupiter.api.Test)6 Vector2i (org.joml.Vector2i)5 Vector4f (org.joml.Vector4f)5 Rectanglei (org.terasology.joml.geom.Rectanglei)5 Rectanglef (org.terasology.joml.geom.Rectanglef)4 IOException (java.io.IOException)3 ByteBuffer (java.nio.ByteBuffer)3 Vector3i (org.joml.Vector3i)3 SubtextureData (org.terasology.engine.rendering.assets.texture.subtexture.SubtextureData)3 Name (org.terasology.gestalt.naming.Name)3 Vector2fc (org.joml.Vector2fc)2 Vector3d (org.joml.Vector3d)2 MeshBuilder (org.terasology.engine.rendering.assets.mesh.MeshBuilder)2 TFloatList (gnu.trove.list.TFloatList)1 TObjectIntMap (gnu.trove.map.TObjectIntMap)1 TObjectIntHashMap (gnu.trove.map.hash.TObjectIntHashMap)1 Location (io.xol.chunkstories.api.Location)1 Controller (io.xol.chunkstories.api.entity.Controller)1