소스 검색

minor refinements to nurbs interface

David Rose 22 년 전
부모
커밋
e7a163652e

+ 3 - 3
panda/src/egg2pg/eggLoader.cxx

@@ -529,7 +529,7 @@ make_nurbs_curve(EggNurbsCurve *egg_curve, PandaNode *parent,
   if (egg_curve->get_subdiv() != 0) {
   if (egg_curve->get_subdiv() != 0) {
     int subdiv_per_segment = 
     int subdiv_per_segment = 
       (int)((egg_curve->get_subdiv() + 0.5) / nurbs->get_num_segments());
       (int)((egg_curve->get_subdiv() + 0.5) / nurbs->get_num_segments());
-    rope->set_num_subdiv(subdiv_per_segment);
+    rope->set_num_subdiv(max(subdiv_per_segment, 1));
   }
   }
 
 
   // Now get the attributes to apply to the rope.  We create a
   // Now get the attributes to apply to the rope.  We create a
@@ -735,12 +735,12 @@ make_nurbs_surface(EggNurbsSurface *egg_surface, PandaNode *parent,
   if (egg_surface->get_u_subdiv() != 0) {
   if (egg_surface->get_u_subdiv() != 0) {
     int u_subdiv_per_segment = 
     int u_subdiv_per_segment = 
       (int)((egg_surface->get_u_subdiv() + 0.5) / nurbs->get_num_u_segments());
       (int)((egg_surface->get_u_subdiv() + 0.5) / nurbs->get_num_u_segments());
-    sheet->set_num_u_subdiv(u_subdiv_per_segment);
+    sheet->set_num_u_subdiv(max(u_subdiv_per_segment, 1));
   }
   }
   if (egg_surface->get_v_subdiv() != 0) {
   if (egg_surface->get_v_subdiv() != 0) {
     int v_subdiv_per_segment = 
     int v_subdiv_per_segment = 
       (int)((egg_surface->get_v_subdiv() + 0.5) / nurbs->get_num_v_segments());
       (int)((egg_surface->get_v_subdiv() + 0.5) / nurbs->get_num_v_segments());
-    sheet->set_num_v_subdiv(v_subdiv_per_segment);
+    sheet->set_num_v_subdiv(max(v_subdiv_per_segment, 1));
   }
   }
 
 
   // Now get the attributes to apply to the sheet.  We create a
   // Now get the attributes to apply to the sheet.  We create a

+ 26 - 0
panda/src/parametrics/nurbsCurveEvaluator.I

@@ -98,6 +98,26 @@ get_vertex(int i) const {
   return _vertices[i].get_vertex();
   return _vertices[i].get_vertex();
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: NurbsCurveEvaluator::get_vertex
+//       Access: Published
+//  Description: Returns the nth control vertex of the curve, relative
+//               to the given coordinate space.
+////////////////////////////////////////////////////////////////////
+INLINE LVecBase4f NurbsCurveEvaluator::
+get_vertex(int i, const NodePath &rel_to) const {
+  nassertr(i >= 0 && i < (int)_vertices.size(), LVecBase4f::zero());
+
+  NodePath space = _vertices[i].get_space(rel_to);
+  const LVecBase4f &vertex = _vertices[i].get_vertex();
+  if (space.is_empty()) {
+    return vertex;
+  } else {
+    const LMatrix4f &mat = space.get_mat(rel_to);
+    return vertex * mat;
+  }
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: NurbsCurveEvaluator::set_vertex_space
 //     Function: NurbsCurveEvaluator::set_vertex_space
 //       Access: Published
 //       Access: Published
@@ -201,3 +221,9 @@ get_num_segments() const {
   }
   }
   return _basis.get_num_segments();
   return _basis.get_num_segments();
 }
 }
+
+INLINE ostream &
+operator << (ostream &out, const NurbsCurveEvaluator &n) {
+  n.output(out);
+  return out;
+}

+ 15 - 16
panda/src/parametrics/nurbsCurveEvaluator.cxx

@@ -130,6 +130,17 @@ evaluate(const NodePath &rel_to) const {
                               (int)_vertices.size());
                               (int)_vertices.size());
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: NurbsCurveEvaluator::output
+//       Access: Published
+//  Description: 
+////////////////////////////////////////////////////////////////////
+void NurbsCurveEvaluator::
+output(ostream &out) const {
+  out << "NurbsCurve, " << get_num_knots() << " knots.";
+}
+
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: NurbsCurveEvaluator::get_vertices
 //     Function: NurbsCurveEvaluator::get_vertices
 //       Access: Public
 //       Access: Public
