Class: Geometry
几何体对象,包含了顶点位置,面片索引、法向量、颜色值、UV 坐标和自定义缓存属性值等,这些数据最终会上传到GPU
中。
示例代码:
const geometry = new ve.Geometry(renderer, {
position: {
size: 3,
data: new Float32Array([
-0.5, 0.5, 0,
-0.5, -0.5, 0,
0.5, 0.5, 0,
0.5, -0.5, 0
])
},
uv: {
size: 2,
data: new Float32Array([0, 1, 1, 1, 0, 0, 1, 0])
},
index: {
data: new Uint16Array([0, 1, 2, 1, 3, 2])
},
});
Hierarchy
Table of contents
Constructors
Properties
Accessors
Methods
- addAttribute
- getAttribute
- setAttributeData
- updateAttribute
- removeAttribute
- setIndex
- setVertices
- setNormals
- setUVs
- setColors
- setDrawRange
- setInstancedCount
- createVAO
- bindAttributes
- computeBoundingBox
- computeBoundingSphere
- draw
- copy
- clone
- destroy
Constructors
constructor
• new Geometry(renderer
, attributes?
): Geometry
Parameters
Name | Type | Description |
---|---|---|
renderer | Renderer | 渲染器 |
attributes | Attributes | 属性信息(顶点数据) |
Returns
Overrides
Base.constructor
Defined in
Properties
renderer
• renderer: Renderer
Inherited from
Base.renderer
Defined in
drawRange
• drawRange: any
Defined in
instancedCount
• instancedCount: number
Defined in
isInstanced
• isInstanced: boolean
Defined in
drawMode
• drawMode: number
Defined in
Accessors
gl
• get
gl(): WebGLRenderingContext
| WebGL2RenderingContext
获取 webgl
实例
Returns
WebGLRenderingContext
| WebGL2RenderingContext
Inherited from
Base.gl
Defined in
rendererState
• get
rendererState(): State
获取渲染状态
Returns
Inherited from
Base.rendererState
Defined in
id
• get
id(): string
获取当前几何体数据的唯一标识
Returns
string
Defined in
attributes
• get
attributes(): Map
<string
, BufferAttribute
>
获取全部的属性信息
Returns
Map
<string
, BufferAttribute
>
Defined in
attributesData
• get
attributesData(): Attributes
获取属性数据
Returns
Defined in
index
• get
index(): undefined
| BufferAttribute
获取顶点索引属性
Returns
undefined
| BufferAttribute
Defined in
bounds
• get
bounds(): any
获取当前几何体的包围盒
Returns
any
Defined in
• set
bounds(bounds
): void
手动设置包围盒,一般我们只需要内部计算
Parameters
Name | Type |
---|---|
bounds | any |
Returns
void
Defined in
Methods
addAttribute
▸ addAttribute(name
, attribute
): void
添加对应的属性信息(顶点数据)
Parameters
Name | Type |
---|---|
name | string |
attribute | BufferAttribute |
Returns
void
Defined in
getAttribute
▸ getAttribute(name
): undefined
| BufferAttribute
获取对应的属性信息(顶点数据)
Parameters
Name | Type |
---|---|
name | any |
Returns
undefined
| BufferAttribute
Defined in
setAttributeData
▸ setAttributeData(name
, data
): void
设置对应的属性数据
Parameters
Name | Type |
---|---|
name | any |
data | any |
Returns
void
Defined in
updateAttribute
▸ updateAttribute(attribute
): void
更新顶点属性数据
Parameters
Name | Type |
---|---|
attribute | any |
Returns
void
Defined in
removeAttribute
▸ removeAttribute(attribute
): void
移除属性信息
Parameters
Name | Type |
---|---|
attribute | any |
Returns
void
Defined in
setIndex
▸ setIndex(index
): void
设置顶点索引数据
Parameters
Name | Type |
---|---|
index | any |
Returns
void
Defined in
setVertices
▸ setVertices(data
): void
设置顶点数据
Parameters
Name | Type |
---|---|
data | any |
Returns
void
Defined in
setNormals
▸ setNormals(data
): void
设置顶点法向量数据
Parameters
Name | Type |
---|---|
data | any |
Returns
void
Defined in
setUVs
▸ setUVs(data
): void
设置纹理 UV 数据
Parameters
Name | Type |
---|---|
data | any |
Returns
void
Defined in
setColors
▸ setColors(colors
): void
设置顶点颜色数据
Parameters
Name | Type |
---|---|
colors | (Float32Array | Float64Array | number [] | Vector3 | Vector4 )[] |
Returns
void
Defined in
setDrawRange
▸ setDrawRange(start
, count
): void
设置顶点渲染的开始索引和数量
Parameters
Name | Type | Description |
---|---|---|
start | number | 开始索引 |
count | number | 数量 |
Returns
void
Defined in
setInstancedCount
▸ setInstancedCount(count
): void
设置实例化渲染的数量
Parameters
Name | Type | Description |
---|---|---|
count | number | 数量 |
Returns
void
Defined in
createVAO
▸ createVAO(program
): void
创建 Vao
Parameters
Name | Type |
---|---|
program | Program |
Returns
void
Defined in
bindAttributes
▸ bindAttributes(program
): void
绑定顶点属性数据 https://devdocs.io/dom/webgl2renderingcontext/vertexattribipointer
Parameters
Name | Type |
---|---|
program | Program |
Returns
void
Defined in
computeBoundingBox
▸ computeBoundingBox(vertices?
): any
计算当前几何体的的矩形边界(立方体包围盒)
Parameters
Name | Type | Description |
---|---|---|
vertices? | number [] | DataType | 外部传入的顶点数据 |
Returns
any
Defined in
computeBoundingSphere
▸ computeBoundingSphere(vertices?
): void
计算当前几何体的的球形边界(球形包围盒)
Parameters
Name | Type | Description |
---|---|---|
vertices? | number [] | DataType | 外部传入的顶点数据 |
Returns
void
Defined in
draw
▸ draw(program
, drawMode?
): void
执行绘制
Parameters
Name | Type | Description |
---|---|---|
program | any | Program 对象 |
drawMode | number | 绘制模式 |
Returns
void
Defined in
copy
▸ copy(source
): Geometry
将传入的几何体对象的属性值拷贝到此对象
Parameters
Name | Type | Description |
---|---|---|
source | Geometry | 源几何体对象 |
Returns
Defined in
clone
▸ clone(): Geometry
克隆此几何体对象
Returns
Defined in
destroy
▸ destroy(): void
销毁几何体对象
Returns
void