Hi,
I'm at the point of finishing a library that imports vector images and holds them in Processing objects.
It's a bit like yours but for 2D stuff.
I ran in to the same problem as you, and I chosed the following solution.
When we want to draw a model (or in my case a 2D vector image) what we really need to specify is what PGraphics object to draw it to.
So instead of your code I used:
Code:
Ex3D modelo = new Ex3D(filename);
modelo.draw(g);
this would be the case we want to draw our model in the applet's default graphics object or canvas. But it would also allow us to draw our image in any graphics object we want, which I think gives us is more flexibility. And I don't think this really is an overhead to newbies, since in any of the ways they must remember something (in your case to pass "this" as parameter and in my case to pass "g" as parameter).
This means when creating your library class you'll need to have a function that looks like the following:
Code:
import processing.core*;
public class Ex3D{
public void draw(PGraphics gfx){
// change colors, call smooth, draw tristrips or whatever, maybe something like this...
gfx.beginShape(TRI_STRIP);
// gfx.vertex() the points of your model ...
gfx.endShape();
// change back the colors to normal...
}
I wouldn't call any specific methods of OPENGL as a requirement. I would rather add those inside a "try catch statement" or by seeing if the gfx object passed as argument is of type PGraphicsGL. And would try to keep the option of loading and drawing 3D models with the other 3D renderers. Because maybe someday someone writes a 3D recorder and this would still be compatible with the Processing API. In my opinion this would give longer life and wider use to your library.
But of course these are just suggestions and any library you make is more than welcome!!!
thanks
ricard