diff options
author | Joe Crayne <joe@jerkface.net> | 2019-07-28 00:16:13 -0400 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2019-07-28 00:17:11 -0400 |
commit | 5aba33b6f801910a8f5e1587c13678e237e31782 (patch) | |
tree | 67e71c9161dc23e1fe120e2e51074cd9f69b96f5 /MeshSketch.hs | |
parent | 175e4a0ee82e4db1fade4fbd8b5e55e88c21a826 (diff) |
Render curve from obj file.
Diffstat (limited to 'MeshSketch.hs')
-rw-r--r-- | MeshSketch.hs | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/MeshSketch.hs b/MeshSketch.hs index a51cd3d..a2e4cbe 100644 --- a/MeshSketch.hs +++ b/MeshSketch.hs | |||
@@ -54,6 +54,10 @@ import Text.Printf | |||
54 | import qualified Foreign.C.Types | 54 | import qualified Foreign.C.Types |
55 | import System.FilePath | 55 | import System.FilePath |
56 | import System.Directory | 56 | import System.Directory |
57 | import Wavefront.Types | ||
58 | import Wavefront.Util | ||
59 | |||
60 | |||
57 | 61 | ||
58 | import CubeMap | 62 | import CubeMap |
59 | import GLWidget (nullableContext, withCurrentGL) | 63 | import GLWidget (nullableContext, withCurrentGL) |
@@ -160,8 +164,8 @@ stateChangeMesh obj mm storage st = do | |||
160 | let glarea = mmWidget mm | 164 | let glarea = mmWidget mm |
161 | -- load OBJ geometry and material descriptions | 165 | -- load OBJ geometry and material descriptions |
162 | let workarea = BoundingBox (-2.5) (2.5) (-2.5) 2.5 (-2.5) (2.5) | 166 | let workarea = BoundingBox (-2.5) (2.5) (-2.5) 2.5 (-2.5) (2.5) |
163 | mtlLib = snd obj | 167 | mtlLib = matLib obj |
164 | (objMesh,objscale) <- uploadOBJToGPU (Just workarea) obj | 168 | ((objMesh,curveData),objscale) <- uploadOBJToGPU (Just workarea) obj |
165 | putStrLn $ "Using object scale:\n" ++ show objscale | 169 | putStrLn $ "Using object scale:\n" ++ show objscale |
166 | -- load materials textures | 170 | -- load materials textures |
167 | gpuMtlLib <- uploadMtlLib mtlLib | 171 | gpuMtlLib <- uploadMtlLib mtlLib |
@@ -172,6 +176,36 @@ stateChangeMesh obj mm storage st = do | |||
172 | addToGroupsPane (mmListStore mm) True groupname | 176 | addToGroupsPane (mmListStore mm) True groupname |
173 | writeIORef (stObjects st) bufs | 177 | writeIORef (stObjects st) bufs |
174 | writeIORef (stMasks st) $ map (objSpan . maskableObject) bufs | 178 | writeIORef (stMasks st) $ map (objSpan . maskableObject) bufs |
179 | forM_ (take 1 $ curves curveData) $ \c -> do | ||
180 | let mn = minimum $ curvePoints c | ||
181 | mx = maximum $ curvePoints c | ||
182 | bs = decomposeCurve (curvePt curveData) c | ||
183 | mapM_ (putStrLn . show) bs | ||
184 | clearRing (stRingBuffer st) | ||
185 | forM_ bs $ \(BezierSegment [a,b,c,d]) -> do | ||
186 | let cv = Bezier.Curve Nothing (vecLocation a) | ||
187 | (vecLocation b) | ||
188 | (vecLocation c) | ||
189 | (vecLocation d) | ||
190 | Nothing | ||
191 | δ = 0.005 -- TODO | ||
192 | range = Polygonization | ||
193 | { curveBufferID = error "curveBufferID" | ||
194 | , curveStartIndex = 0 | ||
195 | , curveSegmentCount = ringCapacity (stRingBuffer st) | ||
196 | } | ||
197 | r <- subdivideCurve δ cv range $ \_ _ v -> do | ||
198 | RingBuffer.pushBack (stRingBuffer st) $ \RingPoint{..} -> do | ||
199 | rpPosition @<- v | ||
200 | rpColor @<- yellow | ||
201 | putStrLn $ "Subdivided "++show (curveSegmentCount r)++" poly-lines." | ||
202 | return () | ||
203 | {- | ||
204 | RingBuffer.pushBack (stRingBuffer st) $ \RingPoint{..} -> do | ||
205 | rpPosition @<- V3 0 0 (0::Float) | ||
206 | rpColor @<- red -} | ||
207 | return () | ||
208 | putStrLn $ "Returning from stateChangeMesh." | ||
175 | return st | 209 | return st |
176 | 210 | ||
177 | initializeState :: MeshSketch -> GLStorage -> IO State | 211 | initializeState :: MeshSketch -> GLStorage -> IO State |
@@ -321,7 +355,7 @@ loadInitialMesh kont = do | |||
321 | objName <- head . (++ ["cube.obj"]) <$> getArgs | 355 | objName <- head . (++ ["cube.obj"]) <$> getArgs |
322 | putStrLn $ "Loading object "++objName++"..." | 356 | putStrLn $ "Loading object "++objName++"..." |
323 | mobj <- loadOBJ objName | 357 | mobj <- loadOBJ objName |
324 | putStrLn $ "Finisehd loading object "++objName++"." | 358 | putStrLn $ "Finished loading object "++objName++"." |
325 | kont mobj | 359 | kont mobj |
326 | 360 | ||
327 | new :: IO Gtk.Paned | 361 | new :: IO Gtk.Paned |