Browse Source

add NodePath.has_texcoord()

David Rose 20 years ago
parent
commit
5ea15b9dd7
3 changed files with 79 additions and 1 deletions
  1. 13 0
      panda/src/pgraph/nodePath.I
  2. 61 1
      panda/src/pgraph/nodePath.cxx
  3. 5 0
      panda/src/pgraph/nodePath.h

+ 13 - 0
panda/src/pgraph/nodePath.I

@@ -1837,6 +1837,19 @@ clear_project_texture(TextureStage *stage) {
   clear_tex_projector(stage);
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: NodePath::has_texcoord
+//       Access: Published
+//  Description: Returns true if there are at least some vertices at
+//               this node and below that use the named texture
+//               coordinate set, false otherwise.  Pass the empty
+//               string for the default texture coordinate set.
+////////////////////////////////////////////////////////////////////
+INLINE bool NodePath::
+has_texcoord(const string &texcoord_name) const {
+  return has_vertex_column(InternalName::get_texcoord_name(texcoord_name));
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: NodePath::set_billboard_axis
 //       Access: Published

+ 61 - 1
panda/src/pgraph/nodePath.cxx

@@ -3849,6 +3849,23 @@ clear_normal_map() {
   }
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: NodePath::has_vertex_column
+//       Access: Published
+//  Description: Returns true if there are at least some vertices at
+//               this node and below that contain a reference to the
+//               indicated vertex data column name, false otherwise.
+//
+//               This is particularly useful for testing whether a
+//               particular model has a given texture coordinate set
+//               (but see has_texcoord()).
+////////////////////////////////////////////////////////////////////
+bool NodePath::
+has_vertex_column(const InternalName *name) const {
+  nassertr_always(!is_empty(), false);
+  return r_has_vertex_column(node(), name);
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: NodePath::find_texture
 //       Access: Published
@@ -3859,6 +3876,7 @@ clear_normal_map() {
 ////////////////////////////////////////////////////////////////////
 Texture *NodePath::
 find_texture(const string &name) const {
+  nassertr_always(!is_empty(), NULL);
   GlobPattern glob(name);
   return r_find_texture(node(), get_net_state(), glob);
 }
@@ -3873,6 +3891,7 @@ find_texture(const string &name) const {
 ////////////////////////////////////////////////////////////////////
 Texture *NodePath::
 find_texture(TextureStage *stage) const {
+  nassertr_always(!is_empty(), NULL);
   return r_find_texture(node(), stage);
 }
 
@@ -3884,6 +3903,7 @@ find_texture(TextureStage *stage) const {
 ////////////////////////////////////////////////////////////////////
 TextureCollection NodePath::
 find_all_textures() const {
+  nassertr_always(!is_empty(), TextureCollection());
   Textures textures;
   r_find_all_textures(node(), get_net_state(), textures);
 
@@ -3904,6 +3924,7 @@ find_all_textures() const {
 ////////////////////////////////////////////////////////////////////
 TextureCollection NodePath::
 find_all_textures(const string &name) const {
+  nassertr_always(!is_empty(), TextureCollection());
   Textures textures;
   r_find_all_textures(node(), get_net_state(), textures);
 
@@ -3929,6 +3950,7 @@ find_all_textures(const string &name) const {
 ////////////////////////////////////////////////////////////////////
 TextureCollection NodePath::
 find_all_textures(TextureStage *stage) const {
+  nassertr_always(!is_empty(), TextureCollection());
   Textures textures;
   r_find_all_textures(node(), stage, textures);
 
@@ -3952,6 +3974,7 @@ find_all_textures(TextureStage *stage) const {
 ////////////////////////////////////////////////////////////////////
 TextureStage *NodePath::
 find_texture_stage(const string &name) const {
+  nassertr_always(!is_empty(), NULL);
   GlobPattern glob(name);
   return r_find_texture_stage(node(), get_net_state(), glob);
 }
@@ -3964,6 +3987,7 @@ find_texture_stage(const string &name) const {
 ////////////////////////////////////////////////////////////////////
 TextureStageCollection NodePath::
 find_all_texture_stages() const {
+  nassertr_always(!is_empty(), TextureStageCollection());
   TextureStages texture_stages;
   r_find_all_texture_stages(node(), get_net_state(), texture_stages);
 
@@ -3987,6 +4011,7 @@ find_all_texture_stages() const {
 ////////////////////////////////////////////////////////////////////
 void NodePath::
 unify_texture_stages(TextureStage *stage) {
+  nassertv_always(!is_empty());
   r_unify_texture_stages(node(), stage);
 }
 
@@ -3999,6 +4024,7 @@ unify_texture_stages(TextureStage *stage) {
 ////////////////////////////////////////////////////////////////////
 TextureStageCollection NodePath::
 find_all_texture_stages(const string &name) const {
+  nassertr_always(!is_empty(), TextureStageCollection());
   TextureStages texture_stages;
   r_find_all_texture_stages(node(), get_net_state(), texture_stages);
 
@@ -5741,12 +5767,46 @@ r_set_collide_mask(PandaNode *node,
   }
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: NodePath::r_has_vertex_column
+//       Access: Private
+//  Description: 
+////////////////////////////////////////////////////////////////////
+bool NodePath::
+r_has_vertex_column(PandaNode *node, const InternalName *name) const {
+  if (node->is_geom_node()) {
+    GeomNode *gnode;
+    DCAST_INTO_R(gnode, node, NULL);
+
+    int num_geoms = gnode->get_num_geoms();
+    for (int i = 0; i < num_geoms; i++) {
+      const Geom *geom = gnode->get_geom(i);
+      CPT(GeomVertexData) vdata = geom->get_vertex_data();
+      if (vdata->has_column(name)) {
+	return true;
+      }
+    }
+  }
+
+  // Now consider children.
+  PandaNode::Children cr = node->get_children();
+  int num_children = cr.get_num_children();
+  for (int i = 0; i < num_children; i++) {
+    PandaNode *child = cr.get_child(i);
+    if (r_has_vertex_column(child, name)) {
+      return true;
+    }
+  }
+
+  return false;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: NodePath::r_find_texture
 //       Access: Private
 //  Description: 
 ////////////////////////////////////////////////////////////////////
-Texture * NodePath::
+Texture *NodePath::
 r_find_texture(PandaNode *node, const RenderState *state,
                const GlobPattern &glob) const {
   if (node->is_geom_node()) {

+ 5 - 0
panda/src/pgraph/nodePath.h

@@ -646,6 +646,9 @@ PUBLISHED:
 		      bool preserve_color = false);
   void clear_normal_map();
 
+  INLINE bool has_texcoord(const string &texcoord_name) const;
+  bool has_vertex_column(const InternalName *name) const;
+
   Texture *find_texture(const string &name) const;
   Texture *find_texture(TextureStage *stage) const;
   TextureCollection find_all_textures() const;
@@ -820,6 +823,8 @@ private:
                           CollideMask and_mask, CollideMask or_mask,
                           TypeHandle node_type);
 
+  bool r_has_vertex_column(PandaNode *node, const InternalName *name) const;
+
   typedef phash_set<Texture *, pointer_hash> Textures;
   Texture *r_find_texture(PandaNode *node, const RenderState *state,
                           const GlobPattern &glob) const;