| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
#ifndef PICOMODEL_H |
| 39 |
#define PICOMODEL_H |
| 40 |
|
| 41 |
#ifdef __cplusplus |
| 42 |
extern "C" |
| 43 |
{ |
| 44 |
#endif |
| 45 |
|
| 46 |
#include <stddef.h> |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
#define PICOMODEL_VERSION "0.8.20" |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
#define PICO_GROW_SHADERS 16 |
| 56 |
#define PICO_GROW_SURFACES 16 |
| 57 |
#define PICO_GROW_VERTEXES 1024 |
| 58 |
#define PICO_GROW_INDEXES 1024 |
| 59 |
#define PICO_GROW_ARRAYS 8 |
| 60 |
#define PICO_GROW_FACES 256 |
| 61 |
#define PICO_MAX_SPECIAL 8 |
| 62 |
#define PICO_MAX_DEFAULT_EXTS 4 |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
typedef unsigned char picoByte_t; |
| 67 |
typedef float picoVec_t; |
| 68 |
typedef float picoVec2_t[ 2 ]; |
| 69 |
typedef float picoVec3_t[ 3 ]; |
| 70 |
typedef float picoVec4_t[ 4 ]; |
| 71 |
typedef picoByte_t picoColor_t[ 4 ]; |
| 72 |
typedef int picoIndex_t; |
| 73 |
|
| 74 |
typedef enum |
| 75 |
{ |
| 76 |
PICO_BAD, |
| 77 |
PICO_TRIANGLES, |
| 78 |
PICO_PATCH |
| 79 |
} |
| 80 |
picoSurfaceType_t; |
| 81 |
|
| 82 |
typedef enum |
| 83 |
{ |
| 84 |
PICO_NORMAL, |
| 85 |
PICO_VERBOSE, |
| 86 |
PICO_WARNING, |
| 87 |
PICO_ERROR, |
| 88 |
PICO_FATAL |
| 89 |
} |
| 90 |
picoPrintLevel_t; |
| 91 |
|
| 92 |
typedef struct picoSurface_s picoSurface_t; |
| 93 |
typedef struct picoShader_s picoShader_t; |
| 94 |
typedef struct picoModel_s picoModel_t; |
| 95 |
typedef struct picoModule_s picoModule_t; |
| 96 |
|
| 97 |
struct picoSurface_s |
| 98 |
{ |
| 99 |
void *data; |
| 100 |
|
| 101 |
picoModel_t *model; |
| 102 |
|
| 103 |
picoSurfaceType_t type; |
| 104 |
char *name; |
| 105 |
picoShader_t *shader; |
| 106 |
|
| 107 |
int numVertexes, maxVertexes; |
| 108 |
picoVec3_t *xyz; |
| 109 |
picoVec3_t *normal; |
| 110 |
picoIndex_t *smoothingGroup; |
| 111 |
|
| 112 |
int numSTArrays, maxSTArrays; |
| 113 |
picoVec2_t **st; |
| 114 |
|
| 115 |
int numColorArrays, maxColorArrays; |
| 116 |
picoColor_t **color; |
| 117 |
|
| 118 |
int numIndexes, maxIndexes; |
| 119 |
picoIndex_t *index; |
| 120 |
|
| 121 |
int numFaceNormals, maxFaceNormals; |
| 122 |
picoVec3_t *faceNormal; |
| 123 |
|
| 124 |
int special[ PICO_MAX_SPECIAL ]; |
| 125 |
}; |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
struct picoShader_s |
| 130 |
{ |
| 131 |
picoModel_t *model; |
| 132 |
|
| 133 |
char *name; |
| 134 |
char *mapName; |
| 135 |
picoColor_t ambientColor; |
| 136 |
picoColor_t diffuseColor; |
| 137 |
picoColor_t specularColor; |
| 138 |
float transparency; |
| 139 |
float shininess; |
| 140 |
}; |
| 141 |
|
| 142 |
struct picoModel_s |
| 143 |
{ |
| 144 |
void *data; |
| 145 |
char *name; |
| 146 |
char *fileName; |
| 147 |
int frameNum; |
| 148 |
int numFrames; |
| 149 |
picoVec3_t mins; |
| 150 |
picoVec3_t maxs; |
| 151 |
|
| 152 |
int numShaders, maxShaders; |
| 153 |
picoShader_t **shader; |
| 154 |
|
| 155 |
int numSurfaces, maxSurfaces; |
| 156 |
picoSurface_t **surface; |
| 157 |
|
| 158 |
const picoModule_t *module; |
| 159 |
}; |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
enum |
| 167 |
{ |
| 168 |
PICO_PMV_OK, |
| 169 |
PICO_PMV_ERROR, |
| 170 |
PICO_PMV_ERROR_IDENT, |
| 171 |
PICO_PMV_ERROR_VERSION, |
| 172 |
PICO_PMV_ERROR_SIZE, |
| 173 |
PICO_PMV_ERROR_MEMORY, |
| 174 |
}; |
| 175 |
|
| 176 |
|
| 177 |
#define PM_PARAMS_CANLOAD \ |
| 178 |
const char *fileName, const void *buffer, int bufSize |
| 179 |
|
| 180 |
#define PM_PARAMS_LOAD \ |
| 181 |
const char *fileName, int frameNum, const void *buffer, int bufSize |
| 182 |
|
| 183 |
#define PM_PARAMS_CANSAVE \ |
| 184 |
void |
| 185 |
|
| 186 |
#define PM_PARAMS_SAVE \ |
| 187 |
const char *fileName, picoModel_t * model |
| 188 |
|
| 189 |
|
| 190 |
struct picoModule_s |
| 191 |
{ |
| 192 |
char *version; |
| 193 |
|
| 194 |
char *displayName; |
| 195 |
char *authorName; |
| 196 |
char *copyright; |
| 197 |
|
| 198 |
char *defaultExts[ PICO_MAX_DEFAULT_EXTS ]; |
| 199 |
int ( *canload )( PM_PARAMS_CANLOAD ); |
| 200 |
picoModel_t *( *load )( PM_PARAMS_LOAD ); |
| 201 |
int ( *cansave )( PM_PARAMS_CANSAVE ); |
| 202 |
int ( *save )( PM_PARAMS_SAVE ); |
| 203 |
}; |
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
int PicoInit( void ); |
| 209 |
void PicoShutdown( void ); |
| 210 |
int PicoError( void ); |
| 211 |
|
| 212 |
void PicoSetMallocFunc( void *( *func )( size_t ) ); |
| 213 |
void PicoSetFreeFunc( void ( *func )( void* ) ); |
| 214 |
void PicoSetLoadFileFunc( void ( *func )( const char*, unsigned char**, int* ) ); |
| 215 |
void PicoSetFreeFileFunc( void ( *func )( void* ) ); |
| 216 |
void PicoSetSaveFileFunc( int ( *func )( const char*, const unsigned char*, int ) ); |
| 217 |
void PicoSetPrintFunc( void ( *func )( int, const char* ) ); |
| 218 |
|
| 219 |
const picoModule_t **PicoModuleList( int *numModules ); |
| 220 |
|
| 221 |
picoModel_t *PicoLoadModel( const char *name, int frameNum ); |
| 222 |
|
| 223 |
typedef size_t ( *PicoInputStreamReadFunc )( void* inputStream, unsigned char* buffer, size_t length ); |
| 224 |
picoModel_t* PicoModuleLoadModelStream( const picoModule_t* module, void* inputStream, PicoInputStreamReadFunc inputStreamRead, size_t streamLength, int frameNum, const char *fileName ); |
| 225 |
|
| 226 |
|
| 227 |
picoModel_t *PicoNewModel( void ); |
| 228 |
void PicoFreeModel( picoModel_t *model ); |
| 229 |
int PicoAdjustModel( picoModel_t *model, int numShaders, int numSurfaces ); |
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
picoShader_t *PicoNewShader( picoModel_t *model ); |
| 234 |
void PicoFreeShader( picoShader_t *shader ); |
| 235 |
picoShader_t *PicoFindShader( picoModel_t *model, char *name, int caseSensitive ); |
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
picoSurface_t *PicoNewSurface( picoModel_t *model ); |
| 240 |
void PicoFreeSurface( picoSurface_t *surface ); |
| 241 |
picoSurface_t *PicoFindSurface( picoModel_t *model, char *name, int caseSensitive ); |
| 242 |
int PicoAdjustSurface( picoSurface_t *surface, int numVertexes, int numSTArrays, int numColorArrays, int numIndexes, int numFaceNormals ); |
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
void PicoSetModelName( picoModel_t *model, const char *name ); |
| 247 |
void PicoSetModelFileName( picoModel_t *model, const char *fileName ); |
| 248 |
void PicoSetModelFrameNum( picoModel_t *model, int frameNum ); |
| 249 |
void PicoSetModelNumFrames( picoModel_t *model, int numFrames ); |
| 250 |
void PicoSetModelData( picoModel_t *model, void *data ); |
| 251 |
|
| 252 |
void PicoSetShaderName( picoShader_t *shader, char *name ); |
| 253 |
void PicoSetShaderMapName( picoShader_t *shader, char *mapName ); |
| 254 |
void PicoSetShaderAmbientColor( picoShader_t *shader, picoColor_t color ); |
| 255 |
void PicoSetShaderDiffuseColor( picoShader_t *shader, picoColor_t color ); |
| 256 |
void PicoSetShaderSpecularColor( picoShader_t *shader, picoColor_t color ); |
| 257 |
void PicoSetShaderTransparency( picoShader_t *shader, float value ); |
| 258 |
void PicoSetShaderShininess( picoShader_t *shader, float value ); |
| 259 |
|
| 260 |
void PicoSetSurfaceData( picoSurface_t *surface, void *data ); |
| 261 |
void PicoSetSurfaceType( picoSurface_t *surface, picoSurfaceType_t type ); |
| 262 |
void PicoSetSurfaceName( picoSurface_t *surface, const char *name ); |
| 263 |
void PicoSetSurfaceShader( picoSurface_t *surface, picoShader_t *shader ); |
| 264 |
void PicoSetSurfaceXYZ( picoSurface_t *surface, int num, picoVec3_t xyz ); |
| 265 |
void PicoSetSurfaceNormal( picoSurface_t *surface, int num, picoVec3_t normal ); |
| 266 |
void PicoSetSurfaceST( picoSurface_t *surface, int array, int num, picoVec2_t st ); |
| 267 |
void PicoSetSurfaceColor( picoSurface_t *surface, int array, int num, const picoColor_t color ); |
| 268 |
void PicoSetSurfaceIndex( picoSurface_t *surface, int num, picoIndex_t index ); |
| 269 |
void PicoSetSurfaceIndexes( picoSurface_t *surface, int num, picoIndex_t *index, int count ); |
| 270 |
void PicoSetFaceNormal( picoSurface_t *surface, int num, picoVec3_t normal ); |
| 271 |
void PicoSetSurfaceSpecial( picoSurface_t *surface, int num, int special ); |
| 272 |
void PicoSetSurfaceSmoothingGroup( picoSurface_t *surface, int num, picoIndex_t smoothingGroup ); |
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
char *PicoGetModelName( picoModel_t *model ); |
| 277 |
char *PicoGetModelFileName( picoModel_t *model ); |
| 278 |
int PicoGetModelFrameNum( picoModel_t *model ); |
| 279 |
int PicoGetModelNumFrames( picoModel_t *model ); |
| 280 |
void *PicoGetModelData( picoModel_t *model ); |
| 281 |
int PicoGetModelNumShaders( picoModel_t *model ); |
| 282 |
picoShader_t *PicoGetModelShader( picoModel_t *model, int num ); |
| 283 |
int PicoGetModelNumSurfaces( picoModel_t *model ); |
| 284 |
picoSurface_t *PicoGetModelSurface( picoModel_t *model, int num ); |
| 285 |
int PicoGetModelTotalVertexes( picoModel_t *model ); |
| 286 |
int PicoGetModelTotalIndexes( picoModel_t *model ); |
| 287 |
|
| 288 |
char *PicoGetShaderName( picoShader_t *shader ); |
| 289 |
char *PicoGetShaderMapName( picoShader_t *shader ); |
| 290 |
picoByte_t *PicoGetShaderAmbientColor( picoShader_t *shader ); |
| 291 |
picoByte_t *PicoGetShaderDiffuseColor( picoShader_t *shader ); |
| 292 |
picoByte_t *PicoGetShaderSpecularColor( picoShader_t *shader ); |
| 293 |
float PicoGetShaderTransparency( picoShader_t *shader ); |
| 294 |
float PicoGetShaderShininess( picoShader_t *shader ); |
| 295 |
|
| 296 |
void *PicoGetSurfaceData( picoSurface_t *surface ); |
| 297 |
char *PicoGetSurfaceName( picoSurface_t *surface ); |
| 298 |
picoSurfaceType_t PicoGetSurfaceType( picoSurface_t *surface ); |
| 299 |
char *PicoGetSurfaceName( picoSurface_t *surface ); |
| 300 |
picoShader_t *PicoGetSurfaceShader( picoSurface_t *surface ); |
| 301 |
|
| 302 |
int PicoGetSurfaceNumVertexes( picoSurface_t *surface ); |
| 303 |
picoVec_t *PicoGetSurfaceXYZ( picoSurface_t *surface, int num ); |
| 304 |
picoVec_t *PicoGetSurfaceNormal( picoSurface_t *surface, int num ); |
| 305 |
picoVec_t *PicoGetSurfaceST( picoSurface_t *surface, int array, int num ); |
| 306 |
picoByte_t *PicoGetSurfaceColor( picoSurface_t *surface, int array, int num ); |
| 307 |
int PicoGetSurfaceNumIndexes( picoSurface_t *surface ); |
| 308 |
picoIndex_t PicoGetSurfaceIndex( picoSurface_t *surface, int num ); |
| 309 |
picoIndex_t *PicoGetSurfaceIndexes( picoSurface_t *surface, int num ); |
| 310 |
picoVec_t *PicoGetFaceNormal( picoSurface_t *surface, int num ); |
| 311 |
int PicoGetSurfaceSpecial( picoSurface_t *surface, int num ); |
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
typedef struct picoVertexCombinationData_s |
| 316 |
{ |
| 317 |
picoVec3_t xyz, normal; |
| 318 |
picoVec2_t st; |
| 319 |
picoColor_t color; |
| 320 |
} picoVertexCombinationData_t; |
| 321 |
|
| 322 |
typedef struct picoVertexCombinationHash_s |
| 323 |
{ |
| 324 |
picoVertexCombinationData_t vcd; |
| 325 |
picoIndex_t index; |
| 326 |
|
| 327 |
void *data; |
| 328 |
|
| 329 |
struct picoVertexCombinationHash_s *next; |
| 330 |
} picoVertexCombinationHash_t; |
| 331 |
|
| 332 |
int PicoGetHashTableSize( void ); |
| 333 |
unsigned int PicoVertexCoordGenerateHash( picoVec3_t xyz ); |
| 334 |
picoVertexCombinationHash_t **PicoNewVertexCombinationHashTable( void ); |
| 335 |
void PicoFreeVertexCombinationHashTable( picoVertexCombinationHash_t **hashTable ); |
| 336 |
picoVertexCombinationHash_t *PicoFindVertexCombinationInHashTable( picoVertexCombinationHash_t **hashTable, picoVec3_t xyz, picoVec3_t normal, picoVec3_t st, picoColor_t color ); |
| 337 |
picoVertexCombinationHash_t *PicoAddVertexCombinationToHashTable( picoVertexCombinationHash_t **hashTable, picoVec3_t xyz, picoVec3_t normal, picoVec3_t st, picoColor_t color, picoIndex_t index ); |
| 338 |
|
| 339 |
|
| 340 |
int PicoFindSurfaceVertexNum( picoSurface_t *surface, picoVec3_t xyz, picoVec3_t normal, int numSTs, picoVec2_t *st, int numColors, const picoColor_t *color, picoIndex_t smoothingGroup ); |
| 341 |
void PicoFixSurfaceNormals( picoSurface_t *surface ); |
| 342 |
int PicoRemapModel( picoModel_t *model, char *remapFile ); |
| 343 |
|
| 344 |
|
| 345 |
void PicoAddTriangleToModel( picoModel_t *model, picoVec3_t** xyz, picoVec3_t** normals, int numSTs, picoVec2_t **st, int numColors, const picoColor_t **colors, picoShader_t* shader, const char *name, picoIndex_t* smoothingGroup ); |
| 346 |
|
| 347 |
|
| 348 |
#ifdef __cplusplus |
| 349 |
} |
| 350 |
#endif |
| 351 |
|
| 352 |
#endif |