goat3d

annotate src/chunk.h @ 54:dad392c710df

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