use of com.jme3.asset.AssetInfo in project jmonkeyengine by jMonkeyEngine.
the class TestMusicPlayer method btnOpenActionPerformed.
// </editor-fold>//GEN-END:initComponents
private void btnOpenActionPerformed(java.awt.event.ActionEvent evt) {
//GEN-FIRST:event_btnOpenActionPerformed
JFileChooser chooser = new JFileChooser();
chooser.setAcceptAllFileFilterUsed(true);
chooser.setDialogTitle("Select OGG file");
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
chooser.setMultiSelectionEnabled(false);
if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
btnStopActionPerformed(null);
final File selected = chooser.getSelectedFile();
AssetLoader loader = null;
if (selected.getName().endsWith(".wav")) {
loader = new WAVLoader();
} else {
loader = new OGGLoader();
}
AudioKey key = new AudioKey(selected.getName(), true, true);
try {
musicData = (AudioData) loader.load(new AssetInfo(null, key) {
@Override
public InputStream openStream() {
try {
return new FileInputStream(selected);
} catch (FileNotFoundException ex) {
ex.printStackTrace();
}
return null;
}
});
} catch (IOException ex) {
ex.printStackTrace();
}
musicSource = new AudioNode(musicData, key);
musicLength = musicData.getDuration();
updateTime();
}
}
use of com.jme3.asset.AssetInfo in project jmonkeyengine by jMonkeyEngine.
the class FbxLoader method load.
@Override
public Object load(AssetInfo assetInfo) throws IOException {
this.assetManager = assetInfo.getManager();
AssetKey<?> assetKey = assetInfo.getKey();
if (!(assetKey instanceof ModelKey)) {
throw new AssetLoadException("Invalid asset key");
}
InputStream stream = assetInfo.openStream();
try {
sceneFilename = assetKey.getName();
sceneFolderName = assetKey.getFolder();
String ext = assetKey.getExtension();
sceneName = sceneFilename.substring(0, sceneFilename.length() - ext.length() - 1);
if (sceneFolderName != null && sceneFolderName.length() > 0) {
sceneName = sceneName.substring(sceneFolderName.length());
}
reset();
// Load the data from the stream.
loadData(stream);
// Bind poses are needed to compute world transforms.
applyBindPoses();
// Need world transforms for skeleton creation.
updateWorldTransforms();
// Need skeletons for meshs to be created in scene graph construction.
// Mesh bone indices require skeletons to determine bone index.
constructSkeletons();
// Create the jME3 scene graph from the FBX scene graph.
// Also creates SkeletonControls based on the constructed skeletons.
Spatial scene = constructSceneGraph();
// Load animations into AnimControls
constructAnimations();
return scene;
} finally {
releaseObjects();
if (stream != null) {
stream.close();
}
}
}
use of com.jme3.asset.AssetInfo in project jmonkeyengine by jMonkeyEngine.
the class SceneLoader method load.
@Override
public Object load(AssetInfo assetInfo) throws IOException {
this.currentAssetInfo = assetInfo;
this.assetManager = assetInfo.getManager();
AssetKey<?> assetKey = assetInfo.getKey();
if (assetKey instanceof SceneKey)
animList = ((SceneKey) assetKey).getAnimations();
InputStream stream = assetInfo.openStream();
final Node sceneNode = this.sceneNode = new Node(sceneName + "-scene");
try {
sceneFilename = assetKey.getName();
sceneFolderName = assetKey.getFolder();
String ext = assetKey.getExtension();
sceneName = sceneFilename.substring(0, sceneFilename.length() - ext.length() - 1);
if (sceneFolderName != null && sceneFolderName.length() > 0)
sceneName = sceneName.substring(sceneFolderName.length());
loadScene(stream);
linkScene();
if (warnings.size() > 0)
logger.log(Level.WARNING, "Model load finished with warnings:\n" + join(warnings, "\n"));
} finally {
releaseObjects();
if (stream != null)
stream.close();
}
return sceneNode;
}
use of com.jme3.asset.AssetInfo 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.AssetInfo 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;
}
}
Aggregations