[Closed] Is it a max bug or just a bad solver?
see this sample:
delete objects
obj =
(
b0 = boneSys.createBone [0,0,0] [10,0,10] [0,1,0]
(b1 = boneSys.createBone [10,0,10] [10,0,25] [0,1,0]).parent = b0
(b2 = boneSys.createBone [10,0,25] [0,0,35] [0,1,0]).parent = b1
(b2_End = boneSys.createBone [0,0,35] [-2,0,37] [0,1,0]).parent = b2
sp = splineShape name:"IK_SplineShape" adaptive:on optimize:off pos:b0.pos vertexTicks:on wirecolor:green
addNewSpline sp
addKnot sp 1 #corner #line b0.pos b0.pos b0.pos
addKnot sp 1 #corner #line b1.pos b1.pos b1.pos
addKnot sp 1 #corner #line b2.pos b2.pos b2.pos
addKnot sp 1 #corner #line b2_End.pos b2_End.pos b2_End.pos
updateShape sp
IKSys.suspendLinkNotify()
obj = IKSys.ikChain b0 b2_End "SplineIKSolver"
obj.name = "IK_Chain"
obj.controller.enabled = 0
obj.controller.pickShape = sp
IKSys.resumeLinkNotify()
obj
)
/*
obj.controller.enabled = 1
*/
I create bones, a spline, and a spline ik solver. Everything is perfectly aligned.
But as I set IK enabled to ON the chain object jumps out the spline and moves whole chain bones excepting the first one. I can expect any problem with a curve spline, but this is a Line! It doesn’t make any sense for me. What the heck?
I double checked the Maya’s IK Spline. It’s works perfect. And much faster. Do I have to write my Spline Solver now?
I confirmed the bug, both in max 2012 update 8 and max 2013 update 3. :banghead:
there is the source code of the spline solver in max SDK. yep… the code is not very old (2002) but very primitive. Definitely it’s time for me to write my own solver.
i already wrote my own, i will post it as soon as possible, take a look at it and tell me your idea.
Ok, sorry for late, this is my StreachySplinIk(with no IK!)
delete objects
b0 = boneSys.createBone [0,0,0] [10,0,10] [0,1,0]
(b1 = boneSys.createBone [10,0,10] [10,0,25] [0,1,0]).parent = b0
(b2 = boneSys.createBone [10,0,25] [0,0,35] [0,1,0]).parent = b1
(b2_End = boneSys.createBone [0,0,35] [-2,0,37] [0,1,0]).parent = b2
Bns= #(b0,b1,b2,b2_End)
fn drawLine pointA pointB =
(
ss = SplineShape pos:pointA
addNewSpline ss
addKnot ss 1 #corner #line PointA
addKnot ss 1 #corner #line PointB
updateShape ss
ss
)
NewSpline = drawLine bns[1].pos bns[bns.count].pos
for i=2 to (bns.count-1) do
(
refineSegment newSpline 1 1 .5
updateshape newSpline
)
knum=numKnots newspline 1
for i=2 to bns.count do
(
setKnotPoint newSpline 1 i bns[i].pos
updateshape newSpline
)
for i=1 to knum do
(
setKnotType newspline 1 i #smooth
updateshape newspline
)
Pts= for i=1 to bns.count collect
(
point centermarker:off axistripod:off cross:off box:off
)
sum=0
lengthB=curveLength newSpline
for p=1 to Pts.count do
(
if p>1 and p< Pts.count then
(
LengthA=bns[P-1].length
sum=sum+LengthA
Per=sum*100/LengthB
Pts[p].pos.controller=path percent:per follow:true
PosCont=Pts[p].pos.controller
PosCont.path=newSpline
deletekey Pts[p].pos.controller.percent.controller 2
)
if P==Pts.count then
(
Pts[p].pos.controller=path percent:100 follow:true
PosCont=Pts[p].pos.controller
PosCont.path=newSpline
deletekey Pts[p].pos.controller.percent.controller 2
)
if p==1 then
(
Pts[1].pos.controller=path follow:true
PosCont=Pts[1].pos.controller
PosCont.path=newSpline
deletekey Pts[1].pos.controller.percent.controller 2
)
)
-- Just for refresh debug!
for i=1 to knum do
(
setKnotType newspline 1 i #smooth
updateshape newspline
)
--end refrsh debug
for i = 1 to (bns.count) do
(
b=bns[i]
posCon=position_constraint()
lookAtCon=lookAt_constraint()
b.pos.controller=posCon
posCon.appendTarget pts[i] 100
if i < bns.count then
(
b.rotation.controller=lookAtCon
lookAtCon.appendTarget pts[i+1] 100
lookAtCon.lookat_vector_length=0
lookAtCon.upnode_world=false
lookAtCon.pickUpNode=pts[i]
)
)
addModifier newspline (Spline_IK_Control ()) ui:on
SPMod = newspline.modifiers[#Spline_IK_Control]
num=SPMod.getKnotCount()
SPMod.createHelper num
newspline.modifiers[#Spline_IK_Control].linkTypes = 2
SPMod.helper_size = 10
I couldn’t figure out how to use the built in one, and I needed a Non-Stretchy version, so ended up doing a bit more scripting on the controlling dummy objects. Worked for what I needed. Only ended up with flipping issues when my spline nodes got too close to each other. Main problem is that it’s so slooooowwww…