diff --git a/types/three/src/core/BufferAttribute.d.ts b/types/three/src/core/BufferAttribute.d.ts index d043231e9..7ac8d2aee 100644 --- a/types/three/src/core/BufferAttribute.d.ts +++ b/types/three/src/core/BufferAttribute.d.ts @@ -5,14 +5,14 @@ import { Matrix4 } from './../math/Matrix4'; /** * see {@link https://github.com/mrdoob/three.js/blob/master/src/core/BufferAttribute.js|src/core/BufferAttribute.js} */ -export class BufferAttribute { - constructor(array: ArrayLike, itemSize: number, normalized?: boolean); // array parameter should be TypedArray. +export class BufferAttribute = ArrayLike> { + constructor(array: ArrayType, itemSize: number, normalized?: boolean); // array parameter should be TypedArray. /** * @default '' */ name: string; - array: ArrayLike; + array: ArrayType; itemSize: number; /** @@ -48,9 +48,9 @@ export class BufferAttribute { onUpload(callback: () => void): this; setUsage(usage: Usage): this; clone(): this; - copy(source: BufferAttribute): this; - copyAt(index1: number, attribute: BufferAttribute, index2: number): this; - copyArray(array: ArrayLike): this; + copy(source: BufferAttribute): this; + copyAt(index1: number, attribute: BufferAttribute, index2: number): this; + copyArray(array: ArrayType): this; copyColorsArray(colors: Array<{ r: number; g: number; b: number }>): this; copyVector2sArray(vectors: Array<{ x: number; y: number }>): this; copyVector3sArray(vectors: Array<{ x: number; y: number; z: number }>): this; @@ -59,7 +59,7 @@ export class BufferAttribute { applyMatrix4(m: Matrix4): this; applyNormalMatrix(m: Matrix3): this; transformDirection(m: Matrix4): this; - set(value: ArrayLike | ArrayBufferView, offset?: number): this; + set(value: ArrayType | ArrayBufferView, offset?: number): this; getX(index: number): number; setX(index: number, x: number): this; getY(index: number): number; @@ -142,82 +142,23 @@ export class Float64Attribute extends BufferAttribute { constructor(array: any, itemSize: number); } -export class Int8BufferAttribute extends BufferAttribute { - constructor( - array: Iterable | ArrayLike | ArrayBuffer | number, - itemSize: number, - normalized?: boolean, - ); -} +export class Int8BufferAttribute extends BufferAttribute {} -export class Uint8BufferAttribute extends BufferAttribute { - constructor( - array: Iterable | ArrayLike | ArrayBuffer | number, - itemSize: number, - normalized?: boolean, - ); -} +export class Uint8BufferAttribute extends BufferAttribute {} -export class Uint8ClampedBufferAttribute extends BufferAttribute { - constructor( - array: Iterable | ArrayLike | ArrayBuffer | number, - itemSize: number, - normalized?: boolean, - ); -} +export class Uint8ClampedBufferAttribute extends BufferAttribute {} -export class Int16BufferAttribute extends BufferAttribute { - constructor( - array: Iterable | ArrayLike | ArrayBuffer | number, - itemSize: number, - normalized?: boolean, - ); -} +export class Int16BufferAttribute extends BufferAttribute {} -export class Uint16BufferAttribute extends BufferAttribute { - constructor( - array: Iterable | ArrayLike | ArrayBuffer | number, - itemSize: number, - normalized?: boolean, - ); -} +export class Uint16BufferAttribute extends BufferAttribute {} -export class Int32BufferAttribute extends BufferAttribute { - constructor( - array: Iterable | ArrayLike | ArrayBuffer | number, - itemSize: number, - normalized?: boolean, - ); -} +export class Int32BufferAttribute extends BufferAttribute {} -export class Uint32BufferAttribute extends BufferAttribute { - constructor( - array: Iterable | ArrayLike | ArrayBuffer | number, - itemSize: number, - normalized?: boolean, - ); -} +export class Uint32BufferAttribute extends BufferAttribute {} -export class Float16BufferAttribute extends BufferAttribute { - constructor( - array: Iterable | ArrayLike | ArrayBuffer | number, - itemSize: number, - normalized?: boolean, - ); -} +// Float 16 arrays don't exist, what to do +export class Float16BufferAttribute extends BufferAttribute {} -export class Float32BufferAttribute extends BufferAttribute { - constructor( - array: Iterable | ArrayLike | ArrayBuffer | number, - itemSize: number, - normalized?: boolean, - ); -} +export class Float32BufferAttribute extends BufferAttribute {} -export class Float64BufferAttribute extends BufferAttribute { - constructor( - array: Iterable | ArrayLike | ArrayBuffer | number, - itemSize: number, - normalized?: boolean, - ); -} +export class Float64BufferAttribute extends BufferAttribute {} diff --git a/types/three/src/core/BufferGeometry.d.ts b/types/three/src/core/BufferGeometry.d.ts index 8e8a9f475..cc4c01387 100644 --- a/types/three/src/core/BufferGeometry.d.ts +++ b/types/three/src/core/BufferGeometry.d.ts @@ -9,6 +9,17 @@ import { EventDispatcher } from './EventDispatcher'; import { InterleavedBufferAttribute } from './InterleavedBufferAttribute'; import { BuiltinShaderAttributeName } from '../constants'; +// TODO make the exhaustive +type TypedArray = Uint8Array | Uint16Array | Int8Array | Int16Array | Float32Array | Float64Array | Uint8ClampedArray; +interface BufferGeometryAttributeMap { + [attributeName: string]: TypedArray, +} + +type AttributesFor = { + // TODO make InterleavedBufferAttribute generic + [attributeName in keyof AttrTypeMap]: BufferAttribute | InterleavedBufferAttribute // +} + /** * This is a superefficent class for geometries because it saves all data in buffers. * It reduces memory costs and cpu cycles. But it is not as easy to work with because of all the necessary buffer calculations. @@ -16,7 +27,7 @@ import { BuiltinShaderAttributeName } from '../constants'; * * see {@link https://github.com/mrdoob/three.js/blob/master/src/core/BufferGeometry.js|src/core/BufferGeometry.js} */ -export class BufferGeometry extends EventDispatcher { +export class BufferGeometry> extends EventDispatcher { /** * This creates a new BufferGeometry. It also sets several properties to an default value. */ @@ -46,9 +57,7 @@ export class BufferGeometry extends EventDispatcher { /** * @default {} */ - attributes: { - [name: string]: BufferAttribute | InterleavedBufferAttribute; - }; + attributes: AttributesFor; /** * @default {} @@ -88,13 +97,14 @@ export class BufferGeometry extends EventDispatcher { userData: { [key: string]: any }; readonly isBufferGeometry: true; + // TODO provide index type getIndex(): BufferAttribute | null; setIndex(index: BufferAttribute | number[] | null): BufferGeometry; - setAttribute( + setAttribute( name: BuiltinShaderAttributeName | (string & {}), - attribute: BufferAttribute | InterleavedBufferAttribute, - ): BufferGeometry; + attribute: BufferAttribute | InterleavedBufferAttribute, + ): BufferGeometry; getAttribute(name: BuiltinShaderAttributeName | (string & {})): BufferAttribute | InterleavedBufferAttribute; deleteAttribute(name: BuiltinShaderAttributeName | (string & {})): BufferGeometry; hasAttribute(name: BuiltinShaderAttributeName | (string & {})): boolean;