use of com.jme3.asset.TextureKey in project jmonkeyengine by jMonkeyEngine.
the class MaterialLoader method readTextureImage.
private void readTextureImage(String content) {
// texture image def
String path = null;
// find extension
int extStart = content.lastIndexOf(".");
for (int i = extStart; i < content.length(); i++) {
char c = content.charAt(i);
if (Character.isWhitespace(c)) {
// extension ends here
path = content.substring(0, i).trim();
content = content.substring(i + 1).trim();
break;
}
}
if (path == null) {
path = content.trim();
content = "";
}
Scanner lnScan = new Scanner(content);
String mips = null;
String type = null;
if (lnScan.hasNext()) {
// more params
type = lnScan.next();
// if (!lnScan.hasNext("\n") && lnScan.hasNext()){
// mips = lnScan.next();
// if (lnScan.hasNext()){
// even more params..
// will have to ignore
// }
// }
}
boolean genMips = true;
boolean cubic = false;
if (type != null && type.equals("0"))
genMips = false;
if (type != null && type.equals("cubic")) {
cubic = true;
}
TextureKey texKey = new TextureKey(folderName + path, false);
texKey.setGenerateMips(genMips);
if (cubic) {
texKey.setTextureTypeHint(Texture.Type.CubeMap);
}
try {
Texture loadedTexture = assetManager.loadTexture(texKey);
textures[texUnit].setImage(loadedTexture.getImage());
textures[texUnit].setMinFilter(loadedTexture.getMinFilter());
textures[texUnit].setMagFilter(loadedTexture.getMagFilter());
textures[texUnit].setAnisotropicFilter(loadedTexture.getAnisotropicFilter());
textures[texUnit].setKey(loadedTexture.getKey());
// XXX: Is this really neccessary?
textures[texUnit].setWrap(WrapMode.Repeat);
if (texName != null) {
textures[texUnit].setName(texName);
texName = null;
} else {
textures[texUnit].setName(texKey.getName());
}
} catch (AssetNotFoundException ex) {
logger.log(Level.WARNING, "Cannot locate {0} for material {1}", new Object[] { texKey, matName });
textures[texUnit].setImage(PlaceholderAssets.getPlaceholderImage(assetManager));
textures[texUnit].setKey(texKey);
}
}
Aggregations