/* dependencies */
#include "picointernal.h"
+#include "globaldefs.h"
/* disable warnings */
-#ifdef WIN32
+#if GDEF_COMPILER_MSVC
#pragma warning( disable:4100 ) /* unref param */
#endif
return 0;
}
- /* helper */
+ /* helpers */
+ #define _obj_mtl_print_ok _pico_printf( PICO_NORMAL, "PICO: loading %s...OK\n", fileName )
+ #define _obj_mtl_print_fail _pico_printf( PICO_WARNING, "PICO: loading %s...FAIL\n", fileName )
#define _obj_mtl_error_return \
{ \
+ _obj_mtl_print_fail; \
_pico_free_parser( p ); \
_pico_free_file( mtlBuffer ); \
_pico_free( fileName ); \
/* check result */
if ( mtlBufSize == 0 ) {
+ _obj_mtl_print_fail;
return 1; /* file is empty: no error */
}
if ( mtlBufSize < 0 ) {
+ _obj_mtl_print_fail;
return 0; /* load failed: error */
}
if ( _pico_parse( p,1 ) == NULL ) {
break;
}
-#if 1
/* skip empty lines */
if ( p->token == NULL || !strlen( p->token ) ) {
/* validate material name */
if ( name == NULL || !strlen( name ) ) {
- _pico_printf( PICO_ERROR,"Missing material name in MTL, line %d.",p->curLine );
+ _pico_printf( PICO_ERROR,"Missing material name in MTL %s, line %d.",fileName,p->curLine );
_obj_mtl_error_return;
}
/* create a new pico shader */
/* diffuse map name */
else if ( !_pico_stricmp( p->token,"map_kd" ) ) {
char *mapName;
- picoShader_t *shader;
/* pointer to current shader must be valid */
if ( curShader == NULL ) {
/* validate map name */
if ( mapName == NULL || !strlen( mapName ) ) {
- _pico_printf( PICO_ERROR,"Missing material map name in MTL, line %d.",p->curLine );
- _obj_mtl_error_return;
- }
- /* create a new pico shader */
- shader = PicoNewShader( model );
- if ( shader == NULL ) {
+ _pico_printf( PICO_ERROR,"Missing material map name in MTL %s, line %d.",fileName,p->curLine );
_obj_mtl_error_return;
}
/* set shader map name */
- PicoSetShaderMapName( shader,mapName );
+ PicoSetShaderMapName( curShader, mapName );
}
/* dissolve factor (pseudo transparency 0..1) */
/* where 0 means 100% transparent and 1 means opaque */
/* set specular color */
PicoSetShaderSpecularColor( curShader,color );
}
-#endif
/* skip rest of line */
_pico_parse_skip_rest( p );
}
/* free parser, file buffer, and file name */
+ _obj_mtl_print_ok;
_pico_free_parser( p );
_pico_free_file( mtlBuffer );
_pico_free( fileName );
newSurface = PicoNewSurface( model ); \
if ( newSurface == NULL ) { \
_obj_error_return( "Error allocating surface" ); } \
- /* reset face index for surface */ \
+ /* reset face index and vertex index for surface */ \
curFace = 0; \
+ curVertex = 0; \
/* if we can, assign the previous shader to this surface */ \
if ( curSurface ) { \
PicoSetSurfaceShader( newSurface, curSurface->shader ); } \
/* helper */
#define _obj_error_return( m ) \
{ \
- _pico_printf( PICO_ERROR,"%s in OBJ, line %d.",m,p->curLine ); \
+ _pico_printf( PICO_ERROR, "%s in OBJ %s, line %d.", m, model->fileName, p->curLine ); \
_pico_free_parser( p ); \
FreeObjVertexData( vertexData ); \
PicoFreeModel( model ); \
PicoSetModelName( model,fileName );
PicoSetModelFileName( model,fileName );
- /* try loading the materials; we don't handle the result */
-#if 1
+ /* try loading the materials */
_obj_mtl_load( model );
-#endif
/* parse obj line by line */
while ( 1 )
int i;
if ( curSurface == NULL ) {
- _pico_printf( PICO_WARNING,"No group defined for faces, so creating an autoSurface in OBJ, line %d.",p->curLine );
+ _pico_printf( PICO_WARNING,"No group defined for faces, so creating an autoSurface in OBJ %s, line %d.",model->fileName,p->curLine );
AUTO_GROUPNAME( autoGroupNameBuf );
NEW_SURFACE( autoGroupNameBuf );
}
name = _pico_parse( p,0 );
if ( curFace != 0 || curSurface == NULL ) {
- _pico_printf( PICO_WARNING,"No group defined for usemtl, so creating an autoSurface in OBJ, line %d.",p->curLine );
+ _pico_printf( PICO_WARNING,"No group defined for usemtl, so creating an autoSurface in OBJ %s, line %d.",model->fileName,p->curLine );
AUTO_GROUPNAME( autoGroupNameBuf );
NEW_SURFACE( autoGroupNameBuf );
}
/* validate material name */
if ( name == NULL || !strlen( name ) ) {
- _pico_printf( PICO_ERROR,"Missing material name in OBJ, line %d.",p->curLine );
+ _pico_printf( PICO_ERROR,"Missing material name in OBJ %s, line %d.",model->fileName,p->curLine );
}
else
{
shader = PicoFindShader( model, name, 1 );
if ( shader == NULL ) {
- _pico_printf( PICO_WARNING,"Undefined material name in OBJ, line %d. Making a default shader.",p->curLine );
+ _pico_printf( PICO_WARNING, "Undefined material name \"%s\" in OBJ, line %d. Making a default shader.", name, p->curLine );
/* create a new pico shader */
shader = PicoNewShader( model );
/* skip unparsed rest of line and continue */
_pico_parse_skip_rest( p );
}
+
/* free memory used by temporary vertexdata */
FreeObjVertexData( vertexData );