Search in sources :

Example 1 with SceneParser

use of org.sunflow.core.SceneParser in project joons-renderer by joonhyublee.

the class SunflowAPI method translate.

/**
 * Translate specfied file into the native sunflow scene file format.
 *
 * @param filename input filename
 * @param outputFilename output filename
 * @return <code>true</code> upon success, <code>false</code> otherwise
 */
public static boolean translate(String filename, String outputFilename) {
    FileSunflowAPI api = null;
    try {
        if (outputFilename.endsWith(".sca")) {
            api = new AsciiFileSunflowAPI(outputFilename);
        } else if (outputFilename.endsWith(".scb")) {
            api = new BinaryFileSunflowAPI(outputFilename);
        } else {
            UI.printError(Module.API, "Unable to determine output filetype: \"%s\"", outputFilename);
            return false;
        }
    } catch (IOException e) {
        UI.printError(Module.API, "Unable to create output file - %s", e.getMessage());
        return false;
    }
    String extension = filename.substring(filename.lastIndexOf('.') + 1);
    SceneParser parser = PluginRegistry.parserPlugins.createObject(extension);
    if (parser == null) {
        UI.printError(Module.API, "Unable to find a suitable parser for: \"%s\"", filename);
        return false;
    }
    try {
        return parser.parse(filename, api);
    } catch (RuntimeException e) {
        Logger.getLogger(SunflowAPI.class.getName()).log(Level.SEVERE, null, e);
        UI.printError(Module.API, "Error occured during translation: %s", e.getMessage());
        return false;
    } finally {
        api.close();
    }
}
Also used : SceneParser(org.sunflow.core.SceneParser) IOException(java.io.IOException)

Example 2 with SceneParser

use of org.sunflow.core.SceneParser in project joons-renderer by joonhyublee.

the class SunflowAPI method include.

@Override
public final boolean include(String filename) {
    if (filename == null) {
        return false;
    }
    filename = includeSearchPath.resolvePath(filename);
    String extension = FileUtils.getExtension(filename);
    SceneParser parser = PluginRegistry.parserPlugins.createObject(extension);
    if (parser == null) {
        UI.printError(Module.API, "Unable to find a suitable parser for: \"%s\" (extension: %s)", filename, extension);
        return false;
    }
    String currentFolder = new File(filename).getAbsoluteFile().getParentFile().getAbsolutePath();
    includeSearchPath.addSearchPath(currentFolder);
    textureSearchPath.addSearchPath(currentFolder);
    return parser.parse(filename, this);
}
Also used : SceneParser(org.sunflow.core.SceneParser) File(java.io.File)

Aggregations

SceneParser (org.sunflow.core.SceneParser)2 File (java.io.File)1 IOException (java.io.IOException)1