Three.js API手册

动画
AnimationAction AnimationClip AnimationMixer AnimationObjectGroup AnimationUtils KeyframeTrack PropertyBinding PropertyMixer
动画 / 轨道
BooleanKeyframeTrack ColorKeyframeTrack NumberKeyframeTrack QuaternionKeyframeTrack StringKeyframeTrack VectorKeyframeTrack
音频
Audio AudioAnalyser AudioContext AudioListener PositionalAudio
摄像机
ArrayCamera Camera CubeCamera OrthographicCamera PerspectiveCamera StereoCamera
常量
Animation Core CustomBlendingEquation DrawModes Materials Renderer Textures
核心
BufferAttribute BufferGeometry Clock DirectGeometry EventDispatcher Face3 Geometry InstancedBufferAttribute InstancedBufferGeometry InstancedInterleavedBuffer InterleavedBuffer InterleavedBufferAttribute Layers Object3D Raycaster Uniform
核心 / BufferAttributes
BufferAttribute_Types
弃用列表
DeprecatedList
附件
Earcut ShapeUtils
附件 / 核心
Curve CurvePath Font Interpolations Path Shape ShapePath
附件 / 曲线
ArcCurve CatmullRomCurve3 CubicBezierCurve CubicBezierCurve3 EllipseCurve LineCurve LineCurve3 QuadraticBezierCurve QuadraticBezierCurve3 SplineCurve
附件 / 物体
ImmediateRenderObject
几何体
BoxBufferGeometry BoxGeometry CircleBufferGeometry CircleGeometry ConeBufferGeometry ConeGeometry CylinderBufferGeometry CylinderGeometry DodecahedronBufferGeometry DodecahedronGeometry EdgesGeometry ExtrudeBufferGeometry ExtrudeGeometry IcosahedronBufferGeometry IcosahedronGeometry LatheBufferGeometry LatheGeometry OctahedronBufferGeometry OctahedronGeometry ParametricBufferGeometry ParametricGeometry PlaneBufferGeometry PlaneGeometry PolyhedronBufferGeometry PolyhedronGeometry RingBufferGeometry RingGeometry ShapeBufferGeometry ShapeGeometry SphereBufferGeometry SphereGeometry TetrahedronBufferGeometry TetrahedronGeometry TextBufferGeometry TextGeometry TorusBufferGeometry TorusGeometry TorusKnotBufferGeometry TorusKnotGeometry TubeBufferGeometry TubeGeometry WireframeGeometry
辅助对象
ArrowHelper AxesHelper BoxHelper Box3Helper CameraHelper DirectionalLightHelper FaceNormalsHelper GridHelper PolarGridHelper PositionalAudioHelper HemisphereLightHelper PlaneHelper PointLightHelper RectAreaLightHelper SkeletonHelper SpotLightHelper VertexNormalsHelper
灯光
AmbientLight DirectionalLight HemisphereLight Light PointLight RectAreaLight SpotLight
灯光 / 阴影
DirectionalLightShadow LightShadow SpotLightShadow
加载器
AnimationLoader AudioLoader BufferGeometryLoader Cache CompressedTextureLoader CubeTextureLoader DataTextureLoader FileLoader FontLoader ImageBitmapLoader ImageLoader Loader LoaderUtils MaterialLoader ObjectLoader TextureLoader
加载器 / 管理器
DefaultLoadingManager LoadingManager
材质
LineBasicMaterial LineDashedMaterial Material MeshBasicMaterial MeshDepthMaterial MeshDistanceMaterial MeshLambertMaterial MeshMatcapMaterial MeshNormalMaterial MeshPhongMaterial MeshPhysicalMaterial MeshStandardMaterial MeshToonMaterial PointsMaterial RawShaderMaterial ShaderMaterial ShadowMaterial SpriteMaterial
数学库
Box2 Box3 Color Cylindrical Euler Frustum Interpolant Line3 Math Matrix3 Matrix4 Plane Quaternion Ray Sphere Spherical Triangle Vector2 Vector3 Vector4
数学库 / 插值
CubicInterpolant DiscreteInterpolant LinearInterpolant QuaternionLinearInterpolant
物体
Bone Group Line LineLoop LineSegments LOD Mesh Points Skeleton SkinnedMesh Sprite
渲染器
WebGLMultisampleRenderTarget WebGLRenderer WebGLRenderTarget WebGLRenderTargetCube
渲染器 / 着色器
ShaderChunk ShaderLib UniformsLib UniformsUtils
场景
Fog FogExp2 Scene
纹理贴图
CanvasTexture CompressedTexture CubeTexture DataTexture DataTexture3D DepthTexture Texture VideoTexture
在线工具推荐: Three.js AI纹理开发包 - YOLO合成数据生成器 - GLTF/GLB在线编辑 - 3D模型格式在线转换 - 可编程3D场景编辑器

