00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef PICOMODEL_H
00037 #define PICOMODEL_H
00038
00039 #ifdef __cplusplus
00040 extern "C"
00041 {
00042 #endif
00043
00044 #include <stddef.h>
00045
00046
00047 #define PICOMODEL_VERSION "0.8.20"
00048
00049
00050 #define PICO_GROW_SHADERS 16
00051 #define PICO_GROW_SURFACES 16
00052 #define PICO_GROW_VERTEXES 1024
00053 #define PICO_GROW_INDEXES 1024
00054 #define PICO_GROW_ARRAYS 8
00055 #define PICO_GROW_FACES 256
00056 #define PICO_MAX_SPECIAL 8
00057 #define PICO_MAX_DEFAULT_EXTS 4
00058
00059
00060 typedef unsigned char picoByte_t;
00061 typedef float picoVec_t;
00062 typedef float picoVec2_t[2];
00063 typedef float picoVec3_t[3];
00064 typedef float picoVec4_t[4];
00065 typedef picoByte_t picoColor_t[4];
00066 typedef int picoIndex_t;
00067
00068 typedef enum
00069 {
00070 PICO_BAD, PICO_TRIANGLES, PICO_PATCH
00071 } picoSurfaceType_t;
00072
00073 typedef enum
00074 {
00075 PICO_NORMAL, PICO_VERBOSE, PICO_WARNING, PICO_ERROR, PICO_FATAL
00076 } picoPrintLevel_t;
00077
00078 typedef struct picoSurface_s picoSurface_t;
00079 typedef struct picoShader_s picoShader_t;
00080 typedef struct picoModel_s picoModel_t;
00081 typedef struct picoModule_s picoModule_t;
00082
00083 struct picoSurface_s
00084 {
00085 void *data;
00086
00087 picoModel_t *model;
00088
00089 picoSurfaceType_t type;
00090 char *name;
00091 picoShader_t *shader;
00092
00093 int numVertexes, maxVertexes;
00094 picoVec3_t *xyz;
00095 picoVec3_t *normal;
00096 picoIndex_t *smoothingGroup;
00097
00098 int numSTArrays, maxSTArrays;
00099 picoVec2_t **st;
00100
00101 int numColorArrays, maxColorArrays;
00102 picoColor_t **color;
00103
00104 int numIndexes, maxIndexes;
00105 picoIndex_t *index;
00106
00107 int numFaceNormals, maxFaceNormals;
00108 picoVec3_t *faceNormal;
00109
00110 int special[PICO_MAX_SPECIAL];
00111 };
00112
00113
00114 struct picoShader_s
00115 {
00116 picoModel_t *model;
00117
00118 char *name;
00119 char *mapName;
00120 picoColor_t ambientColor;
00121 picoColor_t diffuseColor;
00122 picoColor_t specularColor;
00123 float transparency;
00124 float shininess;
00125 };
00126
00127 struct picoModel_s
00128 {
00129 void *data;
00130 char *name;
00131 char *fileName;
00132 int frameNum;
00133 int numFrames;
00134 picoVec3_t mins;
00135 picoVec3_t maxs;
00136
00137 int numShaders, maxShaders;
00138 picoShader_t **shader;
00139
00140 int numSurfaces, maxSurfaces;
00141 picoSurface_t **surface;
00142
00143 const picoModule_t *module;
00144 };
00145
00146
00147
00148
00149 enum
00150 {
00151 PICO_PMV_OK,
00152 PICO_PMV_ERROR,
00153 PICO_PMV_ERROR_IDENT,
00154 PICO_PMV_ERROR_VERSION,
00155 PICO_PMV_ERROR_SIZE,
00156 PICO_PMV_ERROR_MEMORY
00158 };
00159
00160
00161 #define PM_PARAMS_CANLOAD \
00162 const char *fileName, void *buffer, int bufSize
00163
00164 #define PM_PARAMS_LOAD \
00165 const char *fileName, int frameNum, void *buffer, int bufSize
00166
00167 #define PM_PARAMS_CANSAVE \
00168 void
00169
00170 #define PM_PARAMS_SAVE \
00171 const char *fileName, picoModel_t *model
00172
00174 struct picoModule_s
00175 {
00176 const char *version;
00178 const char *displayName;
00179 const char *authorName;
00180 const char *copyright;
00182 const char *defaultExts[PICO_MAX_DEFAULT_EXTS];
00183 int (*canload) (PM_PARAMS_CANLOAD);
00184 picoModel_t *(*load) (PM_PARAMS_LOAD);
00185 int (*cansave) (PM_PARAMS_CANSAVE);
00186 int (*save) (PM_PARAMS_SAVE);
00187 };
00188
00189
00190 int PicoInit (void);
00191 void PicoShutdown (void);
00192 int PicoError (void);
00193
00194 void PicoSetMallocFunc (void *(*func) (size_t));
00195 void PicoSetFreeFunc (void(*func) (void*));
00196 void PicoSetLoadFileFunc (void(*func) (char*, unsigned char**, int*));
00197 void PicoSetFreeFileFunc (void(*func) (void*));
00198 void PicoSetPrintFunc (void(*func) (int, const char*));
00199
00200 const picoModule_t **PicoModuleList (int *numModules);
00201
00202 picoModel_t *PicoLoadModel (char *name, int frameNum);
00203
00204 typedef size_t (*PicoInputStreamReadFunc) (void* inputStream, unsigned char* buffer, size_t length);
00205 picoModel_t* PicoModuleLoadModelStream (const picoModule_t* module, const char *fileName, void* inputStream,
00206 PicoInputStreamReadFunc inputStreamRead, size_t streamLength, int frameNum);
00207
00208
00209 picoModel_t *PicoNewModel (void);
00210 void PicoFreeModel (picoModel_t *model);
00211 int PicoAdjustModel (picoModel_t *model, int numShaders, int numSurfaces);
00212
00213
00214 picoShader_t *PicoNewShader (picoModel_t *model);
00215 void PicoFreeShader (picoShader_t *shader);
00216 picoShader_t *PicoFindShader (picoModel_t *model, char *name, int caseSensitive);
00217
00218
00219 picoSurface_t *PicoNewSurface (picoModel_t *model);
00220 void PicoFreeSurface (picoSurface_t *surface);
00221 picoSurface_t *PicoFindSurface (picoModel_t *model, char *name, int caseSensitive);
00222 int PicoAdjustSurface (picoSurface_t *surface, int numVertexes, int numSTArrays, int numColorArrays,
00223 int numIndexes, int numFaceNormals);
00224
00225
00226 void PicoSetModelName (picoModel_t *model, const char *name);
00227 void PicoSetModelFileName (picoModel_t *model, const char *fileName);
00228 void PicoSetModelFrameNum (picoModel_t *model, int frameNum);
00229 void PicoSetModelNumFrames (picoModel_t *model, int numFrames);
00230 void PicoSetModelData (picoModel_t *model, void *data);
00231
00232 void PicoSetShaderName (picoShader_t *shader, const char *name);
00233 void PicoSetShaderMapName (picoShader_t *shader, char *mapName);
00234 void PicoSetShaderAmbientColor (picoShader_t *shader, picoColor_t color);
00235 void PicoSetShaderDiffuseColor (picoShader_t *shader, picoColor_t color);
00236 void PicoSetShaderSpecularColor (picoShader_t *shader, picoColor_t color);
00237 void PicoSetShaderTransparency (picoShader_t *shader, float value);
00238 void PicoSetShaderShininess (picoShader_t *shader, float value);
00239
00240 void PicoSetSurfaceData (picoSurface_t *surface, void *data);
00241 void PicoSetSurfaceType (picoSurface_t *surface, picoSurfaceType_t type);
00242 void PicoSetSurfaceName (picoSurface_t *surface, char *name);
00243 void PicoSetSurfaceShader (picoSurface_t *surface, picoShader_t *shader);
00244 void PicoSetSurfaceXYZ (picoSurface_t *surface, int num, picoVec3_t xyz);
00245 void PicoSetSurfaceNormal (picoSurface_t *surface, int num, picoVec3_t normal);
00246 void PicoSetSurfaceST (picoSurface_t *surface, int array, int num, picoVec2_t st);
00247 void PicoSetSurfaceColor (picoSurface_t *surface, int array, int num, const picoColor_t color);
00248 void PicoSetSurfaceIndex (picoSurface_t *surface, int num, picoIndex_t index);
00249 void PicoSetSurfaceIndexes (picoSurface_t *surface, int num, picoIndex_t *index, int count);
00250 void PicoSetFaceNormal (picoSurface_t *surface, int num, picoVec3_t normal);
00251 void PicoSetSurfaceSpecial (picoSurface_t *surface, int num, int special);
00252 void PicoSetSurfaceSmoothingGroup (picoSurface_t *surface, int num, picoIndex_t smoothingGroup);
00253
00254
00255 char *PicoGetModelName (picoModel_t *model);
00256 char *PicoGetModelFileName (picoModel_t *model);
00257 int PicoGetModelFrameNum (picoModel_t *model);
00258 int PicoGetModelNumFrames (picoModel_t *model);
00259 void *PicoGetModelData (picoModel_t *model);
00260 int PicoGetModelNumShaders (picoModel_t *model);
00261 picoShader_t *PicoGetModelShader (picoModel_t *model, int num);
00262 int PicoGetModelNumSurfaces (picoModel_t *model);
00263 picoSurface_t *PicoGetModelSurface (picoModel_t *model, int num);
00264 int PicoGetModelTotalVertexes (picoModel_t *model);
00265 int PicoGetModelTotalIndexes (picoModel_t *model);
00266
00267 char *PicoGetShaderName (picoShader_t *shader);
00268 char *PicoGetShaderMapName (picoShader_t *shader);
00269 picoByte_t *PicoGetShaderAmbientColor (picoShader_t *shader);
00270 picoByte_t *PicoGetShaderDiffuseColor (picoShader_t *shader);
00271 picoByte_t *PicoGetShaderSpecularColor (picoShader_t *shader);
00272 float PicoGetShaderTransparency (picoShader_t *shader);
00273 float PicoGetShaderShininess (picoShader_t *shader);
00274
00275 void *PicoGetSurfaceData (picoSurface_t *surface);
00276 char *PicoGetSurfaceName (picoSurface_t *surface);
00277 picoSurfaceType_t PicoGetSurfaceType (picoSurface_t *surface);
00278 char *PicoGetSurfaceName (picoSurface_t *surface);
00279 picoShader_t *PicoGetSurfaceShader (picoSurface_t *surface);
00280
00281 int PicoGetSurfaceNumVertexes (picoSurface_t *surface);
00282 picoVec_t *PicoGetSurfaceXYZ (picoSurface_t *surface, int num);
00283 picoVec_t *PicoGetSurfaceNormal (picoSurface_t *surface, int num);
00284 picoVec_t *PicoGetSurfaceST (picoSurface_t *surface, int array, int num);
00285 picoByte_t *PicoGetSurfaceColor (picoSurface_t *surface, int array, int num);
00286 int PicoGetSurfaceNumIndexes (picoSurface_t *surface);
00287 picoIndex_t PicoGetSurfaceIndex (picoSurface_t *surface, int num);
00288 picoIndex_t *PicoGetSurfaceIndexes (picoSurface_t *surface, int num);
00289 picoVec_t *PicoGetFaceNormal (picoSurface_t *surface, int num);
00290 int PicoGetSurfaceSpecial (picoSurface_t *surface, int num);
00291
00292
00293 typedef struct picoVertexCombinationData_s
00294 {
00295 picoVec3_t xyz, normal;
00296 picoVec2_t st;
00297 picoColor_t color;
00298 } picoVertexCombinationData_t;
00299
00300 typedef struct picoVertexCombinationHash_s
00301 {
00302 picoVertexCombinationData_t vcd;
00303 picoIndex_t index;
00304 void *data;
00305 struct picoVertexCombinationHash_s *next;
00306 } picoVertexCombinationHash_t;
00307
00308 unsigned int PicoVertexCoordGenerateHash (picoVec3_t xyz);
00309 picoVertexCombinationHash_t **PicoNewVertexCombinationHashTable (void);
00310 void PicoFreeVertexCombinationHashTable (picoVertexCombinationHash_t **hashTable);
00311 picoVertexCombinationHash_t *PicoFindVertexCombinationInHashTable (picoVertexCombinationHash_t **hashTable,
00312 picoVec3_t xyz, picoVec3_t normal, picoVec3_t st, picoColor_t color);
00313 picoVertexCombinationHash_t *PicoAddVertexCombinationToHashTable (picoVertexCombinationHash_t **hashTable,
00314 picoVec3_t xyz, picoVec3_t normal, picoVec3_t st, picoColor_t color, picoIndex_t index);
00315
00316
00317 int PicoFindSurfaceVertexNum (picoSurface_t *surface, picoVec3_t xyz, picoVec3_t normal, int numSTs,
00318 picoVec2_t *st, int numColors, picoColor_t *color, picoIndex_t smoothingGroup);
00319 void PicoFixSurfaceNormals (picoSurface_t *surface);
00320
00321 void PicoAddTriangleToModel (picoModel_t *model, picoVec3_t** xyz, picoVec3_t** normals, int numSTs,
00322 picoVec2_t **st, int numColors, picoColor_t **colors, picoShader_t* shader, picoIndex_t* smoothingGroup);
00323
00324
00325 #ifdef __cplusplus
00326 }
00327 #endif
00328
00329 #endif