Maya nurbsCurve parameter

31 views
Skip to first unread message

Yu Xue

unread,
Jun 14, 2022, 10:12:38 PM6/14/22
to NURBS-Python

Hi,

I have a file full of this kind of data structure

```
createNode nurbsCurve;
    setAttr -k off ".v";
    setAttr ".cc" -type "nurbsCurve"
        1 3 0 no 3
        4 0 1 2 3
        4
        7.73287 0 9.99309
        7.15529 0 10.0172
        6.0734 0 10.0624
        4.41394 0 10.1316
        ;
```

From the [Maya helpdesk](https://help.autodesk.com/cloudhelp/2016/ENU/Maya-Tech-Docs/Nodes/nurbsCurve.html), this is create a nurbs curve:

Cached curve Defines geometry of the curve.

The properties are defined in this order:

- First line: degree, number of spans, form (0=open, 1=closed, 2=periodic), rational (yes/no), dimension
- Second line: number of knots, list of knot values
- Third line: number of CVs Fourth and later lines: CV positions in x,y,z (and w if rational)


So from the above:

- degree = 1, spans = 3, form = 0, not rational, dimension = 3
- 4 knots, and values are [0, 1, 2, 3]
- 4 cvs with the positions

So I'm writing this code:

```
from geomdl import BSpline

# Create the curve instance
crv = BSpline.Curve()

# Set degree
crv.degree = 1

# Set control points
crv.ctrlpts = [[7.73287, 0, 9.99309],
        [7.15529, 0, 10.0172],
        [6.0734, 0, 10.0624],
        [4.41394, 0, 10.1316]]

       

# Set knot vector
crv.knotvector = [0, 1, 2, 3]
```
 
The last line `crv.knotvector = [0, 1, 2, 3]` gives me `ValueError: Input is not a valid knot vector`.

What did I do wrong here?

Yu Xue

unread,
Jun 14, 2022, 10:51:53 PM6/14/22
to NURBS-Python
Ok, find the code I think I need to make sure:


# Check the formula; m = p + n + 1
if len(knot_vector) != degree + num_ctrlpts + 1:
       return False.

So How should I adjust the numbers above?

Yu Xue

unread,
Jun 14, 2022, 11:00:13 PM6/14/22
to NURBS-Python
However I found here http://www.bluesmith.co.uk/LW/theoryBuilders/nurbs2.htm that 

number of cvs = degree + spans

I guess I have to figure out the difference here. 

Yu Xue

unread,
Jun 15, 2022, 10:50:44 AM6/15/22
to NURBS-Python
First, found out the below 2 equations do not conflict:

number of cvs = degree + spans 
number of knots = number of cvs + degree + 1

And finally found issue, from both here:



I get to know:

Maya will always return 2 knots less than it should for a given curve. This means that you have to invent the first and last knot for any parametric curve in maya.

So the knots will really be : knots = [knots[0]] + knots  + knots[-1] for the Maya curve parameters. 
Problem solved.
👍
Reply all
Reply to author
Forward
0 new messages