View Full Version : query and setting per vertex weight color?

09 September 2007, 07:52 AM
Hio, I was just wondering if there was a way of querying and/or assigning paint weight per vertex color?

Basically I have a script in mind for an intelligent auto paint weight for clusters, blend shapes, and ik script. But the only thing, I don't know how to do is find out the current value of the grey scale weight maps. This would need to be a per vertex query and setAttr or what ever the command would be. I was thinking maybe there would be a way of getting polyColorPerVertex to print out some info I'd need. And I did search the cgsociety forums, and found diddly.

I mean, I guess I could effect specificly the colorPerVert info, but the only way I can think of getting the map from that is doing an export to file and then importing it as a weight map for the paint weights. But I'd rather have all the info held within the program so things can be updated faster and no need to doing exporting to files.

If anyone has any ideas, I'd be more than appreciative, I really want to get this script on the works, it would save so much time for painting weights.

09 September 2007, 08:23 AM
Why are you querying the color? Why not the actual value on each vertex? That can be found in the weight table. Surely you can query the value placed on a vertex, though I have not tried.

09 September 2007, 07:21 PM
I would like something like that, that is what I'm asking for, I got no clue what this weight table is. I've seen component stuff for per vertex info, but nothing has weighting info. But the likelyness that I'd be able to query info directly from the table is very unlikely. That is why I'd still need per vertex querying. But I would like to look into it.

And querying simply the red channel from the per vertex color would give me the strength for the weighting, that is why I'd want to query the weight on a per vertex level. Build an array with every vert within a certain distance of every joint for each joint in the system. (I'm still trying to think of faster ways to build the arrays)

09 September 2007, 07:27 PM
ok, found what I wanted -

skinPercent -tv joint2 1 skinCluster1 pSphere1.vtx[193];

And yeah I found what the weighting stuff, but the least you could have said was component editor, that is what I thought you meant but it wasn't listing stuff for me, but I got it working.

09 September 2007, 09:15 PM
Awesome man. I can use that later on.


Robert Bateman
10 October 2007, 09:44 AM
just a little tip regarding skinPercent.... it's actually quicker to use getAttr/setAttr directly on the skin clusters attributes to set the weights. Don't ask me why.....

10 October 2007, 12:16 PM
Well that ends up being easier for me. What are the attributes I'm setting and querying? I just want a fast way to evaluate and alter the weight info on a per joint basis for verticies.

10 October 2007, 11:24 AM

let's say your skincluster is called skinCluster1...
you can get the weightlist with this cmd... -->
listAttr -multi skinCluster1.weightList;
//print(`listAttr -multi "skinCluster1.weightList"`);
and the size of it with this one (using a sphere with 382 vertices on for this example look a bit further down)...
getAttr -size skinCluster1.weightList; //= 382...
// Result: 382 //

e.g. using polyEvaluate -v $daObject; //getting numbers of vertices on the object
and this should be the same as the size of the weightList of the skincluster...
getAttr -size ($daSkinCluster+".weightList");

e.g. let's say that we have a sphere with 382 vertices and 4 joints...
then we have 382 "indexes" in the weightList array... and 4 posible indexes in the weights attribute thingie
depending on how many joints influences that vertex the weights attr will vary...

doing a size on the weightlist index 1 (= vertex 1)
getAttr -size skinCluster1.weightList[0].weights = 3 //in this case

doing a getAttr on this will also give 3 results... //= values of weights[0] weights[1] weights[2]
getAttr skinCluster1.weightList[0].weights;
// Result: 0.847568 0.112273 0.0401587 //

to get them separate use listAttr with multi flag...
listAttr -multi skinCluster1.weightList[0].weights;
// Result: weightList[0].weights[0] weightList[0].weights[1] weightList[0].weights[2]

so skinCluster1.weightList[0].weights[0] = skinCluster1."psphere1.vtx[1]"."joint1"....
so skinCluster1.weightList[0].weights[1] = skinCluster1."psphere1.vtx[1]"."joint2"....
so skinCluster1.weightList[0].weights[2] = skinCluster1."psphere1.vtx[1]"."joint3".... etc...

ofcause this might get more and more complex to figure out when there is more joints and vertices involved
e.g. with a character with over 5000 vertices and maybe over 40 joints...

you can e.g. have a look on this script I once wrote to study it... e.g. get the code for getting some of the stuff etc.
however related to your other post "Documentation on hidden commands"
this is one of those times where it can be useful for taking a dive under the hood of maya... ;)

e.g. a fast solution isn't always fast...
preparing/analyzing/planning of a script might take some time... however thinking isn't that bad... :D
what I mean the process to get there might take some time... however the result in that case might
give you some better results and less headaches...

hope it helps a bit... :)



global proc daVertexCopySetValueUI()
if ((`window -exists daVtx2VtxSkinWeightHelperWindowUI`) == true)
deleteUI daVtx2VtxSkinWeightHelperWindowUI;

