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

Matrix3.setFromMatrix4()

Matrix3.setFromMatrix4(matrix)方法用于将4x4矩阵转换为3x3矩阵。

参数

  • matrix:矩阵(Matrix4类型)- 要转换为3x3矩阵的4x4矩阵。

用法

以下示例将4x4矩阵转换为3x3矩阵:

var matrix4 = new THREE.Matrix4();
var matrix3 = new THREE.Matrix3();

// set values of matrix4

matrix3.setFromMatrix4(matrix4);

返回值

该方法没有返回值。它会将原始矩阵转换为3x3矩阵。

示例

以下示例将一个旋转矩阵转换为3x3矩阵:

var matrix4 = new THREE.Matrix4();
matrix4.makeRotationY(Math.PI / 4); // rotate 45 degrees around Y-axis

var matrix3 = new THREE.Matrix3();
matrix3.setFromMatrix4(matrix4);

console.log(matrix3.elements); // outputs "0.7071067811865475,0,0,0,1,0,0,0,0.7071067811865475"

注意事项

  • 将4x4矩阵转换为3x3矩阵时,只保留平移变换之外的部分。
  • 该方法修改了原始矩阵。如果要保留原始矩阵,需要在转换前克隆矩阵。
  • 转换后的3x3矩阵可以用于计算法线矩阵,用于计算光照的方向。