Show
Ignore:
Timestamp:
06/26/08 06:21:13 (5 months ago)
Author:
mattn
Message:

* fixed warnings
* removed www dir (dead links, almost none of the posted links are available - correct me when i'm wrong, then we can revert this remove)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • GtkRadiant/trunk/libs/picomodel/picomodel.c

    r183 r275  
    162162        char                            *modelFileName, *remapFileName; 
    163163 
    164          
     164 
    165165        /* init */ 
    166166        model = NULL; 
    167          
     167 
    168168        /* make sure we've got a file name */ 
    169169        if( fileName == NULL ) 
     
    172172                return NULL; 
    173173        } 
    174          
     174 
    175175        /* load file data (buffer is allocated by host app) */ 
    176176        _pico_load_file( fileName, &buffer, &bufSize ); 
     
    183183        /* get ptr to list of supported modules */ 
    184184        modules = PicoModuleList( NULL ); 
    185          
     185 
    186186        /* run it through the various loader functions and try */ 
    187187        /* to find a loader that fits the given file data */ 
     
    190190                /* get module */ 
    191191                pm = *modules; 
    192                  
     192 
    193193                /* sanity check */ 
    194194                if( pm == NULL) 
     
    198198                if( pm->canload == NULL || pm->load == NULL ) 
    199199                        continue; 
    200                  
     200 
    201201                /* see whether this module can load the model file or not */ 
    202202                if( pm->canload( fileName, buffer, bufSize ) == PICO_PMV_OK ) 
     
    209209                                return NULL; 
    210210                        } 
    211                          
     211 
    212212                        /* assign pointer to file format module */ 
    213213                        model->module = pm; 
    214                          
     214 
    215215                        /* get model file name */ 
    216216                        modelFileName = PicoGetModelFileName( model ); 
    217                          
     217 
    218218                        /* apply model remappings from <model>.remap */ 
    219219                        if( strlen( modelFileName ) ) 
     
    234234                                } 
    235235                        } 
    236                          
     236 
    237237                        /* model was loaded, so break out of loop */ 
    238238                        break; 
    239239                } 
    240240        } 
    241          
     241 
    242242        /* free memory used by file buffer */ 
    243243        if( buffer) 
     
    262262{ 
    263263        picoModel_t     *model; 
    264          
     264 
    265265        /* allocate */ 
    266266        model = _pico_alloc( sizeof(picoModel_t) ); 
     
    270270        /* clear */ 
    271271        memset( model,0,sizeof(picoModel_t) ); 
    272          
     272 
    273273        /* model set up */ 
    274274        _pico_zero_bounds( model->mins,model->maxs ); 
     
    291291{ 
    292292        int                             i; 
    293          
     293 
    294294 
    295295        /* sanity check */ 
    296296        if( model == NULL ) 
    297297                return; 
    298          
     298 
    299299        /* free bits */ 
    300300        if( model->name ) 
    301301                _pico_free( model->name ); 
    302          
     302 
    303303        /* free shaders */ 
    304304        for( i = 0; i < model->numShaders; i++ ) 
    305305                PicoFreeShader( model->shader[ i ] ); 
    306306        free( model->shader ); 
    307          
     307 
    308308        /* free surfaces */ 
    309309        for( i = 0; i < model->numSurfaces; i++ ) 
    310310                PicoFreeSurface( model->surface[ i ] ); 
    311311        free( model->surface ); 
    312          
     312 
    313313        /* free the model */ 
    314314        _pico_free( model ); 
     
    328328        if( model == NULL ) 
    329329                return 0; 
    330          
     330 
    331331        /* bare minimums */ 
    332332        /* sea: null surface/shader fix (1s=>0s) */ 
     
    343343                        return 0; 
    344344        } 
    345          
     345 
    346346        /* set shader count to higher */ 
    347347        if( numShaders > model->numShaders ) 
    348348                model->numShaders = numShaders; 
    349          
     349 
    350350        /* additional surfaces? */ 
    351351        while( numSurfaces > model->maxSurfaces ) 
     
    355355                        return 0; 
    356356        } 
    357          
     357 
    358358        /* set shader count to higher */ 
    359359        if( numSurfaces > model->numSurfaces ) 
    360360                model->numSurfaces = numSurfaces; 
    361          
     361 
    362362        /* return ok */ 
    363363        return 1; 
     
    378378{ 
    379379        picoShader_t    *shader; 
    380          
     380 
    381381 
    382382        /* allocate and clear */ 
     
    385385                return NULL; 
    386386        memset( shader, 0, sizeof(picoShader_t) ); 
    387          
     387 
    388388        /* attach it to the model */ 
    389389        if( model != NULL ) 
     
    424424        if( shader == NULL ) 
    425425                return; 
    426          
     426 
    427427        /* free bits */ 
    428428        if( shader->name ) 
     
    430430        if( shader->mapName ) 
    431431                _pico_free( shader->mapName ); 
    432          
     432 
    433433        /* free the shader */ 
    434434        _pico_free( shader ); 
     
    445445{ 
    446446        int             i; 
    447          
    448          
     447 
     448 
    449449        /* sanity checks */ 
    450450        if( model == NULL || name == NULL )     /* sea: null name fix */ 
    451451                return NULL; 
    452          
     452 
    453453        /* walk list */ 
    454454        for( i = 0; i < model->numShaders; i++ ) 
     
    468468                                return model->shader[ i ]; 
    469469        } 
    470          
     470 
    471471        /* named shader not found */ 
    472472        return NULL; 
     
    488488        picoSurface_t   *surface; 
    489489        char surfaceName[64]; 
    490          
     490 
    491491        /* allocate and clear */ 
    492492        surface = _pico_alloc( sizeof( *surface ) ); 
     
    494494                return NULL; 
    495495        memset( surface, 0, sizeof( *surface ) ); 
    496          
     496 
    497497        /* attach it to the model */ 
    498498        if( model != NULL ) 
     
    504504                        return NULL; 
    505505                } 
    506                  
     506 
    507507                /* attach */ 
    508508                model->surface[ model->numSurfaces - 1 ] = surface; 
    509509                surface->model = model; 
    510                  
     510 
    511511                /* set default name */ 
    512512                sprintf( surfaceName, "Unnamed_%d", model->numSurfaces ); 
    513513                PicoSetSurfaceName( surface, surfaceName ); 
    514514        } 
    515          
     515 
    516516        /* return */ 
    517517        return surface; 
     
    527527{ 
    528528        int             i; 
    529          
    530          
     529 
     530 
    531531        /* dummy check */ 
    532532        if( surface == NULL ) 
    533533                return; 
    534          
     534 
    535535        /* free bits */ 
    536536        _pico_free( surface->xyz ); 
     
    538538        _pico_free( surface->index ); 
    539539        _pico_free( surface->faceNormal ); 
    540          
     540 
    541541        /* free arrays */ 
    542542        for( i = 0; i < surface->numSTArrays; i++ ) 
     
    546546                _pico_free( surface->color[ i ] ); 
    547547        free( surface->color ); 
    548          
     548 
    549549        /* free the surface */ 
    550550        _pico_free( surface ); 
     
    562562{ 
    563563        int             i; 
    564          
    565          
     564 
     565 
    566566        /* dummy check */ 
    567567        if( surface == NULL ) 
    568568                return 0; 
    569          
     569 
    570570        /* bare minimums */ 
    571571        if( numVertexes < 1 ) 
     
    577577        if( numIndexes < 1 ) 
    578578                numIndexes = 1; 
    579          
     579 
    580580        /* additional vertexes? */ 
    581581        while( numVertexes > surface->maxVertexes ) /* fix */ 
     
    593593                        return 0; 
    594594        } 
    595          
     595 
    596596        /* set vertex count to higher */ 
    597597        if( numVertexes > surface->numVertexes ) 
    598598                surface->numVertexes = numVertexes; 
    599          
     599 
    600600        /* additional st arrays? */ 
    601601        while( numSTArrays > surface->maxSTArrays ) /* fix */ 
     
    611611                } 
    612612        } 
    613          
     613 
    614614        /* additional color arrays? */ 
    615615        while( numColorArrays > surface->maxColorArrays ) /* fix */ 
     
    625625                } 
    626626        } 
    627          
     627 
    628628        /* additional indexes? */ 
    629629        while( numIndexes > surface->maxIndexes ) /* fix */ 
     
    633633                        return 0; 
    634634        } 
    635          
     635 
    636636        /* set index count to higher */ 
    637637        if( numIndexes > surface->numIndexes ) 
     
    666666        if( model == NULL || name == NULL ) 
    667667                return NULL; 
    668          
     668 
    669669        /* walk list */ 
    670670        for( i = 0; i < model->numSurfaces; i++ ) 
     
    10361036        if( num < 0 || num >= model->numShaders ) 
    10371037                return NULL; 
    1038          
     1038 
    10391039        /* return the shader */ 
    10401040        return model->shader[ num ]; 
     
    10611061        if( num < 0 || num >= model->numSurfaces ) 
    10621062                return NULL; 
    1063          
     1063 
    10641064        /* return the surface */ 
    10651065        return model->surface[ num ]; 
     
    10711071{ 
    10721072        int             i, count; 
    1073          
    1074          
     1073 
     1074 
    10751075        if( model == NULL ) 
    10761076                return 0; 
    10771077        if( model->surface == NULL ) 
    10781078                return 0; 
    1079          
     1079 
    10801080        count = 0; 
    10811081        for( i = 0; i < model->numSurfaces; i++ ) 
    10821082                 count += PicoGetSurfaceNumVertexes( model->surface[ i ] ); 
    1083          
     1083 
    10841084        return count; 
    10851085} 
     
    10901090{ 
    10911091        int             i, count; 
    1092          
    1093          
     1092 
     1093 
    10941094        if( model == NULL ) 
    10951095                return 0; 
    10961096        if( model->surface == NULL ) 
    10971097                return 0; 
    1098          
     1098 
    10991099        count = 0; 
    11001100        for( i = 0; i < model->numSurfaces; i++ ) 
    11011101                 count += PicoGetSurfaceNumIndexes( model->surface[ i ] ); 
    1102          
     1102 
    11031103        return count; 
    11041104} 
     
    14141414                if( (vertexCombinationHash->vcd.normal[ 0 ] != normal[ 0 ] || vertexCombinationHash->vcd.normal[ 1 ] != normal[ 1 ] || vertexCombinationHash->vcd.normal[ 2 ] != normal[ 2 ]) ) 
    14151415                        continue; 
    1416                  
     1416 
    14171417                /* check st */ 
    14181418                if( vertexCombinationHash->vcd.st[ 0 ] != st[ 0 ] || vertexCombinationHash->vcd.st[ 1 ] != st[ 1 ] ) 
     
    14301430                        ( fabs(normal[ 2 ] - vertexCombinationHash->vcd.normal[ 2 ]) ) > HASH_NORMAL_EPSILON ) 
    14311431                        continue; 
    1432                  
     1432 
    14331433                /* check st */ 
    14341434                if( ( fabs(st[ 0 ] - vertexCombinationHash->vcd.st[ 0 ]) ) > HASH_ST_EPSILON || 
     
    14891489{ 
    14901490        int             i, j; 
    1491          
    1492          
     1491 
     1492 
    14931493        /* dummy check */ 
    14941494        if( surface == NULL || surface->numVertexes <= 0 ) 
    14951495                return -1; 
    1496          
     1496 
    14971497        /* walk vertex list */ 
    14981498        for( i = 0; i < surface->numVertexes; i++ ) 
     
    15011501                if( xyz != NULL && (surface->xyz[ i ][ 0 ] != xyz[ 0 ] || surface->xyz[ i ][ 1 ] != xyz[ 1 ] || surface->xyz[ i ][ 2 ] != xyz[ 2 ]) ) 
    15021502                        continue; 
    1503                  
     1503 
    15041504                /* check normal */ 
    15051505                if( normal != NULL && (surface->normal[ i ][ 0 ] != normal[ 0 ] || surface->normal[ i ][ 1 ] != normal[ 1 ] || surface->normal[ i ][ 2 ] != normal[ 2 ]) ) 
    15061506                        continue; 
    1507                  
     1507 
    15081508                /* check st */ 
    15091509                if( numSTs > 0 && st != NULL ) 
     
    15171517                                continue; 
    15181518                } 
    1519                  
     1519 
    15201520                /* check color */ 
    15211521                if( numColors > 0 && color != NULL ) 
     
    15291529                                continue; 
    15301530                } 
    1531                  
     1531 
    15321532                /* vertex matches */ 
    15331533                return i; 
    15341534        } 
    1535          
     1535 
    15361536        /* nada */ 
    15371537        return -1; 
     
    15551555        picoVec3_t              *normals, diff; 
    15561556        picoVec4_t              plane; 
    1557          
    1558          
     1557 
     1558 
    15591559        /* dummy check */ 
    15601560        if( surface == NULL || surface->numVertexes == 0 ) 
    15611561                return; 
    1562          
     1562 
    15631563        /* fixme: handle other surface types */ 
    15641564        if( surface->type != PICO_TRIANGLES ) 
    15651565                return; 
    1566          
     1566 
    15671567        /* allocate normal storage */ 
    15681568        normals = _pico_alloc( surface->numVertexes * sizeof( *normals ) ); 
     
    15721572                return; 
    15731573        } 
    1574          
     1574 
    15751575        /* zero it out */ 
    15761576        memset( normals, 0, surface->numVertexes * sizeof( *normals ) ); 
    1577          
     1577 
    15781578        /* walk vertex list */ 
    15791579        for( i = 0; i < surface->numVertexes; i++ ) 
     
    15811581                /* zero out votes */ 
    15821582                numVotes = 0; 
    1583                  
     1583 
    15841584                /* find all the triangles that reference this vertex */ 
    15851585                for( j = 0, faceIndex = 0; j < surface->numIndexes; j += 3, faceIndex++ ) 
     
    15891589                        b = surface->index[ j + 1 ]; 
    15901590                        c = surface->index[ j + 2 ]; 
    1591                          
     1591 
    15921592                        /* ignore degenerate triangles */ 
    15931593                        if( a == b || b == c || c == a ) 
    15941594                                continue; 
    1595                          
     1595 
    15961596                        /* ignore indexes out of range */ 
    15971597                        if( a < 0 || a >= surface->numVertexes || 
     
    15991599                                c < 0 || c >= surface->numVertexes ) 
    16001600                                continue; 
    1601                          
     1601 
    16021602                        /* test triangle */ 
    16031603                        if( a == i || b == i || c == i ) 
     
    16311631                                                break; 
    16321632                                } 
    1633                                  
     1633 
    16341634                                /* add a new vote? */ 
    16351635                                if( k == numVotes && numVotes < MAX_NORMAL_VOTES ) 
     
    16401640                        } 
    16411641                } 
    1642                  
     1642 
    16431643                /* tally votes */ 
    16441644                if( numVotes > 0 ) 
     
    16481648                        for( k = 0; k < numVotes; k++ ) 
    16491649                                _pico_add_vec( normals[ i ], votes[ k ], normals[ i ] ); 
    1650                          
     1650 
    16511651                        /* normalize it */ 
    16521652                        if( _pico_normalize_vec( normals[ i ] ) ) 
     
    16631663                } 
    16641664        } 
    1665          
     1665 
    16661666        /* free normal storage */ 
    16671667        _pico_free( normals ); 
     
    16901690        picoByte_t              *remapBuffer; 
    16911691        int                             remapBufSize; 
    1692          
    1693          
     1692 
     1693 
    16941694        /* sanity checks */ 
    16951695        if( model == NULL || remapFile == NULL ) 
    16961696                return 0; 
    1697          
     1697 
    16981698        /* load remap file contents */ 
    16991699        _pico_load_file( remapFile,&remapBuffer,&remapBufSize ); 
    1700          
     1700 
    17011701        /* check result */ 
    17021702        if( remapBufSize == 0 ) 
     
    17041704        if( remapBufSize < 0 ) 
    17051705                return 0;       /* load failed: error */ 
    1706          
     1706 
    17071707        /* create a new pico parser */ 
    17081708        p = _pico_new_parser( remapBuffer, remapBufSize ); 
     
    17121712                _prm_error_return; 
    17131713        } 
    1714          
     1714 
    17151715        /* doo teh parse */ 
    17161716        while( 1 ) 
     
    17261726                        continue; 
    17271727                } 
    1728                  
     1728 
    17291729                /* block for quick material shader name remapping */ 
    17301730                /* materials { "m" (=>|->|=) "s" } */ 
     
    17421742                                picoShader_t    *shader; 
    17431743                                char                    *materialName; 
    1744                                  
    1745                                  
     1744 
     1745 
    17461746                                /* get material name */ 
    17471747                                if (_pico_parse( p,1 ) == NULL) break; 
     
    18081808                        /* check square closing bracket */ 
    18091809                        if (!_pico_parse_check( p,0,"]" )) 
    1810                                 _prm_error_return;                      
     1810                                _prm_error_return; 
    18111811 
    18121812                        /* try to find material by name */ 
     
    18651865                                        color[ 1 ] = (picoByte_t)v[ 1 ]; 
    18661866                                        color[ 2 ] = (picoByte_t)v[ 2 ]; 
     1867                                        color[ 3 ] = 1; 
    18671868 
    18681869                                        /* set new ambient color */ 
     
    18821883                                        color[ 1 ] = (picoByte_t)v[ 1 ]; 
    18831884                                        color[ 2 ] = (picoByte_t)v[ 2 ]; 
     1885                                        color[ 3 ] = 1; 
    18841886 
    18851887                                        /* set new ambient color */ 
     
    18991901                                        color[ 1 ] = (picoByte_t)v[ 1 ]; 
    19001902                                        color[ 2 ] = (picoByte_t)v[ 2 ]; 
     1903                                        color[ 3 ] = 1; 
    19011904 
    19021905                                        /* set new ambient color */ 
     
    19091912                /* end 'materials[' */ 
    19101913        } 
    1911          
     1914 
    19121915        /* free both parser and file buffer */ 
    19131916        _pico_free_parser( p ); 
     
    19251928*/ 
    19261929 
    1927 void PicoAddTriangleToModel( picoModel_t *model, picoVec3_t** xyz, picoVec3_t** normals,  
     1930void PicoAddTriangleToModel( picoModel_t *model, picoVec3_t** xyz, picoVec3_t** normals, 
    19281931                                                        int numSTs, picoVec2_t **st, int numColors, picoColor_t **colors, 
    19291932                                                        picoShader_t* shader ) 
     
    19381941                workSurface = model->surface[i]; 
    19391942                if ( workSurface->shader == shader ) 
    1940                 {                       
     1943                { 
    19411944                        break; 
    19421945                } 
     
    19611964 
    19621965        /* add the triangle data to the surface */ 
    1963         for ( i = 0 ; i < 3 ; i++ )     
     1966        for ( i = 0 ; i < 3 ; i++ ) 
    19641967        { 
    19651968                /* get the next free spot in the index array */ 
     
    19711974                /* the vertex wasn't found, so create a new vertex in the pool from the data we have */ 
    19721975                if ( vertDataIndex == -1 ) 
    1973                 {                       
     1976                { 
    19741977                        /* find the next spot for a new vertex */ 
    1975                         vertDataIndex = PicoGetSurfaceNumVertexes ( workSurface );                      
     1978                        vertDataIndex = PicoGetSurfaceNumVertexes ( workSurface ); 
    19761979 
    19771980                        /* assign the data to it */ 
    19781981                        PicoSetSurfaceXYZ ( workSurface ,vertDataIndex , *xyz[i] ); 
    1979                         PicoSetSurfaceNormal ( workSurface , vertDataIndex , *normals[i] );                     
     1982                        PicoSetSurfaceNormal ( workSurface , vertDataIndex , *normals[i] ); 
    19801983 
    19811984                        /* make sure to copy over all available ST's and colors for the vertex */ 
     
    19901993                } 
    19911994 
    1992                 /* add this vertex to the triangle */           
     1995                /* add this vertex to the triangle */ 
    19931996                PicoSetSurfaceIndex ( workSurface , newVertIndex , vertDataIndex ); 
    1994         }       
    1995 } 
     1997        } 
     1998}