Now with images. Here's what the output looks like for me:
http://adl.serveftp.org/~bryan/pythonocc-tools/bearing.png
The rest of this email is just describing how I did it and what files I used.
You can find bearing.stl in OCC 6.3.0; linux users can run `locate
bearing.stl` and find it.
bearing.stl was here for me on various machines:
/home/bryan/opencascade/OpenCASCADE6.3.0/data/stl/bearing.stl
/home/kanzure/local/opencascade/OpenCASCADE6.3.0/data/stl/bearing.stl
python stl2pov.py bearing.stl bearing.pov
stl file: http://adl.serveftp.org/~bryan/pythonocc-tools/bearing.stl
pov file (mesh data):
http://adl.serveftp.org/~bryan/pythonocc-tools/bearing.pov.inc
pov file: http://adl.serveftp.org/~bryan/pythonocc-tools/bearing.pov
> pov2png.py
> http://adl.serveftp.org/skdb/import_tools/pov2png.py
python pov2png.py bearing.pov bearing.png
pov file (mesh data):
http://adl.serveftp.org/~bryan/pythonocc-tools/bearing.pov.inc
pov file: http://adl.serveftp.org/~bryan/pythonocc-tools/bearing.pov
resulting png: http://adl.serveftp.org/~bryan/pythonocc-tools/bearing.png
> iges2stl.py
> http://adl.serveftp.org/skdb/import_tools/iges2stl.py
You can find bearing.iges in OCC 6.3.0; linux users can run `locate
bearing.iges` and find it.
bearing.iges was here for me on various machines:
/home/bryan/opencascade/OpenCASCADE6.3.0/data/iges/bearing.iges
/home/kanzure/local/opencascade/OpenCASCADE6.3.0/data/iges/bearing.iges
/home/kanzure/code/skdb/import_tools/models/bearing.iges
python iges2stl.py bearing.iges bearing.stl
input iges file: http://adl.serveftp.org/~bryan/pythonocc-tools/bearing.iges
I don't want to upload that STL file, sorry. There's already an STL
file there, but it's the one provided with OCC 6.3.0, not the one
generated by running iges2stl.
iges2stl is *slow*. OCC is very slow when exporting or converting to
STL. Took me about 30 to 60 seconds for the bearing.
> iges2png.py
> http://adl.serveftp.org/skdb/import_tools/iges2png.py
python iges2png.py bearing.iges bearing.png
input iges file: http://adl.serveftp.org/~bryan/pythonocc-tools/bearing.iges
resulting png: http://adl.serveftp.org/~bryan/pythonocc-tools/bearing.png
Clearly the resulting image doesn't look as good as occray. I wish I
would have known about occray last night, I wouldn't have written
iges2png and have to reinvent the wheel.
http://code.google.com/p/occray/
I looked around on the opencascade.org forum and found that others
have been trying to generate images from CAD files since 2000. There
were posts in 2000, 2002, and one more recently in 2008, of people
complaining about Xw_Window.cxx and how OCC uses Xlib to save an image
of the scene, rather than using some off screen rendering mechanism. I
also noticed that src/OpenGl/ isn't included in pythonOCC? I was
hoping to dig around in there and see if I could find a way to do off
screen rendering. PyOpenGL doesn't implement the gl off screen
rendering method, sadly enough, so it might have to be either compiled
into OCC, or we just hope that the OCC devs bothered to put it in
(which I am starting to doubt).
The other option is to use blender for rendering of STL files. Sadly
this still requires using OCC to convert from IGES/STEP to STL, which
takes forever. The other problem is that my blender script doesn't
seem to work-- I use renderAnim, I set up lamps and lights, and point
the camera at the object, but the resulting image is just black
pixels.
I was running blender with:
blender -b -P render_image.py
And here's what I had in render_image.py ...
http://adl.serveftp.org/~bryan/pythonocc-tools/render_image.py
Why is it so hard to get a rendered image? Does anyone know how
thingiverse is rendering their images of STL and DXF files?
I see. Right now converting from IGES to STL is taking a long time.
The povray part is pretty quick. One other option that I am
investigating is using gmsh (which links to OCC) to load an IGES file
and then save an image (it has some image saving functions). The
problem is that the output of the GIF exporter looks like this:
http://adl.serveftp.org/~bryan/pythonocc-tools/bearing.gif
But it is significantly faster, so a compiled tool (linking to gmsh)
might be better in the end. I don't know how fast occray is, it was
just announced this morning. An off-screen OpenGL renderer would be
even better. I guess I'll go back to digging through the OCC
code-base.
Would one of you be able to elaborate on how to have stls be viewable like Thingiverse? The file can be successfully loaded by a user but open up in a new page as data.