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

Wednesday, 18 January 2012

Exporting toxi TriangleMesh to PovRAY Mesh2 as an inc file

This is a completly different approach to my previous exporting PovRAY from processing (but is very similar to the toxiclibs STL/OBJ export). The beauty of this approach it is not reliant on the processing renderer (my povwriter library relies on PGraphics3D, which seems to have gone away in processing-2.0). Further the generated mesh2 should be handled more efficiently by PovRAY than a union of triangles.
Here is a brief outline of the story so far:-

1. I did a "hg clone"
2. Set up a NetBeans Project with the source (including processing-1.5.1 core.jar as a library)
3. I copied OBJWriter (with refactoring) to POVWriter (see gist)
4. I modified the TriangleMesh class to include copies of OBJWriter methods as POVWriter methods (see gist)
5. I wrote tests based on the SuperEllipsoid example (see gist)
6. I wrote pov file to #include ""

There was a mystery to solve the face indices were out of range, it was difficult to pinpoint too many faces/vertices.

Update 21/Jan/2012 from PovRAY tutorial
 The indexes are ZERO-BASED! So the first item in each list has an index of zero.
Presumably list in wavefront obj are not see 7 and toxis code, seems strange though?

Update 22/Jan/2012 from obj specification
The indices start at ONE (thought comes to mind I could now probably hack the joons sunflow-renderer, to export everything bar spheres (and possibly cube) as a PovRAY mesh2 object).

7. I wrote a really simple test based the mesh of a single cube (and created a pov file to include "cube.pov") (see gist)

There is some kludge (which is presumably be required for STL or OBJ export) where faces indices are incremented by one. I removed this adjustment and the problem seemed to be solved (see update above).

8. I ran the SuperEllisoid example again, and here is the resulting PovRAY rendered sketch.

Update 28 Feb (I deleted old code) see revised code here which has been re factored to use a File output, rather than PrintWriter directly.
Rendered with PovRAY 3.7beta

Looks pretty good to me, unlike the cube where the normals seem to be odd, more work to be done there (normalizing the normals did not seem to help). From further reading calculating normals is not trivial.

Carried away with the success I thought I would have a go with the implicit function test, here is the result, intestingly I had to do this adjustment to fit the object in the scene scale<0.009, 0.009, 0.009>:-
Now rendered with Radiosity on took a bit longer, but it was worth it

Here is pretty funky red marble rendering

No comments:

Post a Comment


Blog Archive

About Me

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