当前位置: 首页 > news >正文

three.js BufferAttribute

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 之后的大小。

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

.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,表示不指定更新范围。

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

.usage : Usage

Defines the intended usage pattern of the data store for optimization purposes. Corresponds to the usage parameter of WebGLRenderingContext.bufferData(). Default is THREE.StaticDrawUsage.

.version : Integer

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

方法

.applyMatrix3 ( m : Matrix3 ) : this

Applies matrix m to every Vector3 element of this BufferAttribute.

.applyMatrix4 ( m : Matrix4 ) : this

Applies matrix m to every Vector3 element of this BufferAttribute.

.applyNormalMatrix ( m : Matrix3 ) : this

Applies normal matrix m to every Vector3 element of this BufferAttribute.

.transformDirection ( m : Matrix4 ) : this

Applies matrix m to every Vector3 element of this BufferAttribute, interpreting the elements as a direction vectors.

.clone () : BufferAttribute

返回该 BufferAttribute 的拷贝。

.copyArray ( array ) : BufferAttribute

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

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

.copyAt ( index1 : Integer, bufferAttribute : BufferAttribute, index2 : Integer ) : this

将一个矢量从 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 ) : this

见 onUploadCallback 属性。

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

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

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

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

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

.setUsage ( value : Usage ) : BufferAttribute

Set usage to 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 值)。


http://www.mrgr.cn/news/35991.html

相关文章:

  • 计算机网络(九) —— Tcp协议详解
  • python-比较月亮大小/数组下标/人见人爱a+b
  • Webpack 5的新特性:Asset Modules与Dynamic Import
  • Linux快速安装ClickHouse(附官方文档)
  • 【QT 5 调试软件+Linux下调用脚本shell-无法调度+目录拼写+无法找目录+sudo权限(2)+问题解决方式+后续补充】
  • Java中的位图和布隆过滤器(如果想知道Java中有关位图和布隆过滤器的知识点,那么只看这一篇就足够了!)
  • android11 自动授权访问sdcard
  • ChatGPT 向更多用户推出高级语音模式:支持 50 种语言;字节发布两款新视频生成大模型丨 RTE 开发者日报
  • 多城联动、多形式开展网安周公益活动,开源网安传播网络安全知识
  • 解锁视频生成新时代! 探索智谱CogVideoX-2b:轻松生成6秒视频的详细指南
  • 自适应查询优化(Adaptive Query Optimization, AQO)技术简介
  • Circular dependency between the following tasks(gradle循环依赖的问题)
  • 828华为云征文|华为云Flexus云服务器X实例之openEuler系统下部署经典扫雷小游戏
  • easyExcel导出包括相同列id相同合并单元格,明细导出
  • Python项目Flask框架整合Redis
  • python中SortedList类的用法详解
  • VMware提供虚拟硬盘并使得Oracle Linux集群共享块设备并绑定raw设备。
  • Word 制作会议名牌教程
  • JavaScript 算数运算符
  • C++之 string(中)