Search in sources :

Example 16 with Vector3fc

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

the class VertexResourceTest method testReserveVertexResource.

@Test
public void testReserveVertexResource() {
    VertexResourceBuilder builder = new VertexResourceBuilder();
    VertexAttributeBinding<Vector3fc, Vector3f> a1 = builder.add(0, GLAttributes.VECTOR_3_F_VERTEX_ATTRIBUTE);
    VertexResource resource = builder.build();
    a1.reserve(10);
    a1.put(new Vector3f(10, 10, 10));
    a1.put(new Vector3f(5, 10, 10));
    a1.put(new Vector3f(15, 10, 10));
    assertEquals(3, a1.getPosition());
    resource.writeBuffer(buffer -> {
        assertNotNull(buffer);
        assertEquals(Float.BYTES * 3 * 10, buffer.capacity());
        assertEquals(Float.BYTES * 3 * 3, buffer.limit());
        int index = 0;
        assertEquals(10.0f, buffer.getFloat((index++) * Float.BYTES), 0.001f);
        assertEquals(10.0f, buffer.getFloat((index++) * Float.BYTES), 0.001f);
        assertEquals(10.0f, buffer.getFloat((index++) * Float.BYTES), 0.001f);
        assertEquals(5.0f, buffer.getFloat((index++) * Float.BYTES), 0.001f);
        assertEquals(10.0f, buffer.getFloat((index++) * Float.BYTES), 0.001f);
        assertEquals(10.0f, buffer.getFloat((index++) * Float.BYTES), 0.001f);
        assertEquals(15.0f, buffer.getFloat((index++) * Float.BYTES), 0.001f);
        assertEquals(10.0f, buffer.getFloat((index++) * Float.BYTES), 0.001f);
        assertEquals(10.0f, buffer.getFloat((index++) * Float.BYTES), 0.001f);
    });
}
Also used : VertexResource(org.terasology.engine.rendering.assets.mesh.resource.VertexResource) Vector3fc(org.joml.Vector3fc) VertexResourceBuilder(org.terasology.engine.rendering.assets.mesh.resource.VertexResourceBuilder) Vector3f(org.joml.Vector3f) Test(org.junit.Test)

Example 17 with Vector3fc

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

the class Mesh method getBound.

protected AABBf getBound(AABBf dest) {
    VertexAttributeBinding<Vector3fc, Vector3f> vertices = this.vertices();
    if (elementCount() == 0) {
        dest.set(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY);
        return dest;
    }
    Vector3f pos = new Vector3f();
    for (int x = 0; x < elementCount(); x++) {
        dest.union(vertices.get(x, pos));
    }
    return dest;
}
Also used : Vector3fc(org.joml.Vector3fc) Vector3f(org.joml.Vector3f)

Example 18 with Vector3fc

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

the class AABBRenderer method generateDisplayListSolid.

private void generateDisplayListSolid() {
    MeshBuilder builder = new MeshBuilder();
    builder.addBox(aabb.extent(new Vector3f()).mul(-1.0f), aabb.extent(new Vector3f()).mul(2.0f), 0.0f, 0.0f).setTextureMapper(new MeshBuilder.TextureMapper() {

        @Override
        public void initialize(Vector3fc offset, Vector3fc size) {
        }

        @Override
        public Vector2fc map(int vertexIndex, float u, float v) {
            switch(vertexIndex) {
                // Front face
                case 0:
                    return new Vector2f(0f, 1f);
                case 1:
                    return new Vector2f(1f, 1f);
                case 2:
                    return new Vector2f(1f, 1);
                case 3:
                    return new Vector2f(0f, 1);
                // Back face
                case 4:
                    return new Vector2f(1f, 1f);
                case 5:
                    return new Vector2f(1f, 1);
                case 6:
                    return new Vector2f(0f, 1);
                case 7:
                    return new Vector2f(0f, 1f);
                // Top face
                case 8:
                    return new Vector2f(1f, 0f);
                case 9:
                    return new Vector2f(1f, 1f);
                case 10:
                    return new Vector2f(0f, 1f);
                case 11:
                    return new Vector2f(0f, 0f);
                // Bottom face
                case 12:
                    return new Vector2f(1f, 0f);
                case 13:
                    return new Vector2f(0f, 0f);
                case 14:
                    return new Vector2f(0f, 1f);
                case 15:
                    return new Vector2f(1f, 1f);
                // Right face
                case 16:
                    return new Vector2f(1f, 1f);
                case 17:
                    return new Vector2f(1f, 1);
                case 18:
                    return new Vector2f(0f, 1);
                case 19:
                    return new Vector2f(0f, 1f);
                // Left face
                case 20:
                    return new Vector2f(0f, 0f);
                case 21:
                    return new Vector2f(1f, 0f);
                case 22:
                    return new Vector2f(1f, 1.0f);
                case 23:
                    return new Vector2f(0f, 1.0f);
                default:
                    throw new RuntimeException("Unreachable state.");
            }
        }
    });
    for (int x = 0; x < 24; x++) {
        builder.addColor(new Color(solidColor.x, solidColor.y, solidColor.z, solidColor.w));
    }
    solidMesh = builder.build();
}
Also used : Vector3fc(org.joml.Vector3fc) Vector2fc(org.joml.Vector2fc) MeshBuilder(org.terasology.engine.rendering.assets.mesh.MeshBuilder) Vector2f(org.joml.Vector2f) Vector3f(org.joml.Vector3f) Color(org.terasology.nui.Color)

