A raíz de un aviso de Juan, me he dado cuenta de que el script sólo funciona bien cuando tenemos más de dos puntos seleccionados. Ésta es la versión que funciona también cuando la selección consiste únicamente en dos puntos:
Código: Seleccionar todo
--select two points or more points and run the code below for creating a 'stretchy' bone or a 'stretchy' chain
fn makeNubBone lastBone =
(
local pos = lastBone.transform[4] -- get the position of the last bone.
local xDir = lastBone.transform[1] -- get the vector of the X point.
local startPoint = pos + xDir * lastBone.length
local endPoint = startPoint + xDir * lastBone.width
local nubBone = boneSys.createBone startPoint endPoint lastBone.transform[3] -- create the bone.
nubBone.width = lastBone.width
nubBone.height = lastBone.height
nubBone.wireColor = lastBone.wireColor
nubBone.parent = lastBone
nubBone.name = lastBone.name + "_Nub"
return nubBone
)
fn createElasticBones pointList =
(
if selection.count == 2 do
(
if classof pointList[1] == Point and classof pointList[2] == Point then
(
oBone = boneSys.createBone pointList[1].pos pointList[2].pos pointList[1].transform[3]
theNub = makeNubBone oBone
oBone.position.controller = Position_Constraint()
oBone.position.controller.appendTarget pointList[1] 100
theNub.position.controller = Position_Constraint()
theNub.position.controller.appendTarget pointList[2] 100
oBone.rotation.controller = LookAt_Constraint()
oBone.rotation.controller.appendTarget pointList[2] 100
oBone.rotation.controller.viewline_length_abs = false
oBone.rotation.controller.upnode_world = false
oBone.rotation.controller.pickUpnode = pointList[1]
oBone.rotation.controller.upnodeAxis = 2
oBone.rotation.controller.stoUpAxis = 2
)
else messageBox "Selected objects must be points"
)
if selection.count > 2 do
(
theBones = #()
for i = 1 to (selection.count-1) do
(
theBone = boneSys.createBone pointList[i].pos pointList[i+1].pos pointList[i].transform[3]
append theBones theBone
)
theNub = makeNubBone theBones[theBones.count]
append theBones theNub
theNub.position.controller = Position_Constraint()
theNub.position.controller.appendTarget pointList[pointList.count] 100
for i = 1 to theBones.count-1 do
(
theBones[i].position.controller = Position_Constraint()
theBones[i].position.controller.appendTarget pointList[i] 100
theBones[i].rotation.controller = LookAt_Constraint()
theBones[i].rotation.controller.appendTarget pointList[i+1] 100
theBones[i].rotation.controller.viewline_length_abs = false
theBones[i].rotation.controller.upnode_world = false
theBones[i].rotation.controller.pickUpnode = pointList[i]
theBones[i].rotation.controller.upnodeAxis = 2
theBones[i].rotation.controller.stoUpAxis = 2
)
for i = 2 to theBones.count do
(
theBones[i].parent = theBones[i-1]
)
)
)
createElasticBones selection

¡Saludos!