Panda3D
 All Classes Functions Variables Enumerations
dxfToEggLayer.cxx
1 // Filename: dxfToEggLayer.cxx
2 // Created by: drose (04May04)
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 #include "dxfToEggLayer.h"
16 #include "dxfToEggConverter.h"
17 
18 #include "dxfFile.h"
19 #include "eggGroup.h"
20 #include "eggPolygon.h"
21 #include "eggLine.h"
22 #include "eggVertex.h"
23 #include "eggVertexPool.h"
24 
25 
26 ////////////////////////////////////////////////////////////////////
27 // Function: DXFToEggLayer::Constructor
28 // Access: Public
29 // Description:
30 ////////////////////////////////////////////////////////////////////
31 DXFToEggLayer::
32 DXFToEggLayer(const string &name, EggGroupNode *parent) : DXFLayer(name) {
33  _group = new EggGroup(name);
34  parent->add_child(_group);
35  _vpool = new EggVertexPool(name);
36  _group->add_child(_vpool);
37 }
38 
39 
40 ////////////////////////////////////////////////////////////////////
41 // Function: DXFToEggLayer::add_polygon
42 // Access: Public
43 // Description: Given that done_entity() has just been called and that
44 // the current entity represents a polygon, adds the
45 // corresponding polygon to the layer's EggGroup and
46 // vertex pool.
47 ////////////////////////////////////////////////////////////////////
48 void DXFToEggLayer::
50  EggPolygon *poly = new EggPolygon;
51  _group->add_child(poly);
52 
53  const DXFFile::Color &color = entity->get_color();
54  poly->set_color(LColor(color.r, color.g, color.b, 1.0));
55 
56  // A polyline's vertices are stored in the attached vector by
57  // dxf.cxx. They were defined in the DXF file using a series of
58  // "VERTEX" entries.
59 
60  // For a 3dface, the vertices are defined explicitly as part of the
61  // entity; but in this case, they were added to the vector before
62  // add_polygon() was called.
63 
64  DXFVertices::const_iterator vi;
65  for (vi = entity->_verts.begin();
66  vi != entity->_verts.end();
67  ++vi) {
68  poly->add_vertex(add_vertex(*vi));
69  }
70 
71  poly->cleanup();
72 }
73 
74 
75 ////////////////////////////////////////////////////////////////////
76 // Function: DXFToEggLayer::add_line
77 // Access: Public
78 // Description: Similar to add_polygon(), but adds a set of point
79 // lights instead.
80 ////////////////////////////////////////////////////////////////////
81 void DXFToEggLayer::
82 add_line(const DXFToEggConverter *entity) {
83  EggLine *line = new EggLine;
84  _group->add_child(line);
85 
86  const DXFFile::Color &color = entity->get_color();
87  line->set_color(LColor(color.r, color.g, color.b, 1.0));
88 
89  DXFVertices::const_iterator vi;
90  for (vi = entity->_verts.begin();
91  vi != entity->_verts.end();
92  ++vi) {
93  line->add_vertex(add_vertex(*vi));
94  }
95 }
96 
97 
98 ////////////////////////////////////////////////////////////////////
99 // Function: DXFToEggLayer::add_vertex
100 // Access: Public
101 // Description: Adds a unique vertex to the layer's vertex pool and
102 // returns it. If the vertex was already defined
103 // previously, returns the original definition. This is
104 // designed to share the common vertices within a layer.
105 ////////////////////////////////////////////////////////////////////
107 add_vertex(const DXFVertex &vert) {
108  EggVertex egg_vert;
109  egg_vert.set_pos(vert._p);
110 
111  return _vpool->create_unique_vertex(egg_vert);
112 }
void add_line(const DXFToEggConverter *entity)
Similar to add_polygon(), but adds a set of point lights instead.
This represents a "layer" as read from the DXF file.
Definition: dxfLayer.h:31
A line segment, or a series of connected line segments, defined by a <Line> entry.
Definition: eggLine.h:27
void set_pos(double pos)
Sets the vertex position.
Definition: eggVertex.I:54
A base class for nodes in the hierarchy that are not leaf nodes.
Definition: eggGroupNode.h:51
EggVertex * add_vertex(const DXFVertex &vertex)
Adds a unique vertex to the layer's vertex pool and returns it.
void add_polygon(const DXFToEggConverter *entity)
Given that done_entity() has just been called and that the current entity represents a polygon...
virtual bool cleanup()
Cleans up modeling errors in whatever context this makes sense.
Definition: eggPolygon.cxx:36
The main glue of the egg hierarchy, this corresponds to the <Group>, <Instance>, and <Joint> type nod...
Definition: eggGroup.h:36
Any one-, two-, three-, or four-component vertex, possibly with attributes such as a normal...
Definition: eggVertex.h:41
A single polygon.
Definition: eggPolygon.h:26
const Color & get_color() const
This is a convenience function to return the r,g,b color of the current entity (at the time of done_e...
Definition: dxfFile.cxx:499
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:111
EggNode * add_child(EggNode *node)
Adds the indicated child to the group and returns it.
Stored within DXFFile, this is the basic Vertex data of a DXF file.
Definition: dxfVertex.h:30
A collection of vertices.
Definition: eggVertexPool.h:46
EggVertex * add_vertex(EggVertex *vertex)
Adds the indicated vertex to the end of the primitive's list of vertices, and returns it...
This class supervises the construction of an EggData structure from a DXF file.