PDA

View Full Version : Working with skinOps


IkerCLoN
05-15-2009, 10:03 AM
Hi, guys! I'm stuck with a script I'm writing. I've been looking for ages for a script that allows you to 'transfer' weights from one bone to another, and also be able to 'lock' weights for one bone. But I found nothing, so I thought it was worth giving it a try.

So in this chunk of code what I pretend is pass an array of weights to one bone to another. I'm using a teapot with three bones, and it only stores the weights for the first bone. Here's the code:


-- get the skin
skinMod = $.modifiers[#Skin]

-- get the number of vertices
vertNum = skinOps.getNumberVertices skinMod

-- get the selected bone (index)
selBone = skinOps.getSelectedBone skinMod

-- get the vertices influenced by the selected bone
skinOps.selectVerticesByBone skinMod

-- store the verts index in an array
selectedVerts = #()
for i = 1 to vertNum do
(
theVert = skinOps.IsVertexSelected skinMod i
if theVert == 1 do append selectedVerts i
)

-- store the verts weights in an array
selectedWeights = #()
for i = 1 to selectedVerts.count do
(
theWeight = skinOps.getVertexWeight skinMod selectedVerts[i] selBone
append selectedWeights theWeight
)

-- apply the weights to the new bone
for i = 1 to selectedVerts.count do
(
skinOps.setVertexWeights skinMod selectedVerts[i] selBone selectedWeights[i]
)

The skinOps methods look a bit confusing to me. In addition, after dealing with the question 'how in the hell could I select the vertices owned by a bone using script' I found that there's a method that is not documented in the Help file (although the command is exposed in tue Customize UI dialog).

I guess I'm doing something wrong. Could you guys point me what I'm missing here?

Thanks a lot!!!

S-S
05-19-2009, 08:10 PM
Hi iker!

Haven't touched skin that much... but anyhow:


skinOps.GetVertexWeight <Skin> <vertex_integer> <vertex_bone_integer>
Returns the influence of the Nth bone affecting the specified vertex.


You are most likely writing a script to transfer weight influence of *many* not one bone to one vertex. So you have to first get all bones influencing vert:


theBonesInfluencing = skinOps.GetVertexWeightCount skinMod selectedVerts[i]


This could be any number of bones which influence a vert. 1 to 3 in this case.

Then you could get and store both weights and vertex_bones into arrays. Then loop thru each vertex, and store these to arrays...


for i = 1 to selectedVerts.count do
(
theBonesInfluencing = skinOps.GetVertexWeightCount skinMod selectedVerts[i]

tmpBoneInflueces = #()
tmpBones = #()

for a = 1 to theBonesInfluencing do
(
theWeight = skinOps.getVertexWeight skinMod selectedVerts[i] a
append tmpBoneInflueces theWeight
append tmpBones a
)
append selectedWeights tmpBoneInflueces
append InfluencingBones tmpBones

tmpBoneInflueces = #()
tmpBones = #()
)



Then do the inverse when you paste weights back to another bone.

And as note, when you weight for example bone 1 verts to be "same" as bone 3, you are actually removing weights from bone 3 at the same time.

I tested it quickly, and it seems to be working... but didn't take care of original vert assignment, so this would have to be done too i think.

BTW

"and also be able to 'lock' weights for one bone"

Do you mean you'd like to bake verts or something else?

Anyway, i hope this doesn't lead you to wrong path! I have done something similar once, so there might be easier way to do this ...or not.

CGTalk Moderation
05-19-2009, 08:10 PM
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.