Skip to content

Commit 40e7fbc

Browse files
authored
Update Three.js实用知识点笔记.md
1 parent edb29de commit 40e7fbc

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

Three.js实用知识点笔记.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,5 +170,43 @@ renderer.render(secen, cameraB)
170170

171171

172172

173+
<br>
174+
175+
#### 05、手工修改Object3D实例的.matrix时切记要设置 .matrixAutoUpdate=false
176+
177+
默认情况下 Object3D 实例的 .matrixAutoUpdate 的值为 true,也就是说当通过 .applyMatrix4()、.applyQuaternion() 等修改实例的变换时,默认会自动更新其他所有相关属性值,例如 position、quaternion、scale、rotation。
178+
179+
但是,如果直接通过修改 Object3D 实例的 .matrix 值时,生效的前提是:
180+
181+
1. 先把 .matrixAutoUpdate 设置为 false
182+
2. 不去调用 .updateMatrix()
183+
184+
```
185+
const mesh = new Mesh(...)
186+
187+
mesh.matrixAutoUpdate = false
188+
mesh.matrix.copy(otherMatrix)
189+
```
190+
191+
192+
193+
<br>
194+
195+
但是上面的代码存在另外一个问题:尽管 .matrix 值更新了,可是 mesh 的其他属性值 例如 .position,.quaternion,scale,rotation 却没有自动更新。
196+
197+
解决方式很简单,可以通过 Matrix 的 .decompose() 方法优雅更新它们。
198+
199+
举例说明:假设现在有 meshA、meshB 两个对象,需要将 meshB 的各种变换属性值设置成和 meshA 完全相同
200+
201+
```
202+
meshB.matrixAutoUpdate = false
203+
meshB.matrix.copy(meshA.matrix)
204+
meshB.matrix.decompose(meshB.position, meshB.quaternion, meshB.scale)
205+
```
206+
207+
> 当修改 meshB.quaternion 值后会自动修改 meshB.rotation 的值
208+
209+
210+
173211
<br>
174212

0 commit comments

Comments
 (0)