15 #include "eggMesherFanMaker.h"
16 #include "eggMesher.h"
17 #include "eggPolygon.h"
18 #include "eggGroupNode.h"
31 _edges.push_back(edge);
33 _strips.push_back(tri);
34 _planar = tri->_planar;
45 _vertex(copy._vertex),
47 _strips(copy._strips),
48 _planar(copy._planar),
58 void EggMesherFanMaker::
60 _vertex = copy._vertex;
62 _strips = copy._strips;
63 _planar = copy._planar;
64 _mesher = copy._mesher;
78 nassertr(_vertex == other._vertex,
false);
79 nassertr(_mesher == other._mesher,
false);
81 nassertr(!_edges.empty() && !other._edges.empty(),
false);
88 int my_back_b = my_back->_vi_b;
89 int other_front_a = other_front->_vi_a;
91 if (my_back_b == other_front_a) {
93 _edges.splice(_edges.end(), other._edges);
94 _strips.splice(_strips.end(), other._strips);
103 int my_front_a = my_front->_vi_a;
104 int other_back_b = other_back->_vi_b;
106 if (my_front_a == other_back_b) {
108 _edges.splice(_edges.begin(), other._edges);
109 _strips.splice(_strips.begin(), other._strips);
134 Edges::const_iterator ei;
135 for (ei = _edges.begin(); ei != _edges.end(); ++ei) {
141 angle += acos(dot(v1, v2));
144 return rad_2_deg(angle);
164 nassertr(_edges.size() == _strips.size(), 0);
166 int num_tris = _edges.size();
168 double avg_angle = net_angle / (double)num_tris;
170 if (avg_angle > egg_max_tfan_angle) {
176 if (egg_min_tfan_tris == 0 || num_tris < egg_min_tfan_tris) {
178 if (!egg_unroll_fans) {
193 Strips::iterator si, last_si;
194 Edges::iterator ei, last_ei;
199 si = _strips.begin();
203 int found_seam =
false;
205 for (++si, ++ei; si != _strips.end() && !found_seam; ++si, ++ei) {
206 nassertr(ei != _edges.end(), 0);
207 if ( ((*si)->_prims.front()->compare_to(*(*last_si)->_prims.front()) != 0) ||
208 !(*si)->is_coplanar_with(*(*last_si), egg_coplanar_threshold)) {
211 _edges.splice(_edges.begin(), _edges, ei, _edges.end());
212 _strips.splice(_strips.begin(), _strips, si, _strips.end());
218 si = _strips.begin();
224 for (++si, ++ei; si != _strips.end(); ++si, ++ei) {
225 nassertr(ei != _edges.end(), 0);
226 if ( ((*si)->_prims.front()->compare_to(*(*last_si)->_prims.front()) != 0) ||
227 !(*si)->is_coplanar_with(*(*last_si), egg_coplanar_threshold)) {
229 count +=
unroll(last_si, si, last_ei, ei, unrolled_tris);
234 count +=
unroll(last_si, si, last_ei, ei, unrolled_tris);
239 EggMesherStrip new_fan(EggMesherStrip::PT_trifan, EggMesherStrip::MO_fanpoly);
240 new_fan._verts.push_back(_vertex);
242 new_fan._verts.push_back(_edges.front()->_vi_a);
244 for (ei = _edges.begin(); ei != _edges.end(); ++ei) {
245 new_fan._verts.push_back((*ei)->_vi_b);
249 for (si = _strips.begin(); si != _strips.end(); ++si) {
250 new_fan._prims.splice(new_fan._prims.end(), (*si)->_prims);
251 (*si)->remove_all_edges();
252 (*si)->_verts.clear();
253 (*si)->_status = EggMesherStrip::MS_dead;
259 nassertr(new_fan._verts.size() == new_fan._prims.size() + 2, 0);
263 _mesher->_done.push_back(new_fan);
280 unroll(Strips::iterator strip_begin, Strips::iterator strip_end,
281 Edges::iterator edge_begin, Edges::iterator edge_end,
287 for (ei = edge_begin; ei != edge_end; ++ei) {
305 if ((*ei)->_vi_b != (*edge_begin)->_vi_a) {
310 poly->add_vertex(vertex_pool->
get_vertex((*edge_begin)->_vi_a));
313 for (ei = edge_begin; ei != edge_end; ++ei) {
314 poly->add_vertex(vertex_pool->
get_vertex((*ei)->_vi_b));
319 if (egg_show_quads) {
331 result = poly->triangulate_into(unrolled_tris,
true);
336 for (si = strip_begin; si != strip_end; ++si) {
337 (*si)->remove_all_edges();
338 (*si)->_verts.clear();
339 (*si)->_prims.clear();
340 (*si)->_status = EggMesherStrip::MS_dead;
353 void EggMesherFanMaker::
354 output(ostream &out)
const {
355 out << _vertex <<
":[";
356 if (!_edges.empty()) {
357 Edges::const_iterator ei;
358 for (ei = _edges.begin(); ei != _edges.end(); ++ei) {
359 out <<
" " << (*ei)->_vi_a;
361 out <<
" " << _edges.back()->_vi_b;
EggVertex * get_vertex(int index) const
Returns the vertex in the pool with the indicated index number, or NULL if no vertices have that inde...
EggVertex * add_vertex(EggVertex *vertex, int index=-1)
Adds the indicated vertex to the pool.
A base class for nodes in the hierarchy that are not leaf nodes.
bool is_valid() const
Returns true if the fan maker has enough edges to define at least one fan, false otherwise.
LVertexd get_pos3() const
Valid if get_num_dimensions() returns 3 or 4.
void copy_attributes(const EggAttributes &other)
Copies the rendering attributes from the indicated primitive.
int unroll(Strips::iterator strip_begin, Strips::iterator strip_end, Edges::iterator edge_begin, Edges::iterator edge_end, EggGroupNode *unrolled_tris)
Unrolls a planar subset of the current working fan, defined by the given iterators, into a series of triangles that zig-zag back and forth for better tristripping properties.
This class is used by EggMesher::find_fans() to attempt to make an EggTriangleFan out of the polygons...
Collects together unrelated EggPrimitives, determines their edge connectivity, and generates a set of...
double compute_angle() const
Returns the overall angle subtended by the fan, from the leading edge to the trailing edge...
int build(EggGroupNode *unrolled_tris)
Begins the fanning process.
bool is_coplanar_with(const EggMesherFanMaker &other) const
Returns true if the strip and the other strip are coplanar.
Represents one edge of a triangle, as used by the EggMesher to discover connected triangles...
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
EggNode * add_child(EggNode *node)
Adds the indicated child to the group and returns it.
Represents a triangle strip or quad strip in progress, as assembled by the mesher.
const EggMesherEdge * find_opposite_edge(int vi) const
Returns the first edge found that does not contain the given vertex.
bool join(EggMesherFanMaker &other)
Attempts to connect two fans end-to-end.
A collection of vertices.