当前位置: 首页>>代码示例>>Java>>正文


Java BinaryExporter.getInstance方法代码示例

本文整理汇总了Java中com.jme3.export.binary.BinaryExporter.getInstance方法的典型用法代码示例。如果您正苦于以下问题:Java BinaryExporter.getInstance方法的具体用法?Java BinaryExporter.getInstance怎么用?Java BinaryExporter.getInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.jme3.export.binary.BinaryExporter的用法示例。


在下文中一共展示了BinaryExporter.getInstance方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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());
    }
}
 
开发者ID:huliqing,项目名称:LuoYing,代码行数:24,代码来源:ModelFileUtils.java

示例2: 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;
        }
    }
 
开发者ID:MultiverseKing,项目名称:HexGrid_JME,代码行数:34,代码来源:HexGridMapLoader.java

示例3: 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);
    }
 
开发者ID:chototsu,项目名称:MikuMikuStudio,代码行数:27,代码来源:SaveGame.java

示例4: 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);
    }
}
 
开发者ID:JavaSaBr,项目名称:jmonkeybuilder,代码行数:13,代码来源:EmptyModelCreator.java

示例5: 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);
    }
}
 
开发者ID:JavaSaBr,项目名称:jmonkeybuilder,代码行数:13,代码来源:EmptySceneCreator.java

示例6: 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);
    }
}
 
开发者ID:JavaSaBr,项目名称:jmonkeybuilder,代码行数:16,代码来源:AbstractSceneFileEditor.java

示例7: tempSave

import com.jme3.export.binary.BinaryExporter; //导入方法依赖的package包/类
/**
 * 临时保存文件
 * @param model
 * @param distFile 使用绝对路径,如:c:\temp\abc.j3o
 */
public static void tempSave(Spatial model, String distFile) {
    BinaryExporter exp = BinaryExporter.getInstance();
    File file = new File(distFile);
    try {
        exp.save(model, file);
    } catch (Exception ex) {
        Logger.getLogger(ModelFileUtils.class.getName()).log(Level.SEVERE, ex.getMessage());
    }
}
 
开发者ID:huliqing,项目名称:LuoYing,代码行数:15,代码来源:ModelFileUtils.java

示例8: encode

import com.jme3.export.binary.BinaryExporter; //导入方法依赖的package包/类
/**
 * 如果有需要,可以重写encode和decode方法来对保存数据进行加密解密编码.
 * @param data
 * @return 
 */
protected byte[] encode(Savable data) {
    ByteArrayOutputStream os = new ByteArrayOutputStream(10240);
    BinaryExporter exp = BinaryExporter.getInstance();
    try {
        exp.save(data, os);
        return os.toByteArray();
    } catch (IOException e) {
        LOG.log(Level.SEVERE, "Could not encode save data.", e);
    }
    return null;
}
 
开发者ID:huliqing,项目名称:LuoYing,代码行数:17,代码来源:SaveServiceImpl.java

示例9: saveChunk

import com.jme3.export.binary.BinaryExporter; //导入方法依赖的package包/类
/**
     * Save the selected chunk, two main use as :
     * - When saving the map
     * - When removing data from the memory.
     *
     * @param position the chunk to save.
     * @throws IOException
     * @todo
     */
    private boolean saveChunk(Vector2Int position) throws IOException {
        String userHome = System.getProperty("user.dir") + "/assets";

        BinaryExporter exporter = BinaryExporter.getInstance();
        ChunkDataLoader cdLoader = new ChunkDataLoader();

        if (position == null) {
//            for (Vector2Int pos : chunkPos) {
//                Path file = Paths.get(userHome + "/Data/MapData/" + mapName + "/" + pos.toString() + ".chk");
//                HexTile[][] tiles = getChunkTiles(pos);
//                if (tiles == null) {
//                    Path f = Paths.get(userHome + "/Data/MapData/Temp/" + pos.toString() + ".chk");
//                    if (f.toFile().exists() && !f.toFile().isDirectory()) {
//                        CopyOption[] options = new CopyOption[]{
//                            StandardCopyOption.REPLACE_EXISTING,
//                            StandardCopyOption.COPY_ATTRIBUTES
//                        };
//                        Files.copy(f, file, options);
//                    } else {
//                        Logger.getLogger(MapData.class.getName()).log(Level.WARNING,
//                                "userHome + \"/Data/MapData/\" + mapName + \"/\" + pos.toString() \n"
//                                + "                                + \".chk\" + \" can't be saved, data missing.\"");
//                        return false;
//                    }
//                } else {
//                    cdLoader.setChunk(tiles);
//                    exporter.save(cdLoader, file.toFile());
//                }
//            }
            return true;
        } else {
            File file = new File(userHome + "/Data/MapData/Temp/" + position.toString() + ".chk");
//            cdLoader.setChunk(getChunkTiles(position));
            exporter.save(cdLoader, file);
            return true;
        }
    }
 
