From faa55700265761bdd44c20d4a1726e304ffc7ca0 Mon Sep 17 00:00:00 2001 From: David Rose Date: Tue, 13 Feb 2001 02:00:38 +0000 Subject: [PATCH] *** empty log message *** --- panda/src/sgmanip/nodePath.cxx | 55 ++++++++++++++++++++++++++++++++++ panda/src/sgmanip/nodePath.h | 5 ++-- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/panda/src/sgmanip/nodePath.cxx b/panda/src/sgmanip/nodePath.cxx index 2c216de8e4..b969e61fc6 100644 --- a/panda/src/sgmanip/nodePath.cxx +++ b/panda/src/sgmanip/nodePath.cxx @@ -353,6 +353,41 @@ find_all_matches(const string &path) const { return col; } +//////////////////////////////////////////////////////////////////// +// Function: NodePath::find_singular_transform +// Access: Public +// Description: Scans the subgraph beginning at the bottom node of +// the scene graph, looking for a node with a singular +// matrix transform above it. Returns the first such +// node encountered, or an empty NodePath if no singular +// transforms exist in the scene graph. +// +// This is a handy function for tracking down mysterious +// "tried in invert a singular matrix" errors, which are +// almost always caused by zero-scale transform matrices +// in the scene graph. +//////////////////////////////////////////////////////////////////// +NodePath NodePath:: +find_singular_transform() const { + if (has_mat()) { + LMatrix4f mat; + if (!mat.invert_from(get_mat())) { + // Here's a singular matrix! + return *this; + } + } + + int num_children = get_num_children(); + for (int i = 0; i < num_children; i++) { + NodePath result = get_child(i).find_singular_transform(); + if (!result.is_empty()) { + return result; + } + } + + return NodePath(); +} + //////////////////////////////////////////////////////////////////// // Function: NodePath::get_node // Access: Public @@ -1800,6 +1835,26 @@ set_color(const Colorf &color, int priority) { _head->_arc->set_transition(col_trans, priority); } +//////////////////////////////////////////////////////////////////// +// Function: NodePath::set_color_off +// Access: Public +// Description: Sets the geometry at this level and below to render +// using the geometry color. This is normally the +// default, but it may be useful to use this to +// contradict set_color() at a higher node level (or, +// with a priority, to override a set_color() at a lower +// level). +//////////////////////////////////////////////////////////////////// +void NodePath:: +set_color_off(int priority) { + nassertv(has_arcs()); + nassertv(_head != (ArcComponent *)NULL); + + ColorTransition *col_trans = + new ColorTransition(ColorTransition::off()); + _head->_arc->set_transition(col_trans, priority); +} + //////////////////////////////////////////////////////////////////// // Function: NodePath::get_color // Access: Public diff --git a/panda/src/sgmanip/nodePath.h b/panda/src/sgmanip/nodePath.h index 914803c17c..31fabddca6 100644 --- a/panda/src/sgmanip/nodePath.h +++ b/panda/src/sgmanip/nodePath.h @@ -175,6 +175,8 @@ PUBLISHED: NodePathCollection find_all_matches(const string &path) const; + NodePath find_singular_transform() const; + // Methods that actually move nodes around in the scene graph. The // optional "sort" parameter can be used to force a particular @@ -374,6 +376,7 @@ PUBLISHED: INLINE void set_color(float r, float g, float b, float a = 1.0, int priority = 0); void set_color(const Colorf &color, int priority = 0); + void set_color_off(int priority = 0); INLINE void clear_color(); INLINE bool has_color() const; Colorf get_color() const; @@ -462,8 +465,6 @@ private: const FindApproxLevel &level, int max_matches, int num_levels_remaining) const; - void r_prepare_scene(Node *node); - void r_list_descendants(ostream &out, int indent_level) const; void r_list_transitions(ostream &out, int indent_level) const;