Panda3D

Loading...
Searching...
No Matches
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 */
22EggPolysetMaker::
23EggPolysetMaker() {
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 */
33 void EggPolysetMaker::
34 set_properties(int properties) {
35 _properties = properties;
36}
37
38/**
39 *
40 */
41 int EggPolysetMaker::
42get_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 */
54 bool EggPolysetMaker::
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}
EggAttributes::get_color
LColor get_color() const
Returns the color set on this particular attribute.
Definition eggAttributes.I:91
EggNode
A base class for things that may be directly added into the egg hierarchy.
Definition eggNode.h:36
EggPolygon
A single polygon.
Definition eggPolygon.h:24
EggPolysetMaker::sorts_less
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,...
Definition eggPolysetMaker.cxx:55
EggPolysetMaker::set_properties
void set_properties(int properties)
Sets the set of properties that determines which polygons are allowed to be grouped together into a s...
Definition eggPolysetMaker.cxx:34
EggPrimitive::get_material
get_material
Returns a pointer to the applied material, or NULL if there is no material applied.
Definition eggPrimitive.h:115
EggPrimitive::has_vertex_normal
bool has_vertex_normal() const
Returns true if any vertex on the primitive has a specific normal set, false otherwise.
Definition eggPrimitive.cxx:289
EggPrimitive::get_bface_flag
get_bface_flag
Retrieves the backfacing flag of the polygon.
Definition eggPrimitive.h:116
EggPrimitive::get_num_textures
get_num_textures
Returns the number of textures applied to the primitive.
Definition eggPrimitive.h:100
EggPrimitive::has_vertex_color
bool has_vertex_color() const
Returns true if any vertex on the primitive has a specific color set, false otherwise.
Definition eggPrimitive.cxx:308
EggPrimitive::get_texture
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
EggPrimitive::has_material
has_material
Returns true if the primitive is materiald (and get_material() will return a real pointer),...
Definition eggPrimitive.h:115
EggTexture
Defines a texture map that may be applied to geometry.
Definition eggTexture.h:30
EggTexture::sorts_less_than
bool sorts_less_than(const EggTexture &other, int eq) const
An ordering operator to compare two textures for sorting order.
Definition eggTexture.cxx:405
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
TypedObject::is_of_type
bool is_of_type(TypeHandle handle) const
Returns true if the current object is or derives from the indicated type.
Definition typedObject.I:28
eggPolygon.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
eggPolysetMaker.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.