Moving a Skeleton Joint (Bone) in code?

Software: Away3D 4.x

banal, Newbie
Posted: 05 December 2013 10:17 AM   Total Posts: 4

Hello Forum

I’m trying to move a bone of a 3D Model programmatically and I’m stuck with this problem.

I have an existing model. For the sake of simplicity, there’s a bone called “root”, “left” and “right”.

The model loads fine and I have the Skeleton and the Joints available. How would I go ahead and move the “left” bone to a desired position? It doesn’t have to be animated… I just want to update the bone location (and of course the model should deform as well).

If you know the answer to this, please feel free to answer my question on stackoverflow and get some reputation smile

   

banal, Newbie
Posted: 10 December 2013 09:37 AM   Total Posts: 4   [ # 1 ]

Is there any solution to this? I’ve added a bounty to the question on stackoverflow, so maybe somebody gets some motivation out of that?

   

John Brookes, Moderator
Posted: 10 December 2013 01:13 PM   Total Posts: 732   [ # 2 ]

I would presume the mesh needs an animator to update

eg set up your model as though your were using animation, then something like

skeletonAnimator.skeleton.joints[1].inverseBindPose = Vector.<Number>([1,0,0,0,0,1,0,0,0,0,1,0,0,-10.38+(view.width / 2 - view.mouseX),-0.98,1]);

Would move the 2nd joint.

   

banal, Newbie
Posted: 10 December 2013 01:23 PM   Total Posts: 4   [ # 3 ]

Thanks a lot for your reply.

Sadly, I’m horribly lost when it comes to skeletal animation in Away3D v4, as I have never used it before.

Do you know of any example where the required animator instances have been set up in code (instead of loading stuff via parsers)?

I guess I’ll need something like:

myMesh.animator = new SkeletonAnimatoranimationSet_skeleton 

Is the animationSet parameter just a

new SkeletonAnimationSet() 

? I did a quick try but that resulted in a horribly skewed model… but at least something is happening smile

   

banal, Newbie
Posted: 10 December 2013 03:26 PM   Total Posts: 4   [ # 4 ]

JohnBrookes, you helped me quite a lot with your hint.

It really seems to be the case that the mesh needs a running animator first.

Here’s what I figured out:

// create a pose from the current skeleton position
var rootPose:SkeletonPose = new SkeletonPose();
for 
each(var joint:SkeletonJoint in _skeleton.joints){
    
var m:Matrix3D = new Matrix3D(joint.inverseBindPose);
    
m.invert();
    var 
p:JointPose = new JointPose();
    
p.translation m.transformVector(p.translation);
    
p.orientation.fromMatrix(m);
    
rootPose.jointPoses.push(p);
}

// create idle animation clip by adding the root pose twice
var clip:SkeletonClipNode = new SkeletonClipNode();
clip.addFrame(rootPose1000);
clip.addFrame(rootPose1000);
clip.name "idle";

// build animation set
var animSet:SkeletonAnimationSet = new SkeletonAnimationSet(3);
animSet.addAnimation(clip);

// setup animator with set and skeleton
var animator:SkeletonAnimator = new SkeletonAnimator(animSet_skeleton);
_mesh.animator animator;
animator.play("idle"); 

It seems like an awful lot of overhead, but now I can influence the skeleton joint inverseBindPose directly and it updates the bone position.

Now I just need to figure out how to correctly place the bone to desired world-coordinates.

If anybody has a more elegant (shorter) solution to this, please post it here. The +100 reputation bounty on stackoverflow are still up for grabs.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X