fbxnurbscurve.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /****************************************************************************************
  2. Copyright (C) 2015 Autodesk, Inc.
  3. All rights reserved.
  4. Use of this software is subject to the terms of the Autodesk license agreement
  5. provided at the time of installation or download, or which otherwise accompanies
  6. this software in either electronic or hard copy form.
  7. ****************************************************************************************/
  8. //! \file fbxnurbscurve.h
  9. #ifndef _FBXSDK_SCENE_GEOMETRY_NURBS_CURVE_H_
  10. #define _FBXSDK_SCENE_GEOMETRY_NURBS_CURVE_H_
  11. #include <fbxsdk/fbxsdk_def.h>
  12. #include <fbxsdk/scene/geometry/fbxgeometry.h>
  13. #include <fbxsdk/scene/geometry/fbxline.h>
  14. #include <fbxsdk/fbxsdk_nsbegin.h>
  15. /**
  16. A Non-Uniform Rational B-Spline (NURBS) curve is a type of parametric geometry. A NURBS
  17. curve is defined by the order, form, knot vector and control points.
  18. Let M be the order of the curve.
  19. Let N be the number of control points of the curve.
  20. The form of the curve can be open, closed or periodic. A curve with end points
  21. that do not meet is defined as an open curve. The number of knots in an open curve
  22. is defined as N+(M+1).
  23. A closed curve simply has its last control point equal to its first control point.
  24. Note that this does not imply tangent continuity at the end point. The curve may
  25. have a kink at this point. In FBX the last control point is not specified by the user
  26. in the InitControlPoints() method. For example, if there are to be 10 control points in
  27. total, and the curve is to be closed, than only 9 control points need to be passed
  28. into the InitControlPoints() method. The last control point is implied to be equal
  29. to the first control point. Thus N represents the number of unique CVs.
  30. A periodic curve has its last M control points equal to its first M control points.
  31. A periodic curve is tangent continuous at the ends. Similar to a closed curve,
  32. when creating a periodic curve, only the unique control points need to be set. For
  33. example a periodic curve of order 3 with 10 control points requires only 7 CVs to
  34. be specified in the InitControlPoints() method. The last 3 CVs, which are the same as
  35. the first 3, are not included.
  36. The calculation of the number of knots in closed and periodic curves is more complex.
  37. Since we have excluded one CV in N in a closed curve, the number of knots is N+(M+1)+1.
  38. Similarly, we excluded M CVs in periodic curves so the number of knots is N+(M+1)+M.
  39. Note that FBX stores one extra knot at the beginning and and end of the knot vector,
  40. compared to some other graphics applications such as Maya. The two knots are not
  41. used in calculation, but they are included so that no data is lost when converting
  42. from file formats that do store the extra knots.
  43. * \nosubgrouping
  44. */
  45. class FBXSDK_DLL FbxNurbsCurve : public FbxGeometry
  46. {
  47. FBXSDK_OBJECT_DECLARE(FbxNurbsCurve,FbxGeometry);
  48. public:
  49. //! Returns the EType::eNurbsCurve node attribute type.
  50. virtual FbxNodeAttribute::EType GetAttributeType() const;
  51. /** \enum EDimension The dimension of the CVs.
  52. * - \e e2D The CVs are two dimensional points.
  53. * - \e e3D The CVs are three dimensional points.
  54. */
  55. enum EDimension
  56. {
  57. e2D = 2,
  58. e3D
  59. };
  60. /** \enum EType The curve's form.
  61. * - \e eOpen
  62. * - \e eClosed
  63. * - \e ePeriodic
  64. */
  65. enum EType
  66. {
  67. eOpen,
  68. eClosed,
  69. ePeriodic
  70. };
  71. /** Allocates memory space for the control points array as well as for the knot
  72. * vector.
  73. * \param pCount Number of control points.
  74. * \param pVType NURBS type.
  75. * \remarks This function should always be called after FbxNurbsCurve::SetOrder().
  76. */
  77. void InitControlPoints( int pCount, EType pVType );
  78. /** Returns the knot vector.
  79. * \return Pointer to the knots array.
  80. */
  81. inline double* GetKnotVector() const { return mKnotVector; }
  82. /** Returns the number of elements in the knot vector.
  83. * \return The number of knots.
  84. */
  85. int GetKnotCount() const;
  86. /** Sets the order of the curve.
  87. * \param pOrder The curve order.
  88. * \remarks The curve order must be set before InitControlPoints() is called.
  89. */
  90. inline void SetOrder( int pOrder ) { mOrder = pOrder; }
  91. /** Returns the NURBS curve order.
  92. * \return The NURBS curve order.
  93. */
  94. inline int GetOrder() const { return mOrder; }
  95. /** Sets the step of the curve.
  96. * \param pStep The curve step.
  97. * \remarks To tessellate curve, it denotes the evaluation frequency between two neighbor knots.
  98. */
  99. inline void SetStep( int pStep ) { mStep = pStep; }
  100. /** Returns the NURBS curve step.
  101. * \return The NURBS curve step.
  102. * \remarks To tessellate curve, it denotes the evaluation frequency between two neighbor knots.
  103. */
  104. inline int GetStep() const { return mStep; }
  105. /** Sets the dimension of the CVs.
  106. * For 3D curves: control point = ( x, y, z, w ), where w is the weight.
  107. * For 2D curves: control point = ( x, y, 0, w ), where the z component is unused, and w is the weight.
  108. * \param pDimension The control points dimension(3D or 2D).
  109. */
  110. inline void SetDimension( EDimension pDimension ) { mDimension = pDimension; }
  111. /** Returns the control points dimension.
  112. * \return The curve dimension.
  113. */
  114. inline EDimension GetDimension() const { return mDimension; }
  115. /** Determines if the curve is rational or not.
  116. * \return \c True if the curve is rational, return \c false if not.
  117. */
  118. bool IsRational();
  119. /** Calculates the number of curve spans with the following:
  120. * Where
  121. * S = Number of spans
  122. * N = Number of CVs
  123. * M = Order of the curve
  124. *
  125. * S = N - M + 1;
  126. *
  127. * In this calculation N includes the duplicate CVs for closed and periodic curves.
  128. *
  129. * \return The number of curve spans if the curve has been initialized, returns -1 if the curve has not been initialized.
  130. */
  131. int GetSpanCount() const;
  132. /** Returns NURBS type.
  133. * \return NURBS type identifier.
  134. */
  135. inline EType GetType() const { return mNurbsType; }
  136. /** Checks if the curve is a poly line. (A poly line is a
  137. * linear NURBS curve )
  138. *
  139. * \return \c True if curve is a poly line, return \c false if it is not a poly line.
  140. */
  141. inline bool IsPolyline() const { return ( GetOrder() == 2 ); }
  142. /** This function determines if this NURBS curve is a Bezier curve.
  143. * Bezier curves are a special case of NURBS curve.
  144. * \return \c True if curve is a Bezier curve. If it is not a Bezier curve return \c false.
  145. */
  146. bool IsBezier() const;
  147. /** Evaluate the point on the curve. Save the result as a point array. Meanwhile, return the length of the point array.
  148. * \param pPointArray Save the evaluate result as a point array.
  149. * \param pStep The evaluation frequency between two neighbor knots. Its default value is 16, which is same as Maya.
  150. * \return The length of the point array.
  151. */
  152. int TessellateCurve(FbxArray<FbxVector4>& pPointArray, int pStep = 16);
  153. /** Evaluate the point on the curve. Per the evaluation result, create a FbxLine and return the pointer to the line.
  154. * \param pStep The evaluation frequency between two neighbor knots. Its default value is 16, which is same as Maya.
  155. * \return A line to hold the tessellate points.
  156. */
  157. FbxLine* TessellateCurve(int pStep = 16);
  158. /*****************************************************************************************************************************
  159. ** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! **
  160. *****************************************************************************************************************************/
  161. #ifndef DOXYGEN_SHOULD_SKIP_THIS
  162. virtual FbxObject& Copy(const FbxObject& pObject);
  163. bool FullMultiplicity() const;
  164. // Error identifiers, these are only used internally.
  165. enum EErrorCode
  166. {
  167. eNurbsCurveTypeUnknown,
  168. eWeightTooSmall,
  169. eKnotVectorError,
  170. eWrongNumberOfControlPoint,
  171. eErrorCount
  172. };
  173. bool mIsRational;
  174. virtual void SetControlPointAt(const FbxVector4 &pCtrlPoint , int pIndex) { ParentClass::SetControlPointAt(pCtrlPoint, pIndex); }
  175. virtual void InitControlPoints(int pCount) { ParentClass::InitControlPoints(pCount); }
  176. protected:
  177. virtual void Construct(const FbxObject* pFrom);
  178. virtual void Destruct(bool pRecursive);
  179. void Reset();
  180. private:
  181. double* mKnotVector;
  182. EType mNurbsType;
  183. int mOrder;
  184. EDimension mDimension;
  185. int mStep;
  186. #endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/
  187. };
  188. #include <fbxsdk/fbxsdk_nsend.h>
  189. #endif /* _FBXSDK_SCENE_GEOMETRY_NURBS_CURVE_H_ */