rendering scad images via an api

classic Classic list List threaded Threaded
17 messages Options
Reply | Threaded
Open this post in threaded view
|

rendering scad images via an api

Eyal Dechter
Hi, 

I would like to use OpenSCAD as an element in an image generation pipeline. I've been using the command line features to convert from scad files to png files. However, it would be a lot faster if I did not need to open a new OpenSCAD instance each time I wanted to render an image. Any pointers on how to go about doing this?  

Thanks,
Eyal Dechter

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
Reply | Threaded
Open this post in threaded view
|

Re: rendering scad images via an api

nophead
Would it actually be much faster as starting openscad doesn't take long compared to rendering.


On 29 April 2013 21:54, Eyal Dechter <[hidden email]> wrote:
Hi, 

I would like to use OpenSCAD as an element in an image generation pipeline. I've been using the command line features to convert from scad files to png files. However, it would be a lot faster if I did not need to open a new OpenSCAD instance each time I wanted to render an image. Any pointers on how to go about doing this?  

Thanks,
Eyal Dechter

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
Reply | Threaded
Open this post in threaded view
|

Re: rendering scad images via an api

Felipe Sanches
In reply to this post by Eyal Dechter
Since we don't have disk cache yet, if you want to algorithmically invoke openscad in the command like to generate several images of the same project with different parameters (that can be passed to the command line), then each new instance will have to re-render everything from scratch because caching is done to RAM only. If the SCAD project you're automating is sufficiently complex, then the performance hit will be considerable.

The same thing seems to happen when you're simultaneously working on two portions of a large SCAD project that is split into 2 windows. You can view the model of a sub-assembly in one openscad window and have the full design that "uses" the subassembly in another window. The subassembly model will be rendered twice because multiple instances of openscad do not share the in-memory cache, as far as I can tell.

For those heavy-user usecases (with frequently are my usecases, by the way), I think it would be interesting to run openscad as a daemon that takes care of rendering things, and then openscad windows would delegate models to the daemon to be rendered and the daemon would share the in-memory cache between instances. Also, command line instances wouldn't have the cache purged immediately, so subsequent calls to the command line interface could benefit from a longer-term cache, improving performance of batch rendering.

happy hacking,
Felipe Sanches

On Mon, Apr 29, 2013 at 5:54 PM, Eyal Dechter <[hidden email]> wrote:
Hi, 

I would like to use OpenSCAD as an element in an image generation pipeline. I've been using the command line features to convert from scad files to png files. However, it would be a lot faster if I did not need to open a new OpenSCAD instance each time I wanted to render an image. Any pointers on how to go about doing this?  

Thanks,
Eyal Dechter

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
Reply | Threaded
Open this post in threaded view
|

Re: rendering scad images via an api

Triffid Hunter
In reply to this post by Eyal Dechter
On 30 April 2013 06:54, Eyal Dechter <[hidden email]> wrote:
I would like to use OpenSCAD as an element in an image generation pipeline. I've been using the command line features to convert from scad files to png files. However, it would be a lot faster if I did not need to open a new OpenSCAD instance each time I wanted to render an image. Any pointers on how to go about doing this?  

if you're rendering the same thing from different viewpoints, render it to STL then simply generate scad files with rotate([..]) translate([..]) import("blah.stl"); or even use an external STL renderer

if you're rendering different things, note that the startup time of openscad is completely insignificant compared to the render time, so reusing a single instance would make only a negligible difference


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
Reply | Threaded
Open this post in threaded view
|

Re: rendering scad images via an api

Peter Falke
You may also consider the annimation feature of OpenSCAD.
This will write lots of pictures on disk in one go (one for every time step).
See this thing on thingivers for an example:
http://www.thingiverse.com/thing:27044

Hope it helps,

TakeItAndRun


On 30 April 2013 14:58, Triffid Hunter <[hidden email]> wrote:
On 30 April 2013 06:54, Eyal Dechter <[hidden email]> wrote:
I would like to use OpenSCAD as an element in an image generation pipeline. I've been using the command line features to convert from scad files to png files. However, it would be a lot faster if I did not need to open a new OpenSCAD instance each time I wanted to render an image. Any pointers on how to go about doing this?  

if you're rendering the same thing from different viewpoints, render it to STL then simply generate scad files with rotate([..]) translate([..]) import("blah.stl"); or even use an external STL renderer

if you're rendering different things, note that the startup time of openscad is completely insignificant compared to the render time, so reusing a single instance would make only a negligible difference


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566



--
[hidden email]

P.S. Falls meine E-Mail kürzer ausfällt als Dir angenehm ist:
Ich probiere gerade aus kurze Antworten statt gar keine Antworten zu schreiben.
Wenn Du gerne mehr lesen möchtest, dann lass es mich bitte wissen.

