00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef EGGPRIMITIVE_H
00020 #define EGGPRIMITIVE_H
00021
00022 #include <pandabase.h>
00023
00024 #include "eggNode.h"
00025 #include "eggAttributes.h"
00026 #include "eggVertex.h"
00027 #include "eggTexture.h"
00028 #include "eggMaterial.h"
00029 #include "eggRenderMode.h"
00030 #include "pt_EggTexture.h"
00031 #include "pt_EggMaterial.h"
00032 #include "vector_PT_EggVertex.h"
00033
00034 #include <pointerTo.h>
00035 #include "pvector.h"
00036
00037 class EggVertexPool;
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 class EXPCL_PANDAEGG EggPrimitive : public EggNode, public EggAttributes,
00053 public EggRenderMode
00054 {
00055
00056
00057
00058
00059
00060 private:
00061 typedef vector_PT_EggVertex Vertices;
00062
00063
00064
00065 public:
00066 INLINE EggPrimitive(const string &name = "");
00067 INLINE EggPrimitive(const EggPrimitive ©);
00068 INLINE EggPrimitive &operator = (const EggPrimitive ©);
00069 INLINE ~EggPrimitive();
00070
00071 virtual EggRenderMode *determine_alpha_mode();
00072 virtual EggRenderMode *determine_depth_write_mode();
00073 virtual EggRenderMode *determine_depth_test_mode();
00074 virtual EggRenderMode *determine_draw_order();
00075 virtual EggRenderMode *determine_bin();
00076
00077 INLINE void set_texture(EggTexture *texture);
00078 INLINE void clear_texture();
00079 INLINE EggTexture *get_texture() const;
00080 INLINE bool has_texture() const;
00081
00082 INLINE void set_material(EggMaterial *material);
00083 INLINE void clear_material();
00084 INLINE EggMaterial *get_material() const;
00085 INLINE bool has_material() const;
00086
00087 INLINE void set_bface_flag(bool flag);
00088 INLINE bool get_bface_flag() const;
00089
00090 bool has_vertex_normal() const;
00091 bool has_vertex_color() const;
00092
00093 virtual void reverse_vertex_ordering();
00094 virtual bool cleanup();
00095
00096 void remove_doubled_verts(bool closed);
00097 void remove_nonunique_verts();
00098
00099
00100
00101
00102
00103
00104
00105 #ifdef WIN32_VC
00106 typedef PT_EggVertex *pointer;
00107 typedef PT_EggVertex *const_pointer;
00108 #else
00109 typedef Vertices::const_pointer pointer;
00110 typedef Vertices::const_pointer const_pointer;
00111 #endif
00112 typedef Vertices::const_reference reference;
00113 typedef Vertices::const_reference const_reference;
00114 typedef Vertices::const_iterator iterator;
00115 typedef Vertices::const_iterator const_iterator;
00116 typedef Vertices::const_reverse_iterator reverse_iterator;
00117 typedef Vertices::const_reverse_iterator const_reverse_iterator;
00118 typedef Vertices::size_type size_type;
00119 typedef Vertices::difference_type difference_type;
00120
00121 INLINE iterator begin() const;
00122 INLINE iterator end() const;
00123 INLINE reverse_iterator rbegin() const;
00124 INLINE reverse_iterator rend() const;
00125 INLINE bool empty() const;
00126 INLINE size_type size() const;
00127
00128 INLINE EggVertex *operator [] (int index) const;
00129
00130 INLINE iterator insert(iterator position, EggVertex *x);
00131 INLINE iterator erase(iterator position);
00132 iterator erase(iterator first, iterator last);
00133 INLINE void replace(iterator position, EggVertex *vertex);
00134 INLINE void clear();
00135
00136 EggVertex *add_vertex(EggVertex *vertex);
00137 EggVertex *remove_vertex(EggVertex *vertex);
00138 void copy_vertices(const EggPrimitive &other);
00139
00140
00141 INLINE void set_vertex(int index, EggVertex *vertex);
00142 INLINE EggVertex *get_vertex(int index) const;
00143
00144 INLINE EggVertexPool *get_pool() const;
00145
00146 #ifndef NDEBUG
00147 void test_vref_integrity() const;
00148 #else
00149 void test_vref_integrity() const { }
00150 #endif // NDEBUG
00151
00152 private:
00153 Vertices _vertices;
00154
00155
00156
00157
00158 void prepare_add_vertex(EggVertex *vertex);
00159 void prepare_remove_vertex(EggVertex *vertex);
00160
00161
00162 protected:
00163 void write_body(ostream &out, int indent_level) const;
00164
00165 virtual bool egg_start_parse_body();
00166 virtual void r_transform(const LMatrix4d &mat, const LMatrix4d &inv,
00167 CoordinateSystem to_cs);
00168 virtual void r_flatten_transforms();
00169 virtual void r_apply_texmats(EggTextureCollection &textures);
00170
00171
00172 private:
00173 PT_EggTexture _texture;
00174 PT_EggMaterial _material;
00175 bool _bface;
00176
00177 public:
00178
00179 static TypeHandle get_class_type() {
00180 return _type_handle;
00181 }
00182 static void init_type() {
00183 EggNode::init_type();
00184 EggAttributes::init_type();
00185 EggRenderMode::get_class_type();
00186 register_type(_type_handle, "EggPrimitive",
00187 EggNode::get_class_type(),
00188 EggAttributes::get_class_type(),
00189 EggRenderMode::get_class_type());
00190 }
00191 virtual TypeHandle get_type() const {
00192 return get_class_type();
00193 }
00194 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00195
00196 private:
00197 static TypeHandle _type_handle;
00198 };
00199
00200 #include "eggPrimitive.I"
00201
00202 #endif