Changeset 1415 for GTP/trunk/Lib/Vis/Preprocessing/src/X3dParser.cpp
- Timestamp:
- 09/18/06 18:57:34 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/X3dParser.cpp
r1404 r1415 220 220 void X3dParseHandlers::EndShape() 221 221 { 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 } 256 259 #if 0 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 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 } 300 303 #endif 301 302 303 304 305 306 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 } 308 311 } 309 312 else // default usage: create a mesh instance from the current mesh … … 321 324 else 322 325 { 323 326 // make an instance of this mesh 324 327 TransformedMeshInstance *tmi = new TransformedMeshInstance(mCurrentMesh); 325 328 326 327 328 329 } 330 329 // apply transformation on the instance of the mesh 330 ApplyTransformations(mTransformations, tmi); 331 mi = tmi; 332 } 333 331 334 if (mCurrentMaterial) 332 335 { … … 341 344 } 342 345 } 343 346 344 347 // create local mesh kd tree 345 348 mCurrentMesh->Preprocess(); … … 368 371 369 372 VertexIndexContainer vertices; 370 373 371 374 mIsMeshDefinition = false; 372 375 mUsingMeshDefinition = false; … … 579 582 580 583 if (element == "Shape") { 581 cout << "+";584 //cout << "+"; 582 585 583 586 // reset current shape values
Note: See TracChangeset
for help on using the changeset viewer.