import Ray from './math/Ray'; import { Vec3Array } from './glmatrix/common'; import type Camera from './Camera'; import type Renderable from './Renderable'; import type BoundingBox from './math/BoundingBox'; import type { Intersection } from './picking/rayPicking'; import { AttributeSemantic } from './Shader'; export type AttributeType = 'byte' | 'ubyte' | 'short' | 'ushort' | 'float' | 'int'; export type AttributeSize = 1 | 2 | 3 | 4; export type AttributeValue = { [key: number]: number; readonly length: number; }; type AttributeNumberGetter = (idx: number) => number; type AttributeArrayGetter = (idx: number, out?: number[]) => number[]; type AttributeNumberSetter = (idx: number, value: number) => number; type AttributeArraySetter = (idx: number, value: number[]) => number[]; /** * GeometryBase attribute */ export declare class GeometryAttribute { /** * Attribute name * @type {string} */ readonly name: string; /** * Attribute type * Possible values: * + `'byte'` * + `'ubyte'` * + `'short'` * + `'ushort'` * + `'float'` Most commonly used. * @type {string} */ readonly type: AttributeType; /** * Size of attribute component. 1 - 4. * @type {number} */ readonly size: TSize; /** * Semantic of this attribute. * Possible values: * + `'POSITION'` * + `'NORMAL'` * + `'BINORMAL'` * + `'TANGENT'` * + `'TEXCOORD'` * + `'TEXCOORD_0'` * + `'TEXCOORD_1'` * + `'COLOR'` * + `'JOINT'` * + `'WEIGHT'` * * In shader, attribute with same semantic will be automatically mapped. For example: * ```glsl * attribute vec3 pos: POSITION * ``` * will use the attribute value with semantic POSITION in geometry, no matter what name it used. */ semantic?: AttributeSemantic; /** * Value of the attribute. */ value?: AttributeValue; get: TSize extends 1 ? AttributeNumberGetter : AttributeArrayGetter; set: TSize extends 1 ? AttributeNumberSetter : AttributeArraySetter; copy: (source: number, target: number) => void; constructor(name: string, type: AttributeType, size: TSize, semantic?: AttributeSemantic); /** * Initialize attribute with given vertex count * @param {number} nVertex */ init(nVertex: number): void; /** * Initialize attribute with given array. Which can be 1 dimensional or 2 dimensional * @param {Array} array * @example * geometry.getAttribute('position').fromArray( * [-1, 0, 0, 1, 0, 0, 0, 1, 0] * ); * geometry.getAttribute('position').fromArray( * [ [-1, 0, 0], [1, 0, 0], [0, 1, 0] ] * ); */ fromArray(array: ArrayLike | number[][]): void; clone(copyValue?: boolean): GeometryAttribute; } export interface GeometryBaseOpts { name: string; /** * Indices of geometry. */ indices?: Uint16Array | Uint32Array; /** * Is vertices data dynamically updated. * Attributes value can't be changed after first render if dyanmic is false. */ dynamic: boolean; } interface GeometryBase extends GeometryBaseOpts { } declare class GeometryBase { readonly uid: number; boundingBox?: BoundingBox; /** * Attributes of geometry. */ attributes: Record>; /** * Main attribute will be used to count vertex number * @type {string} */ mainAttribute: string; /** * User defined picking algorithm instead of default * triangle ray intersection * x, y are NDC. * ```typescript * (x, y, renderer, camera, renderable, out) => boolean * ``` * @type {?Function} */ pick?: (x: number, y: number, camera: Camera, renderable: Renderable, out: Intersection[]) => boolean; /** * User defined ray picking algorithm instead of default * triangle ray intersection * ```typescript * (ray: clay.Ray, renderable: clay.Renderable, out: Array) => boolean * ``` * @type {?Function} */ pickByRay?: (ray: Ray, renderable: Renderable, out: Intersection[]) => boolean; private _attributeList; private _enabledAttributes?; private _attributesVersion; __indicesVersion: number; constructor(opts?: Partial); get vertexCount(): number; get triangleCount(): number; /** * Mark attributes and indices in geometry needs to update. * Usually called after you change the data in attributes. */ dirty(): void; /** * Mark the indices needs to update. */ dirtyIndices(): void; /** * Mark the attributes needs to update. * @param {string} [attrName] */ dirtyAttribute(attrName: string): void; /** * Is any of attributes dirty. */ isAttributesDirty(uploadedVersion: Record): boolean; getAttributeVersion(attrName: string): number; /** * Get indices of triangle at given index. * @param {number} idx * @param {Array.} out * @return {Array.} */ getTriangleIndices(idx: number, out: Vec3Array): Vec3Array | undefined; /** * Set indices of triangle at given index. * @param {number} idx * @param {Array.} arr */ setTriangleIndices(idx: number, arr: Vec3Array): void; isUseIndices(): boolean; /** * Initialize indices from an array. * @param {Array} array */ initIndicesFromArray(array: ArrayLike | number[][]): void; /** * Create a new attribute * @param {string} name * @param {string} type * @param {number} size * @param {string} [semantic] */ createAttribute(name: string, type: AttributeType, size: T, semantic?: AttributeSemantic): GeometryAttribute; /** * Remove attribute * @param {string} name */ removeAttribute(name: string): boolean; /** * Get attribute * @param {string} name * @return {clay.GeometryBase.Attribute} */ getAttribute(name: string): GeometryAttribute; /** * Get enabled attributes name list * Attribute which has the same vertex number with position is treated as a enabled attribute * @return {string[]} */ getEnabledAttributes(): string[]; } export default GeometryBase;