Three.js基础功能学习八:数学库与插值

本章介绍threejs的数学库及插值相关内容,包括工具类、常见数据结构的封装类及插值计算等内容。

一、学习视频

three.js学习及项目实战:数学库学习

二、数学库

2.1 Box2

表示二维空间中的一个轴对齐包围盒(axis-aligned bounding box,AABB)。
构造函数(Constructor)

Box2( min : Vector2, max : Vector2 )

  1. min - (可选) Vector2 表示该盒子的下边界(x, y)。默认值为( + Infinity, + Infinity )。
  2. max - (可选) Vector2 表示该盒子的上边界(x, y)。默认值为( - Infinity, - Infinity )。

创建一个介于最小和最大值之间的Box2。

属性(Properties)

  • .min : Vector2
      Vector2 表示该盒子的下边界(x, y)。
      默认值为( + Infinity, + Infinity )。
  • .max : Vector2
      Vector2 表示该盒子的上边界(x, y)。
      默认值为( - Infinity, - Infinity )。

方法(Methods)

  • .clampPoint ( point : Vector2, target : Vector2 ) : Vector2
      point - clamp 的位置 (Vector2)
      target --- 结果会被复制到该二维向量中。
      在该盒子范围内夹紧(Clamps)point。
  • .clone () : Box2
      返回一个新的Box2,其min和max与此盒子相同。
  • .containsBox ( box : Box2 ) : Boolean
      box - 要检查是否被包含的盒子。
      如果盒子包含整个被检查盒子,则返回true。如果两者重叠,也会返回true。
  • .containsPoint ( point : Vector2 ) : Boolean
      point - 要检查是否被包含的点Vector2。
      如果指定的点(point)位于盒子的边界内或边界上,则返回true。
  • .copy ( box : Box2 ) : this
      将box的min 和 max复制到此盒子中。
  • .distanceToPoint ( point : Vector2 ) : Float
      point - 要测量距离的点(Vector2)。
      返回这个盒子的任何边缘到指定点的距离。如果这个点(point)位于这个盒子里,距离将是0。
  • .equals ( box : Box2 ) : Boolean
      box - 要对比的盒子如果这个盒子和被对比盒子具有相同的上下边界,则返回true。
  • .expandByPoint ( point : Vector2 ) : this
      point - 应该被盒子包含的点。
      扩展盒子的边界来包含该点。
  • .expandByScalar ( scalar : Float ) : this
      scalar - 盒子扩展的距离。
      在每个维度上扩展参数scalar所指定的距离,如果为负数,则盒子空间将收缩。
  • .expandByVector ( vector : Vector2 ) : this
      vector - 按照该向量扩展。
      在每个维度中按vector的数值进行扩展。宽度在两个方向上的扩展将由vector的x分量确定, 高度在两个方向上的扩展则由y分量确定。
  • .getCenter ( target : Vector2 ) : Vector2
      target --- 结果将被复制到此二维向量中。
      以二维向量形式返回盒子的中心点。
  • .getParameter ( point : Vector2, target : Vector2 ) : Vector2
      point - 二维向量(Vector2).
      target --- 结果将被复制到此二维向量中。
      返回一个点作为此盒子的宽度和高度的比例。
  • .getSize ( target : Vector2 ) : Vector2
      target --- 结果将被复制到此二维向量中。
      返回此盒子的宽度和高度。
  • .intersect ( box : Box2 ) : this
      box - 要相交的盒子。
      返回两者的相交后的盒子,并将相交后的盒子的上限设置为两者的上限中的较小者,将下限设置为两者的下限中的较大者。
  • .intersectsBox ( box : Box2 ) : Boolean
      box - 用来检查相交的盒子。
      确定该盒子是否和其相交。
  • .isEmpty () : Boolean
      如果这个盒子包含0个顶点,则返回true。
      请注意,一个下上边界相等的的盒子仍然包括一个点,一个两个边界共享的点。
  • .makeEmpty () : this
      使此盒子为空。
  • .set ( min : Vector2, max : Vector2 ) : this
      min - (必须) 表示该盒子的下边界(x, y)。
      max - (必须) 表示该盒子的上边界(x, y)。
      设置这个盒子的上下(x, y)的界限。
      请注意,此方法仅复制给定对象的值。
  • .setFromCenterAndSize ( center : Vector2, size : Vector2 ) : this
      center - 盒子所要设置的中心位置。 (Vector2).
      size - 盒子所要设置的x和y尺寸 (Vector2).
      使盒子的中心点位于center,并设置宽高为size中指定的值。
  • .setFromPoints ( points : Array ) : this
      points - 点的集合,由这些点确定的空间将被盒子包围。
      设置这个盒子的上下边界,来包含所有设置在points参数中的点。
  • .translate ( offset : Vector2 ) : this
      offset - 偏移方向和距离。
      添加 offset 到这个盒子的上下边界,实际上在2D空间移动这个盒子offset个单位。
  • .union ( box : Box2 ) : this
      box - 将要与该盒子联合的盒子
      在box参数的上边界和该盒子的上边界之间取较大者,而对两者的下边界取较小者,这样获得一个新的较大的联合盒子。

2.2 Box3

表示三维空间中的一个轴对齐包围盒(axis-aligned bounding box,AABB)。
构造器(Constructor)

Box3( min : Vector3, max : Vector3 )

  1. min - (参数可选) Vector3 表示包围盒的下边界。 默认值是( + Infinity, + Infinity, + Infinity )。
  2. max - (参数可选) Vector3 表示包围盒的上边界。 默认值是( - Infinity, - Infinity, - Infinity )。

创建一个以max和min为边界的包围盒。

属性(Properties)

  • .isBox3 : Boolean
      Read-only flag to check if a given object is of type Box3.
  • .min : Vector3
      Vector3 表示包围盒的下边界。
      默认值是( + Infinity, + Infinity, + Infinity )。
  • .max : Vector3
      Vector3 包围盒的(x, y, z)上边界。
      默认值是 ( - Infinity, - Infinity, - Infinity ).

方法(Methods)

  • .applyMatrix4 ( matrix : Matrix4 ) : this

    matrix - 要应用的 Matrix4

    使用传入的矩阵变换Box3(包围盒8个顶点都会乘以这个变换矩阵)。

  • .clampPoint ( point : Vector3, target : Vector3 ) : Vector3

    point - 需要做clamp 的坐标 Vector3。

    target --- 结果将会被拷贝到这个对象中

    使这个点point Clamps(处于范围内) 处于包围盒边界范围内。

  • .clone () : Box3

    返回一个与该包围盒子有相同下边界min 和上边界 max的新包围盒。

  • .containsBox ( box : Box3 ) : Boolean

    box - 需要检测是否在当前包围盒内的 Box3。

    传入的 box 整体都被包含在该对象中则返回true。如果他们两个包围盒是一样的也返回true。

  • .containsPoint ( point : Vector3 ) : Boolean

    point - 需要检测是否在当前包围盒内的 Vector3。

    当传入的值 point 在包围盒内部或者边界都会返回true。

  • .copy ( box : Box3 ) : this

    box - 需要复制的包围盒 Box3 。

    将传入的值 box 中的 min 和 max 拷贝到当前对象。

  • .distanceToPoint ( point : Vector3 ) : Float

    point - 用来测试距离的点 Vector3。

    返回这个box的任何边缘到指定点的距离。如果这个点位于这个盒子里,距离将是0。

  • .equals ( box : Box3 ) : Boolean

    box - 将box与当前对象做比较。

    返回true如果传入的值与当前的对象 box 有相同的上下边界。

  • .expandByObject ( object : Object3D ) : this

    object - 包裹在包围盒中的3d对象 Object3D。

    扩展此包围盒的边界,使得对象及其子对象在包围盒内,包括对象和子对象的世界坐标的变换。 该方法可能会导致一个比严格需要的更大的框。

  • .expandByPoint ( point : Vector3 ) : this

    point - 需要在包围盒中的点 Vector3。

    扩展这个包围盒的边界使得该点(point)在包围盒内。

  • .expandByScalar ( scalar : Float ) : this

    scalar - 扩展包围盒的比例。

    按 scalar 的值展开盒子的每个维度。如果是负数,盒子的尺寸会缩小。

  • .expandByVector ( vector : Vector3 ) : this

    vector - 扩展包围盒的数值 Vector3 。

    按 vector 每个纬度的值展开这个箱子。 这个盒子的宽度将由 vector 的x分量在两个方向上展开。 这个盒子的高度将由 vector 两个方向上的y分量展开。 这个盒子的深度将由 vector z分量在两个方向上展开。

  • .getBoundingSphere ( target : Sphere ) : Sphere

    target --- 如果指定了target ,结果将会被拷贝到target。

    获取一个包围球 Sphere。

  • .getCenter ( target : Vector3 ) : Vector3

    target --- 如果指定了target ,结果将会被拷贝到target。

    返回包围盒的中心点 Vector3。

  • .getParameter ( point : Vector3, target : Vector3 ) : Vector3

    point - Vector3.

    target --- 如果指定了target ,结果将会被拷贝到target。

    返回一个点为这个盒子的宽度、高度和深度的比例。

  • .getSize ( target : Vector3 ) : Vector3

    target --- 如果指定了target ,结果将会被拷贝到target。

    返回包围盒的宽度,高度,和深度。

  • .intersect ( box : Box3 ) : this

    box - 与包围盒的交集

    计算此包围盒和 box 的交集,将此框的上界设置为两个框的max的较小部分, 将此包围盒的下界设置为两个包围盒的min的较大部分。如果两个包围盒不相交,则清空此包围盒。

  • .intersectsBox ( box : Box3 ) : Boolean

    box - 用来检测是否相交的包围盒

    确定当前包围盒是否与传入包围盒box 相交。

  • .intersectsPlane ( plane : Plane ) : Boolean

    plane - 用来检测是否相交的 Plane。

    确定当前包围盒是否与平面 plane 相交。

  • .intersectsSphere ( sphere : Sphere ) : Boolean

    sphere - 用来检测是否相交的球体 Sphere。

    确定当前包围盒是否与球体 sphere 相交。

  • .intersectsTriangle ( triangle : Triangle ) : Boolean

    triangle - 用来检测是否相交的三角形 Triangle。

    确定当前包围盒是否与三角形 triangle 相交。

  • .isEmpty () : Boolean

    如果这个盒子包含0个顶点,则返回true。

    注意,下界和上界相等的方框仍然包含一个点,即两个边界共享的那个点。

  • .makeEmpty () : this

    清空包围盒。

  • .set ( min : Vector3, max : Vector3 ) : this

    min - Vector3 表示下边界每个纬度(x,y,z)的值。

    max - Vector3 表示上边界每个纬度(x,y,z)的值。

    设置包围盒上下边界每个纬度(x,y,z)的值。

    请注意,此方法仅复制给定对象的值。

  • .setFromArray ( array : Array ) : this

    array - 数组当中的所有的点都将被包围盒包裹。

    设置包围盒的上下边界使得数组 array 中的所有点的点都被包含在内。

  • .setFromBufferAttribute ( attribute : BufferAttribute ) : this

    attribute - 位置的缓冲数据,包含在返回的包围盒内。

    设置此包围盒的上边界和下边界,以包含 attribute 中的所有位置数据。

  • .setFromCenterAndSize ( center : Vector3, size : Vector3 ) : this

    center, - 包围盒所要设置的中心位置。

    size - 包围盒所要设置的x、y和z尺寸(宽/高/长)。

    将当前包围盒的中心点设置为 center ,并将此包围盒的宽度,高度和深度设置为大小指定 size 的值。

  • .setFromObject ( object : Object3D ) : this

    object - 用来计算包围盒的3D对象 Object3D。

    计算和世界轴对齐的一个对象 Object3D (含其子对象)的包围盒,计算对象和子对象的世界坐标变换。 该方法可能会导致一个比严格需要的更大的框。

  • .setFromPoints ( points : Array ) : this

    points - 计算出的包围盒将包含数组中所有的点 Vector3s

    设置此包围盒的上边界和下边界,以包含数组 points 中的所有点。

  • .translate ( offset : Vector3 ) : this

    offset - 偏移方向和距离。

    给包围盒的上下边界添加偏移量 offset,这样可以有效的在3D空间中移动包围盒。 偏移量为 offset 大小。

  • .union ( box : Box3 ) : this

    box - 将被用于与该盒子计算并集的盒子。

在 box 参数的上边界和已有box对象的上边界之间取较大者,而对两者的下边界取较小者,这样获得一个新的较大的联合盒子。

2.3 颜色(Color)

表示一个颜色。

对 Color 实例进行遍历将按相应的顺序生成它的分量 (r, g, b)。
构造器(Constructor)

