|
 |
"claudio56" <nomail@nomail> wrote:
> I'm looking for a way to 3d-print my povray image. It is indeed a very easy
> picture, consisting only of spheres and cylinders. As far as I could find, there
> is no direct converter from povray to the stl format (or any other format
> suitable for 3d printing). I hoped I could somehow import my cylinders and
> spheres with autocad, by I couldn't. The cylinders and spheres are generated
> (i.e. the coordinates are written) by another program but I can surely re-write
> them in an other format. So, is there a way to convert this easy set of objects
> into a 3d-print suitable format?
I have recently done exactly what you are seeking to do - output some spheres
and cylinders from a POV-Ray source file into an STL file suitable for 3D
printing. I used OpenSCAD, an open-source CSG modelling language, which creates
triangle models from geometric primitives described in a text file in a similar
fashion to POV-Ray.
http://www.openscad.org/
To achieve this, I wrote a couple of POV-Ray macros to create spheres and
cylinders in the OpenSCAD scene format. I've included them below, together with
some sample code to generate a file with a sphere and a cylinder. The macros
also include equivalent POV-Ray code to produce the same objects in a render so
you can check your geometry.
Simply run a render with this code, and the output .scad file should then be
usable in OpenSCAD. If you have a large number of objects it may take OpenSCAD
quite a while to perform the intersections, but I've not seen any errors yet. I
used it to create some polyhedron skeletons, which are very nice printed in
stainless steel :-)
Bill
NB you can change the triangle resolution with the $fs property - see the
OpenSCAD docs for more info.
------------------------------------------------------------------
#macro ScadCylinder(P1, P2, Radius)
#local Len = vlength(P2-P1);
#local Axis = vnormalize(P2-P1);
// ---------- //
// transform taken from Reorient_Trans() and Axis_Rotate_Trans() in
transforms.inc
#local VX1 = z;
#local VX2 = Axis;
#local Y = vcross(VX1, VX2);
#if (vlength(Y) > 0)
#local VY = vnormalize(Y);
#local VZ1 = vnormalize(vcross(VX1, VY));
#local VZ2 = vnormalize(vcross(VX2, VY));
#local Transform = transform {
matrix <VX1.x, VY.x, VZ1.x, VX1.y, VY.y, VZ1.y, VX1.z, VY.z, VZ1.z, 0, 0,
0>
matrix <VX2.x, VX2.y, VX2.z, VY.x, VY.y, VY.z, VZ2.x, VZ2.y, VZ2.z, 0, 0,
0>
}
#write (SCADFile, "translate([",P1.x,", ",P1.y,", ",P1.z,"])\n")
#write (SCADFile, "multmatrix(m=[\n")
#write (SCADFile, " [",VX2.x,", ",VY.x,", ",VZ2.x,", 0],\n")
#write (SCADFile, " [",VX2.y,", ",VY.y,", ",VZ2.y,", 0],\n")
#write (SCADFile, " [",VX2.z,", ",VY.z,", ",VZ2.z,", 0],\n")
#write (SCADFile, " [0, 0, 0, 1]\n")
#write (SCADFile, "])\n")
#write (SCADFile, "multmatrix(m=[\n")
#write (SCADFile, " [",VX1.x,", ",VX1.y,", ",VX1.z,", 0],\n")
#write (SCADFile, " [",VY.x,", ",VY.y,", ",VY.z,", 0],\n")
#write (SCADFile, " [",VZ1.x,", ",VZ1.y,", ",VZ1.z,", 0],\n")
#write (SCADFile, " [0, 0, 0, 1]\n")
#write (SCADFile, "])\n")
#else
#if (vlength(VX1-VX2) = 0)
#local Transform = transform { }
#write (SCADFile, "translate([",P1.x,", ",P1.y,", ",P1.z,"])\n")
#else
#local VZ = VPerp_To_Vector(VX2);
#local AVX = vaxis_rotate(x, VZ, 180);
#local AVY = vaxis_rotate(y, VZ, 180);
#local AVZ = vaxis_rotate(z, VZ, 180);
#local Transform = transform {
matrix <AVX.x, AVX.y, AVX.z, AVY.x, AVY.y, AVY.z, AVZ.x, AVZ.y, AVZ.z, 0,
0, 0>
}
#write (SCADFile, "translate([",P1.x,", ",P1.y,", ",P1.z,"])\n")
#write (SCADFile, "multmatrix(m=[\n")
#write (SCADFile, " [",AVX.x,", ",AVY.x,", ",AVZ.x,", 0],\n")
#write (SCADFile, " [",AVX.y,", ",AVY.y,", ",AVZ.y,", 0],\n")
#write (SCADFile, " [",AVX.z,", ",AVY.z,", ",AVZ.z,", 0],\n")
#write (SCADFile, " [0, 0, 0, 1]\n")
#write (SCADFile, "])\n")
#end
#end
// ---------- //
cylinder {
<0, 0, 0>, <0, 0, Len>, Radius
transform { Transform }
translate P1
}
#write (SCADFile, "cylinder(r=",Radius,",h=",Len,",center=false,$fs=0.02);\n")
#end
#macro ScadSphere(P, Radius)
sphere {
<0, 0, 0>, Radius
translate P
}
#write (SCADFile, "translate([",P.x,", ",P.y,", ",P.z,"])
sphere(r=",Radius,",$fs=0.02);\n")
#end
#declare SCADFileName = "scad_file.scad";
#ifdef (SCADFile) #undef SCADFile #end
#fopen SCADFile SCADFileName write
#write (SCADFile, "// OpenSCAD generated by POV-Ray\n\n")
#write (SCADFile, "union () {\n")
union {
ScadSphere(<0,0,0>, 5)
ScadCylinder(<-10,0,0>, <10,0,0>, 2)
pigment { rgb x }
finish { ambient 0 }
}
#write (SCADFile, "}\n")
------------------------------------------------------------------
Post a reply to this message
|
 |