Changeset 3358 for GTP


Ignore:
Timestamp:
04/16/09 18:55:13 (15 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling
Files:
8 edited

Legend:

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

    r3342 r3358  
    1414                                                const VertexArray &vertices,  
    1515                                                const VertexArray &normals,  
    16                                                 const vector<pair<float, float> > &texcoords, 
     16                                                const TexcoordArray &texcoords, 
    1717                                                VertexArray &faceVertices, 
    1818                                                VertexArray &faceNormals, 
    19                                                 vector<Texcoord> &faceTexcoords 
     19                                                TexcoordArray &faceTexcoords 
    2020                                                ) 
    2121{ 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter.h

    r3261 r3358  
    2323typedef std::map<std::string, Material *> MaterialTable; 
    2424typedef std::map<std::string, int> TextureTable; 
    25  
     25typedef std::vector<Texcoord> TexcoordArray; 
    2626typedef std::vector<std::string> TextureArray; 
    2727 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter2.cpp

    r3342 r3358  
    1212                                                const VertexArray &vertices,  
    1313                                                const VertexArray &normals,  
    14                                                 const vector<Texcoord> &texcoords, 
     14                                                const TexcoordArray &texcoords, 
    1515                                                VertexArray &faceVertices, 
    1616                                                VertexArray &faceNormals, 
    17                                                 vector<Texcoord> &faceTexcoords 
     17                                                TexcoordArray &faceTexcoords 
    1818                                                ) 
    1919{ 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter2.h

    r3261 r3358  
    2323typedef std::map<std::string, Material *> MaterialTable; 
    2424typedef std::map<std::string, int> TextureTable; 
    25  
     25typedef std::vector<Texcoord> TexcoordArray; 
    2626typedef std::vector<std::string> TextureArray; 
    2727 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/PlyConverter.cpp

    r3357 r3358  
    1414VertexArray sVertices; 
    1515VertexArray sNormals; 
     16FaceArray sFaces; 
     17 
    1618 
    1719 
     
    2325 
    2426 
    25 void PlyConverter::LoadShape(const VertexArray &faceVertices, 
    26                                                          const VertexArray &faceNormals, 
    27                                                          const vector<Texcoord> &faceTexcoords 
     27void PlyConverter::LoadShape(const VertexArray &vertices, 
     28                                                         const VertexArray &normals, 
     29                                                         const TexcoordArray &texcoords, 
     30                                                         const FaceArray &faces 
    2831                                                         ) 
    2932{ 
    30         int numElements = (int)faceVertices.size(); 
    3133        Geometry *geom = new Geometry(); 
    32 /* 
    33         // convert the triangles to geometry 
    34         geom->mVertices = new SimpleVec[numElements]; 
    35         geom->mNormals = new SimpleVec[numElements]; 
    36         geom->mTexcoords = new Texcoord[numElements]; 
    37  
    38         geom->mVertexCount = numElements; 
    39         geom->mTexcoordCount = (int)faceTexcoords.size(); 
    40  
    41         cout << "creating new geometry with " << numElements << " vertices" << endl; 
    42  
    43         for (int i = 0; i < numElements; ++ i) 
    44         { 
    45                 geom->mVertices[i] = faceVertices[i] 
    46                 geom->mNormals[i] = faceNormals[i]; 
    47  
    48                 /*if (i < geom->mTexcoordCount) 
     34        size_t idx = 0; 
     35 
     36        for (size_t i = 0; i < faces.size(); ++ i) 
     37        { 
     38                if (i % 1000 == 0) 
     39                        cout << "converted " << i << " lines" << endl; 
     40 
     41                Face face = faces[i]; 
     42 
     43                //cout << "size: " << face.indices.size() << endl; 
     44                for (size_t j = 0; j < face.indices.size(); ++ j) 
    4945                { 
    50                         geom->mTexcoords[i].first = faceTexcoords[i].first; 
    51                         geom->mTexcoords[i].second = faceTexcoords[i].second; 
     46                        geom->mVertices.push_back(vertices[faces[i].indices[j]]); 
     47 
     48                        /*if (!normals.empty()) 
     49                        { 
     50                                for (int j = 0; j < 3; ++ j) 
     51                                        faceNormals.push_back(Normalize(normals[nIndices[idx[j]]])); 
     52                        } 
     53                        else 
     54                        { 
     55                                // no face normals? => create normals 
     56                                const SimpleTri tri(vertices[indices[idx[0]]], 
     57                                                        vertices[indices[idx[1]]],  
     58                                                                        vertices[indices[idx[2]]]); 
     59 
     60                                const SimpleVec n = tri.GetNormal(); 
     61 
     62                                faceNormals.push_back(n); 
     63                                faceNormals.push_back(n); 
     64                                faceNormals.push_back(n); 
     65                        }*/ 
    5266                } 
    53         } 
    54 */ 
     67 
     68                //cout << "idx: " << idx << " " << geom->mVertices.size() << endl; 
     69 
     70                // no face normals? => create normals 
     71                const SimpleTri tri(geom->mVertices[idx], 
     72                                        geom->mVertices[idx + 1],  
     73                                                        geom->mVertices[idx + 2]); 
     74 
     75                const SimpleVec n = tri.GetNormal(); 
     76 
     77                geom->mNormals.push_back(n); 
     78                geom->mNormals.push_back(n); 
     79                geom->mNormals.push_back(n); 
     80 
     81                idx += faces[i].indices.size(); 
     82        } 
     83 
    5584        mGeometry.push_back(geom); 
     85        mNumShapes = 1; 
    5686} 
    5787 
     
    86116    ply_get_argument_user_data(argument, NULL, &eol); 
    87117 
    88         static int mainIndex = 0; 
     118        static SimpleVec v; 
    89119        static int i = 0; 
    90120 
    91         static SimpleVec v; 
    92  
    93         v[i] = (float)ply_get_argument_value(argument); 
     121        v[i ++] = (float)ply_get_argument_value(argument); 
    94122        //printf("here3 %g", ply_get_argument_value(argument)); 
    95123     
    96         if (eol) sVertices.push_back(v); 
    97         i = (i + 1) % 3; 
    98         //else printf(" "); 
     124        if (eol) 
     125        { 
     126                sVertices.push_back(v); 
     127                if (sVertices.size() % 10000 == 0) cout << "read in " << sVertices.size() << " vertices" << endl; 
     128                i = 0; 
     129        } 
    99130     
    100131        return 1; 
     
    107138    ply_get_argument_property(argument, NULL, &length, &value_index); 
    108139 
     140        static Face face; 
     141         
    109142        switch (value_index)  
    110143        { 
    111144        case 0: 
    112145        case 1:  
    113             printf("here4 %g ", ply_get_argument_value(argument)); 
     146            //printf("here4 %g ", ply_get_argument_value(argument)); 
     147                        face.indices.push_back((int)ply_get_argument_value(argument)); 
    114148            break; 
    115149        case 2: 
    116             printf("here5 %g\n", ply_get_argument_value(argument)); 
     150            //printf("here5 %g\n", ply_get_argument_value(argument)); 
     151                        face.indices.push_back((int)ply_get_argument_value(argument)); 
     152                        sFaces.push_back(face); 
     153                        if (sFaces.size() % 10000 == 0) cout << "read in " << sFaces.size() << " faces" << endl; 
     154 
     155                        face.indices.clear(); 
    117156            break; 
    118157        default:  
    119158            break; 
    120159    } 
     160 
     161 
    121162    return 1; 
    122163} 
     
    140181        ntriangles = ply_set_read_cb(ply, "face", "vertex_indices", face_cb, NULL, 0); 
    141182 
    142     printf("%ld\n%ld\n", nvertices, ntriangles); 
    143  
    144     if (!ply_read(ply)) return 1; 
     183        cout << "vertices: " << nvertices << endl; 
     184        cout << "triangles: " << ntriangles << endl; 
     185 
     186    if (!ply_read(ply)) return false; 
    145187    ply_close(ply); 
    146188 
    147     return 0; 
     189        TexcoordArray texCoords; 
     190        LoadShape(sVertices, sNormals, texCoords, sFaces); 
     191 
     192    return true; 
    148193} 
    149194 
     
    152197void PlyConverter::WriteGeometry(ogzstream &str, Geometry *geom) 
    153198{ 
    154         int vertexCount = (int)geom->mVertices.size(); 
     199        size_t vertexCount = (int)geom->mVertices.size(); 
    155200        str.write(reinterpret_cast<char *>(&vertexCount), sizeof(int)); 
    156    
    157         SimpleVec hvertices[3]; 
    158         SimpleVec hnormals[3]; 
    159  
    160         for (int i = 0; i < 3; ++ i) 
    161         { 
    162                 hvertices[i] = geom->mVertices[i]; 
    163                 hnormals[i] = geom->mNormals[i]; 
    164         } 
     201 
     202        cout << "writing geometry" << endl; 
     203 
     204        //SimpleVec vertices = new SimpleVec[vertexCount]; 
     205        //for (size_t i = 0; i < vertexCount; ++ i) vertices[i] = geom->mVertices[i]; 
     206        //for (size_t i = 0; i < vertexCount; ++ i) vertices[i] = geom->mNormals[i]; 
     207 
     208        for (size_t i = 0; i < vertexCount; ++ i) 
     209                str.write(reinterpret_cast<char *>(&geom->mVertices[i]), sizeof(SimpleVec)); 
     210 
     211        for (size_t i = 0; i < vertexCount; ++ i) 
     212                str.write(reinterpret_cast<char *>(&geom->mNormals[i]), sizeof(SimpleVec)); 
     213 
     214        cout << "finished writing geometry" << endl; 
     215        //if (texCoordCount) str.write(reinterpret_cast<char *>(geom->mTexcoords), sizeof(float) * texCoordCount * 2); 
     216 
     217        cout << "here34 " << geom->mNormals.back() << endl; 
    165218 
    166219        int texCoordCount = 0; 
    167  
    168         str.write(reinterpret_cast<char *>(hvertices), sizeof(SimpleVec) * vertexCount); 
    169         str.write(reinterpret_cast<char *>(hnormals), sizeof(SimpleVec) * vertexCount); 
    170220        str.write(reinterpret_cast<char *>(&texCoordCount), sizeof(int)); 
    171221 
     
    177227{ 
    178228        ogzstream ofile(filename.c_str()); 
    179  
    180229        if (!ofile.is_open()) return false; 
    181230         
     231 
     232        mNumShapes = (int)mGeometry.size(); 
    182233 
    183234        ///////// 
     
    218269        { 
    219270                WriteGeometry(ofile, *it); 
     271 
     272 
     273                /////// 
     274                //-- texture 
     275 
     276                int texId = 0; 
     277                ofile.write(reinterpret_cast<char *>(&texId), sizeof(int)); 
     278 
     279                bool alphaTestEnabled = false; 
     280                //bool cullFaceEnabled = false; 
     281                bool cullFaceEnabled = true; 
     282 
     283                ofile.write(reinterpret_cast<char *>(&alphaTestEnabled), sizeof(bool)); 
     284                ofile.write(reinterpret_cast<char *>(&cullFaceEnabled), sizeof(bool)); 
     285 
     286                // material 
     287                bool hasMaterial = false; 
     288                ofile.write(reinterpret_cast<char *>(&hasMaterial), sizeof(bool)); 
    220289        } 
    221290 
     
    238307        float dist = 0; 
    239308        ofile.write(reinterpret_cast<char *>(&dist), sizeof(float)); 
    240  
    241309        ofile.write(reinterpret_cast<char *>(&mNumShapes), sizeof(int)); 
     310         
    242311 
    243312        // all shapes belong to this scene entity 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/PlyConverter.h

    r3357 r3358  
    1313typedef std::vector<SimpleVec> VertexArray; 
    1414typedef std::pair<float, float> Texcoord; 
    15 typedef std::vector<SimpleVec> TexcoordArray; 
     15typedef std::vector<Texcoord> TexcoordArray; 
    1616typedef std::map<std::string, int> TextureTable; 
    1717typedef std::vector<std::string> TextureArray; 
     18 
     19 
     20struct Face 
     21{ 
     22        std::vector<int> indices; 
     23}; 
     24 
     25 
     26typedef std::vector<Face> FaceArray; 
     27 
    1828 
    1929 
     
    3747protected: 
    3848 
    39         void LoadShape(const VertexArray &faceVertices, 
    40                            const VertexArray &faceNormals, 
    41                                    const std::vector<Texcoord> &faceTexcoords 
     49        void LoadShape(const VertexArray &vertices, 
     50                                   const VertexArray &normals, 
     51                                   const TexcoordArray &texcoords, 
     52                                   const FaceArray &faces 
    4253                                   ); 
    4354 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp

    r3274 r3358  
    346346        int vertexCount; 
    347347        str.read(reinterpret_cast<char *>(&vertexCount), sizeof(int)); 
    348          
     348        cout << "vertices: " << vertexCount << endl; 
     349 
    349350        // end of file reached 
    350351        if (str.eof()) return NULL; 
     
    381382                texcoords = NULL; 
    382383        } 
     384 
     385        cout << "here3: " << normals[vertexCount-1] << endl; 
     386        cout << "texCoordCount: " << texCoordCount << endl; 
     387 
    383388 
    384389        const bool delGeometry = true; 
     
    415420        igzstream istr(filename.c_str()); 
    416421         
    417         if (!istr.is_open()) 
    418                 return 0; 
    419  
     422        if (!istr.is_open()) return 0; 
     423 
     424        cout << "here7" << endl; 
    420425        cout << "loading textures" << endl; 
    421426         
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r3353 r3358  
    656656        Matrix4x4 transl = TranslationMatrix(positions[0]); 
    657657         
    658         LoadModel("hbuddha.dem", dynamicObjects); 
     658        //LoadModel("hbuddha.dem", dynamicObjects); 
     659        //LoadModel("horse.dem", dynamicObjects); 
     660        LoadModel("happy.dem", dynamicObjects); 
    659661        //LoadModel("torus.dem", dynamicObjects); 
    660662        //LoadModel("venusm.dem", dynamicObjects); 
Note: See TracChangeset for help on using the changeset viewer.