Stalker

Apply bone orientation and position to mesh without attaching

Recommended Posts

Hi!

 

In my scene I have multiple instanced robots with single skeleton. When two of them get near enough each they should start shooting lasers.

 

Skeleton has a bone named "Arm.Gun L", its position and orientation already define the origin from where the laser is shot and its direction vector, the problem is that I can't find a way how to access the data. It need to be accessed and copied only once.

 

Find the bone:

this._bone = skeletons[0].bones.filter((b: BABYLON.Bone) => {	return b.name === "Arm.Gun L";})[0];

And when firing:

var l = this._laser.createInstance("l");l.position = ? // this._bone.?l.rotation = ? // this._bone.?

After looking through the docs for Bone and InstancedMesh (together with its base classes Mesh and Node) the only useful thing I found are local and globalMatrix methods on bones (if I could apply localMatrix to laser would probably do what I want with some minor fixes), but haven't found any efficient way of applying to a laser.

Share this post


Link to post
Share on other sites

If I may bug you for one more thing regarding this...

After searching through the forum (problem about rotation), I found out that Bone is presented like a point, so there isn't really any direction in which is facing.

 

I used the code bellow to get rotation, scale and translation.

var l = this._laser.clone("l");var s = BABYLON.Vector3.Zero();var r = new BABYLON.Quaternion();var t = BABYLON.Vector3.Zero();this._bone.getWorldMatrix().decompose(s, r, t);l.position.copyFrom(e.position.add(t));l.rotationQuaternion = r.clone();

Right is the result in BJS (red thing is added), and left how bone looks like in Blender. In BJS it should be rotated ~90deg by Y axis, so that it's parallel to the gun barrel.

That bone is the last one, so I can't use next descendant to calculate direction vector.

 

post-17157-0-93419300-1447975680_thumb.p

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.