Color( r : Color_Hex_or_String, g : Float, b : Float )

  1. r - (可选参数) 如果参数g和b被定义,则r表示颜色中的红色分量。 如果未被定义,r可以是一个十六进制 hexadecimal triplet 颜色值或CSS样式的字符串或一个Color实例。
  2. g - (可选参数) 如果被定义,表示颜色中的绿色分量。
  3. b - (可选参数) 如果被定义,表示颜色中的蓝色分量。
      注意使用十六进制 hexadecimal triplet 定义一个颜色在three.js中是标准的方法,而且其余 文档也将会使用这个方法。
      当所有参数被定义时,r是红色分量,g是绿色分量,b是蓝色分量。
      当只有 r 被定义时:
        它可用一个十六进制 hexadecimal triplet 值表示颜色(推荐)。
        它可以是一个另一个颜色实例。
        它可以是另外一个CSS样式。例如:
javascript 复制代码
'rgb(250, 0,0)'
'rgb(100%,0%,0%)'
'hsl(0, 100%, 50%)'
'#ff0000'
'#f00'
'red'

属性(Properties)

  • .isColor : Boolean
      Read-only flag to check if a given object is of type Color.
  • .r : Float
      红色通道的值在0到1之间。默认值为1。
  • .g : Float
      绿色通道的值在0到1之间。默认值为1。
  • .b : Float
      蓝色通道的值在0到1之间。默认值为1。

方法(Methods)

  • .add ( color : Color ) : this
      将给定颜色的RGB值添加到此颜色的RGB值。
  • .addColors ( color1 : Color, color2 : Color ) : this
      将此颜色的RGB值设置为 color1 和 color2 的RGB值之和。
  • .addScalar ( s : Number ) : this
      给现有的RGB值都加上 s 。
  • .clone () : Color
      返回一个与当前颜色的 r, g 和 b 相同的颜色。
  • .copy ( color : Color ) : this
      从 color 中拷贝 r, g 和 b 值到当前的颜色。
  • .convertLinearToSRGB () : this
      将此颜色从线性空间转换成sRGB空间。
  • .convertSRGBToLinear () : this
      将此颜色从sRGB空间转换成线性空间。
  • .copyLinearToSRGB ( color : Color] ) : this
      color --- 需要拷贝的颜色。
      将传入的 color : Color 拷贝给当前颜色,然后将当前颜色从线性空间转换到sRGB空间。
  • .copySRGBToLinear ( color : Color ) : this
      color --- 需要拷贝的颜色。
      将传入的 color : Color 拷贝给当前颜色,然后将当前颜色从sRGB空间转换到线性空间。
  • .equals ( color : Color ) : Boolean
      将 color : Color 的RGB值与该对象的RGB值进行比较。如果它们都是相同的,返回true,否则返回false。
  • .fromArray ( array : Array, offset : Integer ) : this
      array - 格式为 [ r, g, b ] 的数组 Array。
      offset - 数组中可选偏移量
      从格式为[ r, g, b ]的数组数据中来创建Color对象。
  • .fromBufferAttribute ( attribute : BufferAttribute, index : Integer ) : this
      attribute - 数据源
      index - 索引值
      根据参数 attribute 设置该颜色。
  • .getHex ( colorSpace : string = SRGBColorSpace ) : Integer
      返回此颜色的十六进制值。
  • .getHexString ( colorSpace : string = SRGBColorSpace ) : String
      将此颜色的十六进制值作为字符串返回 (例如, 'FFFFFF')。
  • .getHSL ( target : Object, colorSpace : string = LinearSRGBColorSpace ) : Object
      target --- 结果将复制到这个对象中。向对象添加h、s和l键(如果不存在)。
      将此颜色的 r, g 和 b 值转换为 HSL格式,然后返回一个格式如下的对象:
    { h: 0, s: 0, l: 0 }
  • .getRGB ( target : Color, colorSpace : string = LinearSRGBColorSpace ) : Color
      target - 结果将复制到这个对象中.
      Returns the RGB values of this color as an instance of Color.
  • .getStyle ( colorSpace : string = SRGBColorSpace ) : String
      以CSS样式字符串的形式返回该颜色的值。例如:"rgb(255,0,0)"。
  • .lerp ( color : Color, alpha : Float ) : this
      color - 用于收敛的颜色。
      alpha - 介于0到1的数字。
      将该颜色的RGB值线性插值到传入参数的RGB值。alpha参数可以被认为是两种颜色之间的比例值,其中0是当前颜色和1.0是第一个参数的颜色。
  • .lerpColors ( color1 : Color, color2 : Color, alpha : Float ) : this
      color1 - 开始的颜色。
      color2 - 结束收敛的颜色。
      alpha - 介于0到1的数字。
      将该颜色设置为线性插值颜色 color1 和 color2 - 在此 alpha 是连接两种颜色的直线百分比距离 alpha = 0 时为 color1, alpha = 1 时为 color2。
  • .lerpHSL ( color : Color, alpha : Float ) : this
      color - 用于收敛的颜色。
      alpha - 介于0到1的数字。
      将该颜色的HSL值线性插值到传递参数的HSL值。它不同于上诉的lerp。通过不直接从一种颜色插入到另一种颜色, 而是通过插值这两种颜色之间的所有色相(H)、亮度(L)、饱和度(S)。alpha参数可以被认为是两种颜色之间的比例值, 其中0是当前颜色和1.0是第一个参数的颜色。
  • .multiply ( color : Color ) : this
      将此颜色的RGB值乘以给定的 color 的RGB值。
  • .multiplyScalar ( s : Number ) : this
      将此颜色的RGB值乘以给定的s的值。
  • .offsetHSL ( h : Float, s : Float, l : Float ) : this
      将给定的 h, s, 和 l值加到当前颜色值。 内部的机制为:先将该颜色的 r, g 和 b 值转换为HSL,然后与传入的h, s, 和 l 相加,最后再将结果转成RGB值。
  • .set ( r : Color_Hex_or_String, g : Float, b : Float ) : this
      r - (optional) If arguments g and b are defined, the red component of the color. If they are not defined, it can be a hexadecimal triplet (recommended), a CSS-style string, or another Color instance.
      g - (optional) If it is defined, the green component of the color.
      b - (optional) If it is defined, the blue component of the color.
      See the Constructor above for full details about possible arguments. Delegates to .copy, .setStyle, .setRGB or .setHex depending on input type.
  • .setHex ( hex : Integer, colorSpace : string = SRGBColorSpace ) : this
      hex --- hexadecimal triplet 格式。
      采用十六进制值设置此颜色。
  • .setHSL ( h : Float, s : Float, l : Float, colorSpace : string = LinearSRGBColorSpace ) : this
      h --- 色相值处于0到1之间。hue value between 0.0 and 1.0
      s --- 饱和度值处于0到1之间。
      l --- 亮度值处于0到1之间。
      采用HLS值设置此颜色。
    .setRGB ( r : Float, g : Float, b : Float, colorSpace : string = LinearSRGBColorSpace ) : this
      r --- 红色通道的值在0到1之间。
      g --- 绿色通道的值在0到1之间。
      b --- 蓝色通道的值在0到1之间。
      采用RGB值设置此颜色。
  • .setScalar ( scalar : Float ) : this
      scalar --- 处于0到1之间的值
      将颜色的RGB值都设为该 scalar 的值。
  • .setStyle ( style : String, colorSpace : string = SRGBColorSpace ) : this
      style --- 颜色css样式的字符串
      采用ccs样式的字符串设置此颜色。例如, "rgb(250, 0,0)", "rgb(100%, 0%, 0%)", "hsl(0, 100%, 50%)", "#ff0000", "#f00", 或者 "red" ( 或者任何 X11 color name - 所有140种颜色名称都支持 ).
    半透明颜色例如 "rgba(255, 0, 0, 0.5)" and "hsla(0, 100%, 50%, 0.5)" 也能支持, 但是alpha通道的值将会被丢弃。
      注意,对于X11颜色名称,多个单词(如暗橙色)变成字符串"darkorange"。
  • .setColorName ( style : String, colorSpace : string = SRGBColorSpace ) : this
      style --- 颜色名字的英文单词 ( 具体请查阅 X11 color names )
      通过颜色名字设置该颜色。如果你不使用其他 CSS 颜色样式形式,那么这种方式会略快于 .setStyle 方法。
      为了方便使用,颜色名称都可以通过 Color.NAMES 访问,例如:
      Color.NAMES.aliceblue // returns 0xF0F8FF
  • .sub ( color : Color ) : this
      从该颜色的RGB分量中减去传入颜色的RGB分量。如果分量结果是负,则该分量为零。
  • .toArray ( array : Array, offset : Integer ) : Array
      array - 存储颜色的可选数组
      offset - 数组的可选偏移量
      返回一个格式为[ r, g, b ] 数组。
  • .toJSON () : Number
      This methods defines the serialization result of Color. Returns the color as a hexadecimal value.

2.2 圆柱坐标(Cylindrical)

一个点的cylindrical coordinates(圆柱坐标)。
构造器(Constructor)

Cylindrical( radius : Float, theta : Float, y : Float )

  1. radius - 从原点到x-z平面上一点的距离 默认值为 1.0.
  2. theta - 在x-z平面内的逆时针角度,以z轴正方向的计算弧度。默认值为0。
  3. y - x-z平面以上的高度 默认值为 0.

属性(Properties)

  • .radius : Float
  • .theta : Float
  • .y : Float

Methods

  • .clone () : Cylindrical

    返回一个与当前拥有相同 radius, theta 和 y 属性的圆柱坐标。

  • .copy ( other : Cylindrical ) : this

    将传入的圆柱坐标对象的 radius, theta 和 y 属性赋给当前对象。

  • .set ( radius : Float, theta : Float, y : Float ) : this

    设置该对象的 radius, theta 和 y 属性。

  • .setFromVector3 ( vec3 : Vector3 ) : this

    从 Vector3 中取x,y,z,并调用setFromCartesianCoords来设置圆柱坐标的 radius、theta 和 y 的属性值。

  • .setFromCartesianCoords ( x : Float, y : Float, z : Float ) : this

    使用笛卡尔坐标来设置该圆柱坐标中 radius, theta 以及 y 的属性值。

2.2 欧拉角(Euler)

欧拉角描述一个旋转变换,通过指定轴顺序和其各个轴向上的指定旋转角度来旋转一个物体。

对 Euler 实例进行遍历将按相应的顺序生成它的分量 (x, y, z, order)。
构造器(Constructor)

Euler( x : Float, y : Float, z : Float, order : String )

  1. x - (optional) 用弧度表示x轴旋转量。 默认值是 0。
  2. y - (optional) 用弧度表示y轴旋转量。 默认值是 0。
  3. z - (optional) 用弧度表示z轴旋转量。 默认值是 0。
  4. order - (optional) 表示旋转顺序的字符串,默认为'XYZ'(必须是大写)。
    属性(Properties)
  • .isEuler : Boolean
      Read-only flag to check if a given object is of type Euler.
  • .order : String
      order值应用于旋转顺序。默认值为 'XYZ',这意味着对象将首先是 绕X轴旋转,然后是Y轴,最后是Z轴。其他可能性包括: 'YZX', 'ZXY', 'XZY', 'YXZ'和'ZYX'。这些必须是大写字母。
      Three.js 使用intrinsic Tait-Bryan angles(Yaw、Pitch、Roll)。 这意味着旋转是在本地坐标系下进行的。也就是说,对于"XYZ"顺序,首先是围绕local-X轴旋转(与world- x轴相同), 然后是local-Y(现在可能与world y轴不同),然后是local-Z(可能与world z轴不同)。
  • .x : Float
      当前x分量的值。
  • .y : Float
      当前y分量的值。
  • .z : Float
      当前z分量的值。
    方法(Methods)
  • .copy ( euler : Euler ) : this
      将 euler 的属性拷贝到当前对象。
  • .clone () : Euler
      返回一个与当前参数相同的新欧拉角。
  • .equals ( euler : Euler ) : Boolean
      检查 euler 是否与当前对象相同。
  • .fromArray ( array : Array ) : this
      长度为3或4的一个 array 。array[3] 是一个可选的 order 参数。
      将欧拉角的x分量设置为 array[0]。
      将欧拉角的y分量设置为 array[1]。
      将欧拉角的z分量设置为 array[2]。
      将array[3]设置给欧拉角的 order 。可选。
  • .reorder ( newOrder : String ) : this
      通过这个欧拉角创建一个四元数,然后用这个四元数和新顺序设置这个欧拉角。
      警告: 这将弃用旋转信息。
  • .set ( x : Float, y : Float, z : Float, order : String ) : this
      x - 用弧度表示x轴旋转量。
      y - 用弧度表示y轴旋转量。
      z - 用弧度表示z轴旋转量。
      order - (optional) 表示旋转顺序的字符串。
      设置该欧拉变换的角度和旋转顺序 order。
  • .setFromRotationMatrix ( m : Matrix4, order : String) : this
      m - Matrix4 矩阵上面的3x3部分是一个纯旋转矩阵rotation matrix (也就是不发生缩放)
      order - (可选参数) 表示旋转顺序的字符串。
      使用基于 order 顺序的纯旋转矩阵来设置当前欧拉角。
  • .setFromQuaternion ( q : Quaternion, order : String ) : this
      q - 归一化的四元数。
      order - (可选参数) 表示旋转顺序的字符串。
      根据 order 指定的方向,使用归一化四元数设置这个欧拉变换的角度。
  • .setFromVector3 ( vector : Vector3, order : String ) : this
      vector - Vector3.
      order - (可选参数) 表示旋转顺序的字符串。
      设置 x, y and z 并且选择性更新 order。
  • .toArray ( array : Array, offset : Integer ) : Array
      array - (可选参数) 存储欧拉角的数组。
      offset (可选参数) 数组的偏移量。
      返回一个数组:[x, y, z, order ]。

