| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | #if defined(_MSC_VER) |
|---|
| 9 | #pragma warning( disable : 4786 ) |
|---|
| 10 | #endif |
|---|
| 11 | |
|---|
| 12 | #include <string> |
|---|
| 13 | #include <sstream> |
|---|
| 14 | |
|---|
| 15 | #include <osgDB/Registry> |
|---|
| 16 | #include <osgDB/ReadFile> |
|---|
| 17 | #include <osgDB/FileNameUtils> |
|---|
| 18 | #include <osgDB/FileUtils> |
|---|
| 19 | |
|---|
| 20 | #include "SceneLoader.h" |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | class ReaderWriterLWS : public osgDB::ReaderWriter |
|---|
| 24 | { |
|---|
| 25 | public: |
|---|
| 26 | ReaderWriterLWS() |
|---|
| 27 | { |
|---|
| 28 | supportsExtension("lws","Lightwave scene format"); |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | virtual const char* className() const { return "ReaderWriterLWS"; } |
|---|
| 32 | |
|---|
| 33 | virtual bool acceptsExtension(const std::string &extension) const { |
|---|
| 34 | return osgDB::equalCaseInsensitive(extension, "lws"); |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | virtual ReadResult readNode(const std::string &file, const osgDB::ReaderWriter::Options *options) const |
|---|
| 38 | { |
|---|
| 39 | std::string ext = osgDB::getLowerCaseFileExtension(file); |
|---|
| 40 | if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; |
|---|
| 41 | |
|---|
| 42 | std::string fileName = osgDB::findDataFile(file, options); |
|---|
| 43 | if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | osg::ref_ptr<Options> local_opt = options ? static_cast<Options*>(options->clone(osg::CopyOp::SHALLOW_COPY)) : new Options; |
|---|
| 47 | local_opt->setDatabasePath(osgDB::getFilePath(fileName)); |
|---|
| 48 | |
|---|
| 49 | lwosg::SceneLoader::Options conv_options = parse_options(local_opt.get()); |
|---|
| 50 | |
|---|
| 51 | lwosg::SceneLoader scene_loader(conv_options); |
|---|
| 52 | osg::ref_ptr<osg::Node> node = scene_loader.load(fileName, local_opt.get()); |
|---|
| 53 | if (node.valid()) { |
|---|
| 54 | return node.release(); |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | return ReadResult::FILE_NOT_HANDLED; |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | lwosg::SceneLoader::Options parse_options(const Options *options) const; |
|---|
| 61 | |
|---|
| 62 | protected: |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | }; |
|---|
| 67 | |
|---|
| 68 | lwosg::SceneLoader::Options ReaderWriterLWS::parse_options(const Options *options) const |
|---|
| 69 | { |
|---|
| 70 | lwosg::SceneLoader::Options conv_options; |
|---|
| 71 | |
|---|
| 72 | if (options) { |
|---|
| 73 | std::istringstream iss(options->getOptionString()); |
|---|
| 74 | std::string opt; |
|---|
| 75 | while (iss >> opt) { |
|---|
| 76 | |
|---|
| 77 | } |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | return conv_options; |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | REGISTER_OSGPLUGIN(lws, ReaderWriterLWS) |
|---|