@@ -144,14 +155,7 @@ get_vertices(pvector<LVecBase4f> &verts, const NodePath &rel_to) const {
   verts.reserve(verts.size() + num_vertices);
   verts.reserve(verts.size() + num_vertices);
   int vi;
   int vi;
   for (vi = 0; vi < num_vertices; vi++) {
   for (vi = 0; vi < num_vertices; vi++) {
-    NodePath space = _vertices[vi].get_space(rel_to);
-    const LVecBase4f &vertex = _vertices[vi].get_vertex();
-    if (space.is_empty()) {
-      verts.push_back(vertex);
-    } else {
-      const LMatrix4f &mat = space.get_mat(rel_to);
-      verts.push_back(vertex * mat);
-    }
+    verts.push_back(get_vertex(vi, rel_to));
   }
   }
 }
 }
 
 
@@ -160,8 +164,8 @@ get_vertices(pvector<LVecBase4f> &verts, const NodePath &rel_to) const {
 //       Access: Public
 //       Access: Public
 //  Description: Fills the indicated vector with the set of vertices
 //  Description: Fills the indicated vector with the set of vertices
 //               in the curve, transformed to the given space.  This
 //               in the curve, transformed to the given space.  This
-//               flavor returns the vertices in 4-dimensional
-//               homogenous space.
+//               flavor returns the vertices in 3-dimensional
+//               space.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void NurbsCurveEvaluator::
 void NurbsCurveEvaluator::
 get_vertices(pvector<LPoint3f> &verts, const NodePath &rel_to) const {
 get_vertices(pvector<LPoint3f> &verts, const NodePath &rel_to) const {
@@ -169,12 +173,7 @@ get_vertices(pvector<LPoint3f> &verts, const NodePath &rel_to) const {
   verts.reserve(verts.size() + num_vertices);
   verts.reserve(verts.size() + num_vertices);
   int vi;
   int vi;
   for (vi = 0; vi < num_vertices; vi++) {
   for (vi = 0; vi < num_vertices; vi++) {
-    const NodePath &space = _vertices[vi].get_space(rel_to);
-    LVecBase4f vertex = _vertices[vi].get_vertex();
-    if (!space.is_empty()) {
-      const LMatrix4f &mat = space.get_mat(rel_to);
-      vertex = vertex * mat;
-    }
+    LVecBase4f vertex = get_vertex(vi, rel_to);
     LPoint3f v3(vertex[0] / vertex[3], vertex[1] / vertex[3], vertex[2] / vertex[3]);
     LPoint3f v3(vertex[0] / vertex[3], vertex[1] / vertex[3], vertex[2] / vertex[3]);
     verts.push_back(v3);
     verts.push_back(v3);
   }
   }

+ 5 - 0
panda/src/parametrics/nurbsCurveEvaluator.h

@@ -59,6 +59,7 @@ PUBLISHED:
   INLINE void set_vertex(int i, const LVecBase4f &vertex);
   INLINE void set_vertex(int i, const LVecBase4f &vertex);
   INLINE void set_vertex(int i, const LVecBase3f &vertex, float weight = 1.0);
   INLINE void set_vertex(int i, const LVecBase3f &vertex, float weight = 1.0);
   INLINE const LVecBase4f &get_vertex(int i) const;
   INLINE const LVecBase4f &get_vertex(int i) const;
+  INLINE LVecBase4f get_vertex(int i, const NodePath &rel_to) const;
 
 
   INLINE void set_vertex_space(int i, const NodePath &space);
   INLINE void set_vertex_space(int i, const NodePath &space);
   INLINE void set_vertex_space(int i, const string &space);
   INLINE void set_vertex_space(int i, const string &space);
@@ -75,6 +76,8 @@ PUBLISHED:
 
 
   PT(NurbsCurveResult) evaluate(const NodePath &rel_to = NodePath()) const;
   PT(NurbsCurveResult) evaluate(const NodePath &rel_to = NodePath()) const;
 
 
+  void output(ostream &out) const;
+
 public:
 public:
   void get_vertices(pvector<LVecBase4f> &verts, const NodePath &rel_to) const;
   void get_vertices(pvector<LVecBase4f> &verts, const NodePath &rel_to) const;
   void get_vertices(pvector<LPoint3f> &verts, const NodePath &rel_to) const;
   void get_vertices(pvector<LPoint3f> &verts, const NodePath &rel_to) const;
@@ -96,6 +99,8 @@ private:
   NurbsBasisVector _basis;
   NurbsBasisVector _basis;
 };
 };
 
 
+INLINE ostream &operator << (ostream &out, const NurbsCurveEvaluator &n);
+
 #include "nurbsCurveEvaluator.I"
 #include "nurbsCurveEvaluator.I"
 
 
 #endif
 #endif

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

@@ -141,6 +141,27 @@ get_vertex(int ui, int vi) const {
   return vert(ui, vi).get_vertex();
   return vert(ui, vi).get_vertex();
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: NurbsSurfaceEvaluator::get_vertex
+//       Access: Published
+//  Description: Returns the nth control vertex of the surface, relative
+//               to the given coordinate space.
+////////////////////////////////////////////////////////////////////
+INLINE LVecBase4f NurbsSurfaceEvaluator::
+get_vertex(int ui, int vi, const NodePath &rel_to) const {
+  nassertr(ui >= 0 && ui < _num_u_vertices &&
+           vi >= 0 && vi < _num_v_vertices, LVecBase4f::zero());
+
+  NodePath space = vert(ui, vi).get_space(rel_to);
+  const LVecBase4f &vertex = vert(ui, vi).get_vertex();
+  if (space.is_empty()) {
+    return vertex;
+  } else {
+    const LMatrix4f &mat = space.get_mat(rel_to);
+    return vertex * mat;
+  }
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: NurbsSurfaceEvaluator::set_vertex_space
 //     Function: NurbsSurfaceEvaluator::set_vertex_space
 //       Access: Published
 //       Access: Published
@@ -299,3 +320,9 @@ INLINE const NurbsVertex &NurbsSurfaceEvaluator::
 vert(int ui, int vi) const {
 vert(int ui, int vi) const {
   return _vertices[ui * _num_v_vertices + vi];
   return _vertices[ui * _num_v_vertices + vi];
 }
 }
+
+INLINE ostream &
+operator << (ostream &out, const NurbsSurfaceEvaluator &n) {
+  n.output(out);
+  return out;
+}

+ 13 - 2
panda/src/parametrics/nurbsSurfaceEvaluator.cxx

@@ -174,6 +174,17 @@ evaluate(const NodePath &rel_to) const {
                                 _num_u_vertices, _num_v_vertices);
                                 _num_u_vertices, _num_v_vertices);
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: NurbsSurfaceEvaluator::output
+//       Access: Published
+//  Description: 
+////////////////////////////////////////////////////////////////////
+void NurbsSurfaceEvaluator::
+output(ostream &out) const {
+  out << "NurbsSurface, (" << get_num_u_knots() << ", " << get_num_v_knots()
+      << ") knots.";
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: NurbsSurfaceEvaluator::get_vertices
 //     Function: NurbsSurfaceEvaluator::get_vertices
 //       Access: Public
 //       Access: Public
@@ -207,8 +218,8 @@ get_vertices(pvector<LVecBase4f> &verts, const NodePath &rel_to) const {
 //       Access: Public
 //       Access: Public
 //  Description: Fills the indicated vector with the set of vertices
 //  Description: Fills the indicated vector with the set of vertices
 //               in the surface, transformed to the given space.  This
 //               in the surface, transformed to the given space.  This
-//               flavor returns the vertices in 4-dimensional
-//               homogenous space.
+//               flavor returns the vertices in 3-dimensional
+//               space.
 //
 //
 //               Vertices are arranged in linear sequence, with the v
 //               Vertices are arranged in linear sequence, with the v
 //               coordinate changing more rapidly.
 //               coordinate changing more rapidly.

+ 5 - 0
panda/src/parametrics/nurbsSurfaceEvaluator.h

@@ -56,6 +56,7 @@ PUBLISHED:
   INLINE void set_vertex(int ui, int vi, const LVecBase4f &vertex);
   INLINE void set_vertex(int ui, int vi, const LVecBase4f &vertex);
   INLINE void set_vertex(int ui, int vi, const LVecBase3f &vertex, float weight = 1.0);
   INLINE void set_vertex(int ui, int vi, const LVecBase3f &vertex, float weight = 1.0);
   INLINE const LVecBase4f &get_vertex(int ui, int vi) const;
   INLINE const LVecBase4f &get_vertex(int ui, int vi) const;
+  INLINE LVecBase4f get_vertex(int ui, int vi, const NodePath &rel_to) const;
 
 
   INLINE void set_vertex_space(int ui, int vi, const NodePath &space);
   INLINE void set_vertex_space(int ui, int vi, const NodePath &space);
   INLINE void set_vertex_space(int ui, int vi, const string &space);
   INLINE void set_vertex_space(int ui, int vi, const string &space);
@@ -77,6 +78,8 @@ PUBLISHED:
 
 
   PT(NurbsSurfaceResult) evaluate(const NodePath &rel_to = NodePath()) const;
   PT(NurbsSurfaceResult) evaluate(const NodePath &rel_to = NodePath()) const;
 
 
+  void output(ostream &out) const;
+
 public:
 public:
   void get_vertices(pvector<LVecBase4f> &verts, const NodePath &rel_to) const;
   void get_vertices(pvector<LVecBase4f> &verts, const NodePath &rel_to) const;
   void get_vertices(pvector<LPoint3f> &verts, const NodePath &rel_to) const;
   void get_vertices(pvector<LPoint3f> &verts, const NodePath &rel_to) const;
@@ -110,6 +113,8 @@ private:
   NurbsBasisVector _v_basis;
   NurbsBasisVector _v_basis;
 };
 };
 
 
+INLINE ostream &operator << (ostream &out, const NurbsSurfaceEvaluator &n);
+
 #include "nurbsSurfaceEvaluator.I"
 #include "nurbsSurfaceEvaluator.I"
 
 
 #endif
 #endif

+ 6 - 1
panda/src/parametrics/ropeNode.cxx

@@ -181,7 +181,12 @@ cull_callback(CullTraverser *trav, CullTraverserData &data) {
 void RopeNode::
 void RopeNode::
 output(ostream &out) const {
 output(ostream &out) const {
   PandaNode::output(out);
   PandaNode::output(out);
-  out << " " << get_curve();
+  NurbsCurveEvaluator *curve = get_curve();
+  if (curve != (NurbsCurveEvaluator *)NULL) {
+    out << " " << *curve;
+  } else {
+    out << " (no curve)";
+  }
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////

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

@@ -172,7 +172,12 @@ cull_callback(CullTraverser *trav, CullTraverserData &data) {
 void SheetNode::
 void SheetNode::
 output(ostream &out) const {
 output(ostream &out) const {
   PandaNode::output(out);
   PandaNode::output(out);
-  out << " " << get_surface();
+  NurbsSurfaceEvaluator *surface = get_surface();
+  if (surface != (NurbsSurfaceEvaluator *)NULL) {
+    out << " " << *surface;
+  } else {
+    out << " (no surface)";
+  }
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////