TAPs 0.7.7.3
TAPsReadTAPs.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002 TAPsReadTAPs.cpp
00003 
00004 Create an OpenGL Polygonal Model Object from a .TAPs file
00005 
00006 SUKITTI PUNAK   (11/11/2004)
00007 UPDATE          (11/21/2004)
00008 ******************************************************************************/
00009 #include "TAPsReadTAPs.hpp"
00010 // Using Inclusion Model (i.e. definitions are included in declarations)
00011 //                       (this name.cpp is included in name.hpp)
00012 // Each friend is defined directly inside its declaration.
00013 
00014 BEGIN_NAMESPACE_TAPs
00015 //=============================================================================
00016 template <typename T> FILE * ReadTAPs<T>::fileIn = NULL;
00017 //=============================================================================
00018 //-----------------------------------------------------------------------------
00019 // Read an input file
00020 template <typename T>
00021 bool ReadTAPs<T>::readFile( const char *fileName, OpenGL::PolygonalModel<T> * const prModel )
00022 {
00023     // Open the input file
00024     fileIn = fopen( fileName, "r" );
00025     if ( !fileIn ) {
00026         std::perror( fileName );
00027         return false;
00028     }
00029 
00030     // Read in each line, check what its contents are, 
00031     // and pass it out to the relevant decoder function
00032     const char * const NodeFormat    = "Format";
00033     const char * const NodeHeader    = "Header";
00034     const char * const NodeMaterial  = "Material";
00035     const char * const NodeVertices  = "Vertices";
00036     const char * const NodeFaces     = "Faces";
00037     const char * const NodeTexCoords = "TextureCoordinates";
00038     const char * const NodeEnd       = "End";
00039 
00040     char line[128];
00041     while ( !feof(fileIn) ) {
00042         fgets( line, 128, fileIn );     // read a line
00043         if ( line[0] == '#' ) continue;
00044         if      ( !strncmp( line, NodeFormat, strlen(NodeFormat) ) ) {
00045             ProcessNodeFormat( line, prModel );
00046         }
00047         else if ( !strncmp( line, NodeMaterial, strlen(NodeVertices) ) ) {
00048             ProcessNodeMaterial( line, prModel );
00049         }
00050         else if ( !strncmp( line, NodeVertices, strlen(NodeVertices) ) ) {
00051             ProcessNodeVertices( line, prModel );
00052         }
00053         else if ( !strncmp( line, NodeFaces, strlen(NodeFaces) ) ) {
00054             ProcessNodeFaces( line, prModel );
00055         }
00056         else if ( !strncmp( line, NodeTexCoords, strlen(NodeTexCoords) ) ) {
00057             ProcessNodeTextureCoordinates( line, prModel );
00058         }
00059     }
00060     fclose(fileIn);
00061     prModel->GetMaterial()->ApplyMaterial();
00062     return true;
00063 }
00064 //-----------------------------------------------------------------------------
00065 // Read an input file
00066 template <typename T>
00067 bool ReadTAPs<T>::readFile( const char *fileName, OpenGL::XPolygonalModel<T> * const prModel )
00068 {
00069     // Open the input file
00070     fileIn = fopen( fileName, "r" );
00071     if ( !fileIn ) {
00072         std::perror( fileName );
00073         return false;
00074     }
00075 
00076     // Read in each line, check what its contents are, 
00077     // and pass it out to the relevant decoder function
00078     const char * const NodeFormat    = "Format";
00079     const char * const NodeHeader    = "Header";
00080     const char * const NodeMaterial  = "Material";
00081     const char * const NodeVertices  = "Vertices";
00082     const char * const NodeFaces     = "Faces";
00083     const char * const NodeTexCoords = "TextureCoordinates";
00084     const char * const NodeImageTexture = "ImageTexture";
00085     const char * const NodeEnd       = "End";
00086 
00087     char line[128];
00088     while ( !feof(fileIn) ) {
00089         fgets( line, 128, fileIn );     // read a line
00090         if ( line[0] == '#' ) continue;
00091         if      ( !strncmp( line, NodeFormat, strlen(NodeFormat) ) ) {
00092             ProcessNodeFormat( line, prModel );
00093         }
00094         else if ( !strncmp( line, NodeMaterial, strlen(NodeVertices) ) ) {
00095             ProcessNodeMaterial( line, prModel );
00096         }
00097         else if ( !strncmp( line, NodeVertices, strlen(NodeVertices) ) ) {
00098             ProcessNodeVertices( line, prModel );
00099         }
00100         else if ( !strncmp( line, NodeFaces, strlen(NodeFaces) ) ) {
00101             ProcessNodeFaces( line, prModel );
00102         }
00103         else if ( !strncmp( line, NodeTexCoords, strlen(NodeTexCoords) ) ) {
00104             ProcessNodeTextureCoordinates( line, prModel );
00105         }
00106         else if ( !strncmp( line, NodeImageTexture, strlen(NodeImageTexture) ) ) {
00107             ProcessNodeImageTexture( line, prModel );
00108         }
00109     }
00110     fclose(fileIn);
00111     prModel->GetMaterial()->ApplyMaterial();
00112     return true;
00113 }
00114 //=============================================================================
00115 //-----------------------------------------------------------------------------
00116 // Process Format Node
00117 template <typename T>
00118 void ReadTAPs<T>::ProcessNodeFormat( char *line, OpenGL::PolygonalModel<T> * const prModel )
00119 {
00120     // Example:
00121     //   Format TAPs_OpenGL_Model
00122     char s1[64], s2[64];
00123     sscanf( line, "%s %s", s1, s2 );
00124     if ( strncmp( s2, "TAPs_OpenGL_Model", strlen("TAPs_OpenGL_Model") ) ) {
00125         // Not "TAPs_OpenGL_Model" Format
00126         std::cerr << "The Input File is Not \"TAPs_OpenGL_Model\" Format!" << std::endl;
00127         exit ( EXIT_FAILURE );
00128     }
00129 }
00130 //-----------------------------------------------------------------------------
00131 // Process Format Node
00132 template <typename T>
00133 void ReadTAPs<T>::ProcessNodeFormat( char *line, OpenGL::XPolygonalModel<T> * const prModel )
00134 {
00135     // Example:
00136     //   Format TAPs_OpenGL_Model
00137     char s1[64], s2[64];
00138     sscanf( line, "%s %s", s1, s2 );
00139     if ( strncmp( s2, "TAPs_OpenGL_Model", strlen("TAPs_OpenGL_Model") ) ) {
00140         // Not "TAPs_OpenGL_Model" Format
00141         std::cerr << "The Input File is Not \"TAPs_OpenGL_Model\" Format!" << std::endl;
00142         exit ( EXIT_FAILURE );
00143     }
00144 }
00145 //=============================================================================
00146 //-----------------------------------------------------------------------------
00147 // Process Material Node
00148 template <typename T>
00149 void ReadTAPs<T>::ProcessNodeMaterial( char *line, OpenGL::PolygonalModel<T> * const prModel )
00150 {
00151     //Example:
00152     //  Material
00153     //  {
00154     //    ambient     0.1 0.2 0.3 1.0
00155     //    diffuse     0.2 0.4 0.6 0.5   # alpha is the transparency
00156     //    specular    0.81 0.82 0.83 1.0
00157     //    shininess   1
00158     //    emission    0 0 0 0
00159     //  }
00160     char type[128];
00161     char cr[32];
00162     char cg[32];
00163     char cb[32];
00164     char ca[32];
00165     char *end;
00166     double r = 0, g = 0, b = 0, a = 0;
00167     sscanf( line, "%s", type );
00168     while ( type[0] != '{' ) {
00169         fgets( line, 128, fileIn );
00170         sscanf( line, "%s", type );
00171     }
00172     while ( type[0] != '}' ) {
00173         fgets( line, 128, fileIn );
00174         sscanf( line, "%s %s %s %s %s", type, cr, cg, cb, ca );
00175         if ( type[0] == '#' ) continue;
00176         if      ( !strncmp( type, "ambient", strlen("ambient") ) ) {
00177             r = strtod( cr, &end );
00178             g = strtod( cg, &end );
00179             b = strtod( cb, &end );
00180             a = strtod( ca, &end );
00181             prModel->GetMaterial()->SetAmbient( r, g, b, a );
00182         }
00183         else if ( !strncmp( type, "diffuse", strlen("diffuse") ) ) {
00184             r = strtod( cr, &end );
00185             g = strtod( cg, &end );
00186             b = strtod( cb, &end );
00187             a = strtod( ca, &end );
00188             prModel->GetMaterial()->SetDiffuse( r, g, b, a );
00189         }
00190         else if ( !strncmp( type, "specular", strlen("specular") ) ) {
00191             r = strtod( cr, &end );
00192             g = strtod( cg, &end );
00193             b = strtod( cb, &end );
00194             a = strtod( ca, &end );
00195             prModel->GetMaterial()->SetSpecular( r, g, b, a );
00196         }
00197         else if ( !strncmp( type, "shininess", strlen("shininess") ) ) {
00198             r = strtod( cr, &end );
00199             prModel->GetMaterial()->SetShininess( r );
00200         }
00201         else if ( !strncmp( type, "emission", strlen("emission") ) ) {
00202             r = strtod( cr, &end );
00203             g = strtod( cg, &end );
00204             b = strtod( cb, &end );
00205             a = strtod( ca, &end );
00206             prModel->GetMaterial()->SetEmission( r, g, b, a );
00207         }
00208     }
00209 }
00210 //-----------------------------------------------------------------------------
00211 // Process Material Node
00212 template <typename T>
00213 void ReadTAPs<T>::ProcessNodeMaterial( char *line, OpenGL::XPolygonalModel<T> * const prModel )
00214 {
00215     //Example:
00216     //  Material
00217     //  {
00218     //    ambient     0.1 0.2 0.3 1.0
00219     //    diffuse     0.2 0.4 0.6 0.5   # alpha is the transparency
00220     //    specular    0.81 0.82 0.83 1.0
00221     //    shininess   1
00222     //    emission    0 0 0 0
00223     //  }
00224     char type[128];
00225     char cr[32];
00226     char cg[32];
00227     char cb[32];
00228     char ca[32];
00229     char *end;
00230     double r = 0, g = 0, b = 0, a = 0;
00231     sscanf( line, "%s", type );
00232     while ( type[0] != '{' ) {
00233         fgets( line, 128, fileIn );
00234         sscanf( line, "%s", type );
00235     }
00236     while ( type[0] != '}' ) {
00237         fgets( line, 128, fileIn );
00238         sscanf( line, "%s %s %s %s %s", type, cr, cg, cb, ca );
00239         if ( type[0] == '#' ) continue;
00240         if      ( !strncmp( type, "ambient", strlen("ambient") ) ) {
00241             r = strtod( cr, &end );
00242             g = strtod( cg, &end );
00243             b = strtod( cb, &end );
00244             a = strtod( ca, &end );
00245             prModel->GetMaterial()->SetAmbient( r, g, b, a );
00246         }
00247         else if ( !strncmp( type, "diffuse", strlen("diffuse") ) ) {
00248             r = strtod( cr, &end );
00249             g = strtod( cg, &end );
00250             b = strtod( cb, &end );
00251             a = strtod( ca, &end );
00252             prModel->GetMaterial()->SetDiffuse( r, g, b, a );
00253         }
00254         else if ( !strncmp( type, "specular", strlen("specular") ) ) {
00255             r = strtod( cr, &end );
00256             g = strtod( cg, &end );
00257             b = strtod( cb, &end );
00258             a = strtod( ca, &end );
00259             prModel->GetMaterial()->SetSpecular( r, g, b, a );
00260         }
00261         else if ( !strncmp( type, "shininess", strlen("shininess") ) ) {
00262             r = strtod( cr, &end );
00263             prModel->GetMaterial()->SetShininess( r );
00264         }
00265         else if ( !strncmp( type, "emission", strlen("emission") ) ) {
00266             r = strtod( cr, &end );
00267             g = strtod( cg, &end );
00268             b = strtod( cb, &end );
00269             a = strtod( ca, &end );
00270             prModel->GetMaterial()->SetEmission( r, g, b, a );
00271         }
00272     }
00273 }
00274 //=============================================================================
00275 //-----------------------------------------------------------------------------
00276 // Process Vertices Node
00277 template <typename T>
00278 void ReadTAPs<T>::ProcessNodeVertices( char *line, OpenGL::PolygonalModel<T> * const prModel )
00279 {
00280     /*
00281     //Example
00282     // 12 556.629028 2647.669922 436.273010
00283     char *end;
00284     char *delimiters = "\t ";
00285     char *token = strtok( line, delimiters );   // token is "12"
00286     token  = strtok( '\0', delimiters );            // token is "556.629028"
00287     pObject1_c->m_pdVertex[n][0] = strtod( token, &end );
00288     token  = strtok( '\0', delimiters );            // token is "2647.669922"
00289     pObject1_c->m_pdVertex[n][1] = strtod( token, &end );
00290     token  = strtok( '\0', delimiters );            // token is "436.273010"
00291     pObject1_c->m_pdVertex[n][2] = strtod( token, &end );
00292     */
00293 
00294     //Example:
00295     //  Vertices 6
00296     //  {
00297     //    #  x  y  z
00298     //       1 -1  0
00299     //       1  1  0
00300     //      -1  1  0
00301     //      -1 -1  0
00302     //      -2 -1  0
00303     //  }
00304     char cx[128];
00305     char cy[32];
00306     char cz[32];
00307     char *end;
00308 
00309     // Set number of vertices
00310     sscanf( line, "%s %s", cx, cy );
00311     int n = strtod( cy, &end );
00312     prModel->SetNoVertices( n );
00313     prModel->NewVertexListByNoVertices();
00314 
00315     // Set each vertex
00316     n = 0;
00317     while ( cx[0] != '{' ) {
00318         fgets( line, 128, fileIn );
00319         sscanf( line, "%s", cx );
00320     }
00321     while ( cx[0] != '}' && n < prModel->GetNoVertices() ) {
00322         fgets( line, 128, fileIn );
00323         sscanf( line, "%s %s %s", cx, cy, cz );
00324         if ( cx[0] == '#' ) continue;
00325         prModel->GetVertexList()[n  ][0] = strtod( cx, &end );
00326         prModel->GetVertexList()[n  ][1] = strtod( cy, &end );
00327         prModel->GetVertexList()[n++][2] = strtod( cz, &end );
00328     }
00329     prModel->SetNoVertices( n );
00330 }
00331 //-----------------------------------------------------------------------------
00332 // Process Vertices Node
00333 template <typename T>
00334 void ReadTAPs<T>::ProcessNodeVertices( char *line, OpenGL::XPolygonalModel<T> * const prModel )
00335 {
00336     /*
00337     //Example
00338     // 12 556.629028 2647.669922 436.273010
00339     char *end;
00340     char *delimiters = "\t ";
00341     char *token = strtok( line, delimiters );   // token is "12"
00342     token  = strtok( '\0', delimiters );            // token is "556.629028"
00343     pObject1_c->m_pdVertex[n][0] = strtod( token, &end );
00344     token  = strtok( '\0', delimiters );            // token is "2647.669922"
00345     pObject1_c->m_pdVertex[n][1] = strtod( token, &end );
00346     token  = strtok( '\0', delimiters );            // token is "436.273010"
00347     pObject1_c->m_pdVertex[n][2] = strtod( token, &end );
00348     */
00349 
00350     //Example:
00351     //  Vertices 6
00352     //  {
00353     //    #  x  y  z
00354     //       1 -1  0
00355     //       1  1  0
00356     //      -1  1  0
00357     //      -1 -1  0
00358     //      -2 -1  0
00359     //  }
00360     char cx[128];
00361     char cy[32];
00362     char cz[32];
00363     char *end;
00364 
00365     // Set number of vertices
00366     sscanf( line, "%s %s", cx, cy );
00367     int n = strtod( cy, &end );
00368     prModel->SetNoVertices( n );
00369     prModel->NewVertexListByNoVertices();
00370 
00371     // Set each vertex
00372     n = 0;
00373     while ( cx[0] != '{' ) {
00374         fgets( line, 128, fileIn );
00375         sscanf( line, "%s", cx );
00376     }
00377     while ( cx[0] != '}' && n < prModel->GetNoVertices() ) {
00378         fgets( line, 128, fileIn );
00379         sscanf( line, "%s %s %s", cx, cy, cz );
00380         if ( cx[0] == '#' ) continue;
00381         prModel->GetVertexList()[n  ][0] = strtod( cx, &end );
00382         prModel->GetVertexList()[n  ][1] = strtod( cy, &end );
00383         prModel->GetVertexList()[n++][2] = strtod( cz, &end );
00384     }
00385     prModel->SetNoVertices( n );
00386 }
00387 //=============================================================================
00388 //--------------------------------------------------------------------------
00389 // Process Face Node
00390 template <typename T>
00391 void ReadTAPs<T>::ProcessNodeFaces( char *line, OpenGL::PolygonalModel<T> * const prModel )
00392 {
00393     //Example:
00394     //  Faces 2
00395     //  {
00396     //    #nb_nodes   node_0 node_1 ... node_(nb_nodes-1)
00397     //       4        0 1 2 3
00398     //       3        2 3 4
00399     //  }
00400 
00401     // Set number of faces
00402     int n = 0;
00403     char str[128];
00404     sscanf( line, "%s%d", str, &n );
00405     prModel->SetNoFaces( n );
00406     prModel->NewFaceListByNoFaces();
00407 
00408     // Temp Variables
00409     char *delimiters = "\t ";
00410     char *token = NULL;
00411     char *end;
00412     int numberOfVertices;
00413     int vertexNo;
00414 
00415     // For vertex info
00416     //vertexAt = new std::vector<int>[n];
00417 
00418     // Set each Xface
00419     n = 0;
00420     while ( str[0] != '{' ) {
00421         fgets( line, 128, fileIn );
00422         sscanf( line, "%s", str );
00423     }
00424     while ( str[0] != '}' && n < prModel->GetNoFaces() ) {
00425         fgets( line, 128, fileIn );
00426         sscanf( line, "%s", str );
00427         if ( str[0] == '#' ) continue;
00428 
00429         // Get and set number of vertices
00430         token = strtok( line, delimiters );
00431         numberOfVertices = static_cast<int>( strtol( token, &end, 10 ) );
00432         prModel->GetFaceList()[n].SetNoVertices( numberOfVertices );
00433 
00434         // Set the Xface
00435         for ( int i = 0; i < numberOfVertices; ++i )
00436         {
00437             token = strtok( '\0', delimiters );
00438             vertexNo = static_cast<int>( strtol( token, &end, 10 ) );
00439             prModel->GetFaceList()[n].SetVertexNo( i, vertexNo );
00440             //vertexAt[vertexNo].push_back( i );
00441         }
00442         ++n;
00443     }
00444     prModel->SetNoFaces( n );
00445 }
00446 //--------------------------------------------------------------------------
00447 // Process Face Node
00448 template <typename T>
00449 void ReadTAPs<T>::ProcessNodeFaces( char *line, OpenGL::XPolygonalModel<T> * const prModel )
00450 {
00451     //Example:
00452     //  Faces 2
00453     //  {
00454     //    #nb_nodes   node_0 node_1 ... node_(nb_nodes-1)
00455     //       4        0 1 2 3
00456     //       3        2 3 4
00457     //  }
00458 
00459     // Set number of faces
00460     int n = 0;
00461     char str[128];
00462     sscanf( line, "%s%d", str, &n );
00463     prModel->SetNoFaces( n );
00464     prModel->NewFaceListByNoFaces();
00465 
00466     // Temp Variables
00467     char *delimiters = "\t ";
00468     char *token = NULL;
00469     char *end;
00470     int numberOfVertices;
00471     int vertexNo;
00472 
00473     // For vertex info
00474     //vertexAt = new std::vector<int>[n];
00475 
00476     // Set each Xface
00477     n = 0;
00478     while ( str[0] != '{' ) {
00479         fgets( line, 128, fileIn );
00480         sscanf( line, "%s", str );
00481     }
00482     while ( str[0] != '}' && n < prModel->GetNoFaces() ) {
00483         fgets( line, 128, fileIn );
00484         sscanf( line, "%s", str );
00485         if ( str[0] == '#' ) continue;
00486 
00487         // Get and set number of vertices
00488         token = strtok( line, delimiters );
00489         numberOfVertices = static_cast<int>( strtol( token, &end, 10 ) );
00490         prModel->GetFaceList()[n].SetNoVertices( numberOfVertices );
00491 
00492         // Set the Xface
00493         for ( int i = 0; i < numberOfVertices; ++i )
00494         {
00495             token = strtok( '\0', delimiters );
00496             vertexNo = static_cast<int>( strtol( token, &end, 10 ) );
00497             prModel->GetFaceList()[n].SetVertexNo( i, vertexNo );
00498             //vertexAt[vertexNo].push_back( i );
00499         }
00500         ++n;
00501     }
00502     prModel->SetNoFaces( n );
00503 }
00504 //=============================================================================
00505 //-----------------------------------------------------------------------------
00506 // Process TextureCoordinates Node
00507 template <typename T>
00508 void ReadTAPs<T>::ProcessNodeTextureCoordinates( char *line, OpenGL::PolygonalModel<T> * const prModel )
00509 {
00510     //Example:
00511     //  TextureCoordinates 2
00512     //  {
00513     //    # Texture Coordinates assigned at face vertices
00514     //    # vertices    s_0    t_0    s_1    t_1    s_2    t_2    s_3    t_3
00515     //    0    4      0.3166 0.6316 0.3441 0.6337 0.3537 0.6127 0.3225 0.6008
00516     //    1    4      0.3015 0.8142 0.3624 0.8094 0.3548 0.7738 0.3012 0.7804
00517     //  }
00518     //Another Example:
00519     //  TextureCoordinates 1
00520     //  {
00521     //    # Texture Coordinates assigned at face vertices
00522     //    # vertices    s_0    t_0    s_1    t_1    s_2    t_2    s_3    t_3
00523     //    0    4        1      0      1      1      0      1      0      0
00524     //  }
00525 
00526     // Set number of (2-D) texture coordinates
00527     int n = 0;
00528     char str[128];
00529     sscanf( line, "%s%d", str, &n );
00530     prModel->SetNoTexCoords( n );
00531 
00532     // Temp Variables
00533     char *delimiters = "\t ";
00534     char *token = NULL;
00535     char *end;
00536     int numberOfTexCoords;
00537     Real s, t;  // texture coordinates
00538     int faceNo;
00539 
00540     // Set texture coordinates of each Xface
00541     n = 0;
00542     while ( str[0] != '{' ) {
00543         fgets( line, 128, fileIn );
00544         sscanf( line, "%s", str );
00545     }
00546     while ( str[0] != '}' && n < prModel->GetNoTexCoords() ) {
00547         fgets( line, 128, fileIn );
00548         sscanf( line, "%s", str );
00549         if ( str[0] == '#' ) continue;
00550 
00551         // Get number of face
00552         token = strtok( line, delimiters );
00553         faceNo = static_cast<int>( strtol( token, &end, 10 ) );
00554         // Get number of texture coordinates
00555         token = strtok( '\0', delimiters );
00556         numberOfTexCoords = static_cast<int>( strtol( token, &end, 10 ) );
00557         prModel->GetFaceList()[faceNo].SetNoTexCoords( numberOfTexCoords );
00558 
00559         // Set the texture coordinates
00560         for ( int i = 0; i < numberOfTexCoords; ++i )
00561         {
00562             token = strtok( '\0', delimiters );
00563             s = static_cast<Real>( strtod( token, &end ) );
00564             token = strtok( '\0', delimiters );
00565             t = static_cast<Real>( strtod( token, &end ) );
00566             prModel->GetFaceList()[faceNo].SetTexCoordNo( i, s, t );
00567         }
00568         ++n;
00569     }
00570     prModel->SetNoTexCoords( n );
00571 }
00572 //-----------------------------------------------------------------------------
00573 // Process TextureCoordinates Node
00574 template <typename T>
00575 void ReadTAPs<T>::ProcessNodeTextureCoordinates( char *line, OpenGL::XPolygonalModel<T> * const prModel )
00576 {
00577     //Example:
00578     //  Texture 2
00579     //  {
00580     //    # Texture Coordinates assigned at face vertices
00581     //    # virtices    s_0    t_0    s_1    t_1    s_2    t_2    s_3    t_3
00582     //    0    4      0.3166 0.6316 0.3441 0.6337 0.3537 0.6127 0.3225 0.6008
00583     //    1    4      0.3015 0.8142 0.3624 0.8094 0.3548 0.7738 0.3012 0.7804
00584     //  }
00585     //Another Example:
00586     //  Texture 1
00587     //  {
00588     //    # Texture Coordinates assigned at face vertices
00589     //    # vertices    s_0    t_0    s_1    t_1    s_2    t_2    s_3    t_3
00590     //    0    4        1      0      1      1      0      1      0      0
00591     //  }
00592 
00593 
00594     // Set number of (2-D) texture coordinates
00595     int n = 0;
00596     char str[128];
00597     sscanf( line, "%s%d", str, &n );
00598     prModel->SetNoTexCoords( n );
00599 
00600     // Temp Variables
00601     char *delimiters = "\t ";
00602     char *token = NULL;
00603     char *end;
00604     int numberOfTexCoords;
00605     Real s, t;  // texture coordinates
00606     int faceNo;
00607 
00608     // Set texture coordinates of each Xface
00609     n = 0;
00610     while ( str[0] != '{' ) {
00611         fgets( line, 128, fileIn );
00612         sscanf( line, "%s", str );
00613     }
00614     while ( str[0] != '}' && n < prModel->GetNoTexCoords() ) {
00615         fgets( line, 128, fileIn );
00616         sscanf( line, "%s", str );
00617         if ( str[0] == '#' ) continue;
00618 
00619         // Get number of face
00620         token = strtok( line, delimiters );
00621         faceNo = static_cast<int>( strtol( token, &end, 10 ) );
00622         // Get number of texture coordinates
00623         token = strtok( '\0', delimiters );
00624         numberOfTexCoords = static_cast<int>( strtol( token, &end, 10 ) );
00625         prModel->GetFaceList()[faceNo].SetNoTexCoords( numberOfTexCoords );
00626 
00627         // Set the texture coordinates
00628         for ( int i = 0; i < numberOfTexCoords; ++i )
00629         {
00630             token = strtok( '\0', delimiters );
00631             s = static_cast<Real>( strtod( token, &end ) );
00632             token = strtok( '\0', delimiters );
00633             t = static_cast<Real>( strtod( token, &end ) );
00634             prModel->GetFaceList()[faceNo].SetTexCoordNo( i, s, t );
00635         }
00636         ++n;
00637     }
00638     prModel->SetNoTexCoords( n );
00639 }
00640 //=============================================================================
00641 //-----------------------------------------------------------------------------
00642 // Process ImageTexture Node
00643 template <typename T>
00644 void ReadTAPs<T>::ProcessNodeImageTexture( char *line, OpenGL::XPolygonalModel<T> * const prModel )
00645 {
00646     // ImageTexture
00647     // {
00648     //    fileName  "../Textures/dg_gallbladder.bmp"
00649     //    repeatS       false
00650     //    repeatT       false
00651     // }
00652     char type[128];
00653     char argument[128];
00654     //char *end;
00655     double r = 0, g = 0, b = 0, a = 0;
00656     sscanf( line, "%s", type );
00657     while ( type[0] != '{' ) {
00658         fgets( line, 128, fileIn );
00659         sscanf( line, "%s", type );
00660     }
00661     while ( type[0] != '}' ) {
00662         fgets( line, 128, fileIn );
00663         sscanf( line, "%s %s", type, argument );
00664         //std::cout << argument << std::endl;
00665         if ( type[0] == '#' ) continue;
00666         if ( !strncmp( type, "fileName", strlen("fileName") ) ) {
00667             prModel->SetImageFileName( argument );
00668             prModel->m_pcImg = new BitmapImage();
00669             if ( prModel->m_pcImg->LoadBitmapFile( argument ) ) {
00670                 //prModel->EnableTexture();
00671             }
00672             else {
00673                 //prModel->m_pcImg.~BitmapImage();
00674                 std::cout << "ReadTAPs: Could not open the bitmap file!" << std::endl;
00675             }
00676         }
00677         else if ( !strncmp( type, "repeatS", strlen("repeatS") ) ) {
00678             //prModel->GetMaterial()->SetDiffuse( r, g, b, a );
00679         }
00680         else if ( !strncmp( type, "repeatT", strlen("repeatT") ) ) {
00681             //prModel->GetMaterial()->SetSpecular( r, g, b, a );
00682         }
00683     }
00684 }
00685 //-----------------------------------------------------------------------------
00686 //=============================================================================
00687 END_NAMESPACE_TAPs
00688 //-----------------------------------------------------------------------------
00689 //345678901234567890123456789012345678901234567890123456789012345678901234567890
00690 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines