Ignore:
Timestamp:
10/08/08 10:45:08 (16 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter
Files:
4 added
3 edited

Legend:

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

    r2965 r3012  
    11#include "ObjConverter.h" 
     2#include "SimpleTri.h" 
     3#include "SimpleVec.h" 
    24#include "gzstream.h" 
    35#include <iostream> 
     
    3537        for (size_t i = 0; i < substrings.size(); ++ i) 
    3638        { 
    37                 // vertex, normal and texture indices 
     39                // vertex, normal, texture indices 
    3840                char *str = strtok_s(substrings[i], "/", &next_token);     
    3941                int index = (int)strtol(str, NULL, 10) - 1; 
     
    4244                int nIndex = index; 
    4345 
    44                 /*str = strtok_s(substrings[i], "/", &next_token);         
    45                 int tIndex = (int)strtol(str, NULL, 10) - 1; 
    46  
    4746                str = strtok_s(substrings[i], "/", &next_token);           
    48                 int nIndex = (int)strtol(str, NULL, 10) - 1; 
    49 */ 
     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; 
     59                } 
     60 
    5061                // store indices 
    5162                if (index >= 0) 
     
    5970                if (indices.size() > 2) 
    6071                { 
    61 #if 1 
     72#if 0 
    6273                        int idx1 = 0; 
    6374                        int idx2 = (int)indices.size() - 2; 
     
    7182                        faceVertices.push_back(vertices[indices[idx2]]); 
    7283                        faceVertices.push_back(vertices[indices[idx3]]); 
    73          
    74                         Vector3 dummy(1, 0, 0); 
    75                         faceNormals.push_back(dummy); 
    76                         faceNormals.push_back(dummy); 
    77                         faceNormals.push_back(dummy); 
    78  
    79                         /* 
    80                         const Vector3 v2 = mVertices[2] - mVertices[1]; 
    81                         Normalize(CrossProd(v2, v1)); 
    82  
    83                         faceNormals.push_back(normals[nIndices[idx1]]); 
    84                         faceNormals.push_back(normals[nIndices[idx2]]); 
    85                         faceNormals.push_back(normals[nIndices[idx3]]); 
    86  
    87                         faceTexcoords.push_back(texcoords[tIndices[idx1]]); 
    88                         faceTexcoords.push_back(texcoords[tIndices[idx2]]); 
    89                         faceTexcoords.push_back(texcoords[tIndices[idx3]]); 
    90                         */ 
     84 
     85                        if (!normals.empty()) 
     86                        { 
     87                                faceNormals.push_back(normals[nIndices[idx1]]); 
     88                                faceNormals.push_back(normals[nIndices[idx2]]); 
     89                                faceNormals.push_back(normals[nIndices[idx3]]); 
     90                        } 
     91                        else 
     92                        { 
     93                                // no face normals? 
     94                                const SimpleTri tri(vertices[indices[idx1]], vertices[indices[idx2]], vertices[indices[idx3]]); 
     95                                const SimpleVec n = tri.GetNormal(); 
     96 
     97                                faceNormals.push_back(n); 
     98                                faceNormals.push_back(n); 
     99                                faceNormals.push_back(n); 
     100                        } 
     101 
     102                        if (!texcoords.empty()) 
     103                        { 
     104                                faceTexcoords.push_back(texcoords[tIndices[idx1]]); 
     105                                faceTexcoords.push_back(texcoords[tIndices[idx2]]); 
     106                                faceTexcoords.push_back(texcoords[tIndices[idx3]]); 
     107                        } 
    91108                } 
    92109        } 
     
    121138 
    122139        // convert the triangles to geometry 
    123         geom->mVertices = new Vector3[numElements]; 
    124         geom->mNormals = new Vector3[numElements]; 
     140        geom->mVertices = new SimpleVec[numElements]; 
     141        geom->mNormals = new SimpleVec[numElements]; 
    125142        geom->mTexcoords = new Texcoord[numElements]; 
    126143 
     
    132149        for (int i = 0; i < numElements; ++ i) 
    133150        { 
     151#if 0 
    134152                geom->mVertices[i].x = faceVertices[i].x; 
    135153                geom->mVertices[i].y = -faceVertices[i].z; 
    136154                geom->mVertices[i].z = faceVertices[i].y; 
    137  
     155         
    138156                geom->mNormals[i].x = faceNormals[i].x; 
    139157                geom->mNormals[i].y = -faceNormals[i].z; 
    140158                geom->mNormals[i].z = faceNormals[i].y; 
    141  
     159#else 
     160                geom->mVertices[i].x = faceVertices[i].x; 
     161                geom->mVertices[i].y = faceVertices[i].y; 
     162                geom->mVertices[i].z = faceVertices[i].z; 
     163         
     164                geom->mNormals[i].x = faceNormals[i].x; 
     165                geom->mNormals[i].y = faceNormals[i].y; 
     166                geom->mNormals[i].z = faceNormals[i].z; 
     167 
     168#endif 
    142169                if (i < geom->mTexcoordCount) 
    143170                { 
     
    220247                                case 'n' : 
    221248                                        sscanf(str + 2, "%f %f %f", &x, &y, &z); 
    222                                         normals.push_back(Vector3(x, y, z)); 
     249                                        normals.push_back(SimpleVec(x, y, z)); 
    223250                                        break; 
    224251                                case 't': 
     
    228255                                default: 
    229256                                        sscanf(str + 1, "%f %f %f", &x, &y, &z); 
    230                                         vertices.push_back(Vector3(x, y, z)); 
     257                                        vertices.push_back(SimpleVec(x, y, z)); 
    231258                                        //cout <<"v " << x << " " << y << " "<< z << " "; 
    232259                                } 
     
    242269                                                faceVertices, faceNormals, faceTexcoords); 
    243270 
    244                                 if (((line % 1000) == 999) &&  
    245                                         !faceVertices.empty()) 
     271                                if (0 && 
     272                                        (((line % 1000) == 999) && !faceVertices.empty())) 
    246273                                { 
    247274                                        ++ mNumShapes; 
     
    299326        str.write(reinterpret_cast<char *>(&vertexCount), sizeof(int)); 
    300327   
    301         str.write(reinterpret_cast<char *>(geom->mVertices), sizeof(Vector3) * vertexCount); 
    302         str.write(reinterpret_cast<char *>(geom->mNormals), sizeof(Vector3) * vertexCount); 
     328        str.write(reinterpret_cast<char *>(geom->mVertices), sizeof(SimpleVec) * vertexCount); 
     329        str.write(reinterpret_cast<char *>(geom->mNormals), sizeof(SimpleVec) * vertexCount); 
    303330 
    304331        int texCoordCount = geom->mTexcoordCount; 
     
    330357        if (hasMaterial) 
    331358        { 
    332                 Vector3 ambient, diffuse, black; 
     359                SimpleVec ambient, diffuse, black; 
    333360 
    334361                ambient.x = ambient.y = ambient.z = 0.2f; 
     
    337364 
    338365                // only write rgb part of the material 
    339                 str.write(reinterpret_cast<char *>(&ambient), sizeof(Vector3)); 
    340                 str.write(reinterpret_cast<char *>(&diffuse), sizeof(Vector3)); 
    341                 str.write(reinterpret_cast<char *>(&black), sizeof(Vector3)); 
    342                 str.write(reinterpret_cast<char *>(&black), sizeof(Vector3)); 
     366                str.write(reinterpret_cast<char *>(&ambient), sizeof(SimpleVec)); 
     367                str.write(reinterpret_cast<char *>(&diffuse), sizeof(SimpleVec)); 
     368                str.write(reinterpret_cast<char *>(&black), sizeof(SimpleVec)); 
     369                str.write(reinterpret_cast<char *>(&black), sizeof(SimpleVec)); 
    343370        } 
    344371} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter.h

    r2961 r3012  
    22#define _OBJCONVERTER_H 
    33 
     4#include "SimpleVec.h" 
    45#include <string> 
    56#include <vector> 
    67 
    7 struct Vector3 
     8/*struct SimpleVec 
    89{ 
    9         Vector3() {} 
    10         Vector3(float _x, float _y, float _z): x(_x), y(_y), z(_z) {} 
     10        SimpleVec() {} 
     11        SimpleVec(float _x, float _y, float _z): x(_x), y(_y), z(_z) {} 
    1112 
    1213        float x, y, z; 
    13 }; 
     14};*/ 
    1415 
    15 typedef std::vector<Vector3> VertexArray; 
     16typedef std::vector<SimpleVec> VertexArray; 
    1617typedef std::pair<float, float> Texcoord; 
    1718 
     
    3637        struct Geometry 
    3738        { 
    38                 Vector3 *mVertices; 
    39                 Vector3 *mNormals; 
     39                SimpleVec *mVertices; 
     40                SimpleVec *mNormals; 
    4041                Texcoord *mTexcoords; 
    4142 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/main.cpp

    r2963 r3012  
    1515        cout << "converting obj to dem format" << endl; 
    1616 
    17 /*      if (!converter.Convert(model_path + argv[1], model_path + argv[2])) 
     17        if (!converter.Convert(model_path + argv[1], model_path + argv[2])) 
    1818        { 
    1919                cerr << "conversion failed" << endl; 
    2020                exit(0); 
    2121        } 
    22 */ 
    23         //if (!converter.Convert(model_path + "toyplane.obj", model_path + "toyplane.dem")) 
    24         //      cerr << "conversion failed" << endl; 
    25  
    26         //if (!converter.Convert(model_path + "sky.obj", model_path + "sky.dem")) 
    27         //      cerr << "conversion failed" << endl; 
    28  
    29         if (!converter.Convert(model_path + "city_full.obj", model_path + "city_full.dem")) 
    30                 cerr << "conversion failed" << endl; 
    3122 
    3223        cout << "conversion successful" << endl; 
Note: See TracChangeset for help on using the changeset viewer.