From e09ed3bffde4317655c11d6990a8bae5c07cc39a Mon Sep 17 00:00:00 2001 From: Pan7 Date: Thu, 1 Oct 2015 17:56:00 +0200 Subject: [PATCH] usemtl for obj models --- libs/picomodel/pm_obj.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/libs/picomodel/pm_obj.c b/libs/picomodel/pm_obj.c index 1c8c088f..2f6e93c4 100644 --- a/libs/picomodel/pm_obj.c +++ b/libs/picomodel/pm_obj.c @@ -49,7 +49,6 @@ * - '_obj_load' code crashes in a weird way after * '_obj_mtl_load' for a few .mtl files * - process 'mtllib' rather than using .mtl - * - handle 'usemtl' statements */ /* uncomment when debugging this module */ /* #define DEBUG_PM_OBJ */ @@ -859,6 +858,22 @@ static picoModel_t *_obj_load( PM_PARAMS_LOAD ){ /* increase vertex count */ curVertex += max; } + + } + else if ( !_pico_stricmp( p->token, "usemtl" ) ) { + char *materialName; + materialName = _pico_parse( p, 0 ); + if( materialName || strlen( materialName ) ) { + picoShader_t *shader; + shader = PicoFindShader( model, materialName, 0 ); + if( !shader ) { + shader = PicoNewShader( model ); + PicoSetShaderName( shader, materialName ); + } + if( shader && curSurface ) { + PicoSetSurfaceShader( curSurface, shader ); + } + } } /* skip unparsed rest of line and continue */ _pico_parse_skip_rest( p );