window -title "VTX 2 VTX Skinnie thingiebob..." -wh 320 110 daVtx2VtxSkinWeightHelperWindowUI;
formLayout daVtx2VtxSkinWeightHelperWindowUIFormLayout;
button -label "Da First Vtx =" -en true -w 80 -annotation "get the first selected vertex to the textfield..." -c "getDaFirstSelVtx2Vtx;" daFirstSelVtxCmdBtn;
textField -w 200 -ed false -annotation "this field is used to hold the name of the first selected Vertex..." daFirstSelVtxTxtFld;
separator -width 290 "vtx2vtx_UiSep01" ;
button -label "Do da Vtx 2 Vtx" -annotation "executing the command to copy the weight from the first selected vertex, and set it to the other selected vertices..." -w 90 -en false -c "doDaVtx2VtxWeightThingie;" daVtx2VtxCopyCmdBtn;
button -label "Clear" -en false -annotation "clear the textfield with the first selected vertex..." -w 90 -c "doDaVtx2VtxClearThingie;" daVtx2VtxClearCmdBtn;
button -label "Close" -annotation "HUH!!! just closing da UI... :-D" -w 90 -c "deleteUI daVtx2VtxSkinWeightHelperWindowUI;" daVtx2VtxCloseBtn;

formLayout -e
-af "daFirstSelVtxCmdBtn" "left" 10
-af "daFirstSelVtxCmdBtn" "top" 10
-af "daFirstSelVtxTxtFld" "left" 100
-af "daFirstSelVtxTxtFld" "top" 10
-af "vtx2vtx_UiSep01" "left" 10
-af "vtx2vtx_UiSep01" "top" 40
-af "daVtx2VtxCopyCmdBtn" "left" 10
-af "daVtx2VtxCopyCmdBtn" "top" 55
-af "daVtx2VtxClearCmdBtn" "left" 110
-af "daVtx2VtxClearCmdBtn" "top" 55
-af "daVtx2VtxCloseBtn" "left" 210
-af "daVtx2VtxCloseBtn" "top" 55

showWindow daVtx2VtxSkinWeightHelperWindowUI;

global proc getDaFirstSelVtx2Vtx()
string $daFirstVtx[]= eval("filterExpand -ex true -sm 31 `ls -sl -fl`");
if(size($daFirstVtx) >= 1)
textField -e -tx $daFirstVtx[0] daFirstSelVtxTxtFld;
button -e -en true daVtx2VtxCopyCmdBtn;
button -e -en true daVtx2VtxClearCmdBtn;
button -e -en false daFirstSelVtxCmdBtn;
select -cl;

global proc doDaVtx2VtxClearThingie()
textField -e -tx "" daFirstSelVtxTxtFld;
button -e -en false daVtx2VtxCopyCmdBtn;
button -e -en false daVtx2VtxClearCmdBtn;
button -e -en true daFirstSelVtxCmdBtn;

global proc doDaVtx2VtxWeightThingie()
string $daFirstVtx = `textField -q -tx daFirstSelVtxTxtFld`;
string $daSelVtxParent[] = `listRelatives -p $daFirstVtx`;
string $daSkinClusterToVtx = `findRelatedSkinCluster $daSelVtxParent[0]`;
string $daVTXSel[] = eval("filterExpand -ex true -sm 31 `ls -sl -fl`");
string $daSkinJoints[] = `skinPercent -q -t $daSkinClusterToVtx $daFirstVtx`;
float $daWeightValue[] = `skinPercent -q -v $daSkinClusterToVtx $daFirstVtx`;

string $daPreHoldWeightList[];
int $ax, $bx, $cx, $dx, $i,$j;

//make a weight hold state list... and turn on the hold/lock
for($ax = 0; $ax < size($daSkinJoints); $ax++)
$daPreHoldWeightList[$ax] = "setAttr "+($daSkinJoints[$ax]+".liw")+" "+(`getAttr ($daSkinJoints[$ax]+".liw")`)+"";
setAttr ($daSkinJoints[$ax]+".liw") 1;
//zero the weight on the vertices that should get the values copied...
for($bx = 0; $bx<size($daVTXSel); $bx++)
if($daVTXSel[$bx]!= $daFirstVtx)
for($cx=0; $cx<size($daSkinJoints);$cx++)
setAttr ($daSkinJoints[$cx]+".liw") 0;
skinPercent -tv $daSkinJoints[$cx] 0 $daSkinClusterToVtx $daVTXSel[$bx];
setAttr ($daSkinJoints[$cx]+".liw") 1;
//set the values...
for($j=0; $j<size($daVTXSel);$j++)
if($daVTXSel[$j]!= $daFirstVtx)
for($i=0; $i<size($daSkinJoints);$i++)
setAttr ($daSkinJoints[$i]+".liw") 0;
skinPercent -tv $daSkinJoints[$i] $daWeightValue[$i] $daSkinClusterToVtx $daVTXSel[$j];
setAttr ($daSkinJoints[$i]+".liw") 1;
//and restore the hold/lock state...
for($dx = 0; $dx < size($daPreHoldWeightList); $dx++)
textField -e -tx "Done..." daFirstSelVtxTxtFld;
button -e -en false daVtx2VtxCopyCmdBtn;
button -e -en false daVtx2VtxClearCmdBtn;
button -e -en true daFirstSelVtxCmdBtn;

CGTalk Moderation
10 October 2007, 11:24 AM
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.