using toxilibs colormodel stl exporter
in
Contributed Library Questions
•
2 years ago
hi guys,
how do i export color stls using toxilibs? i found this topic here:
http://processing.org/discourse/yabb2/YaBB.pl?num=1268405776 but i could not get the example to work. I'm running the latest version of toxilibs. After some tweaking, this is as far as i've got. the error is at line 34 where i try to retrieve the vertices of the faces.
many thanks
- import toxi.math.conversion.*;
- import toxi.geom.*;
- import toxi.math.*;
- import toxi.geom.mesh2d.*;
- import toxi.util.datatypes.*;
- import toxi.util.events.*;
- import toxi.geom.mesh.subdiv.*;
- import toxi.geom.mesh.*;
- import toxi.math.waves.*;
- import toxi.util.*;
- import toxi.math.noise.*;
- /* a custom mesh STL exporter */
- // assume this has been populated somehow...
- TriangleMesh mesh;
- // create stl color model with mesh base color
- // the true flag means facets can have their own RGB value
- MaterialiseSTLColorModel colModel=new MaterialiseSTLColorModel(0x112233,true);
- // create STLWriter instance
- STLWriter stl = new STLWriter(colModel, 10);
- // write the file header
- stl.beginSave(sketchPath("color.stl"), mesh.getNumFaces());
- int k=0;
- // iterate over all mesh faces
- for (Iterator i=mesh.faces.iterator(); i.hasNext();) {
- ArrayList<Face> f=(ArrayList<Face>)i.next();
- // tint every 2nd face in alternating colors
- // btw. a RGB value of -1 will disable the face color
- // and revert to the default mesh color
- stl.Face(f.b, f.a, f.c, f.normal, 0==k%2 ? 0xff00ff : 0xffff00);
- k++;
- }
- stl.endSave();
1