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

Matrix4.set()

概述

Matrix4.set() 方法用于设置 4x4 矩阵的值并返回该矩阵自身。该方法会用指定的数值依次填充矩阵的元素,矩阵的行和列分别以 x、y、z 和 w 来表示。

语法

matrix.set(n11, n12, n13, n14,
           n21, n22, n23, n24,
           n31, n32, n33, n34,
           n41, n42, n43, n44);

参数

  • n11~n44: 数值类型,指定要设置的矩阵元素的值。

示例

import * as THREE from 'three';

const matrix = new THREE.Matrix4();

matrix.set(1, 0, 0, 0,
           0, 1, 0, 0,
           0, 0, 1, 0,
           0, 0, 0, 1);

注解

Matrix4 是 three.js 中用于处理 3D 空间变换的对象,它保存了一个 4x4 的矩阵,其中前三列分别表示空间坐标系中 X、Y、Z 轴方向的向量,第四列为原点的坐标。Matrix4 支持多种基本变换操作,如旋转、平移、缩放等,也可以用作多个变换的组合。

需要注意的是,在实际应用中往往使用其他三.js 对象(如 Vector3)进行变换,并使用 Matrix4make*() 方法将这些变换指令转换为矩阵操作,例如:

import * as THREE from 'three';

const vector = new THREE.Vector3(1, 2, 3);
const matrix = new THREE.Matrix4();

// 平移 1, 2, 3
matrix.makeTranslation(1, 2, 3);

// 应用变换
vector.applyMatrix4(matrix);

参考