Sign in to follow this  
Raggar

[Solved]Cloning Bones ?

Recommended Posts

Here's the deal, I'm importing a model with skeleton, bones, animations etc. I assign the model (Index 0) and the skeleton (index 0) global variables.

Then, outside of Babylon's native import function, I clone the model and the skeleton, and run animation (from frames) just fine.

The problem is, when I try to manually manipulate bones using their getters and setters, somehow, rotating 1 bone from 1 clone of the original, also rotates the bones of all other clones, as well as the original.

Changing the names and ID's of bones doesn't seem to help, either.

 

Soo. Is there any way of cloning bones? no clone function exists, and I'm unsure of how to approach this.

I'll see if I can create a simple PG, as the project is pretty complex by now.

 

As I mentioned, I can run different animations on the different skeletons without any issues. But as soon as I manually rotate bones, all clones + original are all affected.

Share this post


Link to post
Share on other sites
18 hours ago, adam said:

I'm working on a fix for this.

 

16 hours ago, adam said:

This is a tough one.  You might already now this, but it will work if you import the mesh instead of cloning.

http://www.babylonjs-playground.com/#1ZBQR3#0

 

Yeah. I thought of 2 solutions.

1) Split the mesh into multiple meshes, and rotate the specific parts instead of their corresponding bones.

2) Loading the model everytime it is required. But then, what if I need 20 player objects? That's 20 x importing of meshes and skeletons/bones, and might give some drops in performance every time a new object is required. Maybe IndexedDB could help, by at least cutting the bandwidth?

 

I tried #1. Didn't quite like it. I'll give #2 a go, and see whether or not it is practical.

 

Can you verify that this is indeed a bug? I've been through my code many times, doing various optimizations and bug hunts, and I'm certain that I've done it right.

Share this post


Link to post
Share on other sites
On 2/8/2017 at 8:59 AM, Raggar said:

Can you verify that this is indeed a bug?

It is was bug.  Here is the fix I came up with:

https://github.com/BabylonJS/Babylon.js/pull/1759

When the playground is updated with this code, the dude on the right won't copy the other dude's head rotation:

http://www.babylonjs-playground.com/#1ZBQR3#5

60 cloned dudes:

http://www.babylonjs-playground.com/#1ZBQR3#7

It loads much faster than using import mesh.

 

Share this post


Link to post
Share on other sites

Compiling the master branch somehow broke the bone rotation completely. Switched over from 2.5, so I don't think it's due to API changes. 

I'll check the simpler example from your PR when I get home. 

It was my fist time compiling from source, but everything else seem to work just fine.

Share this post


Link to post
Share on other sites
1 hour ago, adam said:

Show me the code you are using to rotate a bone.

mesh.skeleton.bones[boneIndex].setRotation(new BABYLON.Vector3(x, y, z), BABYLON.Space.LOCAL);

 

The X, Y and Z values are based on the rotation of the bone in local space, from when the mesh was first cloned. Then altered of course.

But the keyframe animations stopped working, too. So I'll do some hunting in the next couple of hours.

 

Share this post


Link to post
Share on other sites

It's working for me, but I did have some trouble after viewing one of the examples for setRotation in the doc.

The example had some code in it that wrote over the Bone.prototype.setRotation with a setRotation that used quaternions.

I just submit a PR to update that doc.

Share this post


Link to post
Share on other sites
15 hours ago, Deltakosh said:

PR validated and PG updated

 

 

On 9/2/2017 at 6:16 PM, adam said:

It is was bug.  Here is the fix I came up with:

https://github.com/BabylonJS/Babylon.js/pull/1759

When the playground is updated with this code, the dude on the right won't copy the other dude's head rotation:

http://www.babylonjs-playground.com/#1ZBQR3#5

60 cloned dudes:

http://www.babylonjs-playground.com/#1ZBQR3#7

It loads much faster than using import mesh.

 

 

Rotating the bone manually seems to work, but the look control still seems to affect both the imported mesh as well as the clone.

I hope my compilation somehow messed it up. 

Can you upload your version?

Share this post


Link to post
Share on other sites
1 hour ago, adam said:

It's weird. Same thing as my own compiled version.

Getters seem to respond, but no change whatsoever with the setters. With the 2.5 version, everything works fine, although the cloning issue is present. But with the newest version, keyframe animations stopped working, and neither of the setters seem to work. .rotate, .setRotation, .setYawPitchRoll etc.

I guess I'll have to investigate what's wrong. The code is the same, with no changes.

Btw. Have you checked your PG?

Rotating the bone manually seems to work independently of the original mesh, but the look control seems to have the same issue, or at least one resembling it.

Share this post


Link to post
Share on other sites

Thank you for all the help.

I've marked this thread as Solved, as I see the main issue as being resolved.

Although using your babylon.max.js file, my own .js files and even the overwritten prototypes functions from your PG examples still produce some weird issues, I'll figure this out, eventually.

For now, I'm back at importing models, but I'll make some time to look it over again at a later date.

When using the dude model, I can manually set the rotation, as long as i DON'T run any animations at the same time. But my own model won't either animate nor manually rotate after updating babylon. Same thing with the overwritten prototypes. The model is only a placeholder, and took less than an hour as I didn't refine skin weights or anything. Therefore I won't completely rule out that the problem might be fixed when finishing a proper model.

Attached is the model I've been using for reference.
 

e.babylon

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...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.