If you've seen anything to to with my previous raytracing experiments, you will have come accross my FTest, here I have translated it to work with toxilibs mesh classes (using my totally custom version of toxiclibscore.jar which allows export as PovRAY mesh). As you will see from my "F" coding I'm not really that familiar with toxicilibs, Karsten would probably have a laugh:-
1 import java.io.FileNotFoundException;
2 import java.io.FileOutputStream;
3 import java.io.PrintWriter;
4 import java.util.logging.Level;
5 import java.util.logging.Logger;
6 import toxi.geom.AABB;
7 import toxi.geom.Vec3D;
8 import toxi.geom.mesh.TriangleMesh;
9 import toxi.processing.*;
10
11
12 /**
13 * <p>FtestPOV demonstrates how to save a model as PovRAY mesh2
14 * format to a generic Java PrintWriter (nested BufferedWriter/FileWriter would be better)
15 * backend. inside the sketch folder.</p>
16 */
17
18 /*
19 * Copyright (c) 2012 Martin Prout
20 *
21 * This library is free software; you can redistribute it and/or modify it
22 * under the terms of the GNU Lesser General Public License as published by
23 * the Free Software Foundation; either version 2.1 of the License, or (at
24 * your option) any later version.
25 *
26 * http://creativecommons.org/licenses/LGPL/2.1/
27 *
28 * This library is distributed in the hope that it will be useful, but
29 * WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
31 * General Public License for more details.
32 *
33 * You should have received a copy of the GNU Lesser General Public License
34 * along with this library; if not, write to the Free Software Foundation,
35 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
36 */
37 TriangleMesh mesh;
38 ToxiclibsSupport gfx;
39
40 void setup() {
41 size(200, 200, P3D);
42 gfx = new ToxiclibsSupport(this);
43 // define a rounded cube using the SuperEllipsoid surface function
44 AABB vert = AABB.fromMinMax(new Vec3D(-1.0f, -4.5f, -1.0f), new Vec3D(1.0f, 3.5f, 1.0f));
45 AABB box = AABB.fromMinMax(new Vec3D(1.0f, 1.5f, -1.0f), new Vec3D(3.0f, 3.5f, 1.0f));
46 AABB box2 = AABB.fromMinMax(new Vec3D(1.0f, -2.5f, -1.0f), new Vec3D(3.0f, -0.5f, 1.0f));
47 mesh = (TriangleMesh) box.toMesh();
48 mesh.addMesh((TriangleMesh) vert.toMesh());
49 mesh.addMesh((TriangleMesh) box2.toMesh());
50 }
51
52 void draw() {
53 translate(width/2, height/2);
54 scale(15);
55 rotateY(radians(-10));
56 gfx.mesh(mesh);
57 }
58
59 void keyPressed() {
60 if (key == 'e') {
61 // attempt to create a PrintWriter and save to it
62 PrintWriter pw = null;
63 try {
64 String fileID = "FTest";//+(System.currentTimeMillis()/1000);
65 pw = new PrintWriter(sketchPath(fileID + ".inc"));
66 mesh.saveAsPOV(pw);
67 }
68 catch (FileNotFoundException ex) {
69 Logger.getLogger(ftest.class.getName()).log(Level.SEVERE, null, ex);
70 }
71 finally {
72 pw.flush();
73 pw.close();
74 }
75 exit();
76 }
77 if (key == 's') {
78 saveFrame("/home/tux/Fpde.png");
79 }
80 }
81
This was always going to produce an upside 'F' an indeed it does here is the screen image:-
 |
| Saved sketch |
 |
| PovRAY traced (no normals) |
|
|
|
However as expected the raytraced image is the right way up, so now I will try and make the raytraced image upside down to match the sketch. (exported normals play badly with this sketch, so I have removed them here).
This has now been done (by mutliplying y and z coordinates by -1 during PovRAY export) here is the resulting PovRAY traced image:-
 |
| Raytraced image with corrected library |
0 comments:
Post a Comment