505c150a1d9c5e70a811ff869a4cee0a207b8d9c
[deeprace] / libs / goat3d / src / chunk.h
1 /*
2 goat3d - 3D scene, and animation file format library.
3 Copyright (C) 2013-2018  John Tsiombikas <nuclear@member.fsf.org>
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18 #ifndef CHUNK_H_
19 #define CHUNK_H_
20
21 #ifndef _MSC_VER
22 #ifdef __sgi
23 #include <inttypes.h>
24 #else
25 #include <stdint.h>
26 #endif
27 #else
28 typedef unsigned __int32 uint32_t;
29 #endif
30
31 enum {
32         CNK_INVALID,            /* this shouldn't appear in files */
33         CNK_SCENE,                      /* the root chunk */
34
35         /* general purpose chunks */
36         CNK_INT,
37         CNK_INT4,
38         CNK_FLOAT,
39         CNK_FLOAT3,
40         CNK_FLOAT4,
41         CNK_STRING,
42
43         /* --- first level chunks --- */
44         /* children of CNK_SCENE */
45         CNK_ENV,                        /* environmental parameters */
46         CNK_MTL,                        /* material */
47         CNK_MESH,
48         CNK_LIGHT,
49         CNK_CAMERA,
50         CNK_NODE,
51
52         /* --- second level chunks --- */
53         /* children of CNK_ENV */
54         CNK_ENV_AMBIENT,        /* ambient color, contains a single CNK_FLOAT3 */
55         CNK_ENV_FOG,
56
57         /* --- third level chunks --- */
58         /* children of CNK_FOG */
59         CNK_FOG_COLOR,          /* fog color, contains a single CNK_FLOAT3 */
60         CNK_FOG_EXP,            /* fog exponent, contains a single CNK_FLOAT */
61
62         /* children of CNK_MTL */
63         CNK_MTL_NAME,           /* has a single CNK_STRING */
64         CNK_MTL_ATTR,           /* material attribute, has a CNK_STRING for its name, */
65                                                 /* a CNK_MTL_ATTR_VAL, and optionally a CNK_MTL_ATTR_MAP */
66         /* children of CNK_MTL_ATTR */
67         CNK_MTL_ATTR_NAME,      /* has a single CNK_STRING */
68         CNK_MTL_ATTR_VAL,       /* can have a single CNK_FLOAT, CNK_FLOAT3, or CNK_FLOAT4 */
69         CNK_MTL_ATTR_MAP,       /* has a single CNK_STRING */
70
71         /* children of CNK_MESH */
72         CNK_MESH_NAME,                  /* has a single CNK_STRING */
73         CNK_MESH_MATERIAL,              /* has one of CNK_STRING or CNK_INT to identify the material */
74         CNK_MESH_VERTEX_LIST,   /* has a series of CNK_FLOAT3 chunks */
75         CNK_MESH_NORMAL_LIST,   /* has a series of CNK_FLOAT3 chunks */
76         CNK_MESH_TANGENT_LIST,  /* has a series of CNK_FLOAT3 chunks */
77         CNK_MESH_TEXCOORD_LIST, /* has a series of CNK_FLOAT3 chunks */
78         CNK_MESH_SKINWEIGHT_LIST,       /* has a series of CNK_FLOAT4 chunks (4 skin weights) */
79         CNK_MESH_SKINMATRIX_LIST,       /* has a series of CNK_INT4 chunks (4 matrix indices) */
80         CNK_MESH_COLOR_LIST,    /* has a series of CNK_FLOAT4 chunks */
81         CNK_MESH_BONES_LIST,    /* has a series of CNK_INT or CNK_STRING chunks identifying the bone nodes */
82         CNK_MESH_FACE_LIST,             /* has a series of CNK_FACE chunks */
83         CNK_MESH_FILE,                  /* optionally mesh data may be in another file, has a CNK_STRING filename */
84
85         /* child of CNK_MESH_FACE_LIST */
86         CNK_MESH_FACE,                  /* has three CNK_INT chunks */
87
88         /* children of CNK_LIGHT */
89         CNK_LIGHT_NAME,                 /* has a single CNK_STRING */
90         CNK_LIGHT_POS,                  /* has a single CNK_FLOAT3 */
91         CNK_LIGHT_COLOR,                /* has a single CNK_FLOAT3 */
92         CNK_LIGHT_ATTEN,                /* has a single CNK_FLOAT3 (constant, linear, squared attenuation) */
93         CNK_LIGHT_DISTANCE,             /* has a single CNK_FLOAT */
94         CNK_LIGHT_DIR,                  /* a single CNK_FLOAT3 (for spotlights and dir-lights) */
95         CNK_LIGHT_CONE_INNER,   /* single CNK_FLOAT, inner cone angle (for spotlights) */
96         CNK_LIGHT_CONE_OUTER,   /* single CNK_FLOAT, outer cone angle (for spotlights) */
97
98         /* children of CNK_CAMERA */
99         CNK_CAMERA_NAME,                /* has a single CNK_STRING */
100         CNK_CAMERA_POS,                 /* single CNK_FLOAT3 */
101         CNK_CAMERA_TARGET,              /* single CNK_FLOAT3 */
102         CNK_CAMERA_FOV,                 /* single CNK_FLOAT (field of view in radians) */
103         CNK_CAMERA_NEARCLIP,    /* single CNK_FLOAT (near clipping plane distance) */
104         CNK_CAMERA_FARCLIP,             /* signle CNK_FLOAT (far clipping plane distance) */
105
106         /* children of CNK_NODE */
107         CNK_NODE_NAME,                  /* node name, a single CNK_STRING */
108         CNK_NODE_PARENT,                /* it can have a CNK_INT or a CNK_STRING to identify the parent node */
109
110         CNK_NODE_MESH,                  /* it can have a CNK_INT or a CNK_STRING to identify this node's mesh */
111         CNK_NODE_LIGHT,                 /* same as CNK_NODE_MESH */
112         CNK_NODE_CAMERA,                /* same as CNK_NODE_MESH */
113
114         CNK_NODE_POS,                   /* has a CNK_FLOAT3, position vector */
115         CNK_NODE_ROT,                   /* has a CNK_FLOAT4, rotation quaternion (x, y, z imaginary, w real) */
116         CNK_NODE_SCALE,                 /* has a CNK_FLOAT3, scaling */
117         CNK_NODE_PIVOT,                 /* has a CNK_FLOAT3, pivot point */
118
119         CNK_NODE_MATRIX0,               /* has a CNK_FLOAT4, first matrix row (4x3) */
120         CNK_NODE_MATRXI1,               /* has a CNK_FLOAT4, second matrix row (4x3) */
121         CNK_NODE_MATRIX2,               /* has a CNK_FLOAT4, third matrix row (4x3) */
122
123         CNK_ANIM,               /* the animation root chunk */
124
125         MAX_NUM_CHUNKS
126 };
127
128 #define UNKNOWN_SIZE    ((uint32_t)0xbaadf00d)
129
130 struct chunk_header {
131         uint32_t id;
132         uint32_t size;
133 };
134
135 struct chunk {
136         struct chunk_header hdr;
137         char data[1];
138 };
139
140
141 void g3dimpl_chunk_header(struct chunk_header *hdr, int id);
142 int g3dimpl_write_chunk_header(const struct chunk_header *hdr, struct goat3d_io *io);
143 int g3dimpl_read_chunk_header(struct chunk_header *hdr, struct goat3d_io *io);
144 void g3dimpl_skip_chunk(const struct chunk_header *hdr, struct goat3d_io *io);
145
146 #endif  /* CHUNK_H_ */