use of com.jme3.export.binary.BinaryExporter in project jmonkeyengine by jMonkeyEngine.
the class TestOgreConvert method simpleInitApp.
@Override
public void simpleInitApp() {
Spatial ogreModel = assetManager.loadModel("Models/Oto/Oto.mesh.xml");
DirectionalLight dl = new DirectionalLight();
dl.setColor(ColorRGBA.White);
dl.setDirection(new Vector3f(0, -1, -1).normalizeLocal());
rootNode.addLight(dl);
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
BinaryExporter exp = new BinaryExporter();
exp.save(ogreModel, baos);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
BinaryImporter imp = new BinaryImporter();
imp.setAssetManager(assetManager);
Node ogreModelReloaded = (Node) imp.load(bais, null, null);
AnimControl control = ogreModelReloaded.getControl(AnimControl.class);
AnimChannel chan = control.createChannel();
chan.setAnim("Walk");
rootNode.attachChild(ogreModelReloaded);
} catch (IOException ex) {
ex.printStackTrace();
}
}
use of com.jme3.export.binary.BinaryExporter in project jmonkeyengine by jMonkeyEngine.
the class SaveGame method saveGame.
/**
* Saves a savable in a system-dependent way.
* @param gamePath A unique path for this game, e.g. com/mycompany/mygame
* @param dataName A unique name for this savegame, e.g. "save_001"
* @param data The Savable to save
* @param storageType The specific type of folder to use to save the data
*/
public static void saveGame(String gamePath, String dataName, Savable data, JmeSystem.StorageFolderType storageType) {
if (storageType == null) {
Logger.getLogger(SaveGame.class.getName()).log(Level.SEVERE, "Base Storage Folder Type is null, using External!");
storageType = JmeSystem.StorageFolderType.External;
}
BinaryExporter ex = BinaryExporter.getInstance();
OutputStream os = null;
try {
File baseFolder = JmeSystem.getStorageFolder(storageType);
if (baseFolder == null) {
Logger.getLogger(SaveGame.class.getName()).log(Level.SEVERE, "Error creating save file!");
throw new IllegalStateException("SaveGame dataset cannot be created");
}
File daveFolder = new File(baseFolder.getAbsolutePath() + File.separator + gamePath.replace('/', File.separatorChar));
if (!daveFolder.exists() && !daveFolder.mkdirs()) {
Logger.getLogger(SaveGame.class.getName()).log(Level.SEVERE, "Error creating save file!");
throw new IllegalStateException("SaveGame dataset cannot be created");
}
File saveFile = new File(daveFolder.getAbsolutePath() + File.separator + dataName);
if (!saveFile.exists()) {
if (!saveFile.createNewFile()) {
Logger.getLogger(SaveGame.class.getName()).log(Level.SEVERE, "Error creating save file!");
throw new IllegalStateException("SaveGame dataset cannot be created");
}
}
os = new GZIPOutputStream(new BufferedOutputStream(new FileOutputStream(saveFile)));
ex.save(data, os);
Logger.getLogger(SaveGame.class.getName()).log(Level.FINE, "Saving data to: {0}", saveFile.getAbsolutePath());
} catch (IOException ex1) {
Logger.getLogger(SaveGame.class.getName()).log(Level.SEVERE, "Error saving data: {0}", ex1);
ex1.printStackTrace();
throw new IllegalStateException("SaveGame dataset cannot be saved");
} finally {
try {
if (os != null) {
os.close();
}
} catch (IOException ex1) {
Logger.getLogger(SaveGame.class.getName()).log(Level.SEVERE, "Error saving data: {0}", ex1);
ex1.printStackTrace();
throw new IllegalStateException("SaveGame dataset cannot be saved");
}
}
}
Aggregations