Search in sources :

Example 1 with Texture2D

use of com.ardor3d.image.Texture2D in project energy3d by concord-consortium.

the class Scene method applyGroundImage.

private void applyGroundImage() {
    final Mesh mesh = SceneManager.getInstance().getGroundImageLand();
    if (groundImage == null) {
        // set a dummy texture in case the mesh holds the original buffered image and causes memory leak
        mesh.setRenderState(new TextureState());
        mesh.setVisible(false);
        setFoundationsVisible(true);
    } else {
        SceneManager.getInstance().resizeGroundImageLand(groundImageScale);
        final Texture2D texture = new Texture2D();
        texture.setTextureKey(TextureKey.getRTTKey(MinificationFilter.NearestNeighborNoMipMaps));
        texture.setImage(AWTImageLoader.makeArdor3dImage(groundImage, true));
        final TextureState textureState = new TextureState();
        textureState.setTexture(texture);
        mesh.setRenderState(textureState);
        mesh.setVisible(!hideGroundImage);
        setFoundationsVisible(false);
    }
}
Also used : Texture2D(com.ardor3d.image.Texture2D) TextureState(com.ardor3d.renderer.state.TextureState) Mesh(com.ardor3d.scenegraph.Mesh)

Example 2 with Texture2D

use of com.ardor3d.image.Texture2D in project energy3d by concord-consortium.

the class SolarRadiation method applyTexture.

private void applyTexture(final Mesh mesh) {
    if (onMesh.get(mesh) == null) {
        mesh.setDefaultColor(ColorRGBA.BLACK);
        mesh.clearRenderState(StateType.Texture);
        return;
    }
    final double[][] solarData = onMesh.get(mesh).dailySolarIntensity;
    final int rows = solarData.length;
    if (rows == 0) {
        return;
    }
    final int cols = solarData[0].length;
    if (cols == 0) {
        return;
    }
    fillBlanksWithNeighboringValues(solarData);
    final ByteBuffer data = BufferUtils.createByteBuffer(cols * rows * 3);
    for (int row = 0; row < rows; row++) {
        for (int col = 0; col < cols; col++) {
            final ColorRGBA color = computeColor(solarData[row][col], maxValue);
            data.put((byte) (color.getRed() * 255)).put((byte) (color.getGreen() * 255)).put((byte) (color.getBlue() * 255));
        }
    }
    final Image image = new Image(ImageDataFormat.RGB, PixelDataType.UnsignedByte, cols, rows, data, null);
    final Texture2D texture = new Texture2D();
    texture.setTextureKey(TextureKey.getRTTKey(MinificationFilter.NearestNeighborNoMipMaps));
    texture.setImage(image);
    // texture.setWrap(WrapMode.Clamp);
    final TextureState textureState = new TextureState();
    textureState.setTexture(texture);
    mesh.setDefaultColor(ColorRGBA.WHITE);
    mesh.setRenderState(textureState);
}
Also used : Texture2D(com.ardor3d.image.Texture2D) TextureState(com.ardor3d.renderer.state.TextureState) ReadOnlyColorRGBA(com.ardor3d.math.type.ReadOnlyColorRGBA) ColorRGBA(com.ardor3d.math.ColorRGBA) Image(com.ardor3d.image.Image) ByteBuffer(java.nio.ByteBuffer) CullHint(com.ardor3d.scenegraph.hint.CullHint) TPoint(org.poly2tri.triangulation.point.TPoint) Point(org.poly2tri.geometry.primitives.Point)

Aggregations

Texture2D (com.ardor3d.image.Texture2D)2 TextureState (com.ardor3d.renderer.state.TextureState)2 Image (com.ardor3d.image.Image)1 ColorRGBA (com.ardor3d.math.ColorRGBA)1 ReadOnlyColorRGBA (com.ardor3d.math.type.ReadOnlyColorRGBA)1 Mesh (com.ardor3d.scenegraph.Mesh)1 CullHint (com.ardor3d.scenegraph.hint.CullHint)1 ByteBuffer (java.nio.ByteBuffer)1 Point (org.poly2tri.geometry.primitives.Point)1 TPoint (org.poly2tri.triangulation.point.TPoint)1