list all skinned points to a joint

1,275 views
Skip to first unread message

ynedelin

unread,
Mar 17, 2009, 7:06:39 PM3/17/09
to python_inside_maya
So the way I have been doing it is using skinPercent command. Going
thought every point and checking if it has weight for my joint. Some
what.

Well, it's slow.

Is there a faster way to list all points skinned to a joint above
certain weight?

Yury

Simon

unread,
Mar 17, 2009, 8:12:27 PM3/17/09
to python_in...@googlegroups.com
hi ynedlin ,

you can use a couple of API_commands , to get to the skinweights (
should be "much faster" - i made myself a simlpe skinCLuster
import-export plugin that way , and compared to "mel-commands" or
"python.cmds" it is really fast ( approx. 40times faster than mel ) ,
but about 2 or 3 times slower than in C++ )

so i post you the "way" i used python to "get the information" from the
maya_API .

then ... while looping through the vertecies , you can find out , if a
joint has a skinweight above a certain value , and then , write the
vertex-number into an array .


// ----------------- start

import maya.OpenMaya as om
import maya.OpenMayaAnim as omAnim

# this will give you the skinweights for "skinCluster1"

skin = 'skinCluster1'

selectionList = om.MSelectionList()
selectionList.add( skin )
node = om.MObject()
selectionList.getDependNode( 0, node )
skinClusterNode = omAnim.MFnSkinCluster(node)

# get the number of influences that affect the skinCluster

infs = om.MDagPathArray()
numInfs = skinClusterNode.influenceObjects(infs)

# get dagPath for the skinCluster at index 0

skinPath = om.MDagPath()

index = 0
skinClusterNode.indexForOutputConnection(index)
skinClusterNode.getPathAtIndex(index,skinPath)

# iterate through all vertecies
geom = om.MItGeometry(skinPath)

vertecies = geom.count()

# here is a list , of all the joint-names and influence objects , inside
the skinCluster

jointNames = []

for counter in range(0,numInfs,1):
infName = infs[counter].partialPathName()
jointNames.append(infName)

print (jointNames)

# here come the weights ( you need to define a maya_API_DoubleArray
wts = om.MDoubleArray()

# now you need to create a MScriptUtil

infCount = om.MScriptUtil()
ccc = infCount.asUintPtr()
# so ccc is the kind of "Unsigned integer" , that i need later for the
skinCluster.getWeights()
# this might be a bit weird to understand , and i dont really understand
it by myself , but it works
# ccc will be the "influenceCount" - that the .getWeight returns

# ok , lets go on

component = om.MObject()

# next is a LOOP ( all vertecies )

# e.g. for getting the pointPosition in worldspace
# not needed , just an example

while ( not geom.isDone()):
point = om.MPoint()
point = geom.position(om.MSpace.kWorld)

# for each vertex , get its component-information

component = geom.component()
# get skinWeights
# needed is the skinCluster_path , output will be an array of weights (
wgts ) for the given "component"

skinClusterNode.getWeights(skinPath,component,wts,ccc)

# print the WTS ( round them , and if they are Zero write '0' instead
of '0.000'
for i in range(0,len(wts),1):
print (wts[i])

geom.next()


// ----------------- end

hope this helps you a bit ...

maybe , these lines of python can be shortened and maybe some lines of
code , can be left out ( i am not a very good programmer ) - but it was
working well for my purpose

have a nice day
sim.On

ynedelin schrieb:

Chadrik

unread,
Mar 18, 2009, 2:00:00 AM3/18/09
to python_inside_maya

as a demo of the new pymel, i rewrote this api snippet using pymel.

here's the full file with both the api and pymel versions:
http://pastebin.com/m63084e53

as you can probably tell it's using many of the same methods as the
API, but wrapped up so you don't have to deal with all the extra API
syntax, like MScriptUtil and passing by reference.

here's just the pymel part:


#---------------------------------------

from pymel import *

skin = 'skinCluster1'
skinClusterNode = SkinCluster(skin)
jointNames = skinClusterNode.influenceObjects()

# get dagPath for the skinCluster at index 0

index = 0
pathIndex = skinClusterNode.indexForOutputConnection(index)
skinPath = skinClusterNode.getPathAtIndex(pathIndex)

print (jointNames)

for geom in skinPath.verts:
point = geom.getPosition('world')
wts = skinClusterNode.getWeights(geom,0)
for wt in wts:
print wt

yury nedelin

unread,
Mar 18, 2009, 3:13:26 AM3/18/09
to python_in...@googlegroups.com
Thanks guys, I will play with it tomorrow morning.

Pymel looks nice.

Yury

sim.On

unread,
Mar 18, 2009, 3:53:42 AM3/18/09
to python_inside_maya
wow chadrik ,

that loooks super-easy . great work !!!

sim.On
Message has been deleted
Message has been deleted

IanJones

unread,
Mar 18, 2009, 3:00:24 PM3/18/09
to python_inside_maya
Alternative in pymel via api:

from pymel import *

skin = PyNode('skinCluster1')
influnces = skin.getInfluence(q=True)
vert_list, values = skin.getPointsAffectedByInfluence(influnces[0])
vert_list = vert_list.getSelectionStrings()

index = 0
for vtxs in vert_list:
vtxs = PyNode(vtxs)
for vert in vtxs:
print vert, values[index]
index += 1

bodyShape.vtx[961] 0.5
bodyShape.vtx[962] 0.5
bodyShape.vtx[1459] 0.5
bodyShape.vtx[1460] 0.5
bodyShape.vtx[1477] 0.016
bodyShape.vtx[1484] 0.036
bodyShape.vtx[1833] 0.016
bodyShape.vtx[1880] 0.015
bodyShape.vtx[1900] 0.5

yury nedelin

unread,
Mar 18, 2009, 7:36:51 PM3/18/09
to python_in...@googlegroups.com
yeah that's nice

pymel ...

I should meet with you guys on Sunday

Yury

Jo Jürgens

unread,
Aug 6, 2009, 2:46:32 PM8/6/09
to python_in...@googlegroups.com
Would it be possible to post this over again, it's expired at pasteBin

Thanks

Paul Molodowitch

unread,
Aug 6, 2009, 3:37:21 PM8/6/09
to python_in...@googlegroups.com
Hey Jo - if you're referring to the pastebin post by Chad, I think
everything is already on this thread - the api version was posted by
Simon, and Chad posted his pymel version...

- Paul

2009/8/6 Jo Jürgens <joju...@gmail.com>:

Jo Jürgens

unread,
Aug 6, 2009, 3:43:34 PM8/6/09
to python_in...@googlegroups.com
aaaaah, okay. actually i thought that was the case right after i posted this (blush)
Reply all
Reply to author
Forward
0 new messages