discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Efficient generation of many PNG images from command line?

V
Vigardo
Sat, Jan 9, 2021 11:54 AM

Dear experts,

I need to generate hundreds (if not thousands) of views from a single
OpenSCAD model using just the command line tool (because it will run on a
linux web server), and as fast as possible. So far, I´ve only found an old
thread about this topic titled " rendering scad images via an api
http://forum.openscad.org/rendering-scad-images-via-an-api-td4277.html  ",
but the issue was not fully solved.

I already can do it using the -D option to pre-define some variable(s), for
example with the following bash script:

for((i=0;i<=100;i++))
do
openscad -o myimage_$i.png --imgsize=640x480 --autocenter --projection o
--camera 0,0,0,90,0,0,10 -D someangle=$i -q mymodel.scad
done

This approach is terribly slow (minutes) because OpenSCAD parses the input
scad file and renders the scene for every single view. Any better
alternatives?

I know that OpenSCAD GUI is able to dump all animation images, but this
option seems not available from command line. Perhaps, adding an
"--animation" option would be a good improvement in future releases, don´t
you think?

Ideally, OpenSCAD would read once the input model and then generate and dump
the PNG image for every pre-defined variable set. Such variable sets would
be provided via some simple text file with, e.g. one variable set per line.
Note that, at least for my application, the model is the same for all
generated views, only the orientation changes.

Thanks a lot in advance!

--
Sent from: http://forum.openscad.org/

Dear experts, I need to generate hundreds (if not thousands) of views from a single OpenSCAD model using just the command line tool (because it will run on a linux web server), and as fast as possible. So far, I´ve only found an old thread about this topic titled " rendering scad images via an api <http://forum.openscad.org/rendering-scad-images-via-an-api-td4277.html> ", but the issue was not fully solved. I already can do it using the -D option to pre-define some variable(s), for example with the following bash script: for((i=0;i<=100;i++)) do openscad -o myimage_$i.png --imgsize=640x480 --autocenter --projection o --camera 0,0,0,90,0,0,10 -D someangle=$i -q mymodel.scad done This approach is terribly slow (minutes) because OpenSCAD parses the input scad file and renders the scene for every single view. Any better alternatives? I know that OpenSCAD GUI is able to dump all animation images, but this option seems not available from command line. Perhaps, adding an "--animation" option would be a good improvement in future releases, don´t you think? Ideally, OpenSCAD would read once the input model and then generate and dump the PNG image for every pre-defined variable set. Such variable sets would be provided via some simple text file with, e.g. one variable set per line. Note that, at least for my application, the model is the same for all generated views, only the orientation changes. Thanks a lot in advance! -- Sent from: http://forum.openscad.org/
TP
Torsten Paul
Sat, Jan 9, 2021 3:29 PM

On 09.01.21 12:54, Vigardo wrote:

I know that OpenSCAD GUI is able to dump all animation images,
but this option seems not available from command line. Perhaps,
adding an "--animation" option would be a good improvement in
future releases, don´t you think?

Yep, that already exists in the release candidates.

In addition there's a persistent cache feature which is still
work in progress. As the name implies, this will persist caches
across multiple separate calls of OpenSCAD via either local
files or redis server.

ciao,
Torsten.

On 09.01.21 12:54, Vigardo wrote: > I know that OpenSCAD GUI is able to dump all animation images, > but this option seems not available from command line. Perhaps, > adding an "--animation" option would be a good improvement in > future releases, don´t you think? Yep, that already exists in the release candidates. In addition there's a persistent cache feature which is still work in progress. As the name implies, this will persist caches across multiple separate calls of OpenSCAD via either local files or redis server. ciao, Torsten.
V
Vigardo
Sat, Jan 9, 2021 5:10 PM

Sorry for my ignorance or if I did not understood you well:

  1. Then, is the  OpenSCAD release candidate 2021.01-RC5 (6 January 2021)
    https://www.openscad.org/news.html  , available as a Development Snapshots
    in the  downloads page https://www.openscad.org/downloads.html  able to
    dump all animation PNGs from the command line?

  2. Will the persistent cache feature persist across multiple separate calls
    to OpenSCAD command-lined or just the GUI version?

  3. When do you think such persistent cache will be available?

