From 69fd075acc764e70acb8287cd57ce4d695a11887 Mon Sep 17 00:00:00 2001 From: Simon Brooke Date: Sun, 24 May 2020 09:50:23 +0100 Subject: [PATCH] Switched from dali to hiccup for rendering SVG, because performance --- .gitignore | 2 ++ project.clj | 1 + src/walkmap/core.clj | 17 +++++++++-------- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 5675e55..52ff58a 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,8 @@ pom.xml pom.xml.asc *.jar *.class +*.stl +*.svg /.lein-* /.nrepl-port .hgignore diff --git a/project.clj b/project.clj index 0c89cae..cac934e 100644 --- a/project.clj +++ b/project.clj @@ -8,6 +8,7 @@ [org.clojure/math.numeric-tower "0.0.4"] [com.taoensso/timbre "4.10.0"] [dali "0.7.4"] + [hiccup "1.0.5"] [me.raynes/fs "1.4.6"] [smee/binary "0.5.5"]] :description "A Clojure library designed to assist in computing walkmaps for games." diff --git a/src/walkmap/core.clj b/src/walkmap/core.clj index 97c9cb8..4ce52f4 100644 --- a/src/walkmap/core.clj +++ b/src/walkmap/core.clj @@ -3,7 +3,7 @@ (STL) files. Not a stable API yet!" (:require [clojure.java.io :as io :refer [file output-stream input-stream]] [clojure.string :as s] - [dali.io :as svg] + [hiccup.core :refer [html]] [me.raynes.fs :as fs] [org.clojars.smee.binary.core :as b] [taoensso.timbre :as l :refer [info error spy]]) @@ -102,10 +102,8 @@ (defn- facet-to-svg-poly [facet] - (vec - (cons - :polygon - (map #(vec (list (:x %) (:y %))) (:vertices facet))))) + [:polygon + {:points (s/join " " (map #(str (:x %) "," (:y %)) (:vertices facet)))}]) (defn stl-to-svg "Convert this in-memory `stl` structure, as read by `decode-binary-stl`, into @@ -131,8 +129,10 @@ (map #(reduce max (map :y (:vertices %))) (:facets stl)))] - [:dali/page - {:width (- maxx minx) + [:svg + {:xmlns "http://www.w3.org/2000/svg" + :version "1.2" + :width (- maxx minx) :height (- maxy miny) :viewBox (s/join " " (map str [minx miny maxx maxy]))} (vec @@ -150,7 +150,8 @@ (stl-to-svg (decode-binary-stl in-filename))) ([in-filename out-filename] (let [s (binary-stl-file-to-svg in-filename)] - (svg/render-svg s out-filename) + ;; (svg/render-svg s out-filename) + (spit out-filename (html s)) s))) ;; (def stl (decode-binary-stl "resources/small_hill.stl"))