Search in sources :

Example 1 with TextureKey

use of com.jme3.asset.TextureKey in project jmonkeyengine by jMonkeyEngine.

the class DDSLoader method load.

public Object load(AssetInfo info) throws IOException {
    if (!(info.getKey() instanceof TextureKey)) {
        throw new IllegalArgumentException("Texture assets must be loaded using a TextureKey");
    }
    InputStream stream = null;
    try {
        stream = info.openStream();
        in = new LittleEndien(stream);
        loadHeader();
        if (texture3D) {
            ((TextureKey) info.getKey()).setTextureTypeHint(Texture.Type.ThreeDimensional);
        } else if (depth > 1) {
            ((TextureKey) info.getKey()).setTextureTypeHint(Texture.Type.CubeMap);
        }
        ArrayList<ByteBuffer> data = readData(((TextureKey) info.getKey()).isFlipY());
        return new Image(pixelFormat, width, height, depth, data, sizes, ColorSpace.sRGB);
    } finally {
        if (stream != null) {
            stream.close();
        }
    }
}
Also used : TextureKey(com.jme3.asset.TextureKey) InputStream(java.io.InputStream) Image(com.jme3.texture.Image) ByteBuffer(java.nio.ByteBuffer) LittleEndien(com.jme3.util.LittleEndien)

Example 2 with TextureKey

use of com.jme3.asset.TextureKey in project jmonkeyengine by jMonkeyEngine.

the class J3MLoaderTest method setupMockForTexture.

private TextureKey setupMockForTexture(final String paramName, final String path, final boolean flipY, final Texture texture) {
    when(materialDef.getMaterialParam(paramName)).thenReturn(new MatParamTexture(VarType.Texture2D, paramName, texture, null));
    final TextureKey textureKey = new TextureKey(path, flipY);
    textureKey.setGenerateMips(true);
    when(assetManager.loadTexture(textureKey)).thenReturn(texture);
    return textureKey;
}
Also used : TextureKey(com.jme3.asset.TextureKey) MatParamTexture(com.jme3.material.MatParamTexture)

Example 3 with TextureKey

use of com.jme3.asset.TextureKey in project jmonkeyengine by jMonkeyEngine.

the class J3MLoaderTest method oldStyleTextureParameters_shouldBeSupported.

@Test
public void oldStyleTextureParameters_shouldBeSupported() throws Exception {
    when(assetInfo.openStream()).thenReturn(J3MLoader.class.getResourceAsStream("/texture-parameters-oldstyle.j3m"));
    final Texture textureOldStyle = Mockito.mock(Texture.class);
    final Texture textureOldStyleUsingQuotes = Mockito.mock(Texture.class);
    final TextureKey textureKeyUsingQuotes = setupMockForTexture("OldStyleUsingQuotes", "old style using quotes/texture.png", true, textureOldStyleUsingQuotes);
    final TextureKey textureKeyOldStyle = setupMockForTexture("OldStyle", "old style/texture.png", true, textureOldStyle);
    j3MLoader.load(assetInfo);
    verify(assetManager).loadTexture(textureKeyUsingQuotes);
    verify(assetManager).loadTexture(textureKeyOldStyle);
    verify(textureOldStyle).setWrap(Texture.WrapMode.Repeat);
    verify(textureOldStyleUsingQuotes).setWrap(Texture.WrapMode.Repeat);
}
Also used : TextureKey(com.jme3.asset.TextureKey) MatParamTexture(com.jme3.material.MatParamTexture) Texture(com.jme3.texture.Texture) Test(org.junit.Test)

Example 4 with TextureKey

use of com.jme3.asset.TextureKey in project jmonkeyengine by jMonkeyEngine.

the class J3MLoaderTest method newStyleTextureParameters_shouldBeSupported.

