Changeset 8264
- Timestamp:
- 04/30/08 17:25:52
- Files:
-
- OpenSceneGraph-TrainingMaterials/trunk/Sources/Exercises/07_databases/7d_ReaderWriterOptions/7d_ReaderWriterOptions.cpp (modified) (2 diffs)
- OpenSceneGraph-TrainingMaterials/trunk/Sources/Exercises/07_databases/7e_ReadCallback/7e_ReadCallback.cpp (modified) (1 diff)
- OpenSceneGraph-TrainingMaterials/trunk/Sources/Exercises/07_databases/7f_Plugins/7f_Plugins.cpp (modified) (1 diff)
- OpenSceneGraph-TrainingMaterials/trunk/Sources/Exercises/07_databases/7f_Plugins/models.txt (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
OpenSceneGraph-TrainingMaterials/trunk/Sources/Exercises/07_databases/7d_ReaderWriterOptions/7d_ReaderWriterOptions.cpp
r8120 r8264 1 1 #include <osg/ArgumentParser> 2 2 #include <osgDB/ReadFile> 3 #include <osgDB/WriteFile> 4 #include <osgViewer/Viewer> 3 5 4 6 #include <iostream> … … 6 8 int main( int argc, char **argv ) 7 9 { 8 std::cout<<"TODO "<<argv[0]<<std::endl; 10 // ReaderWriter::Options are used to pass data to plugins 11 // such custom file path list or controls specific to a plugin 12 // 13 // Example of options for th OpenFlight can be found at: 14 // http://www.openscenegraph.org/projects/osg/wiki/Support/KnowledgeBase/OpenFlight 15 // 16 // Your task is to set different options strings to control the OpenFlight 17 // loading and review the results in the resulting output.osg file. 18 std::cout<<"Exercise "<<argv[0]<<std::endl; 9 19 10 return 0; 20 osg::ref_ptr<osgDB::ReaderWriter::Options> options = new osgDB::ReaderWriter::Options; 21 // 1. set the OptionsString here: 22 23 osg::ref_ptr<osg::Node> node = osgDB::readNodeFile("VisualSimulation/Umemodellen/models/umemain_new.flt", options.get()); 24 if (!node) 25 { 26 std::cout<<"Could not loaded model"<<std::endl; 27 return 1; 28 } 29 30 osgDB::writeNodeFile(*node, "output.osg"); 31 32 osgViewer::Viewer viewer; 33 34 viewer.setSceneData(node.get()); 35 36 return viewer.run(); 11 37 } OpenSceneGraph-TrainingMaterials/trunk/Sources/Exercises/07_databases/7e_ReadCallback/7e_ReadCallback.cpp
r8120 r8264 1 1 #include <osg/ArgumentParser> 2 2 #include <osgDB/ReadFile> 3 #include <osgDB/Registry> 4 #include <osgViewer/Viewer> 3 5 4 6 #include <iostream> 5 7 8 9 class MyReadFileCallback : public osgDB::Registry::ReadFileCallback 10 { 11 public: 12 13 MyReadFileCallback() 14 { 15 } 16 17 virtual osgDB::ReaderWriter::ReadResult readNode(const std::string& filename, const osgDB::ReaderWriter::Options* options) 18 { 19 std::cout<<"MyReadFileCallback::readNode("<<filename<<")"<<std::endl; 20 osgDB::ReaderWriter::ReadResult result = osgDB::Registry::instance()->readNodeImplementation(filename,options); 21 return result; 22 } 23 24 }; 25 6 26 int main( int argc, char **argv ) 7 27 { 8 std::cout<<"TODO "<<argv[0]<<std::endl; 28 // This exercises explores how a user can 29 // an custom operations to loading of models 30 // in a way that is done automatically for all 31 // read objects calls, including with database 32 // paging 33 // 34 // Below we register a custom ReadFileCallback 35 // which has been defined above. Your task is create a file 36 // cache system, by using the following steps: 37 // 38 // 1. run "7e_ReadCallback cow.osg", look for the message 39 // and review the execution flow path the made this happen 40 // 41 // 2. Modify MyReadFileCallback so that it reads the file 42 // from disk then writes an .ive version of it to disk and 43 // then returns the loaded model as done previously. Rerun 44 // the example to verify that you new file has been generated. 45 // 46 // 3. Modify the MyReadFileCallback so that it checks for the 47 // existance of the .ive version of the file and loads this 48 // if it exists, other fallback to loading the actual file and 49 // write a copy with .ive to disk as per 2. 9 50 10 return 0; 51 osgDB::Registry::instance()->setReadFileCallback(new MyReadFileCallback); 52 53 osg::ArgumentParser arguments(&argc, argv); 54 55 osgViewer::Viewer viewer; 56 57 viewer.setSceneData(osgDB::readNodeFiles(arguments)); 58 if (viewer.getSceneData()) 59 { 60 std::cout<<"No data loaded, please specify a file"<<std::endl; 61 return 1; 62 } 63 64 return viewer.run(); 11 65 } OpenSceneGraph-TrainingMaterials/trunk/Sources/Exercises/07_databases/7f_Plugins/7f_Plugins.cpp
r8120 r8264 1 1 #include <osg/ArgumentParser> 2 2 #include <osgDB/ReadFile> 3 #include <osgDB/FileUtils> 4 #include <osgDB/FileNameUtils> 3 5 4 6 #include <iostream> 5 7 8 class ReaderWriterMine : public osgDB::ReaderWriter 9 { 10 public: 11 virtual const char* className() const { return "My Reader/Writer"; } 12 13 virtual bool acceptsExtension(const std::string& extension) const 14 { 15 return osgDB::equalCaseInsensitive(extension,"txt"); 16 } 17 18 virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) const 19 { 20 std::cout<<"ReaderWriterMine::readNode("<<file<<")"<<std::endl; 21 22 std::string ext = osgDB::getLowerCaseFileExtension(file); 23 if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; 24 25 std::string fileName = osgDB::findDataFile( file, options ); 26 if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; 27 28 // parse the text file assuming format: 29 // 30 // ModelName X Y Z FileName 31 // 32 // creating a group of the specified files 33 // with each file transformed by specified X Y Z 34 // and given the ModelName. Return the group 35 36 return 0; 37 } 38 }; 39 40 // now register with Registry to instantiate the above 41 // reader/writer. 42 REGISTER_OSGPLUGIN(myLoader, ReaderWriterMine) 43 6 44 int main( int argc, char **argv ) 7 45 { 8 std::cout<<"TODO "<<argv[0]<<std::endl; 46 // For this exercise we will write a custom 47 // ReaderWriter that will read files 48 49 osg::ref_ptr<osg::Node> node = osgDB::readNodeFile("models.txt"); 9 50 10 51 return 0;