2.2 视锥体(Frustum)

Frustums 用于确定相机视野内的东西。 它有助于加速渲染过程------位于摄像机视锥体外的物体可以安全地排除在渲染之外。

该类主要用于渲染器内部计算 camera 或 shadowCamera的视锥体。
构造器(Constructor)

Frustum(p0 : Plane, p1 : Plane, p2 : Plane, p3 : Plane, p4 : Plane, p5 : Plane)

p0 - (可选参数) Plane.

p1 - (可选参数) Plane.

p2 - (可选参数) Plane.

p3 - (可选参数) Plane.

p4 - (可选参数) Plane.

p5 - (可选参数) Plane.

使用6个面来构建一个视锥体。

属性(Properties)

  • .planes : Array
      包含6个平面 planes 的数组。

方法(Methods)

  • .clone () : Frustum
      返回一个与当前对象有相同参数的视锥体。
  • .containsPoint ( point : Vector3 ) : Boolean
      point - Vector3 被检测的点。
      检测该点 point 是否在视锥体内。
  • .copy ( frustum : Frustum ) : this
      frustum - 用于拷贝的视锥体。
      将传入 frustum 的属性拷贝到当前对象。
  • .intersectsBox ( box : Box3 ) : Boolean
      box - Box3 用于检测是否要交的包围盒。
      返回 true 如果该 box 与视锥体相交。
  • .intersectsObject ( object : Object3D ) : Boolean
      检测 object 的包围球 bounding sphere 是否与视锥体相交。
      注意:该对象必须有一个 BufferGeometry ,因为这样才能计算出包围球。
  • .intersectsSphere ( sphere : Sphere ) : Boolean
      sphere - Sphere 用于检查是否相交。
      返回true 如果球sphere与视锥体相交。
  • .intersectsSprite ( sprite : Sprite ) : Boolean
      检查精灵sprite是否与截锥体相交。
  • .set ( p0 : Plane, p1 : Plane, p2 : Plane, p3 : Plane, p4 : Plane, p5 : Plane ) : this
      从传入的平面设置当前视锥体。没有隐式的顺序。
      请注意,此方法仅复制给定对象的值。
  • .setFromProjectionMatrix ( matrix : Matrix4 ) : this
      matrix - 投影矩阵 Matrix4 会被用来设置该视椎体的 planes
      根据投影矩阵 matrix 来设置当前视椎体的六个面。

2.2 插值器(Interpolant)

A参数样本上插值的抽象基类

参数域是一维的,通常是数据定义的曲线上的时间或路径。

示例值可以具有任何维度,派生类可以对数据应用特殊的解释。

该类提供间隔查找的模板方法,将实际的插值延迟到派生类。

对于最多两个点之间的访问时间复杂度为O(1),对于随机访问时间复杂度为O(log N),其中N为位置数。

2.2 三维几何线段(Line3)

用起点和终点表示的几何线段。
构造器(Constructor)

Line3( start : Vector3, end : Vector3 )

  1. start - 线段的起始点。默认值为 (0, 0, 0)。
  2. end - 线段的终点。默认值为 (0, 0, 0)。
      创建一个三维几何线段 Line3。

属性(Properties)

  • .start : Vector3
      Vector3 表示线段的起点。
  • .end : Vector3
      Vector3 表示线段的终点

方法(Methods)

  • .applyMatrix4 ( matrix : Matrix4 ) : this
      对此线段应用矩阵变换。
  • .at ( t : Float, target : Vector3 ) : Vector3
      t - 使用值0-1返回沿线段的位置。
      target --- 计算结果会被拷贝到target。
      返回一个线段某一位置的向量,当 t = 0的时候返回起始点,当t = 1的时候返回终点。
  • .clone () : Line3
      返回一个与此线段拥有相同起始点 start 和 终点end 的线段。
  • .closestPointToPoint ( point : Vector3, clampToLine : Boolean, target : Vector3 ) : Vector3
      point - 用于计算线段上到该点最近的点。
      clampToLine - 是否将结果限制在线段起始点和终点之间。
      target --- 结果会拷贝到target。
      返回线段上到point最近的点。如果参数 clampToLine 为true。返回值将会在线段之间。
  • .closestPointToPointParameter ( point : Vector3, clampToLine : Boolean ) : Float
      point - 用于计算返回值的点
      clampToLine - 结果是否处于 [0, 1]之间。
      返回一个基于点投影到线段上的点的参数。如果 clampToLine 为true则返回值将在0到1之间。
  • .copy ( line : Line3 ) : this
      拷贝传入线段的起始点 start 和终点 end 向量到当前线段。
  • .delta ( target : Vector3 ) : Vector3
      target --- 结果将会拷贝到target。
      返回线段的向量。(终点end向量减去起始点start向量)。
  • .distance () : Float
      Returns the Euclidean distance (straight-line distance) between the line's start and end points.
  • .distanceSq () : Float
      返回起始点start和终点end的欧几里得距离Euclidean distance。(直线距离)
  • .equals ( line : Line3 ) : Boolean
      line - Line3 to compare with this one.
      如果给定线段与当前线段的起始点start和终点end都相同则返回true。
  • .getCenter ( target : Vector3 ) : Vector3
      target --- 结果会写入target。
      返回线段的中心点。
  • .set ( start : Vector3, end : Vector3 ) : this
      start - 设置线段的起点 start point。
      end - 设置线段的终点 end point。
      将传入的向量设置到线段的起始点和终点。

2.2 数学函数(MathUtils)

  • .clamp ( value : Float, min : Float, max : Float ) : Float
      value --- 需要clamp处理的值。
      min --- 最小值。
      max --- 最大值。
      限制数值value处于最小值min和最大值max之间。
  • .degToRad ( degrees : Float ) : Float
      将度转化为弧度。
  • .euclideanModulo ( n : Integer, m : Integer ) : Integer
      n, m - 整型
      计算 m % n 的欧几里得模:
      ( ( n % m ) + m ) % m
  • .generateUUID ( ) : UUID
      创建一个全局唯一标识符 UUID。
  • .isPowerOfTwo ( n : Number ) : Boolean
      如果 n 是2的幂,返回true。
  • .inverseLerp ( x : Float, y : Float, value : Float ) : Float
      x - 起始点
      y - 终点
      value - 介于起始点和终点的值
      返回参数 value 在起点 x 与终点 y 的闭区间 [0,1] 中的百分比。
  • .lerp ( x : Float, y : Float, t : Float ) : Float
      x - 起始点。
      y - 终点。
      t - 闭区间 [0,1] 内的插值因子。
      返回给定区间的线性插值linearly interpolated结果 - t = 0 将会返回 x 如果 t = 1 将会返回 y.
  • .damp ( x : Float, y : Float, lambda : Float, dt : Float ) : Float
      x - 当前点
      y - 目标点
      lambda - 较高的参数 lambda 值会使运动更加突然,而较低的值会使运动更加平缓。
      dt - 以秒为单位的增量时间
      使用 dt 以类似弹簧的方式从 x 向 y 平滑地插入一个数字,以保持与帧速率无关的运动。有关详细信息,请参阅 Frame rate independent damping using lerp.
  • .mapLinear ( x : Float, a1 : Float, a2 : Float, b1 : Float, b2 : Float ) : Float
    x --- 用于映射的值。
      a1 --- A区间最小值。
      a2 --- A区间最大值。
      b1 --- B区间最小值。
      b2 --- B区间最大值。
      x从范围[a1, a2] 到范围[b1, b2]的线性映射。
  • .pingpong ( x : Float, length : Float ) : Float
      x --- pingpong 的值
      length --- 函数将 pingpong 传递到的正值。默认值为 1。
      返回一个介于 0 和 length : Float 之间的值。
  • .ceilPowerOfTwo ( n : Number ) : Integer
      返回大于等于 n 的2的最小次幂。
  • .floorPowerOfTwo ( n : Number ) : Integer
      返回小于等于 n 的2的最大幂。
  • .radToDeg ( radians : Float ) : Float
      将弧度转换为角度。
  • .randFloat ( low : Float, high : Float ) : Float
      在区间 [low, high] 内随机一个浮点数。
  • .randFloatSpread ( range : Float ) : Float
      在区间 [- range / 2, range / 2] 内随机一个浮点数。
  • .randInt ( low : Integer, high : Integer ) : Integer
      在区间 [low, high] 内随机一个整数。
  • .seededRandom ( seed : Integer ) : Float
      在区间 [0, 1] 中生成确定性的伪随机浮点数。 整数种子是可选的。
  • .smoothstep ( x : Float, min : Float, max : Float ) : Float
      x - 根据其在最小值和最大值之间的位置来计算的值。
      min - 任何x比最小值还小会返回0.
      max - 任何x比最大值还大会返回1.
      返回0-1之间的值,该值表示x在最小值和最大值之间移动的百分比,但是当x接近最小值和最大值时,变化程度会平滑或减慢。
      查看更多详情请移步到 Smoothstep 。
  • .smootherstep ( x : Float, min : Float, max : Float ) : Float
      x - 根据其在最小值和最大值之间的位置来计算的值。
      min - 任何x比最小值还小会返回0.
      max - 任何x比最大值还大会返回1.
      返回一个0-1之间的值。它和smoothstep相同,但变动更平缓。variation on smoothstep 在x=0和x=1处有0阶和二阶导数。
  • .setQuaternionFromProperEuler ( q : Quaternion, a : Float, b : Float, c : Float, order : String ) : undefined
      q - 将被设置的的四元数。
      a - 应用于第一个轴的旋转,以弧度为单位。
      b - 应用于第二个轴的旋转,以弧度为单位。
      c - 应用于第三个轴的旋转,以弧度为单位。
      order - 指定轴旋转顺序的字符串:'XYX', 'XZX', 'YXY', 'YZY', 'ZXZ', 或 'ZYZ'
      根据 a、b、c、order 组成的欧拉角 intrinsic Proper Euler Angles 来设置四元数 q。
      按照 order 指定的轴旋转顺序:先旋转角度 a,再旋转角度 b,最后旋转角度 c。角度以弧度为单位。

2.2 三维矩阵(Matrix3)

一个表示3X3矩阵matrix.的类。
Constructor

Matrix3( n11 : Number, n12 : Number, n13 : Number, n21 : Number, n22 : Number, n23 : Number, n31 : Number, n32 : Number, n33 : Number )

Creates a 3x3 matrix with the given arguments in row-major order. If no arguments are provided, the constructor initializes the Matrix3 to the 3x3 identity matrix.
属性(Properties)

  • .elements : Array
      矩阵列优先column-major列表。

