本文整理汇总了Java中com.jme3.export.binary.BinaryExporter类的典型用法代码示例。如果您正苦于以下问题:Java BinaryExporter类的具体用法?Java BinaryExporter怎么用?Java BinaryExporter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BinaryExporter类属于com.jme3.export.binary包,在下文中一共展示了BinaryExporter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: saveTo
import com.jme3.export.binary.BinaryExporter; //导入依赖的package包/类
/**
* 保存模型文件到目标位置。
* @param model
* @param distFile 完整目标文件路径,如:Models/env/example.j3o
*/
public static void saveTo(Spatial model, String distFile) {
// 备份文件
try {
backup(distFile);
} catch (Exception e) {
Logger.getLogger(ModelFileUtils.class.getName()).log(Level.WARNING, "Could not backup file:{0}", distFile);
}
// 保存文件
BinaryExporter exp = BinaryExporter.getInstance();
URL url = Thread.currentThread().getContextClassLoader().getResource(distFile);
File file = new File(url.getPath());
try {
exp.save(model, file);
} catch (IOException ex) {
Logger.getLogger(ModelFileUtils.class.getName()).log(Level.SEVERE, ex.getMessage());
}
}
示例2: doSaveEdit
import com.jme3.export.binary.BinaryExporter; //导入依赖的package包/类
@Override
protected void doSaveEdit() {
if (savePath == null) {
throw new NullPointerException("Need to set savePath before save edit!");
}
try {
// 先保存一些特殊的”保存行为“, 这些保存操作需要在地形保存之前优先进行保存操作.
// 如地形在修改后的特殊的保存行为
if (!saveActions.isEmpty()) {
for (SaveAction sa : saveActions) {
sa.doSave(editor);
}
}
// 场景保存
scene.updateDatas();
BinaryExporter.getInstance().save(scene.getData(), new File(savePath));
} catch (Exception ex) {
LOG.log(Level.SEVERE, null, ex);
}
}
示例3: doCreateScene
import com.jme3.export.binary.BinaryExporter; //导入依赖的package包/类
public void doCreateScene() {
SceneData sceneData = Loader.loadData(IdConstants.SYS_SCENE);
TreeItem<File> item = fileTree.getSelectionModel().getSelectedItem();
if (item == null || item.getValue() == null)
return;
File dir = item.getValue();
if (!dir.exists() || dir.isFile())
return;
Jfx.runOnJme(() -> {
try {
File saveFile = makeSaveFile(dir, "scene", ".lyo", 0);
BinaryExporter.getInstance().save(sceneData, saveFile);
Jfx.runOnJfx(() -> {
fileTree.refreshItem(item);
fileTree.refresh();
});
} catch (IOException ex) {
Logger.getLogger(CreateSceneMenuItem.class.getName()).log(Level.SEVERE, null, ex);
}
});
}
示例4: createTerrain
import com.jme3.export.binary.BinaryExporter; //导入依赖的package包/类
private void createTerrain(ComponentDefine cd, JfxSceneEdit jfxEdit, Application application
, String terrainName, int totalSize, int patchSize, int alphaTextureSize, String assetFolder, float[] heightMap) {
try {
// 创建地形
Terrain terrain = TerrainUtils.doCreateTerrain(application, assetFolder
, alphaTextureDir, terrainName, totalSize, patchSize, alphaTextureSize, heightMap, TERRAIN_DIRT);
Spatial terrainSpatial = (Spatial) terrain;
// 保存地形文件
String terrainFullName = modelDir.substring(1) + "/" + terrainName + ".j3o";
File terrainFile = new File(assetFolder, terrainFullName);
BinaryExporter.getInstance().save(terrainSpatial, terrainFile);
UncacheAssetEventListener.getInstance().addUncache(terrainFullName);
// 添加到3D场景编辑
EntityData ed = Loader.loadData(cd.getId());
ed.setAttribute("file", terrainFullName); // 去掉"/"
Jfx.runOnJfx(() -> {
jfxEdit.addEntityUseUndoRedo(ed);
});
} catch (IOException ex) {
Logger.getLogger(TerrainEntityComponentConverter.class.getName()).log(Level.SEVERE, null, ex);
}
}
示例5: saveMoleculej3o
import com.jme3.export.binary.BinaryExporter; //导入依赖的package包/类
/**
* save molecule as j3o file
*/
public void saveMoleculej3o() {
final Spatial mol = app.getMoleculeModel();
// open input dialog
TextinputDialog dialog = new TextinputDialog();
dialog.setOnClose(new InputRunnable() {
@Override
public void run(String input) {
try {
String ext = input.endsWith(".j3o") ? "" : ".j3o";
File f = new File(Constants.getMoleculeLocation() + File.separator + input + ext);
BinaryExporter exporter = BinaryExporter.getInstance();
exporter.save(mol, f);
} catch (Exception ex) {
logger.log(Level.SEVERE, null, ex);
}
exitMenu();
}
});
dialog.show(nifty, "Enter name of file:");
}
示例6: registerAction_SaveAsJ3O
import com.jme3.export.binary.BinaryExporter; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static void registerAction_SaveAsJ3O(SpatialExplorer se, SimpleApplication app) {
FileChooser fileChooser = new FileChooser();
fileChooser.getExtensionFilters().addAll(
new FileChooser.ExtensionFilter("jMonkeyEngine Object (*.j3o)", "*.j3o")
);
se.treeItemActions.add(new Action("Save as .j3o", (evt) -> {
System.out.println("target : " + evt.getTarget());
File f0 = fileChooser.showSaveDialog(
null
// ((MenuItem)evt.getTarget()).getGraphic().getScene().getWindow()
// ((MenuItem)evt.getTarget()).getParentPopup()
);
if (f0 != null) {
File f = (f0.getName().endsWith(".j3o"))? f0 : new File(f0.getParentFile(), f0.getName() + ".j3o");
app.enqueue(()->{
Spatial target = ((TreeItem<Spatial>)evt.getSource()).getValue();
new BinaryExporter().save(target, f);
return null;
});
}
}));
}
示例7: saveArea
import com.jme3.export.binary.BinaryExporter; //导入依赖的package包/类
/**
* Save the current map in a folder of the same name of the map.
*
*
* @param mapName "RESET" && "TEMP" cannot be used for a map name since they
* are already be used internaly.
* @todo
*/
public boolean saveArea(String mapName) {
if (mapName == null || mapName.toUpperCase(Locale.ENGLISH).equalsIgnoreCase("TEMP")) {
Logger.getLogger(MapData.class.getName()).log(Level.WARNING, "Invalid Path name");
return false;
}
// this.mapName = mapName;
try {
if (saveChunk(null)) {
String userHome = System.getProperty("user.dir") + "/assets";
BinaryExporter exporter = BinaryExporter.getInstance();
org.hexgridapi.loader.MapDataLoader mdLoader = new org.hexgridapi.loader.MapDataLoader();
// mdLoader.setChunkPos(chunkPos);
File file = new File(userHome + "/Data/MapData/" + mapName + "/" + mapName + ".map");
exporter.save(mdLoader, file);
return true;
} else {
return false;
}
} catch (IOException ex) {
Logger.getLogger(MapData.class.getName()).log(Level.SEVERE, null, ex);
return false;
}
}
示例8: saveGame
import com.jme3.export.binary.BinaryExporter; //导入依赖的package包/类
/**
* Saves a savable in a system-dependent way. Note that only small amounts of data can be saved.
* @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
*/
public static void saveGame(String gamePath, String dataName, Savable data) {
Preferences prefs = Preferences.userRoot().node(gamePath);
BinaryExporter ex = BinaryExporter.getInstance();
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
GZIPOutputStream zos = new GZIPOutputStream(out);
ex.save(data, zos);
zos.close();
} catch (IOException ex1) {
Logger.getLogger(SaveGame.class.getName()).log(Level.SEVERE, "Error saving data: {0}", ex1);
ex1.printStackTrace();
}
UUEncoder enc = new UUEncoder();
String dataString = enc.encodeBuffer(out.toByteArray());
// System.out.println(dataString);
if (dataString.length() > Preferences.MAX_VALUE_LENGTH) {
throw new IllegalStateException("SaveGame dataset too large");
}
prefs.put(dataName, dataString);
}
示例9: writeData
import com.jme3.export.binary.BinaryExporter; //导入依赖的package包/类
@Override
@BackgroundThread
protected void writeData(@NotNull final Path resultFile) throws IOException {
super.writeData(resultFile);
final BinaryExporter exporter = BinaryExporter.getInstance();
final Node newNode = new Node("Model root");
try (final OutputStream out = Files.newOutputStream(resultFile, WRITE, TRUNCATE_EXISTING, CREATE)) {
exporter.save(newNode, out);
}
}
示例10: writeData
import com.jme3.export.binary.BinaryExporter; //导入依赖的package包/类
@Override
@BackgroundThread
protected void writeData(@NotNull final Path resultFile) throws IOException {
super.writeData(resultFile);
final BinaryExporter exporter = BinaryExporter.getInstance();
final SceneNode newNode = createScene();
try (final OutputStream out = Files.newOutputStream(resultFile, WRITE, TRUNCATE_EXISTING, CREATE)) {
exporter.save(newNode, out);
}
}
示例11: doSave
import com.jme3.export.binary.BinaryExporter; //导入依赖的package包/类
@Override
@BackgroundThread
public void doSave(@NotNull final Path toStore) throws IOException {
super.doSave(toStore);
final M currentModel = getCurrentModel();
NodeUtils.visitGeometry(currentModel, geometry -> saveIfNeedTextures(geometry.getMaterial()));
final BinaryExporter exporter = BinaryExporter.getInstance();
try (final OutputStream out = Files.newOutputStream(toStore)) {
exporter.save(currentModel, out);
}
}
示例12: onAction
import com.jme3.export.binary.BinaryExporter; //导入依赖的package包/类
public void onAction(String name, boolean pressed, float tpf) {
if (name.equals("save") && !pressed) {
FileOutputStream fos = null;
try {
long start = System.currentTimeMillis();
fos = new FileOutputStream(new File("terrainsave.jme"));
// we just use the exporter and pass in the terrain
BinaryExporter.getInstance().save((Savable)terrain, new BufferedOutputStream(fos));
fos.flush();
float duration = (System.currentTimeMillis() - start) / 1000.0f;
System.out.println("Save took " + duration + " seconds");
} catch (IOException ex) {
Logger.getLogger(TerrainTestReadWrite.class.getName()).log(Level.SEVERE, null, ex);
} finally {
try {
if (fos != null) {
fos.close();
}
} catch (IOException e) {
Logger.getLogger(TerrainTestReadWrite.class.getName()).log(Level.SEVERE, null, e);
}
}
}
}
示例13: storeConfig
import com.jme3.export.binary.BinaryExporter; //导入依赖的package包/类
/**
* This method stores the current blender config.
* @param configuration the blender config to store
*/
private void storeConfig(BlenderKeyConfiguration configuration) {
if (configuration.lastUsedKey != null) {//reading animations
DefaultTableModel animationsTableModel = (DefaultTableModel) jTableAnimations.getModel();
if (configuration.lastUsedKey.getAnimations() != null) {
configuration.lastUsedKey.getAnimations().clear();
}
int animCounter = 0;
for (int i = 0; i < animationsTableModel.getRowCount(); ++i) {
String objectName = (String) animationsTableModel.getValueAt(i, 0);
String animName = (String) animationsTableModel.getValueAt(i, 1);
Number startFrame = (Number) animationsTableModel.getValueAt(i, 2);
Number stopFrame = (Number) animationsTableModel.getValueAt(i, 3);
if (objectName != null && animName != null && startFrame.intValue() <= stopFrame.intValue()) {
configuration.lastUsedKey.addAnimation(objectName, animName, startFrame.intValue(), stopFrame.intValue());
++animCounter;
}
}
if (animCounter < animationsTableModel.getRowCount()) {
JOptionPane.showMessageDialog(ConfigDialog.this, "Some animations had errors!\nThey had not been added!",
"Invalid animations definitions", JOptionPane.WARNING_MESSAGE);
}
}
//getting the key type
configuration.useModelKey = jCheckBoxUseModelKey.isSelected();
configuration.logLevel = JRadioButtonLevel.getSelectedLevel();
//storing the config
JmeExporter jmeExporter = new BinaryExporter();
try {
if (!jmeExporter.save(configuration, configFile)) {
JOptionPane.showMessageDialog(ConfigDialog.this, "Unable to save the config data!", "Config save problem", JOptionPane.ERROR_MESSAGE);
}
} catch (IOException e) {
JOptionPane.showMessageDialog(ConfigDialog.this, "Error occured during config saving!\nReason: " + e.getLocalizedMessage(),
"Config save problem", JOptionPane.ERROR_MESSAGE);
}
}
示例14: simpleInitApp
import com.jme3.export.binary.BinaryExporter; //导入依赖的package包/类
@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();
}
}
示例15: ClipboardSpatial
import com.jme3.export.binary.BinaryExporter; //导入依赖的package包/类
public ClipboardSpatial(Spatial spat){
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
BinaryExporter.getInstance().save(spat, out);
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
data= out.toByteArray();
}