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场景编辑器

BufferAttribute

这个类用于存储与BufferGeometry相关联的 attribute(例如顶点位置向量,面片索引,法向量,颜色值,UV坐标以及任何自定义 attribute )。 利用 BufferAttribute,可以更高效的向GPU传递数据。详情和例子见该页。

在 BufferAttribute 中,数据被存储为任意长度的矢量(通过itemSize进行定义),下列函数如无特别说明, 函数参数中的index会自动乘以矢量长度进行计算。

构造函数

BufferAttribute( array : TypedArray, itemSize : Integer, normalized : Boolean )

array -- 必须是 TypedArray. 类型,用于实例化缓存。
该队列应该包含: itemSize * numVertices 个元素,numVertices 是 BufferGeometry中的顶点数目

itemSize -- 队列中与顶点相关的数据值的大小。举例,如果 attribute 存储的是三元组(例如顶点空间坐标、法向量或颜色值)则itemSize的值应该是3。

normalized -- (可选) 指明缓存中的数据如何与GLSL代码中的数据对应。例如,如果array是 UInt16Array类型,且normalized的值是 true,则队列中的值将会从 0 - +65535 映射为 GLSL 中的 0.0f - +1.0f。 如果array是 Int16Array (有符号),则值将会从 -32767 - +32767 映射为 -1.0f - +1.0f。若 normalized 的值为 false,则数据映射不会归一化,而会直接映射为 float 值,例如,32767 将会映射为 32767.0f.

属性

# .array : TypedArray

在 array 中保存着缓存中的数据。

# .count : Integer

保存 array 除以 itemSize 之后的大小。

若缓存存储三元组(例如顶点位置、法向量、颜色值),则该值应等于队列中三元组的个数。

# .dynamic : Boolean

不论缓存是否是动态的,默认值都将是 false
如果该值为 false,即告知 GPU 缓存中的数据会经常使用但不经常变化。 该值与 gl.STATIC_DRAW 标志位相一致。
如果该值为 true,即告知 GPU 缓存中的数据会经常使用且经常变化。 该值与 gl.DYNAMIC_DRAW 标志位相一致。

# .isBufferAttribute : Boolean

指示当前类或派生类是 BufferAttributes. 默认值为 true.

开发者不应当改变该值,该值用于内部实现优化。

# .itemSize : Integer

保存在 array 中矢量的长度。

# .name : String

该 attribute 实例的别名,默认值为空字符串。

# .needsUpdate : Boolean

该标志位指明当前 attribute 已经被修改过,且需要再次送入 GPU 处理。当开发者改变了该队列的值,则标志位需要设置为 true。

将标志位设为 true 同样会增加 version 的值。

# .normalized : Boolean

指明缓存中数据在转化为GLSL着色器代码中数据时是否需要被归一化。详见构造函数中的说明。

# .onUploadCallback : Function

attribute 数据传输到GPU后的回调函数。

# .updateRange : Object

对象包含如下成员:
offset: 默认值为 0。 指明更新的起始位置。
count: 默认值为 -1,表示不指定更新范围。

该值只可以被用于更新某些矢量数据(例如,颜色相关数据)。

# .version : Integer

版本号,当 needsUpdate 被设置为 true 时,该值会自增。

方法

# .clone () : BufferAttribute

返回该 BufferAttribute 的拷贝。

# .copyArray ( array ) : BufferAttribute

将参数中所给定的普通队列或 TypedArray 拷贝到 array 中。

拷贝 TypedArray 相关注意事项详见 TypedArray.set

# .copyAt ( index1 : Integer, bufferAttribute : BufferAttribute, index2 : Integer ) : null

将一个矢量从 bufferAttribute[index2] 拷贝到 array[index1] 中。

# .copyColorsArray ( colors : Array ) : BufferAttribute

将一个存储 RGB 颜色值的队列拷贝到 array 中。

# .copyVector2sArray ( vectors : Array ) : BufferAttribute

将一个存储 Vector2 的队列拷贝到 array 中。

# .copyVector3sArray ( vectors : Array ) : BufferAttribute

将一个存储 Vector3 的队列拷贝到 array 中。

# .copyVector4sArray ( vectors : Array ) : BufferAttribute

将一个存储 Vector4 的队列拷贝到 array 中。

# .getX ( index : Integer ) : Number

获取给定索引的矢量的第一维元素 (即 X 值)。

# .getY ( index : Integer ) : Number

获取给定索引的矢量的第二维元素 (即 Y 值)。

# .getZ ( index : Integer ) : Number

获取给定索引的矢量的第三维元素 (即 Z 值)。

# .getW ( index : Integer ) : Number

获取给定索引的矢量的第四维元素 (即 W 值)。

# .onUpload ( callback : Function ) : null

见 onUploadCallback 属性。

WebGL / Buffergeometry 中,该方在缓存数据传递给 GPU 后,用于释放内存。

# .set ( value : Array, offset : Integer ) : BufferAttribute

value -- 被拷贝的 Array 或 TypedArray 类型的数据。
offset -- (可选) array 中开始拷贝的位置索引。

对 array,调用 TypedArray.set( value, offset ) 方法。

特别的, 对将 value 转为 TypedArray 的要求详见上述链接。

# .setArray ( array : TypedArray ) : BufferAttribute

array 被赋值的 TypedArray 队列。

队列被复制后,needsUpdate 应当被设置为 true。

# .setDynamic ( value : Boolean ) : BufferAttribute

将 dynamic 设置为 value.

# .setX ( index : Integer, x : Float ) : BufferAttribute

设置给定索引的矢量的第一维数据(设置 X 值)。

# .setY ( index : Integer, y : Float ) : BufferAttribute

设置给定索引的矢量的第二维数据(设置 Y 值)。

# .setZ ( index : Integer, z : Float ) : BufferAttribute

设置给定索引的矢量的第三维数据(设置 Z 值)。

# .setW ( index : Integer, w : Float ) : BufferAttribute

设置给定索引的矢量的第四维数据(设置 W 值)。

# .setXY ( index : Integer, x : Float, y : Float ) : BufferAttribute

设置给定索引的矢量的第一、二维数据(设置 X 和 Y 值)。

# .setXYZ ( index : Integer, x : Float, y : Float, z : Float ) : BufferAttribute

设置给定索引的矢量的第一、二、三维数据(设置 X、Y 和 Z 值)。

# .setXYZW ( index : Integer, x : Float, y : Float, z : Float, w : Float ) : BufferAttribute

设置给定索引的矢量的第一、二、三、四维数据(设置 X、Y、Z 和 W 值)。

源代码

src/core/BufferAttribute.js