方法(Methods)

  • .clone () : Matrix3
      创建一个新的矩阵,元素 elements 与该矩阵相同。
  • .copy ( m : Matrix3 ) : this
      将矩阵m的元素复制到当前矩阵中。
  • .determinant () : Float
      计算并返回矩阵的行列式determinant 。
  • .equals ( m : Matrix3 ) : Boolean
      如果矩阵m 与当前矩阵所有对应元素相同则返回true。
  • .extractBasis ( xAxis : Vector3, yAxis : Vector3, zAxis : Vector3 ) : this
      将该矩阵的基向量 basis 提取到提供的三个轴向中。如果该矩阵如下:
      a, b, c,
      d, e, f,
      g, h, i那么 xAxis, yAxis, zAxis 将会被设置为:
      xAxis = (a, d, g)
      yAxis = (b, e, h)
      zAxis = (c, f, i)
  • .fromArray ( array : Array, offset : Integer ) : this
      array - 用来存储设置元素数据的数组
      offset - (可选参数) 数组的偏移量,默认值为 0。
      使用基于列优先格式column-major的数组来设置该矩阵。
  • .invert () : this
      将当前矩阵翻转为它的逆矩阵,使用 analytic method 解析方式。你不能对行或列为 0 的矩阵进行翻转,如果你尝试这样做,该方法将生成一个零矩阵。
  • .getNormalMatrix ( m : Matrix4 ) : this
      m - Matrix4
      将这个矩阵设置为给定矩阵的正规矩阵normal matrix(左上角的3x3)。 正规矩阵是矩阵m的逆矩阵inverse 的转置transpose。
  • .identity () : this
      将此矩阵重置为3x3单位矩阵:
      1, 0, 0
      0, 1, 0
      0, 0, 1
  • .makeRotation ( theta : Float ) : this
      theta --- Rotation angle in radians. Positive values rotate counterclockwise.
      Sets this matrix as a 2D rotational transformation by theta radians. The resulting matrix will be:
      cos(θ) -sin(θ) 0
      sin(θ) cos(θ) 0
      0 0 1
  • .makeScale ( x : Float, y : Float ) : this
      x - the amount to scale in the X axis.
      y - the amount to scale in the Y axis.
      Sets this matrix as a 2D scale transform:
      x, 0, 0,
      0, y, 0,
      0, 0, 1
  • .makeTranslation ( v : Vector2 ) : this
  • .makeTranslation ( x : Float, y : Float ) : this
      v a translation transform from vector.
      or
      x - the amount to translate in the X axis.
      y - the amount to translate in the Y axis.
      Sets this matrix as a 2D translation transform:
      1, 0, x,
      0, 1, y,
      0, 0, 1
  • .multiply ( m : Matrix3 ) : this
      将当前矩阵乘以矩阵m。
  • .multiplyMatrices ( a : Matrix3, b : Matrix3 ) : this
      设置当前矩阵为矩阵a x 矩阵b。
  • .multiplyScalar ( s : Float ) : this
      当前矩阵所有的元素乘以该缩放值s
  • .set ( n11 : Float, n12 : Float, n13 : Float, n21 : Float, n22 : Float, n23 : Float, n31 : Float, n32 :   Float, n33 : Float ) : this
      n11 - 设置第一行第一列的值。
      n12 - 设置第一行第二列的值。
      ...
      ...
      n32 - 设置第三行第二列的值。
      n33 - 设置第三行第三列的值。
      使用行优先 row-major 的格式来设置该矩阵。
  • .premultiply ( m : Matrix3 ) : this
      将矩阵m乘以当前矩阵。
  • .setFromMatrix4 ( m : Matrix4 ) : this
      根据参数 m 左上 3x3 的矩阵值,设置当前矩阵的值。
  • .setUvTransform ( tx : Float, ty : Float, sx : Float, sy : Float, rotation : Float, cx : Float, cy : Float ) : this
      tx - x偏移量
      ty - y偏移量
      sx - x方向的重复比例
      sy - y方向的重复比例
      rotation - 旋转, 弧度。Positive values rotate counterclockwise
      cx - 旋转中心x
      cy - 旋转中心y
      使用偏移,重复,旋转和中心点位置设置UV变换矩阵。
  • .toArray ( array : Array, offset : Integer ) : Array
      array - (可选参数) 存储矩阵元素的数组,如果未指定会创建一个新的数组。
      offset - (可选参数) 存放矩阵元素数组的偏移量。
      使用列优先column-major格式将此矩阵的元素写入数组中。
  • .transpose () : this
      将该矩阵转置Transposes。
  • .transposeIntoArray ( array : Array ) : this
      array - 用于存储当前矩阵转置结果的数组。
      将当前矩阵的转置Transposes存入给定的数组 array 中,但不改变当前矩阵, 并返回当前矩阵。

2.2 四维矩阵(Matrix4)

表示为一个 4x4 matrix.

在3D计算机图形学中,4x4矩阵最常用的用法是作为一个变换矩阵Transformation Matrix。 有关WebGL中使用的变换矩阵的介绍,请参阅本教程this tutorial。

这使得表示三维空间中的一个点的向量Vector3通过乘以矩阵来进行转换,如平移、旋转、剪切、缩放、反射、正交或透视投影等。这就是把矩阵应用到向量上。
构造器(Constructor)

Matrix4( n11 : Number, n12 : Number, n13 : Number, n14 : Number, n21 : Number, n22 : Number, n23 : Number, n24 : Number, n31 : Number, n32 : Number, n33 : Number, n34 : Number, n41 : Number, n42 : Number, n43 : Number, n44 : Number )

Creates a 4x4 matrix with the given arguments in row-major order. If no arguments are provided, the constructor initializes the Matrix4 to the 4x4 identity matrix.
属性(Properties)

.elements : Array

矩阵列优先column-major列表。
方法(Methods)

  • .clone () : Matrix4
      创建一个新的矩阵,元素elements与该矩阵相同。
  • .compose ( position : Vector3, quaternion : Quaternion, scale : Vector3 ) : this
      设置将该对象位置 position,四元数quaternion 和 缩放scale 组合变换的矩阵。
  • .copy ( m : Matrix4 ) : this
      将矩阵m的元素elements复制到当前矩阵中。
  • .copyPosition ( m : Matrix4 ) : this
      将给定矩阵 m : Matrix4 的平移分量拷贝到当前矩阵中。
  • .decompose ( position : Vector3, quaternion : Quaternion, scale : Vector3 ) : this
      将矩阵分解到给定的平移position ,旋转 quaternion,缩放scale分量中。
      注意:并非所有矩阵都可以通过这种方式分解。 例如,如果一个对象有一个非均匀缩放的父对象,那么该对象的世界矩阵可能是不可分解的,这种方法可能不合适。
  • .determinant () : Float
      计算并返回矩阵的行列式determinant 。
      基于这个的方法概述here。
  • .equals ( m : Matrix4 ) : Boolean
      如果矩阵m 与当前矩阵所有对应元素相同则返回true。
  • .extractBasis ( xAxis : Vector3, yAxis : Vector3, zAxis : Vector3 ) : this
      将矩阵的基向量basis提取到指定的3个轴向量中。 如果矩阵如下:
      a, b, c, d,
      e, f, g, h,
      i, j, k, l,
      m, n, o, p然后x轴y轴z轴被设为:
      xAxis = (a, e, i)
      yAxis = (b, f, j)
      zAxis = (c, g, k)
  • .extractRotation ( m : Matrix4 ) : this
      将给定矩阵m的旋转分量提取到该矩阵的旋转分量中。
  • .fromArray ( array : Array, offset : Integer ) : this
      array - 用来存储设置元素数据的数组
      offset - (可选参数) 数组的偏移量,默认值为 0。
      使用基于列优先格式column-major的数组来设置该矩阵。
  • .invert () : this
      将当前矩阵翻转为它的逆矩阵,使用 analytic method 解析方式。你不能对行或列为 0 的矩阵进行翻转,如果你尝试这样做,该方法将生成一个零矩阵。
  • .getMaxScaleOnAxis () : Float
      获取3个轴方向的最大缩放值。
  • .identity () : this
      将当前矩阵重置为单位矩阵identity matrix。
  • .lookAt ( eye : Vector3, target : Vector3, up : Vector3 ) : this
      构造一个旋转矩阵,从eye 指向 target,由向量 up 定向。
  • .makeRotationAxis ( axis : Vector3, theta : Float ) : this
      axis --- 旋转轴,需要被归一化。
      theta --- 旋转量(弧度)。
      设置当前矩阵为围绕轴 axis 旋转量为 theta弧度。
      这是一种有点争议但在数学上可以替代通过四元数Quaternions旋转的办法。 请参阅此处here的讨论。
  • .makeBasis ( xAxis : Vector3, yAxis : Vector3, zAxis : Vector3 ) : this
      通过给定的三个向量设置该矩阵为基矩阵basis:
      xAxis.x, yAxis.x, zAxis.x, 0,
      xAxis.y, yAxis.y, zAxis.y, 0,
      xAxis.z, yAxis.z, zAxis.z, 0,
      0, 0, 0, 1
  • .makePerspective ( left : Float, right : Float, top : Float, bottom : Float, near : Float, far : Float ) : this
      创建一个透视投影矩阵perspective projection。 在引擎内部由PerspectiveCamera.updateProjectionMatrix()使用。
  • .makeOrthographic ( left : Float, right : Float, top : Float, bottom : Float, near : Float, far : Float ) : this
      创建一个正交投影矩阵orthographic projection。 在引擎内部由OrthographicCamera.updateProjectionMatrix()使用。
  • .makeRotationFromEuler ( euler : Euler ) : this
      将传入的欧拉角转换为该矩阵的旋转分量(左上角的3x3矩阵)。 矩阵的其余部分被设为单位矩阵。根据欧拉角euler的旋转顺序order,总共有六种可能的结果。 详细信息,请参阅本页this page。
  • .makeRotationFromQuaternion ( q : Quaternion ) : this
      将这个矩阵的旋转分量设置为四元数q指定的旋转,如下链接所诉here。 矩阵的其余部分被设为单位矩阵。因此,给定四元数q = w + xi + yj + zk,得到的矩阵为:
      1-2y²-2z² 2xy-2zw 2xz+2yw 0
      2xy+2zw 1-2x²-2z² 2yz-2xw 0
      2xz-2yw 2yz+2xw 1-2x²-2y² 0
      0 0 0 1
  • .makeRotationX ( theta : Float ) : this
      theta --- Rotation angle in radians.
      把该矩阵设置为绕x轴旋转弧度theta (θ)大小的矩阵。 结果如下:
      1 0 0 0
      0 cos(θ) -sin(θ) 0
      0 sin(θ) cos(θ) 0
      0 0 0 1
  • .makeRotationY ( theta : Float ) : this
      theta --- Rotation angle in radians.
      把该矩阵设置为绕Y轴旋转弧度theta (θ)大小的矩阵。 结果如下:
      cos(θ) 0 sin(θ) 0
      0 1 0 0
    -sin(θ) 0 cos(θ) 0
      0 0 0 1
  • .makeRotationZ ( theta : Float ) : this
      theta --- Rotation angle in radians.
      把该矩阵设置为绕z轴旋转弧度theta (θ)大小的矩阵。 结果如下:
      cos(θ) -sin(θ) 0 0
      sin(θ) cos(θ) 0 0
      0 0 1 0
      0 0 0 1
  • .makeScale ( x : Float, y : Float, z : Float ) : this
      x - 在X轴方向的缩放比。
      y - 在Y轴方向的缩放比。
      z - 在Z轴方向的缩放比。
      将这个矩阵设置为缩放变换:
      x, 0, 0, 0,
      0, y, 0, 0,
      0, 0, z, 0,
      0, 0, 0, 1
  • .makeShear ( x : Float, y : Float, z : Float ) : this
      x - 在X轴上剪切的量。
      y - 在Y轴上剪切的量。
      z - 在Z轴上剪切的量。
      将此矩阵设置为剪切变换:
      1, y, z, 0,
      x, 1, z, 0,
      x, y, 1, 0,
      0, 0, 0, 1
  • .makeTranslation ( v : Vector3 ) : this
  • .makeTranslation ( x : Float, y : Float, z : Float ) : this // optional API
      取传入参数v : Vector3中值设设置该矩阵为平移变换:
      1, 0, 0, x,
      0, 1, 0, y,
      0, 0, 1, z,
      0, 0, 0, 1
  • .multiply ( m : Matrix4 ) : this
      将当前矩阵乘以矩阵m。
  • .multiplyMatrices ( a : Matrix4, b : Matrix4 ) : this
      设置当前矩阵为矩阵a x 矩阵b。
  • .multiplyScalar ( s : Float ) : this
      当前矩阵所有的元素乘以该缩放值s
  • .premultiply ( m : Matrix4 ) : this
      将矩阵m乘以当前矩阵。
  • .scale ( v : Vector3 ) : this
      将该矩阵的列向量乘以对应向量v的分量。
  • .set ( n11 : Float, n12 : Float, n13 : Float, n14 : Float, n21 : Float, n22 : Float, n23 : Float, n24 :   Float, n31 : Float, n32 : Float, n33 : Float, n34 : Float, n41 : Float, n42 : Float, n43 : Float, n44 : Float ) : this
      以行优先的格式将传入的数值设置给该矩阵中的元素elements。
  • .setFromMatrix3 ( m : Matrix3 ) : this
      根据参数 m 的值,设置当前矩阵左上 3x3 的矩阵值。
  • .setPosition ( v : Vector3 ) : this
  • .setPosition ( x : Float, y : Float, z : Float ) : this // optional API
      取传入参数v : Vector3中值设置该矩阵的位置分量,不影响该矩阵的其余部分------即,如果该矩阵当前为:
      a, b, c, d,
      e, f, g, h,
      i, j, k, l,
      m, n, o, p变成:
      a, b, c, v.x,
      e, f, g, v.y,
      i, j, k, v.z,
      m, n, o, p
  • .toArray ( array : Array, offset : Integer ) : Array
      array - (可选参数) 存储矩阵元素的数组,如果未指定会创建一个新的数组。
    offset - (可选参数) 存放矩阵元素数组的偏移量。
      使用列优先column-major格式将此矩阵的元素写入数组中。
  • .transpose () : this
      将该矩阵转置Transposes。

