Ignore:
Timestamp:
10/06/06 08:59:09 (18 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/src/UnigraphicsParser.cpp

    r1486 r1577  
    5050  map<string, Vector3, ltstr> cht; // hash table for colors 
    5151   
    52   FILE         *file; 
     52  FILE *file; 
    5353  char str[80]; 
    54   Face     *face; 
    55   //Vector3  *vptr; 
    56    
     54  Face *face; 
     55     
    5756  float x,y,z; 
    58   int i; 
     57  //int i; 
    5958   
    6059  if ((file = fopen(filename.c_str(),"rt")) == NULL) 
     
    6665  Environment::GetSingleton()->GetIntValue("Unigraphics.meshGrouping", 
    6766                           meshGrouping); 
    68    
    69   while(fscanf(file,"%s",str)!=EOF) { 
    70     switch (str[0]) { 
    71        
    72     case 'c': 
    73       if (strcmp(str,"c_rgb")==0) 
    74         { 
    75           cout<<"c"; 
    76           cout.flush(); 
    77           /* vertex */ 
    78           fscanf(file,"%s",str); // label 
    79           fscanf(file,"%f %f %f",&x,&y,&z); 
    80            
    81           cht[str] = Vector3(x,y,z); // swap the file coordinates 
    82         } 
    83       break; 
    84        
    85        
    86     case 'v':            // is it v ? 
    87       cout<<"."; 
    88       cout.flush(); 
    89       /* vertex */ 
    90       fscanf(file,"%s",str); // label 
    91       fscanf(file,"%f %f %f",&x,&y,&z); 
    92        
    93       vht[str] = Vector3(x,z,-y); // swap the file coordinates 
    94       //         vptr = new Vector3C(x,y,z); // swap the file coordinates 
    95       break; 
    96        
    97     case 'f': { 
    98       cout<<"+"; 
    99       vector<Vector3> vertices; 
    100       VertexIndexContainer vertexIndices; 
    101  
    102       /* face */ 
    103       fscanf(file,"%s",str); // label may  be ? 
    104       if (str[0]!='(') 
    105         fscanf(file,"%s",str); 
    106        
    107       i = 0;                              // index of the vertex 
    108        
    109        
    110       map<string, Vector3, ltstr>::const_iterator c = vht.find(&str[1]); 
    111        
    112       if (c == vht.end()) { 
    113         cout<<"error reading file : "<< 
    114           filename<<" ---missing vertex:"<<str<<endl; exit(1); 
    115       } 
    116        
    117       vertices.push_back((*c).second); 
    118        
    119       fscanf(file,"%s",str);      // get the vertex label 
    120        
    121       while(str[0]!=')') { 
    122          
    123         c = vht.find(str); 
    124          
    125         if (c == vht.end()) 
     67 
     68  while(fscanf(file,"%s",str)!=EOF)  
     69  { 
     70          switch (str[0])  
    12671          { 
    127             cout<<"error reading file : "<<filename<<" -- missing vertex\n"; 
    128             exit(1);  } 
    129          
    130         vertices.push_back((*c).second); 
    131         fscanf(file,"%s",str);   // get the next vertex label 
    132       } 
    133  
    134       // add vertices to the mesh vertex list 
    135       int index = (int)currentMesh->mVertices.size(); 
    136       for (i=0; i < vertices.size(); i++, index++) { 
    137                 currentMesh->mVertices.push_back(vertices[i]); 
    138                 vertexIndices.push_back(index); 
    139       } 
    140      
    141       face = new Face(vertexIndices); 
    142        
    143       fscanf(file,"%s",str);   // get the next vertex label 
    144      
    145       if (str[0]!=';') { 
    146         c = cht.find(str); 
    147         if (currentMesh->mMaterial == NULL) { 
    148                 Material *mat = MaterialManager::GetSingleton()->CreateResource(); 
    149           if (c != cht.end()) { 
    150             mat->mDiffuseColor = RgbColor((*c).second.x, (*c).second.y, (*c).second.z); 
    151             currentMesh->mMaterial = mat; 
     72          case 'c': 
     73                  if (strcmp(str,"c_rgb")==0) 
     74                  { 
     75                          cout<<"c"; 
     76                          cout.flush(); 
     77                          // vertex 
     78                          fscanf(file,"%s",str); // label 
     79                          fscanf(file,"%f %f %f",&x,&y,&z); 
     80 
     81                          cht[str] = Vector3(x,y,z); // swap the file coordinates 
     82                  } 
     83                  break; 
     84 
     85 
     86          case 'v':            // is it v ? 
     87                  cout<<"."; 
     88                  cout.flush(); 
     89                  // vertex 
     90                  fscanf(file,"%s",str); // label 
     91                  fscanf(file,"%f %f %f",&x,&y,&z); 
     92 
     93                  vht[str] = Vector3(x,z,-y); // swap the file coordinates 
     94                  // vptr = new Vector3C(x,y,z); // swap the file coordinates 
     95                  break; 
     96 
     97          case 'f':  
     98                  { 
     99                          cout << "+"; 
     100                          vector<Vector3> vertices; 
     101                          VertexIndexContainer vertexIndices; 
     102 
     103                          // face 
     104                          fscanf(file,"%s",str); // label may  be ? 
     105                          if (str[0]!='(') 
     106                                  fscanf(file,"%s",str); 
     107 
     108                           map<string, Vector3, ltstr>::const_iterator c = vht.find(&str[1]); 
     109 
     110                          if (c == vht.end())  
     111                          { 
     112                                  cout<<"error reading file : "<< filename  
     113                                          <<" ---missing vertex:"<<str<<endl; exit(1); 
     114                          } 
     115 
     116                          vertices.push_back((*c).second); 
     117 
     118                          fscanf(file,"%s",str); // get the vertex label 
     119 
     120                          while(str[0]!=')')  
     121                          { 
     122                                  c = vht.find(str); 
     123                                  if (c == vht.end()) 
     124                                  { 
     125                                        cout << "error reading file : " << filename << " -- missing vertex\n"; 
     126                                        exit(1);   
     127                                } 
     128 
     129                                vertices.push_back((*c).second); 
     130                                fscanf(file,"%s",str); // get the next vertex label 
     131                        } 
     132 
     133                        // add vertices to the mesh vertex list 
     134                        int index = (int)currentMesh->mVertices.size(); 
     135 
     136                        for (int i=0; i < (int)vertices.size(); ++ i, ++ index)  
     137                        { 
     138                                currentMesh->mVertices.push_back(vertices[i]); 
     139                                vertexIndices.push_back(index); 
     140                        } 
     141 
     142                        face = new Face(vertexIndices); 
     143 
     144                        fscanf(file,"%s",str);   // get the next vertex label 
     145 
     146                        if (str[0]!=';')  
     147                        { 
     148                                c = cht.find(str); 
     149                                if (currentMesh->mMaterial == NULL)  
     150                                { 
     151                                        Material *mat = MaterialManager::GetSingleton()->CreateResource(); 
     152                                        if (c != cht.end())  
     153                          { 
     154                                  mat->mDiffuseColor = RgbColor((*c).second.x, (*c).second.y, (*c).second.z); 
     155                                  currentMesh->mMaterial = mat; 
     156                          } 
     157                                        else 
     158                          { 
     159                                  currentMesh->AssignRandomMaterial(); 
     160                          } 
     161                                } 
     162                        } 
     163 
     164                        currentMesh->AddFace(face); 
     165                        if (meshGrouping != 0 && currentMesh->mFaces.size() >=  meshGrouping)  
     166                        { 
     167                                if (ROTATE_SCENE) 
     168                                { 
     169                                        RotateMesh(currentMesh); 
     170                                } 
     171 
     172                                currentMesh->Preprocess(); 
     173                                // make an instance of this mesh 
     174                                MeshInstance *mi = new MeshInstance(currentMesh); 
     175                                root->mGeometry.push_back(mi);   
     176                                currentMesh = MeshManager::GetSingleton()->CreateResource(); 
     177                        } 
     178                } 
     179                break; 
     180        }      /* end face */ 
     181 
     182        // get the rest of the line 
     183        fgets(str,80,file); 
     184  } 
     185 
     186  if (!currentMesh->mVertices.empty())  
     187  { 
     188          if (ROTATE_SCENE)  
     189          { 
     190                  RotateMesh(currentMesh); 
    152191          } 
    153           else 
    154             currentMesh->AssignRandomMaterial(); 
    155         } 
    156       } 
    157        
    158       currentMesh->AddFace(face); 
    159       if (meshGrouping != 0 && currentMesh->mFaces.size() >=  meshGrouping) { 
    160                 if (ROTATE_SCENE) 
    161                         RotateMesh(currentMesh); 
    162  
    163                 currentMesh->Preprocess(); 
    164                 // make an instance of this mesh 
    165                 MeshInstance *mi = new MeshInstance(currentMesh); 
    166                 root->mGeometry.push_back(mi);   
    167                 currentMesh = MeshManager::GetSingleton()->CreateResource(); 
    168       } 
    169     } 
    170     break; 
    171     }      /* end face */ 
    172      
    173     // get the rest of the line 
    174     fgets(str,80,file); 
    175   } 
    176    
    177   if (currentMesh->mVertices.size())  
    178   { 
    179           if (ROTATE_SCENE) RotateMesh(currentMesh); 
    180   
     192 
    181193          currentMesh->Preprocess(); 
    182194          MeshInstance *mi = new MeshInstance(currentMesh); 
    183195          root->mGeometry.push_back(mi); 
    184196  } 
    185    
     197 
    186198  fclose(file); 
    187199  return true; 
Note: See TracChangeset for help on using the changeset viewer.