Three.js学习笔记-Core(核心)

BufferAttribute

存储和BufferGeometry相关的属性(如定点位置,面部索引,法线,颜色和UV,自定义属性)
构造函数
BufferAttribute( array : TypedArray, itemSize : Integer, normalized : Boolean )
array: 实例化缓冲区
itemSize: 数组中关联特殊顶点的值
normalized: 可选的,规格化数据
特性
- array/itemSize/name/normalized
- count: Integer 存储的数组长度除以itemSize
- needsUpdate: Boolean 修改了数组中的值需要设为true
- onUploadCallback: Function
- updateRange: Object offset默认0,起始的更新的位置;count默认-1,不使用updateRange
- version: Integer 版本
方法
- clone(): BufferAttribute
- copyArray(array): BufferAttribute
- copyAt ( index1 : Integer, bufferAttribute : BufferAttribute, index2 : Integer ) : null 从bufferAttribute[index2]复制到array[index1]
- copyColorsArray(colors): BufferAttribute
- copyVector2/3/4sArray(vactors): BufferAttribute
- getX/Y/Z/W(index): Number
- onUpload(callback: Function): null
- set(value: Array,offset: Integer) offset可选的而开始复制的位置
- setArray(array: TypedArray) 设定后需要needsUpdate为true
- setDynamic(value: Boolean) 设定动态的值
- setX/Y/Z/W/XY/XYZ/XYZW(index,[x,y,z,w])

BufferGeometry

网格,线或点几何的有效表示。包括缓冲区内的顶点位置,面索引,法线,颜色,UV和自定义属性,从而降低将所有这些数据传递到GPU的成本
访问属性
需要用getAttribute来访问
position/normal/color(itemSize:3),由formFeometry()来设置
构造函数
BufferFeometry()
特性
- attributes: Object
- boundingBox/Sphere: Box3 默认null
- drawRange: Object 不能直接设置,而是使用setDrawRange
- groups: Array 其中的每一个将在单独的WebGL中呈现
- id: Integer /index: BufferAttribute/isBufferFeometry: Boolean/name
- userData/uuid
- morphAttributes: Object
方法
- EventDispatcher 方法可用
- addAttribute(name,value)/applyMatrix(matrix)/center()/clone()/copy(bufferGeometry)
- addGroup(staart,count,matrixIndex)/clearGroups()
- computeBoundingBox () /computeBoundingSphere ()/computeVertexNormals ()
- dispose()
- getAttribute(name)/getIndex()/lookAt(vector)/rotateX/Y/Z(radians)/scale(x,y,z)
- setIndex(index)/setDrawRange(start,count)
- translate(x,y,z)

Clock

它可用就用preformance.now(),否则用不太准确的Date.now()
构造函数
Clock(autoStart: Boolean) 默认true
特性
- autoStart/startTime/oldTime/running: Boolean/elapsedTime 时钟运行总时间
方法
- start()/stop()/getElapsedTime()/getDelta()

DirectGeometry

内部用作将Geometry转换BufferGeometry

EventDispatcher

自定义事件 github-EventDispatcher
构造函数
EventDispatcher()
方法
- add/has/removeEventListener(sype,linstener)
- dispatchEvent(event)

Face3

用在Geometry中。为所有的标准几何体自动创建,当你需要自定义几何体的时候需要手动创建
构造函数
Face3( a : Integer, b : Integer, c : Integer, normal : Vector3, color : Color, materialIndex : Integer )

Geometry

存储特性(定点,位置,面,颜色等)
构造函数
Geometry()
特性
- boundingBox/boundingSphere/name/uuid
- colors: Array 匹配数量和顶点序
- faces: Array
- faceVertexUvs :Array 面上的UV层
- id/isGeometry/morphTargets: Array/morphNormasl: Array
- lineDistances: array 定点之间的距离在线性几何体
- skinWeight: Array 作用在SkinnerMesh
- skinIndices: Array
- vertices: Array
- vertices/element/uvs/normals/colors/groups/lineDistancesNeedUpdate: Boolean 只要数组内容发生变化就需要设为true
方法
- EventDispatcher方法可用
- applyMatrix(matrix4)/center()/clone()/copy(geometry)/dispose()/lookAt(v3)
- computeBoundingBox/Sphere()
- computeFace/Morph/VertexNormals()
- fromBufferGeometry(geometry) 将缓冲几何转换成几何体
- merg(geometry,matrix4,materialIndexOfffset)/mergMesh(mesh)/mergVertices()
- normalize()
- rotateX/Y/Z(radians)
- scale/translate(x,y,z)/toJSON()
- setFromPoints(points: Array)
- sortFacesByMaterialIndex ( )

相对应各个类的实例,

InstancedBufferAttribute

InstancedBufferGeometry

InstancedInterleavedBuffer

InterleavedBuffer

意味着可能具有不同类型的多个属性(例如,位置,法线,紫外线,颜色)被打包到单个阵列缓冲器中

InterleavedBufferAttribute

Layers

默认所有的Object3D都是0层,总共32层,层数0~31 控制可见性
构造函数
Layers()
特性
- mask:Integer 存储此层对象属于32层的哪一层
方法
- disable/enable/set/test/toggle(layer: Integer)