2.2 平面(Plane)

在三维空间中无限延伸的二维平面,平面方程用单位长度的法向量和常数表示为海塞法向量Hessian normal form形式。
构造器(Constructor)

Plane( normal : Vector3, constant : Float )

  1. normal - (可选参数) 定义单位长度的平面法向量Vector3。默认值为 (1, 0, 0)。
  2. constant - (可选参数) 从原点到平面的有符号距离。 默认值为 0.

属性(Properties)

  • .isPlane : Boolean
    Read-only flag to check if a given object is of type Plane.
  • .normal : Vector3
  • .constant : Float

方法(Methods)

  • .applyMatrix4 ( matrix : Matrix4, optionalNormalMatrix : Matrix3 ) : this
      matrix - 要应用的四位矩阵(Matrix4)。
      optionalNormalMatrix - (可选参数) 预先计算好的上述Matrix4参数的法线矩阵 Matrix3。
    在平面上应用矩阵。矩阵必须是仿射齐次变换。
      如果提供一个optionalNormalMatrix,可以这样创建:
      const optionalNormalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  • .clone () : Plane
      返回一个与当前平面有相同法线 normal,常量 constant 距离的平面。
  • .coplanarPoint ( target : Vector3 ) : Vector3
      target --- 结果会拷贝到该向量中。
      返回一个共面点,通过原点的法向量在平面上投影算得。
  • .copy ( plane : Plane ) : this
      拷贝给定平面,将其中的法线 normal,距离常量 constant属性拷贝给该对象。
  • .distanceToPoint ( point : Vector3 ) : Float
      返回点point到平面的有符号距离。
  • .distanceToSphere ( sphere : Sphere ) : Float
      返回球面 sphere 的边缘到平面的最短距离。
  • .equals ( plane : Plane ) : Boolean
      检查两个平面是否相等。(法线 normal 以及常量 constant 都相同)。
  • .intersectLine ( line : Line3, target : Vector3 ) : Vector3
      line - 检测是否相交的三维几何线段 Line3。
      target --- 结果将会写入该向量中。
      返回给定线段和平面的交点。如果不相交则返回null。如果线与平面共面,则返回该线段的起始点。
  • .intersectsBox ( box : Box3 ) : Boolean
      box - 检查是否相交的包围盒 Box3。
      确定该平面是否与给定3d包围盒Box3相交。
  • .intersectsLine ( line : Line3 ) : Boolean
      line - 检查是否相交的三维线段 Line3。
      测试线段是否与平面相交。
  • .intersectsSphere ( sphere : Sphere ) : Boolean
      sphere - 检查是否相交的球体 Sphere。
      确定该平面是否与给定球体 Sphere 相交。
  • .negate () : this
      将法向量与常量求反(乘以-1)。
  • .normalize () : this
      归一化法向量 normal ,并相应的调整常量 constant数值。
  • .projectPoint ( point : Vector3, target : Vector3 ) : Vector3
      point - 需要投射到该平面的点。
      target --- 在该平面上离投射点最近的点。
      将一个点point投射到该平面上。
  • .set ( normal : Vector3, constant : Float ) : this
      normal - 单位长度的向量表示平面的法向量。
      constant - 原点到平面有符号距离。默认值为 0。
      设置平面 normal 的法线和常量 constant 属性值。
  • .setComponents ( x : Float, y : Float, z : Float, w : Float ) : this
      x - 单位长度法向量的x值。
      y - 单位长度法向量的y值。
      z - 单位长度法向量的z值。
      w - 原点沿法向量到平面常量 constant 距离。
      设置定义平面的各个变量。
  • .setFromCoplanarPoints ( a : Vector3, b : Vector3, c : Vector3 ) : this
      a - 用于确定平面的第一个点。
      b - 用于确定平面的第二个点。
      c - 用于确定平面的第三个点。
      根据给定的三个点确定平面。如果三个点共线将会抛出错误。通过右手螺旋规则确定(向量叉乘)法向量 normal。
  • .setFromNormalAndCoplanarPoint ( normal : Vector3, point : Vector3 ) : this
      normal - 平面单位法向量
      point - 平面上的点
      通过参数提供的法线 normal 和 平面上的一个点 point 来设置该平面。
  • .translate ( offset : Vector3 ) : this
      offset - 平移量
      将平面平移给定向量大小,注意:这只会影响平面的常量不会影响平面的法向量。

2.2 四元数(Quaternion)

四元数在three.js中用于表示 rotation (旋转)。

对 Quaternion 实例进行遍历将按相应的顺序生成它的分量 (x, y, z, w)。
构造函数

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

  1. x - x 坐标
  2. y - y 坐标
  3. z - z 坐标
  4. w - w 坐标

属性

  • .isQuaternion : Boolean
    Read-only flag to check if a given object is of type Quaternion.
    . x : Float
    . y : Float
    . z : Float
    . w : Float

方法

  • .angleTo ( q : Quaternion ) : Float
      以弧度返回该四元数与四元数 q 之间的夹角。
  • .clone () : Quaternion
      创建一个与该四元数具有相同x、y、z和w 属性的四元数。
  • .conjugate () : this
      返回该四元数的旋转共轭。 四元数的共轭表示的是,围绕旋转轴在相反方向上的相同旋转。
  • .copy ( q : Quaternion ) : this
      复制四元数 q 的 x、y、z 和 w 属性到该四元数中。
  • .equals ( v : Quaternion ) : Boolean
      v - 用于进行比较的四元数。
      将四元数 v 的 x、 y、 z 和 w 的属性 与当前四元数的对应属性相比较,以确定它们是否表示相同的旋转。
  • .dot ( v : Quaternion ) : Float
      计算四元数 v 与当前四元数的dot product(点积)。
  • .fromArray ( array : Array, offset : Integer ) : this
      array - 用于构造四元数的形如(x, y, z, w)的数组。
      offset - (可选)数组的偏移量。(译者注:使用数组中从第offset元素算起的四个元素)
      从一个数组来设置四元数的 x、 y、z 和 w 的属性。
  • .identity () : this
      设置该四元数为 identity 四元数,即表示"不旋转"的四元数。
  • .invert () : this
      翻转该四元数 ------ 计算 conjugate 。假定该四元数具有单位长度。
  • .length () : Float
      计算四元数的 Euclidean length (欧几里得长度,直线长度),视为一个四维向量。
  • .lengthSq () : Float
      计算四元数 Euclidean length (欧几里得长度,直线长度)的平方,视为一个四维向量。 如果要比较两个四元数的长度,这可能会十分有用, 因为这比 length() 的效率稍高一些。
  • .normalize () : this
      Normalizes(归一化)四元数 ------ 即计算与该四元数具有相同旋转、但长度为1的四元数。
  • .multiply ( q : Quaternion ) : this
      将该四元数与q相乘。
  • .multiplyQuaternions ( a : Quaternion, b : Quaternion ) : this
      将该四元数设为 a x b 。
      改编自 here 所概述的方法。
  • .premultiply ( q : Quaternion ) : this
      使用 q 乘以该四元数。
  • .rotateTowards ( q : Quaternion, step : Float ) : this
      q - 目标四元数
      step - 以弧度为单位的角度步长
      将该四元数按照步长 step 向目标 q 进行旋转。该方法确保最终的四元数不会超过 q。
  • .slerp ( qb : Quaternion, t : Float ) : this
      qb - 另一个四元数旋转
      t - 闭区间 [0, 1] 中的插值因子
      处理四元数之间的球面线性插值。t 表示该四元数(其中 t 为 0) 和 qb (其中 t 为1) 之间的旋转量。 该四元数会被设置为上述计算的结果。另请参阅下面 slerp 的静态版本。
      // rotate a mesh towards a target quaternion
      mesh.quaternion.slerp( endQuaternion, 0.01 );
  • .slerpQuaternions ( qa : Quaternion, qb : Quaternion, t : Float ) : this
      在给定的四元数之间执行球面线性插值,并将结果存储在这个四元数中
  • .set ( x : Float, y : Float, z : Float, w : Float ) : this
      设置该四元数的 x、y、z和w属性。
  • .setFromAxisAngle ( axis : Vector3, angle : Float ) : this
      从由 axis(轴) 和 angle(角度)所给定的旋转来设置该四元数。
      改编自 here 所述的方法。
      假定Axis已被归一化,angle以弧度来表示。
  • .setFromEuler ( euler : Euler ) : this
      从由 Euler 角所给定的旋转来设置该四元数。
  • .setFromRotationMatrix ( m : Matrix4 ) : this
      从m的旋转分量中来设置该四元数。
      改编自 here 所概述的方法。
  • .setFromUnitVectors ( vFrom : Vector3, vTo : Vector3 ) : this
      将该四元数设置为从方向向量 vFrom 旋转到方向向量 vTo 所需的旋转。
      改编自方法 here。
      假设 vFrom 和 vTo 都已归一化。
  • .toArray ( array : Array, offset : Integer ) : Array
      array - (可选)存储该四元数的数组。若未指定该参数,则将创建一个新数组。
      offset - (可选)若指定了该值,结果将会被拷贝到该 Array。
      在形如[x, y, z, w]的数组中,返回四元数中的数字元素。
  • .toJSON () : Array
      This methods defines the serialization result of Quaternion. 在形如[x, y, z, w]的数组中,返回四元数中的数字元素。
  • .fromBufferAttribute ( attribute : BufferAttribute, index : Integer ) : this
      attribute - 源 attribute。
      index - attribute 中的索引。
      从 attribute 中设置该四元数的x、 y、 z、 w属性。
    静态方法
  • .slerpFlat ( dst : Array, dstOffset : Integer, src0 : Array, srcOffset0 : Integer, src1 : Array, srcOffset1 : Integer, t : Float ) : undefined
      dst - 输出数组
      dstOffset - 输出数组的偏移量
      src0 - 起始四元数的源数组
      srcOffset0 - 数组 src0 的偏移量
      src1 - 目标四元数的源数组
      srcOffset1 - 数组 src1 的偏移量
      t - 归一化插值因子(介于 0 和 1 之间)
      This SLERP implementation assumes the quaternion data are managed in flat arrays.
  • .multiplyQuaternionsFlat ( dst : Array, dstOffset : Integer, src0 : Array, srcOffset0 : Integer, src1 : Array, srcOffset1 : Integer ) : Array
      dst - The output array.
      dstOffset - An offset into the output array.
      src0 - The source array of the starting quaternion.
      srcOffset0 - An offset into the array src0.
      src1 - The source array of the target quaternion.
      srcOffset1 - An offset into the array src1.
      This multiplication implementation assumes the quaternion data are managed in flat arrays.

2.2 射线(Ray)

射线由一个原点向一个确定的方向发射。它被Raycaster(光线投射)所使用, 以用于辅助raycasting。 光线投射用于在各个物体之间进行拾取(当鼠标经过三维空间中的物体/对象时进行拾取)。
构造函数

Ray( origin : Vector3, direction : Vector3 )

  1. origin - (可选)Ray(射线)的原点,默认值是一个位于(0, 0, 0)的Vector3。
  2. direction - Vector3 Ray(射线)的方向。该向量必须经过标准化(使用Vector3.normalize),这样才能使方法正常运行。 默认值是一个位于(0, 0, -1)的Vector3。
    创建一个新的Ray。

属性

  • .origin : Vector3
      Ray(射线)的原点,默认值是一个位于(0, 0, 0)的Vector3。
  • .direction : Vector3
      Ray(射线)的方向。该向量必须经过标准化(使用Vector3.normalize),这样才能使方法正常运行。 默认值是一个位于(0, 0, -1)的Vector3。