四维向量(Vector4)

该类表示的是一个三维向量(4D vector)。 一个四维向量表示的是一个有顺序的、四个为一组的数字组合(标记为x、y和z), 可被用来表示很多事物,例如:

  • 一个位于四维空间中的点。
  • 一个在四维空间中的方向与长度的定义。在three.js中,长度总是从(0, 0, 0, 0)到(x, y, z, w)的 Euclidean distance(欧几里德距离,即直线距离), 方向也是从(0, 0, 0, 0)到(x, y, z, w)的方向。
  • 任意的、有顺序的、四个为一组的数字组合。

其他的一些事物也可以使用二维向量进行表示,但以上这些是它在three.js中的常用用途。

示例

var a = new THREE.Vector4( 0, 1, 0, 0 ); //no arguments; will be initialised to (0, 0, 0, 1) 
var b = new THREE.Vector4( ); 
var d = a.dot( b );

构造函数

Vector4( x : Float, y : Float, z : Float, w : Float )

x - 向量的x值,默认为0
y - 向量的y值,默认为0
z - 向量的z值,默认为0
w - 向量的w值,默认为1

创建一个新的Vector4。

属性

# .isVector4 : Boolean

用于测试这个类或者派生类是否为Vector4,默认为true

你不应当对这个属性进行改变,因为它在内部使用,以用于优化。

# .x : Float

# .y : Float

# .z : Float

# .w : Float

方法

# .add ( v : Vector4 ) : this

将传入的向量v和这个向量相加。

# .addScalar ( s : Float ) : this

将传入的标量s和这个向量的x值、y值、z值以及w值相加。

# .addScaledVector ( v : Vector4, s : Float ) : this

将所传入的v与s相乘所得的乘积和这个向量相加。

# .addVectors ( a : Vector4, b : Vector4 ) : this

将该向量设置为a + b.

# .applyMatrix4 ( m : Matrix4 ) : this

将该向量乘以四阶矩阵m。

# .ceil () : this

将该向量x分量、 y分量z分量以及w分量向上取整为最接近的整数。

# .clamp ( min : Vector4, max : Vector4 ) : this

min - 在限制范围内,x值、y值、z值以及w值的最小值
max - 在限制范围内,x值、y值、z值以及w值的最大值

如果该向量的x值、y值、z值或w值大于限制范围内最大x值、y值、z值或w值,则该值将会被所对应的值取代。

如果该向量的x值、y值、z值或w值小于限制范围内最小x值、y值、z值或w值,则该值将会被所对应的值取代。

# .clampLength ( min : Float, max : Float ) : this

min - 长度将被限制为的最小值
max - 长度将被限制为的最大值

如果向量长度大于最大值,则它将会被最大值所取代。

如果向量长度小于最小值,则它将会被最小值所取代。

# .clampScalar ( min : Float, max : Float ) : this

min - 分量将被限制为的最小值
max - 分量将被限制为的最大值

如果该向量的x值、y值、z值或w值大于最大值,则它们将被最大值所取代。

如果该向量的x值、y值、z值或w值小于最小值,则它们将被最小值所取代。

# .clone () : Vector4

返回一个新的Vector4,其具有和当前这个向量相同的x、y、z和w。

# .copy ( v : Vector4 ) : this

将所传入Vector4的x、y、z和w属性复制给这一Vector4。

# .divideScalar ( s : Float ) : this

将该向量除以标量s。
如果传入的s = 0,则向量将被设置为( 0, 0, 0, 0 )

# .dot ( v : Vector4 ) : Float

计算该vector和所传入v 的点积(dot product)。

# .equals ( v : Vector4 ) : Boolean

检查该向量和v的严格相等性。

# .floor () : this

向量的分量向下取整为最接近的整数值。

# .fromArray ( array : Array, offset : Integer ) : this

array - 来源矩阵。
offset - (可选)在数组中的元素偏移量,默认值为0。

设置向量中的x值为array[ offset + 0 ],y值为array[ offset + 1 ], z值为array[ offset + 2 ],w 值为array[ offset + 3 ]。

# .fromBufferAttribute ( attribute : BufferAttribute, index : Integer ) : this

