use of com.jme3.asset.AssetNotFoundException in project jmonkeyengine by jMonkeyEngine.
the class JmeDesktopSystem method showSettingsDialog.
@Override
public boolean showSettingsDialog(AppSettings sourceSettings, final boolean loadFromRegistry) {
if (SwingUtilities.isEventDispatchThread()) {
throw new IllegalStateException("Cannot run from EDT");
}
if (GraphicsEnvironment.isHeadless()) {
throw new IllegalStateException("Cannot show dialog in headless environment");
}
final AppSettings settings = new AppSettings(false);
settings.copyFrom(sourceSettings);
String iconPath = sourceSettings.getSettingsDialogImage();
if (iconPath == null) {
iconPath = "";
}
final URL iconUrl = JmeSystem.class.getResource(iconPath.startsWith("/") ? iconPath : "/" + iconPath);
if (iconUrl == null) {
throw new AssetNotFoundException(sourceSettings.getSettingsDialogImage());
}
final AtomicBoolean done = new AtomicBoolean();
final AtomicInteger result = new AtomicInteger();
final Object lock = new Object();
final SelectionListener selectionListener = new SelectionListener() {
public void onSelection(int selection) {
synchronized (lock) {
done.set(true);
result.set(selection);
lock.notifyAll();
}
}
};
SwingUtilities.invokeLater(new Runnable() {
public void run() {
synchronized (lock) {
SettingsDialog dialog = new SettingsDialog(settings, iconUrl, loadFromRegistry);
dialog.setSelectionListener(selectionListener);
dialog.showDialog();
}
}
});
synchronized (lock) {
while (!done.get()) {
try {
lock.wait();
} catch (InterruptedException ex) {
}
}
}
sourceSettings.copyFrom(settings);
return result.get() == SettingsDialog.APPROVE_SELECTION;
}
use of com.jme3.asset.AssetNotFoundException in project jmonkeyengine by jMonkeyEngine.
the class MeshLoader method load.
public Object load(AssetInfo info) throws IOException {
try {
key = info.getKey();
meshName = key.getName();
folderName = key.getFolder();
String ext = key.getExtension();
meshName = meshName.substring(0, meshName.length() - ext.length() - 1);
if (folderName != null && folderName.length() > 0) {
meshName = meshName.substring(folderName.length());
}
assetManager = info.getManager();
if (key instanceof OgreMeshKey) {
// OgreMeshKey is being used, try getting the material list
// from it
OgreMeshKey meshKey = (OgreMeshKey) key;
materialList = meshKey.getMaterialList();
String materialName = meshKey.getMaterialName();
// Material list not set but material name is available
if (materialList == null && materialName != null) {
OgreMaterialKey materialKey = new OgreMaterialKey(folderName + materialName + ".material");
try {
materialList = (MaterialList) assetManager.loadAsset(materialKey);
} catch (AssetNotFoundException e) {
logger.log(Level.WARNING, "Cannot locate {0} for model {1}", new Object[] { materialKey, key });
}
}
} else {
// Make sure to reset it to null so that previous state
// doesn't leak onto this one
materialList = null;
}
// default method.
if (materialList == null) {
OgreMaterialKey materialKey = new OgreMaterialKey(folderName + meshName + ".material");
try {
materialList = (MaterialList) assetManager.loadAsset(materialKey);
} catch (AssetNotFoundException e) {
logger.log(Level.WARNING, "Cannot locate {0} for model {1}", new Object[] { materialKey, key });
}
}
// Added by larynx 25.06.2011
// Android needs the namespace aware flag set to true
// Kirill 30.06.2011
// Now, hack is applied for both desktop and android to avoid
// checking with JmeSystem.
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
XMLReader xr = factory.newSAXParser().getXMLReader();
xr.setContentHandler(this);
xr.setErrorHandler(this);
InputStreamReader r = null;
try {
r = new InputStreamReader(info.openStream());
xr.parse(new InputSource(r));
} finally {
if (r != null) {
r.close();
}
}
return compileModel();
} catch (SAXException ex) {
IOException ioEx = new IOException("Error while parsing Ogre3D mesh.xml");
ioEx.initCause(ex);
throw ioEx;
} catch (ParserConfigurationException ex) {
IOException ioEx = new IOException("Error while parsing Ogre3D mesh.xml");
ioEx.initCause(ex);
throw ioEx;
}
}
use of com.jme3.asset.AssetNotFoundException in project jmonkeyengine by jMonkeyEngine.
the class SceneLoader method parseEntity.
private void parseEntity(Attributes attribs) throws SAXException {
String name = attribs.getValue("name");
if (name == null) {
name = "OgreEntity-" + (++nodeIdx);
} else {
name += "-entity";
}
String meshFile = attribs.getValue("meshFile");
if (meshFile == null) {
throw new SAXException("Required attribute 'meshFile' missing for 'entity' node");
}
// TODO: Not currently used
String materialName = attribs.getValue("materialName");
if (folderName != null) {
meshFile = folderName + meshFile;
}
// NOTE: append "xml" since its assumed mesh files are binary in dotScene
meshFile += ".xml";
entityNode = new com.jme3.scene.Node(name);
OgreMeshKey meshKey = new OgreMeshKey(meshFile, materialList);
try {
try {
Spatial ogreMesh = (Spatial) meshLoader.load(assetManager.locateAsset(meshKey));
entityNode.attachChild(ogreMesh);
} catch (IOException e) {
throw new AssetNotFoundException(meshKey.toString());
}
} catch (AssetNotFoundException ex) {
if (ex.getMessage().equals(meshFile)) {
logger.log(Level.WARNING, "Cannot locate {0} for scene {1}", new Object[] { meshKey, key });
// Attach placeholder asset.
Spatial model = PlaceholderAssets.getPlaceholderModel(assetManager);
model.setKey(key);
entityNode.attachChild(model);
} else {
throw ex;
}
}
node.attachChild(entityNode);
node = null;
}
use of com.jme3.asset.AssetNotFoundException in project jmonkeyengine by jMonkeyEngine.
the class SceneLoader method load.
public Object load(AssetInfo info) throws IOException {
try {
key = info.getKey();
assetManager = info.getManager();
sceneName = key.getName();
String ext = key.getExtension();
folderName = key.getFolder();
sceneName = sceneName.substring(0, sceneName.length() - ext.length() - 1);
reset();
// == Run 1st pass over XML file to determine material list ==
materialList = materialLoader.load(assetManager, folderName, info.openStream());
if (materialList == null || materialList.isEmpty()) {
// NOTE: No materials were found by searching the externals section.
// Try finding a similarly named material file in the same folder.
// (Backward compatibility only!)
OgreMaterialKey materialKey = new OgreMaterialKey(sceneName + ".material");
try {
materialList = (MaterialList) assetManager.loadAsset(materialKey);
} catch (AssetNotFoundException ex) {
logger.log(Level.WARNING, "Cannot locate {0} for scene {1}", new Object[] { materialKey, key });
materialList = null;
}
}
// == Run 2nd pass to load entities and other objects ==
// Added by larynx 25.06.2011
// Android needs the namespace aware flag set to true
// Kirill 30.06.2011
// Now, hack is applied for both desktop and android to avoid
// checking with JmeSystem.
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
XMLReader xr = factory.newSAXParser().getXMLReader();
xr.setContentHandler(this);
xr.setErrorHandler(this);
InputStreamReader r = null;
try {
r = new InputStreamReader(info.openStream());
xr.parse(new InputSource(r));
} finally {
if (r != null) {
r.close();
}
}
return root;
} catch (SAXException ex) {
IOException ioEx = new IOException("Error while parsing Ogre3D dotScene");
ioEx.initCause(ex);
throw ioEx;
} catch (ParserConfigurationException ex) {
IOException ioEx = new IOException("Error while parsing Ogre3D dotScene");
ioEx.initCause(ex);
throw ioEx;
}
}
use of com.jme3.asset.AssetNotFoundException 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