00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "eggPolysetMaker.h"
00016 #include "eggPolygon.h"
00017
00018 TypeHandle EggPolysetMaker::_type_handle;
00019
00020
00021
00022
00023
00024
00025 EggPolysetMaker::
00026 EggPolysetMaker() {
00027 _properties = 0;
00028 }
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 void EggPolysetMaker::
00041 set_properties(int properties) {
00042 _properties = properties;
00043 }
00044
00045
00046
00047
00048
00049
00050 int EggPolysetMaker::
00051 get_bin_number(const EggNode *node) {
00052 if (node->is_of_type(EggPolygon::get_class_type())) {
00053 return (int)BN_polyset;
00054 }
00055
00056 return (int)BN_none;
00057 }
00058
00059
00060
00061
00062
00063
00064
00065 bool EggPolysetMaker::
00066 sorts_less(int bin_number, const EggNode *a, const EggNode *b) {
00067 nassertr((BinNumber)bin_number == BN_polyset, false);
00068
00069 const EggPolygon *pa = DCAST(EggPolygon, a);
00070 const EggPolygon *pb = DCAST(EggPolygon, b);
00071
00072 if ((_properties & (P_has_texture | P_texture)) != 0) {
00073 bool a_has_texture = (pa->get_num_textures() > 0);
00074 bool b_has_texture = (pb->get_num_textures() > 0);
00075 if (a_has_texture != b_has_texture) {
00076 return ((int)a_has_texture < (int)b_has_texture);
00077 }
00078 }
00079 if ((_properties & (P_texture)) != 0) {
00080 int num_textures = min(pa->get_num_textures(), pb->get_num_textures());
00081 for (int i = 0; i < num_textures; i++) {
00082 EggTexture *a_texture = pa->get_texture(i);
00083 EggTexture *b_texture = pb->get_texture(i);
00084 if (a_texture != b_texture) {
00085 return (a_texture->sorts_less_than(*b_texture, ~EggTexture::E_tref_name));
00086 }
00087 }
00088 if (pa->get_num_textures() != pb->get_num_textures()) {
00089 return (pa->get_num_textures() < pb->get_num_textures());
00090 }
00091 }
00092 if ((_properties & (P_has_material | P_material)) != 0) {
00093 if (pa->has_material() != pb->has_material()) {
00094 return ((int)pa->has_material() < (int)pb->has_material());
00095 }
00096 }
00097 if ((_properties & (P_material)) != 0) {
00098 if (pa->has_material()) {
00099 return (pa->get_material()->sorts_less_than(*pb->get_material(), ~EggMaterial::E_mref_name));
00100 }
00101 }
00102 if ((_properties & (P_has_poly_color)) != 0) {
00103 if (pa->has_color() != pb->has_color()) {
00104 return ((int)pa->has_color() < (int)pb->has_color());
00105 }
00106 }
00107 if ((_properties & (P_poly_color)) != 0) {
00108 if (pa->get_color() != pb->get_color()) {
00109 return (pa->get_color() < pb->get_color());
00110 }
00111 }
00112 if ((_properties & (P_has_poly_normal)) != 0) {
00113 if (pa->has_normal() != pb->has_normal()) {
00114 return ((int)pa->has_normal() < (int)pb->has_normal());
00115 }
00116 }
00117 if ((_properties & (P_has_vertex_normal)) != 0) {
00118 bool pa_has_normal = pa->has_vertex_normal();
00119 bool pb_has_normal = pb->has_vertex_normal();
00120 if (pa_has_normal != pb_has_normal) {
00121 return ((int)pa_has_normal < (int)pb_has_normal);
00122 }
00123 }
00124 if ((_properties & (P_has_vertex_color)) != 0) {
00125 bool pa_has_color = pa->has_vertex_color();
00126 bool pb_has_color = pb->has_vertex_color();
00127 if (pa_has_color != pb_has_color) {
00128 return ((int)pa_has_color < (int)pb_has_color);
00129 }
00130 }
00131 if ((_properties & (P_bface)) != 0) {
00132 if (pa->get_bface_flag() != pb->get_bface_flag()) {
00133 return ((int)pa->get_bface_flag() < (int)pb->get_bface_flag());
00134 }
00135 }
00136
00137 return false;
00138 }