Jump to content

Attaching object to bone.


Recommended Posts

  • 2 weeks later...

I Assume sword is a mesh (BABYLON.Mesh) and Armature is a skeleton (BABYLON.Skeleton) containing one bone (BABYLON.bones).


In engine.runRenderLoop function, I use the following code :

engine.runRenderLoop(function() {	sword.parent=Armature.bones[0];	scene.render();});

It result the following error : 

Uncaught TypeError: Object [object Object] has no method 'isEnabled'


And if I use the following code : 

engine.runRenderLoop(function() {	scene.render();	sword.parent=Armature.bones[0];});

It result the following error : 

Uncaught TypeError: Object [object Object] has no method '_needToSynchonizeChildren'


In both cases, sword does not follow bone's motion.


Any Idea about this ?

Link to comment
Share on other sites


a bone cannot be attached this way. You have to set sword.skeleton=skeleton

but you also have to define matrices weights and indices into your sword

How can I do this ?

matricesWeights = ???;floatIndices = ???;sword.setVerticesData(matricesWeights, BABYLON.VertexBuffer.MatricesWeightsKind, false);sword.setVerticesData(floatIndices, BABYLON.VertexBuffer.MatricesIndicesKind, false); 

It's not easy to understand.

Is it 4 float per vertex ? only 4 floats ?

finally an example could be fine ....

Link to comment
Share on other sites

Thanks for your help.

Finally here is my code : 

function mount(obj,ske,boneName){	matricesWeights =[];	floatIndices =[];        boneIndice=-1;	// Find bone's Indice	for (ii=0;ii<ske.bones.length;ii++)	{		if (ske.bones[ii].name==boneName)		{			boneIndice=ii;			break;		}	}        if (boneIndice==-1) {console.error("Unable to find bone : "+boneName); return;}	// Build matrices and indices buffers.	for (ii=0;ii<obj._totalVertices;ii++)	{		matricesWeights[ii*4+0]=1.0;		matricesWeights[ii*4+1]=0.0;		matricesWeights[ii*4+2]=0.0;		matricesWeights[ii*4+3]=0.0;		floatIndices[ii*4+0]=boneIndice;		floatIndices[ii*4+1]=boneIndice;		floatIndices[ii*4+2]=boneIndice;		floatIndices[ii*4+3]=boneIndice;	}        // Mounting the object on the skeleton        obj.skeleton = ske;	obj.setVerticesData(matricesWeights, BABYLON.VertexBuffer.MatricesWeightsKind, false);	obj.setVerticesData(floatIndices, BABYLON.VertexBuffer.MatricesIndicesKind, false);}mounted = false;engine.runRenderLoop(function() {	if ((sword!=undefined) && (Armature!=undefined)) 	{ 		if (!mounted) {			mount(sword,Armature,"Bone");			mounted=true;		}	}	scene.render();});

And that's done. 

@TODO : unmount function

Link to comment
Share on other sites


Could you mark the question as answered?



I can't mark it as answered.

Could it be mark as answered ? Yes .... But.... NO.


If I want to mount a bow or a crossbow on my bone, it might be difficult, because my bow need also a skeleton. This skeleton will be used for fire motion. Can we have multiple skeleton for a single mesh ?

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.

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.


  • Recently Browsing   0 members

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