32 int bin_number_a = _ebm->get_bin_number(a);
33 int bin_number_b = _ebm->get_bin_number(b);
35 if (bin_number_a != bin_number_b) {
38 return bin_number_a < bin_number_b;
70 collect_nodes(root_group);
73 GroupNodes::const_iterator gi;
74 for (gi = _group_nodes.begin(); gi != _group_nodes.end(); ++gi) {
75 num_bins += get_bins_for_group(gi);
117 return std::string();
131 if (collapse_from ==
nullptr) {
134 return new EggBin(*collapse_from);
146 EggGroupNode::iterator i, next;
148 bool first_in_group =
true;
149 GroupNodes::iterator gni = _group_nodes.end();
153 while (i != group->end()) {
159 if (get_bin_number(node) != 0) {
161 if (first_in_group) {
165 std::pair<GroupNodes::iterator, bool> result;
166 result = _group_nodes.insert
167 (GroupNodes::value_type
170 nassertv(result.second);
172 first_in_group =
false;
177 nassertv(gni != _group_nodes.end());
178 (*gni).second.insert(node);
184 if (node->
is_of_type(EggGroupNode::get_class_type())) {
198 get_bins_for_group(GroupNodes::const_iterator gi) {
200 const SortedNodes &nodes = (*gi).second;
203 nassertr(!nodes.empty(), 0);
207 SortedNodes::const_iterator sni, last;
211 bins.push_back(Nodes());
212 bins.back().push_back(*sni);
214 while (sni != nodes.end()) {
215 if (cn(*last, *sni)) {
217 bins.push_back(Nodes());
219 bins.back().push_back(*sni);
225 make_bins_for_group(group, bins);
234 make_bins_for_group(
EggGroupNode *group,
const Bins &bins) {
236 nassertv(!bins.empty());
242 bool collapse =
false;
244 if (group->empty() &&
246 group->get_parent() !=
nullptr &&
247 group->
is_of_type(EggGroup::get_class_type())) {
248 const Nodes &nodes = bins.front();
249 nassertv(!nodes.empty());
250 int bin_number = get_bin_number(nodes.front());
255 const Nodes &nodes = bins.front();
256 nassertv(!nodes.empty());
257 int bin_number = get_bin_number(nodes.front());
258 PT(
EggBin) bin = make_bin(bin_number, nodes.front(), DCAST(
EggGroup, group));
259 setup_bin(bin, nodes);
262 parent->remove_child(group);
266 Bins::const_iterator bi;
267 for (bi = bins.begin(); bi != bins.end(); ++bi) {
268 const Nodes &nodes = (*bi);
269 nassertv(!nodes.empty());
270 int bin_number = get_bin_number(nodes.front());
271 PT(
EggBin) bin = make_bin(bin_number, nodes.front(),
nullptr);
272 setup_bin(bin, nodes);
284 setup_bin(
EggBin *bin,
const Nodes &nodes) {
285 nassertv(!nodes.empty());
286 int bin_number = get_bin_number(nodes.front());
287 bin->set_bin_number(bin_number);
289 std::string bin_name =
get_bin_name(bin_number, nodes.front());
290 if (!bin_name.empty()) {
291 bin->set_name(bin_name);
294 Nodes::const_iterator ni;
295 for (ni = nodes.begin(); ni != nodes.end(); ++ni) {
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual void prepare_node(EggNode *node)
May be overridden in derived classes to perform some setup work as each node is encountered.
A base class for nodes in the hierarchy that are not leaf nodes.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
The main glue of the egg hierarchy, this corresponds to the <Group>, <Instance>, and <Joint> type nod...
bool operator()(const EggNode *a, const EggNode *b) const
Called by the SortedNodes set to put nodes into bin order.
virtual std::string get_bin_name(int bin_number, const EggNode *child)
May be overridden in derived classes to define a name for each new bin, based on its bin number,...
EggNode * add_child(EggNode *node)
Adds the indicated child to the group and returns it.
PT(EggBin) EggBinMaker
May be overridden in derived classes to construct a new EggBin object (or some derived class,...
A base class for things that may be directly added into the egg hierarchy.
int make_bins(EggGroupNode *root_group)
The main entry point to EggBinMaker.
bool is_of_type(TypeHandle handle) const
Returns true if the current object is or derives from the indicated type.
virtual bool collapse_group(const EggGroup *group, int bin_number)
May be overridden in derived classes to specify whether a particular group node, apparently redundant...
TypeHandle is the identifier used to differentiate C++ class types.
This is just an STL function object, used to sort nodes within EggBinMaker.
A type of group node that holds related subnodes.