Search in sources :

Example 41 with Vector2f

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

the class GLTFCommonFormat method loadVector2fList.

protected List<Vector2f> loadVector2fList(MeshAttributeSemantic semantic, GLTFPrimitive gltfPrimitive, GLTF gltf, List<byte[]> loadedBuffers) throws IOException {
    TFloatList floats = readFloatBuffer(semantic, gltfPrimitive, gltf, loadedBuffers);
    if (floats == null) {
        return Collections.emptyList();
    }
    List<Vector2f> vectors = Lists.newArrayListWithCapacity(floats.size() / 2);
    for (int i = 0; i < floats.size(); i += 2) {
        vectors.add(new Vector2f(floats.get(i), floats.get(i + 1)));
    }
    return vectors;
}
Also used : Vector2f(org.joml.Vector2f) TFloatList(gnu.trove.list.TFloatList)

Example 42 with Vector2f

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

the class BlockBuilder method createAppearance.

private BlockAppearance createAppearance(BlockShape shape, Map<BlockPart, BlockTile> tiles, Rotation rot) {
    Map<BlockPart, BlockMeshPart> meshParts = Maps.newEnumMap(BlockPart.class);
    Map<BlockPart, Vector2f> textureAtlasPositions = Maps.newEnumMap(BlockPart.class);
    for (BlockPart part : BlockPart.values()) {
        // TODO: Need to be more sensible with the texture atlas.
        // Because things like block particles read from a part that may not exist, we're being fairly lenient
        Vector2f atlasPos;
        int frameCount;
        BlockTile tile = tiles.get(part);
        if (tile == null) {
            atlasPos = new Vector2f();
            frameCount = 1;
        } else {
            atlasPos = worldAtlas.getTexCoords(tile, shape.getMeshPart(part) != null);
            frameCount = tile.getLength();
        }
        BlockPart targetPart = part.rotate(rot);
        textureAtlasPositions.put(targetPart, atlasPos);
        if (shape.getMeshPart(part) != null) {
            meshParts.put(targetPart, shape.getMeshPart(part).rotate(rot.orientation().get(new Quaternionf())).mapTexCoords(atlasPos, worldAtlas.getRelativeTileSize(), frameCount));
        }
    }
    return new BlockAppearance(meshParts, textureAtlasPositions);
}
Also used : BlockPart(org.terasology.engine.world.block.BlockPart) BlockAppearance(org.terasology.engine.world.block.BlockAppearance) Vector2f(org.joml.Vector2f) BlockTile(org.terasology.engine.world.block.tiles.BlockTile) Quaternionf(org.joml.Quaternionf) BlockMeshPart(org.terasology.engine.world.block.shapes.BlockMeshPart)

Example 43 with Vector2f

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

the class ZoomableLayoutTest method testZoomInAndDrag.

@Test
public void testZoomInAndDrag() throws Exception {
    zoomableLayout.onDraw(canvas);
    // zoom in 2x towards left top corner
    zoomableLayout.zoom(0.5f, 0.5f, new Vector2i(0, 0));
    zoomableLayout.onDraw(canvas);
    // world size halved
    assertEquals(zoomableLayout.getWindowSize(), new Vector2f(WORLD_WIDTH, WORLD_HEIGHT / 2));
    assertEquals(zoomableLayout.getScreenSize(), new Vector2i(CANVAS_WIDTH, CANVAS_HEIGHT));
    assertEquals(zoomableLayout.getPixelSize(), new Vector2f(CANVAS_WIDTH / WORLD_WIDTH, CANVAS_HEIGHT / (WORLD_HEIGHT / 2)));
    verify(canvas).drawWidget(item1, new Rectanglei(new Vector2i(ceilToInt(pos1.x), ceilToInt(pos1.y)), new Vector2i(ceilToInt(pos1.x + size1.x), ceilToInt(pos1.y + size1.y))));
    verify(canvas).drawWidget(item2, new Rectanglei(new Vector2i(ceilToInt(pos2.x), ceilToInt(pos2.y)), new Vector2i(ceilToInt(pos2.x + size2.x), ceilToInt(pos2.y + size2.y))));
    verify(canvas).drawWidget(item3, new Rectanglei(new Vector2i(ceilToInt(pos3.x), ceilToInt(pos3.y)), new Vector2i(ceilToInt(pos3.x + size3.x), ceilToInt(pos3.y + size3.y))));
    // simulate drag to item2
    zoomableLayout.setWindowPosition(pos2);
    zoomableLayout.onDraw(canvas);
    // item1 out of canvas
    verify(canvas).drawWidget(item1, new Rectanglei(new Vector2i(ceilToInt(pos1.x - pos2.x), ceilToInt(pos1.y - pos2.y)), new Vector2i(ceilToInt(pos1.x + size1.x - pos2.x), ceilToInt(pos1.y + size1.y - pos2.y))));
    verify(canvas).drawWidget(item2, new Rectanglei(new Vector2i(), new Vector2i(ceilToInt(size2.x), ceilToInt(size2.y))));
    verify(canvas).drawWidget(item3, new Rectanglei(new Vector2i(ceilToInt(pos3.x - pos2.x), ceilToInt(pos3.y - pos2.y)), new Vector2i(ceilToInt(pos3.x + size3.x - pos2.x), ceilToInt(pos3.y + size3.y - pos2.y))));
}
Also used : Vector2f(org.joml.Vector2f) Vector2i(org.joml.Vector2i) Rectanglei(org.terasology.joml.geom.Rectanglei) Test(org.junit.jupiter.api.Test)

