Jump to content

Applying movement created in Blender to mesh.position in Babylon.js


lisarutan
 Share

Recommended Posts

Hello everyone,

 

I'm trying to get my head around how to work with animations in Blender and Babylon.

I have no trouble exporting/loading etc and my animations works except in one aspect. 

 

I have added some movements to my object in Blender and with movement I mean that my object changes position. My problem now is that if I "walk" with my object in the browser each animation will begin where the object is added during the initialization. I have tried to find some data giving me the new position of the object when one animation is finished. Problem seems to be that the position of the object (mesh) doesn't actually change during the animation even though the object "moves". 

 

Does anyone have any suggestions of how to solve this issue? Or aren't you supposed to change position in Blender, only make animations where the object stays in the same spot all the time? Just seems strange if that would be the case...

Link to comment
Share on other sites

Hello Lisa, 

 

this depends on what you animated in Blender. Do you animate mesh's position? is there any object hierarchy?

 

BTW if animation is controlling object's position, you won't be able to change it because anytime you change it, animation engine will overwrite it. If you want to move an animated object, the good idea could be to make this object child of another one and then move the parent

Link to comment
Share on other sites

Hello,
 
For move a character, for example, taking into account the collisions, I done like this:
 

var forward = new BABYLON.Vector3(parseFloat(Math.sin(parseFloat(Player.rotation.y))) / 8, -0.15, parseFloat(Math.cos(parseFloat(Player.rotation.y))) / 8);Player.moveWithCollisions(forward);

oh and Welcome here  :)

Link to comment
Share on other sites

Hi Lisa, welcome to the forum.  Hi long-timers, too.

 

Lisa, I don't know if your animation is a walking bi-ped, but let's pretend it is.  It sounds to me (by the words of the previous answers) that it would be best if you animate the walking ACTION in Blender, but wait until you import it into babylon.js... before you do the position, rotation, and/or scaling.  (Don't change position in the animation.  Just move the legs.) 

 

After importing, you can give the biped an (invisible) parent and move that (child biped will move too), or maybe use Dad72's collision-active forward-mover code.  I just wanted to reword it all, for some strange reason.

 

But I have a question for these animation experts.  First, let's pretend that this is NOT a biped.  It's just a dancing box.  As it dances around, Lisa made it change position 10 units along +z axis ... in 200 frames.  In brief, by the time frame 200 arrives, it has danced, and it has changed position 10 units +z.

 

Now, may I refer to https://github.com/BabylonJS/Babylon.js/wiki/07-Animation

 

Halway down, see the animation mode "BABYLON.Animation.ANIMATIONLOOPMODE_RELATIVE" ?

 

I could build a test to get this answer, but it's easier to ask.  :)

 

If Lisa used that animation mode, would her box keep dancing and moving another 10 units, then another 10 units, etc, cumulative?  Would the animation start again, and automatically have a 10 unit +z offset ... for each re-run of the animation?  (thx)  I realize this animation method might not apply to bones, skeletons, etc.  I have no experience in that at all.

 

See the comment in there "will it continue on"?  I added that, and I guessed.  I don't know if 'relative' = continue-on.

 

Thoughts/info, anyone?  thanks!  Sorry for interrupting the thread flow, if I did.  Lisa, briefly, you have no limitations at all.  Between the power of Blender, and the power of Babylon.js and a tiny bit of javascript, you can get anything done.  Be patient, as sometimes things need a bit of tweaking.  Be well, everyone.

Link to comment
Share on other sites

  • 2 weeks later...

Ooh.. wasn't expecting to feel this welcome for some reason hehe :) Anyhow, that makes me really happy so thank you!

Sorry for being bad on following up on my own topic, though I kind of thought I would get some kind of mail notification if someone made a reply on my topic. But back to the issue...

 

I might be overexplicit now but I guess that is better than the other way around.

 

I have made a model in Blender which consists of a mesh with belonging bone structure, or maybe it should be put the other way around. If I got it right the armature is the parent to the mesh. Appart from that there is not much of an object hierarchy. The animation is applied to the bones but since the mesh and bones are connected, the mesh will move along with the bones. I added some animations as walking, jumping and turning to my little robot. Maybe it's stupid but I thought it would be nice to add the transition to another position in the blender file since I easily can do some tweaks and make sure that the positioning corresponds with the walking animation and looks correct. But when I think about it I could tweak it almost as easy in the javascript. Maybe need to do some small changes in the animation in Blender as well but I guess I'll manage ;)

 