开发者ID:MultiverseKing,项目名称:HexGrid_JME,代码行数:47,代码来源:HexGridMapLoader.java

示例10: toBytes

import com.jme3.export.binary.BinaryExporter; //导入方法依赖的package包/类
/**
 * Serializes a savable object to a byte array.
 * @param object The object to serialize.
 * @return The byte array.
 * @throws RuntimeException if anything goes wrong - no proper error handling (TODO)
 */
public static byte[] toBytes(Savable object) {
	try {
		BinaryExporter ex = BinaryExporter.getInstance();
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		ex.save(object, baos);
		return baos.toByteArray();
	} catch(IOException e) {
		throw new RuntimeException(e);
	}
}
 
开发者ID:GSam,项目名称:Game-Project,代码行数:17,代码来源:SaveUtils.java

示例11: importModel

import com.jme3.export.binary.BinaryExporter; //导入方法依赖的package包/类
/**
 * Import the external model in a background thread.
 */
@BackgroundThread
private void importModel() {

    final Path modelFile = notNull(getFileToCreate());

    final Path parent = modelFile.getParent();
    final VarTable vars = getVars();

    final Path importedFile = vars.get(PROP_FILE);

    final AssetManager assetManager = EDITOR.getAssetManager();
    final Spatial model;

    FolderAssetLocator.setIgnore(true);
    try {
        model = assetManager.loadModel(importedFile.toString());
    } finally {
        FolderAssetLocator.setIgnore(false);
    }

    if (EDITOR_CONFIG.isAutoTangentGenerating()) {
        TangentGenerator.useMikktspaceGenerator(model);
    }

    final Path texturesFolder = vars.get(PROP_TEXTURES_FOLDER, parent);
    final boolean overwriteTextures = vars.getBoolean(PROP_OVERWRITE_TEXTURES);

    final boolean needExportMaterials = vars.getBoolean(PROP_NEED_MATERIALS_EXPORT);
    final Path materialsFolder = vars.get(PROP_MATERIALS_FOLDER, parent);
    final boolean overwriteMaterials = vars.getBoolean(PROP_OVERWRITE_MATERIALS, false);

    final Array<Texture> textures = ArrayFactory.newArray(Texture.class);
    final Array<Geometry> geometries = ArrayFactory.newArray(Geometry.class);

    NodeUtils.visitGeometry(model, geometry -> {

        final Material material = geometry.getMaterial();
        if (needExportMaterials) geometries.add(geometry);

        material.getParams().stream()
                .filter(MatParamTexture.class::isInstance)
                .map(MatParam::getValue)
                .filter(Texture.class::isInstance)
                .map(Texture.class::cast)
                .filter(texture -> texture.getKey() != null)
                .forEach(textures::add);
    });

    copyTextures(texturesFolder, overwriteTextures, textures);

    if (needExportMaterials) {
        exportMaterials(materialsFolder, overwriteMaterials, geometries);
    }

    final Path assetFile = notNull(getAssetFile(modelFile));
    final String assetPath = toAssetPath(assetFile);

    model.setName(assetPath);

    final BinaryExporter exporter = BinaryExporter.getInstance();

    try (final OutputStream out = Files.newOutputStream(modelFile, WRITE, TRUNCATE_EXISTING, CREATE)) {
        exporter.save(model, out);
    } catch (final IOException e) {
        throw new RuntimeException(e);
    }

    notifyFileCreated(modelFile, true);
}
 
开发者ID:JavaSaBr,项目名称:jmonkeybuilder,代码行数:73,代码来源:ModelImportDialog.java

示例12: convertImpl

import com.jme3.export.binary.BinaryExporter; //导入方法依赖的package包/类
/**
 * Convert a file using settings from the dialog.
 */
