goat3d

view src/chunk.h @ 69:66cd8266f078

fixed animation export
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 21 Apr 2014 03:44:10 +0300
parents 498ca7ac7047
children
line source
1 /*
2 goat3d - 3D scene, character, and animation file format library.
3 Copyright (C) 2013-2014 John Tsiombikas <nuclear@member.fsf.org>
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.
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.
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_
21 #ifndef _MSC_VER
22 #include <stdint.h>
23 #else
24 typedef unsigned __int32 uint32_t;
25 #endif
27 namespace g3dimpl {
29 enum {
30 CNK_INVALID, // this shouldn't appear in files
31 CNK_SCENE, // the root chunk
33 // general purpose chunks
34 CNK_INT,
35 CNK_INT4,
36 CNK_FLOAT,
37 CNK_FLOAT3,
38 CNK_FLOAT4,
39 CNK_STRING,
41 // --- first level chunks ---
42 // children of CNK_SCENE
43 CNK_ENV, // environmental parameters
44 CNK_MTL, // material
45 CNK_MESH,
46 CNK_LIGHT,
47 CNK_CAMERA,
48 CNK_NODE,
50 // --- second level chunks ---
51 // children of CNK_ENV
52 CNK_ENV_AMBIENT, // ambient color, contains a single CNK_FLOAT3
53 CNK_ENV_FOG,
55 // --- third level chunks ---
56 // children of CNK_FOG
57 CNK_FOG_COLOR, // fog color, contains a single CNK_FLOAT3
58 CNK_FOG_EXP, // fog exponent, contains a single CNK_FLOAT
60 // children of CNK_MTL
61 CNK_MTL_NAME, // has a single CNK_STRING
62 CNK_MTL_ATTR, // material attribute, has a CNK_STRING for its name,
63 // a CNK_MTL_ATTR_VAL, and optionally a CNK_MTL_ATTR_MAP
64 // children of CNK_MTL_ATTR
65 CNK_MTL_ATTR_NAME, // has a single CNK_STRING
66 CNK_MTL_ATTR_VAL, // can have a single CNK_FLOAT, CNK_FLOAT3, or CNK_FLOAT4
67 CNK_MTL_ATTR_MAP, // has a single CNK_STRING
69 // children of CNK_MESH
70 CNK_MESH_NAME, // has a single CNK_STRING
71 CNK_MESH_MATERIAL, // has one of CNK_STRING or CNK_INT to identify the material
72 CNK_MESH_VERTEX_LIST, // has a series of CNK_FLOAT3 chunks
73 CNK_MESH_NORMAL_LIST, // has a series of CNK_FLOAT3 chunks
74 CNK_MESH_TANGENT_LIST, // has a series of CNK_FLOAT3 chunks
75 CNK_MESH_TEXCOORD_LIST, // has a series of CNK_FLOAT3 chunks
76 CNK_MESH_SKINWEIGHT_LIST, // has a series of CNK_FLOAT4 chunks (4 skin weights)
77 CNK_MESH_SKINMATRIX_LIST, // has a series of CNK_INT4 chunks (4 matrix indices)
78 CNK_MESH_COLOR_LIST, // has a series of CNK_FLOAT4 chunks
79 CNK_MESH_BONES_LIST, // has a series of CNK_INT or CNK_STRING chunks identifying the bone nodes
80 CNK_MESH_FACE_LIST, // has a series of CNK_FACE chunks
81 CNK_MESH_FILE, // optionally mesh data may be in another file, has a CNK_STRING filename
83 // child of CNK_MESH_FACE_LIST
84 CNK_MESH_FACE, // has three CNK_INT chunks
86 // children of CNK_LIGHT
87 CNK_LIGHT_NAME, // has a single CNK_STRING
88 CNK_LIGHT_POS, // has a single CNK_FLOAT3
89 CNK_LIGHT_COLOR, // has a single CNK_FLOAT3
90 CNK_LIGHT_ATTEN, // has a single CNK_FLOAT3 (constant, linear, squared attenuation)
91 CNK_LIGHT_DISTANCE, // has a single CNK_FLOAT
92 CNK_LIGHT_DIR, // a single CNK_FLOAT3 (for spotlights and dir-lights)
93 CNK_LIGHT_CONE_INNER, // single CNK_FLOAT, inner cone angle (for spotlights)
94 CNK_LIGHT_CONE_OUTER, // single CNK_FLOAT, outer cone angle (for spotlights)
96 // children of CNK_CAMERA
97 CNK_CAMERA_NAME, // has a single CNK_STRING
98 CNK_CAMERA_POS, // single CNK_FLOAT3
99 CNK_CAMERA_TARGET, // single CNK_FLOAT3
100 CNK_CAMERA_FOV, // single CNK_FLOAT (field of view in radians)
101 CNK_CAMERA_NEARCLIP, // single CNK_FLOAT (near clipping plane distance)
102 CNK_CAMERA_FARCLIP, // signle CNK_FLOAT (far clipping plane distance)
104 // children of CNK_NODE
105 CNK_NODE_NAME, // node name, a single CNK_STRING
106 CNK_NODE_PARENT, // it can have a CNK_INT or a CNK_STRING to identify the parent node
108 CNK_NODE_MESH, // it can have a CNK_INT or a CNK_STRING to identify this node's mesh
109 CNK_NODE_LIGHT, // same as CNK_NODE_MESH
110 CNK_NODE_CAMERA, // same as CNK_NODE_MESH
112 CNK_NODE_POS, // has a CNK_FLOAT3, position vector
113 CNK_NODE_ROT, // has a CNK_FLOAT4, rotation quaternion (x, y, z imaginary, w real)
114 CNK_NODE_SCALE, // has a CNK_FLOAT3, scaling
115 CNK_NODE_PIVOT, // has a CNK_FLOAT3, pivot point
117 CNK_NODE_MATRIX0, // has a CNK_FLOAT4, first matrix row (4x3)
118 CNK_NODE_MATRXI1, // has a CNK_FLOAT4, second matrix row (4x3)
119 CNK_NODE_MATRIX2, // has a CNK_FLOAT4, third matrix row (4x3)
121 MAX_NUM_CHUNKS
122 };
124 #define UNKNOWN_SIZE ((uint32_t)0xbaadf00d)
126 struct ChunkHeader {
127 uint32_t id;
128 uint32_t size;
129 };
131 struct Chunk {
132 ChunkHeader hdr;
133 char data[1];
134 };
137 ChunkHeader chunk_header(int id);
138 bool write_chunk_header(const ChunkHeader *hdr, goat3d_io *io);
139 bool read_chunk_header(ChunkHeader *hdr, goat3d_io *io);
140 void skip_chunk(const ChunkHeader *hdr, goat3d_io *io);
142 } // namespace g3dimpl
144 #endif // CHUNK_H_