Example 19 with Vector3fc

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

the class FloatingTextRenderer method render.

private void render(Iterable<EntityRef> floatingTextEntities) {
    Vector3fc cameraPosition = camera.getPosition();
    Matrix4f model = new Matrix4f();
    Matrix4f modelView = new Matrix4f();
    Vector3f worldPos = new Vector3f();
    for (EntityRef entity : floatingTextEntities) {
        FloatingTextComponent floatingText = entity.getComponent(FloatingTextComponent.class);
        LocationComponent location = entity.getComponent(LocationComponent.class);
        if (location == null) {
            logger.warn("location component is not defined can't render text: {}", floatingText.text);
            continue;
        }
        location.getWorldPosition(worldPos);
        if (!worldProvider.isBlockRelevant(worldPos) || !worldPos.isFinite()) {
            continue;
        }
        String[] linesOfText = floatingText.text.split("\n");
        Color baseColor = floatingText.textColor;
        Color shadowColor = floatingText.textShadowColor;
        boolean underline = false;
        int textWidth = 0;
        for (String singleLine : linesOfText) {
            if (font.getWidth(singleLine) > textWidth) {
                textWidth = font.getWidth(singleLine);
            }
        }
        FontMeshBuilder meshBuilder = new FontMeshBuilder(underlineMaterial);
        Map<Material, Mesh> meshMap = entityMeshCache.get(entity);
        if (meshMap == null) {
            meshMap = meshBuilder.createTextMesh(font, Arrays.asList(linesOfText), textWidth, HorizontalAlign.CENTER, baseColor, shadowColor, underline);
            entityMeshCache.put(entity, meshMap);
        }
        if (floatingText.isOverlay) {
            glDisable(GL_DEPTH_TEST);
        }
        float scale = METER_PER_PIXEL * floatingText.scale;
        model.setTranslation(worldPos.sub(cameraPosition));
        modelView.set(camera.getViewMatrix()).mul(model).m00(1.0f).m10(0.0f).m20(0.0f).m01(0.0f).m11(1.0f).m21(0.0f).m02(0.0f).m12(0.0f).m22(1.0f);
        modelView.scale(scale, -scale, scale);
        modelView.translate(-textWidth / 2.0f, 0.0f, 0.0f);
        for (Map.Entry<Material, Mesh> meshMapEntry : meshMap.entrySet()) {
            Mesh mesh = meshMapEntry.getValue();
            Material material = meshMapEntry.getKey();
            material.enable();
            material.bindTextures();
            material.setFloat4("croppingBoundaries", Float.MIN_VALUE, Float.MAX_VALUE, Float.MIN_VALUE, Float.MAX_VALUE);
            material.setMatrix4("modelViewMatrix", modelView);
            material.setMatrix4("projectionMatrix", camera.getProjectionMatrix());
            material.setFloat2("offset", 0.0f, 0.0f);
            material.setFloat("alpha", 1.0f);
            mesh.render();
        }
        // Revert to default state
        if (floatingText.isOverlay) {
            glEnable(GL_DEPTH_TEST);
        }
    }
}
Also used : Color(org.terasology.nui.Color) Mesh(org.terasology.engine.rendering.assets.mesh.Mesh) Material(org.terasology.engine.rendering.assets.material.Material) LocationComponent(org.terasology.engine.logic.location.LocationComponent) Vector3fc(org.joml.Vector3fc) Matrix4f(org.joml.Matrix4f) FontMeshBuilder(org.terasology.engine.rendering.assets.font.FontMeshBuilder) Vector3f(org.joml.Vector3f) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Map(java.util.Map)

Aggregations

Vector3fc (org.joml.Vector3fc)19 Vector3f (org.joml.Vector3f)15 Test (org.junit.Test)8 VertexResourceBuilder (org.terasology.engine.rendering.assets.mesh.resource.VertexResourceBuilder)8 VertexResource (org.terasology.engine.rendering.assets.mesh.resource.VertexResource)7 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)4 LocationComponent (org.terasology.engine.logic.location.LocationComponent)4 FloatBuffer (java.nio.FloatBuffer)2 Matrix4f (org.joml.Matrix4f)2 Quaternionf (org.joml.Quaternionf)2 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)2 VertexByteAttributeBinding (org.terasology.engine.rendering.assets.mesh.resource.VertexByteAttributeBinding)2 Color (org.terasology.nui.Color)2 com.badlogic.gdx.physics.bullet.collision.btBoxShape (com.badlogic.gdx.physics.bullet.collision.btBoxShape)1 com.badlogic.gdx.physics.bullet.collision.btCapsuleShape (com.badlogic.gdx.physics.bullet.collision.btCapsuleShape)1 com.badlogic.gdx.physics.bullet.collision.btConvexHullShape (com.badlogic.gdx.physics.bullet.collision.btConvexHullShape)1 com.badlogic.gdx.physics.bullet.collision.btCylinderShape (com.badlogic.gdx.physics.bullet.collision.btCylinderShape)1 com.badlogic.gdx.physics.bullet.collision.btManifoldPoint (com.badlogic.gdx.physics.bullet.collision.btManifoldPoint)1 com.badlogic.gdx.physics.bullet.collision.btSphereShape (com.badlogic.gdx.physics.bullet.collision.btSphereShape)1 ItemOverlay (io.xol.chunkstories.api.item.interfaces.ItemOverlay)1