@BackgroundThread
private void convertImpl(@NotNull final Path source, @NotNull final VarTable vars) throws IOException {

    final String filename = vars.getString(PROP_RESULT_NAME);
    final Path destinationFolder = notNull(getRealFile(vars.get(PROP_DESTINATION, Path.class)));
    final Path destination = destinationFolder.resolve(filename + "." + FileExtensions.JME_OBJECT);
    final boolean isOverwrite = Files.exists(destination);

    final Path assetFile = notNull(getAssetFile(source), "Not found asset file for " + source);
    final ModelKey modelKey = new ModelKey(toAssetPath(assetFile));

    final AssetManager assetManager = EDITOR.getAssetManager();
    final Spatial model = assetManager.loadAsset(modelKey);

    if (EDITOR_CONFIG.isAutoTangentGenerating()) {
        TangentGenerator.useMikktspaceGenerator(model);
    }

    if (vars.getBoolean(PROP_EXPORT_MATERIALS)) {

        final Array<Geometry> geometries = ArrayFactory.newArray(Geometry.class);
        final ObjectDictionary<String, Geometry> mapping = DictionaryFactory.newObjectDictionary();

        final Path materialsFolder = vars.get(PROP_MATERIALS_FOLDER);
        final boolean canOverwrite = vars.getBoolean(PROP_OVERWRITE_MATERIALS);

        NodeUtils.visitGeometry(model, geometry -> checkAndAdd(geometries, geometry));
        geometries.forEach(geometry -> generateNames(mapping, geometry));
        mapping.forEach((materialName, geometry) -> storeMaterials(materialsFolder, canOverwrite, materialName, geometry));
    }

    final BinaryExporter exporter = BinaryExporter.getInstance();

    try (final OutputStream out = Files.newOutputStream(destination, WRITE, TRUNCATE_EXISTING, CREATE)) {
        exporter.save(model, out);
    }

    if (isOverwrite) {
        notifyFileChanged(destination);
    } else {
        notifyFileCreated(destination);
    }
}
 
开发者ID:JavaSaBr,项目名称:jmonkeybuilder,代码行数:47,代码来源:AbstractModelFileConverter.java

示例13: saveAsset

import com.jme3.export.binary.BinaryExporter; //导入方法依赖的package包/类
public void saveAsset() throws IOException {
    ProjectAssetManager mgr = getLookup().lookup(ProjectAssetManager.class);
    if (mgr == null) {
        return;
    }
    String name = getPrimaryFile().getName();
    int idx = name.toLowerCase().indexOf(".mesh");
    if(idx!=-1){
        name = name.substring(0, idx);
    }
    
    ProgressHandle progressHandle = ProgressHandleFactory.createHandle("Saving File..");
    progressHandle.start();
    BinaryExporter exp = BinaryExporter.getInstance();
    FileLock lock = null;
    OutputStream out = null;
    try {
        if (saveExtension == null) {
            out = getPrimaryFile().getOutputStream();
        } else {
            FileObject outFileObject = getPrimaryFile().getParent().getFileObject(name, saveExtension);
            if (outFileObject == null) {
                outFileObject = getPrimaryFile().getParent().createData(name, saveExtension);
            }
            out = outFileObject.getOutputStream();
            outFileObject.getParent().refresh();
        }
        exp.save(savable, out);
    } finally {
        if (lock != null) {
            lock.releaseLock();
        }
        if (out != null) {
            out.close();
        }
    }
    progressHandle.finish();
    StatusDisplayer.getDefault().setStatusText(getPrimaryFile().getNameExt() + " saved.");
    setModified(false);
    
    FileObject outFile = null;
    if (saveExtension == null) {
        outFile = getPrimaryFile();
    } else {
        outFile = getPrimaryFile().getParent().getFileObject(name, saveExtension);
        if (outFile == null) {
            Logger.getLogger(SpatialAssetDataObject.class.getName()).log(Level.SEVERE, "Could not locate saved file.");
            return;
        }
    }
    try {
        DataObject targetModel = DataObject.find(outFile);
        AssetData properties = targetModel.getLookup().lookup(AssetData.class);
        if (properties != null) {
            properties.loadProperties();
            properties.setProperty("ORIGINAL_PATH", mgr.getRelativeAssetPath(outFile.getPath()));
            properties.saveProperties();
        }
    } catch (Exception ex) {
        Exceptions.printStackTrace(ex);
    }
}
 
开发者ID:chototsu,项目名称:MikuMikuStudio,代码行数:63,代码来源:OgreXMLDataObject.java


注:本文中的com.jme3.export.binary.BinaryExporter.getInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。