Panda3D
eggToObjConverter.h
1 // Filename: eggToObjConverter.h
2 // Created by: drose (19Dec12)
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 EGGTOOBJCONVERTER_H
16 #define EGGTOOBJCONVERTER_H
17 
18 #include "pandatoolbase.h"
19 
20 #include "eggToSomethingConverter.h"
21 #include "eggVertexPool.h"
22 #include "eggGroup.h"
23 
24 ////////////////////////////////////////////////////////////////////
25 // Class : EggToObjConverter
26 // Description : Convert an obj file to egg data.
27 ////////////////////////////////////////////////////////////////////
29 public:
33 
35 
36  virtual string get_name() const;
37  virtual string get_extension() const;
38  virtual bool supports_compressed() const;
39 
40  virtual bool write_file(const Filename &filename);
41 
42 private:
44  class VertexDef {
45  public:
46  VertexDef();
47  int _vert3_index;
48  int _vert4_index;
49  int _uv2_index;
50  int _uv3_index;
51  int _norm_index;
52  };
54 
55  bool process(const Filename &filename);
56 
57  void collect_vertices(EggNode *egg_node);
58  void write_faces(ostream &out, EggNode *egg_node);
59  void write_group_reference(ostream &out, EggNode *egg_node);
60  void get_group_name(string &group_name, EggGroupNode *egg_group);
61 
62  void record_vertex(EggVertex *vertex);
63  int record_unique(UniqueVertices &unique, const LVecBase4d &vec);
64  int record_unique(UniqueVertices &unique, const LVecBase3d &vec);
65  int record_unique(UniqueVertices &unique, const LVecBase2d &vec);
66  int record_unique(UniqueVertices &unique, double pos);
67 
68  void write_vertices(ostream &out, const string &prefix, int num_components,
69  const UniqueVertices &unique);
70 
71 private:
72  bool _triangulate_polygons;
73 
74  UniqueVertices _unique_vert3, _unique_vert4, _unique_uv2, _unique_uv3, _unique_norm;
75  VertexMap _vmap;
76  EggGroupNode *_current_group;
77 };
78 
79 #endif
virtual bool supports_compressed() const
Returns true if this file type can transparently save compressed files (with a .pz extension)...
virtual string get_extension() const
Returns the common extension of the file type this converter supports.
This is the base class for all two-component vectors and points.
Definition: lvecBase2.h:1257
A base class for nodes in the hierarchy that are not leaf nodes.
Definition: eggGroupNode.h:51
virtual bool write_file(const Filename &filename)
Handles the conversion of the internal EggData to the target file format, written to the specified fi...
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:1677
virtual EggToSomethingConverter * make_copy()
Allocates and returns a new copy of the converter.
virtual string get_name() const
Returns the English name of the file type this converter supports.
This is a base class for a family of converter classes that manage a conversion from egg format to so...
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
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:1471
A base class for things that may be directly added into the egg hierarchy.
Definition: eggNode.h:38
Convert an obj file to egg data.