summaryrefslogtreecommitdiff
path: root/src/Graphics/Formats/Collada/ColladaTypes.hs
blob: ad78aa840ab5f839a7e4c2e00ea6214ebf042431 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
-- some of the Types are from http://hackage.haskell.org/package/GPipe-Collada
-- adopted for possible future combination

module Graphics.Formats.Collada.ColladaTypes
(
    Scene(..),
    SceneNode(..), NodeType(..),
    Transform(..),
    Camera(..),
    ViewSize(..),
    Z(..),
    
    Light(..),
    Attenuation(..),
    Controller(..),
    
    Geometry(..),
    Mesh(..),
    Vertices(..),
    LinePrimitive(..), Polygon(..),
	-- Polylist(..), Spline(..), TriangleMesh(..), TriFan(..), TriStrip(..),
    AnimChannel(..),
    ID, SID,
    Semantic,
    Profile(..), NewParam(..), TechniqueCommon(..), Material, Effect,
    C(..), Color(..),
    Animation(..),
    Fx_common_color_type(..), Fx_common_texture_type(..), Texture(..),
	Interpolation(..),
)
where

import Data.Tree
import Data.Vector
import Graphics.Rendering.OpenGL (TextureObject)
import Graphics.Formats.Collada.Vector2D3D (V3(..), V4(..))

type Mat44 = ((Float,Float,Float,Float),
              (Float,Float,Float,Float),
			  (Float,Float,Float,Float),
			  (Float,Float,Float,Float))

type Scene = Tree SceneNode

data SceneNode = SceneNode {
                nodeId :: ID,
                nodeType :: NodeType,
                nodeLayers :: [String],
                nodeTransformations :: [(SID, Transform)],
                nodeCameras :: [Camera],
                nodeController :: [Controller],
                nodeGeometries :: [Geometry],
                nodeLights :: [Light]
              } | EmptyRoot
              deriving (Show, Eq)


data NodeType = JOINT | NODE | NOTYPE deriving (Show, Eq)

data Transform = LookAt {
                    lookAtEye:: V3,
                    lookAtInterest :: V3,
                    lookAtUp :: V3
                 }
               | Matrix Mat44
               | Rotate V3 Float V3 Float V3 Float
               | Scale V3
               | Skew {
                    skewAngle :: Float,
                    skewRotation :: V3,
                    skewTranslation :: V3
                 }
               | Translate V3
               deriving (Show, Eq)

data Camera = Perspective {
                perspectiveID :: ID,
                perspectiveFov :: ViewSize,
                perspectiveZ :: Z
              }
            | Orthographic {
                orthographicID :: ID,
                orthographicViewSize :: ViewSize,
                orthographicZ :: Z
              }
              deriving (Show, Eq)

data ViewSize = ViewSizeX Float
              | ViewSizeY Float
              | ViewSizeXY (Float,Float)
              deriving (Show, Eq)

data Z = Z { 
            zNear :: Float, 
            zFar :: Float
           }
           deriving (Show, Eq)

data Light = Ambient {
                ambientID :: ID,
                ambientColor :: Color
             }
           | Directional {
                directionalID :: ID,
                directionalColor :: Color
             }
           | Point {
                pointID :: ID,
                pointColor :: Color,
                pointAttenuation :: Attenuation
             }
           | Spot {
                spotID :: ID,
                spotColor :: Color,
                spotAttenuation :: Attenuation,
                spotFallOffAngle :: Float,
                spotFallOffExponent :: Float
             }
              deriving (Show, Eq)

data Attenuation = Attenuation {
                attenuationConstant :: Float,
                attenuationLinear :: Float,
                attenuationQuadratic :: Float
            }
              deriving (Show, Eq)

data Controller = Controller {
                contrId :: ID,
                skin :: [Skin],
                morph :: [Morph]
            }
              deriving (Show, Eq)

data Skin = Skin {
                bindShapeMatrix :: [Mat44],
                source :: [String],
                joint :: [Joint],
                vertexWeights :: String
            }
              deriving (Show, Eq)

data Morph = Morph {
                geometrySource :: String,
                method :: MorphMethod,
                morphSource :: String,
                morphTargets :: [Input]
            }
              deriving (Show, Eq)

data MorphMethod = Normalized | Relative deriving (Show, Eq)

data Joint = Joint {
                jointID :: String,
                prismatic :: Prismatic,
                revolute :: Revolute
            }
              deriving (Show, Eq)

type Prismatic = String
type Revolute = String

data Input = Input {
                offset :: Int,
                semantic :: Semantic,
                inputSource :: String,
                set :: Int
            }
              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, Eq)

data Geometry = Geometry {
                meshID :: ID,
                mesh :: [Mesh],
                vertices :: Vertices
--                convexMesh :: [Mesh],
--                splines :: [Spline],
--                breps :: [Brep]
            }
            deriving (Show)

instance Eq Geometry where
  (Geometry mid1 _ _) == (Geometry mid2 _ _) = mid1 == mid2

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 :: Vector V3,
                  normals :: Vector V3
            }
            deriving (Show, Eq)

data LinePrimitive = LinePrimitive {
                lineP :: Vector (Vector Int), -- point indices
                lineN :: Vector (Vector Int), -- normal indices
                lineT :: Vector (Vector Int), -- texture indices
                ms :: [Material]
            }
            deriving (Show, Eq)

data Polygon = Polygon {
                poylgonP :: Vector (Vector Int),
                poylgonN :: Vector (Vector Int),
                polygonPh :: (Vector Int, Vector Int), -- (indices, indices of a hole)
                polygonMs :: [Material]
            }
            deriving (Show, Eq)

type Material = (SID,Effect)

type Effect = Profile

type Animation = Tree (SID, AnimChannel)

data AnimChannel = AnimChannel {
                     input :: (ID,[Float],Accessor) , -- Accessor: i.e. "TIME"
                     output :: (ID,[Float],Accessor),
                     interp :: [Interpolation],
                     -- target channels in Collada
                     targets :: [(TargetID,AccessorName)] -- transfer values to several objects
                   } | EmptyAnim
                   deriving (Show, Eq)

data Interpolation = Step | Linear | Bezier [Float] [Float] deriving (Show, Eq)

type TargetID = String
type Accessor = [[(AccessorName, AccessorType)]]
type AccessorName = String
type AccessorType = String

data Profile = BRIDGE Asset Extra |
               CG Asset Code Include NewParam TechniqueCG Extra |
               COMMON Asset NewParam TechniqueCommon String |
               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 = 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
                                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
                              deriving (Show, Eq)
data C = Color V4 deriving (Show, Eq)

data Texture = Texture {
                   imageSID :: ID,
                   path :: String, -- ToDo: better type
                   texObj :: Maybe TextureObject -- force evalaution to generate a font cache
            }
            deriving (Show, Eq)

type ID = String
type SID = String -- Maybe

data Color = RGB Float Float Float deriving (Eq, Show)