40 if (result ==
nullptr) {
42 for (
int i = 0; i < num_textures && result ==
nullptr; i++) {
73 if (result ==
nullptr) {
75 for (
int i = 0; i < num_textures && result ==
nullptr; i++) {
97 if (result ==
nullptr) {
99 for (
int i = 0; i < num_textures && result ==
nullptr; i++) {
121 if (result ==
nullptr) {
123 for (
int i = 0; i < num_textures && result ==
nullptr; i++) {
145 if (result ==
nullptr) {
147 for (
int i = 0; i < num_textures && result ==
nullptr; i++) {
169 if (result ==
nullptr) {
171 for (
int i = 0; i < num_textures && result ==
nullptr; i++) {
193 if (result ==
nullptr) {
195 for (
int i = 0; i < num_textures && result ==
nullptr; i++) {
218 EggPrimitive::Shading EggPrimitive::
219 get_shading()
const {
227 if (!first_vertex->has_normal()) {
230 for (
size_t i = 1; i < get_num_vertices(); ++i) {
232 if (!vertex->has_normal()) {
244 if (!first_vertex->has_color()) {
247 for (
size_t i = 1; i < get_num_vertices(); ++i) {
249 if (!vertex->has_color()) {
266 EggAttributes::operator = (other);
274 EggAttributes::operator = (other);
275 _textures = other._textures;
290 Vertices::const_iterator vi;
291 for (vi = _vertices.begin(); vi != _vertices.end(); ++vi) {
292 if ((*vi)->has_normal()) {
309 Vertices::const_iterator vi;
310 for (vi = _vertices.begin(); vi != _vertices.end(); ++vi) {
311 if ((*vi)->has_color()) {
338 if (shading == S_unknown) {
343 if (!has_color() && shading != S_overall) {
344 if (shading != S_per_vertex) {
348 for (pi = begin(); pi != end() && !has_color(); ++pi) {
350 if (vertex->has_color()) {
357 set_color(LColor(1.0f, 1.0f, 1.0f, 1.0f));
366 for (pi = begin(); pi != end(); ++pi) {
369 if (!vertex->has_normal() && has_normal()) {
372 if (!vertex->has_color() && has_color()) {
377 nassertv(vertex_pool !=
nullptr);
379 vertex->copy_grefs_from(*orig_vertex);
392 for (pi = begin(); pi != end(); ++pi) {
395 if (vertex->has_normal()) {
399 vertex->clear_normal();
401 if (vertex->has_color()) {
405 vertex->clear_color();
409 nassertv(vertex_pool !=
nullptr);
411 vertex->copy_grefs_from(*orig_vertex);
421 if (!has_color() && shading == S_overall) {
422 set_color(LColor(1.0f, 1.0f, 1.0f, 1.0f));
437 do_apply_flat_attribute(size() - 1,
this);
452 do_apply_flat_attribute(0,
this);
469 if (has_normal() && !vertex->has_normal()) {
470 vertex->set_normal(get_normal());
472 if (has_color() && !vertex->has_color()) {
489 reverse(_vertices.begin(), _vertices.end());
518 if (!_vertices.empty()) {
519 Vertices new_vertices;
520 Vertices::iterator vi, vlast;
521 vi = _vertices.begin();
522 new_vertices.push_back(*vi);
527 while (vi != _vertices.end()) {
528 if ((*vi)->get_pos4() != (*vlast)->get_pos4()) {
529 new_vertices.push_back(*vi);
531 prepare_remove_vertex(*vi, vi - _vertices.begin() - num_removed,
532 _vertices.size() - num_removed);
538 _vertices.swap(new_vertices);
544 while (_vertices.size() > 1 &&
545 _vertices.back()->get_pos4() == _vertices.front()->get_pos4()) {
546 prepare_remove_vertex(_vertices.back(), _vertices.size() - 1,
548 _vertices.pop_back();
561 Vertices::iterator vi;
562 Vertices new_vertices;
566 for (vi = _vertices.begin(); vi != _vertices.end(); ++vi) {
567 bool inserted = unique_vertices.insert(*vi).second;
569 new_vertices.push_back(*vi);
571 prepare_remove_vertex(*vi, vi - _vertices.begin() - num_removed,
572 _vertices.size() - num_removed);
577 _vertices.swap(new_vertices);
609 for (vi = begin(); vi != end(); ++vi) {
610 if ((*vi)->has_normal()) {
623 EggPrimitive::iterator EggPrimitive::
624 erase(iterator first, iterator last) {
627 for (i = first; i != last; ++i) {
628 prepare_remove_vertex(*i, first - _vertices.begin(),
629 _vertices.size() - num_removed);
632 iterator result = _vertices.erase((Vertices::iterator &)first,
633 (Vertices::iterator &)last);
634 test_vref_integrity();
644 PT_EggVertex vpt = vertex;
645 return std::find(begin(), end(), vpt);
655 prepare_add_vertex(vertex, _vertices.size(), _vertices.size() + 1);
656 _vertices.push_back(vertex);
658 vertex->test_pref_integrity();
659 test_vref_integrity();
670 PT_EggVertex vpt = vertex;
671 iterator i = std::find(begin(), end(), vpt);
673 return PT_EggVertex();
678 vertex->test_pref_integrity();
679 test_vref_integrity();
690 nassertv(index < size());
691 iterator i = begin() + index;
696 test_vref_integrity();
706 _vertices.reserve(other.size());
709 for (vi = other.begin(); vi != other.end(); ++vi) {
713 test_vref_integrity();
714 other.test_vref_integrity();
724 test_vref_integrity()
const {
727 if ((
int)size() <= egg_test_vref_integrity) {
736 for (vi = begin(); vi != end(); ++vi) {
740 VertexCount::iterator vci = _count.find(vert);
741 if (vci == _count.end()) {
750 VertexCount::iterator vci;
751 for (vci = _count.begin(); vci != _count.end(); ++vci) {
754 int count = (*vci).second;
755 int vert_count = vert->
has_pref(
this);
757 nassertv(count == vert_count);
773 prepare_add_vertex(
EggVertex *vertex,
int i,
int n) {
785 vertex->_pref.insert(
this);
801 prepare_remove_vertex(
EggVertex *vertex,
int i,
int n) {
810 EggVertex::PrimitiveRef::iterator pri = vertex->_pref.find(
this);
814 nassertv(pri != vertex->_pref.end());
816 vertex->_pref.erase(pri);
824 write_body(std::ostream &out,
int indent_level)
const {
825 test_vref_integrity();
831 for (
int i = 0; i < num_textures; i++) {
834 indent(out, indent_level) <<
"<TRef> { ";
842 indent(out, indent_level) <<
"<MRef> { ";
848 indent(out, indent_level) <<
"<BFace> { 1 }\n";
855 nassertv(pool !=
nullptr);
860 if ((
int)size() < 10) {
862 indent(out, indent_level) <<
"<VertexRef> {";
864 for (i = begin(); i != end(); ++i) {
866 vert->test_pref_integrity();
881 for (i = begin(); i != end(); ++i) {
883 vert->test_pref_integrity();
891 indent(out, indent_level) <<
"<VertexRef> {\n";
894 indent(out, indent_level+2) <<
"<Ref> { ";
896 indent(out, indent_level) <<
"}\n";
908 egg_start_parse_body() {
909 egg_start_primitive_body();
923 r_transform(
const LMatrix4d &mat,
const LMatrix4d &, CoordinateSystem) {
931 r_flatten_transforms() {
937 size_t num_vertices = size();
938 for (
size_t i = 0; i < num_vertices; i++) {
943 new_vertex.transform(mat);
957 Textures new_textures;
958 Textures::const_iterator ti;
959 for (ti = _textures.begin(); ti != _textures.end(); ++ti) {
963 new_textures.push_back(texture);
968 new_textures.push_back(texture);
976 new_texture.clear_transform();
979 new_textures.push_back(unique);
984 size_t num_vertices = size();
985 for (
size_t i = 0; i < num_vertices; i++) {
989 if (uv_obj !=
nullptr) {
992 LTexCoord3d uvw = uv_obj->
get_uvw() * mat;
994 new_uv_obj->set_uvw(uvw);
996 new_uv_obj->set_uv(LTexCoordd(uvw[0], uvw[1]));
998 new_vertex.set_uv_obj(new_uv_obj);
1010 _textures.swap(new_textures);
1019 do_apply_flat_attribute(
int vertex_index,
EggAttributes *attrib) {
1025 bool significant_change =
false;
1030 if (attrib->has_normal()) {
1031 new_vertex->copy_normal(*attrib);
1033 if (orig_vertex->has_normal() &&
1035 significant_change =
true;
1037 }
else if (has_normal()) {
1038 new_vertex->copy_normal(*
this);
1040 if (orig_vertex->has_normal() &&
1042 significant_change =
true;
1046 if (attrib->has_color()) {
1047 new_vertex->copy_color(*attrib);
1049 if (orig_vertex->has_color() &&
1051 significant_change =
true;
1053 }
else if (has_color()) {
1054 new_vertex->copy_color(*
this);
1056 if (orig_vertex->has_color() &&
1058 significant_change =
true;
1062 if (significant_change) {
1063 new_vertex =
get_pool()->create_unique_vertex(*new_vertex);
1064 new_vertex->copy_grefs_from(*orig_vertex);
1077 set_connected_shading(EggPrimitive::Shading shading,
1079 ConnectedShadingNodes connected_nodes;
1081 r_set_connected_shading(0, shading, neighbor, connected_nodes);
1085 while (!connected_nodes.empty()) {
1086 ConnectedShadingNodes next_nodes;
1087 next_nodes.swap(connected_nodes);
1089 ConnectedShadingNodes::iterator ni;
1090 for (ni = next_nodes.begin(); ni != next_nodes.end(); ++ni) {
1091 r_set_connected_shading(0, (*ni)._shading, (*ni)._neighbor, connected_nodes);
1101 r_set_connected_shading(
int stack_depth, EggPrimitive::Shading shading,
1103 ConnectedShadingNodes &next_nodes) {
1104 if (stack_depth > egg_recursion_limit) {
1106 ConnectedShadingNode next;
1107 next._shading = shading;
1108 next._neighbor = neighbor;
1109 next_nodes.push_back(next);
1113 bool propagate =
false;
1115 if (_connected_shading == S_unknown) {
1121 if (shading > _connected_shading) {
1124 _connected_shading = shading;
1127 }
else if (shading == S_overall && _connected_shading == S_overall) {
1136 if (!neighbor->has_color() && has_color() && _drgbas.empty() &&
1137 get_color() == LColor(1.0f, 1.0f, 1.0f, 1.0f)) {
1139 }
else if (!has_color() && neighbor->has_color() && neighbor->_drgbas.empty() &&
1140 neighbor->
get_color() == LColor(1.0f, 1.0f, 1.0f, 1.0f)) {
1145 _connected_shading = S_per_face;
1151 Vertices::const_iterator vi;
1152 for (vi = _vertices.begin(); vi != _vertices.end(); ++vi) {
1154 EggVertex::PrimitiveRef::const_iterator pi;
1158 (*pi)->r_set_connected_shading(stack_depth + 1, _connected_shading,
this,
A base class for any of a number of kinds of geometry primitives: polygons, point lights,...
The set of UV's that may or may not be assigned to a vertex.
get_material
Returns a pointer to the applied material, or NULL if there is no material applied.
AlphaMode get_alpha_mode() const
Returns the alpha mode that was set, or AM_unspecified if nothing was set.
VisibilityMode get_visibility_mode() const
Returns the visibility mode that was set, or VM_unspecified if nothing was set.
virtual void unify_attributes(Shading shading)
If the shading property is S_per_vertex, ensures that all vertices have a normal and a color,...
This is our own Panda specialization on the default STL map.
virtual EggRenderMode * determine_bin()
Walks back up the hierarchy, looking for an EggGroup or EggPrimitive or some such object at this leve...
const EggVertexUV * get_uv_obj(const std::string &name) const
Returns the named EggVertexUV object, which defines both the UV coordinate pair for this name and the...
EggTexture * create_unique_texture(const EggTexture ©, int eq)
Creates a new texture if there is not already one equivalent (according to eq, see EggTexture::is_equ...
get_uv_name
Returns the texcoord name that has been specified for this texture, or the empty string if no texcoor...
bool has_bin() const
Returns true if a bin name has been set for this particular object.
virtual void apply_first_attribute()
Sets the first vertex of the triangle (or each component) to the primitive normal and/or color,...
EggVertexPool * get_pool() const
Returns the vertex pool this vertex belongs in.
virtual void apply_last_attribute()
Sets the last vertex of the triangle (or each component) to the primitive normal and/or color,...
const LMatrix4d & get_vertex_frame() const
Returns the coordinate frame of the vertices referenced by primitives at or under this node.
virtual bool cleanup()
Cleans up modeling errors in whatever context this makes sense.
const LTexCoord3d & get_uvw() const
Returns the texture coordinate triple, if get_num_dimensions() is 3.
ostream & enquote_string(ostream &out, const string &str, int indent_level, bool always_quote)
Writes the string to the indicated output stream.
void clear()
Removes all of the vertices from the primitive.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Defines a texture map that may be applied to geometry.
bool has_vertex_color() const
Returns true if any vertex on the primitive has a specific color set, false otherwise.
virtual EggRenderMode * determine_draw_order()
Walks back up the hierarchy, looking for an EggGroup or EggPrimitive or some such object at this leve...
void transform(const LMatrix4d &mat)
Applies the indicated transformation matrix to the attributes.
void copy_vertices(const EggPrimitive &other)
Replaces the current primitive's list of vertices with a copy of the list of vertices on the other pr...
virtual EggRenderMode * determine_depth_test_mode()
Walks back up the hierarchy, looking for an EggGroup or EggPrimitive or some such object at this leve...
void copy_normal(const EggAttributes &other)
Sets this normal to be the same as the other's, include morphs.
set_bface_flag
Sets the backfacing flag of the polygon.
bool affects_polygon_alpha() const
Returns true if this texture's environment type or combine mode allows the texture to have an effect ...
void copy_attributes(const EggAttributes &other)
Copies the rendering attributes from the indicated primitive.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_shading
Returns the shading properties apparent on this particular primitive.
bool test_ref_count_integrity() const
Does some easy checks to make sure that the reference count isn't completely bogus.
This is a collection of textures by TRef name.
virtual EggRenderMode * determine_alpha_mode()
Walks back up the hierarchy, looking for an EggGroup or EggPrimitive or some such object at this leve...
set_material
Applies the indicated material to the primitive.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
remove_vertex
Removes the indicated vertex from the primitive and returns it.
LColor get_color() const
Returns the color set on this particular attribute.
bool matches_color(const EggAttributes &other) const
Returns true if this color matches that of the other EggAttributes object, include the morph list.
bool has_vertex_normal() const
Returns true if any vertex on the primitive has a specific normal set, false otherwise.
get_vertex
Returns a particular index based on its index number.
DepthWriteMode get_depth_write_mode() const
Returns the depth_write mode that was set, or DWM_unspecified if nothing was set.
bool matches_normal(const EggAttributes &other) const
Returns true if this normal matches that of the other EggAttributes object, include the morph list.
void write(std::ostream &out, int indent_level) const
Writes the attributes to the indicated output stream in Egg format.
set_vertex
Replaces a particular vertex based on its index number in the list of vertices.
This class stores miscellaneous rendering properties that is associated with geometry,...
The set of attributes that may be applied to vertices as well as polygons, such as surface normal and...
int get_index() const
Returns the index number of the vertex within its pool.
virtual EggRenderMode * determine_depth_test_mode()
Walks back up the hierarchy, looking for an EggGroup or EggPrimitive or some such object at this leve...
virtual bool has_primitives() const
Returns true if there are any primitives (e.g.
bool has_w() const
Returns true if the texture coordinate has a third, w component, false if it is just a normal 2-d tex...
bool is_local_coord() const
Returns true if this node's vertices are not in the global coordinate space.
virtual void reverse_vertex_ordering()
Reverses the ordering of the vertices in this primitive, if appropriate, in order to change the direc...
void copy_color(const EggAttributes &other)
Sets this color to be the same as the other's, include morphs.
virtual void post_apply_flat_attribute()
Intended as a followup to apply_last_attribute(), this also sets an attribute on the first vertices o...
virtual EggRenderMode * determine_visibility_mode()
Walks back up the hierarchy, looking for an EggGroup or EggPrimitive or some such object at this leve...
Any one-, two-, three-, or four-component vertex, possibly with attributes such as a normal.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
void remove_nonunique_verts()
Removes any multiple appearances of the same vertex from the primitive.
virtual bool joint_has_primitives() const
Returns true if there are any primitives (e.g.
PrimitiveRef::const_iterator pref_end() const
Returns an iterator that can, in conjunction with pref_begin(), be used to traverse the entire set of...
iterator find(EggVertex *vertex)
Returns the iterator pointing to the indicated vertex, or end() if the vertex is not part of the prim...
virtual EggRenderMode * determine_depth_offset()
Walks back up the hierarchy, looking for an EggGroup or EggPrimitive or some such object at this leve...
virtual bool has_normals() const
Returns true if any of the primitives (e.g.
void write_long_list(std::ostream &out, int indent_level, InputIterator ifirst, InputIterator ilast, std::string first_prefix="", std::string later_prefix="", int max_col=72)
Writes a list of things to the indicated output stream, with a space separating each item.
virtual EggRenderMode * determine_depth_write_mode()
Walks back up the hierarchy, looking for an EggGroup or EggPrimitive or some such object at this leve...
virtual EggRenderMode * determine_alpha_mode()
Walks back up the hierarchy, looking for an EggGroup or EggPrimitive or some such object at this leve...
int has_pref(const EggPrimitive *prim) const
Returns the number of times the vertex appears in the indicated primitive, or 0 if it does not appear...
void write(std::ostream &out, int indent_level) const
Writes the attributes to the indicated output stream in Egg format.
bool has_draw_order() const
Returns true if the draw-order flag has been set for this particular object.
virtual EggRenderMode * determine_bin()
Walks back up the hierarchy, looking for an EggGroup or EggPrimitive or some such object at this leve...
get_num_textures
Returns the number of textures applied to the primitive.
virtual EggRenderMode * determine_draw_order()
Walks back up the hierarchy, looking for an EggGroup or EggPrimitive or some such object at this leve...
get_pool
Returns the vertex pool associated with the vertices of the primitive, or NULL if the primitive has n...
get_texture
Returns the first texture on the primitive, if any, or NULL if there are no textures on the primitive...
bool has_depth_offset() const
Returns true if the depth-offset flag has been set for this particular object.
void replace(iterator position, EggVertex *vertex)
Replaces the vertex at the indicated position with the indicated vertex.
virtual EggRenderMode * determine_visibility_mode()
Walks back up the hierarchy, looking for an EggGroup or EggPrimitive or some such object at this leve...
This is our own Panda specialization on the default STL set.
get_bface_flag
Retrieves the backfacing flag of the polygon.
void remove_doubled_verts(bool closed)
Certain kinds of primitives, particularly polygons, don't like to have the same vertex repeated conse...
void copy_grefs_from(const EggVertex &other)
Copies all the group references from the other vertex onto this one.
bool has_name() const
Returns true if the Namable has a nonempty name set, false if the name is empty.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle is the identifier used to differentiate C++ class types.
PrimitiveRef::const_iterator pref_begin() const
Returns an iterator that can, in conjunction with pref_end(), be used to traverse the entire set of p...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual EggRenderMode * determine_depth_offset()
Walks back up the hierarchy, looking for an EggGroup or EggPrimitive or some such object at this leve...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
EggVertex * create_unique_vertex(const EggVertex ©)
Creates a new vertex in the pool that is a copy of the indicated one and returns it.
A collection of vertices.
EggVertex * add_vertex(EggVertex *vertex)
Adds the indicated vertex to the end of the primitive's list of vertices, and returns it.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
DepthTestMode get_depth_test_mode() const
Returns the depth_test mode that was set, or DTM_unspecified if nothing was set.
virtual EggRenderMode * determine_depth_write_mode()
Walks back up the hierarchy, looking for an EggGroup or EggPrimitive or some such object at this leve...
has_material
Returns true if the primitive is materiald (and get_material() will return a real pointer),...