From 5291bad4a87c76f9856b7a1bafc7f48e8bf8e19c Mon Sep 17 00:00:00 2001 From: sigurdb Date: Thu, 15 Aug 2019 18:57:32 +0200 Subject: add support for 3D files including STL and DXF --- README.md | 1 + doc/ranger.pod | 11 +++++++++++ ranger/data/scope.sh | 24 ++++++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/README.md b/README.md index bf1533a6..8134bc59 100644 --- a/README.md +++ b/README.md @@ -105,6 +105,7 @@ For enhanced file previews (with `scope.sh`): * `odt2txt` for OpenDocument text files (`odt`, `ods`, `odp` and `sxw`) * `python` or `jq` for JSON files * `fontimage` for font previews +* `openscad` for 3D model previews (`stl`, `off`, `dxf`, `scad`, `csg`) Installing ---------- diff --git a/doc/ranger.pod b/doc/ranger.pod index 911b6480..33b16b92 100644 --- a/doc/ranger.pod +++ b/doc/ranger.pod @@ -1974,6 +1974,17 @@ I will pick up command line options specified in this variable. A C<--style=> option specified here will override C. Similarly, C<--replace-tabs=> will override C. +=item OPENSCAD_COLORSCHEME + +Specifies the colorscheme used by I while previewing 3D models. Read +I man page for colorschemes. Ranger will default to Tomorrow Night. + +=item OPENSCAD_IMGSIZE + +Specifies the internal resolution I will use for rendering 3D models. +The image will be downscaled to fit the preview pane. This resolution will +default to "1000,1000" if no value is set. + =item XDG_CONFIG_HOME Specifies the directory for configuration files. Defaults to F<$HOME/.config>. diff --git a/ranger/data/scope.sh b/ranger/data/scope.sh index caa9475f..f2b9ff9c 100755 --- a/ranger/data/scope.sh +++ b/ranger/data/scope.sh @@ -44,6 +44,8 @@ HIGHLIGHT_TABWIDTH=${HIGHLIGHT_TABWIDTH:-8} HIGHLIGHT_STYLE=${HIGHLIGHT_STYLE:-pablo} HIGHLIGHT_OPTIONS="--replace-tabs=${HIGHLIGHT_TABWIDTH} --style=${HIGHLIGHT_STYLE} ${HIGHLIGHT_OPTIONS:-}" PYGMENTIZE_STYLE=${PYGMENTIZE_STYLE:-autumn} +OPENSCAD_IMGSIZE=${RNGR_OPENSCAD_IMGSIZE:-1000,1000} +OPENSCAD_COLORSCHEME=${RNGR_OPENSCAD_COLORSCHEME:-Tomorrow Night} handle_extension() { case "${FILE_EXTENSION_LOWER}" in @@ -95,6 +97,28 @@ handle_extension() { python -m json.tool -- "${FILE_PATH}" && exit 5 ;; + ## 3D models + ## OpenSCAD only supports png image output, and ${IMAGE_CACHE_PATH} is + ## hardcoded as jpeg. So we make a tempfile.png and just move/rename it + ## to jpg This works because image library is smart enough to handle it + stl|off|dxf) + [[ "${PV_IMAGE_ENABLED}" != 'True' ]] && exit 1 + openscad --colorscheme="${OPENSCAD_COLORSCHEME}" \ + --imgsize="${OPENSCAD_IMGSIZE/x/,}" \ + -o "/tmp/$(basename "${FILE_PATH}").png" \ + <(echo "import(\"${FILE_PATH}\");") + mv "/tmp/$(basename "${FILE_PATH}").png" "${IMAGE_CACHE_PATH}" \ + && exit 6 + ;; + scad|csg) + [[ "${PV_IMAGE_ENABLED}" != 'True' ]] && exit 1 + openscad --colorscheme="${OPENSCAD_COLORSCHEME}" \ + --imgsize="${OPENSCAD_IMGSIZE/x/,}" \ + -o "/tmp/$(basename "${FILE_PATH}").png" "${FILE_PATH}" + mv "/tmp/$(basename "${FILE_PATH}").png" "${IMAGE_CACHE_PATH}" \ + && exit 6 + ;; + ## Direct Stream Digital/Transfer (DSDIFF) dsf) mediainfo "${FILE_PATH}" && exit 5 -- cgit 1.4.1-2-gfad0 From 407ef979427579cd6fd4b1fa97fe9c5b0eb99ef0 Mon Sep 17 00:00:00 2001 From: toonn Date: Sun, 29 Dec 2019 22:07:09 +0100 Subject: Clean up 3d model previews Added more supported formats. Moved the section to `handle_image` because it generates image previews. Extracted the common functionality into a function. --- ranger/data/scope.sh | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/ranger/data/scope.sh b/ranger/data/scope.sh index f2b9ff9c..154028af 100755 --- a/ranger/data/scope.sh +++ b/ranger/data/scope.sh @@ -67,8 +67,10 @@ handle_extension() { ## PDF pdf) ## Preview as text conversion - pdftotext -l 10 -nopgbrk -q -- "${FILE_PATH}" - | fmt -w "${PV_WIDTH}" && exit 5 - mutool draw -F txt -i -- "${FILE_PATH}" 1-10 | fmt -w "${PV_WIDTH}" && exit 5 + pdftotext -l 10 -nopgbrk -q -- "${FILE_PATH}" - | \ + fmt -w "${PV_WIDTH}" && exit 5 + mutool draw -F txt -i -- "${FILE_PATH}" 1-10 | \ + fmt -w "${PV_WIDTH}" && exit 5 exiftool "${FILE_PATH}" && exit 5 exit 1;; @@ -97,28 +99,6 @@ handle_extension() { python -m json.tool -- "${FILE_PATH}" && exit 5 ;; - ## 3D models - ## OpenSCAD only supports png image output, and ${IMAGE_CACHE_PATH} is - ## hardcoded as jpeg. So we make a tempfile.png and just move/rename it - ## to jpg This works because image library is smart enough to handle it - stl|off|dxf) - [[ "${PV_IMAGE_ENABLED}" != 'True' ]] && exit 1 - openscad --colorscheme="${OPENSCAD_COLORSCHEME}" \ - --imgsize="${OPENSCAD_IMGSIZE/x/,}" \ - -o "/tmp/$(basename "${FILE_PATH}").png" \ - <(echo "import(\"${FILE_PATH}\");") - mv "/tmp/$(basename "${FILE_PATH}").png" "${IMAGE_CACHE_PATH}" \ - && exit 6 - ;; - scad|csg) - [[ "${PV_IMAGE_ENABLED}" != 'True' ]] && exit 1 - openscad --colorscheme="${OPENSCAD_COLORSCHEME}" \ - --imgsize="${OPENSCAD_IMGSIZE/x/,}" \ - -o "/tmp/$(basename "${FILE_PATH}").png" "${FILE_PATH}" - mv "/tmp/$(basename "${FILE_PATH}").png" "${IMAGE_CACHE_PATH}" \ - && exit 6 - ;; - ## Direct Stream Digital/Transfer (DSDIFF) dsf) mediainfo "${FILE_PATH}" && exit 5 @@ -247,6 +227,28 @@ handle_image() { # [ "$rar" ] || [ "$zip" ] && rm -- "${IMAGE_CACHE_PATH}" # ;; esac + + # openscad_image() { + # TMPPNG="$(mktemp -t XXXXXX.png)" + # openscad --colorscheme="${OPENSCAD_COLORSCHEME}" \ + # --imgsize="${OPENSCAD_IMGSIZE/x/,}" \ + # -o "${TMPPNG}" "${1}" + # mv "${TMPPNG}" "${IMAGE_CACHE_PATH}" + # } + + # case "${FILE_EXTENSION_LOWER}" in + # ## 3D models + # ## OpenSCAD only supports png image output, and ${IMAGE_CACHE_PATH} + # ## is hardcoded as jpeg. So we make a tempfile.png and just + # ## move/rename it to jpg. This works because image libraries are + # ## smart enough to handle it. + # csg|scad) + # openscad_image "${FILE_PATH}" && exit 6 + # ;; + # 3mf|amf|dxf|off|stl) + # openscad_image <(echo "import(\"${FILE_PATH}\");") && exit 6 + # ;; + # esac } handle_mime() { -- cgit 1.4.1-2-gfad0