Created
June 6, 2014 05:59
-
-
Save monkstone/099ea042c1a7ae58ff72 to your computer and use it in GitHub Desktop.
Some snippets from my povriter code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* beginRaw and endRaw should wrap what you want to ray-trace | |
*/ | |
public void endRaw() { | |
if (this.getState(State.RECORDING)) { | |
parent.endRaw(); | |
this.setState(State.RECORDED); | |
out.println(String.format(INFO_FORMAT, State.RECORDED)); | |
} | |
if ((this.getState(State.RECORDED)) && (povray == null)) { | |
povray = this.rayTrace(); | |
if (povray != null) { | |
out.println(String.format(INFO_FORMAT, State.TRACING)); | |
this.setState(State.TRACING); | |
} | |
} | |
try { | |
if ((this.getState(State.TRACING)) && povray.waitFor() == 0) { | |
this.setState(State.TRACED); // set State as TRACED when povray has finished | |
out.println(String.format(INFO_FORMAT, State.TRACED)); | |
} | |
} catch (InterruptedException ex) { | |
Logger.getLogger(PovExporter.class.getName()).log(Level.SEVERE, null, ex); | |
} // following matches previous pushMatrix() needed to place button | |
parent.popMatrix(); | |
} | |
public Process rayTrace() { | |
if (iniFile != null) { | |
try { | |
String[] args = new String[]{povrayPath, iniFile}; | |
povray = new ProcessBuilder(args).start(); | |
redirect(povray.getErrorStream()); | |
} catch (IOException ex) { | |
Logger.getLogger(PovExporter.class.getName()).log(Level.SEVERE, null, ex); | |
} | |
} | |
return povray; | |
} | |
private static void redirect(InputStream in) throws IOException { | |
int c; | |
while ((c = in.read()) != -1) { | |
out.write((char) c); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment