Panda3D

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