Jump to content

Attach mesh to bone


joshcamas
 Share

Recommended Posts

So,

 

Does anyone have an example where a mesh is connected as a chaild to a bone parent?  And if so. I recommentd that everyone checks this out and understands how to use it as it is a very key function essential to many scenes and projects.

 

Thanks for bringing this to light again.  As it needs to become a standard function used in many projects and games.

 

DB

Link to comment
Share on other sites

I find how.
 
I create a search function of the index by name. 
 

var searchBoneByName = function(skeleton, searchBoneName) {    var index = 0;    for (var i = 0; i < skeleton.bones.length; i++)    {    	if (searchBoneName = skeleton.bones[i].name) {    		index =  i;		    		break;    	}		    }    return index;};

thereby making

sword.attachToBone(skeleton.bones[searchBoneByName(skeleton, "hand_left")], character);
Link to comment
Share on other sites

  • 2 weeks later...
  • 4 weeks later...

I tried attaching swordMesh to mymesh skeleton bone:

 

swordMesh.attachToBone(myMesh.skeleton.bones[7]);

 

then moving myMesh with:

 

forwards = new BABYLON.Vector3(parseFloat((Math.sin(myMesh.rotation.y)) / speedCharacter) * scene.getAnimationRatio(), 0, parseFloat((Math.cos(myMesh.rotation.y)) / speedCharacter) * scene.getAnimationRatio());
myMesh.moveWithCollisions(forwards);
 
however the swordMesh does not follow.
 
Also the swordmesh looks like the normals have been flipped around.
I can see the inside of the sword.
Link to comment
Share on other sites

Thank you deltakosh!

 

I played around with your scene and indeed it does work with moveWithCollisions

 

I investigated further in my scene and found that I missed the second parameter of 

swordMesh.attachToBone(myMesh.skeleton.bones[7]);

changed it to:

swordMesh.attachToBone(myMesh.skeleton.bones[7],myMesh);

and it worked!

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