root/OpenSceneGraph/trunk/src/osgPlugins/mdl/ReaderWriterMDL.cpp @ 13041

Revision 13041, 1.8 kB (checked in by robert, 3 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
Line 
1#include <osg/Node>
2#include <osg/Notify>
3#include <osgDB/Registry>
4#include <osgDB/FileUtils>
5#include <osgDB/ReadFile>
6
7#include "ReaderWriterMDL.h"
8#include "MDLReader.h"
9
10using namespace mdl;
11using namespace osg;
12using namespace osgDB;
13
14
15const char* ReaderWriterMDL::className() const
16{
17    // Return a description of this class
18    return "Valve/Source Engine MDL Reader";
19}
20
21
22bool ReaderWriterMDL::acceptsExtension(const std::string& extension) const
23{
24    // If the extension is empty or "mdl", we accept it
25    return osgDB::equalCaseInsensitive(extension, "mdl") || extension.empty();
26}
27
28
29ReaderWriter::ReadResult ReaderWriterMDL::readNode(
30                                  const std::string& file,
31                                  const ReaderWriter::Options* options) const
32{
33    MDLReader *      mdlReader;
34    ref_ptr<Node>    result;
35
36    // See if we handle this kind of file
37    if (!acceptsExtension(osgDB::getFileExtension(file)))
38        return ReadResult::FILE_NOT_HANDLED;
39
40    // See if we can find the requested file
41    std::string fileName = osgDB::findDataFile(file, options, CASE_INSENSITIVE);
42    if (fileName.empty())
43        return ReadResult::FILE_NOT_FOUND;
44
45    // Read the file (pass the base name and not the file that was found, this
46    // allows us to also find the .vvd and .vtx files without the leading
47    // path confusing things)
48    mdlReader = new MDLReader();
49    if (mdlReader->readFile(file))
50    {
51        // Get the results of our read
52        result = mdlReader->getRootNode();
53
54        // Clean up the reader
55        delete mdlReader;
56
57        // Return the results
58        return ReadResult(result.get());
59    }
60    else
61    {
62        // Clean up the reader
63        delete mdlReader;
64
65        // Return the error
66        return ReadResult::ERROR_IN_READING_FILE;
67    }
68}
69
70
71REGISTER_OSGPLUGIN(mdl, ReaderWriterMDL)
Note: See TracBrowser for help on using the browser.