# How to apply a local transform matrix to an Object?

**URL:** <https://discourse.threejs.org/t/how-to-apply-a-local-transform-matrix-to-an-object/21662>\
**Category:** Questions\
**Tags:** object3d\
**Created:** [December 16, 2020, 9:56am UTC](https://discourse.threejs.org/t/how-to-apply-a-local-transform-matrix-to-an-object/21662 "2020-12-16T09:56:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tfoller](https://avatars.discourse-cdn.com/v4/letter/t/3e96dc/32.png) [@tfoller](https://discourse.threejs.org/u/tfoller)\
**Post date:** [December 16, 2020, 9:56am UTC](https://discourse.threejs.org/t/how-to-apply-a-local-transform-matrix-to-an-object/21662/1 "2020-12-16T09:56:29Z")

</div>

If I write:

```
const cube = new THREE.Mesh(
     new THREE.BoxBufferGeometry(50, 50, 50, 1, 1, 1),
     new THREE.MeshPhongMaterial({
       color: 0xffff00
     })
   );
cube.matrix = new THREE.Matrix4();
cube.matrix.set(1,0,0,80, 0,1,0,0, 0,0,1,0, 0,0,0,1);

```

that doesn’t work. If I write:

```
const matrix = new THREE.Matrix4();
matrix.set(1,0,0,80, 0,1,0,0, 0,0,1,0, 0,0,0,1);
cube.applyMatrix4(matrix);

```

that works but I’m not sure if it’s the same as setting `.matrix` property on an Object or it’s a `.matrixWorld` or both.

What’s the proper way to make a new object and set a local matrix so it takes hold?

> **[Edit fiddle - JSFiddle - Code Playground](https://jsfiddle.net/tfoller/u7v0wcq5/32/)**

---

<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:** [December 16, 2020, 10:23am UTC](https://discourse.threejs.org/t/how-to-apply-a-local-transform-matrix-to-an-object/21662/2 "2020-12-16T10:23:46Z")

</div>

`Object3D.matrix` is automatically computed based on `Object3D.position`, `Object3D.rotation` and `Object3D.scale`. You can disable this by setting [Object3D.matrixAutoUpdate](https://threejs.org/docs/index.html#api/en/core/Object3D.matrixAutoUpdate) to `false`.

BTW: `Object3D.applyMatrix4()` multiplies the given matrix with the existing local one. This is something different than just setting a new matrix. In any event, `Object3D.applyMatrix4()` also updates `Object3D.position`, `Object3D.rotation` and `Object3D.scale`.

---

<div class="post-metadata">

**Author:** ![tfoller](https://avatars.discourse-cdn.com/v4/letter/t/3e96dc/32.png) [@tfoller](https://discourse.threejs.org/u/tfoller)\
**Post date:** [December 16, 2020, 10:39am UTC](https://discourse.threejs.org/t/how-to-apply-a-local-transform-matrix-to-an-object/21662/3 "2020-12-16T10:39:15Z")

</div>

Ok, thank you, so how do I achieve what I want?  
I have matrices coming from another software, so I would like to:

1. Apply them to existing objects without splitting them into position/rotation/scale
2. Apply them as in “setting a new matrix”, not pre-multiplying the existing one
3. After matrices are applied, be able to continue using various functions for setting pos/rot/scale individually, as in modifying these matrices further.

---

<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:** [December 16, 2020, 11:14am UTC](https://discourse.threejs.org/t/how-to-apply-a-local-transform-matrix-to-an-object/21662/4 "2020-12-16T11:14:50Z")

</div>

> [@tfoller](#):
>
> Apply them to existing objects without splitting them into position/rotation/scale

Why is this a problem? I suggest you do this and everything should work out of the box:

```js
externalMatrix.decompose( cube.position, cube.quaternion, cube.scale );

```

---

<div class="post-metadata">

**Author:** ![tfoller](https://avatars.discourse-cdn.com/v4/letter/t/3e96dc/32.png) [@tfoller](https://discourse.threejs.org/u/tfoller)\
**Post date:** [December 20, 2020, 2:59pm UTC](https://discourse.threejs.org/t/how-to-apply-a-local-transform-matrix-to-an-object/21662/5 "2020-12-20T14:59:06Z")

</div>

Removing solution because `decompose()` can not be composed back if the matrix has skew/sheer component, decomposition loses information. If I make matrices manually with `.matrixAutoUpdate = false;` I’ll have to do everything manually because then I can’t use all pos/rot/scale built-in functions.  
Also, as I understand, I need to manually recalculate `.matrixWorld`.

---

<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:** [December 20, 2020, 5:10pm UTC](https://discourse.threejs.org/t/how-to-apply-a-local-transform-matrix-to-an-object/21662/6 "2020-12-20T17:10:19Z")

</div>

> [@tfoller](#):
>
> Also, as I understand, I need to manually recalculate `.matrixWorld` .

The engine is actually not considered for this use case. I can’t guarantee that manually computing world matrices works. You have a least to set `matrixWorldNeedsUpdate` to `false` for all nodes and never use `updateMatrix()`.
