File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -170,5 +170,43 @@ renderer.render(secen, cameraB)
170
170
171
171
172
172
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
+
173
211
<br >
174
212
You can’t perform that action at this time.
0 commit comments