Example 44 with Vector2f

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

the class ZoomableLayoutTest method setup.

@BeforeEach
public void setup() {
    zoomableLayout = new ZoomableLayout();
    item1 = mock(ZoomableLayout.PositionalWidget.class);
    item2 = mock(ZoomableLayout.PositionalWidget.class);
    item3 = mock(ZoomableLayout.PositionalWidget.class);
    canvas = mock(Canvas.class);
    // 
    // +------+
    // |  1   |
    // +------+
    // +-+
    // |2|
    // +-+
    // 
    // +---+
    // | 3 |
    // |   |
    // +---+
    // positions of the widgets in the world
    pos1 = new Vector2f(10, 10);
    pos2 = new Vector2f(40, 40);
    pos3 = new Vector2f(80, 70);
    when(item1.getPosition()).thenReturn(pos1);
    when(item2.getPosition()).thenReturn(pos2);
    when(item3.getPosition()).thenReturn(pos3);
    // size of widgets
    size1 = new Vector2f(20, 10);
    size2 = new Vector2f(5, 10);
    size3 = new Vector2f(10, 20);
    when(item1.getSize()).thenReturn(size1);
    when(item2.getSize()).thenReturn(size2);
    when(item3.getSize()).thenReturn(size3);
    when(item1.isVisible()).thenReturn(true);
    when(item2.isVisible()).thenReturn(true);
    when(item3.isVisible()).thenReturn(true);
    Vector2i availableSize = new Vector2i(CANVAS_WIDTH, CANVAS_HEIGHT);
    when(canvas.size()).thenReturn(availableSize);
    zoomableLayout.setWindowSize(new Vector2f(WORLD_WIDTH, WORLD_HEIGHT));
    zoomableLayout.addWidget(item1);
    zoomableLayout.addWidget(item2);
    zoomableLayout.addWidget(item3);
}
Also used : Vector2f(org.joml.Vector2f) Canvas(org.terasology.nui.Canvas) Vector2i(org.joml.Vector2i) ZoomableLayout(org.terasology.nui.layouts.ZoomableLayout) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 45 with Vector2f

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

the class ObjMeshFormat method processData.

private StandardMeshData processData(List<Vector3f> rawVertices, List<Vector3f> rawNormals, List<Vector2f> rawTexCoords, List<Vector3i[]> rawIndices) throws IOException {
    int numIndices = 0;
    int numVerts = 0;
    for (int x = 0; x < rawIndices.size(); x++) {
        numIndices += (rawIndices.get(x).length - 2) * 3;
        numVerts += rawIndices.get(x).length;
    }
    StandardMeshData result = new StandardMeshData();
    result.reserve(numVerts, numIndices);
    int vertCount = 0;
    for (Vector3i[] face : rawIndices) {
        for (Vector3i indexSet : face) {
            if (indexSet.x > rawVertices.size()) {
                throw new IOException("Vertex index out of range: " + indexSet.x);
            }
            Vector3f vertex = rawVertices.get(indexSet.x - 1);
            result.position.put(vertex);
            if (indexSet.y != -1) {
                if (indexSet.y > rawTexCoords.size()) {
                    throw new IOException("TexCoord index out of range: " + indexSet.y);
                }
                Vector2f texCoord = rawTexCoords.get(indexSet.y - 1);
                result.uv0.put(new Vector2f(texCoord.x, 1 - texCoord.y));
            }
            if (indexSet.z != -1) {
                if (indexSet.z > rawNormals.size()) {
                    throw new IOException("Normal index out of range: " + indexSet.z);
                }
                Vector3f normal = rawNormals.get(indexSet.z - 1);
                result.normal.put(normal);
            }
        }
        for (int i = 0; i < face.length - 2; ++i) {
            result.indices.put(vertCount);
            result.indices.put(vertCount + i + 1);
            result.indices.put(vertCount + i + 2);
        }
        vertCount += face.length;
    }
    return result;
}
Also used : Vector2f(org.joml.Vector2f) Vector3f(org.joml.Vector3f) Vector3i(org.joml.Vector3i) IOException(java.io.IOException)

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