From c8e4f430aab2484c5ba2dd1079ed9bfdb80d8e3e Mon Sep 17 00:00:00 2001 From: Josh Yelon Date: Thu, 11 Aug 2005 05:44:47 +0000 Subject: [PATCH] Added pview option -i (ignore group/channel names) --- panda/src/chan/auto_bind.cxx | 26 +++++++++++++++++-------- panda/src/framework/windowFramework.cxx | 4 ++-- panda/src/framework/windowFramework.h | 5 ++++- panda/src/testbed/pview.cxx | 16 +++++++++++++-- 4 files changed, 38 insertions(+), 13 deletions(-) diff --git a/panda/src/chan/auto_bind.cxx b/panda/src/chan/auto_bind.cxx index 160411358f..5e10e7322c 100644 --- a/panda/src/chan/auto_bind.cxx +++ b/panda/src/chan/auto_bind.cxx @@ -22,6 +22,7 @@ #include "partBundleNode.h" #include "config_chan.h" #include "string_utils.h" +#include "partGroup.h" typedef pset AnimNodes; typedef pmap Anims; @@ -96,23 +97,29 @@ bind_anims(const PartNodes &parts, const AnimNodes &anims, // Function: r_find_bundles // Description: A support function for auto_bind(), below. Walks // through the hierarchy and finds all of the -// PartBundles and AnimBundles. +// PartBundles and AnimBundles. The flag 'classify' +// controls whether or not the bundles are separated +// into groups according to their root name. If not, +// they are all filed under the same name. //////////////////////////////////////////////////////////////////// static void -r_find_bundles(PandaNode *node, Anims &anims, Parts &parts) { +r_find_bundles(PandaNode *node, Anims &anims, Parts &parts, bool classify) { if (node->is_of_type(AnimBundleNode::get_class_type())) { AnimBundleNode *bn = DCAST(AnimBundleNode, node); - anims[bn->get_bundle()->get_name()].insert(bn); - + if (classify) + anims[bn->get_bundle()->get_name()].insert(bn); + else anims[""].insert(bn); } else if (node->is_of_type(PartBundleNode::get_class_type())) { PartBundleNode *bn = DCAST(PartBundleNode, node); - parts[bn->get_bundle()->get_name()].insert(bn); + if (classify) + parts[bn->get_bundle()->get_name()].insert(bn); + else parts[""].insert(bn); } PandaNode::Children cr = node->get_children(); int num_children = cr.get_num_children(); for (int i = 0; i < num_children; i++) { - r_find_bundles(cr.get_child(i), anims, parts); + r_find_bundles(cr.get_child(i), anims, parts, classify); } } @@ -132,8 +139,11 @@ auto_bind(PandaNode *root_node, AnimControlCollection &controls, // First, locate all the bundles in the subgraph. Anims anims; Parts parts; - r_find_bundles(root_node, anims, parts); - + bool classify = true; + if (hierarchy_match_flags & PartGroup::HMF_ok_wrong_root_name) + classify = false; + r_find_bundles(root_node, anims, parts, classify); + if (chan_cat.is_debug()) { int anim_count = 0; Anims::const_iterator ai; diff --git a/panda/src/framework/windowFramework.cxx b/panda/src/framework/windowFramework.cxx index 92e86b1170..0ff0efa55e 100644 --- a/panda/src/framework/windowFramework.cxx +++ b/panda/src/framework/windowFramework.cxx @@ -661,11 +661,11 @@ load_default_model(const NodePath &parent) { // matching animations found. //////////////////////////////////////////////////////////////////// void WindowFramework:: -loop_animations() { +loop_animations(int hierarchy_match_flags) { // If we happened to load up both a character file and its matching // animation file, attempt to bind them together now and start the // animations looping. - auto_bind(get_render().node(), _anim_controls, ~0); + auto_bind(get_render().node(), _anim_controls, hierarchy_match_flags); _anim_controls.loop_all(true); } diff --git a/panda/src/framework/windowFramework.h b/panda/src/framework/windowFramework.h index f74f47f255..98899b8908 100644 --- a/panda/src/framework/windowFramework.h +++ b/panda/src/framework/windowFramework.h @@ -28,6 +28,7 @@ #include "filename.h" #include "frameRateMeter.h" #include "pointerTo.h" +#include "partGroup.h" #include "pvector.h" #include "typedWritableReferenceCount.h" #include "graphicsWindow.h" @@ -87,7 +88,9 @@ public: const pvector &files); NodePath load_model(const NodePath &parent, Filename filename); NodePath load_default_model(const NodePath &parent); - void loop_animations(); + void loop_animations(int hierarchy_match_flags = + PartGroup::HMF_ok_part_extra | + PartGroup::HMF_ok_anim_extra); enum BackgroundType { BT_other = 0, diff --git a/panda/src/testbed/pview.cxx b/panda/src/testbed/pview.cxx index 98042eb12a..e782189418 100644 --- a/panda/src/testbed/pview.cxx +++ b/panda/src/testbed/pview.cxx @@ -23,6 +23,7 @@ #include "texturePool.h" #include "multitexReducer.h" #include "sceneGraphReducer.h" +#include "partGroup.h" // By including checkPandaVersion.h, we guarantee that runtime // attempts to run pview will fail if it inadvertently links with the @@ -219,6 +220,10 @@ help() { " displayed in the window. The default is not to open the window\n" " until all models are loaded.\n\n" + " -i\n" + " Ignore bundle/group names. Normally, the name must match\n" + " the name, or the animation will not be used.\n\n" + " -s filename\n" " After displaying the models, immediately take a screenshot and\n" " exit.\n\n" @@ -246,11 +251,13 @@ main(int argc, char *argv[]) { bool auto_center = false; bool show_loading = false; bool auto_screenshot = false; + int hierarchy_match_flags = PartGroup::HMF_ok_part_extra | + PartGroup::HMF_ok_anim_extra; Filename screenshotfn; extern char *optarg; extern int optind; - static const char *optflags = "cls:Vh"; + static const char *optflags = "cls:Vhi"; int flag = getopt(argc, argv, optflags); while (flag != EOF) { @@ -263,6 +270,10 @@ main(int argc, char *argv[]) { show_loading = true; break; + case 'i': + hierarchy_match_flags |= PartGroup::HMF_ok_wrong_root_name; + break; + case 's': auto_screenshot = true; screenshotfn = optarg; @@ -322,7 +333,8 @@ main(int argc, char *argv[]) { } else { window->load_models(framework.get_models(), argc, argv); } - window->loop_animations(); + window->loop_animations(hierarchy_match_flags); + loading_np.remove_node(); if (auto_center) {