collada-output 0.2 → 0.3
raw patch · 6 files changed
+154/−97 lines, 6 filesdep −Vecdep ~containersdep ~timePVP ok
version bump matches the API change (PVP)
Dependencies removed: Vec
Dependency ranges changed: containers, time
API changes (from Hackage documentation)
- Graphics.Formats.Collada.ColladaTypes: Annotate :: NewParam
- Graphics.Formats.Collada.ColladaTypes: type Animations = Tree (SID, AnimChannel)
+ Graphics.Formats.Collada.ColladaTypes: Annotat :: NewParam
+ Graphics.Formats.Collada.ColladaTypes: instance Eq AnimChannel
+ Graphics.Formats.Collada.ColladaTypes: instance Eq C
+ Graphics.Formats.Collada.ColladaTypes: instance Eq Controller
+ Graphics.Formats.Collada.ColladaTypes: instance Eq Extra
+ Graphics.Formats.Collada.ColladaTypes: instance Eq Fx_common_color_type
+ Graphics.Formats.Collada.ColladaTypes: instance Eq Fx_common_texture_type
+ Graphics.Formats.Collada.ColladaTypes: instance Eq Input
+ Graphics.Formats.Collada.ColladaTypes: instance Eq Joint
+ Graphics.Formats.Collada.ColladaTypes: instance Eq LinePrimitive
+ Graphics.Formats.Collada.ColladaTypes: instance Eq Mesh
+ Graphics.Formats.Collada.ColladaTypes: instance Eq Morph
+ Graphics.Formats.Collada.ColladaTypes: instance Eq MorphMethod
+ Graphics.Formats.Collada.ColladaTypes: instance Eq NewParam
+ Graphics.Formats.Collada.ColladaTypes: instance Eq NodeType
+ Graphics.Formats.Collada.ColladaTypes: instance Eq Polygon
+ Graphics.Formats.Collada.ColladaTypes: instance Eq Profile
+ Graphics.Formats.Collada.ColladaTypes: instance Eq SceneNode
+ Graphics.Formats.Collada.ColladaTypes: instance Eq Semantic
+ Graphics.Formats.Collada.ColladaTypes: instance Eq Skin
+ Graphics.Formats.Collada.ColladaTypes: instance Eq Technique
+ Graphics.Formats.Collada.ColladaTypes: instance Eq TechniqueCG
+ Graphics.Formats.Collada.ColladaTypes: instance Eq TechniqueCommon
+ Graphics.Formats.Collada.ColladaTypes: instance Eq Texture
+ Graphics.Formats.Collada.ColladaTypes: instance Eq Vertices
+ Graphics.Formats.Collada.ColladaTypes: instance Show AnimChannel
+ Graphics.Formats.Collada.ColladaTypes: instance Show C
+ Graphics.Formats.Collada.ColladaTypes: instance Show Extra
+ Graphics.Formats.Collada.ColladaTypes: instance Show Fx_common_color_type
+ Graphics.Formats.Collada.ColladaTypes: instance Show Fx_common_texture_type
+ Graphics.Formats.Collada.ColladaTypes: instance Show Geometry
+ Graphics.Formats.Collada.ColladaTypes: instance Show LinePrimitive
+ Graphics.Formats.Collada.ColladaTypes: instance Show Mesh
+ Graphics.Formats.Collada.ColladaTypes: instance Show NewParam
+ Graphics.Formats.Collada.ColladaTypes: instance Show Polygon
+ Graphics.Formats.Collada.ColladaTypes: instance Show Profile
+ Graphics.Formats.Collada.ColladaTypes: instance Show SceneNode
+ Graphics.Formats.Collada.ColladaTypes: instance Show Technique
+ Graphics.Formats.Collada.ColladaTypes: instance Show TechniqueCG
+ Graphics.Formats.Collada.ColladaTypes: instance Show TechniqueCommon
+ Graphics.Formats.Collada.ColladaTypes: instance Show Texture
+ Graphics.Formats.Collada.ColladaTypes: instance Show Vertices
+ Graphics.Formats.Collada.ColladaTypes: type Animation = Tree (SID, AnimChannel)
+ Graphics.Formats.Collada.GenerateCollada: gCollada :: Element -> Scene -> [Animation] -> IO ()
+ Graphics.Formats.Collada.GenerateObjects: aCube :: SceneNode
+ Graphics.Formats.Collada.GenerateObjects: emptyAnimation :: [[Animation]]
+ Graphics.Formats.Collada.GenerateObjects: ge :: Geometry -> SceneNode
+ Graphics.Formats.Collada.GenerateObjects: lightedScene :: [Geometry] -> [Scene]
+ Graphics.Formats.Collada.GenerateObjects: obj :: String -> [Geometry] -> SceneNode
+ Graphics.Formats.Collada.GenerateObjects: polys :: [(Float, Float, Float)] -> [(Float, Float, Float)] -> [[Int]] -> [[Int]] -> [Geometry]
+ Graphics.Formats.Collada.GenerateObjects: scene2 :: Scene
- Graphics.Formats.Collada.Animations: collada_array :: (Show a) => [a] -> [Char]
+ Graphics.Formats.Collada.Animations: collada_array :: Show a => [a] -> [Char]
- Graphics.Formats.Collada.ColladaTypes: LookAt :: Vec3 Float -> Vec3 Float -> Vec3 Float -> Transform
+ Graphics.Formats.Collada.ColladaTypes: LookAt :: Vec3 -> Vec3 -> Vec3 -> Transform
- Graphics.Formats.Collada.ColladaTypes: Matrix :: (Mat44 Float) -> Transform
+ Graphics.Formats.Collada.ColladaTypes: Matrix :: Mat44 -> Transform
- Graphics.Formats.Collada.ColladaTypes: Rotate :: (Vec3 Float) -> Float -> (Vec3 Float) -> Float -> (Vec3 Float) -> Float -> Transform
+ Graphics.Formats.Collada.ColladaTypes: Rotate :: Vec3 -> Float -> Vec3 -> Float -> Vec3 -> Float -> Transform
- Graphics.Formats.Collada.ColladaTypes: Scale :: (Vec3 Float) -> Transform
+ Graphics.Formats.Collada.ColladaTypes: Scale :: Vec3 -> Transform
- Graphics.Formats.Collada.ColladaTypes: Skew :: Float -> Vec3 Float -> Vec3 Float -> Transform
+ Graphics.Formats.Collada.ColladaTypes: Skew :: Float -> Vec3 -> Vec3 -> Transform
- Graphics.Formats.Collada.ColladaTypes: Translate :: (Vec3 Float) -> Transform
+ Graphics.Formats.Collada.ColladaTypes: Translate :: Vec3 -> Transform
- Graphics.Formats.Collada.ColladaTypes: lookAtEye :: Transform -> Vec3 Float
+ Graphics.Formats.Collada.ColladaTypes: lookAtEye :: Transform -> Vec3
- Graphics.Formats.Collada.ColladaTypes: lookAtInterest :: Transform -> Vec3 Float
+ Graphics.Formats.Collada.ColladaTypes: lookAtInterest :: Transform -> Vec3
- Graphics.Formats.Collada.ColladaTypes: lookAtUp :: Transform -> Vec3 Float
+ Graphics.Formats.Collada.ColladaTypes: lookAtUp :: Transform -> Vec3
- Graphics.Formats.Collada.ColladaTypes: skewRotation :: Transform -> Vec3 Float
+ Graphics.Formats.Collada.ColladaTypes: skewRotation :: Transform -> Vec3
- Graphics.Formats.Collada.ColladaTypes: skewTranslation :: Transform -> Vec3 Float
+ Graphics.Formats.Collada.ColladaTypes: skewTranslation :: Transform -> Vec3
- Graphics.Formats.Collada.GenerateCollada: basicFrame :: Element -> (Scene, Animations) -> Element
+ Graphics.Formats.Collada.GenerateCollada: basicFrame :: Element -> Scene -> [Animation] -> Element
- Graphics.Formats.Collada.GenerateCollada: genCollada :: Element -> (Scene, Animations) -> IO ()
+ Graphics.Formats.Collada.GenerateCollada: genCollada :: Scene -> [Animation] -> IO ()
- Graphics.Formats.Collada.GenerateObjects: animation :: Animations
+ Graphics.Formats.Collada.GenerateObjects: animation :: [Animation]
- Graphics.Formats.Collada.GenerateObjects: animation2 :: Animations
+ Graphics.Formats.Collada.GenerateObjects: animation2 :: [Animation]
Files
- README +6/−1
- collada-output.cabal +3/−4
- src/Examples.hs +1/−2
- src/Graphics/Formats/Collada/ColladaTypes.hs +52/−35
- src/Graphics/Formats/Collada/GenerateCollada.hs +27/−21
- src/Graphics/Formats/Collada/GenerateObjects.hs +65/−34
README view
@@ -17,4 +17,9 @@ Changes from 0.1 to 0.2 ------------------------ -Textures working+- Textures working + +0.2 to 0.3 +------------ +- Materials working again +- Vec dependency removed
collada-output.cabal view
@@ -1,5 +1,5 @@ Name: collada-output -Version: 0.2 +Version: 0.3 Synopsis: Generate animated 3d objects in COLLADA Description: Generate a COLLADA file with textures, materials, animations, ... category: graphics @@ -15,9 +15,8 @@ build-depends: base ==4.*, xml == 1.3.*, - containers == 0.3.*, - Vec == 0.9.7, - time == 1.*, + containers == 0.4.*, + time == 1.2.*, SVGPath == 1.0.* exposed-modules: Graphics.Formats.Collada.ColladaTypes
src/Examples.hs view
@@ -5,6 +5,5 @@ import Graphics.Formats.Collada.GenerateObjects main :: IO () -main = genCollada (standardAsset " Haskell Programmer " " My Tool ") - animatedCubes +main = genCollada (fst animatedCubes) (snd animatedCubes) --animatedCube
src/Graphics/Formats/Collada/ColladaTypes.hs view
@@ -24,14 +24,17 @@ Semantic, Profile(..), NewParam(..), TechniqueCommon(..), Material, Effect, C(..), Color(..), - Animations(..), + Animation(..), Fx_common_color_type(..), Fx_common_texture_type(..), Texture(..) ) where import Data.Tree -import qualified Data.Vec as Vec -import Data.Vec (Vec2, Vec3, Mat44, Mat33, (:.)(..), ) +type Vec3 = (Float,Float,Float) +type Mat44 = ((Float,Float,Float,Float), + (Float,Float,Float,Float), + (Float,Float,Float,Float), + (Float,Float,Float,Float)) type Scene = Tree SceneNode @@ -45,25 +48,25 @@ nodeGeometries :: [Geometry], nodeLights :: [Light] } --- deriving (Show) + deriving (Show, Eq) -data NodeType = JOINT | NODE | NOTYPE deriving (Show) +data NodeType = JOINT | NODE | NOTYPE deriving (Show, Eq) data Transform = LookAt { - lookAtEye:: Vec3 Float, - lookAtInterest :: Vec3 Float, - lookAtUp :: Vec3 Float + lookAtEye:: Vec3, + lookAtInterest :: Vec3, + lookAtUp :: Vec3 } - | Matrix (Mat44 Float) - | Rotate (Vec3 Float) Float (Vec3 Float) Float (Vec3 Float) Float - | Scale (Vec3 Float) + | Matrix Mat44 + | Rotate Vec3 Float Vec3 Float Vec3 Float + | Scale Vec3 | Skew { skewAngle :: Float, - skewRotation :: Vec3 Float, - skewTranslation :: Vec3 Float + skewRotation :: Vec3, + skewTranslation :: Vec3 } - | Translate (Vec3 Float) + | Translate Vec3 deriving (Show, Eq) data Camera = Perspective { @@ -123,15 +126,15 @@ skin :: [Skin], morph :: [Morph] } - deriving (Show) + deriving (Show, Eq) data Skin = Skin { - bindShapeMatrix :: [Mat44 Float], + bindShapeMatrix :: [Mat44], source :: [String], joint :: [Joint], vertexWeights :: String } - deriving (Show) + deriving (Show, Eq) data Morph = Morph { geometrySource :: String, @@ -139,16 +142,16 @@ morphSource :: String, morphTargets :: [Input] } - deriving (Show) + deriving (Show, Eq) -data MorphMethod = Normalized | Relative deriving (Show) +data MorphMethod = Normalized | Relative deriving (Show, Eq) data Joint = Joint { jointID :: String, prismatic :: Prismatic, revolute :: Revolute } - deriving (Show) + deriving (Show, Eq) type Prismatic = String type Revolute = String @@ -159,35 +162,43 @@ inputSource :: String, set :: Int } - deriving (Show) + deriving (Show, Eq) data Semantic = BINORMAL | COLOR | CONTINUITY | IMAGE | INPUT | IN_TANGENT | INTERPOLATION | INV_BIND_MATRIX | ISJOINT | LINEAR_STEPS | MORPH_TARGET | MORPH_WEIGHT | NORMAL | OUTPUT | OUT_TANGENT | POSITION | TANGENT | TEXBINORMAL | TEXCOORD | TEXTANGENT | UV | VERTEX | WEIGHT - deriving (Show) + deriving (Show, Eq) data Geometry = Geometry { meshID :: ID, --- convexMesh :: [Mesh], mesh :: [Mesh], vertices :: Vertices +-- convexMesh :: [Mesh], -- splines :: [Spline], -- breps :: [Brep] } --- deriving (Show) + deriving (Show) instance Eq Geometry where (Geometry mid1 _ _) == (Geometry mid2 _ _) = mid1 == mid2 -data Mesh = LP LinePrimitive | LS LinePrimitive | P Polygon | PL LinePrimitive | - Tr LinePrimitive | Trf LinePrimitive | Trs LinePrimitive | S LinePrimitive +data Mesh = LP LinePrimitive | -- ^Lines + LS LinePrimitive | -- ^LineStrips + P Polygon | -- ^Polygon: Contains polygon primitives which may contain holes. + PL LinePrimitive | -- ^PolyList: Contains polygon primitives that cannot contain holes. + Tr LinePrimitive | -- ^Triangles + Trf LinePrimitive | -- ^TriFans + Trs LinePrimitive | -- ^TriStrips + S LinePrimitive -- ^Splines + deriving (Show, Eq) data Vertices = Vertices { name :: ID, verts :: [(Float,Float,Float)], normals :: [(Float,Float,Float)] } + deriving (Show, Eq) data LinePrimitive = LinePrimitive { lineP :: [[Int]], -- point indices @@ -195,6 +206,7 @@ lineT :: [[Int]], -- texture indices ms :: [Material] } + deriving (Show, Eq) data Polygon = Polygon { poylgonP :: [[Int]], @@ -202,12 +214,13 @@ polygonPh :: ([Int],[Int]), -- (indices, indices of a hole) polygonMs :: [Material] } + deriving (Show, Eq) type Material = (SID,Effect) -type Effect = Profile -- (ID,Profile) +type Effect = Profile -type Animations = Tree (SID, AnimChannel) +type Animation = Tree (SID, AnimChannel) data AnimChannel = Bezier { -- these 5 items are called sampler in Collada @@ -220,6 +233,7 @@ -- target channels in Collada targets :: [(TargetID,AccessorName)] -- transfer values to several objects } + deriving (Show, Eq) type TargetID = String type Accessor = [[(AccessorName, AccessorType)]] @@ -232,33 +246,36 @@ GLES Asset NewParam TechniqueCG Extra | GLES2 Asset Code Include NewParam TechniqueCG Extra | GLSL Asset Code Include NewParam TechniqueCG Extra + deriving (Show, Eq) type Asset = String type Code = String type Include = String -data NewParam = Annotate | Semantic | Modifier | NoParam +data NewParam = Annotat | Semantic | Modifier | NoParam deriving (Show, Eq) data TechniqueCommon = Constant | LambertCol [Fx_common_color_type] | LambertTex [Fx_common_texture_type] [[Float]] | PhongCol [Fx_common_color_type] | PhongTex [Fx_common_texture_type] [[Float]] | Blinn -data TechniqueCG = IsAsset | IsAnnotate | Pass | Extra -data Extra = String -- Asset | Technique -data Technique = Profile -- XML -- | Xmlns Schema + deriving (Show, Eq) +data TechniqueCG = IsAsset | IsAnnotate | Pass | Extra deriving (Show, Eq) +data Extra = String deriving (Show, Eq) -- Asset | Technique +data Technique = Profile deriving (Show, Eq) -- XML -- | Xmlns Schema data Fx_common_color_type = CEmission C | CAmbient C | CDiffuse C | CSpecular C | CShininess Float | CReflective C | CReflectivity Float | CTransparent C | CTransparency Float | CIndex_of_refraction Float + deriving (Show, Eq) data Fx_common_texture_type = TEmission Texture | TAmbient Texture | TDiffuse Texture | TSpecular Texture | TShininess Float | TReflective Texture | TReflectivity Float | TTransparent Texture | TTransparency Float | TIndex_of_refraction Float - -data C = Color (Float, Float, Float, Float) + deriving (Show, Eq) +data C = Color (Float, Float, Float, Float) deriving (Show, Eq) data Texture = Texture { imageSID :: ID, path :: String -- ToDo: better type, embedded images } - + deriving (Show, Eq) type ID = String type SID = String -- Maybe
src/Graphics/Formats/Collada/GenerateCollada.hs view
@@ -13,19 +13,23 @@ import Data.Fixed (div') import Data.Tree import Data.List -import Data.Vec (Vec2, Vec3, Mat44, Mat33, (:.)(..), ) +import Debug.Trace -genCollada :: Element -> (Scene, Animations) -> IO () -genCollada asset (sc, anim) = writeFile "Collada-File.dae" $ - ppTopElement (basicFrame asset (sc, anim)) +genCollada :: Scene -> [Animation] -> IO () +genCollada sc anim = gCollada (standardAsset " Haskell Programmer " " My Tool ") sc anim + +gCollada :: Element -> Scene -> [Animation] -> IO () +gCollada asset sc anim = writeFile "Collada-File.dae" $ + ppTopElement (basicFrame asset sc anim) + -- | The basic structure of a Collada file, contains library_... nodes, where library_s are used for referencing -basicFrame :: Element -> (Scene, Animations) -> Element -basicFrame asset (sc, anim) = +basicFrame :: Element -> Scene -> [Animation] -> Element +basicFrame asset sc anim = attr "xmlns" "http://www.collada.org/2005/11/COLLADASchema" $ attr "version" "1.4.0" $ unode "COLLADA" $ [ asset ] ++ -- , unode "library_animation_clips" $ - (library_animations (flatten anim)) ++ + (library_animations (concat $ map flatten anim)) ++ [ unode "library_cameras"$ concat $ map cam extr_cam , unode "library_lights" $ concat $ map light extr_light] ++ (im extr_im) ++ @@ -86,17 +90,17 @@ -- | Extract cameras from SceneNodes and remove duplicates extract_cameras :: [SceneNode] -> [SceneNode] extract_cameras snodes = nubBy (\(SceneNode _ _ _ _ c0s _ _ _) - (SceneNode _ _ _ _ c1s _ _ _) -> c0s == c1s) $ snodes + (SceneNode _ _ _ _ c1s _ _ _) -> c0s == c1s) snodes -- | Extract lights from SceneNodes and remove duplicates extract_lights :: [SceneNode] -> [SceneNode] extract_lights snodes = nubBy (\(SceneNode _ _ _ _ _ _ _ l0s) - (SceneNode _ _ _ _ _ _ _ l1s) -> l0s == l1s) $ snodes + (SceneNode _ _ _ _ _ _ _ l1s) -> l0s == l1s) snodes -- | Extract geometries from SceneNodes and remove duplicates extract_geometries :: [SceneNode] -> [SceneNode] extract_geometries snodes = nubBy (\(SceneNode _ _ _ _ _ _ g0s _) - (SceneNode _ _ _ _ _ _ g1s _) -> g0s == g1s) $ snodes + (SceneNode _ _ _ _ _ _ g1s _) -> g0s == g1s) snodes --------------------------------------------------------- -- | library_cameras @@ -179,11 +183,12 @@ getMaterials (LS (LinePrimitive p n t m)) = m getMaterials (P (Polygon p n ph m)) = m getMaterials (PL (LinePrimitive p n t m)) = m +getMaterials (S (LinePrimitive p n t m)) = m ---------------------------------------------------------- -- | library_materials mat :: [SceneNode] -> [Element] -mat fs = map (materialElement.fst) $ concat $ +mat fs = map (materialElement.fst) $ nubBy (\(a,b) (c,d) -> a==c) $ concat $ map getMaterials $ concat $ map getMeshes $ concat $ map getGeometries fs @@ -196,7 +201,7 @@ ---------------------------------------------------------- -- | library_effects eff :: [SceneNode] -> [Element] -eff fs = map effects $ concat $ +eff fs = map effects $ nubBy (\(a,b) (c,d) -> a==c) $ concat $ map getMaterials $ concat $ map getMeshes $ concat $ map getGeometries fs @@ -291,9 +296,11 @@ attr "material" (symbol ++ "G") $ unode prname ( (vnt s str (symbol,profile)) ++ - [ unode "vcount" (collada_array $ map length ps), - unode "p" (collada_array $ concat $ zipWith3 interleave3 ps ns ts) - ] + [ unode "vcount" (collada_array $ map length ps), + unode "p" $ + if (or $ hasTextures (symbol,profile)) then (collada_array $ concat $ zipWith3 interleave3 ps ns ts) + else (collada_array $ concat $ zipWith interleave ps ns) + ] ) ] @@ -313,12 +320,11 @@ primitives :: String -> String -> [Point] -> [Normal] -> Mesh -> [Element] primitives s str parr narr (S (LinePrimitive ps ns ts mats)) -- Spline = (sources s str (toTriple spl) na) - ++ (concat (map (tex_ar ps ns ts "linestrips" s str) mats)) ++ (lib_vertices s str (toTriple spl) na) - ++ (concat (map (material ps ns ts "linestrips" s str) mats)) + ++ (concat (map (material new_ps new_ps [] "linestrips" s str) mats)) where spl = bSubCurve False (difference_x / 100, difference_y / 100) (toTuple parr) -- using bSubCurve is a hack na = take (length spl) $ repeat (head narr) - il = interleave [0..((length spl)-1)] [0..((length spl)-1)] + new_ps = [[0..((length spl)-1)]] difference_x = (maximum x) - (minimum x) difference_y = (maximum y) - (minimum y) x = map sel3_1 parr @@ -468,7 +474,7 @@ transf :: (SID,Transform) -> [Element] -- transf (Matrix (Mat44 Float)) = unode -transf (sid,(Rotate (xrx:.xry:.xrz:.()) x (yrx:.yry:.yrz:.()) y (zrx:.zry:.zrz:.()) z)) = +transf (sid,(Rotate (xrx,xry,xrz) x (yrx,yry,yrz) y (zrx,zry,zrz) z)) = [ add_attr (Attr (unqual "sid") "rotateX") $ unode "rotate" (show xrx ++ " " ++ show xry ++ " " ++ show xrz ++ " " ++ show x), add_attr (Attr (unqual "sid") "rotateY") $ @@ -476,11 +482,11 @@ add_attr (Attr (unqual "sid") "rotateZ") $ unode "rotate" (show zrx ++ " " ++ show zry ++ " " ++ show zrz ++ " " ++ show z) ] -transf (sid,(Scale (s0:.s1:.s2:.()))) = +transf (sid,(Scale (s0,s1,s2))) = [ add_attr (Attr (unqual "sid") "scale") $ unode "scale" (show s0 ++ " " ++ show s1 ++ " " ++ show s2) ] -transf (sid,(Translate (t0:.t1:.t2:.()))) = +transf (sid,(Translate (t0,t1,t2))) = [ add_attr (Attr (unqual "sid") "translate") $ unode "translate" (show t0 ++ " " ++ show t1 ++ " " ++ show t2) ]
src/Graphics/Formats/Collada/GenerateObjects.hs view
@@ -3,7 +3,7 @@ import Graphics.Formats.Collada.ColladaTypes import Graphics.Formats.Collada.GenerateCollada -import Data.Vec (Vec2, Vec3, Mat44, Mat33, (:.)(..), ) +-- import Graphics.SVGFonts.ReadFont (displayString, triang, cycleNeighbours, AObj(..), Prop(..), Mode(..), Spacing(..), CharProp(..), makeMaps) import Data.Tree animatedCube = (aScene, animation) @@ -12,48 +12,61 @@ aScene :: Scene aScene = Node empty_root [ n aCamera, n (pointLight "pointLight" 3 4 10), - n (pointLight "pointL" (-500) 1000 400), - n aCube ] + n (pointLight "pointL" (-500) 1000 400), + n aCube ] +-- type Scene = Tree SceneNode + n x = Node x [] empty_root = SceneNode "empty" NOTYPE [] [] [] [] [] [] aCamera = SceneNode "camera0" NOTYPE [] - [("cubeTran", Translate ((-827.749):.633.855:.1255.017)), - ("rot", Rotate (1:.0:.0) (-22.1954) - (0:.1:.0) (-33) - (0:.0:.1) 0)] + [("tran", Translate ((-827.749),633.855,1255.017)), + ("rot", Rotate (1,0,0) (-22.1954) + (0,1,0) (-33) + (0,0,1) 0)] [(Perspective "Persp" (ViewSizeXY (37,37)) (Z 10 1000) )] [] [] [] pointLight str x y z = SceneNode str NOTYPE [] - [("cubeTran", Translate (x:.y:.z)), - ("rot", Rotate (1:.0:.0) 0 - (0:.1:.0) 0 - (0:.0:.1) 0)] + [("tran", Translate (x,y,z)), + ("rot", Rotate (1,0,0) 0 + (0,1,0) 0 + (0,0,1) 0)] [] [] [] [(Point "point" (RGB 1 1 1) (Attenuation 1 0 0) )] ambientLight = SceneNode "ambientLight" NOTYPE [] - [("cubeTran", Translate ((-500):.1000:.400)), - ("rot", Rotate (1:.0:.0) 0 - (0:.1:.0) 0 - (0:.0:.1) 0)] + [("tran", Translate ((-500),1000,400)), + ("rot", Rotate (1,0,0) 0 + (0,1,0) 0 + (0,0,1) 0)] [] [] [] [(Ambient "ambient" (RGB 1 1 1) )] +aCube :: SceneNode aCube = SceneNode "cube_geometry" NOTYPE [] - [("cubeTran", Translate (0:.0:.0)), - ("rot", Rotate (1:.0:.0) 0 - (0:.1:.0) 0 - (0:.0:.1) 0) ] + [("tran", Translate (0,0,0)), + ("rot", Rotate (1,0,0) 0 + (0,1,0) 0 + (0,0,1) 0) ] [] [] [cube] -- geometries [] +obj :: String -> [Geometry] -> SceneNode +obj name c = SceneNode name NOTYPE [] + [("tran", Translate (0,0,0)), + ("rot", Rotate (1,0,0) 0 + (0,1,0) 0 + (0,0,1) 0)] + [] [] + c -- geometries + [] + -- | Example animation of the cube -animation :: Animations -animation = Node ("cube_rotate", anim_channel) [] +animation :: [Animation] +animation = [Node ("cube_rotate", anim_channel) []] anim_channel = Bezier ("input", [0, 2.5, 3.75, 5], [[("name","TIME"),("type","Float")]] ) ("output",[0, 0, 56, 0], [[("name","ANGLE"),("type","Float")]] ) @@ -73,7 +86,7 @@ cube :: Geometry cube = Geometry "cube" [PL (LinePrimitive [[0,2,3,1],[0,1,5,4],[6,7,3,2],[0,4,6,2],[3,7,5,1],[5,7,6,4]] -- indices to vertices - [[0,1,2,3],[4,5,6,7],[8,9,10,11],[12,13,14,15],[16,17,18,19],[20,21,22,23]] -- indices to normals + [[0,0,0,0],[1,1,1,1],[2,2,2,2],[3,3,3,3],[4,4,4,4],[5,5,5,5]] -- indices to normals [[0,1,2,3],[0,1,2,3],[0,1,2,3],[0,1,2,3],[0,1,2,3],[0,1,2,3]] -- indices to texture coordinates, use an empty list when no texture [logo] -- [blue] @@ -81,12 +94,7 @@ (Vertices "cube_vertices" [(-50,50,50), (50,50,50), (-50,-50,50), (50,-50,50), -- vertices (-50,50,-50),(50,50,-50),(-50,-50,-50),(50,-50,-50)] - [(0,0,1),(0,0,1),(0,0,1),(0,0,1), -- normals - (0,1,0),(0,1,0),(0,1,0),(0,1,0), - (0,-1,0),(0,-1,0),(0,-1,0),(0,-1,0), - (-1,0,0),(-1,0,0),(-1,0,0),(-1,0,0), - (1,0,0),(1,0,0),(1,0,0),(1,0,0), - (0,0,-1),(0,0,-1),(0,0,-1),(0,0,-1)] + [(0,0,1), (0,1,0), (0,-1,0), (-1,0,0), (1,0,0), (0,0,-1)] -- normals ) blue = ("blue", COMMON "" NoParam @@ -113,17 +121,40 @@ tex = Texture "logo" "Haskell-Logo-Variation.png" +polys :: [(Float,Float,Float)] -> [(Float,Float,Float)] -> [[Int]] -> [[Int]] -> [Geometry] +polys p n pi ni = [Geometry "polygons" + [PL (LinePrimitive pi -- indices to vertices + ni -- indices to normals + [] -- no texure + [blue] + )] + (Vertices "polygons_vertices" p n)] + + +lightedScene :: [Geometry] -> [Scene] +lightedScene g = [ Node empty_root ( [ n aCamera, + n (pointLight "pointLight" 3 4 10), + n (pointLight "pointL" (-500) 1000 400)] ++ + (map n (map ge g)) ) ] + +ge :: Geometry -> SceneNode +ge (Geometry name p v) = obj name [Geometry name p v] -- ------------------ -- a bigger example -- ------------------ animatedCubes = (scene2, animation2) +animatedCubes2 = [(scene2, animation2)] +scene2 :: Scene scene2 = Node empty_root $ [ n aCamera, n (pointLight "pl" (-500) 1000 400) ] ++ (map n test_objs) -- | Animation of several cubes -animation2 :: Animations -animation2 = Node ("cube_rotate", new_channels anim_channel test_objs) [] +animation2 :: [Animation] +animation2 = [Node ("cube_rotate", new_channels anim_channel test_objs) []] +emptyAnimation :: [[Animation]] +emptyAnimation = [] + -- | generate an animation that points to the cubes new_channels :: AnimChannel -> [SceneNode] -> AnimChannel new_channels (Bezier i o it ot interp _) nodes = @@ -134,7 +165,7 @@ -- | a helper function for xyz_grid tran :: SceneNode -> (Float,Float,Float) -> String -> SceneNode tran (SceneNode _ typ layer tr cam contr geo light) (tx, ty, tz) str = - (SceneNode str typ layer ([("tr", Translate (tx:.ty:.tz:.()))] ++ tr) cam contr geo light) + (SceneNode str typ layer ([("tr", Translate (tx,ty,tz))] ++ tr) cam contr geo light) test_objs :: [SceneNode] test_objs = xyz_grid 2 2 2 150 aCube @@ -143,10 +174,10 @@ xyz_grid :: Int -> Int -> Int -> Float -> SceneNode -> [SceneNode] xyz_grid x y z d obj = zipWith (tran obj) (concat (concat (x_line x (map (map (\(a,b,c) -> (a+d,b,c)))) $ - x_line y (map (\(a,b,c) -> (a,b+d,c))) $ - x_line z (\(a,b,c) -> (a,b,c+d)) (0,0,0)) )) + x_line y (map (\(a,b,c) -> (a,b+d,c))) $ + x_line z (\(a,b,c) -> (a,b,c+d)) (0,0,0)) )) (map enum_obj [1..(x*y*z)]) where enum_obj i = (obj_name obj) ++ (show i) x_line 0 change value = [] -x_line n change value = value : ( x_line (n-1) change (change value) ) +x_line n change value = value : ( x_line (n-1) change (change value) )