import Data.Attoparsec.Text
import qualified Data.Text as T
data IndexedFace
-- | block of faces-lines
faces
:: Parser
[[(Int, IndexedFace
)]]faces = faceLine `sepBy` endOfLine
-- | Line containing up to two indexed faces
faceLine
:: Parser
[(Int, IndexedFace
)]faceLine
= face `sepBy`
(take 6)
-- | single indexed-face
face
:: Parser
(Int, IndexedFace
)face = do
i <- index
v1 <- index
v2 <- index
v3 <- index
v4 <- index
case v4 of
0 -> return (i
, IndexedFaceTriangle v1 v2 v3
) _ -> return (i
, IndexedFaceQuad v1 v2 v3 v4
)
-- | node or face index 6 wide
index = do
test1 = do
let ele = T.pack " 1 10 1 9 0 2 1 2 9 0\n"
r = parse faceLine ele
case r of
Partial
_ -> print $ feed r
(T
.pack
"")
test2 = do
let eles
= T
.pack
$ concat [" 1 10 1 9 0 2 1 2 9 0\n" ," 3 11 9 2 0\n"
," 4 12 8 1 0\n"
]
r = parse faces eles
case r of
Partial
_ -> print $ feed r
(T
.pack
"")
test3 = do
let eles
= T
.pack
$ concat [" 1 10 1 9 0 2 1 2 9 0\n" ," 3 11 9 2 0\n"
," 4 12 8 1 0\n"
]
r = parse faces eles
case r of
Partial
_ -> print $ feed r
(T
.pack
"")
test4 = do
let eles
= T
.pack
$ concat [" 1 10 1 9 0 2 1 2 9 0\n" ," 3 11 9 2 0\n"
," 4 12 8 1 0\n"
]
r = parse faces eles
case r of
Partial
_ -> print $ feed r
(T
.pack
"")
test5 = do
let eles
= T
.pack
$ concat [" 1 10 1 9 0 2 1 2 9 0\n" ," 3 11 9 2 0 4 12 8 1 0\n"
]
r = parse faces eles
case r of
Partial
_ -> print $ feed r
(T
.pack
"")
aW1wb3J0ICAgICAgICAgICBEYXRhLkF0dG9wYXJzZWMuVGV4dAppbXBvcnQgcXVhbGlmaWVkIERhdGEuVGV4dCBhcyBUCmltcG9ydCBQcmVsdWRlIGhpZGluZyAodGFrZVdoaWxlLCB0YWtlKQoKZGF0YSBJbmRleGVkRmFjZQogICAgICAgID0gSW5kZXhl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gICAgMFxuIgogICAgICAgICAgciAgICA9ICBwYXJzZSBmYWNlTGluZSBlbGUKICAgICAgY2FzZSByIG9mCiAgICAgICAgICAgUGFydGlhbCBfIC0+IHByaW50ICQgZmVlZCByIChULnBhY2sgIiIpCiAgICAgICAgICAgXyAgICAgICAgIC0+IHByaW50IHIKCnRlc3QyID0gZG8KICAgICAgbGV0IGVsZXMgPSBULnBhY2sgJCBjb25jYXQgWyIgICAgIDEgICAgMTAgICAgIDEgICAgIDkgICAgIDAgICAgICAgMiAgICAgMSAgICAgMiAgICAgOSAgICAgMFxuIgogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAsIiAgICAgMyAgICAxMSAgICAgOSAgICAgMiAgICAgMFxuIgogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAsIiAgICAgNCAgICAxMiAgICAgOCAgICAgMSAgICAgMFxuIgogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBdCiAgICAgICAgICByICAgID0gIHBhcnNlIGZhY2VzIGVsZXMKICAgICAgY2FzZSByIG9mCiAgICAgICAgICAgUGFydGlhbCBfIC0+IHByaW50ICQgZmVlZCByIChULnBhY2sgIiIpCiAgICAgICAgICAgXyAgICAgICAgIC0+IHByaW50IHIKCnRlc3QzID0gZG8KICAgICAgbGV0IGVsZXMgPSBULnBhY2sgJCBjb25jYXQgWyIgICAgIDEgICAgMTAgICAgIDEgICAgIDkgICAgIDAgICAgICAgMiAgICAgMSAgICAgMiAgICAgOSAgICAgMFxuIgogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAsIiAgICAgMyAgICAxMSAgICAgOSAgICAgMiAgICAgMFxuIgogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAsIiAgICAgNCAgICAxMiAgICAgOCAgICAgMSAgICAgMFxuIgogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBdCiAgICAgICAgICByICAgID0gIHBhcnNlIGZhY2VzIGVsZXMKICAgICAgY2FzZSByIG9mCiAgICAgICAgICAgUGFydGlhbCBfIC0+IHByaW50ICQgZmVlZCByIChULnBhY2sgIiIpCiAgICAgICAgICAgXyAgICAgICAgIC0+IHByaW50IHIKCgoKdGVzdDQgPSBkbwogICAgICBsZXQgZWxlcyA9IFQucGFjayAkIGNvbmNhdCBbIiAgICAgMSAgICAxMCAgICAgMSAgICAgOSAgICAgMCAgICAgICAyICAgICAxICAgICAyICAgICA5ICAgICAwXG4iCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICwiICAgICAzICAgIDExICAgICA5ICAgICAyICAgICAwXG4iCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICwiICAgICA0ICAgIDEyICAgICA4ICAgICAxICAgICAwXG4iCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIF0KICAgICAgICAgIHIgICAgPSAgcGFyc2UgZmFjZXMgZWxlcwogICAgICBjYXNlIHIgb2YKICAgICAgICAgICBQYXJ0aWFsIF8gLT4gcHJpbnQgJCBmZWVkIHIgKFQucGFjayAiIikKICAgICAgICAgICBfICAgICAgICAgLT4gcHJpbnQgcgoKCnRlc3Q1ID0gZG8KICAgICAgbGV0IGVsZXMgPSBULnBhY2sgJCBjb25jYXQgWyIgICAgIDEgICAgMTAgICAgIDEgICAgIDkgICAgIDAgICAgICAgMiAgICAgMSAgICAgMiAgICAgOSAgICAgMFxuIgogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAsIiAgICAgMyAgICAxMSAgICAgOSAgICAgMiAgICAgMCAgICAgICA0ICAgIDEyICAgICA4ICAgICAxICAgICAwXG4iCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIF0KICAgICAgICAgIHIgICAgPSAgcGFyc2UgZmFjZXMgZWxlcwogICAgICBjYXNlIHIgb2YKICAgICAgICAgICBQYXJ0aWFsIF8gLT4gcHJpbnQgJCBmZWVkIHIgKFQucGFjayAiIikKICAgICAgICAgICBfICAgICAgICAgLT4gcHJpbnQgcg==