root/OpenSceneGraph/trunk/src/osgPlugins/lws/ReaderWriterLWS.cpp @ 13041

Revision 13041, 2.4 kB (checked in by robert, 2 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/*******************************************************
2      Lightwave Scene Loader for OSG
3
4  Copyright (C) 2004 Marco Jez <marco.jez@poste.it>
5  OpenSceneGraph is (C) 2004 Robert Osfield
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
23class ReaderWriterLWS : public osgDB::ReaderWriter
24{
25public:
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        // code for setting up the database path so that internally referenced file are searched for on relative paths.
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
62protected:
63
64
65
66};
67
68lwosg::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            // no options yet!
77        }
78    }
79
80    return conv_options;
81}
82
83
84// register with Registry to instantiate the above reader/writer.
85REGISTER_OSGPLUGIN(lws, ReaderWriterLWS)
Note: See TracBrowser for help on using the browser.