]> git.xonotic.org Git - xonotic/netradiant.git/blobdiff - libs/picomodel/pm_obj.c
Merge commit 'd7763cb7e0d7f6c16cc45335f344385fa6f73ac5' into master-merge
[xonotic/netradiant.git] / libs / picomodel / pm_obj.c
index 24f3ee8ac6ad7cc3e23046c377d586a70b4288cc..7a0ebd5f4068a788900bde501de28efbb09e0c48 100644 (file)
@@ -228,9 +228,12 @@ static int _obj_mtl_load( picoModel_t *model ){
                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 ); \
@@ -250,9 +253,11 @@ static int _obj_mtl_load( picoModel_t *model ){
 
        /* 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 */
 
        }
@@ -269,7 +274,6 @@ static int _obj_mtl_load( picoModel_t *model ){
                if ( _pico_parse( p,1 ) == NULL ) {
                        break;
                }
-#if 1
 
                /* skip empty lines */
                if ( p->token == NULL || !strlen( p->token ) ) {
@@ -291,7 +295,7 @@ static int _obj_mtl_load( picoModel_t *model ){
 
                        /* 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 */
@@ -309,7 +313,6 @@ static int _obj_mtl_load( picoModel_t *model ){
                /* 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 ) {
@@ -321,16 +324,11 @@ static int _obj_mtl_load( picoModel_t *model ){
 
                        /* 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 */
@@ -482,12 +480,12 @@ static int _obj_mtl_load( picoModel_t *model ){
                        /* 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 );
@@ -524,8 +522,9 @@ static picoModel_t *_obj_load( PM_PARAMS_LOAD ){
                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 ); } \
@@ -540,7 +539,7 @@ static picoModel_t *_obj_load( PM_PARAMS_LOAD ){
        /* 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 ); \
@@ -563,10 +562,8 @@ static picoModel_t *_obj_load( PM_PARAMS_LOAD ){
        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 )
@@ -706,7 +703,7 @@ static picoModel_t *_obj_load( PM_PARAMS_LOAD ){
                        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 );
                        }
@@ -889,20 +886,20 @@ static picoModel_t *_obj_load( PM_PARAMS_LOAD ){
                        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 );
@@ -921,6 +918,7 @@ static picoModel_t *_obj_load( PM_PARAMS_LOAD ){
                /* skip unparsed rest of line and continue */
                _pico_parse_skip_rest( p );
        }
+
        /* free memory used by temporary vertexdata */
        FreeObjVertexData( vertexData );