Thanks a lot for the help and quick response!

--
Sent from: http://forum.openscad.org/

Sorry for my ignorance or if I did not understood you well: 1) Then, is the OpenSCAD release candidate 2021.01-RC5 (6 January 2021) <https://www.openscad.org/news.html> , available as a Development Snapshots in the downloads page <https://www.openscad.org/downloads.html> able to dump all animation PNGs from the command line? 2) Will the persistent cache feature persist across multiple separate calls to OpenSCAD command-lined or just the GUI version? 3) When do you think such persistent cache will be available? Thanks a lot for the help and quick response! -- Sent from: http://forum.openscad.org/
TP
Torsten Paul
Sat, Jan 9, 2021 6:44 PM

On 09.01.21 18:10, Vigardo wrote:

  1. Then, is the  OpenSCAD release candidate 2021.01-RC5
    (6 January 2021) https://www.openscad.org/news.html,
    available as a Development Snapshots in the downloads
    page https://www.openscad.org/downloads.html able to
    dump all animation PNGs from the command line?

At this point dev snapshots and the release candidate
are almost identical but that will start to diverge
again pretty soon. Both support the new --animate
command line option.

Downloads are separate:
RC: https://www.openscad.org/downloads.html#rc
DEV: https://www.openscad.org/downloads.html#snapshots

  1. Will the persistent cache feature persist across
    multiple separate calls to OpenSCAD command-lined or
    just the GUI version?

It's supposed to work with both (but commandline will
need explicit setup options, not using the config that
is available in GUI).

  1. When do you think such persistent cache will be
    available?

No idea. I'd love to see that as soon as possible, but
there's no way to plan free time of people.

ciao,
Torsten.

On 09.01.21 18:10, Vigardo wrote: > 1) Then, is the OpenSCAD release candidate 2021.01-RC5 > (6 January 2021) <https://www.openscad.org/news.html>, > available as a Development Snapshots in the downloads > page <https://www.openscad.org/downloads.html> able to > dump all animation PNGs from the command line? At this point dev snapshots and the release candidate are almost identical but that will start to diverge again pretty soon. Both support the new --animate command line option. Downloads are separate: RC: https://www.openscad.org/downloads.html#rc DEV: https://www.openscad.org/downloads.html#snapshots > 2) Will the persistent cache feature persist across > multiple separate calls to OpenSCAD command-lined or > just the GUI version? It's supposed to work with both (but commandline will need explicit setup options, not using the config that is available in GUI). > 3) When do you think such persistent cache will be > available? No idea. I'd love to see that as soon as possible, but there's no way to plan free time of people. ciao, Torsten.
T
Troberg
Sat, Jan 9, 2021 7:11 PM

I have a similar problem, though with SVG export. Just having to restart
everything for every export takes ages. Animation doesn't work for anything
but PNG.

It would be great if there was a built-in export (filename) module.

Example:

export("mypart.svg")
mypart();

--
Sent from: http://forum.openscad.org/

I have a similar problem, though with SVG export. Just having to restart everything for every export takes ages. Animation doesn't work for anything but PNG. It would be great if there was a built-in export (filename) module. Example: export("mypart.svg") mypart(); -- Sent from: http://forum.openscad.org/
TP
Torsten Paul
Sat, Jan 9, 2021 7:39 PM

On 09.01.21 20:11, Troberg wrote:

I have a similar problem, though with SVG export. Just
having to restart everything for every export takes ages.
Animation doesn't work for anything but PNG.

It does work in command line mode.

--- square.scad ---
rotate(90 * $t) square(10);

openscad-nightly --animate 10 -o square.svg square.scad

produces 10 SVG files with a rotating square, although it
might be useful to also add a camera option too for a
fixed view.

export("mypart.svg")
mypart();

No. There's likely some feature to export multiple files,
but it's not going to be an imperative call writing a file.

ciao,
Torsten.

