Skip to content

Instantly share code, notes, and snippets.

@spuder
Last active Jan 1, 2022
Embed
What would you like to do?

Produces 360 images

This uses --animate which doesn't work with more than 3 frames when running in a docker container spuder/openscad-dockerhub#2

openscad /dev/null -D '$vpt = [0,0,0];' -D '$vpd = 20; $vpr = [0,$t * 360,0];' -o 'foo.png' -D 'cube([2,3,4]);' --imgsize=250,250 --animate 360 --colorscheme "Tomorrow Night"

The following all work, but not very well

   /Applications/OpenSCAD.app/Contents/MacOS/OpenSCAD /dev/null -D '$vpr = [60, 0, 360 * $t];' -o "${MYTMPDIR}/foo.png"  -D "import(\"$file\");" --imgsize=300,300 --animate 60 --colorscheme "Tomorrow Night" --viewall --autocenter
    # openscad /dev/null -D '$vpt = [0,0,0];' -D '$vpd = 20;' -D '$vpr = [0,$t * 360,0];' -o foo.png  -D "cube([2,3,4]);" --imgsize=250,250 --animate 360 --colorscheme "Tomorrow Night"
    # openscad /dev/null -D '$vpt = [0,0,0];' -D '$vpd = 20; $vpr = [0,$t * 360,0];' -o 'foo.png' -D 'cube([2,3,4]);' --imgsize=250,250 --animate 360 --colorscheme "Tomorrow Night"

    # https://github.com/spuder/openscad-dockerhub/issues/1
    # not working: X Error of failed request:  BadLength (poly request too large or internal Xlib length error)
    # docker run --rm -v $(PWD):/data -v ${MYTMPDIR}:/foo -v /dev/null:/dev/null spuder/openscad:latest openscad /dev/null -D '$vpt = [0,0,0];' -D '$vpd = 20; $vpr = [0,$t * 360,0];' -o '/foo/foo.png' -D 'cube([2,3,4]);' --imgsize=250,250 --animate 60 --colorscheme 'Tomorrow Night' --viewall --autocenter
    # docker run --rm -v $(PWD):/data -v ${MYTMPDIR}:/foo spuder/openscad:opengl openscad /dev/null -D '$vpd = 20; $vpr = [0,$t * 360,0];' -o '/foo/foo.png' -D 'cube([2,3,4]);' --imgsize=250,250 --animate 3 --colorscheme 'Tomorrow Night' --viewall --autocenter --preview
    # docker run -e DISPLAY=:99 -v /tmp/.X11-unix:/tmp/.X11-unix --rm -v $(PWD):/data -v ${MYTMPDIR}:/foo spuder/openscad:opengl /usr/local/bin/openscad /dev/null -D '$vpd = 20; $vpr = [0,$t * 360,0];' -o '/foo/foo.png' -D 'cube([2,3,4]);' --imgsize=250,250 --animate 3 --colorscheme 'Tomorrow Night' --viewall --autocenter --preview
    # docker run -e DISPLAY=:99 -v /tmp/.X11-unix:/tmp/.X11-unix --rm -v $(PWD):/data -v ${MYTMPDIR}:/foo spuder/openscad:opengl openscad /dev/null -D '$vpd = 20; $vpr = [0,$t * 360,0];' -o '/foo/foo.png' -D 'cube([2,3,4]);' --imgsize=250,250 --animate 3 --colorscheme 'Tomorrow Night' --viewall --autocenter --preview
    # docker run --init -v $(pwd):/openscad openscad:2021.01 xvfb-run -a openscad CSG.scad -o csg.png
    # docker run --init --rm -v $(PWD):/data -v ${MYTMPDIR}:/foo openscad/openscad:2021.01 xvfb-run -a openscad /dev/null -D '$vpd = 20; $vpr = [0,$t * 360,0];' -o '/foo/foo.png' -D 'cube([2,3,4]);' --imgsize=250,250 --animate 30 --colorscheme 'Tomorrow Night' --viewall --autocenter --preview

    steps=30
    for (( i=0; i<$steps; i++ )); do
        echo "i is ${i}"
        angle=$(echo "$i * 360 / $steps" | bc -l)
        echo $angle
        openscad /dev/null -D "\$vpd=20" -D "\$vpr = [60,0, $angle];" -o "foo${i}.png" -D 'cube([2,3,4]);' --imgsize=250,250 --colorscheme "Tomorrow Night" --viewall --autocenter
    done

Here is another approach but it has glitches

    for ((angle=0; angle <=360; angle+=5)); do
        echo "Rendering $angle"
        ls $MYTMPDIR
        # openscad /dev/null -o dump$angle.png  -D "cube([2,3,4]);" --imgsize=250,250 --camera=0,0,0,45,0,$angle,25
        docker run \
            -v "$MYTMPDIR:/input" \
            -v "$MYTMPDIR:/output" \
            --init \
            openscad/openscad:2021.01 xvfb-run -a openscad /dev/null -D "\$vpr = [60, 0, ${angle}];" -D 'import("/input/foo-centered.stl");' -o "/output/bar${angle}.png" --imgsize=600,600 --autocenter --viewall --quiet
    done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment