- Timestamp:
- 03/11/10 17:53:35 (3 years ago)
- Files:
-
- 1 modified
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