Object3D

大多数对象的基类
构造函数
Object3D()
特性
- castShadow: Boolean 投射阴影,默认false
- children: Object3D 数组表示对象的子类
- id: Integer 只读,对象实例的唯一数字
- isObject3D: Boolean
- layers: Layers 只有该物体至少有一层与正在使用的照相机相同,该物体才是可见的
- matrix: Matrix4 本地变换矩阵
- matrixAutoUpdate: Boolean 默认true
- matrixWorld: Matrix4 全局的变换矩阵,没有父对象则和本地转换一样
- matrixWorldNeedsUpdate: Boolean 默认false。设置此项后,它将计算该帧中的matrixWorld并将此属性重置为false
- name: String 默认null,可选的对象的名
- normalMatrix: Matrix3 传递给着色器来计算对象上的灯光
- onAfterRender: Function 可选的渲染对象后的回调函数,参数 renderer, scene, camera, geometry, material, group.
- onBeforeRender: Function
- parent: Object3D
- position: Vector3 对象的本地位置,默认(0,0,0)
- quaternion: Quaternion 对象的本地旋转(四元数)
- receiveShadow: Boolean 默认false,材料是否接收阴影
- renderOrder: Number 默认0,呈现从低到高的方式
- rotation: Eular 对象本地旋转(欧拉角,弧度)
- scale: Vector3 默认(1,1,1) 缩放
- up: Vector3 默认(0,1,0),LookAt()用它来确定结果的方向
- userData: Object 存储用户自定义数据的对象
- uuid: String 自动分配的不可编辑
- visible: Boolean 默认true
静态特性
- DefaultUp: Vector3 默认(0,1,0),用作直射光,聚光灯的默认位置
- DefaultMatrixAutoUpdate: Vector3 新创建的Object3D对象默认设置matrixAutoUpdate

方法
- EventDispatcher() 在这个类上可用
- add(object: Object3D…) 给添加子对象,对象对多只能有一个父对象
- applyMatrix(matrix: Mateix4): null 更新位置,旋转和缩放
- applyQuaternion(quaternion: Quaternion) 更新旋转
- clone(recursive: Boolean) 默认true,对象的后代也被克隆
- copy(object: Object3D,recursive: Boolean): this 复制对象到当前对象
- getObjectById(id: Integer): Object3D
- getObjectByName(name: String): Object3D
- getObjectByProperty(name: string,value: Float) : Object3D 搜索对象的子类,返回第一个匹配的值
- getWorldposition(target: Vector3): Vector3
- getWorldQuaternion(target: Quaternion): Quaternion
- getWorldScale(target: Vector3): Vector3
- getWorldDirection(target: Vector3): Vector3
- localToWorld(vector: Vector3): Vector3 转换本地坐标到世界坐标
- lootAt(vector: Vector3): null
- lookAt(x: Float,y: Float,z: Float): null
- raycast(raycast: Raycast, intersects: Array): Array 获取投射线和对象之间的交集
- remove(object: object3D…): null 移除任意数量的子对象
- rotateOnAxis(axis: Vector3,angle: Float): this
- rotateOnWorldAxis(axis: Vector3,angle: Float): this
- rotateX/Y/Z(rad: Float): this 旋转轴是x/y/z轴,旋转rad弧度
- setRotationFromAxisAngle(axis: Vector3,angle: Float): null
- setRotationFromEular(eular: Eular): null
- setRotationFromMatrix ( m : Matrix4 ) : null
- setRotationFromQuaternion ( q : Quaternion ) : null
- toJSON(q: Quaternion): null
- translateOnAxis ( axis : Vector3, distance : Float ) : this
- translateX/Y/Z ( distance : Float ) : this
- traverse ( callback : Function ) : null 遍历,对象和后代均执行回调
- traverseVisible ( callback : Function ) : null 只针对可见的对象
- traverseAncestors ( callback : Function ) : null 对所有祖先执行回调
- updateMatrix () : null 更新本地的变换
- updateMatrixWorld ( force : Boolean ) : null 更新对象和子类的世界变换
- worldToLocal ( vector : Vector3 ) : Vector3 世界坐标转换本地坐标

Raycaster

一般用在鼠标选择事件等
构造函数
Raycaster( origin : Vector3, direction : Vector3, near : Float, far : Float )
特性
- far
- linePrecision: Float 与直线物体相交时的精度因子
- near: Float
- params: Object 可选特效{Mesh:{},Line:{},LOD:{},Points:{threshold: 1},Sprite:{}}
- ray: Ray 用在光线投射
方法
- set(origin: Vector3,direction: Vector3)
- setFormCamera(coords : Vector2, camera : Camera)
- intersectObject ( object, recursive : Boolean, optionalTarget : Array ): Array recursive 默认false,设置为true则检查所有后代
- intersectObject ( objects: Array, recursive : Boolean, optionalTarget : Array )

Uniform

全局GLSL变量,被传递给着色器程序

猜你喜欢

转载自blog.csdn.net/u013270347/article/details/81117956