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));
}
}
}
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();
}
}
}
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();
}
}
}
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();
}
}
}
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());
}
Aggregations