Adding Influence Object

200 views
Skip to first unread message

Brandon Harris

unread,
Dec 16, 2009, 11:34:54 AM12/16/09
to python_inside_maya
Alright, so I have a system where you can grab components on multiple
meshes and apply weights to specified joints. Everything works fine
unless you run into a joint that doesn't effect one of the meshes. The
easiest way to do this would be just to check if the object influences
the skin cluster and if it doesn't add it. This would be simple with
Mel, but is there a way to accomplish this with API? In MFnSkinCluster
there isn't a method for this and I haven't been able to locate one.
There's got to be something there for it though.

Brandon Harris

unread,
Dec 16, 2009, 4:00:07 PM12/16/09
to python_inside_maya
And this has actually raised another issue. If a joints influence is
entirely at 0 on a skinCluster and I use the setWeights() it won't set
the weights. It just leaves the joint influence at 0. This a known
issue?

br...@meljunky.com

unread,
Dec 16, 2009, 4:27:28 PM12/16/09
to python_in...@googlegroups.com
I used MFnSkinCluster not that long ago and I retrieved the fullPathName of two different skinClusters and stored them in a list.

Then, I had to compare the list to see if I need to add any influence objects:
list( set( first.influenceObjectsStr ).difference( second.influenceObjectsStr) )

If, the results wasn't None then I executed the MEL command to add them as an influence using "OpenMaya.MDGModifier()", with the two methods commandToExecute and doIt.

So, I recommend to go with your first instinct and use MEL. Don't remember where but someone mentioned that MEL is easier to add influences then trying to use the API.


As for the setWeights() issue...I had no problem changing the weight from zero. Are you using the dataBlock for help setting the weights by chance to retrieve values for setting the final weights?

Try printing out the values from the OpenMaya.MDoubleArray() that you are using to set the values are correct. Could also double check arguments for the setWeights is correct... I had a problem before with setWeights and I tracked it down to a previous issue.

-brian




Brandon Harris

unread,
Dec 16, 2009, 5:56:07 PM12/16/09
to python_inside_maya
MelJunky, Was hoping that you would respond.

Are you normalizing your weights when using the setWeight()? When I
turn Normalization to False it works fine, but then my weights aren't
normalized and I don't want weights over a value of 1.

Brandon L. Harris

Brandon Harris

unread,
Dec 16, 2009, 6:13:48 PM12/16/09
to python_inside_maya
Also, some information on how you're using datablocks in your code
would be nice. I am currently not using that. I'm just taking the
weights. Running them through a small equation and then putting them
back.

Brandon L. Harris

br...@meljunky.com

unread,
Dec 16, 2009, 6:13:54 PM12/16/09
to python_in...@googlegroups.com
Floating point representations are inherently imprecise for many numbers. Which caused you values to go beyond 1.0 or set below 1.0. The way I approached it was to get the sum of the weights for the given component and used it to normalize the weights.

finalVertWeight = vertWeight / totalWeightForThatVertOfAllJoints


Dividing the weights by the totalWeights will normalize the weights to 1.0 rathen then something like 1.000006 or 0.999995..its more like 1.0000000000000000477 now. Normalization should fix that


-brian




Brandon Harris

unread,
Dec 16, 2009, 8:01:47 PM12/16/09
to python_inside_maya
let me run this by you and see if this is my problem. Getting the
index of a joint in a skincluster

joint = "joint1"
jointDag = openMaya.MDagPath()
jointName = openMaya.MSelectionList()
jointName.add(joint)
jointName.getDagPath(0, jointDag)

jointIndex = (skinCluster.indexForInfluenceObject(jointDag))

If I'm not mistaken, this should give me the index value for the joint
that I can then pipe into the setWeights() like so

weight=.45

skinCluster.setWeights(objectPath, compItr.currentItem(), jointIndex,
weight, True, throwAwayWeights)

It seems that the index gets mixed up somehow because sometimes I get
a value of 6 when there's only 2 or 3 joints in the scene, or as I'm
setting values, it will apply a value that I specified for joint1 onto
joint2 or joint3.

Also, when I add a joint to the skinCluster, it gives it a higher
index than the number of joints in the scene.

Any help would be awesome!

Brandon L. Harris

br...@meljunky.com

unread,
Dec 16, 2009, 8:58:34 PM12/16/09
to python_in...@googlegroups.com
When I used the setWeights methods I used and
OpenMaya.MIntArray () for the index
OpenMaya.MDoubleArray() for the values

Check out the thread:

Not sure whats the deal with indexes higher then the joint count. Have you been recycling the same skinCluster for your testing? I imagine that could produce sporadic indexes.

-brian

Brandon Harris

unread,
Dec 16, 2009, 9:02:53 PM12/16/09
to python_inside_maya
well at this moment, I'm not apply several weights to several joints,
I'm only apply 1 weight to 1 specific joint, also, I suppose the main
issue I'm bumping into is when I take a joint, remove it from the
skincluster and then add it back in. That is when the indexing gets
lost. There probably won't be a huge inflow of this kind of error, but
I would prefer to understand why it's doing that so I can avoid it
happening if possible. thanks!

Brandon L. Harris

Reply all
Reply to author
Forward
0 new messages