attribute - 来源的attribute。
index - 在attribute中的索引。

从attribute中设置向量的x值、y值、z值和w值。

# .getComponent ( index : Integer ) : Float

index - 0, 1, 2 or 3.

如果index值为0返回x值。
如果index值为1返回y值。
如果index值为2返回z值。
如果index值为3返回w值。

# .length () : Float

计算从(0, 0, 0, 0) 到 (x, y, z, w)的欧几里得长度 (Euclidean length,即直线长度)。

# .manhattanLength () : Float

计算该向量的曼哈顿长度(Manhattan length)。

# .lengthSq () : Float

计算从(0, 0, 0, 0)到(x, y, z, w)的欧几里得长度 (Euclidean length,即直线长度)的平方。 如果你正在比较向量的长度,应当比较的是长度的平方,因为它的计算效率更高一些。

# .lerp ( v : Vector4, alpha : Float ) : this

v - 朝着进行插值的Vector4。
alpha - 插值因数,其范围在[0, 1]闭区间。

在该向量与传入的向量v之间的线性插值,alpha是沿着线的距离长度。 —— alpha = 0 时表示的是当前向量,alpha = 1 时表示的是所传入的向量v。

# .lerpVectors ( v1 : Vector4, v2 : Vector4, alpha : Float ) : this

v1 - 起始的Vector4。
v2 - 朝着进行插值的Vector4。
alpha - 插值因数,其范围在[0, 1]闭区间。

将此向量设置为在v1和v2之间进行线性插值的向量, 其中alpha为两个向量之间连线的距离长度。 —— alpha = 0 时表示的是v1,alpha = 1 时表示的是v2。

# .negate () : this

向量取反,即: x = -x, y = -y, z = -z , w = -w。

# .normalize () : this

将该向量转换为单位向量(unit vector), 也就是说,将该向量的方向设置为和原向量相同,但是其长度(length)为1。

# .max ( v : Vector4 ) : this

如果该向量的x值、y值、z值或w值小于所传入v的x值、y值、z值或w值, 则将该值替换为对应的最大值。

# .min ( v : Vector4 ) : this

如果该向量的x值、y值、z值或w值大于所传入v的x值、y值、z值或w值, 则将该值替换为对应的最小值。

# .multiplyScalar ( s : Float ) : this

将该向量与所传入的标量s进行相乘。

# .round () : this

向量中的分量四舍五入取整为最接近的整数值。

# .roundToZero () : this

向量中的分量朝向0取整数(若分量为负数则向上取整,若为正数则向下取整)

# .set ( x : Float, y : Float, z : Float, w : Float ) : this

设置该向量的x、y、z和w分量。

# .setAxisAngleFromQuaternion ( q : Quaterion ) : this

q - 归一化的Quaterion(四元数)

将该向量的x、y和z分量设置为四元数的轴, w分量设置为四元数的角度。

# .setAxisAngleFromRotationMatrix ( m : Matrix4 ) : this

m - 一个Matrix4(四阶矩阵),其左上角3x3的元素表示的是一个纯旋转矩。

将该向量的x、y和z设置为旋转轴,w为角度。

# .setComponent ( index : Integer, value : Float ) : null

index - 0、1或2。
value - Float

若index为 0 则设置 x 值为 value。
若index为 1 则设置 y 值为 value。
若index为 2 则设置 z 值为 value。
若index为 3 则设置 w 值为 value。

# .setLength ( l : Float ) : this

将该向量的方向设置为和原向量相同,但是长度(length)为l。

# .setScalar ( scalar : Float ) : this

将该向量的x、y、z值和w同时设置为等于传入的scalar。

# .setX ( x : Float ) : this

将向量中的x值替换为x。

# .setY ( y : Float ) : this

将向量中的y值替换为y。

# .setZ ( z : Float ) : this

将向量中的z值替换为z。

# .setW ( w : Float ) : this

将向量中的w值替换为w。

# .sub ( v : Vector4 ) : this

从该向量减去向量v。

# .subScalar ( s : Float ) : this

从该向量的x、y、z和w分量中减去标量s。

# .subVectors ( a : Vector4, b : Vector4 ) : this

将该向量设置为a - b。

# .toArray ( array : Array, offset : Integer ) : Array

array - (可选)被用于存储向量的数组。如果这个值没有传入,则将创建一个新的数组。
offset - (可选) 数组中元素的偏移量。

返回一个数组[x, y, z, w],或者将x、y、z和w复制到所传入的array中。

源代码

src/math/Vector4.js