Ignore:
Timestamp:
11/20/08 10:12:28 (16 years ago)
Author:
mattausch
Message:

normal mapping hack not working yet. found problems with ssao if the geometry is not tesselated enough (especially with smoothed
normals: one can see the underlying tesselation!

Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter.cpp

    r3128 r3146  
    77 
    88using namespace std; 
     9 
     10//#define USE_TEXTURE 
    911 
    1012 
     
    1820                                                ) 
    1921{ 
    20         vector<char *> substrings; 
     22        vector<string> triples; 
    2123 
    2224        char *next_token; 
     
    2527        char *pch = strtok_s(str + 1, " ", &next_token); 
    2628 
    27         while (pch != NULL) 
    28         { 
    29                 substrings.push_back(pch); 
     29        while (pch) 
     30        { 
     31                string s(pch); 
     32                //s += "\n", 
     33                triples.push_back(s); 
     34                 
    3035                pch = strtok_s(NULL, " ", &next_token);    
    3136        } 
     
    3540        vector<int> tIndices; 
    3641 
    37         for (size_t i = 0; i < substrings.size(); ++ i) 
    38         { 
     42        char seps[] = " /\t\n"; 
     43 
     44        for (size_t i = 0; i < triples.size(); ++ i) 
     45        { 
     46                static int dummy = 0; 
     47 
     48                size_t found; 
     49                found = triples[i].find_first_of(seps); 
     50                size_t prevfound = 0; 
    3951                // vertex, normal, texture indices 
    40                 char *str = strtok_s(substrings[i], "/", &next_token);     
    41                 int index = (int)strtol(str, NULL, 10) - 1; 
     52                string str = triples[i].substr(prevfound, found); 
     53 
     54                int index = (int)strtol(str.c_str(), NULL, 10) - 1; 
    4255 
    4356                int tIndex = index; 
    44                 int nIndex = index; 
    45  
    46                 str = strtok_s(substrings[i], "/", &next_token);           
    47  
    48                 if (str != NULL) 
    49                 { 
    50                         int idx = (int)strtol(str, NULL, 10) - 1; 
    51                         if (idx) tIndex = idx; 
    52                 } 
    53                 str = strtok_s(substrings[i], "/", &next_token);           
    54  
    55                 if (str != NULL) 
    56                 { 
    57                         int idx = (int)strtol(str, NULL, 10) - 1; 
    58                         if (idx) nIndex = idx; 
     57                int nIndex = index;      
     58                 
     59                prevfound = found; 
     60                found = triples[i].find_first_of(seps, found + 1);   
     61 
     62                if (found != string::npos) 
     63                { 
     64                        str = triples[i].substr(prevfound, found); 
     65 
     66                        int idx = (int)strtol(str.c_str(), NULL, 10) - 1; 
     67                        if (idx > 0) tIndex = idx; 
     68                } 
     69 
     70                if ((found + 1) < triples[i].size()) 
     71                { 
     72                        str = triples[i].substr(found + 1); 
     73 
     74                        int idx = (int)strtol(str.c_str(), NULL, 10) - 1; 
     75                        if (idx > 0) nIndex = idx; 
    5976                } 
    6077 
     
    84101                        faceVertices.push_back(vertices[indices[idx3]]); 
    85102 
     103 
    86104                        if (!normals.empty()) 
    87105                        { 
     106                                //if (dummy < 3) cout << nIndices[idx1] << " " << nIndices[idx2] << " " << nIndices[idx3] << endl; 
    88107                                faceNormals.push_back(normals[nIndices[idx1]]); 
    89108                                faceNormals.push_back(normals[nIndices[idx2]]); 
     
    92111                        else 
    93112                        { 
    94                                 // no face normals? 
    95                                 const SimpleTri tri(vertices[indices[idx1]], vertices[indices[idx2]], vertices[indices[idx3]]); 
     113                                // no face normals? => create normals 
     114                                const SimpleTri tri(vertices[indices[idx1]], 
     115                                                        vertices[indices[idx2]],  
     116                                                                        vertices[indices[idx3]]); 
    96117                                const SimpleVec n = tri.GetNormal(); 
    97118 
     
    101122                        } 
    102123 
     124                        ++ dummy; 
    103125                        if (!texcoords.empty()) 
    104126                        { 
     
    150172        for (int i = 0; i < numElements; ++ i) 
    151173        { 
    152 #if 0 
     174#if 1 
    153175                // convert to our camera system: change y and z 
    154176                geom->mVertices[i].x = faceVertices[i].x; 
     
    159181                geom->mNormals[i].y = -faceNormals[i].z; 
    160182                geom->mNormals[i].z = faceNormals[i].y; 
     183 
    161184#else 
    162185                geom->mVertices[i].x = faceVertices[i].x; 
     
    169192 
    170193#endif 
    171                 geom->mVertices[i].x += 470.398f; 
    172                 geom->mVertices[i].y += 240.364f; 
    173                 geom->mVertices[i].z += 182.5f; 
    174194 
    175195                if (i < geom->mTexcoordCount) 
     
    236256 
    237257        int line = 0; 
    238  
    239258        const int len = 10000; 
    240259        char str[len]; 
     
    242261        while (fgets(str, len, file) != NULL) 
    243262        { 
    244 //              if (1)//(line % 100) == 0) 
    245 //                      cout << "read line " << line << " " << str; 
    246                 switch (str[0])  
     263                switch (str[0]) 
    247264                { 
    248265                case 'v': // vertex or normal 
     
    262279                                default: 
    263280                                        sscanf(str + 1, "%f %f %f", &x, &y, &z); 
    264                                         vertices.push_back(SimpleVec(x, y, z)); 
     281                                        const float scale = 5e-3f; 
     282                                        vertices.push_back(SimpleVec(x * scale, y * scale, z* scale)); 
    265283                                        //cout <<"v " << x << " " << y << " "<< z << " "; 
    266284                                } 
     
    305323                        break; 
    306324                default: 
     325                        // throw away line 
    307326                        break; 
    308327                } 
     
    346365        //-- texture 
    347366 
    348         //int texId = -1; 
     367#ifdef USE_TEXTURE 
    349368        int texId = 0; 
     369#else 
     370        int texId = -1; 
     371#endif 
     372 
    350373        str.write(reinterpret_cast<char *>(&texId), sizeof(int)); 
    351374 
    352375        bool alphaTestEnabled = false; 
    353         bool cullFaceEnabled = false; 
    354         //bool cullFaceEnabled = true; 
     376        //bool cullFaceEnabled = false; 
     377        bool cullFaceEnabled = true; 
    355378 
    356379        str.write(reinterpret_cast<char *>(&alphaTestEnabled), sizeof(bool)); 
     
    368391                ambient.x = ambient.y = ambient.z = 0.2f; 
    369392                diffuse.x = diffuse.y = diffuse.z = 1.0f; 
    370                 spec.x   = spec.y   = spec.z   =  .0f; 
     393                spec.x    = spec.y    = spec.z    =  .0f; 
    371394                emm = spec; 
    372395 
     
    391414        //-- write textures 
    392415 
     416#ifdef USE_TEXTURE 
    393417        int textureCount = 1; 
    394         //int textureCount = 0; 
    395  
     418#else 
     419        int textureCount = 0; 
     420#endif 
    396421        ofile.write(reinterpret_cast<char *>(&textureCount), sizeof(int)); 
    397422 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/main.cpp

    r3076 r3146  
    2222                exit(0); 
    2323        } 
    24  
     24        //std::cin.get(); 
    2525        cout << "conversion successful" << endl; 
    2626 
Note: See TracChangeset for help on using the changeset viewer.