~saiarcot895/ubuntu/trusty/openscenegraph/armhf-support

« back to all changes in this revision

Viewing changes to OpenSceneGraph/src/osgPlugins/mdl/ReaderWriterMDL.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Loic Dachary (OuoU)
  • Date: 2009-03-23 14:08:20 UTC
  • mfrom: (1.1.7 upstream) (2.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20090323140820-i4j3jozdlhyn4lre
rules prevent lib64 with -D LIB_POSTFIX="" (Closes: #517671)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
10
using namespace mdl;
 
11
using namespace osg;
 
12
using namespace osgDB;
 
13
 
 
14
 
 
15
const char* ReaderWriterMDL::className() const
 
16
{
 
17
    // Return a description of this class
 
18
    return "Valve/Source Engine MDL Reader";
 
19
}
 
20
 
 
21
 
 
22
bool 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
 
 
29
ReaderWriter::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
 
 
71
REGISTER_OSGPLUGIN(mdl, ReaderWriterMDL)
 
72