Skip to main content

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

  • default

    Geometry

    ↳↳ Box

    ↳↳ Plane

Table of contents

Constructors

Properties

Accessors

Methods

Constructors

constructor

new Geometry(renderer, attributes?): Geometry

Parameters

NameTypeDescription
rendererRenderer渲染器
attributesAttributes属性信息(顶点数据)

Returns

Geometry

Overrides

Base.constructor

Defined in

src/core/Geometry.ts:65

Properties

renderer

renderer: Renderer

Inherited from

Base.renderer

Defined in

src/core/Base.ts:7


drawRange

drawRange: any

Defined in

src/core/Geometry.ts:53


instancedCount

instancedCount: number

Defined in

src/core/Geometry.ts:55


isInstanced

isInstanced: boolean

Defined in

src/core/Geometry.ts:57


drawMode

drawMode: number

Defined in

src/core/Geometry.ts:59

Accessors

gl

get gl(): WebGLRenderingContext | WebGL2RenderingContext

获取 webgl 实例

Returns

WebGLRenderingContext | WebGL2RenderingContext

Inherited from

Base.gl

Defined in

src/core/Base.ts:16


rendererState

get rendererState(): State

获取渲染状态

Returns

State

Inherited from

Base.rendererState

Defined in

src/core/Base.ts:23


id

get id(): string

获取当前几何体数据的唯一标识

Returns

string

Defined in

src/core/Geometry.ts:105


attributes

get attributes(): Map<string, BufferAttribute>

获取全部的属性信息

Returns

Map<string, BufferAttribute>

Defined in

src/core/Geometry.ts:112


attributesData

get attributesData(): Attributes

获取属性数据

Returns

Attributes

Defined in

src/core/Geometry.ts:119


index

get index(): undefined | BufferAttribute

获取顶点索引属性

Returns

undefined | BufferAttribute

Defined in

src/core/Geometry.ts:136


bounds

get bounds(): any

获取当前几何体的包围盒

Returns

any

Defined in

src/core/Geometry.ts:143

set bounds(bounds): void

手动设置包围盒,一般我们只需要内部计算

Parameters

NameType
boundsany

Returns

void

Defined in

src/core/Geometry.ts:151

Methods

addAttribute

addAttribute(name, attribute): void

添加对应的属性信息(顶点数据)

Parameters

NameType
namestring
attributeBufferAttribute

Returns

void

Defined in

src/core/Geometry.ts:160


getAttribute

getAttribute(name): undefined | BufferAttribute

获取对应的属性信息(顶点数据)

Parameters

NameType
nameany

Returns

undefined | BufferAttribute

Defined in

src/core/Geometry.ts:191


setAttributeData

setAttributeData(name, data): void

设置对应的属性数据

Parameters

NameType
nameany
dataany

Returns

void

Defined in

src/core/Geometry.ts:200


updateAttribute

updateAttribute(attribute): void

更新顶点属性数据

Parameters

NameType
attributeany

Returns

void

Defined in

src/core/Geometry.ts:212


removeAttribute

removeAttribute(attribute): void

移除属性信息

Parameters

NameType
attributeany

Returns

void

Defined in

src/core/Geometry.ts:235


setIndex

setIndex(index): void

设置顶点索引数据

Parameters

NameType
indexany

Returns

void

Defined in

src/core/Geometry.ts:243


setVertices

setVertices(data): void

设置顶点数据

Parameters

NameType
dataany

Returns

void

Defined in

src/core/Geometry.ts:262


setNormals

setNormals(data): void

设置顶点法向量数据

Parameters

NameType
dataany

Returns

void

Defined in

src/core/Geometry.ts:282


setUVs

setUVs(data): void

设置纹理 UV 数据

Parameters

NameType
dataany

Returns

void

Defined in

src/core/Geometry.ts:296


setColors

setColors(colors): void

设置顶点颜色数据

Parameters

NameType
colors(Float32Array | Float64Array | number[] | Vector3 | Vector4)[]

Returns

void

Defined in

src/core/Geometry.ts:310


setDrawRange

setDrawRange(start, count): void

设置顶点渲染的开始索引和数量

Parameters

NameTypeDescription
startnumber开始索引
countnumber数量

Returns

void

Defined in

src/core/Geometry.ts:333


setInstancedCount

setInstancedCount(count): void

设置实例化渲染的数量

Parameters

NameTypeDescription
countnumber数量

Returns

void

Defined in

src/core/Geometry.ts:342


createVAO

createVAO(program): void

创建 Vao

Parameters

NameType
programProgram

Returns

void

Defined in

src/core/Geometry.ts:350


bindAttributes

bindAttributes(program): void

绑定顶点属性数据 https://devdocs.io/dom/webgl2renderingcontext/vertexattribipointer

Parameters

NameType
programProgram

Returns

void

Defined in

src/core/Geometry.ts:363


computeBoundingBox

computeBoundingBox(vertices?): any

计算当前几何体的的矩形边界(立方体包围盒)

Parameters

NameTypeDescription
vertices?number[] | DataType外部传入的顶点数据

Returns

any

Defined in

src/core/Geometry.ts:402


computeBoundingSphere

computeBoundingSphere(vertices?): void

计算当前几何体的的球形边界(球形包围盒)

Parameters

NameTypeDescription
vertices?number[] | DataType外部传入的顶点数据

Returns

void

Defined in

src/core/Geometry.ts:437


draw

draw(program, drawMode?): void

执行绘制

Parameters

NameTypeDescription
programanyProgram 对象
drawModenumber绘制模式

Returns

void

Defined in

src/core/Geometry.ts:458


copy

copy(source): Geometry

将传入的几何体对象的属性值拷贝到此对象

Parameters

NameTypeDescription
sourceGeometry源几何体对象

Returns

Geometry

Defined in

src/core/Geometry.ts:502


clone

clone(): Geometry

克隆此几何体对象

Returns

Geometry

Defined in

src/core/Geometry.ts:540


destroy

destroy(): void

销毁几何体对象

Returns

void

Defined in

src/core/Geometry.ts:549