Recently I've been looking at Povray, pyprocessing, and cfdg (version 3.0) as tools for creating digital images. I have branched two separate blogs where I mainly explore jruby + processing and processing.py

Friday, 1 April 2011

Developing and Using My Povwriter Library from NetBeans IDE

Here is my TestPov class that I've started to use to continue the development of my library that exports pov files, from a processing sketch, it is so easy to run directly from NetBeans. To speed the evaluation of the output pov file (a lot), the program automatically opens the file within jEdit. This allows me to edit the pov file as necessary with jEdit (which has syntax highlighting for PovRAY built in) and to launch PovRAY using my jEdit commando file (available as community download from jEdit). There are several quality options available when running povray choose medium for quick evaluation. To get radiosity to work select High or Highest Quality.


/**
 * This class is only for testing purposes, however it also demonstrates
 * running a PApplet directly from NetBeans
 * Author Martin Prout
 *
 */
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import processing.core.PApplet;

public class PovTest extends PApplet {

    boolean record = false;

    @Override
    public void setup() {
        size(400, 400, "processing.core.PGraphics3D");
        camera(200.0f, 200.0f, 600.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
    }

    @Override
    public void draw() {
        if (this.record) {            
            noLoop();
            beginRaw("povexport.RawPovray", "FTest.pov");
        }
        render();
        if (this.record) {
            endRaw();
            this.record = false;
            loop();
        }
    }

    public void render() {        
        fill(255.0f, 0.0f, 0.0f);
        box(50.0f);
        translate(0.0f, -50.0f, 0.0f);
        box(50.0f);
        translate(50.0f, 0.0f, 0.0f);
        box(50.0f);
        translate(-50.0f, -50.0f, 0.0f);
        box(50.0f);
        translate(0.0f, -50.0f, 0.0f);
        box(50.0f);
        translate(50.0f, 0.0f, 0.0f);
        box(50.0f);
    }

    @Override
    public void keyPressed() {
        switch (key) {
            case 'r':
                this.record = true;
            case 'e':
                String[] jargs = {"/home/tux/bin/jedit", "FTest.pov"};
                Runtime runtime = Runtime.getRuntime();
                try {
                    if (this.record == false) {
                        runtime.exec(jargs); // open jedit with FTest.pov file
                    }
                } catch (IOException ex) {
                    Logger.getLogger(PovTest.class.getName()).log(Level.SEVERE, null, ex);
                }
        }
    }

    public static void main(String[] strings) {
        PApplet.main(new String[]{"--bgcolor=#DFDFDF", "PovTest"});
    }
}

Processing Sketch run from NetBeans

Medium Quality PovRAY rendering




It is of course quite possible to run jEdit directly from the processing ide using the 'open' function in place of the runtime.exec() (which is how open gets implemented), which is handy if you want to stick with the terse processing syntax...
If you are on Windows you probably can run the Povray-GUI directly? However as you currently need to edit the file (move colour declarations), you might as well use jEdit, and ignore the GUI for now......

NB: 'r' is record, 'e' is for launch editor....

No comments:

Post a Comment

Followers

Blog Archive

About Me

My photo
Pembrokeshire, United Kingdom
I have developed JRubyArt and propane new versions of ruby-processing for JRuby-9.1.5.0 and processing-3.2.2