Prechádzať zdrojové kódy

add set_uv_direction(), fix bounding sphere problem

David Rose 22 rokov pred
rodič
commit
04dfcb2695

+ 27 - 0
panda/src/parametrics/ropeNode.I

@@ -27,6 +27,7 @@ CData() {
   _curve = new NurbsCurveEvaluator;
   _render_mode = RopeNode::RM_thread;
   _uv_mode = RopeNode::UV_none;
+  _u_dominant = true;
   _uv_scale.set(1.0f, 1.0f);
   _use_vertex_color = false;
   _num_subdiv = 10;
@@ -43,6 +44,7 @@ CData(const RopeNode::CData &copy) :
   _curve(copy._curve),
   _render_mode(copy._render_mode),
   _uv_mode(copy._uv_mode),
+  _u_dominant(copy._u_dominant),
   _uv_scale(copy._uv_scale),
   _use_vertex_color(copy._use_vertex_color),
   _num_subdiv(copy._num_subdiv),
@@ -122,6 +124,31 @@ get_uv_mode() const {
   return cdata->_uv_mode;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: set_uv_direction
+//       Access: Public
+//  Description: Specify true to vary the U coordinate down the length
+//               of the rope, or false to vary the V coordinate.
+////////////////////////////////////////////////////////////////////
+INLINE void RopeNode::
+set_uv_direction(bool u_dominant) {
+  CDWriter cdata(_cycler);
+  cdata->_u_dominant = u_dominant;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: get_uv_direction
+//       Access: Public
+//  Description: Returns true if the rope runs down the U coordinate
+//               of the texture, or false if it runs down the V
+//               coordinate.
+////////////////////////////////////////////////////////////////////
+INLINE bool RopeNode::
+get_uv_direction() const {
+  CDReader cdata(_cycler);
+  return cdata->_u_dominant;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: set_uv_scale
 //       Access: Public

+ 40 - 11
panda/src/parametrics/ropeNode.cxx

@@ -197,7 +197,7 @@ output(ostream &out) const {
 void RopeNode::
 write(ostream &out, int indent_level) const {
   PandaNode::write(out, indent_level);
-  indent(out, indent_level) << get_curve() << "\n";
+  indent(out, indent_level) << *get_curve() << "\n";
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -245,7 +245,7 @@ do_recompute_bound(const NodePath &rel_to) {
     
     GeometricBoundingVolume *gbv;
     DCAST_INTO_R(gbv, bound, bound);
-    gbv->around(&verts[0], &verts[verts.size() - 1]);
+    gbv->around(&verts[0], &verts[0] + verts.size());
   }
   return bound;
 }
@@ -268,6 +268,7 @@ render_thread(CullTraverser *trav, CullTraverserData &data,
               NurbsCurveResult *result) {
   UVMode uv_mode = get_uv_mode();
   LVecBase2f uv_scale = get_uv_scale();
+  bool u_dominant = get_uv_direction();
   bool use_vertex_color = get_use_vertex_color();
 
   PTA_Vertexf verts;
@@ -298,7 +299,11 @@ render_thread(CullTraverser *trav, CullTraverserData &data,
         break;
         
       case UV_parametric:
-        uvs.push_back(TexCoordf(t * uv_scale[0], 0.0f));
+        if (u_dominant) {
+          uvs.push_back(TexCoordf(t * uv_scale[0], 0.0f));
+        } else {
+          uvs.push_back(TexCoordf(0.0f, t * uv_scale[1]));
+        }
         break;
 
       case UV_distance:
@@ -306,7 +311,11 @@ render_thread(CullTraverser *trav, CullTraverserData &data,
           LVector3f vec = point - last_point;
           dist += vec.length();
         }
-        uvs.push_back(TexCoordf(dist * uv_scale[0], 0.0f));
+        if (u_dominant) {
+          uvs.push_back(TexCoordf(dist * uv_scale[0], 0.0f));
+        } else {
+          uvs.push_back(TexCoordf(0.0f, dist * uv_scale[1]));
+        }
         break;
 
       case UV_distance2:
@@ -314,7 +323,11 @@ render_thread(CullTraverser *trav, CullTraverserData &data,
           LVector3f vec = point - last_point;
           dist += vec.length_squared();
         }
-        uvs.push_back(TexCoordf(dist * uv_scale[0], 0.0f));
+        if (u_dominant) {
+          uvs.push_back(TexCoordf(dist * uv_scale[0], 0.0f));
+        } else {
+          uvs.push_back(TexCoordf(0.0f, dist * uv_scale[1]));
+        }
         break;
       }
 
@@ -367,6 +380,7 @@ render_billboard(CullTraverser *trav, CullTraverserData &data,
   float thickness = get_thickness();
   float radius = thickness * 0.5f;
   UVMode uv_mode = get_uv_mode();
+  bool u_dominant = get_uv_direction();
   LVecBase2f uv_scale = get_uv_scale();
 
   // We can't just build one tristrip per segment.  Instead, we should
@@ -447,8 +461,13 @@ render_billboard(CullTraverser *trav, CullTraverserData &data,
         break;
 
       case UV_parametric:
-        uvs.push_back(TexCoordf(t * uv_scale[0], uv_scale[1]));
-        uvs.push_back(TexCoordf(t * uv_scale[0], 0.0f));
+        if (u_dominant) {
+          uvs.push_back(TexCoordf(t * uv_scale[0], uv_scale[1]));
+          uvs.push_back(TexCoordf(t * uv_scale[0], 0.0f));
+        } else {
+          uvs.push_back(TexCoordf(uv_scale[0], t * uv_scale[1]));
+          uvs.push_back(TexCoordf(0.0f, t * uv_scale[1]));
+        }
         break;
 
       case UV_distance:
@@ -456,8 +475,13 @@ render_billboard(CullTraverser *trav, CullTraverserData &data,
           LVector3f vec = point - center_verts[vi + j - 1];
           dist += vec.length();
         }
-        uvs.push_back(TexCoordf(dist * uv_scale[0], thickness * uv_scale[1]));
-        uvs.push_back(TexCoordf(dist * uv_scale[0], 0.0f));
+        if (u_dominant) {
+          uvs.push_back(TexCoordf(dist * uv_scale[0], thickness * uv_scale[1]));
+          uvs.push_back(TexCoordf(dist * uv_scale[0], 0.0f));
+        } else {
+          uvs.push_back(TexCoordf(thickness * uv_scale[0], dist * uv_scale[1]));
+          uvs.push_back(TexCoordf(0.0f, dist * uv_scale[1]));
+        }
         break;
 
       case UV_distance2:
@@ -465,8 +489,13 @@ render_billboard(CullTraverser *trav, CullTraverserData &data,
           LVector3f vec = point - center_verts[vi + j - 1];
           dist += vec.length_squared();
         }
-        uvs.push_back(TexCoordf(dist * uv_scale[0], thickness * uv_scale[1]));
-        uvs.push_back(TexCoordf(dist * uv_scale[0], 0.0f));
+        if (u_dominant) {
+          uvs.push_back(TexCoordf(dist * uv_scale[0], thickness * uv_scale[1]));
+          uvs.push_back(TexCoordf(dist * uv_scale[0], 0.0f));
+        } else {
+          uvs.push_back(TexCoordf(thickness * uv_scale[0], dist * uv_scale[1]));
+          uvs.push_back(TexCoordf(0.0f, dist * uv_scale[1]));
+        }
         break;
       }
     }

+ 4 - 0
panda/src/parametrics/ropeNode.h

@@ -92,6 +92,9 @@ PUBLISHED:
   INLINE void set_uv_mode(UVMode uv_mode);
   INLINE UVMode get_uv_mode() const;
 
+  INLINE void set_uv_direction(bool u_dominant);
+  INLINE bool get_uv_direction() const;
+
   INLINE void set_uv_scale(const LVecBase2f &uv_scale);
   INLINE const LVecBase2f &get_uv_scale() const;
 
@@ -129,6 +132,7 @@ private:
     PT(NurbsCurveEvaluator) _curve;
     RenderMode _render_mode;
     UVMode _uv_mode;
+    bool _u_dominant;
     LVecBase2f _uv_scale;
     bool _use_vertex_color;
     int _num_subdiv;

+ 1 - 1
panda/src/parametrics/sheetNode.cxx

@@ -236,7 +236,7 @@ do_recompute_bound(const NodePath &rel_to) {
     
     GeometricBoundingVolume *gbv;
     DCAST_INTO_R(gbv, bound, bound);
-    gbv->around(&verts[0], &verts[verts.size() - 1]);
+    gbv->around(&verts[0], &verts[0] + verts.size());
   }
   return bound;
 }