So, I think that all of you answers make sense... :) Though I got to say I'm curious of the answer to Wingnut's question. No offense taken for hijacking my topic btw ;)

 

Thank you for simple but constructive answers!! Now I know where I will spend all my free time that I don't have haha... :)

 

Have a nice day

Link to comment
Share on other sites

Hi Lisa :)

 

My guess is your animations from Blender, like walk and jump, have a hip translation component - the figure walks/jumps from position A to B. If so,  as DK says the "animation engine will overwrite it".

 

What you need are animations for your character that stay in the same spot - not hard to do in Blender.  Then use javascript to move the avatar from A->B->C etc.

 

You might want to take a look at ProfessorF's efforts here - the avatar moves to where you click on the ground:

 

Avatar Movement

 

The link is to all the files which you can download and run on your server. I know I have seen it somewhere on the web - but I don't have a link for the demo. It seems to have a bug in Firefox and Chrome browsers - but sure you can fix that .

 

I also seem to remember dad72 had a demo where the avatar movement was linked to a 3rd person camera. Sorry don't have a link - but I'm sure dad72 will know it ;)

 

The secret I think is removing the translation component - and using javascript to provide it in some fashion when certain conditions are met (key presses or mouse clicks). I'm a javascript wimp otherwise I would suggest some code - though my immediate thoughts would be to parent the avatar to another object (invisible)  - and use that object  to provide translation info.

 

cheers, gryff :)

Link to comment
Share on other sites

Yes I have a full demo for you. You can see a concrete animate animation of a character who get the gravity and collisions.  ;)

With the mouse wheel you can zoom back and forth.

 

with SHIFT + z you can run but it's walking animation is playing.
As specified, you must animate your character but leaving them in place in blender or other moving this shalt make Babylon shalt play the animation.

 

http://www.castorengine.com/babylon/moveCharacter/

Link to comment
Share on other sites

  • 10 months later...

Hi oz, I'm getting this warning (image below)from my antivirus software (Avast).

 

As for your walking issue, you have to delete the location frames of hips/pelvis bone  in your 3d software - that will make your model walk on the spot. Then use a script like dad72 or ProfessorF did, in the links above, to provide the movement across the terrain.

 

cheers, gryff :)

post-7026-0-18375400-1446699716.png

Link to comment
Share on other sites

i've checked my page using some online scanners (securi.net and scanurl.net) and neither of them reported any malware.  Its just a straight-up Babylon.js file.  Anyone else having the same issue?

 

I was hoping to incorporate root motion because some movements are more complicated than a simple linear walk, or curved walk and can't be coded in as accurately as the motion was recorded.  Ah well :(

Link to comment
Share on other sites

The animation for the root bone (the hip) is in there and it works in Babylon.js cos the man does move forward as he's walking.  There's only a problem when the animation is run a second time and the man starts from the initial position again.  Unity3D has an option that allows root motion to update the actual position and rotation of the object, instead of just moving the bone and all its children.  Maybe there's a way in Babylonjs to do this

Link to comment
Share on other sites

I am not sure I am qualified to answer your question.  Am just starting to work with skeletons.  A bone animation frame is a Matrix.  This encapsulates a change in scale, rotation & translation (position).

 

Looking at mocaps from CMU library to try to convert them outside of an exporter,  I see they only record rotation.  Are you including translation in yours?  That would explain how the move is temporary.  If so, you may have an number of options, including:

  • pull translation out, and manage with a concurrent position animation.
  • do looping yourself.  At the end of the animation, apply the translation to the mesh position & play again.

I plan on sort of doing the first, but am both interpolating in a beforeRender & and is an integrated operation.  Will only have bone rotation in matrices.  Mesh position & rotation are optionally interpolated separately, but in the same beforeRender, so it is permanent.  Can also do multiple morphs at the same time, if all goes well  Do not wait for me, though.  I am doing it for me own purposes, thus my own timetable.

Link to comment
Share on other sites

Actually I don't think it's really to do with the looping (tho the looping makes the problem apparent). I think the process of applying root motion is just taking all transformations from hip bone (the root) during the animation and applying it to the mesh itself instead of the hip bone. If there's a way to do that then I can probably get it working

Link to comment
Share on other sites

