BufferGeometry
Object3D
Raycaster
Camera
CubeCamera
PerspectiveCamera
OrthographicCamera
StereoCamera
Clock
Curve
CurvePath
Path
Shape
ShapePath
ArrowHelper
AxesHelper
BoxHelper
Box3Helper
CameraHelper
DirectionalLightHelper
GridHelper
PolarGridHelper
HemisphereLightHelper
PlaneHelper
PointLightHelper
SkeletonHelper
SpotLightHelper
Light
PointLight
RectAreaLight
SpotLight
DirectionalLight
HemisphereLight
LightShadow
PointLightShadow
AnimationLoader
AudioLoader
BufferGeometryLoader
CompressedTextureLoader
CubeTextureLoader
DataTextureLoader
FileLoader
ImageBitmapLoader
ImageLoader
Loader
LoaderUtils
MaterialLoader
ObjectLoader
TextureLoader
LoadingManager
Material
Box2
Box3
Color
Cylindrical
Euler
Frustum
Interpolant
Line3
MathUtils
Matrix3
Matrix4
Plane
Quaternion
AnimationAction
AnimationClip
AnimationMixer
AnimationObjectGroup
AnimationUtils
keyframeTrack
PropertyBinding
PropertyMixer
BooleanKeyframeTrack
QuaternionKeyframeTrack
StringKeyframeTrack
Audio
AudioAnalyser
AudioContext
AudioListener
PositionalAudio

Object3D.updateMatrixWorld()

该方法用于更新 MatrixWorld,MatrixWorld 是 Object3D 对象的全局矩阵。

应用这个矩阵,将会使得 Object3D 对象对于其父元素和全局位置和旋转变化,都有正确的表现。换句话说,更新 MatrixWorld 用于确保对象在场景中使用正确的世界变换。

语法

object.updateMatrixWorld(force : Boolean)

参数

  • force - {Boolean} 为 true 时将会强制计算全局矩阵,否则若该对象位置未变化则不计算。

示例

var geometry = new THREE.BoxGeometry( 1, 1, 1 );
var material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
var cube = new THREE.Mesh( geometry, material );
var group = new THREE.Group();
group.add( cube );
scene.add( group );
group.position.set( 0, 2, 0 );
cube.position.set( 1, 1, 1 );
console.log( group.getWorldPosition() ); // (0, 2, 0)
console.log( cube.getWorldPosition() ); // (1, 3, 1)
console.log( group.matrixWorld.elements ); // [ 1, 0, 0, 0, 0, 1, 0, 2, 0, 0, 1, 0, 0, 0, 0, 1 ]
console.log( cube.matrixWorld.elements ); // [ 1, 0, 0, 1, 0, 1, 0, 3, 0, 0, 1, 1, 0, 0, 0, 1 ]
cube.updateMatrixWorld();
console.log( group.getWorldPosition() ); // (0, 2, 0)
console.log( cube.getWorldPosition() ); // (1, 3, 1)
console.log( group.matrixWorld.elements ); // [ 1, 0, 0, 0, 0, 1, 0, 2, 0, 0, 1, 0, 0, 0, 0, 1 ]
console.log( cube.matrixWorld.elements ); // [ 1, 0, 0, 1, 0, 1, 0, 3, 0, 0, 1, 1, 0, 0, 0, 1 ]

备注

在大多数情况下,无需手动调用此方法。在更新层次结构信息时会自动调用。但是,在有些情况下,手动调用此方法可以使代码更加清晰、更有效。

参考

https://threejs.org/docs/index.html#api/en/core/Object3D.updateMatrixWorld