Parcourir la source

instanceUnderNode

David Rose il y a 24 ans
Parent
commit
ddd3f7048b
2 fichiers modifiés avec 18 ajouts et 5 suppressions
  1. 16 5
      panda/src/pgraph/qpnodePath.cxx
  2. 2 0
      panda/src/pgraph/qpnodePath.h

+ 16 - 5
panda/src/pgraph/qpnodePath.cxx

@@ -267,6 +267,22 @@ instance_to(const qpNodePath &other, int sort) const {
   return new_instance;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: qpNodePath::instance_under_node
+//       Access: Published
+//  Description: Behaves like instance_to(), but implicitly creates a
+//               new node to instance the geometry under, and returns a
+//               NodePath to that new node.  This allows the
+//               programmer to set a unique state and/or transform on
+//               this instance.
+////////////////////////////////////////////////////////////////////
+qpNodePath qpNodePath::
+instance_under_node(const qpNodePath &other, const string &name, int sort) const {
+  qpNodePath new_node = other.attach_new_node(name, sort);
+  instance_to(new_node);
+  return new_node;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: qpNodePath::copy_to
 //       Access: Published
@@ -275,11 +291,6 @@ instance_to(const qpNodePath &other, int sort) const {
 //               descendents, which is then parented to the indicated
 //               node.  A qpNodePath to the newly created copy is
 //               returned.
-//
-//               Certain kinds of nodes (like a Camera, for instance,
-//               whose pointer value is important) may not be copied;
-//               if one of these is encountered, the node will be
-//               instanced, instead of actually copied.
 ////////////////////////////////////////////////////////////////////
 qpNodePath qpNodePath::
 copy_to(const qpNodePath &other, int sort) const {

+ 2 - 0
panda/src/pgraph/qpnodePath.h

@@ -196,6 +196,8 @@ PUBLISHED:
   void reparent_to(const qpNodePath &other, int sort = 0);
   void wrt_reparent_to(const qpNodePath &other, int sort = 0);
   qpNodePath instance_to(const qpNodePath &other, int sort = 0) const;
+  qpNodePath instance_under_node(const qpNodePath &other, const string &name,
+                                 int sort = 0) const;
   qpNodePath copy_to(const qpNodePath &other, int sort = 0) const;
   qpNodePath attach_new_node(PandaNode *node, int sort = 0) const;
   INLINE qpNodePath attach_new_node(const string &name, int sort = 0) const;