Search in sources :

Example 1 with Tessellator

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

the class BlockSelectionRenderer method initialize.

private void initialize() {
    Tessellator tessellator = new Tessellator();
    TessellatorHelper.addBlockMesh(tessellator, new Vector4f(1, 1, 1, 1f), textureRegion.min(), textureRegion.size(), 1.001f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f);
    overlayMesh = tessellator.generateMesh();
    tessellator = new Tessellator();
    TessellatorHelper.addBlockMesh(tessellator, new Vector4f(1, 1, 1, .2f), textureRegion.min(), textureRegion.size(), 1.001f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f);
    overlayMesh2 = tessellator.generateMesh();
    defaultTextured = Assets.getMaterial("engine:prog.defaultTextured").get();
}
Also used : Tessellator(org.terasology.rendering.primitives.Tessellator) Vector4f(org.terasology.math.geom.Vector4f)

Example 2 with Tessellator

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

the class IconMeshFactory method generateIconMeshData.

public static MeshData generateIconMeshData(TextureRegion tex, int alphaLimit, boolean withContour, Vector4f colorContour) {
    ByteBuffer buffer = tex.getTexture().getData().getBuffers()[0];
    Rect2i pixelRegion = tex.getPixelRegion();
    int posX = pixelRegion.minX();
    int posY = pixelRegion.minY();
    int stride = tex.getTexture().getWidth() * 4;
    float textureSize = Math.max(tex.getWidth(), tex.getHeight());
    Tessellator tessellator = new Tessellator();
    for (int y = 0; y < tex.getHeight(); y++) {
        for (int x = 0; x < tex.getWidth(); x++) {
            int r = buffer.get((posY + y) * stride + (posX + x) * 4) & 255;
            int g = buffer.get((posY + y) * stride + (posX + x) * 4 + 1) & 255;
            int b = buffer.get((posY + y) * stride + (posX + x) * 4 + 2) & 255;
            int a = buffer.get((posY + y) * stride + (posX + x) * 4 + 3) & 255;
            if (a > alphaLimit) {
                Vector4f color = new Vector4f(r / 255f, g / 255f, b / 255f, a / 255f);
                TessellatorHelper.addBlockMesh(tessellator, color, 2f / textureSize, 1.0f, 0.5f, 2f / textureSize * x - 1f, 2f / textureSize * (tex.getHeight() - y - 1) - 1f, 0f);
                if (withContour) {
                    int newX = 0;
                    int newY = 0;
                    int newA = 0;
                    for (int i = 0; i < 4; i++) {
                        newA = alphaLimit + 1;
                        switch(i) {
                            case 0:
                                // check left
                                if (x > 0) {
                                    newX = x - 1;
                                    newY = y;
                                    newA = buffer.get((posY + newY) * stride + (posX + newX) * 4 + 3) & 255;
                                }
                                break;
                            case 1:
                                // check top
                                if (y > 0) {
                                    newX = x;
                                    newY = y - 1;
                                    newA = buffer.get((posY + newY) * stride + (posX + newX) * 4 + 3) & 255;
                                }
                                break;
                            case 2:
                                // check right
                                if (x < 16) {
                                    newX = x + 1;
                                    newY = y;
                                    newA = buffer.get((posY + newY) * stride + (posX + newX) * 4 + 3) & 255;
                                }
                                break;
                            case 3:
                                // check bottom
                                if (y < 16) {
                                    newX = x;
                                    newY = y + 1;
                                    newA = buffer.get((posY + newY) * stride + (posX + newX) * 4 + 3) & 255;
                                }
                                break;
                            default:
                                break;
                        }
                        if (newA < alphaLimit) {
                            Vector4f cColor = new Vector4f(colorContour.x / 255f, colorContour.y / 255f, colorContour.z / 255f, colorContour.w);
                            TessellatorHelper.addBlockMesh(tessellator, cColor, 0.125f, 1.0f, 0.5f, 2f * 0.0625f * newX - 0.5f, 0.125f * (15 - newY) - 1f, 0f);
                        }
                    }
                }
            }
        }
    }
    return tessellator.generateMeshData();
}
Also used : Rect2i(org.terasology.math.geom.Rect2i) Tessellator(org.terasology.rendering.primitives.Tessellator) Vector4f(org.terasology.math.geom.Vector4f) ByteBuffer(java.nio.ByteBuffer)

Example 3 with Tessellator

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

the class InitialiseGraphics method step.

@Override
public boolean step() {
    // Refresh widget library after modules got laoded:
    NUIManager nuiManager = context.get(NUIManager.class);
    ((NUIManagerInternal) nuiManager).refreshWidgetsLibrary();
    // TODO: This should be elsewhere
    // Create gelatinousCubeMesh
    Tessellator tessellator = new Tessellator();
    TessellatorHelper.addBlockMesh(tessellator, new Vector4f(1.0f, 1.0f, 1.0f, 1.0f), 0.8f, 0.8f, 0.6f, 0f, 0f, 0f);
    TessellatorHelper.addBlockMesh(tessellator, new Vector4f(1.0f, 1.0f, 1.0f, 0.6f), 1.0f, 1.0f, 0.8f, 0f, 0f, 0f);
    tessellator.generateMesh(new ResourceUrn(TerasologyConstants.ENGINE_MODULE, new Name("gelatinousCube")));
    return true;
}
Also used : Tessellator(org.terasology.rendering.primitives.Tessellator) Vector4f(org.terasology.math.geom.Vector4f) NUIManager(org.terasology.rendering.nui.NUIManager) ResourceUrn(org.terasology.assets.ResourceUrn) NUIManagerInternal(org.terasology.rendering.nui.internal.NUIManagerInternal) Name(org.terasology.naming.Name)

Aggregations

Vector4f (org.terasology.math.geom.Vector4f)3 Tessellator (org.terasology.rendering.primitives.Tessellator)3 ByteBuffer (java.nio.ByteBuffer)1 ResourceUrn (org.terasology.assets.ResourceUrn)1 Rect2i (org.terasology.math.geom.Rect2i)1 Name (org.terasology.naming.Name)1 NUIManager (org.terasology.rendering.nui.NUIManager)1 NUIManagerInternal (org.terasology.rendering.nui.internal.NUIManagerInternal)1