Jump to content

Mesh position of animated character


DezOnlyOne
 Share

Recommended Posts

I am using an animated character with different meshes for the head, body, body part markers etc. I am trying to create an arrow that points to a given body part marker,which is created in max and exported as part of the character animation, but when I get the position, it is always incorrect. If I just create a box in code and move it to the same place as the head let's say, it's position is wildly different than the position that is returned from "head.position".

When I use the debug layer and check clickable labels, I get a perfectly placed label in the middle of the mesh. How do I get that location from the mesh itself? What am I missing. 

When I create a box:

var box = BABYLON.Mesh.CreateBox('box', 5, scene);

box.position works great as well. 

When I load my animated character, the bones have mesh representations, which I dispose of, but they all have the correct positions. It seems to be the meshes that are attached to the skeletons that has an issue. How do I get the position that the debugLayer uses?

 

Link to comment
Share on other sites

I figured it out. It took a little bit of reading, but now I got it. 

http://www.babylonjs-playground.com/#1HZPNI#8

In line 31 I send the position of the head to the console. 

mesh.position

which is essentially

scene.getMeshByName('HEAD').position

...but I get the wrong location. 

{x: -46.1542, y: 0, z: 33.9001}

As you can see from the lines 18-21, the box is at the location (-106, 54, 38) which is in the same space where the head is. the head position should give me a similar location as the box that is covering the character's face. 

The debug clickable layers work perfectly, how do they calculate position differently than using the mesh.position value?

Thank you in advance for all your help on this stuff. 

Link to comment
Share on other sites

1 hour ago, Deltakosh said:

This is because your mesh is not centered at the origin. To get the value, you should then use the bounding box:

http://www.babylonjs-playground.com/#1HZPNI#9

That is the answer. That works great for me and I am integrating into my app now. I really appreciate it. You guys are really awesome. 

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...