]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - libs/picomodel/pm_obj.c
* picomodel: do some guessings about shader paths to handle more cases out of the...
[xonotic/netradiant.git] / libs / picomodel / pm_obj.c
index 6e11a1cdbaca6875bce3d01f474b0212a690f375..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 ) ) {
@@ -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 ) {
@@ -324,13 +327,8 @@ static int _obj_mtl_load( picoModel_t *model ){
                                _pico_printf( PICO_ERROR,"Missing material map name in MTL %s, line %d.",fileName,p->curLine );
                                _obj_mtl_error_return;
                        }
-                       /* create a new pico shader */
-                       shader = PicoNewShader( model );
-                       if ( shader == NULL ) {
-                               _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 );
@@ -564,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 )
@@ -903,7 +899,7 @@ static picoModel_t *_obj_load( PM_PARAMS_LOAD ){
                        {
                                shader = PicoFindShader( model, name, 1 );
                                if ( shader == NULL ) {
-                                       _pico_printf( PICO_WARNING,"Undefined material name \"%s\" in OBJ %s, line %d. Making a default shader.",name,model->fileName,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 );
@@ -922,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 );