Panda3D
eggPolysetMaker.cxx
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file eggPolysetMaker.cxx
10  * @author drose
11  * @date 2001-06-20
12  */
13 
14 #include "eggPolysetMaker.h"
15 #include "eggPolygon.h"
16 
17 TypeHandle EggPolysetMaker::_type_handle;
18 
19 /**
20  *
21  */
22 EggPolysetMaker::
23 EggPolysetMaker() {
24  _properties = 0;
25 }
26 
27 /**
28  * Sets the set of properties that determines which polygons are allowed to be
29  * grouped together into a single polyset. This is the bitwise 'or' of all
30  * the properties that matter. If this is 0, all polygons (within a given
31  * group) will be lumped into a common polyset regardless of their properties.
32  */
34 set_properties(int properties) {
35  _properties = properties;
36 }
37 
38 /**
39  *
40  */
41 int EggPolysetMaker::
42 get_bin_number(const EggNode *node) {
43  if (node->is_of_type(EggPolygon::get_class_type())) {
44  return (int)BN_polyset;
45  }
46 
47  return (int)BN_none;
48 }
49 
50 
51 /**
52  *
53  */
55 sorts_less(int bin_number, const EggNode *a, const EggNode *b) {
56  nassertr((BinNumber)bin_number == BN_polyset, false);
57 
58  const EggPolygon *pa = DCAST(EggPolygon, a);
59  const EggPolygon *pb = DCAST(EggPolygon, b);
60 
61  if ((_properties & (P_has_texture | P_texture)) != 0) {
62  bool a_has_texture = (pa->get_num_textures() > 0);
63  bool b_has_texture = (pb->get_num_textures() > 0);
64  if (a_has_texture != b_has_texture) {
65  return ((int)a_has_texture < (int)b_has_texture);
66  }
67  }
68  if ((_properties & (P_texture)) != 0) {
69  int num_textures = std::min(pa->get_num_textures(), pb->get_num_textures());
70  for (int i = 0; i < num_textures; i++) {
71  EggTexture *a_texture = pa->get_texture(i);
72  EggTexture *b_texture = pb->get_texture(i);
73  if (a_texture != b_texture) {
74  return (a_texture->sorts_less_than(*b_texture, ~EggTexture::E_tref_name));
75  }
76  }
77  if (pa->get_num_textures() != pb->get_num_textures()) {
78  return (pa->get_num_textures() < pb->get_num_textures());
79  }
80  }
81  if ((_properties & (P_has_material | P_material)) != 0) {
82  if (pa->has_material() != pb->has_material()) {
83  return ((int)pa->has_material() < (int)pb->has_material());
84  }
85  }
86  if ((_properties & (P_material)) != 0) {
87  if (pa->has_material()) {
88  return (pa->get_material()->sorts_less_than(*pb->get_material(), ~EggMaterial::E_mref_name));
89  }
90  }
91  if ((_properties & (P_has_poly_color)) != 0) {
92  if (pa->has_color() != pb->has_color()) {
93  return ((int)pa->has_color() < (int)pb->has_color());
94  }
95  }
96  if ((_properties & (P_poly_color)) != 0) {
97  if (pa->get_color() != pb->get_color()) {
98  return (pa->get_color() < pb->get_color());
99  }
100  }
101  if ((_properties & (P_has_poly_normal)) != 0) {
102  if (pa->has_normal() != pb->has_normal()) {
103  return ((int)pa->has_normal() < (int)pb->has_normal());
104  }
105  }
106  if ((_properties & (P_has_vertex_normal)) != 0) {
107  bool pa_has_normal = pa->has_vertex_normal();
108  bool pb_has_normal = pb->has_vertex_normal();
109  if (pa_has_normal != pb_has_normal) {
110  return ((int)pa_has_normal < (int)pb_has_normal);
111  }
112  }
113  if ((_properties & (P_has_vertex_color)) != 0) {
114  bool pa_has_color = pa->has_vertex_color();
115  bool pb_has_color = pb->has_vertex_color();
116  if (pa_has_color != pb_has_color) {
117  return ((int)pa_has_color < (int)pb_has_color);
118  }
119  }
120  if ((_properties & (P_bface)) != 0) {
121  if (pa->get_bface_flag() != pb->get_bface_flag()) {
122  return ((int)pa->get_bface_flag() < (int)pb->get_bface_flag());
123  }
124  }
125 
126  return false;
127 }
get_material
Returns a pointer to the applied material, or NULL if there is no material applied.
Definition: eggPrimitive.h:115
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void set_properties(int properties)
Sets the set of properties that determines which polygons are allowed to be grouped together into a s...
Defines a texture map that may be applied to geometry.
Definition: eggTexture.h:30
bool has_vertex_color() const
Returns true if any vertex on the primitive has a specific color set, false otherwise.
virtual bool sorts_less(int bin_number, const EggNode *a, const EggNode *b)
May be overridden in derived classes to create additional bins within a particular bin number,...
LColor get_color() const
Returns the color set on this particular attribute.
Definition: eggAttributes.I:91
bool has_vertex_normal() const
Returns true if any vertex on the primitive has a specific normal set, false otherwise.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool sorts_less_than(const EggTexture &other, int eq) const
An ordering operator to compare two textures for sorting order.
Definition: eggTexture.cxx:405
A single polygon.
Definition: eggPolygon.h:24
get_num_textures
Returns the number of textures applied to the primitive.
Definition: eggPrimitive.h:100
A base class for things that may be directly added into the egg hierarchy.
Definition: eggNode.h:35
get_texture
Returns the first texture on the primitive, if any, or NULL if there are no textures on the primitive...
Definition: eggPrimitive.h:100
bool is_of_type(TypeHandle handle) const
Returns true if the current object is or derives from the indicated type.
Definition: typedObject.I:28
get_bface_flag
Retrieves the backfacing flag of the polygon.
Definition: eggPrimitive.h:116
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
has_material
Returns true if the primitive is materiald (and get_material() will return a real pointer),...
Definition: eggPrimitive.h:115