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.toArray()

The Matrix3.toArray() method in Three.js is used to convert a Three.js Matrix3 object to a flat array of 9 numbers.

Syntax

matrix.toArray(array, offset);

Parameters

  • array - An (optional) array to which the elements of the matrix will be copied. If not provided, a new array will be created.
  • offset - An (optional) index offset into the target array at which to begin storing values. If not provided, the array is assumed to start at index 0.

Return value

The method has no return value. The elements of the matrix will be copied to the target array starting at the specified offset.

Example

const matrix = new THREE.Matrix3();
matrix.set(
    1, 0, 0,
    0, 1, 0,
    0, 0, 1
);
const array = [];
matrix.toArray(array);

In the above example, a new Matrix3 object is created and initialized with the identity matrix. Then, a new empty array is created and the elements of the matrix are copied to it using the toArray() method. The resulting array will be [1, 0, 0, 0, 1, 0, 0, 0, 1].

Notes

  • The toArray() method can be useful for passing matrix data to external libraries or APIs that expect a flat array of values.
  • When using the toArray() method with an existing array, care should be taken to ensure that the array is large enough to store all the values of the matrix. If the array is not large enough, the toArray() method will throw an error.