Panda3D
 All Classes Functions Variables Enumerations
objToEggConverter.h
1 // Filename: ObjToEggConverter.h
2 // Created by: drose (07Dec10)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef OBJTOEGGCONVERTER_H
16 #define OBJTOEGGCONVERTER_H
17 
18 #include "pandatoolbase.h"
19 
20 #include "somethingToEggConverter.h"
21 #include "eggVertexPool.h"
22 #include "eggGroup.h"
23 #include "geomVertexData.h"
24 #include "geomVertexWriter.h"
25 #include "geomPrimitive.h"
26 #include "geomNode.h"
27 #include "pandaNode.h"
28 #include "pvector.h"
29 #include "epvector.h"
30 
31 ////////////////////////////////////////////////////////////////////
32 // Class : ObjToEggConverter
33 // Description : Convert an Obj file to egg data.
34 ////////////////////////////////////////////////////////////////////
36 public:
40 
42 
43  virtual string get_name() const;
44  virtual string get_extension() const;
45  virtual bool supports_compressed() const;
46  virtual bool supports_convert_to_node(const LoaderOptions &options) const;
47 
48  virtual bool convert_file(const Filename &filename);
49  virtual PT(PandaNode) convert_to_node(const LoaderOptions &options, const Filename &filename);
50 
51 protected:
52  bool process(const Filename &filename);
53  bool process_line(const string &line);
54  bool process_ref_plane_res(const string &line);
55 
56  bool process_v(vector_string &words);
57  bool process_vt(vector_string &words);
58  bool process_xvt(vector_string &words);
59  bool process_xvc(vector_string &words);
60  bool process_vn(vector_string &words);
61  bool process_f(vector_string &words);
62  bool process_g(vector_string &words);
63 
64  EggVertex *get_face_vertex(const string &face_reference);
65 
66  bool process_node(const Filename &filename);
67  bool process_line_node(const string &line);
68 
69  bool process_f_node(vector_string &words);
70  bool process_g_node(vector_string &words);
71 
72  void generate_points();
73  int add_synth_normal(const LVecBase3 &normal);
74 
75  // Read from the obj file.
76  int _line_number;
77  typedef epvector<LVecBase4> Vec4Table;
78  typedef epvector<LVecBase3> Vec3Table;
79  typedef epvector<LVecBase2> Vec2Table;
81 
82  Vec4Table _v_table;
83  Vec3Table _vn_table, _rgb_table;
84  Vec3Table _vt_table;
85  Vec2Table _xvt_table;
86  Vec3Table _synth_vn_table;
87  UniqueVec3Table _unique_synth_vn_table;
88  LVecBase2 _ref_plane_res;
89  bool _v4_given, _vt3_given;
90  bool _f_given;
91 
92  pset<string> _ignored_tags;
93 
94  // Structures filled when creating an egg file.
95  PT(EggVertexPool) _vpool;
96  PT(EggGroup) _root_group;
97  EggGroup *_current_group;
98 
99  // Structures filled when creating a PandaNode directly.
100  PT(PandaNode) _root_node;
101 
102  class VertexEntry {
103  public:
104  VertexEntry();
105  VertexEntry(const ObjToEggConverter *converter, const string &obj_vertex);
106 
107  INLINE bool operator < (const VertexEntry &other) const;
108  INLINE bool operator == (const VertexEntry &other) const;
109  INLINE bool matches_except_normal(const VertexEntry &other) const;
110 
111  // The 1-based vertex, texcoord, and normal index numbers
112  // appearing in the obj file for this vertex. 0 if the index
113  // number is not given.
114  int _vi, _vti, _vni;
115 
116  // The 1-based index number to the synthesized normal, if needed.
117  int _synth_vni;
118  };
121 
122  class VertexData {
123  public:
124  VertexData(PandaNode *parent, const string &name);
125 
126  int add_vertex(const ObjToEggConverter *converter, const VertexEntry &entry);
127  void add_triangle(const ObjToEggConverter *converter, const VertexEntry &v0,
128  const VertexEntry &v1, const VertexEntry &v2,
129  int synth_vni);
130  void close_geom(const ObjToEggConverter *converter);
131 
132  PT(PandaNode) _parent;
133  string _name;
134  PT(GeomNode) _geom_node;
135 
136  PT(GeomPrimitive) _prim;
137  VertexEntries _entries;
138  UniqueVertexEntries _unique_entries;
139 
140  bool _v4_given, _vt3_given;
141  bool _vt_given, _rgb_given, _vn_given;
142  };
143 
144  VertexData *_current_vertex_data;
145 
146  friend class VertexData;
147 };
148 
149 #include "objToEggConverter.I"
150 
151 #endif
A basic node of the scene graph or data graph.
Definition: pandaNode.h:72
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:105
virtual SomethingToEggConverter * make_copy()
Allocates and returns a new copy of the converter.
Specifies parameters that may be passed to the loader.
Definition: loaderOptions.h:26
This is an abstract base class for a family of classes that represent the fundamental geometry primit...
Definition: geomPrimitive.h:63
virtual string get_name() const
Returns the English name of the file type this converter supports.
virtual bool convert_file(const Filename &filename)
Handles the reading of the input file and converting it to egg.
The main glue of the egg hierarchy, this corresponds to the &lt;Group&gt;, &lt;Instance&gt;, and &lt;Joint&gt; type nod...
Definition: eggGroup.h:36
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
Any one-, two-, three-, or four-component vertex, possibly with attributes such as a normal...
Definition: eggVertex.h:41
virtual bool supports_compressed() const
Returns true if this file type can transparently load compressed files (with a .pz extension)...
Convert an Obj file to egg data.
This is the base class for all two-component vectors and points.
Definition: lvecBase2.h:105
virtual string get_extension() const
Returns the common extension of the file type this converter supports.
This is a base class for a family of converter classes that manage a conversion from some file type t...
A collection of vertices.
Definition: eggVertexPool.h:46
virtual bool supports_convert_to_node(const LoaderOptions &options) const
Returns true if this converter can directly convert the model type to internal Panda memory structure...
A node that holds Geom objects, renderable pieces of geometry.
Definition: geomNode.h:37