# How to dynamically set the orientation of bones at run time?

**URL:** <https://discourse.threejs.org/t/how-to-dynamically-set-the-orientation-of-bones-at-run-time/12832>\
**Category:** Questions\
**Tags:** animation\
**Created:** [February 18, 2020, 9:16am UTC](https://discourse.threejs.org/t/how-to-dynamically-set-the-orientation-of-bones-at-run-time/12832 "2020-02-18T09:16:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![KaizerSozay](https://avatars.discourse-cdn.com/v4/letter/k/f475e1/32.png) [@KaizerSozay](https://discourse.threejs.org/u/KaizerSozay)\
**Post date:** [February 18, 2020, 9:16am UTC](https://discourse.threejs.org/t/how-to-dynamically-set-the-orientation-of-bones-at-run-time/12832/1 "2020-02-18T09:16:58Z")

</div>

I have a 3d model of a humanoid skeleton (in this case a c3b file, but I’m willing to try other formats) with lots of bones (feet, hands, upper arm, lower arm, spine, neck, fingers, toes etc…)

I would like to display the skeleton onscreen, and dynamically set the orientation of individual bones. For example, is there some kind of api like:

SkeletonObject.getBone(“upper-leg”).setQuaternion(5,12,2,24);

I would like to be able to set the orientation of an individual bone by passing it a quaternion. The impact of adjusting the parent bone should be felt on the child.

There are many examples about loading animations, but that is not what I want to do. I would like to be able to set the orientation of any bone dynamically at run time.

Can someone point me in the right direction ? I’ve posted on stack overflow, and tried to go through the documentation of Three.js , but haven’t been able to figure this out. Thanks.

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [February 18, 2020, 9:47am UTC](https://discourse.threejs.org/t/how-to-dynamically-set-the-orientation-of-bones-at-run-time/12832/2 "2020-02-18T09:47:58Z")

</div>

The following live example shows how to animate the rotation of a single bone. This is done with Euler angles since [Object3D.rotation](https://threejs.org/docs/index.html#api/en/core/Object3D.rotation) is used. But can achieve the same result by working with [Object3D.quaternion](https://threejs.org/docs/index.html#api/en/core/Object3D.quaternion).

[https://jsfiddle.net/1cv2p5aq/](https://jsfiddle.net/1cv2p5aq/)

As you can see in the code, the right arm of the model is selected like so after the loading process has finished:

```auto
rightArm = model.getObjectByName( 'mixamorigRightArm' );

```

In the animation loop, the rotation is then modulated:

```auto
if ( rightArm ) {
	
    rightArm.rotation.z += Math.sin( t ) * 0.005;

}	

```

---

<div class="post-metadata">

**Author:** ![KaizerSozay](https://avatars.discourse-cdn.com/v4/letter/k/f475e1/32.png) [@KaizerSozay](https://discourse.threejs.org/u/KaizerSozay)\
**Post date:** [February 18, 2020, 11:18am UTC](https://discourse.threejs.org/t/how-to-dynamically-set-the-orientation-of-bones-at-run-time/12832/3 "2020-02-18T11:18:02Z")

</div>

Thanks so much! I really appreciate it. Can you tell me how you created this scene or model ? I can see it is from an example hosted on the site, but I was wondering if I can load any arbitrary model.

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [February 18, 2020, 12:08pm UTC](https://discourse.threejs.org/t/how-to-dynamically-set-the-orientation-of-bones-at-run-time/12832/4 "2020-02-18T12:08:38Z")

</div>

The soldier model is from: [https://www.mixamo.com/](https://www.mixamo.com/)

You should be able to use this approach for all types of skinned meshes.
