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