updateMatrixWorld( force ) { if ( this.matrixAutoUpdate ) this.updateMatrix(); if ( this.matrixWorldNeedsUpdate || force ) { if ( this.parent === null ) { this.matrixWorld.copy( this.matrix ); } else { // 物体的世界矩阵就是其父元素的世界矩阵乘以自己的本地矩阵 this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix ); }
this.matrixWorldNeedsUpdate = false; force = true; }
// 递归调用,update children const children = this.children; for ( let i = 0, l = children.length; i < l; i ++ ) { children[ i ].updateMatrixWorld( force ); } }
源码信息
Object3D
Object3D.js也是位于core下面的,这个设计在可视化领域已经是一个约定俗成的原则了。
里面引入了math目录下的四元数、欧拉角、三维矩阵、四维矩阵等。
Matrix4.js中,有个计算三种矩阵乘积的方法:
1
compose( position, quaternion, scale )
几个关键的API
1 2 3 4
var worldPosition = newTHREE.Vector3(); mesh.getWorldPosition(worldPosition) console.log('世界坐标',worldPosition); console.log('本地坐标',mesh.position);