@Test
public void newStyleTextureParameters_shouldBeSupported() throws Exception {
    when(assetInfo.openStream()).thenReturn(J3MLoader.class.getResourceAsStream("/texture-parameters-newstyle.j3m"));
    final Texture textureNoParameters = Mockito.mock(Texture.class);
    final Texture textureFlip = Mockito.mock(Texture.class);
    final Texture textureRepeat = Mockito.mock(Texture.class);
    final Texture textureRepeatAxis = Mockito.mock(Texture.class);
    final Texture textureMin = Mockito.mock(Texture.class);
    final Texture textureMag = Mockito.mock(Texture.class);
    final Texture textureCombined = Mockito.mock(Texture.class);
    final Texture textureLooksLikeOldStyle = Mockito.mock(Texture.class);
    final TextureKey textureKeyNoParameters = setupMockForTexture("Empty", "empty.png", false, textureNoParameters);
    final TextureKey textureKeyFlip = setupMockForTexture("Flip", "flip.png", true, textureFlip);
    setupMockForTexture("Repeat", "repeat.png", false, textureRepeat);
    setupMockForTexture("RepeatAxis", "repeat-axis.png", false, textureRepeatAxis);
    setupMockForTexture("Min", "min.png", false, textureMin);
    setupMockForTexture("Mag", "mag.png", false, textureMag);
    setupMockForTexture("Combined", "combined.png", true, textureCombined);
    setupMockForTexture("LooksLikeOldStyle", "oldstyle.png", true, textureLooksLikeOldStyle);
    j3MLoader.load(assetInfo);
    verify(assetManager).loadTexture(textureKeyNoParameters);
    verify(assetManager).loadTexture(textureKeyFlip);
    verify(textureRepeat).setWrap(Texture.WrapMode.Repeat);
    verify(textureRepeatAxis).setWrap(Texture.WrapAxis.T, Texture.WrapMode.Repeat);
    verify(textureMin).setMinFilter(Texture.MinFilter.Trilinear);
    verify(textureMag).setMagFilter(Texture.MagFilter.Bilinear);
    verify(textureCombined).setMagFilter(Texture.MagFilter.Nearest);
    verify(textureCombined).setMinFilter(Texture.MinFilter.BilinearNoMipMaps);
    verify(textureCombined).setWrap(Texture.WrapMode.Repeat);
}
Also used : TextureKey(com.jme3.asset.TextureKey) MatParamTexture(com.jme3.material.MatParamTexture) Texture(com.jme3.texture.Texture) Test(org.junit.Test)

Example 5 with TextureKey

use of com.jme3.asset.TextureKey in project jmonkeyengine by jMonkeyEngine.

the class HDRLoader method load.

public Object load(AssetInfo info) throws IOException {
    if (!(info.getKey() instanceof TextureKey))
        throw new IllegalArgumentException("Texture assets must be loaded using a TextureKey");
    boolean flip = ((TextureKey) info.getKey()).isFlipY();
    InputStream in = null;
    try {
        in = info.openStream();
        Image img = load(in, flip);
        return img;
    } finally {
        if (in != null) {
            in.close();
        }
    }
}
Also used : TextureKey(com.jme3.asset.TextureKey) InputStream(java.io.InputStream) Image(com.jme3.texture.Image)

Aggregations

TextureKey (com.jme3.asset.TextureKey)37 Texture (com.jme3.texture.Texture)26 Material (com.jme3.material.Material)16 Image (com.jme3.texture.Image)9 InputStream (java.io.InputStream)9 Geometry (com.jme3.scene.Geometry)7 Vector3f (com.jme3.math.Vector3f)6 Texture2D (com.jme3.texture.Texture2D)6 MatParamTexture (com.jme3.material.MatParamTexture)4 AssetLoadException (com.jme3.asset.AssetLoadException)3 AssetNotFoundException (com.jme3.asset.AssetNotFoundException)3 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)3 DirectionalLight (com.jme3.light.DirectionalLight)3 ByteBuffer (java.nio.ByteBuffer)3 AssetManager (com.jme3.asset.AssetManager)2 Vector2f (com.jme3.math.Vector2f)2 FilterPostProcessor (com.jme3.post.FilterPostProcessor)2 Spatial (com.jme3.scene.Spatial)2 Box (com.jme3.scene.shape.Box)2 Quad (com.jme3.scene.shape.Quad)2