MFnNurbsCurve add/remove CVs and Knots?

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Search this Thread Display Modes
  06 June 2013
MFnNurbsCurve add/remove CVs and Knots?

has anyone seen how to add or remove cvs and knots from a curve via openMaya api?
There's a removeKnot function but it doesn't seem to work and I suspect I'd also need to remove CVs. I don't see any function to add either after creation. wtf autodesk
  06 June 2013
setKnots(), setCVs() ?
  06 June 2013
Originally Posted by palohman: has anyone seen how to add or remove cvs and knots from a curve via openMaya api?
There's a removeKnot function but it doesn't seem to work and I suspect I'd also need to remove CVs. I don't see any function to add either after creation. wtf autodesk

How are you using removeknot? It can be misleading (and do nothing) because, if I remember right, it takes the time of the curve the knot is located at, and not something more intuitive like an index, I assume to deal with knots multiplicity more intuitively.

To test you should be able to simply get the knots domain, and use removeKnot with one end of the domain and true in the second argument (which should remove every knot except the one at that end). That should be brutal enough to show if it's working.

Also remember you need to call updateCurve() once done with the editing if you do anything CV related. You doing that?
To work on CVs you can just get them, reduce the set of CVs, set them, then call updateCurve.

This is all from memory from a while back, but should be reasonably accurate.
Come, Join the Cult - Rigging from First Principles
  06 June 2013
I have a cubic curve with 6 knots, 8 cvs, laid straight along the z axis.

knots = OpenMaya.MDoubleArray()
debug_knots = []
debug_knotPoints = []
knotPoint = OpenMaya.MPoint()
for k in range(knots.length()):
	debug_knots.append(str("%.2f" % knots[k]))
	fnCurve.getPointAtParam(knots[k], knotPoint, OpenMaya.MSpace.kWorld)
	debug_knotPoints.append(str("%.2f" % knotPoint[2]))
print 'knotPrm:\t'+'\t'.join(debug_knots)
print 'knotPnt:\t'+'\t'.join(debug_knotPoints)

CVs = OpenMaya.MPointArray()
debug_CVs = []
for k in range(CVs.length()):
	debug_CVs.append( "%.2f" % CVs[k][2] )
print 'CVs:\t\t\t\t'+'\t'.join(debug_CVs)

outputs the knots param value, the knots point.z, and cvs point.z, I've indented to align them.
knotPrm:	0.00	0.00	0.00	1.00	2.00	3.00	4.00	5.00	5.00	5.00
knotPnt:	0.00	0.00	0.00	2.00	4.00	6.00	8.00	10.0	10.0	10.0
CVs:			0.00	0.67	2.00	4.00	6.00	8.00	9.33	10.0
KnotDomain start:0.0, end:5.0

attempting to just set them with a reduced array
fnCurve.setKnots(knots, 0, knots.length()-1) #Knot indices range from 0 to numKnots() - 1.
fnCurve.setCVs(CVs, OpenMaya.MSpace.kWorld)

This doesn't error at first, but results in a invalid curve that will error on the next pass.
All the knots appear unmoveable when I try selecting and moving them by hand.

attempting to use removeKnot
fnCurve.getKnotDomain( kStart_ptr, kEnd_ptr )
print ("KnotDomain start:%s, end:%s")%(ks_util.getDouble(kStart_ptr),ke_util.getDouble  (kEnd_ptr))
atThisParam = ks_util.getDouble(kStart_ptr)
removeAll = True
fnCurve.removeKnot( atThisParam, removeAll)

also tried removeAll = False, got the same error

KnotDomain start:0.0, end:5.0
# Error: (kFailure): Unexpected Internal Failure
# Traceback (most recent call last):
#   File "E:/Works/Scripts/", line 200, in drag
#     self.cut(oldMousePoint,newMousePoint)
#   File "E:/Works/Scripts/", line 357, in cut
#     fnCurve.removeKnot( atThisParam, removeAll)
#   File "c:\buildforge\Maya_2013_Win64\build\wrk\optim\runT  ime\Python\Lib\site-packages\maya\", line 5981, in removeKnot
# RuntimeError: (kFailure): Unexpected Internal Failure # 

ok so maybe it doesn't like removing end knots, lets try one in the middle
fnCurve.removeKnot( knots[4], removeAll)

hmm, no error, no change
  06 June 2013
Have you tried with getting the CVs, reducing that list, then using it to set the CVs, and then using updateCurve? I understand that's what you originally wanted to do.

That not working (knots not auto-filtering in regards to multiplicity and pairing) knots and CVs will most likely need to be kept in sync, so if you just brutalize the knots without taking care of the CVs you're likely to get an invalid curve, which seems to be what you are getting in your first example.

IE: notice knot multiplicity (param) at the ends and their point pairing.
Come, Join the Cult - Rigging from First Principles

Last edited by ThE_JacO : 06 June 2013 at 04:57 AM.
  06 June 2013
sadly .setCVs with a reduced list of CVs just sets the position of the CVS at their index, any not set get 0,0,0.
found someone else with the same issue;
  06 June 2013
Report a bug then? It sounds past the point of user error.
Last I did it (path editing) it was working... if I remember right, but it was a while ago and it was C++, so I might be either or both me remembering wrong and/or the issue might be on the python side of the bindings.
Come, Join the Cult - Rigging from First Principles
  06 June 2013
Dear Paul,

Please be thorough. Even if you report a bug, they will ask you for this. I suggest the following. When asked for a code for manual GUI operations, look at the script editor for mel hints.

1. Construct an example curve c1 with python or the GUI. Please provide a python code that constructs it.
2. Using the GUI or python delete or perform any edit operation on c1 that would result in a new curve c2. Please provide the python script that does that.
3. Write step 2 that converts c1 to c2 in open maya. Please use the commands I hinted before, and not some specialized remove methods. Please provide full code.
4. Write step 2 that creates c2 from scratch in open maya. Please provide full code.
5. For each of the step 2-4, print the CVs and knots of c1 and c2 in open maya and maya cmds.

In my estimation, you'll find your problem in no time. Else you'll have a short script that reproduces the problem, where we or Autodesk support could help you with.

  06 June 2013
this is what I was working on, endup just making a new curve when I cut or grow.
  06 June 2013
Cool plugin
  06 June 2013
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
Thread Closed share thread

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 01:18 PM.

Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.