Used to create a Geometry from given parameters like instances count or geometry attributes (vertices, uvs, normals).
Holds all attributes arrays, bounding box and create as WGSL code snippet for the vertex shader input attributes.

During the render, the Geometry is responsible for setting the vertexBuffers and drawing the vertices.

Example

const vertices = new Float32Array([
// first triangle
1, 1, 0,
1, -1, 0,
-1, -1, 0,

// second triangle
1, 1, 0,
-1, -1, 0,
-1, 1, 0
])

// create a quad geometry made of 2 triangles
const geometry = new Geometry()

geometry.setAttribute({
name: 'position',
type: 'vec3f',
bufferFormat: 'float32x3',
size: 3,
bufferLength: vertices.length,
array: vertices,
})

Hierarchy (view full)

Constructors

Properties

verticesCount: number

Number of vertices defined by this geometry

verticesOrder: GPUFrontFace

Vertices order to be drawn by the render pipeline

topology: GPUPrimitiveTopology

Topology to use with this Geometry, i.e. whether to draw triangles or points

instancesCount: number

Number of instances of this geometry to draw

vertexBuffers: VertexBuffer[]

Array of vertex buffers to use with this geometry

Options used to create this geometry

type: string

The type of the geometry

uuid: string

The universal unique id of the geometry

boundingBox: Box3

The bounding box of the geometry, i.e. two Vec3 defining the min and max positions to wrap this geometry in a cube

wgslStructFragment: string

A string to append to our shaders code describing the WGSL structure representing this geometry attributes

layoutCacheKey: string

A string representing the vertexBuffers layout, used for pipelines caching

consumers: Set<string>

A Set to store this Geometry consumers (Mesh uuid)

ready: boolean

Whether this geometry is ready to be drawn, i.e. it has been computed and all its vertex buffers have been created

Accessors

  • get shouldCompute(): boolean
  • Get whether this Geometry is ready to compute, i.e. if its first vertex buffer array has not been created yet

    Returns boolean

Methods

  • Compute a Geometry, which means iterate through all vertex buffers and create the attributes array that will be sent as buffers. Also compute the Geometry bounding box.

    Returns void

  • Set our render pass geometry vertex buffers

    Parameters

    • pass: GPURenderPassEncoder

      current render pass

    Returns void

  • Set our vertex buffers then draw the geometry

    Parameters

    • pass: GPURenderPassEncoder

      current render pass

    Returns void