Panda3D
|
00001 // Filename: eggMesherStrip.h 00002 // Created by: drose (13Mar05) 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 #ifndef EGGMESHERSTRIP_H 00016 #define EGGMESHERSTRIP_H 00017 00018 #include "pandabase.h" 00019 #include "eggVertexPool.h" 00020 #include "eggPrimitive.h" 00021 #include "eggMesherEdge.h" 00022 #include "plist.h" 00023 00024 class EggMesherEdge; 00025 00026 //////////////////////////////////////////////////////////////////// 00027 // Class : EggMesherStrip 00028 // Description : Represents a triangle strip or quad strip in 00029 // progress, as assembled by the mesher. It might also 00030 // represent a single polygon such as a triangle or 00031 // quad, since that's how strips generally start out. 00032 //////////////////////////////////////////////////////////////////// 00033 class EggMesherStrip { 00034 public: 00035 enum PrimType { 00036 PT_poly, 00037 PT_point, 00038 PT_line, 00039 PT_tri, 00040 PT_tristrip, 00041 PT_trifan, 00042 PT_quad, 00043 PT_quadstrip, 00044 PT_linestrip, 00045 }; 00046 00047 enum MesherOrigin { 00048 MO_unknown, 00049 MO_user, 00050 MO_firstquad, 00051 MO_fanpoly, 00052 MO_mate 00053 }; 00054 00055 EggMesherStrip(PrimType prim_type, MesherOrigin origin); 00056 EggMesherStrip(const EggPrimitive *prim, int index, const EggVertexPool *vertex_pool, 00057 bool flat_shaded); 00058 INLINE EggMesherStrip(const EggMesherStrip ©); 00059 00060 PT(EggPrimitive) make_prim(const EggVertexPool *vertex_pool); 00061 00062 void measure_sheet(const EggMesherEdge *edge, int new_row, 00063 int &num_prims, int &num_rows, 00064 int first_row_id, int this_row_id, 00065 int this_row_distance); 00066 void cut_sheet(int first_row_id, int do_mate, 00067 const EggVertexPool *vertex_pool); 00068 00069 bool mate(const EggVertexPool *vertex_pool); 00070 bool find_ideal_mate(EggMesherStrip *&mate, EggMesherEdge *&common_edge, 00071 const EggVertexPool *vertex_pool); 00072 static bool mate_pieces(EggMesherEdge *common_edge, EggMesherStrip &front, 00073 EggMesherStrip &back, const EggVertexPool *vertex_pool); 00074 static bool mate_strips(EggMesherEdge *common_edge, EggMesherStrip &front, 00075 EggMesherStrip &back, PrimType type); 00076 static bool must_invert(const EggMesherStrip &front, const EggMesherStrip &back, 00077 bool will_reverse_back, PrimType type); 00078 static bool convex_quad(EggMesherEdge *common_edge, EggMesherStrip &front, 00079 EggMesherStrip &back, const EggVertexPool *vertex_pool); 00080 00081 int count_neighbors() const; 00082 void output_neighbors(ostream &out) const; 00083 00084 INLINE bool is_coplanar_with(const EggMesherStrip &other, PN_stdfloat threshold) const; 00085 INLINE PN_stdfloat coplanarity(const EggMesherStrip &other) const; 00086 INLINE int type_category() const; 00087 00088 int find_uncommon_vertex(const EggMesherEdge *edge) const; 00089 const EggMesherEdge *find_opposite_edge(int vi) const; 00090 const EggMesherEdge *find_opposite_edge(const EggMesherEdge *edge) const; 00091 const EggMesherEdge *find_adjacent_edge(const EggMesherEdge *edge) const; 00092 00093 INLINE void rotate_forward(); 00094 INLINE void rotate_back(); 00095 void rotate_to_front(const EggMesherEdge *edge); 00096 void rotate_to_back(const EggMesherEdge *edge); 00097 bool can_invert() const; 00098 bool invert(); 00099 00100 INLINE EggMesherEdge get_head_edge() const; 00101 INLINE EggMesherEdge get_tail_edge() const; 00102 00103 bool is_odd() const; 00104 bool would_reverse_tail(PrimType want_type) const; 00105 void convert_to_type(PrimType want_type); 00106 00107 void combine_edges(EggMesherStrip &other, int remove_sides); 00108 void remove_all_edges(); 00109 00110 // ptr equality 00111 INLINE bool operator == (const EggMesherStrip &other) const; 00112 INLINE bool operator != (const EggMesherStrip &other) const; 00113 00114 bool pick_mate(const EggMesherStrip &a_strip, const EggMesherStrip &b_strip, 00115 const EggMesherEdge &a_edge, const EggMesherEdge &b_edge, 00116 const EggVertexPool *vertex_pool) const; 00117 00118 bool pick_sheet_mate(const EggMesherStrip &a_strip, 00119 const EggMesherStrip &b_strip) const; 00120 00121 void output(ostream &out) const; 00122 00123 typedef plist<CPT(EggPrimitive) > Prims; 00124 typedef plist<EggMesherEdge *> Edges; 00125 typedef plist<int> Verts; 00126 00127 Prims _prims; 00128 Edges _edges; 00129 Verts _verts; 00130 00131 enum MesherStatus { 00132 MS_alive, 00133 MS_dead, 00134 MS_done, 00135 MS_paired 00136 }; 00137 00138 PrimType _type; 00139 int _index; 00140 MesherStatus _status; 00141 00142 bool _planar; 00143 LNormald _plane_normal; 00144 PN_stdfloat _plane_offset; 00145 int _row_id, _row_distance; 00146 MesherOrigin _origin; 00147 bool _flat_shaded; 00148 }; 00149 00150 INLINE ostream & 00151 operator << (ostream &out, const EggMesherStrip &strip) { 00152 strip.output(out); 00153 return out; 00154 } 00155 00156 #include "eggMesherStrip.I" 00157 00158 #endif