1 /*
2  * Lightwave Object version 2 loader for Open Scene Graph
3  * Version 2 introduced in Lightwave v6.0
4  *
5  * Copyright (C) 2002 Pavel Moloshtan <pasha@moloshtan.com>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
20  *
21  * The Open Scene Graph (OSG) is a cross platform C++/OpenGL library for
22  * real-time rendering of large 3D photo-realistic models.
23  * The OSG homepage is http://www.openscenegraph.org/
24  */
25 
26 #ifndef LWO2_H
27 #define LWO2_H 1
28 
29 #include <vector>
30 #include <map>
31 #include <string>
32 
33 #include <osg/Referenced>
34 #include <osg/Vec2>
35 #include <osg/Vec3>
36 #include <osg/Geometry>
37 #include <osg/Group>
38 #include <osg/Notify>
39 
40 #include <osgDB/fstream>
41 
42 using namespace osg;
43 using namespace std;
44 
45 class Lwo2Layer;
46 struct Lwo2Surface;
47 struct Lwo2PolygonMapping;
48 
49 typedef vector< string >::iterator IteratorString;
50 typedef map< int, Lwo2Layer* >::iterator IteratorLayers;
51 typedef map< string, Lwo2Surface* >::iterator IteratorSurfaces;
52 typedef pair< const short, Lwo2PolygonMapping > PairVMAD;
53 
54 class Lwo2
55 {
56  public:
57   Lwo2();
58   ~Lwo2();
59   bool ReadFile( const string& filename );
60   bool GenerateGroup( Group& );
61 
62  private:
63   map< int, Lwo2Layer* > _layers;
64   map< string, Lwo2Surface* > _surfaces;
65   Lwo2Layer* _current_layer;
66   vector< string > _tags;
67   vector< string > _images;
68   osgDB::ifstream _fin;
69 
70   unsigned char _read_char();
71   unsigned short _read_short();
72   unsigned int _read_uint();
73   float _read_float();
74   string& _read_string(string&);
75 
76   bool _successfully_read;
77 
78   void _print_tag(unsigned int, unsigned int);
79   void _print_type(unsigned int);
80 
81   void _read_tag_strings(unsigned long);
82   void _read_layer(unsigned long);
83   void _read_points(unsigned long);
84   void _read_vertex_mapping(unsigned long);
85   void _read_polygons(unsigned long);
86   void _read_polygons_mapping(unsigned long);
87   void _read_polygon_tag_mapping(unsigned long);
88   void _read_image_definition(unsigned long);
89   void _read_surface(unsigned long);
90 
91   // generate StateSets for each surface
92   void _generate_statesets_from_surfaces();
93 };
94 
95 #endif
96