Panda3D
|
00001 // Filename: dxfToEggLayer.cxx 00002 // Created by: drose (04May04) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #include "dxfToEggLayer.h" 00016 #include "dxfToEggConverter.h" 00017 00018 #include "dxfFile.h" 00019 #include "eggGroup.h" 00020 #include "eggPolygon.h" 00021 #include "eggLine.h" 00022 #include "eggVertex.h" 00023 #include "eggVertexPool.h" 00024 00025 00026 //////////////////////////////////////////////////////////////////// 00027 // Function: DXFToEggLayer::Constructor 00028 // Access: Public 00029 // Description: 00030 //////////////////////////////////////////////////////////////////// 00031 DXFToEggLayer:: 00032 DXFToEggLayer(const string &name, EggGroupNode *parent) : DXFLayer(name) { 00033 _group = new EggGroup(name); 00034 parent->add_child(_group); 00035 _vpool = new EggVertexPool(name); 00036 _group->add_child(_vpool); 00037 } 00038 00039 00040 //////////////////////////////////////////////////////////////////// 00041 // Function: DXFToEggLayer::add_polygon 00042 // Access: Public 00043 // Description: Given that done_entity() has just been called and that 00044 // the current entity represents a polygon, adds the 00045 // corresponding polygon to the layer's EggGroup and 00046 // vertex pool. 00047 //////////////////////////////////////////////////////////////////// 00048 void DXFToEggLayer:: 00049 add_polygon(const DXFToEggConverter *entity) { 00050 EggPolygon *poly = new EggPolygon; 00051 _group->add_child(poly); 00052 00053 const DXFFile::Color &color = entity->get_color(); 00054 poly->set_color(LColor(color.r, color.g, color.b, 1.0)); 00055 00056 // A polyline's vertices are stored in the attached vector by 00057 // dxf.cxx. They were defined in the DXF file using a series of 00058 // "VERTEX" entries. 00059 00060 // For a 3dface, the vertices are defined explicitly as part of the 00061 // entity; but in this case, they were added to the vector before 00062 // add_polygon() was called. 00063 00064 DXFVertices::const_iterator vi; 00065 for (vi = entity->_verts.begin(); 00066 vi != entity->_verts.end(); 00067 ++vi) { 00068 poly->add_vertex(add_vertex(*vi)); 00069 } 00070 00071 poly->cleanup(); 00072 } 00073 00074 00075 //////////////////////////////////////////////////////////////////// 00076 // Function: DXFToEggLayer::add_line 00077 // Access: Public 00078 // Description: Similar to add_polygon(), but adds a set of point 00079 // lights instead. 00080 //////////////////////////////////////////////////////////////////// 00081 void DXFToEggLayer:: 00082 add_line(const DXFToEggConverter *entity) { 00083 EggLine *line = new EggLine; 00084 _group->add_child(line); 00085 00086 const DXFFile::Color &color = entity->get_color(); 00087 line->set_color(LColor(color.r, color.g, color.b, 1.0)); 00088 00089 DXFVertices::const_iterator vi; 00090 for (vi = entity->_verts.begin(); 00091 vi != entity->_verts.end(); 00092 ++vi) { 00093 line->add_vertex(add_vertex(*vi)); 00094 } 00095 } 00096 00097 00098 //////////////////////////////////////////////////////////////////// 00099 // Function: DXFToEggLayer::add_vertex 00100 // Access: Public 00101 // Description: Adds a unique vertex to the layer's vertex pool and 00102 // returns it. If the vertex was already defined 00103 // previously, returns the original definition. This is 00104 // designed to share the common vertices within a layer. 00105 //////////////////////////////////////////////////////////////////// 00106 EggVertex *DXFToEggLayer:: 00107 add_vertex(const DXFVertex &vert) { 00108 EggVertex egg_vert; 00109 egg_vert.set_pos(vert._p); 00110 00111 return _vpool->create_unique_vertex(egg_vert); 00112 }