方法

  • .applyMatrix4 ( matrix4 : Matrix4 ) : this
      matrix4 - 将被用于这个Ray的Matrix4。
      使用传入的Matrix4来变换这个Ray。
  • .at ( t : Float, target : Vector3 ) : Vector3
      t - 使用这一传入的距离,在Ray上确定一个位置。
      target --- 结果将复制到这一Vector3中。
      获得这一Ray上给定距离处的Vector3。
  • .clone () : Ray
      创建一个新的和这个Ray具有相同origin和direction的Ray。
  • .closestPointToPoint ( point : Vector3, target : Vector3 ) : Vector3
      point - 获得距离射线上的点最接近的点。
      target --- 结果将复制到这一Vector3中。
      沿着Ray,获得与所传入Vector3最接近的点。
  • .copy ( ray : Ray ) : this
      复制所传入Ray的origin和direction属性到这个Ray上。
  • .distanceSqToPoint ( point : Vector3 ) : Float
      point - 将被用于计算到其距离的 Vector3。
      获得Ray与传入的Vector3之间最近的平方距离。
  • .distanceSqToSegment ( v0 : Vector3, v1 : Vector3, optionalPointOnRay : Vector3, optionalPointOnSegment : Vector3 ) : Float
      v0 - 线段的起点。
      v1 - 线段的终点。
      optionalPointOnRay - (可选)若这个值被给定,它将接收在Ray(射线)上距离线段最近的点。
      optionalPointOnSegment - (可选)若这个值被给定,它将接收在线段上距离Ray(射线)最近的点。
      获取Ray(射线)与线段之间的平方距离。
  • .distanceToPlane ( plane : Plane ) : Float
      plane - 将要获取射线原点到该平面的距离的平面。
      获取射线原点(origin)到平面(Plane)之间的距离。若射线(Ray)不与平面(Plane)相交,则将返回null。
  • .distanceToPoint ( point : Vector3 ) : Float
      point - Vector3 将被用于计算到其距离的Vector3。
      获得Ray(射线)到所传入point之间最接近的距离。
  • .equals ( ray : Ray ) : Boolean
      ray - 用于比较的Ray。
      如果所传入的ray具有和当前Ray相同的origin和direction则返回true。
  • .intersectBox ( box : Box3, target : Vector3 ) : Vector3
      box - 将会与之相交的Box3。
      target --- 结果将会被复制到这一Vector3中。
      将Ray(射线)与一个Box3相交,并返回交点,倘若没有交点将返回null。
  • .intersectPlane ( plane : Plane, target : Vector3 ) : Vector3
      plane - 将会与之相交的Plane。
      target --- 结果将会被复制到这一Vector3中。
      将Ray(射线)与一个Plane相交,并返回交点,倘若没有交点将返回null。
  • .intersectSphere ( sphere : Sphere, target : Vector3 ) : Vector3
      sphere - 将会与之相交的Sphere。
      target --- 结果将会被复制到这一Vector3中。
      将Ray(射线)与一个Sphere(球)相交,并返回交点,倘若没有交点将返回null。
  • .intersectTriangle ( a : Vector3, b : Vector3, c : Vector3, backfaceCulling : Boolean, target : Vector3 ) : Vector3
      a, b, c - 组成三角形的三个Vector3。
      backfaceCulling - 是否使用背面剔除。
      target --- 结果将会被复制到这一Vector3中。
      将Ray(射线)与一个三角形相交,并返回交点,倘若没有交点将返回null。
  • .intersectsBox ( box : Box3 ) : Boolean
      box - 将被检查是否与之相交的Box3。
      若这一射线与Box3相交,则将返回true。
  • .intersectsPlane ( plane : Plane ) : Boolean
      plane - 将被检查是否与之相交的Plane。
      若这一射线与Plane相交,则将返回true。
  • .intersectsSphere ( sphere : Sphere ) : Boolean
      sphere - 将被检查是否与之相交的Sphere。
      若这一射线与Sphere相交,则将返回true。
  • .lookAt ( v : Vector3 ) : this
      v - 将要"直视"的Vector3
      调整光线的方向到世界坐标中该向量所指代的点。
  • .recast ( t : Float ) : this
      t - 沿着Ray进行插值的距离。
      将Ray(射线)的原点沿着其方向移动给定的距离。
  • .set ( origin : Vector3, direction : Vector3 ) : this
      origin - Ray(射线)的origin(原点)。
      direction - Ray(射线)的direction(方向)。 该向量必须经过标准化(使用  Vector3.normalize),这样才能使方法正常运行。
      根据参数设置该射线的 origin 和 direction 。

2.球(Sphere)

一个球由球心和半径所定义。
构造函数

Sphere( center : Vector3, radius : Float )

center - 球心的位置,默认值是一个位于(0, 0, 0)的Vector3。

radius - 球的半径,默认值是-1。

创建一个新的Sphere。
属性

  • .center : Vector3
      A Vector3定义了球心的位置,默认值位于(0, 0, 0)。
  • .radius : Float
      球的半径,默认值为-1。

方法

  • .applyMatrix4 ( matrix : Matrix4 ) : this

    matrix - 将被应用的Matrix4矩阵。

    使用所传入的Matrix4矩阵来对球进行变换。

  • .clampPoint ( point : Vector3, target : Vector3 ) : Vector3

    point - Vector3 将要夹取的点。

    target --- 结果将被复制到这个Vector3中。

    从球中夹取一个点。若这一点位于球外,则将会夹取到该点球边缘最近的点。已位于球中的点将不会受到影响。

  • .clone () : Sphere

    返回一个新的球,新的球与这个球具有相同的center和radius。

  • .containsPoint ( point : Vector3 ) : Boolean

    point - Vector3 要被检查的点

    检查球体中是否包含所传入的point点,包括球的表面。

  • .copy ( sphere : Sphere ) : this

    复制所传入的球的center和radius到这个球上。

  • .distanceToPoint ( point : Vector3 ) : Float

    返回球的边界到所传入的point点的最近距离。 若这个点位于球内,则距离将为负值。

  • .expandByPoint ( point : Vector3 ) : this

    point - Vector3 将被包含在球内的点

    扩展该球的边界以包含此点 point。

  • .isEmpty () : Boolean

    检查球是否为空(球半径为负值)。半径为 0 的球体仅包含其中心点,并不会被视为空。

  • .makeEmpty () : this

    将该球修改为空,即中心点 center 为 (0,0,0),半径 radius 为 -1。

  • .equals ( sphere : Sphere ) : Boolean

    检查这两个球的球心与半径是否相等。

  • .getBoundingBox ( target : Box3 ) : Box3

    target --- 结果将被复制到这个Box3中。

    返回这个球的Minimum Bounding Box(最小包围盒)。

  • .intersectsBox ( box : Box3 ) : Boolean

    box - 将被用于测试是否与这个球有交集的Box3。

    检测这个球与所传入的box是否有交集。

  • .intersectsPlane ( plane : Plane ) : Boolean

    plane - 将被用于测试是否与这个球有交集的Plane。

    检测这个球与所传入的plane是否有交集。

  • .intersectsSphere ( sphere : Sphere ) : Boolean

    sphere - 将被用于测试是否与这个球有交集的Sphere。

    检测两球之间是否有交集。

  • .set ( center : Vector3, radius : Float ) : this

    center - 球心位置。

    radius - 球的半径。

    设置球的center和radius属性。

    请注意此,方法使用复制的方式来设置中心值。

  • .setFromPoints ( points : Array, optionalCenter : Vector3 ) : this

    points - 一个包含有Vector3位置的Array。

    optionalCenter - 可选, Vector3 球心位置。

    计算一个points数组(中的点)的最小边界球。如果给定了optionalCenter,则它将被用作该球的球心; 否则,环绕points的包围盒的轴心将通过计算来得到。

  • .translate ( offset : Vector3 ) : this

    使用所给定Vector3 offset(偏移量)平移球心。

  • .union ( sphere : Sphere ) : this

    sphere - 将与该球体即将结合的边界球体。

    扩展此球体以包含原始球体和给定球体。

2.球坐标(Spherical)

一个点的spherical coordinates(球坐标)。
构造函数

Spherical( radius : Float, phi : Float, theta : Float )

radius - 半径值,或者说从该点到原点的 Euclidean distance(欧几里得距离,即直线距离)。默认值为1.0。

phi - 与 y (up) 轴的极角(以弧度为单位)。 默认值为 0。

theta - 绕 y (up) 轴的赤道角(方位角)(以弧度为单位)。 默认值为 0。

极角(phi)位于正 y 轴和负 y 轴上。赤道角(方位角)(theta)从正 z 开始。
属性

  • .radius : Float
  • .phi : Float
  • .theta : Float

方法

  • .clone () : Spherical
      返回一个新的球坐标,新的球坐标与该球坐标具有相同的 radius、phi和theta。
  • .copy ( s : Spherical ) : this
      复制所传入的球坐标的radius、 phi 和theta属性到该球坐标中。
  • .makeSafe () : this
      将极角 phi 的值限制在0.000001 和 π - 0.000001 之间。
  • .set ( radius : Float, phi : Float, theta : Float ) : this
      设置球坐标中radius、phi 和 theta 属性的值。
  • .setFromVector3 ( vec3 : Vector3 ) : this
      从Vector3中设置球坐标的radius、phi和theta值。
  • .setFromCartesianCoords ( x : Float, y : Float, z : Float ) : this
      从笛卡尔坐标系中设置球坐标的radius、phi和theta值。

2. SphericalHarmonics3

表示三次球面谐波(SH)。光照探测器使用此类来编码光照信息。

构造函数(Constructor)

SphericalHarmonics3()

创建SphericalHarmonics3的新实例。
特性(Properties)

  • .coefficients : Array
      包含(9)个SH系数的数组。单个系数表示为Vector3的实例。
  • .isSphericalHarmonics3 : Boolean
      用于检查给定对象是否为SphericalHarmonics3类型的只读标志。

Methods

  • .add ( sh : SphericalHarmonics3 ) : SphericalHarmonics3
      sh - 要添加的SH。
      将给定的 SH 添加到此实例。
  • .addScaledSH ( sh : SphericalHarmonics3, scale : Number ) : SphericalHarmonics3
      sh - 要添加的SH。
      scale - 比例因子。
      一次 执行.add()和.scale()的便捷方法。
  • .clone () : SphericalHarmonics3
      返回具有相等系数的SphericalHarmonics3的新实例。
  • .copy ( sh : SphericalHarmonics3 ) : SphericalHarmonics3
      sh - 要复制的SH。
      将给定的SH复制到此实例。
  • .equals ( sh : SphericalHarmonics3 ) : Boolean
      sh - 要与之比较的 SH。
      如果给定的SH和此实例具有相等的系数,则返回true。
  • .fromArray ( array : Array, offset : Number ) : SphericalHarmonics3
      array - 保存SH系数数的数组。
      offset - (可选)数组偏移量。
      从给定数组设置此实例的系数。
  • .getAt ( normal : Vector3, target : Vector3 ) : Vector3
      normal - 法向量(假定为单位长度)。
      target - 结果向量。
      返回给定法线方向的辐射度。
  • .getIrradianceAt ( normal : Vector3, target : Vector3 ) : Vector3
      normal - 法向量(假定为单位长度)。
      target - 结果向量。
      返回给定法线方向的辐照度(辐射度与余弦波瓣卷积)。
  • .lerp ( sh : SphericalHarmonics3, alpha : Number ) : SphericalHarmonics3
      sh - 要插入的SH。
      alpha - alpha因子。
      通过给定的alpha因子在给定的SH和此实例之间进行线性插值。
  • .scale ( scale : Number ) : SphericalHarmonics3
      sh - 比例因子。
      按给定的比例因子缩放此SH。
  • .set ( coefficients : Array ) : SphericalHarmonics3
      coefficients - 一组SH系数。
      将给定的SH系数设置为此实例。
  • .toArray ( array : Array, offset : Number ) : Array
      array - (可选)目标数组。
      offset - (可选)数组偏移量。
      返回包含系数的数组,或将它们复制到提供的数组中。系数表示为数字。
  • .zero () : SphericalHarmonics3
      将所有SH系数设置为0。

静态方法(Static Methods)

  • .getBasisAt ( normal : Vector3, shBasis : Array ) : undefined
      normal - 法向量(假定为单位长度)。
      shBasis - 生成的SH基础。
      计算给定法向量的 SH 基础。

2.三角形(Triangle)

一个三角形由三个表示其三个角的Vector3所定义。
构造函数

Triangle( a : Vector3, b : Vector3, c : Vector3 )

a - 三角形的第一个角,默认值是一个在(0, 0, 0)处的Vector3。

b - 三角形的第二个角,默认值是一个在(0, 0, 0)处的Vector3。

c - 三角形的第三个角(最后一个角),默认值是一个在(0, 0, 0)处的Vector3。

创建一个新的Triangle。
属性

  • .a : Vector3
      三角形的第一个角,默认值是一个在(0, 0, 0)处的Vector3。
  • .b : Vector3
      三角形的第二个角,默认值是一个在(0, 0, 0)处的Vector3。
  • .c : Vector3
      三角形的第三个角(最后一个角),默认值是一个在(0, 0, 0)处的Vector3。

