openTRI 0.1
triModel.h
1/*
2 * triModel.h: Header for model loading/saving
3 * This file is part of the "tri Engine".
4 *
5 * Copyright (C) 2007 tri
6 * Copyright (C) 2007 Tomas Jakobsson 'Tomaz'
7 * Copyright (C) 2007 Alexander Berl 'Raphael' <raphael@fx-world.org>
8 *
9 * $Id: $
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */
25
26#ifndef __TRIMESH_H__
27#define __TRIMESH_H__
28
29#ifdef __PSP__
30#include <pspgu.h>
31#endif
32#include "triTypes.h"
33#include "triTexman.h"
34
35
40/* triModel file format:
41 *
42 * <triModelFileHeader>
43 * n-times:
44 * <triChunkHeader>
45 * <triXHeader>
46 * [data]
47 *
48 * A chunk header contains the header ID (magic) and the size of the chunk including the following tri*Header and data.
49 * This is to make sure all readers can parse the whole file, even if they don't know a specific chunk header.
50 *
51 * NOTE: The loader currently needs the meshes to be stored at the start of the file.
52 *
53 * TODO: - Add texture skinning support.
54 */
55typedef struct triModelFileHeader
56{
57 triChar magic[8]; // "triModel"
58 triU16 numMeshes; // number of Meshes contained in File
59 triU16 numModels; // number of Models contained in File
60 triU16 numTexs; // number of Textures contained in File
61 triU16 reserved;
62} triModelFileHeader; // 16 bytes
63
64
65typedef struct triChunkHeader
66{
67 triChar magic[4];
68 triU32 chunkSize;
69} triChunkHeader; // 8 bytes
70
71
72/* A Model header: "tMH "
73 * followed by numMeshes triPart objects
74 */
75typedef struct triModelHeader
76{
77 triChar name[12];
78 triU16 numParts;
79 triU16 flags;
80 triVec4f pos;
81 triVec4f rot;
82} triModelHeader; // 48 bytes
83
84
85typedef struct triPart
86{
87 triChar name[12];
88 triU16 meshID; // ID of mesh to connect to (0 = first mesh in file, 1 = second mesh in file, etc.)
89 triU16 texID; // ID of tex to connect to (see above)
90 triVec4f pos;
91 triVec4f rot;
92} triPart; // 48 bytes
93
94
95#define TRI_MESH_FLAGS_GZIP 1
96#define TRI_MESH_FLAGS_SAVE_IMAGE 2 // Only for trim saver. Stores the image data in the .trim
97#define TRI_MESH_FLAGS_TRIANGLES 0 // to stay backward compatible
98#define TRI_MESH_FLAGS_TRIANGLE_STRIP 4
99#define TRI_MESH_FLAGS_TRIANGLE_FAN 5
100
101
102/* A Mesh header: "tMhH"
103 * followed by numVerts vertices, each with size vertSize
104 */
105typedef struct triMeshHeader
106{
107 triChar name[12];
108 triU32 vertFormat;
109 triU16 numVerts;
110 triU16 flags;
111 triU16 vertSize; // Size of one vertex in bytes
112 triU16 texID;
113 triU32 dataSize; // Size of following data block in bytes (needed for GZIP compression)
114} triMeshHeader; // 28 bytes
115
116
117/* A Texture header: "tTH "
118 */
119typedef struct triTexHeader
120{
121 triChar filename[64]; // filename of texture
122} triTexHeader; // 64 bytes
123
124
125/* An Image header: "tImg"
126 * followed by a triTexHeader and a triImage file
127 */
128
129
130/* A Morph weights header: "tMoH"
131 * followed by numWeights floats, giving weights for vertex indices 0 - numWeights-1
132 */
133typedef struct triMorphHeader
134{
135 triU8 numWeights;
136 triU8 reserved1;
137 triU16 reserved2;
138} triMorphHeader; // 4 bytes
139
140
141/* A Skinning bone header: "tBH "
142 * followed by numBones 4x4 float matrices, giving skinning matrices for weight indices 0 - numBones-1
143 */
144typedef struct triBoneHeader
145{
146 triU8 numBones;
147 triU8 reserved1;
148 triU16 reserved2;
149} triBoneHeader; // 4 bytes
150
151
152
153
154
155typedef struct triMesh
156{
157 void* verts;
158 triImage* texture; // Mesh texture (only needed for the trim saver any more)
159 triS32 texID;
160 triU32 numVerts;
161 triU32 vertFormat; // Vertex format
162 triU32 renderFormat; // Render format (GU_TRIANGLES, GU_TRIANGLE_STRIP, GU_TRIANGLE_FAN)
163
164 triS32 boundingCheck; // flag which bounding checks to do on the mesh (0 = none, 1 = boundingBox, 2 = boundingSphere)
165 triVec3f boundingBox[8];
166 triVec4f boundingSphere; // x,y,z,radius
167 struct triMesh* next;
168} triMesh;
169
170typedef struct triModelPart
171{
172 triVec4f pos; // Vec4fs need be aligned on 16bytes, so keep them at start of struct
173 triVec4f rot;
174 triMesh* mesh; // mesh
175
176 triS32 texID; // Allow different parts with same meshes to have different textures
177
178 triS32 reserved[2];
180
181typedef struct triModel
182{
183 triVec4f pos;
184 triVec4f rot;
185 triModelPart* parts; // parts
186 triU32 numParts;
187
188 triS32 boundingCheck; // flag which bounding checks to do on the mesh (0 = none, 1 = boundingBox, 2 = boundingSphere)
189 triVec3f boundingBox[8];
190 triVec4f boundingSphere; // x,y,z,radius
191
192 struct triModel* next;
193} triModel;
194
195typedef struct triTex
196{
197 triImage* tex;
198 triS32 texID;
199
200 struct triTex* next;
201} triTex;
202
203
204typedef struct triModelManager
205{
206 triMesh* lastMesh;
207 triMesh* meshes;
208 triS32 numMeshes;
209
210 triTex* lastTex;
211 triTex* texs;
212 triS32 numTexs;
213
214 triModel* lastModel;
215 triModel* models;
216 triS32 numModels;
218
219
220
221void triModelManagerInit();
222void triModelManagerFreeAll();
223
224
225triModel* triModelsLoadTrim( triChar* filename, triS32* numModels );
226#ifdef TRI_SUPPORT_SAVE_TRIM
227void triModelsSaveTrim( triChar* filename, triModel* models, triS32 numModels, triS32 flags );
228#endif
229void triModelsFree( triModel* models, triS32 numModels );
230
231void triModelRender( triModel* model );
232void triMeshCalcBoundings( triMesh* mesh );
233
234void triModelOptimize( triModel* model, triS32 format );
235void triMeshOptimize( triMesh* mesh, triS32 format );
236
237
238extern triMesh* triMeshLoadTrim ( triChar* fileName, triChar* texName );
239extern void triMeshFree ( triMesh* pMesh );
240
243#endif // __TRIMESH_H__
Definition: triModel.h:145
Definition: triModel.h:66
Image struct.
Definition: triImage.h:158
Definition: triModel.h:106
Definition: triModel.h:156
Definition: triModel.h:56
Definition: triModel.h:76
Definition: triModel.h:205
Definition: triModel.h:171
Definition: triModel.h:182
Definition: triModel.h:134
Definition: triModel.h:86
Definition: triModel.h:120
Definition: triModel.h:196
3D float Vector
Definition: triTypes.h:156
4D float Vector (quaternion)
Definition: triTypes.h:228