----------------------------------------------------------------------------- */
-
-
-/* marker */
-#define PM_MS3D_C
-
/* dependencies */
#include "picointernal.h"
+#include "globaldefs.h"
/* disable warnings */
-#ifdef _WIN32
+#if GDEF_COMPILER_MSVC
#pragma warning( disable:4100 ) /* unref param */
#endif
#define DEBUG_PM_MS3D
#define DEBUG_PM_MS3D_EX
-/* plain white */
-static picoColor_t white = { 255,255,255,255 };
-
/* ms3d limits */
-#define MS3D_MAX_VERTS 8192
-#define MS3D_MAX_TRIS 16384
-#define MS3D_MAX_GROUPS 128
-#define MS3D_MAX_MATERIALS 128
-#define MS3D_MAX_JOINTS 128
-#define MS3D_MAX_KEYFRAMES 216
+const int MS3D_MAX_VERTS = 8192;
+const int MS3D_MAX_TRIS = 16384;
+const int MS3D_MAX_GROUPS = 128;
+const int MS3D_MAX_MATERIALS = 128;
+const int MS3D_MAX_JOINTS = 128;
+const int MS3D_MAX_KEYFRAMES = 216;
/* ms3d flags */
-#define MS3D_SELECTED 1
-#define MS3D_HIDDEN 2
-#define MS3D_SELECTED2 4
-#define MS3D_DIRTY 8
+const int MS3D_SELECTED = 1;
+const int MS3D_HIDDEN = 2;
+const int MS3D_SELECTED2 = 4;
+const int MS3D_DIRTY = 8;
/* this freaky loader needs byte alignment */
#pragma pack(push, 1)
* validates a milkshape3d model file.
*/
static int _ms3d_canload( PM_PARAMS_CANLOAD ){
- TMsHeader *hdr;
-
+ const TMsHeader *hdr;
- /* to keep the compiler happy */
- *fileName = *fileName;
/* sanity check */
- if ( bufSize < sizeof( TMsHeader ) ) {
+ if ( (size_t) bufSize < sizeof( TMsHeader ) ) {
return PICO_PMV_ERROR_SIZE;
}
/* get ms3d header */
- hdr = (TMsHeader *)buffer;
+ hdr = (const TMsHeader *)buffer;
/* check ms3d magic */
if ( strncmp( hdr->magic,"MS3D000000",10 ) != 0 ) {
*/
static picoModel_t *_ms3d_load( PM_PARAMS_LOAD ){
picoModel_t *model;
- unsigned char *bufptr;
+ unsigned char *bufptr, *bufptr0;
int shaderRefs[ MS3D_MAX_GROUPS ];
int numGroups;
int numMaterials;
PicoSetModelName( model, fileName );
PicoSetModelFileName( model, fileName );
+ bufptr0 = bufptr = (picoByte_t*) _pico_alloc( bufSize );
+ memcpy( bufptr, buffer, bufSize );
/* skip header */
- bufptr = (unsigned char *)buffer + sizeof( TMsHeader );
+ bufptr += sizeof( TMsHeader );
/* get number of vertices */
bufptr = GetWord( bufptr,&numVerts );
if ( triangle->vertexIndices[ k ] >= numVerts ) {
_pico_printf( PICO_ERROR,"Vertex %d index %d out of range (%d, max %d)",i,k,triangle->vertexIndices[k],numVerts - 1 );
PicoFreeModel( model );
+ _pico_free( bufptr0 );
return NULL; /* yuck */
}
}
surface = PicoNewSurface( model );
if ( surface == NULL ) {
PicoFreeModel( model );
+ _pico_free( bufptr0 );
return NULL;
}
/* do surface setup */
PicoSetSurfaceXYZ( surface,vertexIndex,vertex->xyz );
/* store vertex color */
- PicoSetSurfaceColor( surface,0,vertexIndex,white );
+ PicoSetSurfaceColor( surface, 0, vertexIndex, picoColor_white );
/* store vertex normal */
PicoSetSurfaceNormal( surface,vertexIndex,triangle->vertexNormals[ m ] );
shader = PicoNewShader( model );
if ( shader == NULL ) {
PicoFreeModel( model );
+ _pico_free( bufptr0 );
return NULL;
}
/* scale shader colors */
#endif
}
/* return allocated pico model */
+ _pico_free( bufptr0 );
return model;
// return NULL;
}