MeshAttribute

View source

Represents a mesh-attribute value describing its name and vertex layout.

Examples

import { GlDataType, MeshAttribute } from '@wimaengine/render-core'
import { AttributeMap } from '@wimaengine/render-webgl'

const attributes = new AttributeMap()
attributes.set('weights', new MeshAttribute('weights', 9, GlDataType.Float, 1))

Constructor


constructor(name: string, location: number, type: number, size: number)

View source

Creates a mesh-attribute descriptor from its name and vertex layout.

The supplied location is stored as MeshAttribute#id; all four values are stored directly without validation or normalization.

Parameters

NameDescriptionDefault
name

Mesh and shader attribute name.

—
location

Numeric vertex-attribute location.

—
type

WebGL scalar type for each component.

—
size

Number of components per vertex.

—

Properties


readonlyname: string

View source

Name used to match this descriptor with a named mesh attribute and shader input.

Default: ''

readonlyid: number

View source

Numeric location assigned to this vertex attribute.

Default: 0

readonlysize: number

View source

Number of components in each vertex attribute.

Default: 0

staticPosition2D: MeshAttribute

View source

Built-in 2D position descriptor: position2d, location 0, float type, and two components per vertex.

Default: ...

staticPosition3D: MeshAttribute

View source

Built-in 3D position descriptor: position3d, location 1, float type, and three components per vertex.

Default: ...

staticUV: MeshAttribute

View source

Built-in UV descriptor: uv, location 2, float type, and two components per vertex.

Default: ...

staticUVB: MeshAttribute

View source

Built-in secondary UV descriptor: uvb, location 3, float type, and two components per vertex.

Default: ...

staticNormal2D: MeshAttribute

View source

Built-in 2D normal descriptor: normal2d, location 4, float type, and two components per vertex.

Default: ...

staticNormal3D: MeshAttribute

View source

Built-in 3D normal descriptor: normal3d, location 5, float type, and three components per vertex.

Default: ...

staticTangent2D: MeshAttribute

View source

Built-in 2D tangent descriptor: tangent2d, location 6, float type, and two components per vertex.

Default: ...

staticTangent3D: MeshAttribute

View source

Built-in 3D tangent descriptor: tangent3d, location 7, float type, and three components per vertex.

Default: ...

staticColor: MeshAttribute

View source

Built-in color descriptor: color, location 8, float type, and four components per vertex.

Default: ...

Methods


staticserialize(value: MeshAttribute): MeshAttributeSerial

View source

Converts a descriptor to its plain serialized representation.

The returned object contains name, id, type, and size copied from the descriptor. Serialization creates a new object and does not mutate the descriptor.

Parameters

NameDescriptionDefault
value

Descriptor to serialize.

—

Returns

Plain descriptor data.

staticdeserialize(value: MeshAttributeSerial, out?: MeshAttribute): MeshAttribute

View source

Restores descriptor fields from plain serialized data.

When out is supplied, this method writes all four fields into that same descriptor and returns it. Without out, it creates a zero-value descriptor first and then populates it. The input is assumed to have the serialized shape; this method does not call MeshAttribute.validateSerial or perform validation itself.

Parameters

NameDescriptionDefault
value

Serialized descriptor data.

—
out?

Descriptor to populate in place.

...

Returns

The populated descriptor.

staticvalidateSerial(value: unknown): value is MeshAttributeSerial

View source

Checks whether a value has the serialized descriptor shape.

The check requires name, id, type, and size properties with types string, number, number, and number. It does not require finite numbers, check that type is one of GlDataType, enforce layout ranges, or construct a MeshAttribute.

Parameters

NameDescriptionDefault
value

Value to check.

—

Returns

Whether the value has the accepted shape.