use of com.jme3.asset.AssetInfo in project jmonkeyengine by jMonkeyEngine.
the class AWTLoader method load.
public Object load(AssetInfo info) throws IOException {
if (ImageIO.getImageReadersBySuffix(info.getKey().getExtension()) != null) {
boolean flip = ((TextureKey) info.getKey()).isFlipY();
InputStream in = null;
try {
in = info.openStream();
Image img = load(in, flip);
if (img == null) {
throw new AssetLoadException("The given image cannot be loaded " + info.getKey());
}
return img;
} finally {
if (in != null) {
in.close();
}
}
} else {
throw new AssetLoadException("The extension " + info.getKey().getExtension() + " is not supported");
}
}
use of com.jme3.asset.AssetInfo in project jmonkeyengine by jMonkeyEngine.
the class ImageTileLoader method getHeightMapAt.
/**
* Lets you specify the type of images that are being loaded. All images
* must be the same type.
* @param imageType eg. BufferedImage.TYPE_USHORT_GRAY
*/
/*public void setImageType(int imageType) {
this.imageType = imageType;
}*/
/**
* The ImageHeightmap that will parse the image type that you
* specify with setImageType().
* @param customImageHeightmap must extend AbstractHeightmap
*/
/*public void setCustomImageHeightmap(ImageHeightmap customImageHeightmap) {
if (!(customImageHeightmap instanceof AbstractHeightMap)) {
throw new IllegalArgumentException("customImageHeightmap must be an AbstractHeightMap!");
}
this.customImageHeightmap = customImageHeightmap;
}*/
private HeightMap getHeightMapAt(Vector3f location) {
// HEIGHTMAP image (for the terrain heightmap)
int x = (int) location.x;
int z = (int) location.z;
AbstractHeightMap heightmap = null;
//BufferedImage im = null;
String name = null;
try {
name = namer.getName(x, z);
logger.log(Level.FINE, "Loading heightmap from file: {0}", name);
final Texture texture = assetManager.loadTexture(new TextureKey(name));
heightmap = new ImageBasedHeightMap(texture.getImage());
/*if (assetInfo != null){
InputStream in = assetInfo.openStream();
im = ImageIO.read(in);
} else {
im = new BufferedImage(patchSize, patchSize, imageType);
logger.log(Level.WARNING, "File: {0} not found, loading zero heightmap instead", name);
}*/
// CREATE HEIGHTMAP
/*if (imageType == BufferedImage.TYPE_USHORT_GRAY) {
heightmap = new Grayscale16BitHeightMap(im);
} else if (imageType == BufferedImage.TYPE_3BYTE_BGR) {
heightmap = new ImageBasedHeightMap(im);
} else if (customImageHeightmap != null && customImageHeightmap instanceof AbstractHeightMap) {
// If it gets here, it means you have specified a different image type, and you must
// then also supply a custom image heightmap class that can parse that image into
// a heightmap.
customImageHeightmap.setImage(im);
heightmap = (AbstractHeightMap) customImageHeightmap;
} else {
// error, no supported image format and no custom image heightmap specified
if (customImageHeightmap == null)
logger.log(Level.SEVERE, "Custom image type specified [{0}] but no customImageHeightmap declared! Use setCustomImageHeightmap()",imageType);
if (!(customImageHeightmap instanceof AbstractHeightMap))
logger.severe("customImageHeightmap must be an AbstractHeightMap!");
return null;
}*/
heightmap.setHeightScale(1);
heightmap.load();
//} catch (IOException e) {
// e.printStackTrace();
} catch (AssetNotFoundException e) {
logger.log(Level.WARNING, "Asset {0} not found, loading zero heightmap instead", name);
}
return heightmap;
}
use of com.jme3.asset.AssetInfo in project jmonkeyengine by jMonkeyEngine.
the class AssetLinkNode method read.
@Override
public void read(JmeImporter e) throws IOException {
super.read(e);
InputCapsule capsule = e.getCapsule(this);
BinaryImporter importer = BinaryImporter.getInstance();
AssetManager loaderManager = e.getAssetManager();
assetLoaderKeys = (ArrayList<ModelKey>) capsule.readSavableArrayList("assetLoaderKeyList", new ArrayList<ModelKey>());
for (Iterator<ModelKey> it = assetLoaderKeys.iterator(); it.hasNext(); ) {
ModelKey modelKey = it.next();
AssetInfo info = loaderManager.locateAsset(modelKey);
Spatial child = null;
if (info != null) {
child = (Spatial) importer.load(info);
}
if (child != null) {
child.parent = this;
children.add(child);
assetChildren.put(modelKey, child);
} else {
Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "Cannot locate {0} for asset link node {1}", new Object[] { modelKey, key });
}
}
}
use of com.jme3.asset.AssetInfo in project jmonkeyengine by jMonkeyEngine.
the class SceneMeshLoader method load.
@Override
public Object load(AssetInfo info) throws IOException {
AssetKey key = info.getKey();
Spatial output = cache.get(key);
if (output == null) {
output = (Spatial) super.load(info);
cache.put(key, output);
}
return output.clone(false);
}
use of com.jme3.asset.AssetInfo in project jmonkeyengine by jMonkeyEngine.
the class TestMaterialWrite method testWriteMat.
@Test
public void testWriteMat() throws Exception {
Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
mat.setBoolean("UseMaterialColors", true);
mat.setColor("Diffuse", ColorRGBA.White);
mat.setColor("Ambient", ColorRGBA.DarkGray);
mat.setFloat("AlphaDiscardThreshold", 0.5f);
mat.setFloat("Shininess", 2.5f);
Texture tex = assetManager.loadTexture("Common/Textures/MissingTexture.png");
tex.setMagFilter(Texture.MagFilter.Nearest);
tex.setMinFilter(Texture.MinFilter.BilinearNoMipMaps);
tex.setWrap(Texture.WrapAxis.S, Texture.WrapMode.Repeat);
tex.setWrap(Texture.WrapAxis.T, Texture.WrapMode.MirroredRepeat);
mat.setTexture("DiffuseMap", tex);
mat.getAdditionalRenderState().setDepthWrite(false);
mat.getAdditionalRenderState().setDepthTest(false);
mat.getAdditionalRenderState().setLineWidth(5);
mat.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha);
final ByteArrayOutputStream stream = new ByteArrayOutputStream();
J3MExporter exporter = new J3MExporter();
try {
exporter.save(mat, 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());
}
};
Material mat2 = (Material) loader.load(info);
assertTrue(mat.contentEquals(mat2));
}
Aggregations