方法

  • .clone () : Triangle
      返回一个和该三角形具有相同a、b和c属性的新三角形。
  • .closestPointToPoint ( point : Vector3, target : Vector3 ) : Vector3
      point - Vector3
      target --- 结果将被拷贝到这一Vector3中。
      返回三角形上最靠近所给定的point的点。
  • .containsPoint ( point : Vector3 ) : Boolean
      point - 将被检测的Vector3。
      如果传入的点投影到三角形的平面内,则返回true。
  • .copy ( triangle : Triangle ) : this
      将传入的三角形的a、b和c属性复制给这一三角形。
  • .equals ( triangle : Triangle ) : Boolean
      若这两个三角形具有相同的a、b和c属性,则返回true。
  • .getArea () : Float
      返回三角形的面积。
  • .getBarycoord ( point : Vector3, target : Vector3 ) : Vector3
      point - Vector3
      target --- 结果将会被拷贝到这一Vector3中。
      从给定的向量中返回一个barycentric coordinate(重心坐标)。
      请参阅关于这一概念的相关图片:Picture of barycentric coordinates。
  • .getMidpoint ( target : Vector3 ) : Vector3
      target --- 结果将会被拷贝到这一Vector3中。
      计算三角形的中点。
  • .getNormal ( target : Vector3 ) : Vector3
      target --- 结果将会被拷贝到这一Vector3中。
      计算三角形的法向量(normal vector)。
  • .getPlane ( target : Plane ) : Plane
      target --- 结果将会被拷贝到这一Plane中。
      基于三角形计算出一个平面(plane)。
  • .intersectsBox ( box : Box3 ) : Boolean
      box - 将被用于检测是否与三角形有交集的box。
      判定三角形与传入的box是否相交。
  • .set ( a : Vector3, b : Vector3, c : Vector3 ) : this this : Triangle
      将三角形的a、b和c属性设置为所传入的vector3。
      请注意,此方法仅复制给定对象的值。
  • .setFromAttributeAndIndices ( attribute : BufferAttribute, i0 : Integer, i1 : Integer, i2 : Integer ) : this this : Triangle
      attribute - BufferAttribute of vertex data
      i0 - Integer index
      i1 - Integer index
      i2 - Integer index
      Sets the triangle's vertices from the buffer attribute vertex data.
  • .setFromPointsAndIndices ( points : Array, i0 : Integer, i1 : Integer, i2 : Integer ) : this this : Triangle
      points - Vector3数组(Array)
      i0 - 整数(Integer)索引
      i1 - 整数(Integer)索引
      i2 - 整数(Integer)索引
      设置三角形的向量为数组中的向量。

2.二维向量(Vector2)

表示2D vector(二维向量)的类。 一个二维向量是一对有顺序的数字(标记为x和y),可用来表示很多事物,例如:

一个位于二维空间中的点(例如一个在平面上的点)。

一个在平面上的方向与长度的定义。在three.js中,长度总是从(0, 0)到(x, y)的 Euclidean distance(欧几里德距离,即直线距离), 方向也是从(0, 0)到(x, y)的方向。

任意的、有顺序的一对数字。

其他的一些事物也可以使用二维向量进行表示,比如说动量矢量、复数等等;但以上这些是它在three.js中的常用用途。

对 Vector2 实例进行遍历将按相应的顺序生成它的分量 (x, y)。
构造函数

Vector2( x : Float, y : Float )

x - 向量的x值,默认为0。

y - 向量的y值,默认为0。

创建一个新的Vector2。
属性

  • .height : Float
      y的别名。
  • .isVector2 : Boolean
      Read-only flag to check if a given object is of type Vector2.
  • .width : Float
      x的别名。
  • .x : Float
  • .y : Float

方法

  • .add ( v : Vector2 ) : this
      将传入的向量v和这个向量相加。
  • .addScalar ( s : Float ) : this
      将传入的标量s和这个向量的x值、y值相加。
  • .addScaledVector ( v : Vector2, s : Float ) : this
      将所传入的v与s相乘所得乘积和这个向量相加。
  • .addVectors ( a : Vector2, b : Vector2 ) : this
      将该向量设置为 a + b。
  • .angle () : Float
      计算该向量相对于x轴正方向的弧度角度。
  • .angleTo ( v : Vector2 ) : Float
      以弧度返回该向量与向量v之间的角度。
  • .applyMatrix3 ( m : Matrix3 ) : this
      将该向量乘以三阶矩阵m(第三个值隐式地为1)。
  • .ceil () : this
      向量中的x分量和y分量向上取整为最接近的整数值。
  • .clamp ( min : Vector2, max : Vector2 ) : this
      min - 在限制范围内,x和y的最小值。
      max - 在限制范围内,x和y的最大值。
      如果该向量的x值或y值大于限制范围内最大x值或y值,则该值将会被所对应的值取代。
      如果该向量的x值或y值小于限制范围内最小x值或y值,则该值将会被所对应的值取代。
  • .clampLength ( min : Float, max : Float ) : this
      min - 长度将被限制为的最小值
      max - 长度将被限制为的最大值
      如果向量长度大于最大值,则它将会被最大值所取代。
      如果向量长度小于最小值,则它将会被最小值所取代。
  • .clampScalar ( min : Float, max : Float ) : this
      min - 分量将被限制为的最小值
      max - 分量将被限制为的最大值
      如果该向量的x值或y值大于最大值,则它们将被最大值所取代。
      如果该向量的x值或y值小于最小值,则它们将被最小值所取代。
  • .clone () : Vector2
      返回一个新的Vector2,其具有和当前这个向量相同的x和y。
  • .copy ( v : Vector2 ) : this
      将所传入Vector2的x和y属性复制给这一Vector2。
  • .distanceTo ( v : Vector2 ) : Float
      计算该vector到传入的v的距离。
  • .manhattanDistanceTo ( v : Vector2 ) : Float
      计算该vector到传入的v的曼哈顿距离(Manhattan distance)。
  • .distanceToSquared ( v : Vector2 ) : Float
      计算该向量到传入的v的平方距离。 如果你只是将该距离和另一个距离进行比较,则应当比较的是距离的平方, 因为它的计算效率会更高一些。
  • .divide ( v : Vector2 ) : this
      将该向量除以向量v。
  • .divideScalar ( s : Float ) : this
      将该向量除以标量s。
  • .dot ( v : Vector2 ) : Float
      计算该vector和所传入v的点积(dot product)。
  • .cross ( v : Vector2 ) : Float
      计算该vector和所传入v的叉积(cross product)。 请注意,"叉积"在2D中并没 有被明确定义。该函数计算的是2D图形中经常使用的几何叉积。
  • .equals ( v : Vector2 ) : Boolean
      检查该向量和v的严格相等性。
  • .floor () : this
      向量中的x分量和y分量向下取整为最接近的整数值。
  • .fromArray ( array : Array, offset : Integer ) : this
      array - 来源的数组。
      offset - (可选)在数组中的元素偏移量,默认值为0。
      设置向量中的x值为array[ offset ],y值为array[ offset + 1 ]。
  • .fromBufferAttribute ( attribute : BufferAttribute, index : Integer ) : this
      attribute - 来源的attribute。
      index - 在attribute中的索引。
      从attribute中设置向量的x值和y值。 、
  • .getComponent ( index : Integer ) : Float
      index - 0 或 1
      如果index值为0则返回x值。
      如果index值为1则返回y值。
  • .length () : Float
      计算从(0, 0)到(x, y)的欧几里得长度 (Euclidean length,即直线长度)。
  • .manhattanLength () : Float
      计算该向量的曼哈顿长度(Manhattan length)。
  • .lengthSq () : Float
      计算从(0, 0)到(x, y)的欧几里得长度 (Euclidean length,即直线长度)的平方。 如果你正在比较向量的长度,应当比较的是长度的平方,因为它的计算效率更高一些。
  • .lerp ( v : Vector2, alpha : Float ) : this
      v - 朝着进行插值的Vector2。
      alpha - 插值因数,其范围通常在[0, 1]闭区间。
      在该向量与传入的向量v之间的线性插值,alpha是沿着线的长度的百分比 ------ alpha = 0 时表示的是当前向量,alpha = 1 时表示的是所传入的向量v。
  • .lerpVectors ( v1 : Vector2, v2 : Vector2, alpha : Float ) : this
      v1 - 起始的Vector2。
      v2 - 朝着进行插值的Vector2。
      alpha - 插值因数,其范围通常在[0, 1]闭区间。
      将此向量设置为在v1和v2之间进行线性插值的向量, 其中alpha为两个向量之间连线的长度的百分比 ------ alpha = 0 时表示的是v1,alpha = 1 时表示的是v2。
  • .negate () : this
      向量取反,即: x = -x , y = -y。
  • .normalize () : this
      将该向量转换为单位向量(unit vector), 也就是说,将该向量的方向设置为和原向量相同,但是其长度(length)为1。
  • .max ( v : Vector2 ) : this
      如果该向量的x值或y值小于所传入v的x值或y值,则将该值替换为对应的最大值。
  • .min ( v : Vector2 ) : this
      如果该向量的x值或y值大于所传入v的x值或y值,则将该值替换为对应的最小值。
  • .multiply ( v : Vector2 ) : this
      将该向量与所传入的向量v进行相乘。
  • .multiplyScalar ( s : Float ) : this
      将该向量与所传入的标量s进行相乘。
  • .rotateAround ( center : Vector2, angle : Float ) : this
      center - 将被围绕旋转的点。
      angle - 将要旋转的角度,以弧度来表示。
      将向量围绕着center旋转angle弧度。
  • .round () : this
      向量中的x分量和y分量四舍五入取整为最接近的整数值。
  • .roundToZero () : this
      向量中的分量朝向0取整数(若分量为负数则向上取整,若为正数则向下取整)。
  • .set ( x : Float, y : Float ) : this
      设置该向量的x和y分量。
  • .setComponent ( index : Integer, value : Float ) : this
      index - 0 或 1
      value - Float
      如果index值为0则将x值设置为value。
      如果index值为1则将y值设置为value
  • .setLength ( l : Float ) : this
      将该向量的方向设置为和原向量相同,但是长度(length)为l。
  • .setScalar ( scalar : Float ) : this
      将该向量的x、y值同时设置为等于传入的scalar。
  • .setX ( x : Float ) : this
      将向量中的x值替换为x。
  • .setY ( y : Float ) : this
      将向量中的y值替换为y。
  • .sub ( v : Vector2 ) : this
      从该向量减去向量v。
  • .subScalar ( s : Float ) : this
      从该向量的x和y中减去标量s。
  • .subVectors ( a : Vector2, b : Vector2 ) : this
      将该向量设置为a - b。
  • .toArray ( array : Array, offset : Integer ) : Array
      array - (可选)被用于存储向量的数组。如果这个值没有传入,则将创建一个新的数组。
      offset - (可选) 数组中元素的偏移量。
      返回一个数组[x, y],或者将x和y复制到所传入的array中。
  • .random () : this
      将该向量的每个分量(x、y)设置为介于 0 和 1 之间的伪随机数,不包括 1。

2.三维向量(Vector3)

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

一个位于三维空间中的点。

一个在三维空间中的方向与长度的定义。在three.js中,长度总是从(0, 0, 0)到(x, y, z)的 Euclidean distance(欧几里德距离,即直线距离), 方向也是从(0, 0, 0)到(x, y, z)的方向。

任意的、有顺序的、三个为一组的数字组合。

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

对 Vector3 实例进行遍历将按相应的顺序生成它的分量 (x, y, z)。
构造函数

Vector3( x : Float, y : Float, z : Float )

x - 向量的x值,默认为0。

y - 向量的y值,默认为0。

z - 向量的z值,默认为0。

创建一个新的Vector3。
属性

.isVector3 : Boolean

Read-only flag to check if a given object is of type Vector3.

.x : Float

.y : Float

.z : Float

