Bläddra i källkod

*** empty log message ***

David Rose 25 år sedan
förälder
incheckning
faa5570026
2 ändrade filer med 58 tillägg och 2 borttagningar
  1. 55 0
      panda/src/sgmanip/nodePath.cxx
  2. 3 2
      panda/src/sgmanip/nodePath.h

+ 55 - 0
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

+ 3 - 2
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;