Permalink
Browse files

Update STL output.

  • Loading branch information...
1 parent ed3e934 commit ef3f51e1952d62583ada02cb2e4503543c13d204 @matthewSorensen committed Aug 24, 2012
Showing with 24 additions and 19 deletions.
  1. +4 −4 Graphics/Implicit/Export/PolylineFormats.hs
  2. +20 −15 Graphics/Implicit/Export/TriangleMeshFormats.hs
View
8 Graphics/Implicit/Export/PolylineFormats.hs
@@ -31,15 +31,15 @@ svg = renderSvg . svg11 . svg'
-- and we need to compute the requisite translation.
svg' [] = mempty
-- When we have a known point, we can compute said transformation:
- svg' polylines@((start:_):_) = let mm = foldl' (foldl' minmax) start polylines
- in thinBlueGroup $ mapM_ (poly mm) polylines
+ svg' polylines@((start:_):_) = let (xmin, ymax) = foldl' (foldl' minmax) start polylines
+ in thinBlueGroup $ mapM_ (poly xmin ymax) polylines
-- Otherwise, if we don't have a point to start out with, skip this polyline:
svg' ([]:rest) = svg' rest
minmax (xa,ya) (xb,yb) = (min xa xb, max ya yb)
- poly (minx,maxy) line = polyline ! A.points pointList
- where pointList = toValue $ unwords [pack $ show (x-minx) ++ "," ++ show (maxy - y) | (x,y) <- line]
+ poly xmin ymax line = polyline ! A.points pointList
+ where pointList = toValue $ unwords [pack $ show (x-xmin) ++ "," ++ show (ymax - y) | (x,y) <- line]
-- Instead of setting styles on every polyline, we wrap the lines in a group element and set the styles on it:
thinBlueGroup = g ! A.stroke "rgb(0,0,255)" ! A.strokeWidth "1" ! A.fill "none" -- $ obj
View
35 Graphics/Implicit/Export/TriangleMeshFormats.hs
@@ -1,3 +1,5 @@
+{-# LANGUAGE OverloadedStrings #-}
+
-- Implicit CAD. Copyright (C) 2011, Christopher Olah (chris@colah.ca)
-- Released under the GNU GPL, see LICENSE
@@ -7,24 +9,27 @@ import Graphics.Implicit.Definitions
import Data.Text.Lazy (Text,pack)
-stl triangles = pack text
+import Data.Text.Lazy.Builder
+
+import Data.Monoid
+
+stl triangles = toLazyText $ stlHeader <> mconcat (map triangle triangles) <> stlFooter
where
stlHeader = "solid ImplictCADExport\n"
stlFooter = "endsolid ImplictCADExport\n"
- vertex :: ℝ3 -> String
- vertex (x,y,z) = "vertex " ++ show x ++ " " ++ show y ++ " " ++ show z
- stlTriangle :: (ℝ3, ℝ3, ℝ3) -> String
- stlTriangle (a,b,c) =
- "facet normal 0 0 0\n"
- ++ "outer loop\n"
- ++ vertex a ++ "\n"
- ++ vertex b ++ "\n"
- ++ vertex c ++ "\n"
- ++ "endloop\n"
- ++ "endfacet\n"
- text = stlHeader
- ++ (concat $ map stlTriangle triangles)
- ++ stlFooter
+ vertex :: ℝ3 -> Builder
+ vertex (x,y,z) = mconcat ["vertex "
+ ,fromString $ show x , " "
+ ,fromString $ show y , " "
+ ,fromString $ show z]
+ triangle :: (ℝ3, ℝ3, ℝ3) -> Builder
+ triangle (a,b,c) =
+ "facet normal 0 0 0\n"
+ <> "outer loop\n"
+ <> vertex a <> "\n"
+ <> vertex b <> "\n"
+ <> vertex c
+ <> "\nendloop\nendfacet\n"
jsTHREE :: TriangleMesh -> Text

0 comments on commit ef3f51e

Please sign in to comment.