方法

  • .add ( v : Vector3 ) : this
      将传入的向量v和这个向量相加。
  • .addScalar ( s : Float ) : this
      将传入的标量s和这个向量的x值、y值以及z值相加。
  • .addScaledVector ( v : Vector3, s : Float ) : this
      将所传入的v与s相乘所得的乘积和这个向量相加。
  • .addVectors ( a : Vector3, b : Vector3 ) : this
      将该向量设置为a + b。
  • .applyAxisAngle ( axis : Vector3, angle : Float ) : this
      axis - 一个被归一化的Vector3。
      angle - 以弧度表示的角度。
      将轴和角度所指定的旋转应用到该向量上。
  • .applyEuler ( euler : Euler ) : this
      通过将Euler(欧拉)对象转换为Quaternion(四元数)并应用, 将欧拉变换应用到这一向量上。
  • .applyMatrix3 ( m : Matrix3 ) : this
      将该向量乘以三阶矩阵m。
  • .applyMatrix4 ( m : Matrix4 ) : this
      将该向量乘以四阶矩阵m(第四个维度隐式地为1),并按角度进行划分。
  • .applyNormalMatrix ( m : Matrix3 ) : this
      将该向量乘以正规矩阵 m,并将结果进行归一化。
  • .applyQuaternion ( quaternion : Quaternion ) : this
      将Quaternion变换应用到该向量。
  • .angleTo ( v : Vector3 ) : Float
      以弧度返回该向量与向量v之间的角度。
  • .ceil () : this
      将该向量x分量、 y分量以及z分量向上取整为最接近的整数。
  • .clamp ( min : Vector3, max : Vector3 ) : this
      min - 在限制范围内,x值、y值和z的最小值。
      max - 在限制范围内,x值、y值和z的最大值。
      如果该向量的x值、y值或z值大于限制范围内最大x值、y值或z值,则该值将会被所对应的值取代。
      如果该向量的x值、y值或z值小于限制范围内最小x值、y值或z值,则该值将会被所对应的值取代。
  • .clampLength ( min : Float, max : Float ) : this
      min - 长度将被限制为的最小值
      max - 长度将被限制为的最大值
      如果向量长度大于最大值,则它将会被最大值所取代。
      如果向量长度小于最小值,则它将会被最小值所取代。
  • .clampScalar ( min : Float, max : Float ) : this
      min - 分量将被限制为的最小值
      max - 分量将被限制为的最大值
      如果该向量的x值、y值或z值大于最大值,则它们将被最大值所取代。
      如果该向量的x值、y值或z值小于最小值,则它们将被最小值所取代。
  • .clone () : Vector3
      返回一个新的Vector3,其具有和当前这个向量相同的x、y和z。
  • .copy ( v : Vector3 ) : this
      将所传入Vector3的x、y和z属性复制给这一Vector3。
  • .cross ( v : Vector3 ) : this
      将该向量设置为它本身与传入的v的叉积(cross product)。
  • .crossVectors ( a : Vector3, b : Vector3 ) : this
      将该向量设置为传入的a与b的叉积(cross product)。
  • .distanceTo ( v : Vector3 ) : Float
      计算该向量到所传入的v间的距离。
  • .manhattanDistanceTo ( v : Vector3 ) : Float
      计算该向量到所传入的v之间的曼哈顿距离(Manhattan distance)。
  • .distanceToSquared ( v : Vector3 ) : Float
      计算该向量到传入的v的平方距离。 如果你只是将该距离和另一个距离进行比较,则应当比较的是距离的平方, 因为它的计算效率会更高一些。
  • .divide ( v : Vector3 ) : this
      将该向量除以向量v。
  • .divideScalar ( s : Float ) : this
      将该向量除以标量s。
  • .dot ( v : Vector3 ) : Float
      计算该vector和所传入v的点积(dot product)。
  • .equals ( v : Vector3 ) : 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 ]。
  • .fromBufferAttribute ( attribute : BufferAttribute, index : Integer ) : this
      attribute - 来源的attribute。
      index - 在attribute中的索引。
      从attribute中设置向量的x值、y值和z值。
  • .getComponent ( index : Integer ) : Float
      index - 0, 1 or 2.
      如果index值为0返回x值。
      如果index值为1返回y值。
      如果index值为2返回z值。
  • .length () : Float
      计算从(0, 0, 0) 到 (x, y, z)的欧几里得长度 (Euclidean length,即直线长度)
  • .manhattanLength () : Float
      计算该向量的曼哈顿长度(Manhattan length)。
  • .lengthSq () : Float
      计算从(0, 0, 0)到(x, y, z)的欧几里得长度 (Euclidean length,即直线长度)的平方。 如果你正在比较向量的长度,应当比较的是长度的平方,因为它的计算效率更高一些。
  • .lerp ( v : Vector3, alpha : Float ) : this
      v - 朝着进行插值的Vector3。
      alpha - 插值因数,其范围通常在[0, 1]闭区间。
      在该向量与传入的向量v之间的线性插值,alpha是沿着线的长度的百分比 ------ alpha = 0 时表示的是当前向量,alpha = 1 时表示的是所传入的向量v。
  • .lerpVectors ( v1 : Vector3, v2 : Vector3, alpha : Float ) : this
      v1 - 起始的Vector3。
      v2 - 朝着进行插值的Vector3。
      alpha - 插值因数,其范围通常在[0, 1]闭区间。
      将此向量设置为在v1和v2之间进行线性插值的向量, 其中alpha为两个向量之间连线的长度的百分比 ------ alpha = 0 时表示的是v1,alpha = 1 时表示的是v2。
  • .max ( v : Vector3 ) : this
      如果该向量的x值、y值或z值小于所传入v的x值、y值或z值, 则将该值替换为对应的最大值。
  • .min ( v : Vector3 ) : this
      如果该向量的x值、y值或z值大于所传入v的x值、y值或z值, 则将该值替换为对应的最小值。
  • .multiply ( v : Vector3 ) : this
      将该向量与所传入的向量v进行相乘。
  • .multiplyScalar ( s : Float ) : this
      将该向量与所传入的标量s进行相乘。
  • .multiplyVectors ( a : Vector3, b : Vector3 ) : this
      按照分量顺序,将该向量设置为和a * b相等。
  • .negate () : this
      向量取反,即: x = -x, y = -y , z = -z。
  • .normalize () : this
      将该向量转换为单位向量(unit vector), 也就是说,将该向量的方向设置为和原向量相同,但是其长度(length)为1。
  • .project ( camera : Camera ) : this
      camera --- 在投影中使用的摄像机。
      将此向量(坐标)从世界空间投影到相机的标准化设备坐标 (NDC) 空间。
  • .projectOnPlane ( planeNormal : Vector3 ) : this
      planeNormal - 表示平面法线的向量
      Projects 通过从该向量减去投影到平面法线上的向量,将该向量投影到平面上。
  • .projectOnVector ( v : Vector3 ) : this
      投影(Projects)该向量到向量v上。
  • .reflect ( normal : Vector3 ) : this
      normal - 反射面法线
      将该向量设置为对指定 normal 法线的表面的反射向量。假设法线具有单位长度。
  • .round () : this
      向量中的分量四舍五入取整为最接近的整数值。
  • .roundToZero () : this
      向量中的分量朝向0取整数(若分量为负数则向上取整,若为正数则向下取整)。
  • .set ( x : Float, y : Float, z : Float ) : this
      设置该向量的x、y 和 z 分量。
  • setComponent ( index : Integer, value : Float ) : this
      index - 0、1 或 2。
      value - Float
      若index为 0 则设置 x 值为 value。
      若index为 1 则设置 y 值为 value。
      若index为 2 则设置 z 值为 value。
  • .setFromCylindrical ( c : Cylindrical ) : this
      从圆柱坐标c中设置该向量。
  • .setFromCylindricalCoords ( radius : Float, theta : Float, y : Float ) : this
      从圆柱坐标中的radius、theta和y设置该向量。
  • .setFromEuler ( euler : Euler ) : this
      根据指定的Euler Angle的x、y、z分量来设置该向量的x、y、z分量。
  • .setFromMatrixColumn ( matrix : Matrix4, index : Integer ) : this
      从传入的四阶矩阵matrix由index指定的列中, 设置该向量的x值、y值和z值。
  • .setFromMatrix3Column ( matrix : Matrix3, index : Integer ) : this
      从传入的三阶矩阵 matrix 由 index 指定的列中,设置该向量的 x 值、y 值和 z 值。
  • .setFromMatrixPosition ( m : Matrix4 ) : this
      从变换矩阵(transformation matrix)m中, 设置该向量为其中与位置相关的元素。
  • .setFromMatrixScale ( m : Matrix4 ) : this
      从变换矩阵(transformation matrix)m中, 设置该向量为其中与缩放相关的元素。
  • .setFromSpherical ( s : Spherical ) : this
      从球坐标s中设置该向量。
  • .setFromSphericalCoords ( radius : Float, phi : Float, theta : Float ) : this
      从球坐标中的radius、phi和theta设置该向量。
  • .setLength ( l : Float ) : this
      将该向量的方向设置为和原向量相同,但是长度(length)为l。
  • .setScalar ( scalar : Float ) : this
      将该向量的x、y和z值同时设置为等于传入的scalar。
  • .setX ( x : Float ) : this
      将向量中的x值替换为x。
  • .setY ( y : Float ) : this
      将向量中的y值替换为y。
  • .setZ ( z : Float ) : this
      将向量中的z值替换为z。
  • .sub ( v : Vector3 ) : this
      从该向量减去向量v。
  • .subScalar ( s : Float ) : this
      从该向量的x、y和z中减去标量s。
  • .subVectors ( a : Vector3, b : Vector3 ) : this
      将该向量设置为a - b。
  • .toArray ( array : Array, offset : Integer ) : Array
      array - (可选)被用于存储向量的数组。如果这个值没有传入,则将创建一个新的数组。
      offset - (可选) 数组中元素的偏移量。
      返回一个数组[x, y ,z],或者将x、y和z复制到所传入的array中。
  • .transformDirection ( m : Matrix4 ) : this
      通过传入的矩阵(m的左上角3 x 3子矩阵)变换向量的方向, 并将结果进行normalizes(归一化)。
  • .unproject ( camera : Camera ) : this
      camera --- 在投影中使用的摄像机。
      将此向量(坐标)从相机的标准化设备坐标 (NDC) 空间投影到世界空间。
  • .random () : this
      将该向量的每个分量(x、y、z)设置为介于 0 和 1 之间的伪随机数,不包括 1。

2.四维向量(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中的常用用途。

对 Vector4 实例进行遍历将按相应的顺序生成它的分量 (x, y, z, w)。
构造函数

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

x - 向量的x值,默认为0。

y - 向量的y值,默认为0。

z - 向量的z值,默认为0。

w - 向量的w值,默认为1。

创建一个新的Vector4。
属性

  • .isVector4 : Boolean
    Read-only flag to check if a given object is of type Vector4.
  • .x : Float
  • .y : Float
  • .z : Float
  • .w : Float
    .width : Float
      z的别名。
  • .height : Float
      w的别名。

方法

  • .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。

  • .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值, 则将该值替换为对应的最小值。

  • .multiply ( v : Vector4 ) : this

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

  • .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 : Quaternion ) : this

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

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

  • .setAxisAngleFromRotationMatrix ( m : Matrix4 ) : this

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

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

  • .setComponent ( index : Integer, value : Float ) : this

    index - 0、1、2 或 3。

    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中。

  • .random () : this

    将该向量的每个分量(x、y、z、w)设置为介于 0 和 1 之间的伪随机数,不包括 1。

三、插值

3. 三次插值(CubicInterpolant)

构造函数(Constructor)

CubicInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer )

  1. parameterPositions -- 位置数组
  2. sampleValues -- 样本数组
  3. sampleSize -- 样本数量
  4. resultBuffer -- 用于存储插值结果的缓冲区。

属性(Properties)

  • .parameterPositions : null
  • .resultBuffer : null
  • .sampleValues : null
  • .settings : Object
  • .valueSize : null

方法(Methods)

  • .evaluate ( t : Number ) : Array
      评估位置t处的插值。

3. 离散插值(DiscreteInterpolant)

属性(Properties)

  • .parameterPositions : null
  • .resultBuffer : null
  • .sampleValues : null
  • .settings : Object
  • .valueSize : null

Methods

  • .evaluate ( t : Number ) : Array
    评估位置t处的插值。

3. 线性插值(LinearInterpolant)

属性(Properties)

  • .parameterPositions : null
  • .resultBuffer : null
  • .sampleValues : null
  • .settings : Object
  • .valueSize : null

方法(Methods)

  • .evaluate ( t : Number ) : Array
      评估位置t处的插值。

3. 四元数线性插值(QuaternionLinearInterpolant)

属性(Properties)

  • .parameterPositions : null
  • .resultBuffer : null
  • .sampleValues : null
  • .settings : Object
  • .valueSize : null

方法(Methods)

  • .evaluate ( t : Number ) : Array
      评估位置t处的插值。
相关推荐
WeiXiao_Hyy6 小时前
成为 Top 1% 的工程师
java·开发语言·javascript·经验分享·后端
吃杠碰小鸡6 小时前
高中数学-数列-导数证明
前端·数学·算法
kingwebo'sZone6 小时前
C#使用Aspose.Words把 word转成图片
前端·c#·word
xjt_09016 小时前
基于 Vue 3 构建企业级 Web Components 组件库
前端·javascript·vue.js
我是伪码农6 小时前
Vue 2.3
前端·javascript·vue.js
夜郎king7 小时前
HTML5 SVG 实现日出日落动画与实时天气可视化
前端·html5·svg 日出日落
辰风沐阳7 小时前
JavaScript 的宏任务和微任务
javascript
夏幻灵8 小时前
HTML5里最常用的十大标签
前端·html·html5
冰暮流星8 小时前
javascript之二重循环练习
开发语言·javascript·数据库
Mr Xu_8 小时前
Vue 3 中 watch 的使用详解:监听响应式数据变化的利器
前端·javascript·vue.js