root/OpenSceneGraph/trunk/src/osgPlugins/vrml/ConvertToVRML.h @ 13041

Revision 13041, 3.5 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/*
2 *
3 * OSG to VRML2  converter for OpenSceneGraph.
4 *
5 * authors :
6 *           Johan Nouvel (johan_nouvel@yahoo.com)
7 *
8 *
9 */
10
11
12#ifndef __convert_to_vrml_to_osg_
13#define __convert_to_vrml_to_osg_ 1
14
15#include <fstream>
16#include <sstream>
17
18// OSG headers
19#include <osg/MatrixTransform>
20#include <osg/PositionAttitudeTransform>
21#include <osg/Geode>
22#include <osg/Billboard>
23#include <osg/Notify>
24#include <osg/LineWidth>
25#include <osg/Point>
26#include <osg/TexEnv>
27#include <osg/TexGen>
28#include <osg/Texture2D>
29#include <osg/PolygonMode>
30#include <osg/BlendFunc>
31#include <osg/Material>
32#include <osg/CullFace>
33#include <osg/LightModel>
34#include <osg/LOD>
35#include <osgUtil/TransformCallback>
36#include <osg/Object>
37#include <osgDB/ReaderWriter>
38#include <osg/NodeVisitor>
39
40#include <string>
41#include <stack>
42#include <osg/Node>
43#include <vector>
44#include <map>
45#include <stack>
46
47using namespace std;
48
49/**
50   * This function is called to write an osg graph into a VRML file
51   *
52   */
53osgDB::ReaderWriter::WriteResult convertToVRML(const osg::Node& root, const std::string& filename, const osgDB::ReaderWriter::Options* options=NULL) ;
54
55class ToVRML: public osg::NodeVisitor {
56  public:
57
58    typedef enum {
59      NO_TEXTURE = 0, KEEP_ORIGINAL_TEXTURE = 1, COPY_TEXTURE = 2, CONVERT_TEXTURE = 3
60    } TextureMode;
61    ToVRML(const std::string& fileName, const osgDB::ReaderWriter::Options* options);
62    virtual ~ToVRML();
63    osgDB::ReaderWriter::WriteResult result() {
64      return (_res);
65    }
66    ;
67
68    virtual void apply(osg::Geode& node);
69    virtual void apply(osg::Group& node);
70    virtual void apply(osg::Billboard& node);
71    virtual void apply(osg::MatrixTransform& node);
72    virtual void apply(osg::PositionAttitudeTransform& node);
73    virtual void apply(osg::Node& node);
74    virtual void apply(osg::LOD& node);
75
76    char *indent();
77    char *indentM();
78    char *indentL();
79    void pushStateSetStack(osg::StateSet* ss);
80    void popStateSetStack();
81    osg::StateSet* getCurrentStateSet();
82
83    //void findObjectName(osg::Object* obj,std::string& name, bool& alreadyLoaded);
84    void findMaterialName(osg::Material* mat, std::string& name, bool& alreadyLoaded);
85    void findTextureName(osg::Texture2D* tex, std::string& name, bool& alreadyLoaded);
86
87    void apply(osg::Geometry* geom);
88    void apply(osg::Drawable* drawable);
89    void writeAppearance(osg::StateSet* stateset);
90    void writeCoord(osg::Vec3Array* array);
91    template<typename T> void writeCoordIndex(GLenum mode, T* indices, unsigned int number, std::vector<int>& primitiveSetFaces, int& primitiveFaces);
92    void writeTexCoord(osg::Vec2Array* array, osg::Vec3Array* array2);
93    osg::Vec2Array* buildUVArray(osg::TexGen* tGen, osg::Vec3Array* array);
94    osg::Vec2Array* buildUVArray(osg::TexEnv* tEnv, osg::Vec3Array* array);
95    void writeUVArray(osg::Vec2Array* uvArray, osg::Texture::WrapMode wrap_s, osg::Texture::WrapMode wrap_t);
96    void writeNormal(osg::Geometry* geom, std::vector<int>& primitiveSetFaces, int nbFaces);
97    void writeColor(osg::Geometry* geom, std::vector<int>& primitiveSetFaces, int nbFaces);
98
99    osgDB::ReaderWriter::WriteResult _res;
100    ofstream _fout;
101    int _indent;
102    char* _strIndent;
103
104    map<osg::ref_ptr<osg::Texture2D>, std::string> _texMap;
105    map<osg::ref_ptr<osg::Material>, std::string> _matMap;
106    vector<osg::ref_ptr<osg::StateSet> > _stack;
107    osg::ref_ptr<osg::Image> _defaultImage;
108    std::string _pathToOutput;
109    std::string _pathRelativeToOutput;
110    TextureMode _textureMode;
111    int _txtUnit;
112
113};
114
115#endif
Note: See TracBrowser for help on using the browser.