Search in sources :

Example 36 with AssetInfo

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

the class TestMaterialDefWrite method testWriteMat.

@Test
public void testWriteMat() throws Exception {
    Material mat = new Material(assetManager, "example.j3md");
    final ByteArrayOutputStream stream = new ByteArrayOutputStream();
    J3mdExporter exporter = new J3mdExporter();
    try {
        exporter.save(mat.getMaterialDef(), stream);
    } catch (IOException e) {
        e.printStackTrace();
    }
    //   System.err.println(stream.toString());
    J3MLoader loader = new J3MLoader();
    AssetInfo info = new AssetInfo(assetManager, new AssetKey("test")) {

        @Override
        public InputStream openStream() {
            return new ByteArrayInputStream(stream.toByteArray());
        }
    };
    MaterialDef matDef = (MaterialDef) loader.load(info);
    MaterialDef ref = mat.getMaterialDef();
    for (MatParam refParam : ref.getMaterialParams()) {
        MatParam matParam = matDef.getMaterialParam(refParam.getName());
        assertTrue(refParam != null);
        assertEquals(refParam, matParam);
    }
    for (String key : ref.getTechniqueDefsNames()) {
        List<TechniqueDef> refDefs = ref.getTechniqueDefs(key);
        List<TechniqueDef> defs = matDef.getTechniqueDefs(key);
        assertNotNull(defs);
        assertTrue(refDefs.size() == defs.size());
        for (int i = 0; i < refDefs.size(); i++) {
            assertEqualTechniqueDefs(refDefs.get(i), defs.get(i));
        }
    }
}
Also used : J3MLoader(com.jme3.material.plugins.J3MLoader) J3mdExporter(com.jme3.material.plugin.export.materialdef.J3mdExporter)

Example 37 with AssetInfo

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

the class TGALoader 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) DataInputStream(java.io.DataInputStream) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) Image(com.jme3.texture.Image)

Example 38 with AssetInfo

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

the class KTXLoader method load.

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

Example 39 with AssetInfo

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

the class CursorLoader method load.

/**
     * Loads and return a cursor file of one of the following format: .ani, .cur and .ico.
     * @param info The {@link AssetInfo} describing the cursor file.
     * @return A JmeCursor representation of the LWJGL's Cursor.
     * @throws IOException if the file is not found.
     */
public JmeCursor load(AssetInfo info) throws IOException {
    isIco = false;
    isAni = false;
    isCur = false;
    isIco = ((AssetKey) info.getKey()).getExtension().equals("ico");
    if (!isIco) {
        isCur = ((AssetKey) info.getKey()).getExtension().equals("cur");
        if (!isCur) {
            isAni = ((AssetKey) info.getKey()).getExtension().equals("ani");
        }
    }
    if (!isAni && !isIco && !isCur) {
        throw new IllegalArgumentException("Cursors supported are .ico, .cur or .ani");
    }
    InputStream in = null;
    try {
        in = info.openStream();
        return loadCursor(in);
    } finally {
        if (in != null) {
            in.close();
        }
    }
}
Also used : AssetKey(com.jme3.asset.AssetKey) DataInputStream(java.io.DataInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream)

Example 40 with AssetInfo

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

the class J3MLoaderTest method multipleSameNamedTechniques_shouldBeSupported.

@Test
public void multipleSameNamedTechniques_shouldBeSupported() throws IOException {
    when(assetInfo.openStream()).thenReturn(J3MLoader.class.getResourceAsStream("/same-name-technique.j3md"));
    MaterialDef def = (MaterialDef) j3MLoader.load(assetInfo);
    assertEquals(2, def.getTechniqueDefs("Test").size());
    assertEquals(EnumSet.of(Caps.GLSL150), def.getTechniqueDefs("Test").get(0).getRequiredCaps());
    assertEquals(EnumSet.of(Caps.GLSL100), def.getTechniqueDefs("Test").get(1).getRequiredCaps());
}
Also used : MaterialDef(com.jme3.material.MaterialDef) Test(org.junit.Test)

Aggregations

InputStream (java.io.InputStream)17 TextureKey (com.jme3.asset.TextureKey)12 IOException (java.io.IOException)9 Image (com.jme3.texture.Image)7 AssetInfo (com.jme3.asset.AssetInfo)6 Texture (com.jme3.texture.Texture)6 AssetLoadException (com.jme3.asset.AssetLoadException)5 Test (org.junit.Test)5 AssetKey (com.jme3.asset.AssetKey)4 AssetNotFoundException (com.jme3.asset.AssetNotFoundException)4 ModelKey (com.jme3.asset.ModelKey)4 InputStreamReader (java.io.InputStreamReader)4 BlenderKey (com.jme3.asset.BlenderKey)3 AudioStream (com.jme3.audio.AudioStream)3 MaterialDef (com.jme3.material.MaterialDef)3 DataInputStream (java.io.DataInputStream)3 AssetFileDescriptor (android.content.res.AssetFileDescriptor)2 AssetManager (com.jme3.asset.AssetManager)2 AndroidAssetInfo (com.jme3.asset.plugins.AndroidLocator.AndroidAssetInfo)2 AudioBuffer (com.jme3.audio.AudioBuffer)2