Ignore:
Timestamp:
09/18/06 18:57:34 (18 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

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

    r1404 r1415  
    220220void X3dParseHandlers::EndShape() 
    221221{ 
    222          //-- if shape is merely a definition => don't create particular mesh instance 
    223          if (!mCurrentMesh || mIsMeshDefinition)  
    224          {  
    225                  return; 
    226          } 
    227  
    228          //////////////////////////////////// 
    229          //-- each triangle is one single mesh 
    230  
    231          if (!mLoadMeshes) 
    232          { 
    233                  cout << "m";    
    234                  Mesh tempMesh(*mCurrentMesh); 
    235                  ApplyTransformations(mTransformations, &tempMesh); 
    236  
    237                  FaceContainer::const_iterator fit, fit_end = tempMesh.mFaces.end(); 
    238                  
    239                  for (fit = tempMesh.mFaces.begin(); fit != fit_end; ++ fit) 
    240                  { 
    241                          cout << "f"; 
    242                          // triangulate the faces 
    243                          Face *face = *fit; 
    244                          vector<Triangle3> triangles; 
    245                          Polygon3 poly(face, &tempMesh); 
    246                          poly.Triangulate(triangles); 
    247  
    248                          vector<Triangle3>::const_iterator tit, tit_end = triangles.end(); 
    249  
    250                          for (tit = triangles.begin(); tit != tit_end; ++ tit) 
    251                          { 
    252                                  //cout << "triangle: " << *tit << endl; 
    253                                  TriangleIntersectable *ti = new TriangleIntersectable(*tit); 
    254                                  mCurrentNode->mGeometry.push_back(ti); 
    255                          } 
     222        ////////////// 
     223        //-- shape is only a definition =>  
     224        //-- don't create particular mesh instance 
     225 
     226        if (!mCurrentMesh || mIsMeshDefinition)  
     227        {  
     228                return; 
     229        } 
     230 
     231        if (!mLoadMeshes) 
     232        { 
     233                //////////////////////////////////// 
     234                //-- load data as single triangles instead of whole meshes 
     235 
     236                //cout << "m";   
     237                Mesh tempMesh(*mCurrentMesh); 
     238                ApplyTransformations(mTransformations, &tempMesh); 
     239 
     240                FaceContainer::const_iterator fit, fit_end = tempMesh.mFaces.end(); 
     241 
     242                for (fit = tempMesh.mFaces.begin(); fit != fit_end; ++ fit) 
     243                { 
     244                        //cout << "f"; 
     245                        // triangulate the faces 
     246                        Face *face = *fit; 
     247                        vector<Triangle3> triangles; 
     248                        Polygon3 poly(face, &tempMesh); 
     249                        poly.Triangulate(triangles); 
     250 
     251                        vector<Triangle3>::const_iterator tit, tit_end = triangles.end(); 
     252 
     253                        for (tit = triangles.begin(); tit != tit_end; ++ tit) 
     254                        { 
     255                                //cout << "triangle: " << *tit << endl; 
     256                                TriangleIntersectable *ti = new TriangleIntersectable(*tit); 
     257                                mCurrentNode->mGeometry.push_back(ti); 
     258                        } 
    256259#if 0 
    257                          // we create a new mesh for each face from the current mesh 
    258                          Mesh *mesh = MeshManager::GetSingleton()->CreateResource(); 
    259                          
    260                          VertexIndexContainer::const_iterator vit, vit_end = face->mVertexIndices.end(); 
    261                  
    262                          int i = 0; 
    263                          // dummy vertex indices container 
    264                          VertexIndexContainer vcIndices; 
    265  
    266                          for (vit = face->mVertexIndices.begin(); vit != vit_end; ++ vit, ++ i) 
    267                          { 
    268                                  cout << "i"; 
    269                                  const int index = (*vit); 
    270                                  // add vertices 
    271                                  mesh->mVertices.push_back(mCurrentMesh->mVertices[index]); 
    272                                  // indices don't make much sense if mesh == face, but we need them anyway ... 
    273                                  vcIndices.push_back(i); 
    274                          } 
    275  
    276                          mesh->mFaces.push_back(new Face(vcIndices)); 
    277  
    278                          // write transformations directly into the mesh 
    279                          // note: could be transformed in parent mesh, save some transformations 
    280                          ApplyTransformations(mTransformations, mesh); 
    281  
    282                          mesh->Preprocess(); 
    283                                  
    284                          if (mesh->mFaces.empty()) 
    285                          { 
    286                                  cout << "error: empy mesh" << endl; 
    287                          } 
    288                          else 
    289                          { 
    290                                  // make an instance of this mesh 
    291                                  MeshInstance *mi = new MeshInstance(mesh); 
    292                                  mCurrentNode->mGeometry.push_back(mi); 
    293  
    294                                  if (mCurrentMaterial && !mCurrentMesh->mMaterial) 
    295                                  { 
    296                                          // HACK: add the material to the mesh directly if no material yet 
    297                                          mCurrentMesh->mMaterial = mCurrentMaterial; 
    298                                  } 
    299                          } 
     260                        // we create a new mesh for each face from the current mesh 
     261                        Mesh *mesh = MeshManager::GetSingleton()->CreateResource(); 
     262 
     263                        VertexIndexContainer::const_iterator vit, vit_end = face->mVertexIndices.end(); 
     264 
     265                        int i = 0; 
     266                        // dummy vertex indices container 
     267                        VertexIndexContainer vcIndices; 
     268 
     269                        for (vit = face->mVertexIndices.begin(); vit != vit_end; ++ vit, ++ i) 
     270                        { 
     271                                cout << "i"; 
     272                                const int index = (*vit); 
     273                                // add vertices 
     274                                mesh->mVertices.push_back(mCurrentMesh->mVertices[index]); 
     275                                // indices don't make much sense if mesh == face, but we need them anyway ... 
     276                                vcIndices.push_back(i); 
     277                        } 
     278 
     279                        mesh->mFaces.push_back(new Face(vcIndices)); 
     280 
     281                        // write transformations directly into the mesh 
     282                        // note: could be transformed in parent mesh, save some transformations 
     283                        ApplyTransformations(mTransformations, mesh); 
     284 
     285                        mesh->Preprocess(); 
     286 
     287                        if (mesh->mFaces.empty()) 
     288                        { 
     289                                cout << "error: empy mesh" << endl; 
     290                        } 
     291                        else 
     292                        { 
     293                                // make an instance of this mesh 
     294                                MeshInstance *mi = new MeshInstance(mesh); 
     295                                mCurrentNode->mGeometry.push_back(mi); 
     296 
     297                                if (mCurrentMaterial && !mCurrentMesh->mMaterial) 
     298                                { 
     299                                        // HACK: add the material to the mesh directly if no material yet 
     300                                        mCurrentMesh->mMaterial = mCurrentMaterial; 
     301                                } 
     302                        } 
    300303#endif 
    301                  } 
    302  
    303                  // this mesh is not needed, unless it is used as a definition 
    304                  if (!mUsingMeshDefinition) 
    305                  { 
    306                          MeshManager::GetSingleton()->DestroyEntry(mCurrentMesh->GetId()); 
    307                  } 
     304                } 
     305 
     306                // this mesh is not needed, unless it is used as a definition 
     307                if (!mUsingMeshDefinition) 
     308                { 
     309                        MeshManager::GetSingleton()->DestroyEntry(mCurrentMesh->GetId()); 
     310                } 
    308311        } 
    309312        else // default usage: create a mesh instance from the current mesh 
     
    321324                else 
    322325                { 
    323                          // make an instance of this mesh 
     326                        // make an instance of this mesh 
    324327                        TransformedMeshInstance *tmi = new TransformedMeshInstance(mCurrentMesh); 
    325328 
    326                          // apply transformation on the instance of the mesh  
    327                          ApplyTransformations(mTransformations, tmi); 
    328                          mi = tmi; 
    329                 } 
    330                          
     329                        // apply transformation on the instance of the mesh  
     330                        ApplyTransformations(mTransformations, tmi); 
     331                        mi = tmi; 
     332                } 
     333 
    331334                if (mCurrentMaterial) 
    332335                { 
     
    341344                        } 
    342345                } 
    343                  
     346 
    344347                // create local mesh kd tree 
    345348                mCurrentMesh->Preprocess(); 
     
    368371 
    369372        VertexIndexContainer vertices; 
    370    
     373 
    371374        mIsMeshDefinition = false; 
    372375        mUsingMeshDefinition = false; 
     
    579582  
    580583  if (element == "Shape") { 
    581           cout << "+";  
     584          //cout << "+";  
    582585 
    583586          // reset current shape values 
Note: See TracChangeset for help on using the changeset viewer.