P.S. In case my e-mail is shorter than you enjoy:
I am currently trying short replies instead of no replies at all.
Please let me know, if you like to read more.

Enjoy!

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
Reply | Threaded
Open this post in threaded view
|

Re: rendering scad images via an api

Triffid Hunter
On 30 April 2013 23:28, Peter Falke <[hidden email]> wrote:
You may also consider the annimation feature of OpenSCAD.
This will write lots of pictures on disk in one go (one for every time step).
See this thing on thingivers for an example:
http://www.thingiverse.com/thing:27044

can that be triggered via headless terminal invocation?

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
Reply | Threaded
Open this post in threaded view
|

Re: rendering scad images via an api

kintel
Administrator
In reply to this post by Eyal Dechter
On 2013-04-29, at 16:54 , Eyal Dechter wrote:
>
> I would like to use OpenSCAD as an element in an image generation pipeline. I've been using the command line features to convert from scad files to png files. However, it would be a lot faster if I did not need to open a new OpenSCAD instance each time I wanted to render an image. Any pointers on how to go about doing this?  
>
I've been thinking about creating an IPC mechanism which would allow external processes to talk to a (headless?) OpenSCAD instance and request commands like rendering images or STLs. This would allow reuse of existing internal caches and could even allow for real-time image output of rotating models.

It's a fair bit of work to do this properly though.

 -Marius

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
Reply | Threaded
Open this post in threaded view
|

Re: rendering scad images via an api

Felipe Sanches
That's exactly what I meant in my previous message! I think that would be great!

On Tue, Apr 30, 2013 at 11:33 AM, Marius Kintel <[hidden email]> wrote:
On 2013-04-29, at 16:54 , Eyal Dechter wrote:
>
> I would like to use OpenSCAD as an element in an image generation pipeline. I've been using the command line features to convert from scad files to png files. However, it would be a lot faster if I did not need to open a new OpenSCAD instance each time I wanted to render an image. Any pointers on how to go about doing this?
>
I've been thinking about creating an IPC mechanism which would allow external processes to talk to a (headless?) OpenSCAD instance and request commands like rendering images or STLs. This would allow reuse of existing internal caches and could even allow for real-time image output of rotating models.

It's a fair bit of work to do this properly though.

 -Marius

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
Reply | Threaded
Open this post in threaded view
|

Re: rendering scad images via an api

Bryan Bishop
In reply to this post by kintel
On Tue, Apr 30, 2013 at 9:33 AM, Marius Kintel <[hidden email]> wrote:
I've been thinking about creating an IPC mechanism which would allow external processes to talk to a (headless?) OpenSCAD instance and request commands like rendering images or STLs. This would allow reuse of existing internal caches and could even allow for real-time image output of rotating models.

Does openscad run headlessly yet? I think it still requires an X server, right?

- Bryan
http://heybryan.org/
1 512 203 0507
_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
Reply | Threaded
Open this post in threaded view
|

Re: rendering scad images via an api

kintel
Administrator
On 2013-04-30, at 16:03 , Bryan Bishop wrote:
>
> Does openscad run headlessly yet? I think it still requires an X server, right?
>
On Linux/Unix, it needs at least a virtual framebuffer. If you don't run an X server, you can use Xvnc or Xvfb to set one up.
We're running headlessly all the time for the test framework, which uses the OpenSCAD binary for regression tests.

I believe the X requirement could be killed if someone rewrites OffscreenContextGLX to not be dependent on X..

 -Marius

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
Reply | Threaded
Open this post in threaded view
|

Re: rendering scad images via an api

Bryan Bishop
On Tue, Apr 30, 2013 at 3:14 PM, Marius Kintel <[hidden email]> wrote:
On Linux/Unix, it needs at least a virtual framebuffer. If you don't run an X server, you can use Xvnc or Xvfb to set one up.

Ah, that's unfortunate. I don't consider that headless. I think qt/lighthouse (QPA) might be one option to become headless without xvnc, xvfb, or xserver-xorg-video-dummy.

- Bryan
http://heybryan.org/
1 512 203 0507
_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
Reply | Threaded
Open this post in threaded view
|

Re: rendering scad images via an api

kintel
Administrator
On 2013-04-30, at 16:34 , Bryan Bishop wrote:
>
> Ah, that's unfortunate. I don't consider that headless. I think qt/lighthouse (QPA) might be one option to become headless without xvnc, xvfb, or xserver-xorg-video-dummy.
>
Actually, we don't use Qt on the backend - we only use X to get an OpenGL context for rendering to PNG output.
If you don't want to render to images, just to STL, X shouldn't be needed even today.

 -Marius

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
Reply | Threaded
Open this post in threaded view
|

Re: rendering scad images via an api

Bryan Bishop
On Tue, Apr 30, 2013 at 3:40 PM, Marius Kintel <[hidden email]> wrote:
Actually, we don't use Qt on the backend - we only use X to get an OpenGL context for rendering to PNG output.
If you don't want to render to images, just to STL, X shouldn't be needed even today.

