Changeset 752 for GTP/trunk/Lib/Vis/Preprocessing/src/X3dParser.cpp
- Timestamp:
- 04/20/06 13:25:41 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/X3dParser.cpp
r726 r752 100 100 string element(lname.LocalForm()); 101 101 102 // only create new mesh instance if define mechanism was not used 102 103 if (element == "Shape") 103 104 EndShape(); 104 if (1) 105 105 106 if (element == "Transform") 106 107 EndTransform(); … … 138 139 139 140 const int len = attributes.getLength(); 141 Matrix4x4 *rotm = NULL; 142 Matrix4x4 *scalem = NULL; 143 Matrix4x4 *translm = NULL; 140 144 141 145 for (int i = 0; i < len; ++ i) … … 153 157 if (sscanf(ptr, "%f %f %f %f", &axis.x, &axis.y, &axis.z, &angle) == 4) 154 158 { 155 Matrix4x4 rot = RotationAxisMatrix(axis, angle); 156 currentTransform *= rot; 159 rotm = new Matrix4x4(RotationAxisMatrix(axis, angle)); 157 160 } 158 161 } … … 163 166 if (sscanf(ptr, "%f %f %f %f", &transl.x, &transl.y, &transl.z) == 3) 164 167 { 165 Matrix4x4 tm = TranslationMatrix(transl); 166 167 currentTransform *= tm; 168 translm = new Matrix4x4(TranslationMatrix(transl)); 168 169 } 169 170 } 171 else if (attrName == "scale") 172 { 173 Vector3 scale; 174 175 if (sscanf(ptr, "%f %f %f %f", &scale.x, &scale.y, &scale.z) == 3) 176 { 177 scalem = new Matrix4x4(ScaleMatrix(scale.x, scale.y, scale.z)); 178 } 179 } 180 // todo: scale orientation 170 181 } 171 182 183 if (scalem) 184 currentTransform *= (*scalem); 185 if (rotm) 186 currentTransform *= (*rotm); 187 if (translm) 188 currentTransform *= (*translm); 189 190 DEL_PTR(scalem); 191 DEL_PTR(rotm); 192 DEL_PTR(translm); 193 172 194 mTransformations.push(currentTransform); 173 195 } … … 180 202 181 203 182 void 183 X3dParseHandlers::EndShape() 184 { 204 void X3dParseHandlers::EndShape() 205 { 206 // this shape is a definition => don't create mesh instance 207 if (mIsMeshDefinition) 208 { 209 mMeshDefinitions[mCurrentMeshName.c_str()] = mCurrentMesh; 210 //cout << "new definition: " << mCurrentMeshName << endl; 211 212 return; 213 } 214 215 // each polygon is one single mesh 185 216 if (mLoadPolygonsAsMeshes) 186 217 { 187 vector<VertexIndexContainer>::const_iterator it, it_end = mCurrentVertexIndices.end(); 218 219 /*vector<VertexIndexContainer>::const_iterator it, 220 it_end = mCurrentVertexIndices.end(); 188 221 189 222 for (it = mCurrentVertexIndices.begin(); it != it_end; ++ it) … … 211 244 mCurrentNode->mGeometry.push_back(mi); 212 245 213 } 214 215 delete mCurrentMesh; 216 mCurrentVertices.clear(); 217 mCurrentVertexIndices.clear(); 246 }*/ 247 248 //if (mCurrentMesh->mFaces.empty()) cout << "error!" << endl; 249 250 FaceContainer::const_iterator fit, fit_end = mCurrentMesh->mFaces.end(); 251 252 cout << "m"; 253 //cout << "m: " << mCurrentMesh->mFaces.size() << endl; 254 for (fit = mCurrentMesh->mFaces.begin(); fit != fit_end; ++ fit) 255 { 256 cout << "f"; 257 258 Face *face = *fit; 259 // only one face per mesh 260 Mesh *mesh = new Mesh(); 261 VertexIndexContainer vc; 262 263 VertexIndexContainer::const_iterator vit, vit_end = face->mVertexIndices.end(); 264 265 int i = 0; 266 for (vit = face->mVertexIndices.begin(); vit != vit_end; ++ vit, ++ i) 267 { 268 cout << "i"; 269 int index = (*vit); 270 // add vertices 271 mesh->mVertices.push_back(mCurrentMesh->mVertices[index]); 272 vc.push_back(i); 273 } 274 275 mesh->mFaces.push_back(new Face(vc)); 276 277 // NOTE: should rather be written into trafo of mesh instance 278 ApplyTransformations(mTransformations, mesh); 279 280 mesh->Preprocess(); 281 282 // make an instance of this mesh 283 MeshInstance *mi = new MeshInstance(mesh); 284 mCurrentNode->mGeometry.push_back(mi); 285 } 286 287 // LEAK!! TODO: delete if not defd 288 if (!mUsingMeshDefinition) 289 delete mCurrentMesh; 290 291 //mCurrentVertices.clear(); 292 //mCurrentVertexIndices.clear(); 218 293 } 219 294 else 220 295 { 221 if ( mCurrentMesh->mFaces.size())296 if (!mCurrentMesh->mFaces.empty()) 222 297 { 223 298 // should rather be written into the transformation … … 228 303 // make an instance of this mesh 229 304 MeshInstance *mi = new MeshInstance(mCurrentMesh); 305 230 306 mCurrentNode->mGeometry.push_back(mi); 231 307 // set the object id to a unique value … … 234 310 else 235 311 { 312 // empty mesh => discard 236 313 cout<<"X"; 314 237 315 delete mCurrentMesh; 238 316 } … … 243 321 244 322 245 void 246 X3dParseHandlers::StartIndexedFaceSet( 247 AttributeList& attributes) 323 void X3dParseHandlers::StartIndexedFaceSet(AttributeList& attributes) 248 324 { 249 325 int len = attributes.getLength(); 326 250 327 int i; 251 328 VertexIndexContainer vertices; 252 329 253 for (i=0; i < len; i++) { 254 string attrName(StrX(attributes.getName(i)).LocalForm()); 255 if (attrName == "coordIndex") { 256 StrX attrValue(attributes.getValue(i)); 257 // handle coordIndex 258 vertices.clear(); 259 const char *ptr = attrValue.LocalForm(); 260 char *endptr; 261 while(1) { 262 int index = strtol(ptr, &endptr, 10); 263 if (ptr == endptr || index == -1) { 264 if (vertices.size() > 2) { 265 Face *face = new Face(vertices); 266 267 if (!mLoadPolygonsAsMeshes) 268 { 269 mCurrentMesh->mFaces.push_back(face); 270 } 271 else 272 // every polygon is a mesh 273 { 274 mCurrentVertexIndices.push_back(vertices); 275 } 276 } 277 278 vertices.clear(); 279 if (ptr == endptr) 280 break; 281 } else { 282 vertices.push_back(index); 283 } 284 ptr = endptr; 285 } 286 } 287 } 288 } 330 mIsMeshDefinition = false; 331 mUsingMeshDefinition = false; 332 for (i = 0; i < len; ++ i) 333 { 334 string attrName(StrX(attributes.getName(i)).LocalForm()); 335 336 // this is a definition of a mesh 337 if (attrName == "DEF") 338 { 339 mIsMeshDefinition = true; 340 StrX attrValue(attributes.getValue(i)); 341 const char *ptr = attrValue.LocalForm(); 342 mCurrentMeshName = ptr; 343 344 cout << "d"; 345 } 346 347 // we use an already defined mesh 348 if (attrName == "USE") 349 { 350 StrX attrValue(attributes.getValue(i)); 351 352 // discard new mesh and assign defined mesh 353 DEL_PTR(mCurrentMesh); 354 const char *ptr = attrValue.LocalForm(); 355 356 mCurrentMesh = mMeshDefinitions[ptr]; 357 mUsingMeshDefinition = true; 358 cout << "u"; 359 } 360 361 if (attrName == "coordIndex") 362 { 363 StrX attrValue(attributes.getValue(i)); 364 // handle coordIndex 365 vertices.clear(); 366 const char *ptr = attrValue.LocalForm(); 367 368 char *endptr; 369 370 while (1) 371 { 372 int index = strtol(ptr, &endptr, 10); 373 374 if (ptr == endptr || index == -1) 375 { 376 if (vertices.size() > 2) 377 { 378 Face *face = new Face(vertices); 379 mCurrentMesh->mFaces.push_back(face); 380 } 381 382 vertices.clear(); 383 384 if (ptr == endptr) 385 break; 386 387 } 388 else 389 { 390 vertices.push_back(index); 391 } 392 ptr = endptr; 393 } 394 } 395 } 396 } 397 289 398 290 399 void … … 358 467 vertices.push_back(v); 359 468 } 360 if (mLoadPolygonsAsMeshes) 361 { 362 mCurrentVertices = vertices; 363 } 364 else 365 { 366 mCurrentMesh->mVertices = vertices; 367 } 469 470 mCurrentMesh->mVertices = vertices; 368 471 } 369 472 } … … 388 491 } 389 492 390 if (element == "Coordinate") { 493 if (element == "Coordinate") 494 { 391 495 if (mCurrentMesh) 392 496 StartCoordinate(attributes); … … 396 500 StartMaterial(attributes); 397 501 } 398 if (1) 502 399 503 if (element == "Transform") { 400 504 StartTransform(attributes); … … 599 703 X3dViewCellsParseHandlers::EndShape() 600 704 { 705 // currently processing no shape 601 706 } 602 707 … … 607 712 int len = attributes.getLength(); 608 713 int i; 714 609 715 // clear previous vertex indices 610 716 mCurrentVertexIndices.clear(); 717 718 611 719 for (i=0; i < len; i++) 612 720 { 613 721 string attrName(StrX(attributes.getName(i)).LocalForm()); 614 722 723 615 724 if (attrName == "coordIndex") 616 725 {
Note: See TracChangeset
for help on using the changeset viewer.