On 09.01.21 20:11, Troberg wrote: > I have a similar problem, though with SVG export. Just > having to restart everything for every export takes ages. > Animation doesn't work for anything but PNG. It does work in command line mode. --- square.scad --- rotate(90 * $t) square(10); ------------------- openscad-nightly --animate 10 -o square.svg square.scad produces 10 SVG files with a rotating square, although it might be useful to also add a camera option too for a fixed view. > export("mypart.svg") > mypart(); No. There's likely some feature to export multiple files, but it's not going to be an imperative call writing a file. ciao, Torsten.
JB
Jordan Brown
Sat, Jan 9, 2021 8:09 PM

On 1/9/2021 11:39 AM, Torsten Paul wrote:

No. There's likely some feature to export multiple files, but it's not
going to be an imperative call writing a file.

Indeed.  Danger, Will Robinson!  As soon as the language has a way to
write named files, you have to worry about what interesting files a
malicious program might write.

(That's one of the disturbing aspects of a Python-based replacement,
that it's hard to avoid giving the program you just downloaded way too
much access to your system.)

On 1/9/2021 11:39 AM, Torsten Paul wrote: > No. There's likely some feature to export multiple files, but it's not > going to be an imperative call writing a file. Indeed.  Danger, Will Robinson!  As soon as the language has a way to write named files, you have to worry about what interesting files a malicious program might write. (That's one of the disturbing aspects of a Python-based replacement, that it's hard to avoid giving the program you just downloaded way too much access to your system.)
T
Troberg
Sun, Jan 10, 2021 7:06 AM

I have a similar problem, though with SVG export. Just
having to restart everything for every export takes ages.
Animation doesn't work for anything but PNG.

It does work in command line mode.

Wow, didn't know that! Now I'll have to rethink my 11 hour export batch!

produces 10 SVG files with a rotating square, although it
might be useful to also add a camera option too for a
fixed view.

Not really, as the SVG files will be top down of the entire object, no
matter what, which is what I like.

export("mypart.svg")
mypart();

No. There's likely some feature to export multiple files,
but it's not going to be an imperative call writing a file.

So, just don't allow any directory except the same as the SCAD file. Can't
do much damage then, unless the user does something really, really stupid,
such as running it from the Windows directory.

Or just have a setting to turn off all file writing in the settings, which
is set to disable as default.

For me, it would be immensely useful to be able to write to files, both as
export and as an ability to echo() to a file. It makes it much easier to
build an integrated tool chain where you can connect everything with little
or no manual interaction.

--
Sent from: http://forum.openscad.org/

> > I have a similar problem, though with SVG export. Just > > having to restart everything for every export takes ages. > > Animation doesn't work for anything but PNG. > > It does work in command line mode. Wow, didn't know that! Now I'll have to rethink my 11 hour export batch! > produces 10 SVG files with a rotating square, although it > might be useful to also add a camera option too for a > fixed view. Not really, as the SVG files will be top down of the entire object, no matter what, which is what I like. > > export("mypart.svg") > > mypart(); > > No. There's likely some feature to export multiple files, > but it's not going to be an imperative call writing a file. So, just don't allow any directory except the same as the SCAD file. Can't do much damage then, unless the user does something really, really stupid, such as running it from the Windows directory. Or just have a setting to turn off all file writing in the settings, which is set to disable as default. For me, it would be immensely useful to be able to write to files, both as export and as an ability to echo() to a file. It makes it much easier to build an integrated tool chain where you can connect everything with little or no manual interaction. -- Sent from: http://forum.openscad.org/
TP
Torsten Paul
Sun, Jan 10, 2021 4:11 PM

On 10.01.21 08:06, Troberg wrote:

produces 10 SVG files with a rotating square, although it
might be useful to also add a camera option too for a
fixed view.

Not really, as the SVG files will be top down of the entire
object, no matter what, which is what I like.

Right, I was thinking of PNG where the camera does define
the field of view. I think you are correct that it would
not have an effect on the viewport of the SVG. Some other
workaround like tiny boxes in the viewport corners might
work.

ciao,
Torsten.

