Changeset 11203
- Timestamp:
- 03/11/10 17:53:35 (3 years ago)
- Location:
- OpenSceneGraph/trunk/src/osgPlugins/3ds
- Files:
-
- 4 modified
-
ReaderWriter3DS.cpp (modified) (34 diffs)
-
WriterCompareTriangle.cpp (modified) (3 diffs)
-
WriterNodeVisitor.cpp (modified) (37 diffs)
-
WriterNodeVisitor.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgPlugins/3ds/ReaderWriter3DS.cpp
r11194 r11203 95 95 } 96 96 97 void copyLib3dsVec3ToOsgVec3(osg::Vec3f osgVec, const float vertices[3]) { 97 void copyLib3dsVec3ToOsgVec3(osg::Vec3f osgVec, const float vertices[3]) 98 { 98 99 return osgVec.set(vertices[0], vertices[1], vertices[2]); 99 100 } 100 101 101 osg::Vec3f copyLib3dsVec3ToOsgVec3(const float vertices[3]) { 102 osg::Vec3f copyLib3dsVec3ToOsgVec3(const float vertices[3]) 103 { 102 104 return osg::Vec3f(vertices[0], vertices[1], vertices[2]); 103 105 } 104 106 105 osg::Quat copyLib3dsQuatToOsgQuat(const float quat[4]) { 107 osg::Quat copyLib3dsQuatToOsgQuat(const float quat[4]) 108 { 106 109 return osg::Quat(quat[0], quat[1], quat[2], quat[3]); 107 110 } … … 226 229 227 230 #if 0 228 osg::notify(osg::NOTICE)<<"3DS reader sizes:"<<std::endl;229 osg::notify(osg::NOTICE)<<" sizeof(Lib3dsBool)="<<sizeof(Lib3dsBool)<<std::endl;230 osg::notify(osg::NOTICE)<<" sizeof(Lib3dsByte)="<<sizeof(Lib3dsByte)<<std::endl;231 osg::notify(osg::NOTICE)<<" sizeof(Lib3dsWord)="<<sizeof(Lib3dsWord)<<std::endl;232 osg::notify(osg::NOTICE)<<" sizeof(Lib3dsDword)="<<sizeof(Lib3dsDword)<<std::endl;233 osg::notify(osg::NOTICE)<<" sizeof(Lib3dsIntb)="<<sizeof(Lib3dsIntb)<<std::endl;234 osg::notify(osg::NOTICE)<<" sizeof(Lib3dsIntw)="<<sizeof(Lib3dsIntw)<<std::endl;235 osg::notify(osg::NOTICE)<<" sizeof(Lib3dsIntd)="<<sizeof(Lib3dsIntd)<<std::endl;236 osg::notify(osg::NOTICE)<<" sizeof(Lib3dsFloat)="<<sizeof(Lib3dsFloat)<<std::endl;237 osg::notify(osg::NOTICE)<<" sizeof(Lib3dsDouble)="<<sizeof(Lib3dsDouble)<<std::endl;238 osg::notify(osg::NOTICE)<<" sizeof(Lib3dsVector)="<<sizeof(Lib3dsVector)<<std::endl;239 osg::notify(osg::NOTICE)<<" sizeof(Lib3dsTexel)="<<sizeof(Lib3dsTexel)<<std::endl;240 osg::notify(osg::NOTICE)<<" sizeof(Lib3dsQuat)="<<sizeof(Lib3dsQuat)<<std::endl;241 osg::notify(osg::NOTICE)<<" sizeof(Lib3dsMatrix)="<<sizeof(Lib3dsMatrix)<<std::endl;242 osg::notify(osg::NOTICE)<<" sizeof(Lib3dsRgb)="<<sizeof(Lib3dsRgb)<<std::endl;243 osg::notify(osg::NOTICE)<<" sizeof(Lib3dsRgba)="<<sizeof(Lib3dsRgba)<<std::endl;231 OSG_NOTIFY(osg::NOTICE)<<"3DS reader sizes:"<<std::endl; 232 OSG_NOTIFY(osg::NOTICE)<<" sizeof(Lib3dsBool)="<<sizeof(Lib3dsBool)<<std::endl; 233 OSG_NOTIFY(osg::NOTICE)<<" sizeof(Lib3dsByte)="<<sizeof(Lib3dsByte)<<std::endl; 234 OSG_NOTIFY(osg::NOTICE)<<" sizeof(Lib3dsWord)="<<sizeof(Lib3dsWord)<<std::endl; 235 OSG_NOTIFY(osg::NOTICE)<<" sizeof(Lib3dsDword)="<<sizeof(Lib3dsDword)<<std::endl; 236 OSG_NOTIFY(osg::NOTICE)<<" sizeof(Lib3dsIntb)="<<sizeof(Lib3dsIntb)<<std::endl; 237 OSG_NOTIFY(osg::NOTICE)<<" sizeof(Lib3dsIntw)="<<sizeof(Lib3dsIntw)<<std::endl; 238 OSG_NOTIFY(osg::NOTICE)<<" sizeof(Lib3dsIntd)="<<sizeof(Lib3dsIntd)<<std::endl; 239 OSG_NOTIFY(osg::NOTICE)<<" sizeof(Lib3dsFloat)="<<sizeof(Lib3dsFloat)<<std::endl; 240 OSG_NOTIFY(osg::NOTICE)<<" sizeof(Lib3dsDouble)="<<sizeof(Lib3dsDouble)<<std::endl; 241 OSG_NOTIFY(osg::NOTICE)<<" sizeof(Lib3dsVector)="<<sizeof(Lib3dsVector)<<std::endl; 242 OSG_NOTIFY(osg::NOTICE)<<" sizeof(Lib3dsTexel)="<<sizeof(Lib3dsTexel)<<std::endl; 243 OSG_NOTIFY(osg::NOTICE)<<" sizeof(Lib3dsQuat)="<<sizeof(Lib3dsQuat)<<std::endl; 244 OSG_NOTIFY(osg::NOTICE)<<" sizeof(Lib3dsMatrix)="<<sizeof(Lib3dsMatrix)<<std::endl; 245 OSG_NOTIFY(osg::NOTICE)<<" sizeof(Lib3dsRgb)="<<sizeof(Lib3dsRgb)<<std::endl; 246 OSG_NOTIFY(osg::NOTICE)<<" sizeof(Lib3dsRgba)="<<sizeof(Lib3dsRgba)<<std::endl; 244 247 #endif 245 248 … … 254 257 restoreMatrixTransformsNoMeshes(false) 255 258 { 256 if (options) { 259 if (options) 260 { 257 261 std::istringstream iss(options->getOptionString()); 258 262 std::string opt; … … 273 277 These print methods for 3ds hacking 274 278 */ 275 void pad(int level) { 279 void pad(int level) 280 { 276 281 for(int i=0;i<level;i++) std::cout<<" "; 277 282 } … … 281 286 void print(Lib3dsNode *node, int level); 282 287 283 void print(Lib3dsMatrix matrix,int level) { 288 void print(Lib3dsMatrix matrix,int level) 289 { 284 290 pad(level); cout << matrix[0][0] <<" "<< matrix[0][1] <<" "<< matrix[0][2] <<" "<< matrix[0][3] << endl; 285 291 pad(level); cout << matrix[1][0] <<" "<< matrix[1][1] <<" "<< matrix[1][2] <<" "<< matrix[1][3] << endl; … … 287 293 pad(level); cout << matrix[3][0] <<" "<< matrix[3][1] <<" "<< matrix[3][2] <<" "<< matrix[3][3] << endl; 288 294 } 289 void print(Lib3dsMesh *mesh,int level) { 290 if (mesh) { 295 void print(Lib3dsMesh *mesh,int level) 296 { 297 if (mesh) 298 { 291 299 pad(level); cout << "mesh name " << mesh->name << endl; 292 300 print(mesh->matrix,level); 293 } else { 301 } 302 else 303 { 294 304 pad(level); cout << "no mesh " << endl; 295 305 } 296 306 } 297 void print(Lib3dsUserData *user,int level) { 298 if (user) { 307 void print(Lib3dsUserData *user,int level) 308 { 309 if (user) 310 { 299 311 pad(level); cout << "user data" << endl; 300 312 //print(user->mesh,level+1); 301 } else { 313 } 314 else 315 { 302 316 pad(level); cout << "no user data" << endl; 303 317 } 304 318 } 305 319 306 void print(Lib3dsMeshInstanceNode *object,int level) { 307 if (object) { 320 void print(Lib3dsMeshInstanceNode *object,int level) 321 { 322 if (object) 323 { 308 324 pad(level); cout << "objectdata instance [" << object->instance_name << "]" << endl; 309 325 pad(level); cout << "pivot " << object->pivot[0] <<" "<< object->pivot[1] <<" "<< object->pivot[2] << endl; … … 311 327 pad(level); cout << "scl " << object->scl[0] <<" "<< object->scl[1] <<" "<< object->scl[2] << endl; 312 328 pad(level); cout << "rot " << object->rot[0] <<" "<< object->rot[1] <<" "<< object->rot[2] <<" "<< object->rot[3] << endl; 313 } else { 329 } 330 else 331 { 314 332 pad(level); cout << "no object data" << endl; 315 333 } 316 334 } 317 335 318 void print(Lib3dsNode *node, int level) { 336 void print(Lib3dsNode *node, int level) 337 { 319 338 320 339 pad(level); cout << "node name [" << node->name << "]" << endl; … … 324 343 print(node->matrix,level+1); 325 344 326 if (node->type == LIB3DS_NODE_MESH_INSTANCE) { 345 if (node->type == LIB3DS_NODE_MESH_INSTANCE) 346 { 327 347 pad(level); cout << "mesh instance data:" << endl; 328 348 print(reinterpret_cast<Lib3dsMeshInstanceNode *>(node),level+1); 329 } else { 349 } 350 else 351 { 330 352 pad(level); cout << "node is not a mesh instance (not handled)" << endl; 331 353 } … … 333 355 print(&node->user_ptr,level); 334 356 335 for(Lib3dsNode *child=node->childs; child; child=child->next) { 357 for(Lib3dsNode *child=node->childs; child; child=child->next) 358 { 336 359 print(child,level+1); 337 360 } … … 387 410 // Creates a Geode and Geometry (as parent,child) and adds the Geode to 'parent' parameter iff 'parent' is non-NULL 388 411 // Returns ptr to the Geode 389 osg::Node* ReaderWriter3DS::ReaderObject::processMesh(StateSetMap& drawStateMap,osg::Group* parent,Lib3dsMesh* mesh, const osg::Matrix * matrix) { 412 osg::Node* ReaderWriter3DS::ReaderObject::processMesh(StateSetMap& drawStateMap,osg::Group* parent,Lib3dsMesh* mesh, const osg::Matrix * matrix) 413 { 390 414 typedef std::vector<FaceList> MaterialFaceMap; 391 415 MaterialFaceMap materialFaceMap; … … 395 419 for (unsigned int i=0; i<mesh->nfaces; ++i) 396 420 { 397 if (mesh->faces[i].material>=0) { 421 if (mesh->faces[i].material>=0) 422 { 398 423 materialFaceMap[mesh->faces[i].material].push_back(i); 399 424 } 400 425 else 426 { 401 427 defaultMaterialFaceList.push_back(i); 428 } 402 429 } 403 430 if (materialFaceMap.empty() && defaultMaterialFaceList.empty()) 404 431 { 405 osg::notify(osg::NOTICE)<<"Warning : no triangles assigned to mesh '"<<mesh->name<<"'"<< std::endl;406 // osg::notify(osg::INFO) << "No material assigned to mesh '" << mesh->name << "'" << std::endl;432 OSG_NOTIFY(osg::NOTICE)<<"Warning : no triangles assigned to mesh '"<<mesh->name<<"'"<< std::endl; 433 //OSG_NOTIFY(osg::INFO) << "No material assigned to mesh '" << mesh->name << "'" << std::endl; 407 434 return NULL; 408 435 } … … 473 500 474 501 osg::Matrix meshMat; 475 if (mesh) { 476 if (!noMatrixTransforms) { 502 if (mesh) 503 { 504 if (!noMatrixTransforms) 505 { 477 506 // There can be a transform directly on a mesh instance (= as if a osg::MatrixTransform and a osg::Geode were merged together) in object->pos/rot/scl 478 507 if (!pivoted) { … … 493 522 494 523 bool isOsgNodeMatrixIdentity = false; 495 if (osgNodeMatrix.isIdentity() || (checkForEspilonIdentityMatrices && isIdentityEquivalent(osgNodeMatrix, MATRIX_EPSILON))) { 524 if (osgNodeMatrix.isIdentity() || (checkForEspilonIdentityMatrices && isIdentityEquivalent(osgNodeMatrix, MATRIX_EPSILON))) 525 { 496 526 isOsgNodeMatrixIdentity = true; 497 527 } 498 528 499 529 500 //if (node->childs != NULL || pivoted || (!isOsgNodeMatrixIdentity && !noMatrixTransforms)) { 501 if (node->childs != NULL || (!isOsgNodeMatrixIdentity && !noMatrixTransforms)) { 502 if (isOsgNodeMatrixIdentity || noMatrixTransforms) { 530 //if (node->childs != NULL || pivoted || (!isOsgNodeMatrixIdentity && !noMatrixTransforms)) 531 if (node->childs != NULL || (!isOsgNodeMatrixIdentity && !noMatrixTransforms)) 532 { 533 if (isOsgNodeMatrixIdentity || noMatrixTransforms) 534 { 503 535 group = new osg::Group; 504 } else { 536 } 537 else 538 { 505 539 group = new osg::MatrixTransform(osgNodeMatrix); 506 540 } 507 541 } 508 542 509 if (group) { 543 if (group) 544 { 510 545 if (strcmp(node->name, "$$$DUMMY") == 0) 511 546 { … … 517 552 518 553 // Handle all children of this node for hierarchical assemblies 519 for (Lib3dsNode *p=node->childs; p!=NULL; p=p->next) { 554 for (Lib3dsNode *p=node->childs; p!=NULL; p=p->next) 555 { 520 556 group->addChild(processNode(drawStateMap,f,p)); 521 557 } 522 } else { 558 } 559 else 560 { 523 561 assert(node->childs == NULL); // Else we must have a group to put childs into 524 562 } 525 563 526 564 // Handle mesh 527 if (mesh) { 565 if (mesh) 566 { 528 567 osg::Matrix * meshAppliedMatPtr = NULL; 529 if (!meshMat.isIdentity() && !(checkForEspilonIdentityMatrices && isIdentityEquivalent(meshMat, MATRIX_EPSILON))) { 568 if (!meshMat.isIdentity() && !(checkForEspilonIdentityMatrices && isIdentityEquivalent(meshMat, MATRIX_EPSILON))) 569 { 530 570 meshAppliedMatPtr = &meshMat; 531 571 } 532 572 533 if(group) { 573 if (group) 574 { 534 575 // add our geometry to group (where our children already are) 535 576 // creates geometry under modifier node 536 577 processMesh(drawStateMap,group,mesh,meshAppliedMatPtr); 537 578 return group; 538 } else { 579 } 580 else 581 { 539 582 // didnt use group for children 540 583 // return a ptr directly to the Geode for this mesh … … 542 585 } 543 586 544 } else { 587 } 588 else 589 { 545 590 // no mesh for this node - probably a camera or something of that persuasion 546 591 //cout << "no mesh for object " << node->name << endl; … … 550 595 551 596 552 static long filei_seek_func(void *self, long offset, Lib3dsIoSeek origin) { 597 static long filei_seek_func(void *self, long offset, Lib3dsIoSeek origin) 598 { 553 599 std::istream *f = reinterpret_cast<std::istream*>(self); 554 600 ios_base::seekdir o = ios_base::beg; … … 560 606 } 561 607 562 static long fileo_seek_func(void *self, long offset, Lib3dsIoSeek origin) { 608 static long fileo_seek_func(void *self, long offset, Lib3dsIoSeek origin) 609 { 563 610 std::ostream *f = reinterpret_cast<std::ostream*>(self); 564 611 ios_base::seekdir o = ios_base::beg; … … 570 617 } 571 618 572 static long filei_tell_func(void *self) { 619 static long filei_tell_func(void *self) 620 { 573 621 std::istream *f = reinterpret_cast<std::istream*>(self); 574 622 return f->tellg(); 575 623 } 576 624 577 static long fileo_tell_func(void *self) { 625 static long fileo_tell_func(void *self) 626 { 578 627 std::ostream *f = reinterpret_cast<std::ostream*>(self); 579 628 return f->tellp(); … … 581 630 582 631 583 static size_t filei_read_func(void *self, void *buffer, size_t size) { 632 static size_t filei_read_func(void *self, void *buffer, size_t size) 633 { 584 634 std::istream *f = reinterpret_cast<std::istream*>(self); 585 635 f->read(reinterpret_cast<char*>(buffer), size); … … 587 637 } 588 638 589 static size_t fileo_write_func(void *self, const void *buffer, size_t size) { 639 static size_t fileo_write_func(void *self, const void *buffer, size_t size) 640 { 590 641 std::ostream *f = reinterpret_cast<std::ostream*>(self); 591 642 f->write(static_cast<const char*>(buffer), size); … … 601 652 else if (level == LIB3DS_LOG_INFO) l = osg::INFO; 602 653 else if (level == LIB3DS_LOG_DEBUG) l = osg::DEBUG_INFO; 603 osg::notify(l) << msg << std::endl;654 OSG_NOTIFY(l) << msg << std::endl; 604 655 } 605 656 … … 700 751 int level=0; 701 752 std::cout << "NODE TRAVERSAL of 3ds file "<<f->name<<std::endl; 702 for(Lib3dsNode *node=f->nodes; node; node=node->next) { 753 for(Lib3dsNode *node=f->nodes; node; node=node->next) 754 { 703 755 print(node,level+1); 704 756 } 705 757 std::cout << "MESH TRAVERSAL of 3ds file "<<f->name<<std::endl; 706 for (int imesh=0; imesh<f->nmeshes; ++imesh) {758 for (int imesh=0; imesh<f->nmeshes; ++imesh){ 707 759 print(f->meshes[imesh],level+1); 708 760 } … … 716 768 // MIKEC: have found 3ds files with NO node structure - only meshes, for this case we fall back to the old traverse-by-meshes code 717 769 // Loading and re-exporting these files from 3DS produces a file with correct node structure, so perhaps these are not 100% conformant? 718 if (f->nodes == NULL) { 719 osg::notify(osg::WARN)<<"Warning: in 3ds loader: file has no nodes, traversing by meshes instead"<< std::endl; 770 if (f->nodes == NULL) 771 { 772 OSG_NOTIFY(osg::WARN)<<"Warning: in 3ds loader: file has no nodes, traversing by meshes instead"<< std::endl; 720 773 traverse_nodes=true; 721 774 } … … 723 776 osg::Node* group = NULL; 724 777 725 if (traverse_nodes) { // old method 778 if (traverse_nodes) // old method 779 { 726 780 group = new osg::Group(); 727 for (int imesh=0; imesh<f->nmeshes; ++imesh) { 781 for (int imesh=0; imesh<f->nmeshes; ++imesh) 782 { 728 783 reader.processMesh(drawStateMap,group->asGroup(),f->meshes[imesh],NULL); 729 784 } 730 } else { // new method 785 } 786 else 787 { // new method 731 788 Lib3dsNode *node=f->nodes; 732 789 if (!node->next) 790 { 733 791 group = reader.processNode(drawStateMap,f,node); 792 } 734 793 else 735 794 { 736 795 group = new osg::Group(); 737 for(; node; node=node->next) { 796 for(; node; node=node->next) 797 { 738 798 group->asGroup()->addChild(reader.processNode(drawStateMap,f,node)); 739 799 } … … 744 804 if (osg::getNotifyLevel()>=osg::INFO) 745 805 { 746 osg::notify(osg::NOTICE) << "Final OSG node structure looks like this:"<< endl;806 OSG_NOTIFY(osg::NOTICE) << "Final OSG node structure looks like this:"<< endl; 747 807 PrintVisitor pv(osg::notify(osg::NOTICE)); 748 808 group->accept(pv); … … 903 963 if (texture && *(texture->name)) 904 964 { 905 osg::notify(osg::INFO)<<"texture->name="<<texture->name<<", _directory="<<_directory<<std::endl;965 OSG_NOTIFY(osg::INFO)<<"texture->name="<<texture->name<<", _directory="<<_directory<<std::endl; 906 966 907 967 std::string fileName = osgDB::findFileInDirectory(texture->name,_directory,osgDB::CASE_INSENSITIVE); … … 910 970 // file not found in .3ds file's directory, so we'll look in the datafile path list. 911 971 fileName = osgDB::findDataFile(texture->name,options, osgDB::CASE_INSENSITIVE); 912 osg::notify(osg::INFO)<<"texture->name="<<texture->name<<", _directory="<<_directory<<std::endl;972 OSG_NOTIFY(osg::INFO)<<"texture->name="<<texture->name<<", _directory="<<_directory<<std::endl; 913 973 } 914 974 … … 919 979 // if 3DS file is loaded from http, just attempt to load texture from same location. 920 980 fileName = _directory + "/" + texture->name; 921 } else { 922 osg::notify(osg::WARN) << "texture '"<<texture->name<<"' not found"<< std::endl; 981 } 982 else 983 { 984 OSG_NOTIFY(osg::WARN) << "texture '"<<texture->name<<"' not found"<< std::endl; 923 985 return NULL; 924 986 } 925 987 } 926 988 927 if (label) osg::notify(osg::DEBUG_INFO) << label; 928 else osg::notify(osg::DEBUG_INFO) << "texture name"; 929 osg::notify(osg::DEBUG_INFO) << " '"<<texture->name<<"'"<< std::endl; 930 osg::notify(osg::DEBUG_INFO) << " texture flag "<<texture->flags<< std::endl; 931 osg::notify(osg::DEBUG_INFO) << " LIB3DS_TEXTURE_DECALE "<<((texture->flags)&LIB3DS_TEXTURE_DECALE)<< std::endl; 932 osg::notify(osg::DEBUG_INFO) << " LIB3DS_TEXTURE_MIRROR "<<((texture->flags)&LIB3DS_TEXTURE_MIRROR)<< std::endl; 933 osg::notify(osg::DEBUG_INFO) << " LIB3DS_TEXTURE_NEGATE "<<((texture->flags)&LIB3DS_TEXTURE_NEGATE)<< std::endl; 934 osg::notify(osg::DEBUG_INFO) << " LIB3DS_TEXTURE_NO_TILE "<<((texture->flags)&LIB3DS_TEXTURE_NO_TILE)<< std::endl; 935 osg::notify(osg::DEBUG_INFO) << " LIB3DS_TEXTURE_SUMMED_AREA "<<((texture->flags)&LIB3DS_TEXTURE_SUMMED_AREA)<< std::endl; 936 osg::notify(osg::DEBUG_INFO) << " LIB3DS_TEXTURE_ALPHA_SOURCE "<<((texture->flags)&LIB3DS_TEXTURE_ALPHA_SOURCE)<< std::endl; 937 osg::notify(osg::DEBUG_INFO) << " LIB3DS_TEXTURE_TINT "<<((texture->flags)&LIB3DS_TEXTURE_TINT)<< std::endl; 938 osg::notify(osg::DEBUG_INFO) << " LIB3DS_TEXTURE_IGNORE_ALPHA "<<((texture->flags)&LIB3DS_TEXTURE_IGNORE_ALPHA)<< std::endl; 939 osg::notify(osg::DEBUG_INFO) << " LIB3DS_TEXTURE_RGB_TINT "<<((texture->flags)&LIB3DS_TEXTURE_RGB_TINT)<< std::endl; 989 if (label) { OSG_NOTIFY(osg::DEBUG_INFO) << label; } 990 else { OSG_NOTIFY(osg::DEBUG_INFO) << "texture name"; } 991 992 OSG_NOTIFY(osg::DEBUG_INFO) << " '"<<texture->name<<"'"<< std::endl; 993 OSG_NOTIFY(osg::DEBUG_INFO) << " texture flag "<<texture->flags<< std::endl; 994 OSG_NOTIFY(osg::DEBUG_INFO) << " LIB3DS_TEXTURE_DECALE "<<((texture->flags)&LIB3DS_TEXTURE_DECALE)<< std::endl; 995 OSG_NOTIFY(osg::DEBUG_INFO) << " LIB3DS_TEXTURE_MIRROR "<<((texture->flags)&LIB3DS_TEXTURE_MIRROR)<< std::endl; 996 OSG_NOTIFY(osg::DEBUG_INFO) << " LIB3DS_TEXTURE_NEGATE "<<((texture->flags)&LIB3DS_TEXTURE_NEGATE)<< std::endl; 997 OSG_NOTIFY(osg::DEBUG_INFO) << " LIB3DS_TEXTURE_NO_TILE "<<((texture->flags)&LIB3DS_TEXTURE_NO_TILE)<< std::endl; 998 OSG_NOTIFY(osg::DEBUG_INFO) << " LIB3DS_TEXTURE_SUMMED_AREA "<<((texture->flags)&LIB3DS_TEXTURE_SUMMED_AREA)<< std::endl; 999 OSG_NOTIFY(osg::DEBUG_INFO) << " LIB3DS_TEXTURE_ALPHA_SOURCE "<<((texture->flags)&LIB3DS_TEXTURE_ALPHA_SOURCE)<< std::endl; 1000 OSG_NOTIFY(osg::DEBUG_INFO) << " LIB3DS_TEXTURE_TINT "<<((texture->flags)&LIB3DS_TEXTURE_TINT)<< std::endl; 1001 OSG_NOTIFY(osg::DEBUG_INFO) << " LIB3DS_TEXTURE_IGNORE_ALPHA "<<((texture->flags)&LIB3DS_TEXTURE_IGNORE_ALPHA)<< std::endl; 1002 OSG_NOTIFY(osg::DEBUG_INFO) << " LIB3DS_TEXTURE_RGB_TINT "<<((texture->flags)&LIB3DS_TEXTURE_RGB_TINT)<< std::endl; 940 1003 941 1004 osg::ref_ptr<osg::Image> osg_image = osgDB::readRefImageFile(fileName.c_str(), options); //Absolute Path 942 1005 if (!osg_image.valid()) 943 1006 { 944 osg::notify(osg::NOTICE) << "Warning: Cannot create texture "<<texture->name<< std::endl;1007 OSG_NOTIFY(osg::NOTICE) << "Warning: Cannot create texture "<<texture->name<< std::endl; 945 1008 return NULL; 946 1009 } … … 1071 1134 1072 1135 1073 osgDB::ReaderWriter::WriteResult ReaderWriter3DS::writeNode(const osg::Node& node,const std::string& fileName,const Options* options) const { 1136 osgDB::ReaderWriter::WriteResult ReaderWriter3DS::writeNode(const osg::Node& node,const std::string& fileName,const Options* options) const 1137 { 1074 1138 std::string ext = osgDB::getLowerCaseFileExtension(fileName); 1075 1139 if (!acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED; … … 1084 1148 if (!file3ds) return WriteResult(WriteResult::ERROR_IN_WRITING_FILE); 1085 1149 1086 try { 1087 osg::ref_ptr<Options> local_opt = options ? static_cast<Options*>(options->clone(osg::CopyOp::SHALLOW_COPY)) : new Options; 1088 local_opt->getDatabasePathList().push_front(osgDB::getFilePath(fileName)); 1089 1090 if (!createFileObject(node, file3ds, fileName, local_opt)) ok = false; 1091 if (ok && !lib3ds_file_save(file3ds, fileName.c_str())) ok = false; 1092 } catch (...) { 1093 lib3ds_file_free(file3ds); 1094 throw; 1095 } 1150 osg::ref_ptr<Options> local_opt = options ? static_cast<Options*>(options->clone(osg::CopyOp::SHALLOW_COPY)) : new Options; 1151 local_opt->getDatabasePathList().push_front(osgDB::getFilePath(fileName)); 1152 if (!createFileObject(node, file3ds, fileName, local_opt)) ok = false; 1153 if (ok && !lib3ds_file_save(file3ds, fileName.c_str())) ok = false; 1096 1154 lib3ds_file_free(file3ds); 1097 1155 … … 1101 1159 1102 1160 1103 osgDB::ReaderWriter::WriteResult ReaderWriter3DS::writeNode(const osg::Node& node,std::ostream& fout,const Options* options) const { 1104 //osg::notify(osg::WARN) << "!!WARNING!! 3DS write support is incomplete" << std::endl; 1161 osgDB::ReaderWriter::WriteResult ReaderWriter3DS::writeNode(const osg::Node& node,std::ostream& fout,const Options* options) const 1162 { 1163 //OSG_NOTIFY(osg::WARN) << "!!WARNING!! 3DS write support is incomplete" << std::endl; 1105 1164 std::string optFileName; 1106 if (options) { 1165 if (options) 1166 { 1107 1167 optFileName = options->getPluginStringData("STREAM_FILENAME"); 1108 1168 } … … 1111 1171 } 1112 1172 1113 osgDB::ReaderWriter::WriteResult ReaderWriter3DS::doWriteNode(const osg::Node& node,std::ostream& fout, const Options* options, const std::string & fileNamelib3ds) const { 1173 osgDB::ReaderWriter::WriteResult ReaderWriter3DS::doWriteNode(const osg::Node& node,std::ostream& fout, const Options* options, const std::string & fileNamelib3ds) const 1174 { 1114 1175 osg::ref_ptr<Options> local_opt = options ? static_cast<Options*>(options->clone(osg::CopyOp::SHALLOW_COPY)) : new Options; 1115 1176 local_opt->getDatabasePathList().push_front(osgDB::getFilePath(fileNamelib3ds)); … … 1127 1188 1128 1189 bool ok = true; 1129 try { 1130 if (!createFileObject(node, file3ds, fileNamelib3ds, local_opt.get())) ok = false; 1131 if (ok && !lib3ds_file_write(file3ds, &io)) ok = false; 1132 1133 } catch (...) { 1134 lib3ds_file_free(file3ds); 1135 throw; 1136 } 1190 if (!createFileObject(node, file3ds, fileNamelib3ds, local_opt.get())) ok = false; 1191 if (ok && !lib3ds_file_write(file3ds, &io)) ok = false; 1137 1192 lib3ds_file_free(file3ds); 1138 1193 … … 1141 1196 } 1142 1197 1143 bool ReaderWriter3DS::createFileObject(const osg::Node& node, Lib3dsFile * file3ds,const std::string& fileName, const osgDB::ReaderWriter::Options* options) const { 1198 bool ReaderWriter3DS::createFileObject(const osg::Node& node, Lib3dsFile * file3ds,const std::string& fileName, const osgDB::ReaderWriter::Options* options) const 1199 { 1144 1200 WriterNodeVisitor w(file3ds, fileName, options, osgDB::getFilePath(node.getName())); 1145 1201 const_cast<osg::Node &>(node).accept(w); // Ugly const_cast<> for visitor... 1146 if (!w.suceedLastApply()) 1147 return false; 1202 if (!w.succeeded()) return false; 1148 1203 w.writeMaterials(); 1149 return true; //w.good();1150 } 1151 1204 return w.succeeded(); 1205 } 1206 -
OpenSceneGraph/trunk/src/osgPlugins/3ds/WriterCompareTriangle.cpp
r11194 r11203 1 1 #include "WriterCompareTriangle.h" 2 #include <assert.h> 2 3 3 4 WriterCompareTriangle::WriterCompareTriangle(const osg::Geode & geode, unsigned int nbVertices) : geode(geode) … … 51 52 setMaxMin (nbVerticesX, nbVerticesY, nbVerticesZ); // This function prevent from cutting the scene in too many blocs 52 53 53 osg::notify(osg::INFO)54 OSG_NOTIFY(osg::INFO) 54 55 << "Cutting x by " << nbVerticesX << std::endl 55 56 << "Cutting y by " << nbVerticesY << std::endl … … 120 121 { 121 122 if (x >= boxList[i].xMin() && 122 x < boxList[i].xMax() &&123 x < boxList[i].xMax() && 123 124 y >= boxList[i].yMin() && 124 y < boxList[i].yMax() &&125 y < boxList[i].yMax() && 125 126 z >= boxList[i].zMin() && 126 z < boxList[i].zMax())127 z < boxList[i].zMax()) 127 128 { 128 129 return i; 129 130 } 130 131 } 131 throw "Point is not in any blocs"; 132 assert(false && "Point is not in any blocs"); 133 return 0; 132 134 } 133 135 -
OpenSceneGraph/trunk/src/osgPlugins/3ds/WriterNodeVisitor.cpp
r11194 r11203 26 26 void copyOsgMatrixToLib3dsMatrix(Lib3dsMatrix lib3ds_matrix, const osg::Matrix& osg_matrix) 27 27 { 28 for(int row=0; row<4; ++row) { 28 for(int row=0; row<4; ++row) 29 { 29 30 lib3ds_matrix[row][0] = osg_matrix.ptr()[row*4+0]; 30 31 lib3ds_matrix[row][1] = osg_matrix.ptr()[row*4+1]; … … 34 35 } 35 36 36 inline void copyOsgVectorToLib3dsVector(Lib3dsVector lib3ds_vector, const osg::Vec3f& osg_vector) { 37 inline void copyOsgVectorToLib3dsVector(Lib3dsVector lib3ds_vector, const osg::Vec3f& osg_vector) 38 { 37 39 lib3ds_vector[0] = osg_vector[0]; 38 40 lib3ds_vector[1] = osg_vector[1]; 39 41 lib3ds_vector[2] = osg_vector[2]; 40 42 } 41 inline void copyOsgVectorToLib3dsVector(Lib3dsVector lib3ds_vector, const osg::Vec3d& osg_vector) { 43 inline void copyOsgVectorToLib3dsVector(Lib3dsVector lib3ds_vector, const osg::Vec3d& osg_vector) 44 { 42 45 lib3ds_vector[0] = osg_vector[0]; 43 46 lib3ds_vector[1] = osg_vector[1]; … … 45 48 } 46 49 47 inline void copyOsgColorToLib3dsColor(Lib3dsVector lib3ds_vector, const osg::Vec4f& osg_vector) { 50 inline void copyOsgColorToLib3dsColor(Lib3dsVector lib3ds_vector, const osg::Vec4f& osg_vector) 51 { 48 52 lib3ds_vector[0] = osg_vector[0]; 49 53 lib3ds_vector[1] = osg_vector[1]; 50 54 lib3ds_vector[2] = osg_vector[2]; 51 55 } 52 inline void copyOsgColorToLib3dsColor(Lib3dsVector lib3ds_vector, const osg::Vec4d& osg_vector) { 56 inline void copyOsgColorToLib3dsColor(Lib3dsVector lib3ds_vector, const osg::Vec4d& osg_vector) 57 { 53 58 lib3ds_vector[0] = osg_vector[0]; 54 59 lib3ds_vector[1] = osg_vector[1]; … … 56 61 } 57 62 58 inline void copyOsgQuatToLib3dsQuat(float lib3ds_vector[4], const osg::Quat& osg_quat) { 63 inline void copyOsgQuatToLib3dsQuat(float lib3ds_vector[4], const osg::Quat& osg_quat) 64 { 59 65 //lib3ds_vector[0] = osg_quat[3]; // Not sure 60 66 //lib3ds_vector[1] = osg_quat[0]; … … 70 76 } 71 77 72 std::string getFileName(const std::string & path) { 78 std::string getFileName(const std::string & path) 79 { 73 80 unsigned int slashPos = path.find_last_of("/\\"); 74 81 if (slashPos == std::string::npos) return path; … … 78 85 79 86 /// Checks if a filename (\b not path) is 8.3 (an empty name is never 8.3, and a path is never 8.3). 80 bool is83(const std::string & s) { 87 bool is83(const std::string & s) 88 { 81 89 // 012345678901 82 90 // ABCDEFGH.ABC … … 93 101 94 102 /// Tests if the given string is a path supported by 3DS format (8.3, 63 chars max). 95 bool is3DSpath(const std::string & s, bool extendedFilePaths) { 103 bool is3DSpath(const std::string & s, bool extendedFilePaths) 104 { 96 105 unsigned int len = s.length(); 97 106 if (len >= 64 || len == 0) return false; … … 113 122 114 123 /** writes all primitives of a primitive-set out to a stream, decomposes quads to triangles, line-strips to lines etc */ 115 class PrimitiveIndexWriter : public osg::PrimitiveIndexFunctor { 124 class PrimitiveIndexWriter : public osg::PrimitiveIndexFunctor 125 { 116 126 public: 117 127 PrimitiveIndexWriter(osg::Geometry * geo, … … 341 351 //break; 342 352 default: 343 osg::notify(osg::WARN) << "3DS WriterNodeVisitor: can't handle mode " << mode << std::endl;353 OSG_NOTIFY(osg::WARN) << "3DS WriterNodeVisitor: can't handle mode " << mode << std::endl; 344 354 break; 345 355 } … … 362 372 //static unsigned int s_objmaterial_id = 0; 363 373 //++s_objmaterial_id; 364 if (mat) { 374 if (mat) 375 { 365 376 assert(stateset); 366 377 diffuse = mat->getDiffuse(osg::Material::FRONT); … … 371 382 name = writerNodeVisitor.getUniqueName(mat->getName(),"mat"); 372 383 osg::StateAttribute * attribute = stateset->getAttribute(osg::StateAttribute::CULLFACE); 373 if (!attribute) { 384 if (!attribute) 385 { 374 386 double_sided = true; 375 } else { 387 } 388 else 389 { 376 390 assert(dynamic_cast<osg::CullFace *>(attribute)); 377 391 osg::CullFace::Mode mode = static_cast<osg::CullFace *>(attribute)->getMode(); 378 392 if (mode == osg::CullFace::BACK) double_sided = false; 379 else if (mode == osg::CullFace::FRONT) { 380 osg::notify(osg::WARN) << "3DS Writer: Reversed face (culled FRONT) not supported yet." << std::endl; 393 else if (mode == osg::CullFace::FRONT) 394 { 395 OSG_NOTIFY(osg::WARN) << "3DS Writer: Reversed face (culled FRONT) not supported yet." << std::endl; 381 396 double_sided = false; 382 397 } 383 else { 398 else 399 { 384 400 assert(mode == osg::CullFace::FRONT_AND_BACK); 385 osg::notify(osg::WARN) << "3DS Writer: Invisible face (culled FRONT_AND_BACK) not supported yet." << std::endl;401 OSG_NOTIFY(osg::WARN) << "3DS Writer: Invisible face (culled FRONT_AND_BACK) not supported yet." << std::endl; 386 402 double_sided = false; 387 403 } 388 404 } 389 405 } 390 if (tex) { 406 if (tex) 407 { 391 408 osg::Image* img = tex->getImage(0); 392 409 if(img) … … 398 415 } 399 416 400 if (name.empty()) { 417 if (name.empty()) 418 { 401 419 std::stringstream ss; 402 420 ss << "m" << index; … … 466 484 const std::string & srcDirectory) : 467 485 osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN), 468 _suc eedLastApply(true),486 _succeeded(true), 469 487 _srcDirectory(srcDirectory), 470 488 file3ds(file3ds), … … 480 498 _directory = options->getDatabasePathList().empty() ? osgDB::getFilePath(fileName) : options->getDatabasePathList().front(); 481 499 482 if (options) { 500 if (options) 501 { 483 502 std::istringstream iss(options->getOptionString()); 484 503 std::string opt; … … 524 543 path = oss.str(); 525 544 } 526 else { 545 else 546 { 527 547 path = getPathRelative(_srcDirectory, mat.image->getFileName()); 528 548 } 529 549 path = convertExt(path, _extendedFilePaths); 530 550 531 if(!is3DSpath(path, _extendedFilePaths)) { 551 if(!is3DSpath(path, _extendedFilePaths)) 552 { 532 553 path = getUniqueName(path, "", true); 533 554 //path = osgDB::getSimpleFileName(path); … … 547 568 if (mat.texture_no_tile) tex.flags |= LIB3DS_TEXTURE_NO_TILE; 548 569 } 549 if (!suc eedLastApply())570 if (!succeeded()) 550 571 return; 551 572 lib3ds_file_insert_material(file3ds, mat3ds, itr->second.index); 552 573 break; // Ugly thing (3) 553 574 } 554 if (!found) throw "Implementation error"; // Ugly thing (4) 555 } 556 } 557 558 559 std::string WriterNodeVisitor::getUniqueName(const std::string& _defaultValue, const std::string & _defaultPrefix, bool nameIsPath) { 560 static const unsigned int MAX_PREFIX_LEGNTH = 4; 561 if (_defaultPrefix.length()>MAX_PREFIX_LEGNTH) throw "Default prefix is too long"; // Arbitrarily defined to 4 chars. 575 assert(found); // Ugly thing (4) - Implementation error if !found 576 } 577 } 578 579 580 std::string WriterNodeVisitor::getUniqueName(const std::string& _defaultValue, const std::string & _defaultPrefix, bool nameIsPath) 581 { 582 static const unsigned int MAX_PREFIX_LEGNTH = 4; // Arbitrarily defined to 4 chars 583 assert(_defaultPrefix.length()<=MAX_PREFIX_LEGNTH); // Default prefix is too long (implementation error) 562 584 563 585 // Tests if default name is valid and unique 564 586 bool defaultIs83 = is83(_defaultValue); 565 587 bool defaultIsValid = nameIsPath ? is3DSpath(_defaultValue, _extendedFilePaths) : defaultIs83; 566 if (defaultIsValid && _nameMap.find(_defaultValue) == _nameMap.end()) { 588 if (defaultIsValid && _nameMap.find(_defaultValue) == _nameMap.end()) 589 { 567 590 _nameMap.insert(_defaultValue); 568 591 return _defaultValue; … … 611 634 612 635 unsigned int searchStart = 0; 613 if (pairPrefix != _mapPrefix.end()) { 636 if (pairPrefix != _mapPrefix.end()) 637 { 614 638 searchStart = pairPrefix->second; 615 639 } 616 640 617 for(unsigned int i = searchStart; i <= max_val; ++i) { 641 for(unsigned int i = searchStart; i <= max_val; ++i) 642 { 618 643 std::stringstream ss; 619 644 ss << defaultPrefix << i; 620 645 const std::string & res = ss.str(); 621 if (_nameMap.find(res) == _nameMap.end()) { 622 if (pairPrefix != _mapPrefix.end()) { 646 if (_nameMap.find(res) == _nameMap.end()) 647 { 648 if (pairPrefix != _mapPrefix.end()) 649 { 623 650 pairPrefix->second = i + 1; 624 } else { 651 } else 652 { 625 653 _mapPrefix.insert(std::pair<std::string, unsigned int>(defaultPrefix, i + 1)); 626 654 } … … 635 663 // Try with default prefix if not arleady done 636 664 if (defaultPrefix != std::string("_")) return getUniqueName(_defaultValue, "_", nameIsPath); 637 throw "No more names available! Is default prefix too long?"; 665 666 // No more names 667 OSG_NOTIFY(osg::FATAL) << "No more names available!" << std::endl; 668 _succeeded = false; 669 return "ERROR"; 638 670 } 639 671 … … 641 673 { 642 674 MaterialMap::const_iterator itr = _materialMap.find(ss); 643 if (itr != _materialMap.end()) { 675 if (itr != _materialMap.end()) 676 { 644 677 assert(itr->second.index>=0); 645 678 return itr->second.index; … … 672 705 { 673 706 MapIndices::iterator itIndex = index_vert.find(std::pair<unsigned int, unsigned int>(index, drawable_n)); 674 if (itIndex == index_vert.end()) { 707 if (itIndex == index_vert.end()) 708 { 675 709 unsigned int indexMesh = index_vert.size(); 676 710 index_vert.insert(std::make_pair(std::pair<unsigned int, unsigned int>(index, drawable_n), indexMesh)); … … 688 722 Lib3dsMesh * mesh) 689 723 { 690 osg::notify(osg::DEBUG_INFO) << "Building Mesh" << std::endl; 691 692 if (!mesh) throw "Allocation error"; // TODO 724 OSG_NOTIFY(osg::DEBUG_INFO) << "Building Mesh" << std::endl; 725 assert(mesh); 693 726 694 727 // Write points … … 701 734 assert(g->getVertexArray()); 702 735 if (g->getVertexArray()->getType() != osg::Array::Vec3ArrayType) 703 throw "Vertex array is not Vec3. Not implemented"; // TODO 736 { 737 // TODO Handle double presision vertices by converting them to float with a warning 738 OSG_NOTIFY(osg::FATAL) << "Vertex array is not Vec3. Not implemented" << std::endl; 739 _succeeded = false; 740 return; 741 } 704 742 const osg::Vec3Array & vecs= *static_cast<osg::Vec3Array *>(g->getVertexArray()); 705 743 copyOsgVectorToLib3dsVector(mesh->vertices[it->second], vecs[it->first.first]*mat); … … 712 750 { 713 751 osg::Geometry *g = geo.getDrawable( it->first.second )->asGeometry(); 714 osg::Array * array = g->getTexCoordArray(0);715 if (array)752 osg::Array * texarray = g->getTexCoordArray(0); 753 if (texarray) 716 754 { 717 755 if (g->getTexCoordArray(0)->getType() != osg::Array::Vec2ArrayType) 718 throw "Texture coords array is not Vec2. Not implemented"; // TODO 719 const osg::Vec2Array & vecs= *static_cast<osg::Vec2Array *>(array); 756 { 757 OSG_NOTIFY(osg::FATAL) << "Texture coords array is not Vec2. Not implemented" << std::endl; 758 _succeeded = false; 759 return; 760 } 761 const osg::Vec2Array & vecs= *static_cast<osg::Vec2Array *>(texarray); 720 762 mesh->texcos[it->second][0] = vecs[it->first.first][0]; 721 763 mesh->texcos[it->second][1] = vecs[it->first.first][1]; … … 739 781 assert(g->getVertexArray()); 740 782 if (g->getVertexArray()->getType() != osg::Array::Vec3ArrayType) 741 throw "Vertex array is not Vec3. Not implemented"; // TODO 783 { 784 // TODO Handle double presision vertices by converting them to float with a warning 785 OSG_NOTIFY(osg::FATAL) << "Vertex array is not Vec3. Not implemented" << std::endl; 786 _succeeded = false; 787 return 0; 788 } 742 789 const osg::Vec3Array & vecs= *static_cast<osg::Vec3Array *>(g->getVertexArray()); 743 790 numVertice += vecs.getNumElements(); … … 753 800 bool texcoords) 754 801 { 755 MapIndices index_vert;756 Lib3dsMesh *mesh = lib3ds_mesh_new( getUniqueName(geo.getName().empty() ? geo.className() : geo.getName(), "geo").c_str() );757 if (!mesh) throw "Allocation error";758 759 802 unsigned int nbTrianglesRemaining = listTriangles.size(); 760 unsigned int nbVerticesRemaining = calcVertices(geo); 803 unsigned int nbVerticesRemaining = calcVertices(geo); // May set _succeded to false 804 if (!succeeded()) return; 805 806 std::string name( getUniqueName(geo.getName().empty() ? geo.className() : geo.getName(), "geo") ); 807 if (!succeeded()) return; 808 Lib3dsMesh *mesh = lib3ds_mesh_new( name.c_str() ); 809 if (!mesh) 810 { 811 OSG_NOTIFY(osg::FATAL) << "Allocation error" << std::endl; 812 _succeeded = false; 813 return; 814 } 761 815 762 816 lib3ds_mesh_resize_faces (mesh, osg::minimum(nbTrianglesRemaining, MAX_FACES)); … … 766 820 if (nbVerticesRemaining >= MAX_VERTICES || nbTrianglesRemaining >= MAX_FACES) 767 821 { 768 osg::notify(osg::INFO) << "Sorting elements..." << std::endl;822 OSG_NOTIFY(osg::INFO) << "Sorting elements..." << std::endl; 769 823 WriterCompareTriangle cmp(geo, nbVerticesRemaining); 770 824 std::sort(listTriangles.begin(), listTriangles.end(), cmp); 771 825 } 772 826 827 MapIndices index_vert; 773 828 unsigned int numFace = 0; // Current face index 774 829 for (ListTriangle::iterator it = listTriangles.begin(); it != listTriangles.end(); ++it) //Go through the triangle list to define meshs … … 780 835 lib3ds_mesh_resize_faces (mesh, numFace); 781 836 //lib3ds_mesh_resize_vertices() will be called in buildMesh() 782 buildMesh(geo, mat, index_vert, texcoords, mesh); 837 buildMesh(geo, mat, index_vert, texcoords, mesh); // May set _succeded to false 838 if (!succeeded()) 839 { 840 lib3ds_mesh_free(mesh); 841 return; 842 } 783 843 784 844 // "Reset" values and start over a new mesh … … 790 850 791 851 mesh = lib3ds_mesh_new( getUniqueName(geo.getName().empty() ? geo.className() : geo.getName(), "geo").c_str()); 792 if (!mesh) throw "Allocation error"; 852 if (!mesh) 853 { 854 OSG_NOTIFY(osg::FATAL) << "Allocation error" << std::endl; 855 _succeeded = false; 856 return; 857 } 793 858 lib3ds_mesh_resize_faces (mesh, osg::minimum(nbTrianglesRemaining, MAX_FACES)); 794 859 lib3ds_mesh_resize_vertices(mesh, osg::minimum(nbVerticesRemaining, MAX_VERTICES), texcoords ? 0 : 1, 0); // Not mandatory but will allocate once a big block … … 800 865 face.material = it->first.material; 801 866 } 802 buildMesh(geo, mat, index_vert, texcoords, mesh); //When a Mesh is completed without restriction of vertices number 867 868 buildMesh(geo, mat, index_vert, texcoords, mesh); // May set _succeded to false 869 if (!succeeded()) 870 { 871 lib3ds_mesh_free(mesh); 872 return; 873 } 803 874 } 804 875 … … 812 883 { 813 884 if (geo->getVertexArray() && geo->getVertexArray()->getType() != osg::Array::Vec3ArrayType) 814 throw "Vertex array is not Vec3. Not implemented"; // TODO 885 { 886 // TODO Handle double presision vertices by converting them to float with a warning 887 OSG_NOTIFY(osg::FATAL) << "Vertex array is not Vec3. Not implemented" << std::endl; 888 _succeeded = false; 889 return; 890 } 815 891 const osg::Vec3Array * vecs = geo->getVertexArray() ? static_cast<osg::Vec3Array *>(geo->getVertexArray()) : NULL; 816 892 if (vecs) … … 819 895 // Texture coords 820 896 if (geo->getTexCoordArray(0) && geo->getTexCoordArray(0)->getType() != osg::Array::Vec2ArrayType) 821 throw "Texture coords array is not Vec2. Not implemented"; // TODO 897 { 898 OSG_NOTIFY(osg::FATAL) << "Texture coords array is not Vec2. Not implemented" << std::endl; 899 _succeeded = false; 900 return; 901 } 822 902 const osg::Vec2Array * texvecs = geo->getTexCoordArray(0) ? static_cast<osg::Vec2Array *>(geo->getTexCoordArray(0)) : NULL; 823 903 if (texvecs) 824 904 { 825 905 unsigned int nb = geo->getTexCoordArray(0)->getNumElements(); 826 if (nb != geo->getVertexArray()->getNumElements()) throw "There are more/less texture coords than vertices!"; 906 if (nb != geo->getVertexArray()->getNumElements()) 907 { 908 OSG_NOTIFY(osg::FATAL) << "There are more/less texture coords than vertices (corrupted geometry)" << std::endl; 909 _succeeded = false; 910 return; 911 } 827 912 texcoords = true; 828 913 } … … 842 927 } 843 928 844 bool WriterNodeVisitor::suceedLastApply() const 845 { 846 return _suceedLastApply; 847 } 848 849 void WriterNodeVisitor::failedApply() 850 { 851 _suceedLastApply = false; 852 osg::notify(osg::NOTICE) << "Error going through node" << std::endl; 853 } 854 855 void WriterNodeVisitor::apply( osg::Geode &node ) { 929 void WriterNodeVisitor::apply( osg::Geode &node ) 930 { 856 931 pushStateSet(node.getStateSet()); 857 932 //_nameStack.push_back(node.getName()); … … 865 940 { 866 941 pushStateSet(g->getStateSet()); 867 createListTriangle(g, listTriangles, texcoords, i); 942 createListTriangle(g, listTriangles, texcoords, i); // May set _succeded to false 868 943 popStateSet(g->getStateSet()); 869 } 870 } 871 if (count > 0) 944 if (!succeeded()) break; 945 } 946 } 947 if (succeeded() && count > 0) 872 948 { 873 949 osg::Matrix mat( osg::computeLocalToWorld(getNodePath()) ); 874 buildFaces(node, mat, listTriangles, texcoords); 950 buildFaces(node, mat, listTriangles, texcoords); // May set _succeded to false 875 951 } 876 952 popStateSet(node.getStateSet()); 877 953 //_nameStack.pop_back(); 878 if (suc eedLastApply())954 if (succeeded()) 879 955 traverse(node); 880 956 } 881 957 882 void WriterNodeVisitor::apply( osg::Billboard &node ) { 958 void WriterNodeVisitor::apply( osg::Billboard &node ) 959 { 883 960 // TODO Does not handle Billboards' points yet 884 961 … … 889 966 ListTriangle listTriangles; 890 967 bool texcoords = false; 891 osg::notify(osg::NOTICE) << "Warning: 3DS writer is incomplete for Billboards (rotation not implemented)." << std::endl;968 OSG_NOTIFY(osg::NOTICE) << "Warning: 3DS writer is incomplete for Billboards (rotation not implemented)." << std::endl; 892 969 osg::Matrix m( osg::computeLocalToWorld(getNodePath()) ); 893 970 for ( unsigned int i = 0; i < count; i++ ) … … 901 978 pushStateSet(g->getStateSet()); 902 979 createListTriangle(g, listTriangles, texcoords, i); 903 popStateSet(g->getStateSet()); 980 popStateSet(g->getStateSet()); // May set _succeded to false 981 if (!succeeded()) break; 904 982 905 983 osg::Matrix currentBillBoardMat(osg::Matrix::translate(node.getPosition(i)) * m); // TODO handle rotation 906 984 apply3DSMatrixNode(node, currentBillBoardMat, "bil"); // Add a 3DS matrix node 907 buildFaces(node, currentBillBoardMat, listTriangles, texcoords); 908 } 909 } 910 911 if (suceedLastApply()) 985 buildFaces(node, currentBillBoardMat, listTriangles, texcoords); // May set _succeded to false 986 if (!succeeded()) break; 987 } 988 } 989 990 if (succeeded()) 912 991 traverse(node); 913 992 _cur3dsNode = parent; … … 922 1001 Lib3dsMeshInstanceNode * parent = _cur3dsNode; 923 1002 apply3DSMatrixNode(node, osg::computeLocalToWorld(getNodePath()), "grp"); 924 if (suc eedLastApply())1003 if (succeeded()) 925 1004 traverse(node); 926 1005 _cur3dsNode = parent; … … 933 1012 Lib3dsMeshInstanceNode * parent = _cur3dsNode; 934 1013 apply3DSMatrixNode(node, osg::computeLocalToWorld(getNodePath()), "mtx"); 935 if (suc eedLastApply())1014 if (succeeded()) 936 1015 traverse(node); 937 1016 _cur3dsNode = parent; -
OpenSceneGraph/trunk/src/osgPlugins/3ds/WriterNodeVisitor.h
r11194 r11203 59 59 const std::string & srcDirectory); 60 60 61 bool suceedLastApply() const; 62 void failedApply(); 61 bool succeeded() const { return _succeeded; } 63 62 virtual void apply(osg::Geode &node); 64 63 virtual void apply(osg::Billboard &node); … … 146 145 * \return the number of vertices in the geode. 147 146 */ 148 unsigned int 149 calcVertices(osg::Geode & geo); 147 unsigned int calcVertices(osg::Geode & geo); 150 148 151 149 /** … … 198 196 void apply3DSMatrixNode(osg::Node &node, const osg::Matrix & m, const char * const prefix); 199 197 200 bool _suc eedLastApply;198 bool _succeeded; 201 199 std::string _directory; 202 200 std::string _srcDirectory;
