Changeset 7348
- Timestamp:
- 09/03/07 15:52:19 (6 years ago)
- Location:
- OpenSceneGraph/trunk/src/osgPlugins/Inventor
- Files:
-
- 2 added
- 5 modified
-
CMakeLists.txt (modified) (3 diffs)
-
ConvertFromInventor.cpp (modified) (7 diffs)
-
ConvertToInventor.cpp (added)
-
ConvertToInventor.h (added)
-
README.txt (modified) (2 diffs)
-
ReaderWriterIV.cpp (modified) (3 diffs)
-
ReaderWriterIV.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgPlugins/Inventor/CMakeLists.txt
r7025 r7348 3 3 INCLUDE_DIRECTORIES( ${INVENTOR_INCLUDE_DIR} ) 4 4 5 # Disable the build of a problem section in ConvertToInventor.cpp 6 ADD_DEFINITIONS(-DDISABLE_PROBLEM_COMPILE_SECTIONS) 5 7 6 8 SET(TARGET_SRC 9 ConvertToInventor.cpp 7 10 ConvertFromInventor.cpp 8 11 GroupSoLOD.cpp … … 10 13 ReaderWriterIV.cpp 11 14 ShuttleCallback.cpp 12 )15 ) 13 16 SET(TARGET_HDRS 17 ConvertToInventor.h 14 18 ConvertFromInventor.h 15 19 GroupSoLOD.h … … 17 21 ReaderWriterIV.h 18 22 ShuttleCallback.h 19 )23 ) 20 24 21 25 SET(TARGET_EXTERNAL_LIBRARIES ${INVENTOR_LIBRARY} ) -
OpenSceneGraph/trunk/src/osgPlugins/Inventor/ConvertFromInventor.cpp
r6544 r7348 41 41 #include <Inventor/SbLinear.h> 42 42 43 #ifdef COIN_BASIC_H43 #ifdef __COIN__ 44 44 #include <Inventor/VRMLnodes/SoVRMLImageTexture.h> 45 45 #endif … … 96 96 cbAction.addPostCallback(SoGroup::getClassTypeId(), postGroup, this); 97 97 cbAction.addPreCallback(SoTexture2::getClassTypeId(), preTexture, this); 98 #ifdef COIN_BASIC_H98 #ifdef __COIN__ 99 99 cbAction.addPreCallback(SoVRMLImageTexture::getClassTypeId(), 100 100 preVRMLImageTexture, this); … … 499 499 stateSet->clear(); 500 500 501 // Convert the IV texture to OSG texture if any 502 osg::ref_ptr<osg::Texture2D> texture; 503 const SoNode *ivTexture = soTexStack.top(); 504 if (ivTexture) 505 { 506 osg::notify(osg::INFO)<<"Have texture"<<std::endl; 507 508 // Found a corresponding OSG texture object 509 if (ivToOsgTexMap[ivTexture]) 510 texture = ivToOsgTexMap[ivTexture]; 511 else 512 { 513 // Create a new osg texture 514 texture = convertIVTexToOSGTex(ivTexture, action); 515 516 // Add the new texture to the database 517 ivToOsgTexMap[ivTexture] = texture.get(); 518 } 519 520 stateSet->setTextureAttributeAndModes(0, texture.get(), osg::StateAttribute::ON); 521 522 // Set the texture environment 523 osg::ref_ptr<osg::TexEnv> texEnv = new osg::TexEnv; 524 switch (action->getTextureModel()) 525 { 526 case SoTexture2::MODULATE: 527 texEnv->setMode(osg::TexEnv::MODULATE); 528 break; 529 case SoTexture2::DECAL: 530 texEnv->setMode(osg::TexEnv::DECAL); 531 break; 532 case SoTexture2::BLEND: 533 texEnv->setMode(osg::TexEnv::BLEND); 534 break; 535 536 // SGI's Inventor does not have REPLACE mode, but the Coin 3D library does. 537 // Coin supports REPLACE since 2.2 release, TGS Inventor from 4.0. 538 // Let's convert to the TexEnv anyway. 539 case (SoTexture2::Model)GL_REPLACE: // SoTexture2::REPLACE is the same as GL_REPLACE 540 texEnv->setMode(osg::TexEnv::REPLACE); 541 break; 542 } 543 stateSet->setTextureAttributeAndModes(0,texEnv.get(),osg::StateAttribute::ON); 544 } 545 501 546 SbColor ambient, diffuse, specular, emission; 502 547 float shininess, transparency; … … 507 552 508 553 // Set transparency 509 if (transparency > 0) 554 SbBool hasTextureTransparency = FALSE; 555 if (ivTexture) { 556 SbVec2s tmp; 557 int bpp; 558 if (ivTexture->isOfType(SoTexture2::getClassTypeId())) 559 ((SoTexture2*)ivTexture)->image.getValue(tmp, bpp); 560 #ifdef __COIN__ 561 else 562 if (ivTexture->isOfType(SoVRMLImageTexture::getClassTypeId())) { 563 const SbImage *img = ((SoVRMLImageTexture*)ivTexture)->getImage(); 564 if (img) img->getValue(tmp, bpp); 565 else bpp = 0; 566 } 567 #endif 568 hasTextureTransparency = bpp==4 || bpp==2; 569 } 570 571 if (transparency > 0 || hasTextureTransparency) 510 572 { 511 573 osg::ref_ptr<osg::BlendFunc> transparency = new osg::BlendFunc; … … 622 684 } 623 685 624 // Convert the IV texture to OSG texture if any625 osg::ref_ptr<osg::Texture2D> texture;626 if (soTexStack.top())627 {628 osg::notify(osg::INFO)<<"Have texture"<<std::endl;629 630 // Found a corresponding OSG texture object631 if (ivToOsgTexMap[soTexStack.top()])632 texture = ivToOsgTexMap[soTexStack.top()];633 else634 {635 // Create a new osg texture636 texture = convertIVTexToOSGTex(soTexStack.top(), action);637 638 // Add the new texture to the database639 ivToOsgTexMap[soTexStack.top()] = texture.get();640 }641 642 stateSet->setTextureAttributeAndModes(0,texture.get(), osg::StateAttribute::ON);643 644 // Set the texture environment645 osg::ref_ptr<osg::TexEnv> texEnv = new osg::TexEnv;646 switch (action->getTextureModel())647 {648 case SoTexture2::MODULATE:649 texEnv->setMode(osg::TexEnv::MODULATE);650 break;651 case SoTexture2::DECAL:652 texEnv->setMode(osg::TexEnv::DECAL);653 break;654 case SoTexture2::BLEND:655 texEnv->setMode(osg::TexEnv::BLEND);656 break;657 658 #ifdef __COIN__659 // SGI's Inventor does not have REPLACE mode, but the Coin 3D library does.660 // Coin supports REPLACE since 2.2 release, TGS Inventor from 4.0.661 case SoTexture2::REPLACE:662 texEnv->setMode(osg::TexEnv::REPLACE);663 break;664 #endif665 }666 stateSet->setTextureAttributeAndModes(0,texEnv.get(),osg::StateAttribute::ON);667 }668 669 686 return stateSet; 670 687 } … … 697 714 if (soNode->isOfType(SoTexture2::getClassTypeId())) 698 715 fileName = ((SoTexture2*)soNode)->filename.getValue().getString(); 699 #ifdef COIN_BASIC_H716 #ifdef __COIN__ 700 717 else 701 718 if (soNode->isOfType(SoVRMLImageTexture::getClassTypeId())) … … 734 751 735 752 // Set texture wrap mode 736 #ifdef COIN_BASIC_H753 #ifdef __COIN__ 737 754 if (soNode->isOfType(SoVRMLImageTexture::getClassTypeId())) { 738 755 // It looks like there is a high probability of bug in Coin (investigated on version 2.4.6). -
OpenSceneGraph/trunk/src/osgPlugins/Inventor/README.txt
r6543 r7348 1 1 ######################################################## 2 # # 2 3 # Inventor plugin # 3 # Supported file formats (import only): # 4 # # 5 # Supported import formats: # 4 6 # - iv (ascii, binary) file format # 5 # - vrml 1.0 # 6 # - vrml 2.0 (when using Coin) # 7 # - VRML 1.0 # 8 # - VRML 2.0 (when using Coin) # 9 # # 10 # Supported export formats: # 11 # - iv format # 12 # - VRML 1.0 # 13 # # 7 14 ######################################################## 8 15 … … 10 17 The plugin requires one of Inventor libraries: 11 18 12 - Coin (http://www.coin3d.org) - GPL, support of VRML 2.0 19 - Coin - GPL, support of VRML 2.0 20 (http://www.coin3d.org) 13 21 - SGI Inventor - LGPL 22 (http://oss.sgi.com/projects/inventor/) 14 23 - TGS Inventor - commercial 24 (http://www.tgs.com/) 15 25 16 26 -
OpenSceneGraph/trunk/src/osgPlugins/Inventor/ReaderWriterIV.cpp
r7076 r7348 11 11 #include <Inventor/nodekits/SoNodeKit.h> 12 12 #include <Inventor/nodes/SoSeparator.h> 13 #include <Inventor/actions/SoWriteAction.h> 14 #include <Inventor/actions/SoCallbackAction.h> 13 15 14 16 #ifdef COIN_BASIC_H … … 18 20 #include "ConvertFromInventor.h" 19 21 #include "GroupSoLOD.h" 22 #include "ConvertToInventor.h" 23 20 24 21 25 // Register with Registry to instantiate the inventor reader. … … 82 86 } 83 87 88 89 osgDB::ReaderWriter::WriteResult 90 ReaderWriterIV::writeNode(const osg::Node& node, const std::string& fileName, 91 const osgDB::ReaderWriter::Options* options) const 92 { 93 // accept extension 94 std::string ext = osgDB::getLowerCaseFileExtension(fileName); 95 if (!acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED; 96 bool useVRML1 = !isInventorExtension(osgDB::getFileExtension(fileName)); 97 98 osg::notify(osg::INFO) << "osgDB::ReaderWriterIV::writeNode() Writing file " 99 << fileName.data() << std::endl; 100 101 // Initialize Inventor 102 SoInteraction::init(); 103 104 // Convert OSG graph to Inventor graph 105 ConvertToInventor osg2iv; 106 osg2iv.setVRML1Conversion(useVRML1); 107 (const_cast<osg::Node*>(&node))->accept(osg2iv); 108 SoNode *ivRoot = osg2iv.getIvSceneGraph(); 109 if (ivRoot == NULL) 110 return WriteResult::ERROR_IN_WRITING_FILE; 111 ivRoot->ref(); 112 113 // Change prefix according to VRML spec: 114 // Node names must not begin with a digit, and must not contain spaces or 115 // control characters, single or double quote characters, backslashes, curly braces, 116 // the sharp (#) character, the plus (+) character or the period character. 117 if (useVRML1) 118 SoBase::setInstancePrefix("_"); 119 120 // Write Inventor graph to file 121 SoOutput out; 122 out.setHeaderString((useVRML1) ? "#VRML V1.0 ascii" : "#Inventor V2.1 ascii"); 123 if (!out.openFile(fileName.c_str())) 124 return WriteResult::ERROR_IN_WRITING_FILE; 125 SoWriteAction wa(&out); 126 wa.apply(ivRoot); 127 ivRoot->unref(); 128 129 return WriteResult::FILE_SAVED; 130 } -
OpenSceneGraph/trunk/src/osgPlugins/Inventor/ReaderWriterIV.h
r3694 r7348 12 12 virtual const char* className() const 13 13 { 14 return "Inventor Reader";14 return "Inventor reader/writer"; 15 15 } 16 16 17 bool isInventorExtension(const std::string& extension) const 18 { 19 return osgDB::equalCaseInsensitive(extension, "iv") ? true : false; 20 } 21 17 22 virtual bool acceptsExtension(const std::string& extension) const 18 23 { 19 return osgDB::equalCaseInsensitive(extension, "iv") ? true :24 return isInventorExtension(extension) ? true : 20 25 osgDB::equalCaseInsensitive(extension, "wrl") ? true : false; 21 26 } … … 24 29 const osgDB::ReaderWriter::Options *) const; 25 30 31 virtual WriteResult writeNode(const osg::Node& node, const std::string& filename, 32 const osgDB::ReaderWriter::Options* options = NULL) const; 26 33 }; 27 34