Oh. In that case, for a headless pipeline, you could just export STL, then run it through BRLCAD's raytracer. Eyal, would this work for you?

- Bryan
http://heybryan.org/
1 512 203 0507
_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
Reply | Threaded
Open this post in threaded view
|

Re: rendering scad images via an api

Felipe Sanches
hmm... One of the enhancements I had in mind was to add support for exporting yafaray scenes (preserving color info and maybe even material type by adding a material("glass") draw_something(); syntax) and than raytracing photorealistic scenes developed in openscad.

I even started working on the yafaray exporter here:

https://github.com/openscad/openscad/pull/216
https://github.com/openscad/openscad/issues/215

happy hacking,
Felipe Sanches


On Tue, Apr 30, 2013 at 6:09 PM, Bryan Bishop <[hidden email]> wrote:
On Tue, Apr 30, 2013 at 3:40 PM, Marius Kintel <[hidden email]> wrote:
Actually, we don't use Qt on the backend - we only use X to get an OpenGL context for rendering to PNG output.
If you don't want to render to images, just to STL, X shouldn't be needed even today.

Oh. In that case, for a headless pipeline, you could just export STL, then run it through BRLCAD's raytracer. Eyal, would this work for you?


- Bryan
http://heybryan.org/
<a href="tel:1%20512%20203%200507" value="+15122030507" target="_blank">1 512 203 0507

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
Reply | Threaded
Open this post in threaded view
|

Re: rendering scad images via an api

Eyal Dechter
In reply to this post by Bryan Bishop



On Tue, Apr 30, 2013 at 5:09 PM, Bryan Bishop <[hidden email]> wrote:
On Tue, Apr 30, 2013 at 3:40 PM, Marius Kintel <[hidden email]> wrote:
Actually, we don't use Qt on the backend - we only use X to get an OpenGL context for rendering to PNG output.
If you don't want to render to images, just to STL, X shouldn't be needed even today.

Oh. In that case, for a headless pipeline, you could just export STL, then run it through BRLCAD's raytracer. Eyal, would this work for you?

Hmm, I don't know. I'm a little bit of a novice at this. So I have my generated scad file, say test.scad. Are you suggesting I run  

$ openSCAD -o test.stl test.scad

?

Suppose test.scad contains 

color([0.5, 0.5, 0.5, 1.0]) cylinder(h = 10.0, r1 = 3.0, r2 = 3.0, center = false, $fn = 100);

Then running 

$ time OpenSCAD -o test.stl test.scad

gives

Root Context:

real 0m1.045s
user 0m0.599s
sys 0m0.086s

Which is prohibitively slow for me. Running 

$ time OpenSCAD -o test.png test.scad

giving 

Root Context:
Compiling design (CSG Products normalization)...
Normalized CSG tree has 1 elements

real 0m0.839s
user 0m0.364s
sys 0m0.108s

is also slow, given the simplicity of the scene, right? 

Is there a faster way to do this, particularly if I want to batch hundreds or thousands of these scad to image conversions at once?

Thanks,
Eyal





- Bryan
http://heybryan.org/
<a href="tel:1%20512%20203%200507" value="+15122030507" target="_blank">1 512 203 0507

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
Reply | Threaded
Open this post in threaded view
|

Re: rendering scad images via an api

kintel
Administrator
On 2013-04-30, at 22:19 , Eyal Dechter wrote:
>
> is also slow, given the simplicity of the scene, right?
>
> Is there a faster way to do this, particularly if I want to batch hundreds or thousands of these scad to image conversions at once?
>
Is 500ms too slow for real models, or are your referring to expected increase in computation time based on your experience?

Try running some more involved examples and see what your results are - the openscad startup time should be insignificant in those cases.
If you actually want to process thousands of conversions at once, you're by far exceeding the normal use cases for OpenSCAD invocation, and it would be time to look at optimization opportunities. The first ones which come to mind are implementation of persistent caching or IPC-based rendering requests.

 -Marius

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
Reply | Threaded
Open this post in threaded view
|

Re: rendering scad images via an api

onebeartoe
This post has NOT been accepted by the mailing list yet.
In reply to this post by Eyal Dechter
I created a test suite for OpenSCAD scripts.  

The test suite creates baseline snapshots of each .scad rendering.  The test suite is run again after changes are made to 'library' .scad files.  Then a comparison is made between the baseline snapshot and the snapshot after the changes.

The test suite then reports any files that differ, allowing you to check that only the expected baseline image were updated.

It is written in Java and run from the command line, so I guess it runs in headless mode by default.

https://github.com/onebeartoe/3D-Modeling/tree/master/OpenSCAD/test-suite

If you are interested, check it out and please let me know what you think.