<commit_before>{-# LANGUAGE RecordWildCards, ViewPatterns #-}

module Main(main) where

import Development.Shake.Command
import System.Directory
import Util
import OBJ
import Surface
import Data.Function
import Data.Maybe
import Data.List
import Control.Monad


main :: IO ()
main = do
    copyDirectory "web" "output"
    copyDirectory "data/set1" "output/models/set1"
    copyFile "data/materials.mtl" "output/models/set1/materials.mtl"
    surface <- readFileSurface "data/set1/surface.txt"
    points <- readFilePoints "data/set1/points.txt"
    writeFile "output/models/set1/set1.obj" $ unlines $ showOBJ $
        [MaterialFile "materials.mtl"] ++
        convertSurface surface ++
        concatMap convertPoints points
    () <- cmd (Cwd "output/models/set1") Shell "..\\..\\..\\bin\\objcompress set1.obj set1.utf8 > set1.js"
    writeFile "output/models/set1/responses.txt" $ unlines
        ["set1.obj","0","1"
        ,"surf","surf","set1"
        ,"1","1","1","1"
        ]
    () <- cmd (Cwd "output/models/set1") Shell "py ..\\..\\..\\bin\\part_grouping.py < responses.txt"
    () <- cmd (Cwd "output/models/set1") Shell "py ..\\..\\..\\bin\\make_viewer_metadata.py"
    writeFile "output/scripts/models.js" $ unlines
        ["o3v.MODELS = [{"
        ,"  name:'set1.obj',"
        ,"  scriptName:'set1.js',"
        ,"  modelPath:'models/set1/',"
        ,"  metadataFile:'entity_metadata.json',"
        ,"  numLayers:1"
        ,"}];"
        ]
    return ()


readFileSurface :: FilePath -> IO (Surface (Double, Double, Maybe Double))
readFileSurface file = do
    src <- readFile file
    return $ Surface.fromList [(x,y,z) | item <- lines src, let [x,y,z] = map read $ words item]

readFilePoints :: FilePath -> IO [(String, [Vertex])]
readFilePoints file = do
    src <- readFile file
    return $ map (\x -> (fst $ head x, map snd x)) $
        groupBy ((==) `on` fst) $ sortBy (compare `on` fst)
        [(s,Vertex (read x) (read y) (read z)) | item <- lines src, let [x,y,z,s] = words item]


convertPoints :: (String,[Vertex]) -> [OBJ]
convertPoints (s,xyz) =
    [Material $ "mtl" ++ s] ++
    [Face [Vertex x y z, Vertex (x+d) y z, Vertex x (y+d) z] [] | Vertex{..} <- xyz]
    where d = 0.1


convertSurface :: Surface (Double, Double, Maybe Double) -> [OBJ]
convertSurface s =
    [Material "mtlsurface",Group "surface"] ++
    collect (faces (allNormals s) s)
<commit_msg>Make the points based on spheres<commit_after>{-# LANGUAGE RecordWildCards, ViewPatterns #-}

module Main(main) where

import Development.Shake.Command
import System.Directory
import Util
import OBJ
import Surface
import Data.Function
import Data.Maybe
import Data.List
import Control.Applicative
import Control.Monad


main :: IO ()
main = do
    copyDirectory "web" "output"
    copyDirectory "data/set1" "output/models/set1"
    copyFile "data/materials.mtl" "output/models/set1/materials.mtl"
    surface <- readFileSurface "data/set1/surface.txt"
    points <- readFilePoints "data/set1/points.txt"
    sphere <- readOBJ . lines <$> readFile "data/sphere.obj"
    writeFile "output/models/set1/set1.obj" $ unlines $ showOBJ $
        [MaterialFile "materials.mtl"] ++
        convertSurface surface ++
        concatMap (convertPoints sphere) points
    () <- cmd (Cwd "output/models/set1") Shell "..\\..\\..\\bin\\objcompress set1.obj set1.utf8 > set1.js"
    writeFile "output/models/set1/responses.txt" $ unlines
        ["set1.obj","0","1"
        ,"surf","surf","set1"
        ,"1","1","1","1"
        ]
    () <- cmd (Cwd "output/models/set1") Shell "py ..\\..\\..\\bin\\part_grouping.py < responses.txt"
    () <- cmd (Cwd "output/models/set1") Shell "py ..\\..\\..\\bin\\make_viewer_metadata.py"
    writeFile "output/scripts/models.js" $ unlines
        ["o3v.MODELS = [{"
        ,"  name:'set1.obj',"
        ,"  scriptName:'set1.js',"
        ,"  modelPath:'models/set1/',"
        ,"  metadataFile:'entity_metadata.json',"
        ,"  numLayers:1"
        ,"}];"
        ]
    return ()


readFileSurface :: FilePath -> IO (Surface (Double, Double, Maybe Double))
readFileSurface file = do
    src <- readFile file
    return $ Surface.fromList [(x,y,z) | item <- lines src, let [x,y,z] = map read $ words item]

readFilePoints :: FilePath -> IO [(String, [Vertex])]
readFilePoints file = do
    src <- readFile file
    return $ map (\x -> (fst $ head x, map snd x)) $
        groupBy ((==) `on` fst) $ sortBy (compare `on` fst)
        [(s,Vertex (read x) (read y) (read z)) | item <- lines src, let [x,y,z,s] = words item]


convertPoints :: [OBJ] -> (String,[Vertex]) -> [OBJ]
convertPoints obj (s,xyz) =
    [Material $ "mtl" ++ s] ++
    [Face (map ((+v) . (*0.05)) vs) vns | v <- xyz, Face vs vns <- obj]


convertSurface :: Surface (Double, Double, Maybe Double) -> [OBJ]
convertSurface s =
    [Material "mtlsurface",Group "surface"] ++
    collect (faces (allNormals s) s)

{'fraction_non_alphanumeric': 0.17495921696574226, 'fraction_numerical': 0.012438825448613376, 'mean_word_length': 2.874407582938389, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1381032', 'n_tokens_mistral': 1743, 'n_tokens_neox': 1666, 'n_words': 413}