00001 // Filename: eggBinner.cxx 00002 // Created by: drose (17Feb00) 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 "eggBinner.h" 00020 00021 #include "eggSwitchCondition.h" 00022 #include "eggGroup.h" 00023 #include "dcast.h" 00024 00025 //////////////////////////////////////////////////////////////////// 00026 // Function: EggBinner::get_bin_number 00027 // Access: Public, Virtual 00028 // Description: 00029 //////////////////////////////////////////////////////////////////// 00030 int EggBinner:: 00031 get_bin_number(const EggNode *node) { 00032 if (node->is_of_type(EggGroup::get_class_type())) { 00033 const EggGroup *group = DCAST(EggGroup, node); 00034 if (group->has_lod()) { 00035 return (int)BN_lod; 00036 } 00037 } 00038 00039 return (int)BN_none; 00040 } 00041 00042 00043 //////////////////////////////////////////////////////////////////// 00044 // Function: EggBinner::sorts_less 00045 // Access: Public, Virtual 00046 // Description: 00047 //////////////////////////////////////////////////////////////////// 00048 bool EggBinner:: 00049 sorts_less(int bin_number, const EggNode *a, const EggNode *b) { 00050 assert((BinNumber)bin_number == BN_lod); 00051 00052 const EggGroup *ga = DCAST(EggGroup, a); 00053 const EggGroup *gb = DCAST(EggGroup, b); 00054 00055 const EggSwitchCondition &swa = ga->get_lod(); 00056 const EggSwitchCondition &swb = gb->get_lod(); 00057 00058 // For now, this is the only kind of switch condition there is. 00059 const EggSwitchConditionDistance &swda = 00060 *DCAST(EggSwitchConditionDistance, &swa); 00061 const EggSwitchConditionDistance &swdb = 00062 *DCAST(EggSwitchConditionDistance, &swb); 00063 00064 // Group LOD nodes in order by switching center. 00065 return (swda._center.compare_to(swdb._center) < 0); 00066 } 00067 00068 //////////////////////////////////////////////////////////////////// 00069 // Function: EggBinner::collapse_group 00070 // Access: Public, Virtual 00071 // Description: 00072 //////////////////////////////////////////////////////////////////// 00073 bool EggBinner:: 00074 collapse_group(const EggGroup *group, int) { 00075 if (group->get_dart_type() != EggGroup::DT_none) { 00076 // A group with the <Dart> flag set means to create a character. 00077 // We can't turn the top character node into an LOD. 00078 return false; 00079 } 00080 00081 return true; 00082 }