On 10.01.21 08:06, Troberg wrote: >> produces 10 SVG files with a rotating square, although it >> might be useful to also add a camera option too for a >> fixed view. > Not really, as the SVG files will be top down of the entire > object, no matter what, which is what I like. Right, I was thinking of PNG where the camera does define the field of view. I think you are correct that it would not have an effect on the viewport of the SVG. Some other workaround like tiny boxes in the viewport corners might work. ciao, Torsten.
MB
Michael Bronnenberg
Mon, Jan 11, 2021 6:27 AM

You can get pretty good speed boost, at least with Linux.  You can add a
space and ampersand at the end of the commands your script is making.  That
will launch that command in a separate thread, so you'll have multiple
instances of openscad running simultaneously.  Depending on how many cores
your computer has, you should get a pretty good reduction in processing
time.  You have to add a 'wait' command at the end for the script to wait
for all the threads to finish.

On January 9, 2021 6:55:32 AM Vigardo bioramon@gmail.com wrote:

Dear experts,

I need to generate hundreds (if not thousands) of views from a single
OpenSCAD model using just the command line tool (because it will run on a
linux web server), and as fast as possible. So far, I´ve only found an old
thread about this topic titled " rendering scad images via an api
http://forum.openscad.org/rendering-scad-images-via-an-api-td4277.html  ",
but the issue was not fully solved.

I already can do it using the -D option to pre-define some variable(s), for
example with the following bash script:

for((i=0;i<=100;i++))
do
openscad -o myimage_$i.png --imgsize=640x480 --autocenter --projection o
--camera 0,0,0,90,0,0,10 -D someangle=$i -q mymodel.scad
done

This approach is terribly slow (minutes) because OpenSCAD parses the input
scad file and renders the scene for every single view. Any better
alternatives?

I know that OpenSCAD GUI is able to dump all animation images, but this
option seems not available from command line. Perhaps, adding an
"--animation" option would be a good improvement in future releases, don´t
you think?

Ideally, OpenSCAD would read once the input model and then generate and dump
the PNG image for every pre-defined variable set. Such variable sets would
be provided via some simple text file with, e.g. one variable set per line.
Note that, at least for my application, the model is the same for all
generated views, only the orientation changes.

Thanks a lot in advance!

--
Sent from: http://forum.openscad.org/


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

You can get pretty good speed boost, at least with Linux. You can add a space and ampersand at the end of the commands your script is making. That will launch that command in a separate thread, so you'll have multiple instances of openscad running simultaneously. Depending on how many cores your computer has, you should get a pretty good reduction in processing time. You have to add a 'wait' command at the end for the script to wait for all the threads to finish. On January 9, 2021 6:55:32 AM Vigardo <bioramon@gmail.com> wrote: > Dear experts, > > I need to generate hundreds (if not thousands) of views from a single > OpenSCAD model using just the command line tool (because it will run on a > linux web server), and as fast as possible. So far, I´ve only found an old > thread about this topic titled " rendering scad images via an api > <http://forum.openscad.org/rendering-scad-images-via-an-api-td4277.html> ", > but the issue was not fully solved. > > I already can do it using the -D option to pre-define some variable(s), for > example with the following bash script: > > for((i=0;i<=100;i++)) > do > openscad -o myimage_$i.png --imgsize=640x480 --autocenter --projection o > --camera 0,0,0,90,0,0,10 -D someangle=$i -q mymodel.scad > done > > This approach is terribly slow (minutes) because OpenSCAD parses the input > scad file and renders the scene for every single view. Any better > alternatives? > > I know that OpenSCAD GUI is able to dump all animation images, but this > option seems not available from command line. Perhaps, adding an > "--animation" option would be a good improvement in future releases, don´t > you think? > > Ideally, OpenSCAD would read once the input model and then generate and dump > the PNG image for every pre-defined variable set. Such variable sets would > be provided via some simple text file with, e.g. one variable set per line. > Note that, at least for my application, the model is the same for all > generated views, only the orientation changes. > > Thanks a lot in advance! > > > > -- > Sent from: http://forum.openscad.org/ > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org