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!!!
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!!!
