00001 // Filename: eggPolysetMaker.cxx 00002 // Created by: drose (20Jun01) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 #include "eggPolysetMaker.h" 00020 #include "eggPolygon.h" 00021 00022 //////////////////////////////////////////////////////////////////// 00023 // Function: EggPolysetMaker::Constructor 00024 // Access: Public 00025 // Description: 00026 //////////////////////////////////////////////////////////////////// 00027 EggPolysetMaker:: 00028 EggPolysetMaker() { 00029 _properties = 0; 00030 } 00031 00032 //////////////////////////////////////////////////////////////////// 00033 // Function: EggPolysetMaker::set_properties 00034 // Access: Public 00035 // Description: Sets the set of properties that determines which 00036 // polygons are allowed to be grouped together into a 00037 // single polyset. This is the bitwise 'or' of all the 00038 // properties that matter. If this is 0, all polygons 00039 // (within a given group) will be lumped into a common 00040 // polyset regardless of their properties. 00041 //////////////////////////////////////////////////////////////////// 00042 void EggPolysetMaker:: 00043 set_properties(int properties) { 00044 _properties = properties; 00045 } 00046 00047 //////////////////////////////////////////////////////////////////// 00048 // Function: EggPolysetMaker::get_bin_number 00049 // Access: Public, Virtual 00050 // Description: 00051 //////////////////////////////////////////////////////////////////// 00052 int EggPolysetMaker:: 00053 get_bin_number(const EggNode *node) { 00054 if (node->is_of_type(EggPolygon::get_class_type())) { 00055 return (int)BN_polyset; 00056 } 00057 00058 return (int)BN_none; 00059 } 00060 00061 00062 //////////////////////////////////////////////////////////////////// 00063 // Function: EggPolysetMaker::sorts_less 00064 // Access: Public, Virtual 00065 // Description: 00066 //////////////////////////////////////////////////////////////////// 00067 bool EggPolysetMaker:: 00068 sorts_less(int bin_number, const EggNode *a, const EggNode *b) { 00069 nassertr((BinNumber)bin_number == BN_polyset, false); 00070 00071 const EggPolygon *pa = DCAST(EggPolygon, a); 00072 const EggPolygon *pb = DCAST(EggPolygon, b); 00073 00074 if ((_properties & (P_has_texture | P_texture)) != 0) { 00075 if (pa->has_texture() != pb->has_texture()) { 00076 return ((int)pa->has_texture() < (int)pb->has_texture()); 00077 } 00078 } 00079 if ((_properties & (P_texture)) != 0) { 00080 if (pa->has_texture()) { 00081 return (pa->get_texture()->sorts_less_than(*pb->get_texture(), ~EggTexture::E_tref_name)); 00082 } 00083 } 00084 if ((_properties & (P_has_material | P_material)) != 0) { 00085 if (pa->has_material() != pb->has_material()) { 00086 return ((int)pa->has_material() < (int)pb->has_material()); 00087 } 00088 } 00089 if ((_properties & (P_material)) != 0) { 00090 if (pa->has_material()) { 00091 return (pa->get_material()->sorts_less_than(*pb->get_material(), ~EggMaterial::E_mref_name)); 00092 } 00093 } 00094 if ((_properties & (P_has_poly_color)) != 0) { 00095 if (pa->has_color() != pb->has_color()) { 00096 return ((int)pa->has_color() < (int)pb->has_color()); 00097 } 00098 } 00099 if ((_properties & (P_poly_color)) != 0) { 00100 if (pa->get_color() != pb->get_color()) { 00101 return (pa->get_color() < pb->get_color()); 00102 } 00103 } 00104 if ((_properties & (P_has_poly_normal)) != 0) { 00105 if (pa->has_normal() != pb->has_normal()) { 00106 return ((int)pa->has_normal() < (int)pb->has_normal()); 00107 } 00108 } 00109 if ((_properties & (P_has_vertex_normal)) != 0) { 00110 bool pa_has_normal = pa->has_vertex_normal(); 00111 bool pb_has_normal = pb->has_vertex_normal(); 00112 if (pa_has_normal != pb_has_normal) { 00113 return ((int)pa_has_normal < (int)pb_has_normal); 00114 } 00115 } 00116 if ((_properties & (P_has_vertex_color)) != 0) { 00117 bool pa_has_color = pa->has_vertex_color(); 00118 bool pb_has_color = pb->has_vertex_color(); 00119 if (pa_has_color != pb_has_color) { 00120 return ((int)pa_has_color < (int)pb_has_color); 00121 } 00122 } 00123 if ((_properties & (P_bface)) != 0) { 00124 if (pa->get_bface_flag() != pb->get_bface_flag()) { 00125 return ((int)pa->get_bface_flag() < (int)pb->get_bface_flag()); 00126 } 00127 } 00128 00129 return false; 00130 }