benoit-1842

animate a bone through code

Recommended Posts

So I will explain my situation.  I am now good with creating a scene in Blender and porting it to babylon.js in two viewports (thanx Gryff and Iceman). So right now I have a model that plays an animation created in Blender.  But now I want to create an animation directly through code (i.e moving one of my bones through code not passing by Blender).... So how works the animation of a model bone through code ?  I have seen the dude tutorial and  I still need some enlightement and my ultimate challenge it's to put kinect 2 data x,y,z qx,qy,qz and qw in my bone information so it can move accordingly to the position I get from my motion capture....

 

So for example this is my data for my left knee : 

        "x": 0.223173529,
        "y": -0.388017774,
        "z": 0.582939148,
        "qx": 0.425287217,
        "qy": 0.6508006,
        "qz": -0.478602648,
        "qw": -0.408079475
 
How can I implement that "inside my bone " data in babylon.js........it will be fantastic !!!!
 
 
 

Share this post


Link to post
Share on other sites

Hi, 

 

I did something with babylon that maybe could help you  :

 

http://www.html5gamedevs.com/topic/11918-ts-sources-character-study-demo-keyframe-animation-ragdoll/

 

It s about switching  keyframes animation character to a ragdoll physic mode. So I had to reflect ragdoll part to bones. You can have a look to my source, perhaps it will help you.

 

My dev is very specific to the model I use, but you can give it a try.

 

Sam

Share this post


Link to post
Share on other sites

Bonjour Samuel.....  Yesterday I have downloaded your code of your chef d'oeuvre !!!!  I couldn't find the file(s) that was coding the *switch* of animation.... If you can point me in witch file it is, it will be very cool....

 

Merci,

 

Benoit

Share this post


Link to post
Share on other sites

Salut, 

 

It's in Bundle.ts 

public compute(v:BABYLON.Vector3 , o:BABYLON.Quaternion): void {        //waarning call order here are very  important                     //  translation offset         var t: BABYLON.Vector3 = this.offset;        this.helper.locallyTranslate(new BABYLON.Vector3(-t.x, -t.y, -t.z));                       //compute matrix and update skeleton         var world: BABYLON.Matrix = this.helper.getWorldMatrix();        world.invert();        var m = this.bone.getWorldMatrix().multiply(world);        // waitt 1 one frame before update         if (!this.wait) {            this.bone.update(m);        }                    // this f..... rotation quaternion offset fix        var qinvert = BABYLON.Quaternion.Inverse(this.qset);        var r = this.mesh.rotationQuaternion;                 this.helper.rotationQuaternion = r.multiply(qinvert);          var t = new BABYLON.Vector3(this.mesh.position.x-v.x, this.mesh.position.y-v.y, this.mesh.position.z-v.z)        this.helper.position = t;          this.wait = false;    }

As I said you it's very specific to my model, and I need to deal with  some strange 3dsmax exporter behavior (the new one maybe fix that). It's very important to do not have hierarchy between your bones when you export you model. Hope this help.

Share this post


Link to post
Share on other sites

Exactly, I use this trick because, with hierarchy each bone is relative to his parent. I was no very comfortable with heavy matrix computing. With independant bones, position and rotation are stored in world unit. So it was not a problem for keyframe mode  and for the ragdoll mode, the hierarchy is giving by the ragdoll boxes.

Share this post


Link to post
Share on other sites

So is it possible if I use data from a kinect has a json file to update my model everytime....  Because that's the goal, I have a model and I want to be able to change the animation of my model with the info of a json file....

 

Merci,

 

Benoit

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.