as JCP mentioned, if you have a translation in your animation, this is the expected result.

 

If you want to keep this translation (which I do not recommend), you can still add a parent mesh to your root object an then manually control the parent.

 

I think this is better to not have translation in your animation because it is then easier to control the root object manually

Link to comment
Share on other sites

I'm not sure if you guys have worked on a lot of human animation, but root motion can be very complicated.  Its not always something you can replicate in code using a mathematical formula.  Have a look at my breakdancing girl here 

 There are parts of that animation which change the rotation and position of the mesh and its not linear at all.  Its quite complicated and scattered.  You can see she starts at a different position and direction each time. She's not just going from A to B in one straight line.  Even the flips she does changes her position slightly.
Link to comment
Share on other sites

I'm not sure if you guys have worked on a lot of human animation

For me, actually not ever, except for shape keys for speech.  Give me 1 more week or 2.  Am just now parsing (regex-ing) the frame file of the Aclaim mocap file pair.  See the root bone has both translation & rotation for each frame.

 

I am thinking of replacing the root bone's animation with Matrix.identity, then taking & storing both the translations & rotations of each frame in their own arrays.  When this is being performed, these changes will go against the mesh position & rotation so that they are permanent.

 

Reducing the 120 frames / sec down to poses that can be interpolated between is probably going to be my biggest challenge.  I am already setup to concurrently move / morph / skeletal articulate in my beforeRenderer, so that part should not be a problem.

 

i have got to say that I do not really understand what DK is saying, but I do not use BABYLON.Animation objects other than for pose storage.

Link to comment
Share on other sites

Oh, now I think I see what you are talking about the different position & direction at starts.  That always happens right after I hit the "Post" button.

 

FYI,  when you move this parent thingy DK is talking about, use can use POV moves & rotations.  There are methods in AbstractMesh for calculating POV.

 

I will not be storing absolute values, rather the change in value for me (they may be relative values already, going to find out).  I will call the POV methods, passing the relative change, & it will calculate the final absolute position or rotation in all 3 dimensions for me as it is being performed.

Link to comment
Share on other sites

I am thinking of replacing the root bone's animation with Matrix.identity, then taking & storing both the translations & rotations of each frame in their own arrays.  When this is being performed, these changes will go against the mesh position & rotation so that they are permanent.

 

Yeh, I'm pretty sure this is how its handled in other animation applications.  Root bone transformation is applied to the mesh instead of the root bone.  Also, big thanks for trying to help out with this :)  I didn't understand what DK was saying either.  I thought maybe I wasn't smart enough to interpret his words, so I just kept silent lol 

Link to comment
Share on other sites

  • 1 year later...

Sorry for unburring this post, but I just spend an hour wondering why my blender animated object was "unmoveable" in the babylon scene while the animation was playing.

All I could find was this thread, so I wanted to post my solution here:

this.spider.beginAnimation("Walk", true, 1.0);

This was my animation code, that made my object unmoveable, unscaleable while the animation was playing.

With no change in blender (after trying a bunch of stuff) this was the solution:

this.spider.skeleton.beginAnimation("Walk", true, 1.0);

Difference: The skeleton has to be animated, not the mesh.

Stupid me, but I hope this might help others that run into the same problem and think they did something wrong in blender.. when actually it's just the wrong thing that gets animated.

Link to comment
Share on other sites

  • 8 months later...
On 11/6/2015 at 8:28 AM, Deltakosh said:

as JCP mentioned, if you have a translation in your animation, this is the expected result.

 

If you want to keep this translation (which I do not recommend), you can still add a parent mesh to your root object an then manually control the parent.

 

I think this is better to not have translation in your animation because it is then easier to control the root object manually

@Deltakosh  I mean it.. You DA MAN... I was looking around about what the best way for us to handle animations... And that is IN-PLACE and NOT ROOT MOTION were the x and z get animated (I do like 'y' thou.. for a little jump looks good... what do think ..No Y either???) 

 

Anyways... I am working out a way to ZERO the x and z (and maybe keep y offset to starting position or zero or leave alone) on root motions animations kinda like unity does if you uncheck the 'Apply Root Motion'

 

But you right .. a set of in place animations work best... I think... much easier to stick a character in parent object with a simple invisible collision mesh as the main character and put the skinned mesh with animations as child that is pure window dressing :)

 

Link to comment
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...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...