Search in sources :

Example 1 with TextureState

use of com.ardor3d.renderer.state.TextureState 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 TextureState

use of com.ardor3d.renderer.state.TextureState in project energy3d by concord-consortium.

the class SceneManager method changeSkyTexture.

public void changeSkyTexture() {
    if (sky != null) {
        final boolean isNightTime = Heliodon.getInstance().isNightTime();
        String textureFile;
        switch(Scene.getInstance().getTheme()) {
            case Scene.DESERT_THEME:
                textureFile = isNightTime ? "desert-night.jpg" : "desert.jpg";
                break;
            case Scene.GRASSLAND_THEME:
                textureFile = isNightTime ? "grassland-night.jpg" : "grassland.jpg";
                break;
            case Scene.FOREST_THEME:
                textureFile = isNightTime ? "forest-night.jpg" : "forest.jpg";
                break;
            default:
                textureFile = isNightTime ? "nightsky.jpg" : "daysky.jpg";
        }
        final TextureState ts = new TextureState();
        ts.setTexture(TextureManager.load(textureFile, Texture.MinificationFilter.Trilinear, TextureStoreFormat.GuessNoCompressedFormat, true));
        sky.setRenderState(ts);
    }
}
Also used : TextureState(com.ardor3d.renderer.state.TextureState)

Example 3 with TextureState

use of com.ardor3d.renderer.state.TextureState 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)

Example 4 with TextureState

use of com.ardor3d.renderer.state.TextureState in project energy3d by concord-consortium.

the class Scene method destroy.

// just in case to prevent possible memory leaks
private void destroy() {
    for (final HousePart p : parts) {
        p.delete();
        // detachment cannot be put into delete(), we detach all children here to help garbage collection
        p.getRoot().detachAllChildren();
    }
    parts.clear();
    if (groundImage != null) {
        groundImage.flush();
        groundImage = null;
    }
    if (SceneManager.getInstance().getGroundImageLand() != null) {
        SceneManager.getInstance().getGroundImageLand().setRenderState(new TextureState());
    }
    if (foundationGroups != null) {
        foundationGroups.clear();
    }
}
Also used : TextureState(com.ardor3d.renderer.state.TextureState) HousePart(org.concord.energy3d.model.HousePart)

Example 5 with TextureState

use of com.ardor3d.renderer.state.TextureState in project energy3d by concord-consortium.

the class SceneManager method createSky.

private Mesh createSky() {
    final Dome sky = new Dome("Sky", 100, 100, SKY_RADIUS);
    sky.setRotation(new Matrix3().fromAngles(Math.PI / 2, 0, 0));
    sky.getSceneHints().setLightCombineMode(LightCombineMode.Off);
    sky.getSceneHints().setAllPickingHints(false);
    sky.updateModelBound();
    sky.updateWorldBound(true);
    final TextureState ts = new TextureState();
    ts.setTexture(TextureManager.load("daysky.jpg", Texture.MinificationFilter.Trilinear, TextureStoreFormat.GuessNoCompressedFormat, true));
    sky.setRenderState(ts);
    return sky;
}
Also used : Dome(com.ardor3d.scenegraph.shape.Dome) TextureState(com.ardor3d.renderer.state.TextureState) Matrix3(com.ardor3d.math.Matrix3)

Aggregations

TextureState (com.ardor3d.renderer.state.TextureState)9 ReadOnlyVector3 (com.ardor3d.math.type.ReadOnlyVector3)3 Mesh (com.ardor3d.scenegraph.Mesh)3 Texture (com.ardor3d.image.Texture)2 Texture2D (com.ardor3d.image.Texture2D)2 ReadOnlyVector2 (com.ardor3d.math.type.ReadOnlyVector2)2 CullHint (com.ardor3d.scenegraph.hint.CullHint)2 FloatBuffer (java.nio.FloatBuffer)2 ArrayList (java.util.ArrayList)2 GroupData (org.concord.energy3d.util.MeshLib.GroupData)2 BoundingBox (com.ardor3d.bounding.BoundingBox)1 Image (com.ardor3d.image.Image)1 ColorRGBA (com.ardor3d.math.ColorRGBA)1 Matrix3 (com.ardor3d.math.Matrix3)1 Vector2 (com.ardor3d.math.Vector2)1 Vector3 (com.ardor3d.math.Vector3)1 ReadOnlyColorRGBA (com.ardor3d.math.type.ReadOnlyColorRGBA)1 Line (com.ardor3d.scenegraph.Line)1 Node (com.ardor3d.scenegraph.Node)1 Spatial (com.ardor3d.scenegraph.Spatial)1