nuclear@1: #ifndef CHUNK_H_ nuclear@1: #define CHUNK_H_ nuclear@1: nuclear@41: #ifndef _MSC_VER nuclear@9: #include nuclear@41: #else nuclear@41: typedef unsigned __int32 uint32_t; nuclear@41: #endif nuclear@9: nuclear@1: enum { nuclear@1: CNK_INVALID, // this shouldn't appear in files nuclear@1: CNK_SCENE, // the root chunk nuclear@1: nuclear@1: // general purpose chunks nuclear@1: CNK_INT, nuclear@2: CNK_INT4, nuclear@1: CNK_FLOAT, nuclear@2: CNK_FLOAT3, nuclear@2: CNK_FLOAT4, nuclear@1: CNK_STRING, nuclear@1: nuclear@1: // --- first level chunks --- nuclear@1: // children of CNK_SCENE nuclear@1: CNK_ENV, // environmental parameters nuclear@14: CNK_MTL, // material nuclear@14: CNK_MESH, nuclear@14: CNK_LIGHT, nuclear@14: CNK_CAMERA, nuclear@14: CNK_NODE, nuclear@1: nuclear@1: // --- second level chunks --- nuclear@1: // children of CNK_ENV nuclear@2: CNK_ENV_AMBIENT, // ambient color, contains a single CNK_FLOAT3 nuclear@1: CNK_ENV_FOG, nuclear@1: nuclear@1: // --- third level chunks --- nuclear@1: // children of CNK_FOG nuclear@2: CNK_FOG_COLOR, // fog color, contains a single CNK_FLOAT3 nuclear@14: CNK_FOG_EXP, // fog exponent, contains a single CNK_FLOAT nuclear@1: nuclear@1: // children of CNK_MTL nuclear@14: CNK_MTL_NAME, // has a single CNK_STRING nuclear@1: CNK_MTL_ATTR, // material attribute, has a CNK_STRING for its name, nuclear@1: // a CNK_MTL_ATTR_VAL, and optionally a CNK_MTL_ATTR_MAP nuclear@1: // children of CNK_MTL_ATTR nuclear@14: CNK_MTL_ATTR_NAME, // has a single CNK_STRING nuclear@2: CNK_MTL_ATTR_VAL, // can have a single CNK_FLOAT, CNK_FLOAT3, or CNK_FLOAT4 nuclear@1: CNK_MTL_ATTR_MAP, // has a single CNK_STRING nuclear@1: nuclear@1: // children of CNK_MESH nuclear@2: CNK_MESH_NAME, // has a single CNK_STRING nuclear@2: CNK_MESH_MATERIAL, // has one of CNK_STRING or CNK_INT to identify the material nuclear@2: CNK_MESH_VERTEX_LIST, // has a series of CNK_FLOAT3 chunks nuclear@2: CNK_MESH_NORMAL_LIST, // has a series of CNK_FLOAT3 chunks nuclear@2: CNK_MESH_TANGENT_LIST, // has a series of CNK_FLOAT3 chunks nuclear@2: CNK_MESH_TEXCOORD_LIST, // has a series of CNK_FLOAT3 chunks nuclear@2: CNK_MESH_SKINWEIGHT_LIST, // has a series of CNK_FLOAT4 chunks (4 skin weights) nuclear@2: CNK_MESH_SKINMATRIX_LIST, // has a series of CNK_INT4 chunks (4 matrix indices) nuclear@2: CNK_MESH_COLOR_LIST, // has a series of CNK_FLOAT4 chunks nuclear@2: CNK_MESH_BONES_LIST, // has a series of CNK_INT or CNK_STRING chunks identifying the bone nodes nuclear@8: CNK_MESH_FACE_LIST, // has a series of CNK_FACE chunks nuclear@14: CNK_MESH_FILE, // optionally mesh data may be in another file, has a CNK_STRING filename nuclear@8: nuclear@8: // child of CNK_MESH_FACE_LIST nuclear@8: CNK_MESH_FACE, // has three CNK_INT chunks nuclear@2: nuclear@2: // children of CNK_LIGHT nuclear@2: CNK_LIGHT_NAME, // has a single CNK_STRING nuclear@2: CNK_LIGHT_POS, // has a single CNK_FLOAT3 nuclear@2: CNK_LIGHT_COLOR, // has a single CNK_FLOAT3 nuclear@2: CNK_LIGHT_ATTEN, // has a single CNK_FLOAT3 (constant, linear, squared attenuation) nuclear@2: CNK_LIGHT_DISTANCE, // has a single CNK_FLOAT nuclear@2: CNK_LIGHT_DIR, // a single CNK_FLOAT3 (for spotlights and dir-lights) nuclear@2: CNK_LIGHT_CONE_INNER, // single CNK_FLOAT, inner cone angle (for spotlights) nuclear@2: CNK_LIGHT_CONE_OUTER, // single CNK_FLOAT, outer cone angle (for spotlights) nuclear@2: nuclear@2: // children of CNK_CAMERA nuclear@2: CNK_CAMERA_NAME, // has a single CNK_STRING nuclear@2: CNK_CAMERA_POS, // single CNK_FLOAT3 nuclear@2: CNK_CAMERA_TARGET, // single CNK_FLOAT3 nuclear@2: CNK_CAMERA_FOV, // single CNK_FLOAT (field of view in radians) nuclear@2: CNK_CAMERA_NEARCLIP, // single CNK_FLOAT (near clipping plane distance) nuclear@2: CNK_CAMERA_FARCLIP, // signle CNK_FLOAT (far clipping plane distance) nuclear@2: nuclear@2: // children of CNK_NODE nuclear@2: CNK_NODE_NAME, // node name, a single CNK_STRING nuclear@2: CNK_NODE_PARENT, // it can have a CNK_INT or a CNK_STRING to identify the parent node nuclear@2: nuclear@2: CNK_NODE_MESH, // it can have a CNK_INT or a CNK_STRING to identify this node's mesh nuclear@2: CNK_NODE_LIGHT, // same as CNK_NODE_MESH nuclear@2: CNK_NODE_CAMERA, // same as CNK_NODE_MESH nuclear@2: nuclear@14: CNK_NODE_POS, // has a CNK_FLOAT3, position vector nuclear@14: CNK_NODE_ROT, // has a CNK_FLOAT4, rotation quaternion (x, y, z imaginary, w real) nuclear@14: CNK_NODE_SCALE, // has a CNK_FLOAT3, scaling nuclear@14: CNK_NODE_PIVOT, // has a CNK_FLOAT3, pivot point nuclear@2: nuclear@14: CNK_NODE_MATRIX0, // has a CNK_FLOAT4, first matrix row (4x3) nuclear@14: CNK_NODE_MATRXI1, // has a CNK_FLOAT4, second matrix row (4x3) nuclear@14: CNK_NODE_MATRIX2, // has a CNK_FLOAT4, third matrix row (4x3) nuclear@2: nuclear@2: MAX_NUM_CHUNKS nuclear@1: }; nuclear@1: nuclear@9: #define UNKNOWN_SIZE ((uint32_t)0xbaadf00d) nuclear@9: nuclear@1: struct ChunkHeader { nuclear@1: uint32_t id; nuclear@1: uint32_t size; nuclear@1: }; nuclear@1: nuclear@1: struct Chunk { nuclear@1: ChunkHeader hdr; nuclear@1: char data[1]; nuclear@1: }; nuclear@1: nuclear@9: nuclear@13: ChunkHeader chunk_header(int id); nuclear@13: bool write_chunk_header(const ChunkHeader *hdr, goat3d_io *io); nuclear@13: bool read_chunk_header(ChunkHeader *hdr, goat3d_io *io); nuclear@13: void skip_chunk(const ChunkHeader *hdr, goat3d_io *io); nuclear@13: nuclear@9: nuclear@1: #endif // CHUNK_H_