How to convert STL to rotating GIF using OpenSCAD? - openscad

Given an STL file, how can you convert it to an animated gif using the command line (bash)?
I've discovered a few articles that vaguely describe how to do this through the GUI. I've been able to generate the following, however the animation is very rough and the shadows jump around.
for ((angle=0; angle <=360; angle+=5)); do
openscad /dev/null -o dump$angle.png -D "cube([2,3,4]);" --imgsize=250,250 --camera=0,0,0,45,0,$angle,25
done
# https://unix.stackexchange.com/a/489210/39263
ffmpeg \
-framerate 24 \
-pattern_type glob \
-i 'dump*.png' \
-r 8 \
-vf scale=512:-1 \
out.gif \
;
OpenScad has a built in --animation X parameter, however using that likely won't work when passing in the camera angle as a parameter.
Resources
https://github.com/openscad/openscad/issues/1632#issuecomment-219203658
https://blog.prusaprinters.org/how-to-animate-models-in-openscad_29523/
https://github.com/openscad/openscad/issues/1573
https://github.com/openscad/openscad/pull/1808
https://forum.openscad.org/Product-Video-produced-with-OpenSCAD-td15783.html

Bash + Docker
Converting an STL to a GIF requires several steps
Center the STL at the origin
Convert the STL into a collection of .PNG files from different angles
Combine those PNG files into a .gif file
Assuming you have docker installed you can run the the following to convert an STL into an animated GIF
(Note: A more up to date version of this script is available at spuder/CAD-scripts/stl2gif
This depends on 3 docker containers
spuder/stl2origin
openscad/openscad:2021.01
linuxserver/ffmpeg:version-4.4-cli
# 1. Use spuder/stl2origin:latest docker container to center the file at origin
# A file with the offsets will be saved to `${MYTMPDIR}/foo.sh`
file=/tmp/foo.stl
MYTMPDIR="$(mktemp -d)"
trap 'rm -rf -- "$MYTMPDIR"' EXIT
docker run \
-e OUTPUT_BASH_FILE=/output/foo.sh \
-v $(dirname "$file"):/input \
-v $MYTMPDIR:/output \
--rm spuder/stl2origin:latest \
"/input/$(basename "$file")"
cp "${file}" "$MYTMPDIR/foo.stl"
# 2. Read ${MYTMPDIR}/foo.sh and load the offset variables ($XTRANS, $XMID,$YTRANS,$YMID,$ZTRANS,$ZMID)
# Save the new centered STL to `$MYTMPDIR/foo-centered.stl`
source $MYTMPDIR/foo.sh
docker run \
-v "$MYTMPDIR:/input" \
-v "$MYTMPDIR:/output" \
openscad/openscad:2021.01 openscad /dev/null -D "translate([$XTRANS-$XMID,$YTRANS-$YMID,$ZTRANS-$ZMID])import(\"/input/foo.stl\");" -o "/output/foo-centered.stl"
# 3. Convert the STL into 60 .PNG images with the camera rotating around the object. Note `$t` is a built in openscad variable that is automatically set based on time when --animate option is used
# OSX users will need to replace `openscad` with `/Applications/OpenSCAD.app/Contents/MacOS/OpenSCAD`
# Save all images to $MYTMPDIR/foo{0..60}.png
# This is not yet running in a docker container due to a bug: https://github.com/openscad/openscad/issues/4028
openscad /dev/null \
-D '$vpr = [60, 0, 360 * $t];' \
-o "${MYTMPDIR}/foo.png" \
-D "import(\"${MYTMPDIR}/foo-centered.stl\");" \
--imgsize=600,600 \
--animate 60 \
--colorscheme "Tomorrow Night" \
--viewall --autocenter
# 4. Use ffmpeg to combine all images into a .GIF file
# Tune framerate (15) and -r (60) to produce a faster/slower/smoother image
yes | ffmpeg \
-framerate 15 \
-pattern_type glob \
-i "$MYTMPDIR/*.png" \
-r 60 \
-vf scale=512:-1 \
"${file}.gif" \
;
rm -rf -- "$MYTMPDIR"
STL File
Gif without centering
Gif with centering

Related

How to convert Org mode file to ODT using a template and Pandoc?

I have a file plan.org with following contents:
* Hello!
This is a test.
I want to convert it to LibreOffice (ODT) format using Pandoc so that it is formatted according to a template draft.ott or draft-template.odt both of which are available here.
When I run
cat plan.org | \
pandoc -f org \
-t odt \
--template=draft-template.odt \
--log=plan.odt.log \
--fail-if-warnings \
-o plan.odt
I get the error
pandoc: Cannot decode byte '\xc6': Data.Text.Internal.Encoding.decodeUtf8: Invalid UTF-8 stream
The call
cat plan.org | \
pandoc -f org \
-t odt \
--reference-doc=draft-template.odt \
--log=plan.odt.log \
--fail-if-warnings \
-o plan.odt
does not generate any errors, but the resulting document plan.odt is not formatted according to draft-template.odt.
Same problem with
cat plan.org | \
pandoc -f org \
-t odt \
--reference-doc=draft.ott \
--log=plan.odt.log \
--fail-if-warnings \
-o plan.odt
How can I make sure that the resulting file plan.odt is using the fonts specified in draft.ott or draft-template.odt?
I am using pandoc 2.11.3.1, compiled with pandoc-types 1.22, texmath 0.12.0.3, skylighting 0.10.2, citeproc 0.3.0.1, ipynb 0.1.0.1 under MacOS BigSur 11.1.
Update 1: Adding
#+ODT_STYLES_FILE: "draft-template.odt" or
#+ODT_STYLES_FILE: "draft.ott"
to plan.org did not solve the problem.
Update 2: I tried exporting the default template using pandoc -D odt > template.odt, then replacing Courier New with Courier Prime in template.odt and then generating the ODT file using
pandoc plan.org \
-f org \
-t odt \
--standalone \
--template=template.odt \
--log=plan.odt.log \
--fail-if-warnings \
-o plan.odt
Still no luck.
Update 3: file plan.org returns
plan.org: ASCII text
Update 4: The call
iconv -t utf-8 plan.org | \
pandoc plan.org \
-f org \
-t odt \
--standalone \
--template=template.odt \
--log=plan.odt.log \
--fail-if-warnings \
-o plan.odt
did not work (plan.odt does not have the formatting from template.odt).
Following
https://pandoc.org/MANUAL.html#character-encoding
try
iconv -t utf-8 plan.org | pandoc | iconv -f utf-8
(Sorry not to answer this question in a comment. I do not have 50 points)

Build all packages for an image

Is it possible to build all of the packages for a specific image? I know I can build packages individually, but ideally would like to build all of them at once, through a single command.
Alternatively, is there a way to prevent the do_rootfs task from being executed for a particular image.
Cheers, Donal
First make an image that contains a packagegroup (or just list your dependencies there).
$ cat sources/meta-custom/recipes-custom/images/only-packages-image.bb
SUMMARY = "All dependencies no image"
LICENSE = "CLOSED"
version = "##DISTRO_VERSION##"
BB_SCHEDULER = "speed"
# option 1 - packagegroup, package list can be reused in real image
CORE_IMAGE_BASE_INSTALL += "\
packagegroup_all-depends \
"
# option 2 - list deps here, package list can not be reused in real image
CORE_IMAGE_BASE_INSTALL += "\
lshw \
systemd \
cronie \
glibc \
sqlite \
bash \
python3-dev \
python3-2to3 \
python3-misc \
python3-pyvenv \
python3-modules \
python3-pip \
wget \
apt \
pciutils \
file \
tree \
\
wpa-supplicant \
dhcpcd \
networkmanager \
curl-dev \
curl \
hostapd \
iw \
"
# remove the rootfs step
do_rootfs() {
}
Second make your packagegroup if you opted to reuse the list of packages
$ cat sources/meta-custom/recipes-custom/packagegroups/packagegroup-alldeps.bb
PACKAGE_ARCH = "${MACHINE_ARCH}"
inherit packagegroup
RDEPENDS_${PN} = " \
lshw \
systemd \
cronie \
glibc \
sqlite \
bash \
python3-dev \
python3-2to3 \
python3-misc \
python3-pyvenv \
python3-modules \
python3-pip \
wget \
apt \
pciutils \
file \
tree \
\
wpa-supplicant \
dhcpcd \
networkmanager \
curl-dev \
curl \
hostapd \
iw \
"
Finally build your new image placeholder
$ bitbake only-packages-image
In Yocto >=4.0 this is actually pretty easy to achieve. The packagegroup method did not work for me at all.
I don't know if this works in older versions though.
Create a new file in your custom layer, e.g. meta-custom/classes/norootfs.bbclass and put the following lines in there (as far as I noticed the order does not matter):
deltask do_deploy
deltask do_image
deltask do_rootfs
deltask do_image_complete
deltask do_image_setscene
then in your meta-custom/recipes-core/images/myimage.bb add norootfs to your other inherit commands
e.g. the most basic one
inherit core-image norootfs
You will notice your number of tasks decreasing by a fair amount (mine from ~4700 to ~3000) and there is no complete rootfs image anymore in build/tmp/deploy/images, except for bzImage and modules, just the plain ipk files in build/tmp/deploy/ipk.
I got this information by looking at https://docs.yoctoproject.org/ref-manual/tasks.html?highlight=do_image and .bbclass files in meta/classes where deltask is frequently used.

Progress of simulations in headless mode

Is there any way to check the progress of simulations in headless mode as opposed to gui?
Basic Code:
$ ~/netlogo-5.1.0/netlogo-headless.sh \
--model ~/myproject/MyModel.nlogo \
--experiment MyExperiment \
--table ~/myproject/MyNewOutputData.csv
I'd suggest doing tail -f ~/myproject/MyNewOutputData.csv. This will show you a live view of the output file as it is being written to.

wget not saving images while --page-requisites is on

I try to save images from a site using wget. I have --page-requisites in the command line but it doesn't save the images. For the rest everything goes so fine, it even saves the extension.
wget \
--recursive \
--no-clobber \
--page-requisites \
--html-extension \
--convert-links \
--restrict-file-names=windows \
http://leveldesigninspirationmachine.tumblr.com/
Why doesn't it get the images?

GRUB2 + VESA BIOS Extensions / VBE broken?

Whereas I did get my earlier problem with building proper boot images fixed, I've been struggling with another GRUB2-related problem for most of the day.
The problem is that even though I do set the video info request bit in my multiboot header, GRUB2 does not return proper VESA BIOS Extensions (VBE) info.
The kernel is my own work, and it's noteworthy that it Used to Work (TM) with some earlier version of GRUB2 (I could fill the screen with white pixels, no problem).
Here's my current grub.cfg:
set timeout=10
set default=0
menuentry "zero" {
set gfxmode=1024x768x24
set gfxpayload=keep
insmod vbe
insmod gfxterm
multiboot /kern
}
And here's the script I use to build my boot images:
echo Building kernel
./build.sh
echo Creating bootable CD image...
cp zero cdimg2/kern
grub-mkimage --format=i386-pc --output=core.img \
--config="cdimg2/boot/grub/grub.cfg" loadenv biosdisk \
part_msdos part_gpt fat ntfs \
ext2 ntfscomp iso9660 loopback search linux boot \
minicmd cat cpuid chain \
halt help ls reboot echo test configfile normal sleep \
memdisk tar font \
gfxterm gettext true vbe vga video_bochs video_cirrus \
multiboot multiboot2
cat /usr/lib/grub/i386-pc/cdboot.img core.img > \
cdimg2/grub.img
genisoimage -A "ZERO" -input-charset "iso8859-1" -R -b \
grub.img -no-emul-boot \
-boot-load-size 4 -boot-info-table -o cd.iso cdimg2