diff options
Diffstat (limited to 'src/Wavefront')
-rw-r--r-- | src/Wavefront/Lex.hs | 20 | ||||
-rw-r--r-- | src/Wavefront/Types.hs | 24 |
2 files changed, 35 insertions, 9 deletions
diff --git a/src/Wavefront/Lex.hs b/src/Wavefront/Lex.hs index f4cb54a..811553a 100644 --- a/src/Wavefront/Lex.hs +++ b/src/Wavefront/Lex.hs | |||
@@ -38,7 +38,7 @@ data ObjBuilder m = ObjBuilder | |||
38 | , trim :: [CurveSpec] -> m () | 38 | , trim :: [CurveSpec] -> m () |
39 | , hole :: [CurveSpec] -> m () | 39 | , hole :: [CurveSpec] -> m () |
40 | , specialCurves :: [CurveSpec] -> m () | 40 | , specialCurves :: [CurveSpec] -> m () |
41 | , equivalentCurves :: [EmbeddedCurve] -> m () | 41 | , equivalentCurves :: [EmbeddedCurveRef] -> m () |
42 | , groups :: [S.ByteString] -> m () | 42 | , groups :: [S.ByteString] -> m () |
43 | , smoothingGroup :: Int -> m () | 43 | , smoothingGroup :: Int -> m () |
44 | , mergingGroup :: Int -> Double -> m () | 44 | , mergingGroup :: Int -> Double -> m () |
@@ -188,7 +188,7 @@ echoBuilder = ObjBuilder | |||
188 | , trim = \ss -> echo $ unwords ("trim":concatMap (\(CurveSpec s e r) -> [show s,show e,show r]) ss) | 188 | , trim = \ss -> echo $ unwords ("trim":concatMap (\(CurveSpec s e r) -> [show s,show e,show r]) ss) |
189 | , hole = \ss -> echo $ unwords ("hole":concatMap (\(CurveSpec s e r) -> [show s,show e,show r]) ss) | 189 | , hole = \ss -> echo $ unwords ("hole":concatMap (\(CurveSpec s e r) -> [show s,show e,show r]) ss) |
190 | , specialCurves = \ss -> echo $ unwords ("scrv":concatMap (\(CurveSpec s e r) -> [show s,show e,show r]) ss) | 190 | , specialCurves = \ss -> echo $ unwords ("scrv":concatMap (\(CurveSpec s e r) -> [show s,show e,show r]) ss) |
191 | , equivalentCurves = \ccs -> echo $ unwords ("con":map showEmbeddedCurve ccs) | 191 | , equivalentCurves = \ccs -> echo $ unwords ("con":map showEmbeddedCurveRef ccs) |
192 | , groups = \gs -> echo $ unwords $ "g":map unpackUtf8 gs | 192 | , groups = \gs -> echo $ unwords $ "g":map unpackUtf8 gs |
193 | , smoothingGroup = \sg -> echo ("s " ++ show sg) | 193 | , smoothingGroup = \sg -> echo ("s " ++ show sg) |
194 | , mergingGroup = \mg δ -> echo $ unwords ["mg",show mg,show δ] | 194 | , mergingGroup = \mg δ -> echo $ unwords ["mg",show mg,show δ] |
@@ -264,6 +264,8 @@ newtype ObjConfig = ObjConfig | |||
264 | { cfgSubst :: IntMap L.ByteString | 264 | { cfgSubst :: IntMap L.ByteString |
265 | } | 265 | } |
266 | 266 | ||
267 | defaultConfig = ObjConfig IntMap.empty | ||
268 | |||
267 | -- consChunk :: S.ByteString -> L.ByteString -> L.ByteString | 269 | -- consChunk :: S.ByteString -> L.ByteString -> L.ByteString |
268 | -- consChunk c bs = L.fromChunks (c : L.toChunks bs) | 270 | -- consChunk c bs = L.fromChunks (c : L.toChunks bs) |
269 | 271 | ||
@@ -430,11 +432,11 @@ parseCurveSpecsN n tok bs cont = parseFloatsN 2 tok bs $ \fs bs' -> case fs of | |||
430 | 432 | ||
431 | _ -> cont [] bs' | 433 | _ -> cont [] bs' |
432 | 434 | ||
433 | parseEmbeddedCurves :: (L.ByteString -> L.ByteString) -> L.ByteString -> ([EmbeddedCurve] -> L.ByteString -> b) -> b | 435 | parseEmbeddedCurveRefs :: (L.ByteString -> L.ByteString) -> L.ByteString -> ([EmbeddedCurveRef] -> L.ByteString -> b) -> b |
434 | parseEmbeddedCurves tok bs cont = parseIntsN 1 tok bs $ \is bs' -> case is of | 436 | parseEmbeddedCurveRefs tok bs cont = parseIntsN 1 tok bs $ \is bs' -> case is of |
435 | (sref:_) -> do | 437 | (sref:_) -> do |
436 | parseCurveSpecsN 1 tok bs' $ \cs bs'' -> case cs of | 438 | parseCurveSpecsN 1 tok bs' $ \cs bs'' -> case cs of |
437 | (c:_) -> parseEmbeddedCurves tok bs'' $ cont . (EmbeddedCurve sref c :) | 439 | (c:_) -> parseEmbeddedCurveRefs tok bs'' $ cont . (EmbeddedCurveRef sref c :) |
438 | _ -> cont [] bs'' | 440 | _ -> cont [] bs'' |
439 | 441 | ||
440 | _ -> cont [] bs' | 442 | _ -> cont [] bs' |
@@ -472,14 +474,14 @@ data CurveSpec = CurveSpec | |||
472 | } | 474 | } |
473 | deriving (Eq,Ord,Show) | 475 | deriving (Eq,Ord,Show) |
474 | 476 | ||
475 | data EmbeddedCurve = EmbeddedCurve | 477 | data EmbeddedCurveRef = EmbeddedCurveRef |
476 | { curveSurfaceRef :: Int | 478 | { curveSurfaceRef :: Int |
477 | , embeddedCurve :: CurveSpec | 479 | , embeddedCurve :: CurveSpec |
478 | } | 480 | } |
479 | deriving (Eq,Ord,Show) | 481 | deriving (Eq,Ord,Show) |
480 | 482 | ||
481 | showEmbeddedCurve :: EmbeddedCurve -> String | 483 | showEmbeddedCurveRef :: EmbeddedCurveRef -> String |
482 | showEmbeddedCurve (EmbeddedCurve s c) = unwords | 484 | showEmbeddedCurveRef (EmbeddedCurveRef s c) = unwords |
483 | [ show s | 485 | [ show s |
484 | , show (curveStart c) | 486 | , show (curveStart c) |
485 | , show (curveEnd c) | 487 | , show (curveEnd c) |
@@ -560,7 +562,7 @@ parseOBJ builder args bs0 | |||
560 | then parseI deprecated_cdc 4 -- cdc | 562 | then parseI deprecated_cdc 4 -- cdc |
561 | else parseI deprecated_cdp 4 -- cdp | 563 | else parseI deprecated_cdp 4 -- cdp |
562 | "co" -> -- con | 564 | "co" -> -- con |
563 | parseEmbeddedCurves (findToken args) (next 2 bs) $ \ss bs' -> do | 565 | parseEmbeddedCurveRefs (findToken args) (next 2 bs) $ \ss bs' -> do |
564 | equivalentCurves builder ss | 566 | equivalentCurves builder ss |
565 | parseOBJ builder args bs' | 567 | parseOBJ builder args bs' |
566 | "cs" -> if lengthLessThan 3 bs | 568 | "cs" -> if lengthLessThan 3 bs |
diff --git a/src/Wavefront/Types.hs b/src/Wavefront/Types.hs index 99bbb15..2ab48ba 100644 --- a/src/Wavefront/Types.hs +++ b/src/Wavefront/Types.hs | |||
@@ -18,9 +18,12 @@ data OBJ v = OBJ { | |||
18 | objLocations :: v Location | 18 | objLocations :: v Location |
19 | , objTexCoords :: v TexCoord | 19 | , objTexCoords :: v TexCoord |
20 | , objNormals :: v Normal | 20 | , objNormals :: v Normal |
21 | , objEmbeddedCurves :: v EmbeddedCurve | ||
21 | , objPoints :: v (Element Point) | 22 | , objPoints :: v (Element Point) |
22 | , objLines :: v (Element Line) | 23 | , objLines :: v (Element Line) |
23 | , objFaces :: v (Element Face) | 24 | , objFaces :: v (Element Face) |
25 | , objCurves :: v (Element Curve) | ||
26 | , objSurfaces :: v (Element Surface) | ||
24 | , objMtlLibs :: v Text | 27 | , objMtlLibs :: v Text |
25 | } | 28 | } |
26 | 29 | ||
@@ -28,18 +31,24 @@ type ForThisOBJ (c :: * -> Constraint) v = | |||
28 | ( c (v Location) | 31 | ( c (v Location) |
29 | , c (v TexCoord) | 32 | , c (v TexCoord) |
30 | , c (v Normal) | 33 | , c (v Normal) |
34 | , c (v EmbeddedCurve) | ||
31 | , c (v (Element Point)) | 35 | , c (v (Element Point)) |
32 | , c (v (Element Line)) | 36 | , c (v (Element Line)) |
33 | , c (v (Element Face)) | 37 | , c (v (Element Face)) |
38 | , c (v (Element Curve)) | ||
39 | , c (v (Element Surface)) | ||
34 | , c (v Text) ) | 40 | , c (v Text) ) |
35 | 41 | ||
36 | type ForAllOBJ (c :: * -> Constraint) = | 42 | type ForAllOBJ (c :: * -> Constraint) = |
37 | ( c Location | 43 | ( c Location |
38 | , c TexCoord | 44 | , c TexCoord |
39 | , c Normal | 45 | , c Normal |
46 | , c EmbeddedCurve | ||
40 | , c (Element Point) | 47 | , c (Element Point) |
41 | , c (Element Line) | 48 | , c (Element Line) |
42 | , c (Element Face) | 49 | , c (Element Face) |
50 | , c (Element Curve) | ||
51 | , c (Element Surface) | ||
43 | , c Text | 52 | , c Text |
44 | ) | 53 | ) |
45 | 54 | ||
@@ -51,9 +60,12 @@ instance Rank2.Functor OBJ where | |||
51 | { objLocations = f (objLocations obj) | 60 | { objLocations = f (objLocations obj) |
52 | , objTexCoords = f (objTexCoords obj) | 61 | , objTexCoords = f (objTexCoords obj) |
53 | , objNormals = f (objNormals obj) | 62 | , objNormals = f (objNormals obj) |
63 | , objEmbeddedCurves = f (objEmbeddedCurves obj) | ||
54 | , objPoints = f (objPoints obj) | 64 | , objPoints = f (objPoints obj) |
55 | , objLines = f (objLines obj) | 65 | , objLines = f (objLines obj) |
56 | , objFaces = f (objFaces obj) | 66 | , objFaces = f (objFaces obj) |
67 | , objCurves = f (objCurves obj) | ||
68 | , objSurfaces = f (objSurfaces obj) | ||
57 | , objMtlLibs = f (objMtlLibs obj) | 69 | , objMtlLibs = f (objMtlLibs obj) |
58 | } | 70 | } |
59 | 71 | ||
@@ -65,9 +77,12 @@ instance ForAllOBJ c => Payload c OBJ where | |||
65 | { objLocations = f (objLocations obj) | 77 | { objLocations = f (objLocations obj) |
66 | , objTexCoords = f (objTexCoords obj) | 78 | , objTexCoords = f (objTexCoords obj) |
67 | , objNormals = f (objNormals obj) | 79 | , objNormals = f (objNormals obj) |
80 | , objEmbeddedCurves = f (objEmbeddedCurves obj) | ||
68 | , objPoints = f (objPoints obj) | 81 | , objPoints = f (objPoints obj) |
69 | , objLines = f (objLines obj) | 82 | , objLines = f (objLines obj) |
70 | , objFaces = f (objFaces obj) | 83 | , objFaces = f (objFaces obj) |
84 | , objCurves = f (objCurves obj) | ||
85 | , objSurfaces = f (objSurfaces obj) | ||
71 | , objMtlLibs = f (objMtlLibs obj) | 86 | , objMtlLibs = f (objMtlLibs obj) |
72 | } | 87 | } |
73 | 88 | ||
@@ -111,6 +126,15 @@ data Normal = Normal { | |||
111 | , norZ :: {-# UNPACK #-} !Float | 126 | , norZ :: {-# UNPACK #-} !Float |
112 | } deriving (Eq,Ord,Show) | 127 | } deriving (Eq,Ord,Show) |
113 | 128 | ||
129 | data EmbeddedCurve = EmbeddedCurve | ||
130 | deriving (Eq,Ord,Show) | ||
131 | |||
132 | data Curve = Curve | ||
133 | deriving (Eq,Ord,Show) | ||
134 | |||
135 | data Surface = Surface | ||
136 | deriving (Eq,Ord,Show) | ||
137 | |||
114 | -- | A point is a single index that references the locations. It’s a canonical | 138 | -- | A point is a single index that references the locations. It’s a canonical |
115 | -- type that truly represents a polygonal point. | 139 | -- type that truly represents a polygonal point. |
116 | data Point = Point { | 140 | data Point = Point { |