diff --git a/types/three/examples/jsm/Addons.d.ts b/types/three/examples/jsm/Addons.d.ts index ae8067aef49f9c..2ce4e684a6b3f5 100644 --- a/types/three/examples/jsm/Addons.d.ts +++ b/types/three/examples/jsm/Addons.d.ts @@ -46,6 +46,7 @@ export * from "./exporters/USDZExporter.js"; export * from "./geometries/BoxLineGeometry.js"; export * from "./geometries/ConvexGeometry.js"; export * from "./geometries/DecalGeometry.js"; +export * from "./geometries/LoftGeometry.js"; export * from "./geometries/ParametricFunctions.js"; export * from "./geometries/ParametricGeometry.js"; export * from "./geometries/RoundedBoxGeometry.js"; @@ -284,6 +285,7 @@ export * from "./webxr/OculusHandModel.js"; export * from "./webxr/OculusHandPointerModel.js"; export * from "./webxr/Text2D.js"; export * from "./webxr/VRButton.js"; +export * from "./webxr/WebGLXRFallback.js"; export * from "./webxr/XRButton.js"; export * from "./webxr/XRControllerModelFactory.js"; export * from "./webxr/XREstimatedLight.js"; diff --git a/types/three/examples/jsm/controls/FirstPersonControls.d.ts b/types/three/examples/jsm/controls/FirstPersonControls.d.ts index f3890ef60c47aa..adbcdc59431947 100644 --- a/types/three/examples/jsm/controls/FirstPersonControls.d.ts +++ b/types/three/examples/jsm/controls/FirstPersonControls.d.ts @@ -14,6 +14,15 @@ declare class FirstPersonControls extends Controls<{}> { */ lookSpeed: number; + /** + * How quickly the movement and look velocity catches up to the input. Lower + * values feel heavier (more inertia), `1` disables damping. + * + * @type {number} + * @default 0.1 + */ + dampingFactor: number; + /** * Whether or not it's possible to vertically look around. Default is `true`. */ diff --git a/types/three/examples/jsm/controls/OrbitControls.d.ts b/types/three/examples/jsm/controls/OrbitControls.d.ts index da803c4b554e68..449d5452d26f32 100644 --- a/types/three/examples/jsm/controls/OrbitControls.d.ts +++ b/types/three/examples/jsm/controls/OrbitControls.d.ts @@ -20,7 +20,7 @@ export interface OrbitControlsEventMap { /** * Orbit controls allow the camera to orbit around a target. */ -declare class OrbitControls extends Controls { +declare class OrbitControls extends Controls { /** * The focus point of the controls, the {@link .object} orbits around this. It can be updated manually at any point * to change the focus of the controls. @@ -206,7 +206,7 @@ declare class OrbitControls extends Controls { * is the scene itself. * @param domElement The HTML element used for event listeners. (optional) */ - constructor(object: Camera, domElement?: HTMLElement | SVGElement | null); + constructor(object: TCamera, domElement?: HTMLElement | SVGElement | null); set cursorStyle(type: "auto" | "grab"); get cursorStyle(): "auto" | "grab"; diff --git a/types/three/examples/jsm/controls/TransformControls.d.ts b/types/three/examples/jsm/controls/TransformControls.d.ts index 43681160e15295..e8f24461cb6da4 100644 --- a/types/three/examples/jsm/controls/TransformControls.d.ts +++ b/types/three/examples/jsm/controls/TransformControls.d.ts @@ -1,4 +1,4 @@ -import { Camera, ColorRepresentation, Controls, Mesh, Object3D, Quaternion, Raycaster, Vector3 } from "three"; +import { Camera, ColorRepresentation, Controls, Mesh, Object3D, Quaternion, Raycaster, Vector3, Vector4 } from "three"; export type TransformControlsMode = "translate" | "rotate" | "scale"; @@ -41,6 +41,8 @@ export interface TransformControlsEventMap { "showXY-changed": { value: unknown }; "showYZ-changed": { value: unknown }; "showXZ-changed": { value: unknown }; + "showXYZE-changed": { value: unknown }; + "showE-changed": { value: unknown }; "minX-changed": { value: unknown }; "maxX-changed": { value: unknown }; "minY-changed": { value: unknown }; @@ -111,6 +113,17 @@ declare class TransformControls extends Controls { */ size: number; + /** + * The viewport rectangle, in logical (CSS) pixels with the origin at the lower-left + * of the canvas. Set this when the renderer uses a sub-canvas viewport so pointer + * coordinates map to the correct region. If `null`, the full canvas is used. + * + * @name TransformControls#viewport + * @type {?Vector4} + * @default null + */ + viewport: Vector4 | null; + /** * Whether or not dragging is currently performed. Read-only property. */ @@ -152,6 +165,24 @@ declare class TransformControls extends Controls { */ showXZ: boolean; + /** + * Whether the xyze rotation helper should be visible or not. + * + * @name TransformControls#showXYZE + * @type {boolean} + * @default true + */ + showXYZE: boolean; + + /** + * Whether the e rotation helper should be visible or not. + * + * @name TransformControls#showE + * @type {boolean} + * @default true + */ + showE: boolean; + /** * The minimum allowed X position during translation. Default is `-Infinity`. */ diff --git a/types/three/examples/jsm/csm/CSMFrustum.d.ts b/types/three/examples/jsm/csm/CSMFrustum.d.ts index 339f699f00dfe4..f77bca06ab134e 100644 --- a/types/three/examples/jsm/csm/CSMFrustum.d.ts +++ b/types/three/examples/jsm/csm/CSMFrustum.d.ts @@ -1,25 +1,85 @@ import { Matrix4, Vector3 } from "three"; -export interface CSMFrustumVerticies { +export interface CSMFrustumVertices { near: Vector3[]; far: Vector3[]; } export interface CSMFrustumParameters { - webGL?: boolean; - projectionMatrix?: Matrix4; - maxFar?: number; + /** + * - Whether this CSM frustum is used with WebGL or WebGPU. + */ + webGL?: boolean | undefined; + /** + * - Whether reversed depth buffer is enabled. + */ + reversedDepth?: boolean | undefined; + /** + * - A projection matrix usually of the scene's camera. + */ + projectionMatrix?: Matrix4 | undefined; + /** + * - The maximum far value. + */ + maxFar?: number | undefined; } -declare class CSMFrustum { - zNear: number; - vertices: CSMFrustumVerticies; - +/** + * Represents the frustum of a CSM instance. + * + * @three_import import { CSMFrustum } from 'three/addons/csm/CSMFrustum.js'; + */ +export class CSMFrustum { + /** + * Constructs a new CSM frustum. + * + * @param {CSMFrustum~Data} [data] - The CSM data. + */ constructor(data?: CSMFrustumParameters); - - setFromProjectionMatrix(projectionMatrix: Matrix4, maxFar: number): CSMFrustumVerticies; - split(breaks: number[], target: CSMFrustum[]): void; + /** + * The zNear value. This value depends on whether the CSM + * is used with WebGL or WebGPU. Both API use different + * conventions for their projection matrices. + * + * @type {number} + */ + zNear: number; + /** + * The zFar value. + * + * @type {number} + */ + zFar: number; + /** + * An object representing the vertices of the near and + * far plane in view space. + * + * @type {Object} + */ + vertices: CSMFrustumVertices; + /** + * Setups this CSM frustum from the given projection matrix and max far value. + * + * @param {Matrix4} projectionMatrix - The projection matrix, usually of the scene's camera. + * @param {number} maxFar - The maximum far value. + * @returns {Object} An object representing the vertices of the near and far plane in view space. + */ + setFromProjectionMatrix(projectionMatrix: Matrix4, maxFar: number): CSMFrustumVertices; + /** + * Splits the CSM frustum by the given array. The new CSM frustum are pushed into the given + * target array. + * + * @param {Array} breaks - An array of numbers in the range `[0,1]` the defines how the + * CSM frustum should be split up. + * @param {Array} target - The target array that holds the new CSM frustums. + */ + split(breaks: Array, target: Array): void; + /** + * Transforms the given target CSM frustum into the different coordinate system defined by the + * given camera matrix. + * + * @param {Matrix4} cameraMatrix - The matrix that defines the new coordinate system. + * @param {CSMFrustum} target - The CSM to convert. + */ toSpace(cameraMatrix: Matrix4, target: CSMFrustum): void; } - -export { CSMFrustum }; diff --git a/types/three/examples/jsm/exporters/DRACOExporter.d.ts b/types/three/examples/jsm/exporters/DRACOExporter.d.ts index fa73d0fbf817f4..e2527a10765294 100644 --- a/types/three/examples/jsm/exporters/DRACOExporter.d.ts +++ b/types/three/examples/jsm/exporters/DRACOExporter.d.ts @@ -13,5 +13,5 @@ export interface DRACOExporterOptions { export class DRACOExporter { constructor(); - parse(object: Mesh | Points, options?: DRACOExporterOptions): Int8Array; + parseAsync(object: Mesh | Points, options?: DRACOExporterOptions): Promise>; } diff --git a/types/three/examples/jsm/exporters/GLTFExporter.d.ts b/types/three/examples/jsm/exporters/GLTFExporter.d.ts index 5154bb1a92f775..539e62b849ad36 100644 --- a/types/three/examples/jsm/exporters/GLTFExporter.d.ts +++ b/types/three/examples/jsm/exporters/GLTFExporter.d.ts @@ -34,7 +34,7 @@ export interface GLTFExporterOptions { /** * List of animations to be included in the export. */ - animations?: AnimationClip[]; + animations?: AnimationClip[] | AnimationClip[][]; /** * Generate indices for non-index geometry and export with them. Default is false. @@ -88,7 +88,7 @@ declare class GLTFExporter { parse( input: Object3D | Object3D[], onDone: (gltf: ArrayBuffer | { [key: string]: unknown }) => void, - onError: (error: ErrorEvent) => void, + onError: ((error: ErrorEvent) => void) | null, options?: GLTFExporterOptions, ): void; diff --git a/types/three/examples/jsm/exporters/PLYExporter.d.ts b/types/three/examples/jsm/exporters/PLYExporter.d.ts index f13197687d3c61..bc0cf006d9bb3c 100644 --- a/types/three/examples/jsm/exporters/PLYExporter.d.ts +++ b/types/three/examples/jsm/exporters/PLYExporter.d.ts @@ -1,8 +1,9 @@ import { Object3D } from "three"; export interface PLYExporterOptionsBase { - excludeAttributes?: string[]; - littleEndian?: boolean; + excludeAttributes?: string[] | undefined; + littleEndian?: boolean | undefined; + customPropertyMapping?: Record; } export interface PLYExporterOptionsBinary extends PLYExporterOptionsBase { @@ -10,11 +11,11 @@ export interface PLYExporterOptionsBinary extends PLYExporterOptionsBase { } export interface PLYExporterOptionsString extends PLYExporterOptionsBase { - binary?: false; + binary?: false | undefined; } export interface PLYExporterOptions extends PLYExporterOptionsBase { - binary?: boolean; + binary?: boolean | undefined; } export class PLYExporter { diff --git a/types/three/examples/jsm/exporters/USDZExporter.d.ts b/types/three/examples/jsm/exporters/USDZExporter.d.ts index 9e153df4daf651..5f9b471fdaebed 100644 --- a/types/three/examples/jsm/exporters/USDZExporter.d.ts +++ b/types/three/examples/jsm/exporters/USDZExporter.d.ts @@ -1,4 +1,4 @@ -import { Object3D } from "three"; +import { AnimationClip, Object3D } from "three"; import * as WebGLTextureUtils from "../utils/WebGLTextureUtils.js"; import * as WebGPUTextureUtils from "../utils/WebGPUTextureUtils.js"; @@ -8,6 +8,8 @@ export interface USDZExporterOptions { onlyVisible?: boolean | undefined; quickLookCompatible?: boolean | undefined; maxTextureSize?: number | undefined; + animations?: AnimationClip[] | undefined; + animationFrameRate?: number | undefined; } export class USDZExporter { @@ -15,6 +17,8 @@ export class USDZExporter { constructor(); + setTextureUtils(textureUtils: typeof WebGLTextureUtils | typeof WebGPUTextureUtils | null): void; + parse( scene: Object3D, onDone: (result: Uint8Array) => void, diff --git a/types/three/examples/jsm/generators/CityGenerator.d.ts b/types/three/examples/jsm/generators/CityGenerator.d.ts new file mode 100644 index 00000000000000..f27c2e9a48e11a --- /dev/null +++ b/types/three/examples/jsm/generators/CityGenerator.d.ts @@ -0,0 +1,75 @@ +import { Group, Material, MeshStandardNodeMaterial } from "three/webgpu"; +import { SidewalkGenerator } from "./city/SidewalkGenerator.js"; +import { SkyscraperGenerator } from "./city/SkyscraperGenerator.js"; + +export interface CityGeneratorParameters { + seed: number; + street: number; + lot: number; + lotsX: number; + lotsZ: number; + blocksX: number; + blocksZ: number; + curbHeight: number; + curbRadius: number; +} + +export interface CityGeneratorLayout { + street: number; + lot: number; + lotsX: number; + lotsZ: number; + blocksX: number; + blocksZ: number; + blockW: number; + blockD: number; + cityW: number; + cityD: number; +} + +export interface CityGeneratorMaterials { + building?: Material | undefined; +} + +/** + * Lays out a grid of city blocks and fills each lot with a {@link SkyscraperGenerator} + * tower of its own seed, height and footprint, optionally on raised sidewalk + * slabs (curbs). Returns a `THREE.Group` ready to add to a scene. + * + * Pass a building material to dress the towers; the sidewalks dress themselves + * via {@link SidewalkGenerator}. The layout is exposed as + * {@link CityGenerator#layout} so the surrounding scene (road markings, etc.) + * can align to the same grid. + * + * ```js + * const city = new CityGenerator( { seed: 1 } ); + * scene.add( city.build( materials ) ); + * ``` + */ +export class CityGenerator { + constructor(parameters?: Partial); + + parameters: CityGeneratorParameters; + layout: CityGeneratorLayout; + + generators: SkyscraperGenerator[]; + sidewalk: SidewalkGenerator; + group: Group | null; + + build(materials?: CityGeneratorMaterials): Group; + dispose(): void; + + static defaults: CityGeneratorParameters; +} + +/** + * The shared material every tower in a {@link CityGenerator} is dressed with: one flat + * masonry colour per lot, picked from a palette by hashing the lot's grid cell. + */ +export function createBuildingMaterial(layout: CityGeneratorLayout, seed?: number): MeshStandardNodeMaterial; + +/** + * The road surface: wet asphalt with lane lines and crosswalks aligned to a + * {@link CityGenerator} layout. Apply it to a ground plane sized to the city. + */ +export function createRoadMaterial(layout: CityGeneratorLayout): MeshStandardNodeMaterial; diff --git a/types/three/examples/jsm/generators/ForestGenerator.d.ts b/types/three/examples/jsm/generators/ForestGenerator.d.ts new file mode 100644 index 00000000000000..ea278980c26957 --- /dev/null +++ b/types/three/examples/jsm/generators/ForestGenerator.d.ts @@ -0,0 +1,79 @@ +import { Group, InstancedMesh, MeshStandardNodeMaterial, Node, UniformNode, Vector3 } from "three/webgpu"; +import { TerrainGenerator } from "./TerrainGenerator.js"; + +export interface ForestGeneratorParameters { + seed: number; + count: number; + detail: number; + radius: number; + height: number; + distortion: number; + sink: number; + altitudeMin: number; + altitudeMax: number; + minSlope: number; + densityFrequency: number; + minScale: number; + maxScale: number; + from: number; + to: number; + castShadow: boolean; +} + +/** + * Carpets a {@link TerrainGenerator} ( or anything exposing `sampleHeight`, + * `sampleSlope`, `minY`, `maxY` and `parameters.size` ) with a forest of hundreds + * of thousands of trees in a single draw call. + * + * Each tree is the cheapest thing that still reads as a tree: a ~20-face icosphere + * squashed into a tapered teardrop and lumped with a little noise, carrying a baked + * dark-base / bright-top gradient. Tens of triangles each, so a single + * {@link THREE.InstancedMesh} of half a million of them costs one draw call. Trees + * are placed by rejection sampling against ecological rules — a min/max altitude + * band ( above the mist floor, below the snowline ), a slope limit ( none on + * cliffs ) and a low-frequency density mask that opens clearings — then jittered in + * yaw, lean and ( squared-biased ) scale so the stand never reads as copies. + * + * ```js + * const forest = new ForestGenerator( { count: 500000 } ); + * scene.add( forest.build( terrain ) ); + * ``` + */ +export class ForestGenerator { + constructor(parameters?: Partial); + + parameters: ForestGeneratorParameters; + + from: UniformNode<"float", number>; + to: UniformNode<"float", number>; + + material: MeshStandardNodeMaterial; + mesh: InstancedMesh | null; + group: Group | null; + + build(terrain: TerrainGenerator): Group; + setCameraPosition(position: Vector3): void; + dispose(): void; + + static defaults: ForestGeneratorParameters; +} + +/** + * The single material shared by every tree in a {@link ForestGenerator}. A plain + * MeshStandardNodeMaterial lit by the scene — only the surface is authored: deep + * shadowed green in the recesses rising to a bright, yellow-green sunlit crown, + * mottled into needle clumps by 3D noise, with a matching bump so the clumps catch + * the light. Half a million instanced blobs makes this mesh vertex-bound, so the + * regional colour drift is baked to a per-instance attribute ( no shader noise for it ), + * and the costly clump noise + bump are **gated by distance** — full detail on the near + * trees ( where it reads ), skipped on the far canopy ( where it is sub-pixel ). + * + * @param {Node} from - distance within which every tree is drawn. + * @param {Node} to - distance past which no tree is drawn. + * @return {MeshStandardNodeMaterial} + */ +export function createForestMaterial( + from: Node<"float">, + to: Node<"float">, + camPos: Node<"vec3">, +): MeshStandardNodeMaterial; diff --git a/types/three/examples/jsm/generators/TerrainGenerator.d.ts b/types/three/examples/jsm/generators/TerrainGenerator.d.ts new file mode 100644 index 00000000000000..6e13320c49108c --- /dev/null +++ b/types/three/examples/jsm/generators/TerrainGenerator.d.ts @@ -0,0 +1,67 @@ +import { BufferGeometry, Group, MeshStandardNodeMaterial, UniformNode } from "three/webgpu"; + +export interface TerrainGeneratorParameters { + seed: number; + size: number; + segments: number; + heightScale: number; + frequency: number; + octaves: number; + lacunarity: number; + gain: number; + erosion: number; + warp: number; + valleyBias: number; + seaLevel: number; + talus: number; + talusPasses: number; +} + +/** + * Bakes a procedural mountain range into a single {@link THREE.BufferGeometry} and + * returns a `THREE.Group` ready to add to a scene. + * + * The heightfield is a derivative-damped fractal sum ( Quilez's fake erosion ): each + * octave is suppressed where the running slope is already steep, concentrating detail + * into weathered ridgelines, and a low-frequency domain warp makes those ridges + * meander. A few passes of thermal ( talus ) erosion then relax any slope past the + * angle of repose, settling the fractal's needle-spikes into real crests. + * + * The grid is triangulated with alternating quad diagonals ( a diamond pattern ), so a + * coarse mesh holds its silhouette without a one-way grain. The surface shades itself + * from altitude and slope in TSL — grass, forest, rock, scree and snow, with detail + * normals and aerial perspective — so no material or textures are needed. + * + * The baked height grid is exposed through {@link TerrainGenerator#sampleHeight} so a + * scattered forest ( or anything else ) can sit exactly on the surface. + * + * ```js + * const terrain = new TerrainGenerator( { seed: 1 } ); + * scene.add( terrain.build() ); + * ``` + */ +export class TerrainGenerator { + constructor(parameters?: Partial); + + parameters: TerrainGeneratorParameters; + + minHeight: UniformNode<"float", number>; + maxHeight: UniformNode<"float", number>; + + material: MeshStandardNodeMaterial; + geometry: BufferGeometry | null; + group: Group | null; + + heights?: Float32Array; + gridSize?: number; + minY?: number; + maxY?: number; + + build(): Group; + + sampleHeight(x: number, z: number): number; + sampleSlope(x: number, z: number): number; + dispose(): void; + + static defaults: TerrainGeneratorParameters; +} diff --git a/types/three/examples/jsm/generators/TreeGenerator.d.ts b/types/three/examples/jsm/generators/TreeGenerator.d.ts new file mode 100644 index 00000000000000..704984092921bb --- /dev/null +++ b/types/three/examples/jsm/generators/TreeGenerator.d.ts @@ -0,0 +1,97 @@ +import { Color, Material, Mesh, MeshStandardNodeMaterial, Node } from "three/webgpu"; + +export interface TreeGeneratorParameters { + seed: number; + levels: number; + children: number[]; + branchAngle: number[]; + angleVariance: number; + lengthRatio: number; + trunkLength: number; + trunkRadius: number; + taper: number; + taperCurve: number; + rootFlare: number; + flareFrac: number; + radiusExponent: number; + minRadius: number; + minLength: number; + droop: number; + upPull: number; + gnarl: number[]; + radialSegments: number; + sectionLength: number; + childStart: number; + trunkClear: number; +} + +/** + * Grows a procedural tree skeleton — trunk, branches and twigs, each swept as a tapered + * tube — and bakes it into one non-indexed {@link BufferGeometry} (position and normal + * only), ready to instance into a forest. It produces *branches only*; add foliage as a + * separate layer. + * + * The branching is deterministic for a given `seed`: a recursive sweep lays down gently + * curved tubes with a parallel-transport frame (so they never twist), forking by the + * pipe model (each child much thinner than its parent), spreading children along the + * upper part of each branch with a golden-angle roll, and pulling them back up toward + * the light. A flared root, non-linear taper and gravity droop fill in the character. + * + * Parameters are set with a fluent builder: a `set()` exists for every default + * ( `setSeed`, `setLevels`, `setChildren`, … ), each returning `this` for chaining. + * + * Each `build()` returns a fresh, independent mesh that the caller owns, so one + * generator can be re-parametrized and built repeatedly to grow a varied stand: + * + * ```js + * const generator = new TreeGenerator( material ); + * const oak = generator.setSeed( 1 ).setLevels( 4 ).build(); + * const pine = generator.setSeed( 2 ).setLevels( 5 ).build(); + * ``` + */ +export class TreeGenerator { + constructor(material?: Material | null); + + material: Material | null; + parameters: Partial; + + build(): Mesh; + + static defaults: TreeGeneratorParameters; + + setSeed: (seed: number) => this; + setLevels: (levels: number) => this; + setChildren: (children: number[]) => this; + setBranchAngle: (branchAngle: number[]) => this; + setAngleVariance: (angleVariance: number) => this; + setLengthRatio: (lengthRatio: number) => this; + setTrunkLength: (trunkLength: number) => this; + setTrunkRadius: (trunkRadius: number) => this; + setTaper: (taper: number) => this; + setTaperCurve: (taperCurve: number) => this; + setRootFlare: (rootFlare: number) => this; + setFlareFrac: (flareFrac: number) => this; + setRadiusExponent: (radiusExponent: number) => this; + setMinRadius: (minRadius: number) => this; + setMinLength: (minLength: number) => this; + setDroop: (droop: number) => this; + setUpPull: (upPull: number) => this; + setGnarl: (gnarl: number[]) => this; + setRadialSegments: (radialSegments: number) => this; + setSectionLength: (sectionLength: number) => this; + setChildStart: (childStart: number) => this; + setTrunkClear: (trunkClear: number) => this; +} + +export interface TreeMaterialParameters { + barkColor?: Color | number | Node<"color"> | undefined; +} + +/** + * A simple bark material for a {@link TreeGenerator} mesh: a low-saturation brown with a + * faint, vertically-stretched grain, so trunks read near-black against bright fog. + * + * @param {Object} [parameters] - `barkColor` ( a hex, THREE.Color or TSL node ). + * @return {MeshStandardNodeMaterial} + */ +export function createTreeMaterial(parameters?: TreeMaterialParameters): MeshStandardNodeMaterial; diff --git a/types/three/examples/jsm/generators/city/SidewalkGenerator.d.ts b/types/three/examples/jsm/generators/city/SidewalkGenerator.d.ts new file mode 100644 index 00000000000000..7394f2076d0a3c --- /dev/null +++ b/types/three/examples/jsm/generators/city/SidewalkGenerator.d.ts @@ -0,0 +1,40 @@ +import { Group, Matrix4, MeshStandardNodeMaterial } from "three/webgpu"; + +export interface SidewalkGeneratorParameters { + width: number; + depth: number; + height: number; + radius: number; + curbWidth: number; + curbLip: number; +} + +/** + * Generates the raised sidewalk for a city's blocks: per block, a rounded-corner concrete + * slab rimmed by a distinct granite kerbstone that stands proud of the walking surface and + * drops to the road. Instanced across a list of placements and dressed with its own + * procedural material ( poured concrete flags, scored expansion joints, granite curb ). + * Returns a `THREE.Group` of two instanced meshes — the walking slab and the curb. + * + * Unlike the building generator, this one owns its materials: the slab and curb + * geometry and the TSL that shades them live together here. + * + * ```js + * const sidewalk = new SidewalkGenerator( { width: 90, depth: 60, height: 0.5 } ); + * scene.add( sidewalk.build( placements ) ); // placements: Matrix4[] + * ``` + */ +export class SidewalkGenerator { + constructor(parameters?: Partial); + + parameters: SidewalkGeneratorParameters; + + material: MeshStandardNodeMaterial | null; + curbMaterial: MeshStandardNodeMaterial | null; + mesh: Group | null; + + build(placements: Matrix4[]): Group; + dispose(): void; + + static defaults: SidewalkGeneratorParameters; +} diff --git a/types/three/examples/jsm/generators/city/SkyscraperGenerator.d.ts b/types/three/examples/jsm/generators/city/SkyscraperGenerator.d.ts new file mode 100644 index 00000000000000..d1efec3ad7ea57 --- /dev/null +++ b/types/three/examples/jsm/generators/city/SkyscraperGenerator.d.ts @@ -0,0 +1,83 @@ +import { Color, Material, Mesh, MeshStandardNodeMaterial, Node } from "three/webgpu"; + +export interface SkyscraperGeneratorDefaultParameters { + seed: number; + totalHeight: number; + floorHeight: number; + bayWidth: number; + stringCourseEvery: number; + chamferWidth: number; + chamferCornerX: number; + chamferCornerZ: number; + setbackDepth: number; + acChance: number; +} + +export interface SkyscraperGeneratorParameters extends SkyscraperGeneratorDefaultParameters { + footprint: { width: number; depth: number }; + tierFractions: { base: number; crown: number }; + pierWidth: number; + pierDepth: number; + windowReveal: number; + stringCourseHeight: number; + archBayWidthRatio: number; + archRise: number; +} + +/** + * Generates intricate, tripartite "Beaux-Arts / Neo-Gothic" terracotta + * skyscrapers from a small set of parameters. + * + * The mass is read as a footprint polygon (a rectangle with one chamfered + * corner) split into vertical faces, each split into three tiers — a tall + * arcaded base, a repeating shaft and an ornate crown — then into floors and + * bays. A handful of authored pieces (a pier, a window, a cornice profile, a + * gothic arch) are instanced across the whole tower, then baked — together with + * the bespoke base arcade — into a single non-indexed BufferGeometry tagged with + * a per-vertex `partId` ({@link PartId}) so one material can shade every zone. + * + * The generator is material agnostic — it only produces geometry. Pass a single + * material (e.g. a TSL node material that branches on `partId`) to dress it. + * + * ```js + * const generator = new SkyscraperGenerator( { seed: 35, totalHeight: 140 }, material ); + * scene.add( generator.build() ); // a single Mesh + * ``` + */ +export class SkyscraperGenerator { + constructor(parameters?: Partial, material?: Material); + + parameters: Partial; + material: Material; + + mesh: Mesh | null; + + setParameters(parameters: Partial): this; + build(): Mesh; + rebuild(): Mesh; + dispose(): void; + + static defaults: SkyscraperGeneratorDefaultParameters; +} + +/** + * The facade material: a single MeshStandardNodeMaterial that reads the baked + * per-vertex `partId` and reproduces every zone — procedural terracotta brickwork + * on the walls and piers, smooth dressed stone on the window frames and ornament, + * dark glazing, and grey AC units — all dressed with world-space + * weathering. One material covers the whole building ( and a whole city ), which is + * what makes it compute-rasterizer friendly. `buildingBase` is the tower's flat + * masonry colour as a TSL node: pass a `uniform( Color )` for a single tower, or a + * per-fragment palette pick for a city, so the same material dresses both. + */ +export function createSkyscraperMaterial(buildingBase?: Node<"color"> | Color): MeshStandardNodeMaterial; + +/** + * The NYC masonry palette every tower is dressed from ( hex colours ): limestone-dominant + * with terracotta accents. Shared by the single-tower example and {@link CityGenerator}'s + * building material so both stay in sync. + */ +export const buildingPalette: number[]; + +/** Picks one {@link buildingPalette} colour ( a hex number ) for a tower from its seed. */ +export function pickBuildingColor(seed: number): number; diff --git a/types/three/examples/jsm/geometries/LoftGeometry.d.ts b/types/three/examples/jsm/geometries/LoftGeometry.d.ts new file mode 100644 index 00000000000000..5474665111c6c2 --- /dev/null +++ b/types/three/examples/jsm/geometries/LoftGeometry.d.ts @@ -0,0 +1,83 @@ +import { BufferGeometry, Vector3 } from "three"; + +export interface LoftGeometryOptions { + closed?: boolean | undefined; + capStart?: boolean | undefined; + capEnd?: boolean | undefined; +} + +export interface LoftGeometryParameters { + sections: Vector3[][]; + closed: boolean; + capStart: boolean; + capEnd: boolean; +} + +/** + * This class can be used to generate a geometry by lofting (skinning) a surface + * through a series of cross sections. Each section is an array of points in 3D + * space and all sections must have the same number of points. + * + * `LoftGeometry` is the general case of geometries like {@link LatheGeometry} + * (which revolves a fixed profile around an axis) or {@link TubeGeometry} + * (which sweeps a circular section along a path): the sections can have any + * shape, and can change shape, size, position and orientation from one + * section to the next. + * + * Sections wind around the loft so the resulting face normals point outwards + * when each section is ordered counterclockwise as seen from the end of the + * loft, looking back towards the start. If the surface appears inside out, + * reverse the point order of each section. + * + * ```js + * const sections = []; + * + * for ( let i = 0; i <= 10; i ++ ) { + * + * const points = []; + * const radius = 2 + Math.sin( i * 0.8 ); + * + * for ( let j = 0; j < 32; j ++ ) { + * + * const angle = j / 32 * Math.PI * 2; + * points.push( new THREE.Vector3( Math.sin( angle ) * radius, i, Math.cos( angle ) * radius ) ); + * + * } + * + * sections.push( points ); + * + * } + * + * const geometry = new LoftGeometry( sections, { capStart: true, capEnd: true } ); + * const material = new THREE.MeshStandardMaterial( { color: 0x00ff00 } ); + * const mesh = new THREE.Mesh( geometry, material ); + * scene.add( mesh ); + * ``` + * + * @augments BufferGeometry + * @three_import import { LoftGeometry } from 'three/addons/geometries/LoftGeometry.js'; + */ +export class LoftGeometry extends BufferGeometry { + /** + * Constructs a new loft geometry. + * + * @param {Array>} sections - The cross sections to skin. At least + * two sections are required and all sections must have the same number of points. + * @param {Object} [options={}] - The loft options. + * @param {boolean} [options.closed=true] - Whether each section is treated as a + * closed ring (e.g. a fuselage) or an open strip (e.g. a ribbon). + * @param {boolean} [options.capStart=false] - Whether the first section is closed + * with a cap or not. + * @param {boolean} [options.capEnd=false] - Whether the last section is closed + * with a cap or not. + */ + constructor(sections?: Vector3[][], options?: LoftGeometryOptions); + /** + * Holds the constructor parameters that have been + * used to generate the geometry. Any modification + * after instantiation does not change the geometry. + * + * @type {Object} + */ + parameters: LoftGeometryParameters; +} diff --git a/types/three/examples/jsm/inspector/tabs/Parameters.d.ts b/types/three/examples/jsm/inspector/tabs/Parameters.d.ts index ef32caf7f665d0..fc1a58d12e66c8 100644 --- a/types/three/examples/jsm/inspector/tabs/Parameters.d.ts +++ b/types/three/examples/jsm/inspector/tabs/Parameters.d.ts @@ -67,12 +67,15 @@ interface ValueColorWithParameters< } declare class ParametersGroup { - name: string; - paramList: Item; constructor(parameters: never, name: string); + close(): this; + name(name: string): this; + show(): this; + hide(): this; + add( object: T, property: K, diff --git a/types/three/examples/jsm/lighting/ClusteredLighting.d.ts b/types/three/examples/jsm/lighting/ClusteredLighting.d.ts new file mode 100644 index 00000000000000..6ed9b1df0448f9 --- /dev/null +++ b/types/three/examples/jsm/lighting/ClusteredLighting.d.ts @@ -0,0 +1,45 @@ +import { Light, Lighting } from "three/webgpu"; +import ClusteredLightsNode from "../tsl/lighting/ClusteredLightsNode.js"; + +/** + * A custom lighting implementation based on Forward+ Clustered Shading that + * overwrites the default lighting system in {@link WebGPURenderer}. Suitable + * for 3D scenes with many point lights and real depth complexity — the view + * frustum is partitioned into a 3D cluster grid so only the lights actually + * reaching each fragment are evaluated. + * + * ```js + * const lighting = new ClusteredLighting(); + * renderer.lighting = lighting; // set lighting system + * ``` + * + * @augments Lighting + * @three_import import { ClusteredLighting } from 'three/addons/lighting/ClusteredLighting.js'; + */ +export class ClusteredLighting extends Lighting { + maxLights: number; + tileSize: number; + zSlices: number; + maxLightsPerCluster: number; + + /** + * Constructs a new clustered lighting system. + * + * @param {number} [maxLights=1024] - Maximum number of point lights. + * @param {number} [tileSize=32] - Screen tile size in pixels (cluster XY size). + * @param {number} [zSlices=24] - Number of exponential depth slices. + * @param {number} [maxLightsPerCluster=64] - Per-cluster light-list capacity. + */ + constructor(maxLights?: number, tileSize?: number, zSlices?: number, maxLightsPerCluster?: number); + + /** + * Creates a new clustered lights node for the given array of lights. + * + * This method is called internally by the renderer and must be overwritten by + * all custom lighting implementations. + * + * @param {Array} lights - The lights. + * @return {ClusteredLightsNode} The clustered lights node. + */ + createNode(lights?: Light[]): ClusteredLightsNode; +} diff --git a/types/three/examples/jsm/lighting/LightProbeGrid.d.ts b/types/three/examples/jsm/lighting/LightProbeGrid.d.ts index c69b0af841fd58..3ee393985ae4e4 100644 --- a/types/three/examples/jsm/lighting/LightProbeGrid.d.ts +++ b/types/three/examples/jsm/lighting/LightProbeGrid.d.ts @@ -1,21 +1,66 @@ import { Box3, Data3DTexture, Object3D, Scene, Vector3, WebGLRenderer } from "three"; export interface LightProbeGridBakeOptions { + /** + * Resolution of each cubemap face. + */ cubemapSize?: number | undefined; + /** + * Near plane for the cube camera. + */ near?: number | undefined; + /** + * Far plane for the cube camera. + */ far?: number | undefined; + /** + * Additional bounce passes after the initial direct pass. + */ + bounces?: number | undefined; } -declare class LightProbeGrid extends Object3D { - readonly isLightProbeGrid: boolean; - - width: number; - height: number; - depth: number; - resolution: Vector3; - boundingBox: Box3; - texture: Data3DTexture | null; - +/** + * A 3D grid of L2 Spherical Harmonic irradiance probes that provides + * position-dependent diffuse global illumination. + * + * Note that this class can only be used with {@link WebGLRenderer}. + * A version for {@link WebGPURenderer} will be added at a later point. + * + * All seven packed SH sub-volumes are stored in a **single** RGBA + * `WebGL3DRenderTarget` using a texture-atlas layout along the Z axis. + * Each sub-volume occupies `( nz + 2 )` atlas slices: one padding slice at + * each end (a copy of the nearest edge data slice) to prevent color bleeding + * when the hardware trilinear filter reads across a sub-volume boundary. + * + * Atlas layout (nz = resolution.z, PADDING = 1): + * ``` + * slice 0 : padding (copy of sub-volume 0, data slice 0) + * slices 1 … nz : sub-volume 0 data + * slice nz + 1 : padding (copy of sub-volume 0, data slice nz-1) + * slice nz + 2 : padding (copy of sub-volume 1, data slice 0) + * slices nz+3 … 2*nz+2 : sub-volume 1 data + * … + * ``` + * Total atlas depth = `7 * ( nz + 2 )`. + * + * Baking is fully GPU-resident: cubemap rendering, SH projection, and + * texture packing all happen on the GPU with zero CPU readback. + * + * @three_import import { LightProbeGrid } from 'three/addons/lighting/LightProbeGrid.js'; + */ +export class LightProbeGrid extends Object3D { + /** + * Constructs a new irradiance probe grid. + * + * The volume is centered at the object's position. + * + * @param {number} [width=1] - Full width of the volume along X. + * @param {number} [height=1] - Full height of the volume along Y. + * @param {number} [depth=1] - Full depth of the volume along Z. + * @param {number} [widthProbes] - Number of probes along X. Defaults to `Math.max( 2, Math.round( width ) + 1 )`. + * @param {number} [heightProbes] - Number of probes along Y. Defaults to `Math.max( 2, Math.round( height ) + 1 )`. + * @param {number} [depthProbes] - Number of probes along Z. Defaults to `Math.max( 2, Math.round( depth ) + 1 )`. + */ constructor( width?: number, height?: number, @@ -24,11 +69,84 @@ declare class LightProbeGrid extends Object3D { heightProbes?: number, depthProbes?: number, ); - + /** + * This flag can be used for type testing. + * + * @type {boolean} + * @readonly + * @default true + */ + readonly isLightProbeGrid: boolean; + /** + * The full width of the volume along X. + * + * @type {number} + */ + width: number; + /** + * The full height of the volume along Y. + * + * @type {number} + */ + height: number; + /** + * The full depth of the volume along Z. + * + * @type {number} + */ + depth: number; + /** + * The number of probes along each axis. + * + * @type {Vector3} + */ + resolution: Vector3; + /** + * The world-space bounding box for the grid. Updated automatically + * by {@link LightProbeGrid#bake}. + * + * @type {Box3} + */ + boundingBox: Box3; + /** + * The single RGBA atlas 3D texture storing all seven packed SH sub-volumes. + * + * @type {?Data3DTexture} + * @default null + */ + texture: Data3DTexture | null; + /** + * Returns the world-space position of the probe at grid indices (ix, iy, iz). + * + * @param {number} ix - X index. + * @param {number} iy - Y index. + * @param {number} iz - Z index. + * @param {Vector3} target - The target vector. + * @return {Vector3} The world-space position. + */ getProbePosition(ix: number, iy: number, iz: number, target: Vector3): Vector3; + /** + * Updates the world-space bounding box from the current position and size. + */ updateBoundingBox(): void; + /** + * Bakes all probes by rendering cubemaps at each probe position + * and projecting to L2 SH. Optionally iterates additional passes to + * capture indirect bounces — each extra pass samples the previous pass's + * atlas as indirect light, so a grid added to the scene before baking + * accumulates one bounce per extra pass. + * + * @param {WebGLRenderer} renderer - The renderer. + * @param {Scene} scene - The scene to render. + * @param {Object} [options] - Bake options. + * @param {number} [options.cubemapSize=8] - Resolution of each cubemap face. + * @param {number} [options.near=0.1] - Near plane for the cube camera. + * @param {number} [options.far=100] - Far plane for the cube camera. + * @param {number} [options.bounces=0] - Additional bounce passes after the initial direct pass. + */ bake(renderer: WebGLRenderer, scene: Scene, options?: LightProbeGridBakeOptions): void; + /** + * Frees GPU resources. + */ dispose(): void; } - -export { LightProbeGrid }; diff --git a/types/three/examples/jsm/lighting/TiledLighting.d.ts b/types/three/examples/jsm/lighting/TiledLighting.d.ts deleted file mode 100644 index 3764cbd741579a..00000000000000 --- a/types/three/examples/jsm/lighting/TiledLighting.d.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { Lighting } from "three/webgpu"; -import { Light } from "../../../src/lights/Light.js"; -import TiledLightsNode from "../tsl/lighting/TiledLightsNode.js"; - -export class TiledLighting extends Lighting { - constructor(); - - createNode(lights?: Light[]): TiledLightsNode; -} diff --git a/types/three/examples/jsm/loaders/DRACOLoader.d.ts b/types/three/examples/jsm/loaders/DRACOLoader.d.ts index 2e37a6e7d156b0..380d5729f8b685 100644 --- a/types/three/examples/jsm/loaders/DRACOLoader.d.ts +++ b/types/three/examples/jsm/loaders/DRACOLoader.d.ts @@ -1,11 +1,23 @@ import { BufferGeometry, Loader, LoadingManager } from "three"; -export class DRACOLoader extends Loader { +interface DecoderPaths { + js: string; + wasm: string; +} + +declare const DRACO_GLTF_CONFIG: DecoderPaths; + +declare class DRACOLoader extends Loader { constructor(manager?: LoadingManager); - setDecoderPath(path: string): DRACOLoader; - setDecoderConfig(config: object): DRACOLoader; - setWorkerLimit(workerLimit: number): DRACOLoader; + setDecoderPath(path: string | DecoderPaths): this; + + /** + * @deprecated setDecoderConfig to has been deprecated and will be removed in r194. + */ + setDecoderConfig(config: object): this; + + setWorkerLimit(workerLimit: number): this; load( url: string, @@ -20,6 +32,8 @@ export class DRACOLoader extends Loader { onError?: (err: unknown) => void, ): void; - preload(): DRACOLoader; - dispose(): DRACOLoader; + preload(): this; + dispose(): this; } + +export { DRACO_GLTF_CONFIG, DRACOLoader }; diff --git a/types/three/examples/jsm/loaders/EXRLoader.d.ts b/types/three/examples/jsm/loaders/EXRLoader.d.ts index bd3d157557662e..a2856c4f061e77 100644 --- a/types/three/examples/jsm/loaders/EXRLoader.d.ts +++ b/types/three/examples/jsm/loaders/EXRLoader.d.ts @@ -1,25 +1,15 @@ import { DataTextureLoader, + DataTextureLoaderTexData, FloatType, HalfFloatType, LoadingManager, - PixelFormat, RedFormat, RGBAFormat, RGFormat, TextureDataType, } from "three"; -export interface EXR { - header: object; - width: number; - height: number; - data: Float32Array | Uint16Array; - format: PixelFormat; - colorSpace: string; - type: typeof HalfFloatType | typeof FloatType; -} - declare class EXRLoader extends DataTextureLoader { type: TextureDataType; outputFormat: typeof RGBAFormat | typeof RGFormat | typeof RedFormat; @@ -27,7 +17,7 @@ declare class EXRLoader extends DataTextureLoader { constructor(manager?: LoadingManager); - parse(buffer: ArrayBuffer): EXR; + parse(buffer: ArrayBuffer): DataTextureLoaderTexData; setDataType(type: typeof HalfFloatType | typeof FloatType): this; setOutputFormat(value: typeof RGBAFormat | typeof RGFormat | typeof RedFormat): this; setPart(value: number): this; diff --git a/types/three/examples/jsm/loaders/GLTFLoader.d.ts b/types/three/examples/jsm/loaders/GLTFLoader.d.ts index da46dfa4f7918d..ad18a1f8baaf5a 100644 --- a/types/three/examples/jsm/loaders/GLTFLoader.d.ts +++ b/types/three/examples/jsm/loaders/GLTFLoader.d.ts @@ -47,7 +47,7 @@ export class GLTFLoader extends Loader { constructor(manager?: LoadingManager); - setDRACOLoader(dracoLoader: DRACOLoader): this; + setDRACOLoader(dracoLoader: DRACOLoader | null): this; setKTX2Loader(ktx2Loader: KTX2Loader | null): this; setMeshoptDecoder(meshoptDecoder: typeof MeshoptDecoder | null): this; diff --git a/types/three/examples/jsm/loaders/HDRLoader.d.ts b/types/three/examples/jsm/loaders/HDRLoader.d.ts index 14d8d41a0d387b..805a3736cfa8c6 100644 --- a/types/three/examples/jsm/loaders/HDRLoader.d.ts +++ b/types/three/examples/jsm/loaders/HDRLoader.d.ts @@ -1,21 +1,11 @@ -import { DataTextureLoader, LoadingManager, TextureDataType } from "three"; - -export interface HDR { - width: number; - height: number; - data: Float32Array | Uint8Array; - header: string; - gamma: number; - exposure: number; - type: TextureDataType; -} +import { DataTextureLoader, DataTextureLoaderTexData, LoadingManager, TextureDataType } from "three"; declare class HDRLoader extends DataTextureLoader { type: TextureDataType; constructor(manager?: LoadingManager); - parse(buffer: ArrayBuffer): HDR; + parse(buffer: ArrayBuffer): DataTextureLoaderTexData; setDataType(type: TextureDataType): this; } diff --git a/types/three/examples/jsm/loaders/KTX2Loader.d.ts b/types/three/examples/jsm/loaders/KTX2Loader.d.ts index f8cdfb635951c1..d9ecc93b885e4e 100644 --- a/types/three/examples/jsm/loaders/KTX2Loader.d.ts +++ b/types/three/examples/jsm/loaders/KTX2Loader.d.ts @@ -54,5 +54,5 @@ export class KTX2Loader extends Loader { /** * Disposes the loader object, de-allocating any Web Workers created. */ - dispose(): this; + dispose(): void; } diff --git a/types/three/examples/jsm/loaders/LWOLoader.d.ts b/types/three/examples/jsm/loaders/LWOLoader.d.ts index ed92b45c038258..31ccde3ab0bef8 100644 --- a/types/three/examples/jsm/loaders/LWOLoader.d.ts +++ b/types/three/examples/jsm/loaders/LWOLoader.d.ts @@ -12,7 +12,13 @@ export interface LWOLoaderParameters { resourcePath?: string; } +/** + * @deprecated The loader has been deprecated and will be removed with r195. Export your LWO files to glTF before using them on the web. + */ export class LWOLoader extends Loader { + /** + * @deprecated The loader has been deprecated and will be removed with r195. Export your LWO files to glTF before using them on the web. + */ constructor(manager?: LoadingManager, parameters?: LWOLoaderParameters); parse(data: ArrayBuffer, path: string, modelName: string): LWO; diff --git a/types/three/examples/jsm/loaders/RGBELoader.d.ts b/types/three/examples/jsm/loaders/RGBELoader.d.ts index 5819174c8c183f..8b71698a242d9a 100644 --- a/types/three/examples/jsm/loaders/RGBELoader.d.ts +++ b/types/three/examples/jsm/loaders/RGBELoader.d.ts @@ -1,10 +1,4 @@ -import { HDR, HDRLoader } from "./HDRLoader.js"; - -/** - * @deprecated RGBELoader has been deprecated. Please use HDRLoader instead. - */ -export interface RGBE extends HDR { -} +import { HDRLoader } from "./HDRLoader.js"; /** * @deprecated RGBELoader has been deprecated. Please use HDRLoader instead. diff --git a/types/three/examples/jsm/loaders/SVGLoader.d.ts b/types/three/examples/jsm/loaders/SVGLoader.d.ts index 216bb6d1869ed4..12d5baaa176ccf 100644 --- a/types/three/examples/jsm/loaders/SVGLoader.d.ts +++ b/types/three/examples/jsm/loaders/SVGLoader.d.ts @@ -1,11 +1,7 @@ -import { BufferGeometry, Loader, LoadingManager, Shape, ShapePath, Vector2, Vector3 } from "three"; - -export interface SVGResultPaths extends ShapePath { - userData?: Record | undefined; -} +import { BufferGeometry, Loader, LoadingManager, MeshBasicMaterial, Shape, ShapePath, Vector2 } from "three"; export interface SVGResult { - paths: SVGResultPaths[]; + paths: ShapePath[]; xml: XMLDocument; } @@ -60,5 +56,12 @@ export class SVGLoader extends Loader { vertexOffset?: number, ): number; + static createFillMaterial(shapePath: ShapePath): MeshBasicMaterial | null; + + static createStrokeMaterial(shapePath: ShapePath): MeshBasicMaterial | null; + + /** + * @deprecated Use shapePath.toShapes() instead. + */ static createShapes(shapePath: ShapePath): Shape[]; } diff --git a/types/three/examples/jsm/loaders/TGALoader.d.ts b/types/three/examples/jsm/loaders/TGALoader.d.ts index f8c7ffd831bdb9..6b120784b8446e 100644 --- a/types/three/examples/jsm/loaders/TGALoader.d.ts +++ b/types/three/examples/jsm/loaders/TGALoader.d.ts @@ -1,7 +1,7 @@ -import { DataTexture, DataTextureLoader, LoadingManager } from "three"; +import { DataTextureLoader, DataTextureLoaderTexData, LoadingManager } from "three"; export class TGALoader extends DataTextureLoader { constructor(manager?: LoadingManager); - parse(data: ArrayBuffer): DataTexture; + parse(data: ArrayBuffer): DataTextureLoaderTexData; } diff --git a/types/three/examples/jsm/loaders/TIFFLoader.d.ts b/types/three/examples/jsm/loaders/TIFFLoader.d.ts index d95e0ea51e756c..9962757faef0b6 100644 --- a/types/three/examples/jsm/loaders/TIFFLoader.d.ts +++ b/types/three/examples/jsm/loaders/TIFFLoader.d.ts @@ -1,16 +1,7 @@ -import { DataTextureLoader, LoadingManager, TextureFilter } from "three"; - -export interface TIFFResult { - width: number; - height: number; - data: Uint8Array; - flipY: true; - magFilter: TextureFilter; - minFilter: TextureFilter; -} +import { DataTextureLoader, DataTextureLoaderTexData, LoadingManager, TextureFilter } from "three"; export class TIFFLoader extends DataTextureLoader { constructor(manager?: LoadingManager); - parse(buffer: Iterable): TIFFResult; + parse(buffer: ArrayBuffer): DataTextureLoaderTexData; } diff --git a/types/three/examples/jsm/loaders/USDLoader.d.ts b/types/three/examples/jsm/loaders/USDLoader.d.ts index ad13001d8d16a2..906a04d8879a5e 100644 --- a/types/three/examples/jsm/loaders/USDLoader.d.ts +++ b/types/three/examples/jsm/loaders/USDLoader.d.ts @@ -3,7 +3,12 @@ import { Group, Loader, LoadingManager } from "three"; declare class USDLoader extends Loader { constructor(manager?: LoadingManager); - parse(buffer: ArrayBuffer | string): Group; + parse( + buffer: ArrayBuffer | string, + path?: string, + onLoad?: (group: Group) => void, + onError?: (err: unknown) => void, + ): Group; } export { USDLoader }; diff --git a/types/three/examples/jsm/misc/TileCreasedNormalsPlugin.d.ts b/types/three/examples/jsm/misc/TileCreasedNormalsPlugin.d.ts new file mode 100644 index 00000000000000..66d67dfaca7629 --- /dev/null +++ b/types/three/examples/jsm/misc/TileCreasedNormalsPlugin.d.ts @@ -0,0 +1,49 @@ +import { Object3D } from "../../../src/core/Object3D.js"; + +export interface TileCreasedNormalsPluginOptions { + creaseAngle?: number | undefined; +} + +/** + * A plugin for `3d-tiles-renderer` that computes creased vertex normals for the + * geometry of each loaded tile: smooth normals everywhere except where faces meet + * at an angle greater than the crease angle. Useful for photogrammetry tile sets + * like Google Photorealistic 3D Tiles which come without vertex normals. + * + * The normals are computed in a Web Worker so tile processing doesn't block the + * main thread. Tiles are displayed once their normals are ready. + * + * ```js + * tiles.registerPlugin( new TileCreasedNormalsPlugin( { creaseAngle: Math.PI / 6 } ) ); + * ``` + * + * @three_import import { TileCreasedNormalsPlugin } from 'three/addons/misc/TileCreasedNormalsPlugin.js'; + */ +export class TileCreasedNormalsPlugin { + /** + * Constructs a new plugin. + * + * @param {Object} [options] - The configuration options. + * @param {number} [options.creaseAngle=Math.PI/3] - The crease angle in radians. + */ + constructor({ creaseAngle }?: TileCreasedNormalsPluginOptions); + /** + * The crease angle in radians. + * + * @type {number} + */ + creaseAngle: number; + /** + * Called by the tiles renderer for each loaded tile model. The tile is + * displayed once the returned promise resolves. + * + * @param {Object3D} scene - The tile model. + * @return {Promise} A promise that resolves when all geometries have creased normals. + */ + processTileModel(scene: Object3D): Promise; + /** + * Called by the tiles renderer when the plugin is unregistered or the + * tiles renderer is disposed. + */ + dispose(): void; +} diff --git a/types/three/examples/jsm/objects/MarchingCubes.d.ts b/types/three/examples/jsm/objects/MarchingCubes.d.ts index f34ad9ac80a6a9..16d02cd4f3977b 100644 --- a/types/three/examples/jsm/objects/MarchingCubes.d.ts +++ b/types/three/examples/jsm/objects/MarchingCubes.d.ts @@ -72,5 +72,5 @@ export class MarchingCubes extends Mesh { generateBufferGeometry(): BufferGeometry; } -export const edgeTable: Int32Array[]; -export const triTable: Int32Array[]; +export const edgeTable: Int32Array; +export const triTable: Int32Array; diff --git a/types/three/examples/jsm/objects/Reflector.d.ts b/types/three/examples/jsm/objects/Reflector.d.ts index a5ff3bf8996201..36d7ea38f47c51 100644 --- a/types/three/examples/jsm/objects/Reflector.d.ts +++ b/types/three/examples/jsm/objects/Reflector.d.ts @@ -1,4 +1,4 @@ -import { BufferGeometry, ColorRepresentation, Mesh, WebGLRenderTarget } from "three"; +import { BufferGeometry, Camera, ColorRepresentation, Mesh, WebGLRenderTarget } from "three"; export interface ReflectorOptions { color?: ColorRepresentation | undefined; @@ -10,12 +10,45 @@ export interface ReflectorOptions { } export class Reflector extends Mesh { - type: "Reflector"; + /** + * This flag can be used for type testing. + * + * @type {boolean} + * @readonly + * @default true + */ + readonly isReflector: boolean; + + /** + * Whether to force an update, no matter if the reflector + * is in view or not. + * + * @type {boolean} + * @default false + */ forceUpdate: boolean; - constructor(geometry?: BufferGeometry, options?: ReflectorOptions); + /** + * Returns the reflector's internal render target. + * + * @return {WebGLRenderTarget} The internal render target + */ + getRenderTarget: () => WebGLRenderTarget; + + /** + * Frees the GPU-related resources allocated by this instance. Call this + * method whenever this instance is no longer used in your app. + */ + dispose: () => void; - getRenderTarget(): WebGLRenderTarget; + /** + * Returns a reflection camera for the given camera. The reflection camera is used to + * render the scene from the reflector's view so correct reflections can be produced. + * + * @param {Camera} camera - The scene's camera. + * @return {Camera} The corresponding reflection camera. + */ + getReflectionCamera: (camera: Camera) => Camera; - dispose(): void; + constructor(geometry: BufferGeometry, options?: ReflectorOptions); } diff --git a/types/three/examples/jsm/objects/SkyMesh.d.ts b/types/three/examples/jsm/objects/SkyMesh.d.ts index 3db13f671ccc75..9b40f26bb821a1 100644 --- a/types/three/examples/jsm/objects/SkyMesh.d.ts +++ b/types/three/examples/jsm/objects/SkyMesh.d.ts @@ -12,7 +12,7 @@ declare class SkyMesh extends Mesh { cloudCoverage: UniformNode<"float", number>; cloudDensity: UniformNode<"float", number>; cloudElevation: UniformNode<"float", number>; - showSunDisc: UniformNode<"float", number>; + showSunDisc: UniformNode<"float", number | boolean>; /** * @deprecated diff --git a/types/three/examples/jsm/physics/RapierPhysics.d.ts b/types/three/examples/jsm/physics/RapierPhysics.d.ts index 76cfb4676b91b5..4c6af517f7db32 100644 --- a/types/three/examples/jsm/physics/RapierPhysics.d.ts +++ b/types/three/examples/jsm/physics/RapierPhysics.d.ts @@ -18,6 +18,7 @@ export interface RapierPhysicsObject { heights: Float32Array, scale: Vector, ) => RAPIER.RigidBody; + applyImpulse: (mesh: Mesh, impulse: Vector, index?: number) => void; } export function RapierPhysics(): Promise; diff --git a/types/three/examples/jsm/tsl/display/AnamorphicNode.d.ts b/types/three/examples/jsm/tsl/display/AnamorphicNode.d.ts deleted file mode 100644 index 38f2fae2f3247a..00000000000000 --- a/types/three/examples/jsm/tsl/display/AnamorphicNode.d.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { Node, TempNode, Vector2 } from "three/webgpu"; - -export default class AnamorphicNode extends TempNode<"vec4"> { - textureNode: Node; - thresholdNode: Node; - scaleNode: Node; - samples: number; - resolutionScale: number; - - constructor(textureNode: Node, thresholdNode: Node, scaleNode: Node, samples: number); - - getTextureNode(): Node; - - setSize(width: number, height: number): void; - - /** - * @deprecated The "resolution" property has been renamed to "resolutionScale" and is now of type `number`. - */ - get resolution(): Vector2; - /** - * @deprecated The "resolution" property has been renamed to "resolutionScale" and is now of type `number`. - */ - set resolution(value: Vector2); -} - -export const anamorphic: ( - node: Node, - threshold?: Node, - scale?: Node, - samples?: Node | number, -) => AnamorphicNode; diff --git a/types/three/examples/jsm/tsl/display/BloomNode.d.ts b/types/three/examples/jsm/tsl/display/BloomNode.d.ts index 291e697a37b1f3..924496fab0825e 100644 --- a/types/three/examples/jsm/tsl/display/BloomNode.d.ts +++ b/types/three/examples/jsm/tsl/display/BloomNode.d.ts @@ -1,25 +1,42 @@ import { Node, TempNode, TextureNode, UniformNode } from "three/webgpu"; declare class BloomNode extends TempNode<"vec4"> { - inputNode: Node; + inputNode: Node<"vec4">; strength: UniformNode<"float", number>; radius: UniformNode<"float", number>; threshold: UniformNode<"float", number>; smoothWidth: UniformNode<"float", number>; - constructor(inputNode: Node, strength?: number, radius?: number, threshold?: number); + highPassFn: ( + params: { + input: Node<"vec4">; + threshold: UniformNode<"float", number>; + smoothWidth: UniformNode<"float", number>; + }, + ) => void; + + constructor( + inputNode: Node, + strength?: UniformNode<"float", number> | number, + radius?: UniformNode<"float", number> | number, + threshold?: UniformNode<"float", number> | number, + ); getTexture(): TextureNode; + setResolutionScale(resolutionScale: number): this; + + getResolutionScale(): number; + setSize(width: number, height: number): void; } export const bloom: ( - node: Node, - strength?: number, - radius?: number, - threshold?: number, + node: Node<"vec4">, + strength?: UniformNode<"float", number> | number, + radius?: UniformNode<"float", number> | number, + threshold?: UniformNode<"float", number> | number, ) => BloomNode; export default BloomNode; diff --git a/types/three/examples/jsm/tsl/display/ImportanceSampledEnvironment.d.ts b/types/three/examples/jsm/tsl/display/ImportanceSampledEnvironment.d.ts new file mode 100644 index 00000000000000..ae7648c9895178 --- /dev/null +++ b/types/three/examples/jsm/tsl/display/ImportanceSampledEnvironment.d.ts @@ -0,0 +1,84 @@ +import { Matrix4, Node, Texture, UniformNode } from "three/webgpu"; + +/** + * Manages a preprocessed HDR environment map (CDF textures, uniforms) and exposes + * TSL helpers for BRDF-direction lookups and MIS importance sampling. + * + * @see {@link https://github.com/gkjohnson/three-gpu-pathtracer} + */ +declare class ImportanceSampledEnvironment { + /** + * @param {boolean} [importanceSampling=false] - When `true`, builds luminance CDF tables and enables MIS env sampling. + */ + constructor(importanceSampling?: boolean); + intensity: UniformNode<"float", number>; + /** + * @param {Texture} hdr - Equirectangular HDR environment map. + */ + updateFrom(hdr: Texture): void; + clear(): void; + /** + * Simple environment lookup along the reflected direction (no MIS). + * + * @param {Object} params + * @param {UniformNode} params.cameraWorldMatrix + * @param {Node} params.viewReflectDir + * @param {Node} [params.sampleWeight] - Optional radiance scale (defaults to 1). + * @return {Node} + */ + sampleReflect(params: { + cameraWorldMatrix: UniformNode<"mat4", Matrix4>; + viewReflectDir: Node<"vec3">; + sampleWeight?: Node<"float">; + }): Node<"vec3">; + /** + * Environment reflection for a screen-space miss using only the BRDF / reflected-ray direction. + * + * @param {Object} params + * @param {UniformNode} params.cameraWorldMatrix + * @param {Node} params.viewReflectDir - View-space GGX-sampled reflected ray. + * @param {Node} params.N - View-space shading normal. + * @param {Node} params.V - View-space direction to camera. + * @param {Node} params.alpha - GGX roughness (alpha). + * @param {Node} params.f0 + * @return {Node} + */ + sampleEnvironmentBRDF(params: { + cameraWorldMatrix: UniformNode<"mat4", Matrix4>; + viewReflectDir: Node<"vec3">; + N: Node<"vec3">; + V: Node<"vec3">; + alpha: Node<"float">; + f0: Node<"vec3">; + }): Node<"vec3">; + /** + * Environment reflection for a screen-space miss, estimated with multiple importance + * sampling (MIS) between the BRDF / reflected-ray direction and the env-luminance CDF + * direction. Both techniques use consistent solid-angle PDFs (`D·G1(N·V)/(4·N·V)`), so + * the power heuristic is unbiased. Adapted from three-gpu-pathtracer. + * + * @see {@link https://github.com/gkjohnson/three-gpu-pathtracer} + * + * @param {Object} params + * @param {UniformNode} params.cameraWorldMatrix + * @param {Node} params.viewReflectDir - View-space GGX-sampled reflected ray. + * @param {Node} params.N - View-space shading normal. + * @param {Node} params.V - View-space direction to camera. + * @param {Node} params.alpha - GGX roughness (alpha). + * @param {Node} params.f0 + * @param {Node} params.Xi2 - Second blue-noise sample (zw used for the CDF). + * @return {Node} + */ + sampleEnvironmentMIS(params: { + cameraWorldMatrix: UniformNode<"mat4", Matrix4>; + viewReflectDir: Node<"vec3">; + N: Node<"vec3">; + V: Node<"vec3">; + alpha: Node<"float">; + f0: Node<"vec3">; + Xi2: Node<"vec4">; + }): Node<"vec3">; + dispose(): void; +} + +export default ImportanceSampledEnvironment; diff --git a/types/three/examples/jsm/tsl/display/RecurrentDenoiseNode.d.ts b/types/three/examples/jsm/tsl/display/RecurrentDenoiseNode.d.ts new file mode 100644 index 00000000000000..790b83c60703d1 --- /dev/null +++ b/types/three/examples/jsm/tsl/display/RecurrentDenoiseNode.d.ts @@ -0,0 +1,89 @@ +import { Camera, Node, RenderTarget, TempNode, TextureNode, UniformNode } from "three/webgpu"; + +export type DenoiseMode = "diffuse" | "specular"; + +export type DenoiseAlphaSource = "raylength" | "ao" | "none"; + +export interface RecurrentDenoiseNodeOptions { + depth?: Node<"float"> | Node<"vec4"> | null | undefined; + normal?: Node<"vec3"> | Node<"vec4"> | null | undefined; + metalRoughness?: Node<"vec2"> | null | undefined; + diffuse?: Node<"vec4"> | null | undefined; + raw?: Node<"vec4"> | null | undefined; + mode?: DenoiseMode | undefined; + accumulate?: boolean | undefined; +} + +/** + * Post processing node for denoising temporally-accumulated screen-space effects + * such as SSGI (ambient occlusion / indirect diffuse) and SSR (specular reflections). + * + * The denoising kernel is selected at construction time via `mode`: + * `'diffuse'` (SSGI) or `'specular'` (SSR). The kernel uses a fixed 8-sample Vogel disk. + * + * @augments TempNode + * @three_import import { recurrentDenoise } from 'three/addons/tsl/display/RecurrentDenoiseNode.js'; + */ +declare class RecurrentDenoiseNode extends TempNode<"vec4"> { + readonly isRecurrentDenoiseNode: boolean; + camera: Camera; + + /** + * Denoising kernel type. + * + * @type {DenoiseMode} + */ + mode: DenoiseMode; + + /** + * When `true`, apply temporal blending after spatial denoising. When `false`, output spatially + * filtered colour only (alpha is passed through from the input temporal pass). + * + * @type {boolean} + */ + accumulate: boolean; + + textureNode: Node<"vec4">; + depthNode: Node<"float"> | Node<"vec4"> | null; + normalNode: Node<"vec3"> | Node<"vec4"> | null; + rawNode: TextureNode | null; + roughnessMetalnessNode: Node<"vec2"> | null; + diffuseNode: Node<"vec4"> | null; + + lumaPhi: UniformNode<"float", number>; + depthPhi: UniformNode<"float", number>; + normalPhi: UniformNode<"float", number>; + radius: UniformNode<"float", number>; + alphaPhi: UniformNode<"float", number>; + roughnessPhi: UniformNode<"float", number>; + diffusePhi: UniformNode<"float", number>; + adapt: UniformNode<"float", number>; + smoothDisocclusions: UniformNode<"bool", boolean>; + strength: UniformNode<"float", number>; + maxFrames: UniformNode<"float", number>; + + /** + * Which channel of the raw texture drives alpha-based edge stopping. + * `'raylength'` — alpha encodes SSR ray length; `'ao'` — alpha encodes AO factor; + * `'none'` — skip alpha-based edge stopping. + * + * @type {DenoiseAlphaSource} + * @default 'raylength' + */ + alphaSource: DenoiseAlphaSource; + + flickerSuppression: UniformNode<"float", number>; + adaptiveTrust: UniformNode<"float", number>; + + constructor(inputTexture: Node<"vec4">, camera: Camera, options?: RecurrentDenoiseNodeOptions); + + getRenderTarget(): RenderTarget; +} + +export default RecurrentDenoiseNode; + +export const recurrentDenoise: ( + inputTexture: Node<"vec4">, + camera: Camera, + options?: RecurrentDenoiseNodeOptions, +) => RecurrentDenoiseNode; diff --git a/types/three/examples/jsm/tsl/display/SSAAPassNode.d.ts b/types/three/examples/jsm/tsl/display/SSAAPassNode.d.ts index 4f53e31abd2d6c..27a08b27f0ea1c 100644 --- a/types/three/examples/jsm/tsl/display/SSAAPassNode.d.ts +++ b/types/three/examples/jsm/tsl/display/SSAAPassNode.d.ts @@ -5,8 +5,6 @@ declare class SSAAPassNode extends PassNode { sampleLevel: number; unbiased: boolean; - clearColor: Color; - clearAlpha: number; sampleWeight: UniformNode<"float", number>; diff --git a/types/three/examples/jsm/tsl/display/SSGINode.d.ts b/types/three/examples/jsm/tsl/display/SSGINode.d.ts index 6a3df43dfbfc31..9a6180dceed3e6 100644 --- a/types/three/examples/jsm/tsl/display/SSGINode.d.ts +++ b/types/three/examples/jsm/tsl/display/SSGINode.d.ts @@ -1,4 +1,4 @@ -import { Node, PerspectiveCamera, TempNode, UniformNode } from "three/webgpu"; +import { Node, PerspectiveCamera, TempNode, TextureNode, UniformNode } from "three/webgpu"; declare class SSGINode extends TempNode<"vec4"> { beautyNode: Node; @@ -18,6 +18,9 @@ declare class SSGINode extends TempNode<"vec4"> { useTemporalFiltering: boolean; constructor(beautyNode: Node, depthNode: Node, normalNode: Node, camera: PerspectiveCamera); + + getAONode(): TextureNode; + getGINode(): TextureNode; } export default SSGINode; diff --git a/types/three/examples/jsm/tsl/display/SSRNode.d.ts b/types/three/examples/jsm/tsl/display/SSRNode.d.ts index b892ec18f87bc7..1390ce61535278 100644 --- a/types/three/examples/jsm/tsl/display/SSRNode.d.ts +++ b/types/three/examples/jsm/tsl/display/SSRNode.d.ts @@ -1,42 +1,315 @@ -import { Camera, Node, TempNode, TextureNode, UniformNode } from "three/webgpu"; +import { Camera, Node, RenderTarget, TempNode, Texture, TextureNode, UniformNode } from "three/webgpu"; -declare class SSRNode extends TempNode<"vec4"> { - colorNode: Node; - depthNode: Node; - normalNode: Node; - metalnessNode: Node; - roughnessNode: Node | null; - camera: Camera | null; +export interface SSRNodeOptions { + /** + * - When `false`, traces a single mirror reflection and softens roughness with a blur pass (first-generation SSR). When `true`, varies the reflection direction per pixel with stochastic GGX rays (second-generation SSR); higher quality on rough/glossy surfaces but noisier, so it expects a temporal/spatial denoiser downstream. + */ + stochastic?: boolean | undefined; + /** + * - Per-pixel metalness. Drives GGX reflection sampling and, with `reflectNonMetals=false`, the non-metal early-out. + */ + metalnessNode?: Node<"float"> | undefined; + /** + * - Per-pixel roughness. Drives GGX sampling and the blur mip selection. + */ + roughnessNode?: Node<"float"> | undefined; + /** + * - Only used when `stochastic=false`. When `false`, non-metallic surfaces are discarded for a noticeable performance gain; set `true` to also reflect dielectrics (e.g. marble, polished wood, plastic). + */ + reflectNonMetals?: boolean | undefined; + /** + * - Equirectangular HDR environment map with CPU-side `image.data` (e.g. from RGBELoader). Not compatible with PMREM / `scene.environment` cubemaps. + */ + environmentNode?: Texture | undefined; + /** + * - When `true`, precomputes env-luminance CDF tables and uses MIS for environment misses. Build-time only. + */ + envImportanceSampling?: boolean | undefined; + /** + * - Scene diffuse / base color. Defaults to `vec3(1)` in the shader when omitted. + */ + diffuseNode?: Node<"vec4"> | undefined; + /** + * - Sub-step binary-search refinement of detected hits. Compile-time constant (baked into the shader at construction). + */ + binaryRefine?: boolean | undefined; + /** + * - Camera the scene is rendered with. Inferred from the color pass when omitted. + */ + camera?: Camera | undefined; +} +/** + * Post processing node for computing screen space reflections (SSR). + * + * Reference: {@link https://lettier.github.io/3d-game-shaders-for-beginners/screen-space-reflection.html} + * + * @augments TempNode + * @three_import import { ssr } from 'three/addons/tsl/display/SSRNode.js'; + */ +declare class SSRNode extends TempNode<"vec4"> { + /** + * Constructs a new SSR node. + * + * @param {Node} colorNode - The node that represents the beauty pass. + * @param {Node} depthNode - A node that represents the beauty pass's depth. + * @param {Node} normalNode - A node that represents the beauty pass's normals. + * @param {SSRNodeOptions} [options] - Optional inputs for material and environment data. + */ + constructor( + colorNode: Node<"vec4">, + depthNode: Node<"float"> | Node<"vec4">, + normalNode: Node<"vec3">, + options?: SSRNodeOptions, + ); + /** + * When `true`, the reflection direction is varied per pixel with stochastic GGX rays + * (second-generation SSR). When `false`, a single mirror reflection is traced and + * roughness is softened with a blur pass (first-generation SSR). + * + * @type {boolean} + */ + stochastic: boolean; + /** + * When `true`, env-luminance CDF tables are built and MIS is used for environment misses. + * Fixed at construction time. + * + * @type {boolean} + */ + envImportanceSampling: boolean; + /** + * The node that represents the beauty pass. + * + * @type {Node} + */ + colorNode: Node<"vec4">; + /** + * A node that represents the scene's diffuse color (typically the MRT `diffuseColor` attachment). + * When `null`, the shader uses `vec3(1)`. + * + * @type {?Node} + */ + diffuseNode: Node<"vec4"> | null; + /** + * A node that represents the beauty pass's depth. + * + * @type {Node} + */ + depthNode: Node<"float"> | Node<"vec4">; + /** + * A node that represents the beauty pass's normals. + * + * @type {Node} + */ + normalNode: Node<"vec3">; + /** + * Per-pixel metalness, used to drive the GGX reflection sampling and the non-metal + * early-out. When `null`, the shader treats surfaces as non-metallic. + * + * @type {?Node} + */ + metalnessNode: Node<"float"> | null; + /** + * Per-pixel roughness, used to drive the GGX reflection sampling and the blur mip + * selection. When `null`, the shader treats surfaces as fully smooth. + * + * @type {?Node} + */ + roughnessNode: Node<"float"> | null; + /** + * The resolution scale. Valid values are in the range + * `[0,1]`. `1` means best quality but also results in + * more computational overhead. Setting to `0.5` means + * the effect is computed in half-resolution. + * + * @type {number} + * @default 1 + */ resolutionScale: number; - + /** + * Controls how far a fragment can reflect. Increasing this value result in more + * computational overhead but also increases the reflection distance. + * + * @type {UniformNode} + */ maxDistance: UniformNode<"float", number>; + /** + * Controls the cutoff between what counts as a possible reflection hit and what does not. + * + * @type {UniformNode} + */ thickness: UniformNode<"float", number>; - opacity: UniformNode<"float", number>; + /** + * A multiplier for the overall reflection intensity. `1` leaves the + * reflections unchanged, lower values dim them and higher values boost them. + * + * @type {UniformNode} + * @default 1 + */ + intensity: UniformNode<"float", number>; + /** + * Screen-edge fade width, in UV units. As a screen-space hit approaches a screen + * border, the reflection is faded over this distance — either toward the environment + * reflection ({@link SSRNode#screenEdgeFadeBlack} `false`) or to zero intensity + * (`true`). `0` disables it. + * + * @type {UniformNode} + * @default 0.2 + */ + screenEdgeFade: UniformNode<"float", number>; + /** + * Absolute env luminance cap. HDR env samples above this are scaled down (hue preserved). + * + * @type {UniformNode} + * @default 10 + */ + maxLuminance: UniformNode<"float", number>; + /** + * This parameter controls how detailed the raymarching process works. + * The value ranges is `[0,1]` where `1` means best quality (the maximum number + * of raymarching iterations/samples) and `0` means no samples at all. + * + * A quality of `0.5` is usually sufficient for most use cases. Try to keep + * this parameter as low as possible. Larger values result in noticeable more + * overhead. + * + * @type {UniformNode} + */ quality: UniformNode<"float", number>; - blurQuality: UniformNode<"float", number>; - - constructor( - colorNode: Node, - depthNode: Node, - normalNode: Node, - metalnessNode: Node, - roughnessNode?: Node | null, - camera?: Camera | null, - ); - + /** + * Mirror bias for the stochastic GGX sampling. Concentrates the reflected rays toward + * the lobe's narrow (near-mirror) core, trading a small amount of bias for less noise. + * `0` samples the full VNDF lobe; values toward `1` tighten the cone. Range `[0,1]`. + * + * @type {UniformNode} + * @default 0.5 + */ + mirrorBias: UniformNode<"float", number>; + /** + * HDR environment map for screen-space misses. + * + * @type {?Texture} + */ + environmentNode: Texture | null; + /** + * A node that represents the history texture for multi-bounce reflections. + * + * @type {?Texture} + */ + historyTexture: Texture | null; + /** + * A node that represents the velocity texture for reprojection. + * + * @type {?Node} + */ + velocityTexture: Node<"vec2"> | Node<"vec4"> | null; + /** + * The camera the scene is rendered with. + * + * @type {Camera} + */ + camera: Camera; + /** + * Intensity multiplier applied to environment-map reflections on screen-space + * misses and at screen edges. Defaults to π to match the former hardcoded multiplier. + * + * @type {UniformNode} + * @default Math.PI + */ + environmentIntensity: UniformNode<"float", number>; + /** + * Non-linear step distribution exponent (compile-time constant). See the backing + * field for details. Assigning a new value recompiles the SSR material. + * + * @type {number} + */ + get stepExponent(): number; + set stepExponent(value: number); + /** + * Blur kernel size (compile-time constant). Assigning a new value recompiles the + * blur material. + * + * @type {number} + */ + get blurQuality(): number; + set blurQuality(value: number); + /** + * Whether SSR fades to black near screen borders (compile-time constant). Assigning + * a new value recompiles the SSR material. + * + * @type {boolean} + */ + get screenEdgeFadeBlack(): boolean; + set screenEdgeFadeBlack(value: boolean); + /** + * Whether sub-step binary-search hit refinement is enabled (compile-time constant). + * Assigning a new value rebuilds the SSR material. + * + * @type {boolean} + */ + get binaryRefine(): boolean; + set binaryRefine(value: boolean); + /** + * Whether dielectrics are reflected in the non-stochastic path (compile-time constant). + * Assigning a new value rebuilds the SSR material. + * + * @type {boolean} + */ + get reflectNonMetals(): boolean; + set reflectNonMetals(value: boolean); + /** + * Returns the result of the effect as a texture node. + * + * @return {PassTextureNode} A texture node that represents the result of the effect. + */ getTextureNode(): TextureNode; - + /** + * Sets the size of the effect. + * + * @param {number} width - The width of the effect. + * @param {number} height - The height of the effect. + */ setSize(width: number, height: number): void; + /** + * Wires the feedback inputs for multi-bounce reflections: the previous frame's + * denoised result (`history`) and the velocity buffer used to reproject it + * (`velocity`). `history` accepts the producing node (e.g. a + * {@link RecurrentDenoiseNode}) — its output render target is used — or a raw + * texture. Pass `null` for both to disable multi-bounce. + * + * @param {Texture} history + * @param {Node} velocity + */ + setHistory( + history: Texture | { getRenderTarget(): { texture: Texture } }, + velocity: Node<"vec2"> | Node<"vec4">, + ): void; + /** + * Sets the environment map for importance-sampled env lighting when + * screen-space rays miss. Call this whenever the scene's env map changes. + * + * Uses {@link ImportanceSampledEnvironment} (CDF + MIS adapted from + * [three-gpu-pathtracer](https://github.com/gkjohnson/three-gpu-pathtracer)). + * + * @param {Texture|null} hdr - The equirectangular HDR environment map, or null to disable. + * @see {@link https://github.com/gkjohnson/three-gpu-pathtracer} + */ + setEnvMap(hdr: Texture | null): void; + /** + * Intensity multiplier for the importance-sampled env contribution. + * Only available after {@link setEnvMap} has been called. + * + * @type {?UniformNode} + */ + get envMapIntensity(): UniformNode<"float", number> | null; + getRenderTarget(): RenderTarget; } export default SSRNode; -export const ssr: ( - colorNode: Node, - depthNode: Node, - normalNode: Node, - metalnessNode: Node, - roughnessNode?: Node | null, - camera?: Camera | null, -) => SSRNode; +export function ssr( + colorNode: Node<"vec4">, + depthNode: Node<"float"> | Node<"vec4">, + normalNode: Node<"vec3">, + options?: SSRNodeOptions, +): SSRNode; diff --git a/types/three/examples/jsm/tsl/display/TRAANode.d.ts b/types/three/examples/jsm/tsl/display/TRAANode.d.ts index 2939b4daf9fdc8..5af865cfc84855 100644 --- a/types/three/examples/jsm/tsl/display/TRAANode.d.ts +++ b/types/three/examples/jsm/tsl/display/TRAANode.d.ts @@ -1,6 +1,6 @@ import { Camera, Node, TempNode, TextureNode } from "three/webgpu"; -declare class TRAANode extends TempNode { +declare class TRAANode extends TempNode<"vec4"> { readonly isTRAANode: true; beautyNode: TextureNode; diff --git a/types/three/examples/jsm/tsl/display/TemporalReprojectNode.d.ts b/types/three/examples/jsm/tsl/display/TemporalReprojectNode.d.ts new file mode 100644 index 00000000000000..0b719f8335b653 --- /dev/null +++ b/types/three/examples/jsm/tsl/display/TemporalReprojectNode.d.ts @@ -0,0 +1,64 @@ +import { Camera, Node, TempNode, Texture, TextureNode, UniformNode } from "three/webgpu"; + +export type TemporalReprojectMode = "diffuse" | "specular"; + +export interface TemporalReprojectNodeOptions { + mode?: TemporalReprojectMode | undefined; + hitPointReprojection?: boolean | undefined; + accumulate?: boolean | undefined; +} + +declare class TemporalReprojectNode extends TempNode<"vec4"> { + readonly isTemporalReprojectNode: boolean; + + beautyNode: Node<"vec4">; + depthNode: TextureNode; + normalNode: TextureNode; + velocityNode: TextureNode; + camera: Camera; + + mode: TemporalReprojectMode; + + /** + * When `true`, resolve output is copied into the internal history buffer each frame. + * When `false`, history is supplied externally via {@link TemporalReprojectNode#setHistoryTexture}. + * + * @type {boolean} + */ + accumulate: boolean; + + maxVelocityLength: number; + + maxFrames: UniformNode<"float", number>; + hitPointReprojection: UniformNode<"bool", boolean>; + clampIntensity: UniformNode<"float", number>; + flickerSuppression: UniformNode<"float", number>; + + constructor( + beautyNode: Node<"vec4">, + depthNode: TextureNode, + normalNode: TextureNode, + velocityNode: TextureNode, + camera: Camera, + options?: TemporalReprojectNodeOptions, + ); + + /** + * Supplies an external history source (e.g. a {@link RecurrentDenoiseNode} or its + * texture). Only used when {@link TemporalReprojectNode#accumulate} is `false`. + * + * @param {?(Object|Texture)} source + */ + setHistoryTexture(source: Texture | { getRenderTarget(): { texture: Texture } }): void; +} + +export default TemporalReprojectNode; + +export const temporalReproject: ( + beautyNode: Node<"vec4">, + depthNode: TextureNode, + normalNode: TextureNode, + velocityNode: TextureNode, + camera: Camera, + options?: TemporalReprojectNodeOptions, +) => TemporalReprojectNode; diff --git a/types/three/examples/jsm/tsl/lighting/ClusteredLightsNode.d.ts b/types/three/examples/jsm/tsl/lighting/ClusteredLightsNode.d.ts new file mode 100644 index 00000000000000..f7d3dd5599d07d --- /dev/null +++ b/types/three/examples/jsm/tsl/lighting/ClusteredLightsNode.d.ts @@ -0,0 +1,54 @@ +import { Light, LightsNode, Node } from "three/webgpu"; + +/** + * A custom version of `LightsNode` implementing Forward+ clustered shading: + * the view frustum is subdivided into a 3D grid of clusters (X × Y screen tiles + * times an exponentially-spaced set of Z depth slices), and each cluster holds + * only the point lights whose spheres intersect it. At shading time each fragment + * looks up its cluster and loops over just that cluster's lights. Unlike 2D tiled + * lighting, clustered shading culls lights that share screen pixels but lie at + * different depths — suitable for 3D scenes with real depth complexity. + * + * @augments LightsNode + */ +declare class ClusteredLightsNode extends LightsNode { + materialLights: Light[]; + clusteredLights: Light[]; + maxLights: number; + tileSize: number; + zSlices: number; + maxLightsPerCluster: number; + + /** + * Constructs a new clustered lights node. + * + * @param {number} [maxLights=1024] - Maximum number of point lights. + * @param {number} [tileSize=32] - Screen tile size in pixels (cluster XY size). + * @param {number} [zSlices=24] - Number of exponential depth slices. + * @param {number} [maxLightsPerCluster=64] - Per-cluster light-list capacity. + */ + constructor(maxLights?: number, tileSize?: number, zSlices?: number, maxLightsPerCluster?: number); + + getClusterLightCount(zSliceNode: Node<"int">): Node<"int">; + + setSize(width: number, height: number): this; +} + +/** + * TSL function that creates a clustered lights node. + * + * @function + * @param {number} [maxLights=1024] - Maximum number of point lights. + * @param {number} [tileSize=32] - Screen tile size in pixels. + * @param {number} [zSlices=24] - Depth slice count. + * @param {number} [maxLightsPerCluster=64] - Per-cluster light-list capacity. + * @return {ClusteredLightsNode} The clustered lights node. + */ +export const clusteredLights: ( + maxLights?: number, + tileSize?: number, + zSlices?: number, + maxLightsPerCluster?: number, +) => ClusteredLightsNode; + +export default ClusteredLightsNode; diff --git a/types/three/examples/jsm/tsl/lighting/TiledLightsNode.d.ts b/types/three/examples/jsm/tsl/lighting/TiledLightsNode.d.ts deleted file mode 100644 index d7f1c49309bb0c..00000000000000 --- a/types/three/examples/jsm/tsl/lighting/TiledLightsNode.d.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { LightsNode, Node } from "three/webgpu"; - -export const circleIntersectsAABB: ( - circleCenter: Node, - radius: Node, - minBounds: Node, - maxBounds: Node, -) => Node; - -declare class TiledLightsNode extends LightsNode { - constructor(maxLights?: number, tileSize?: number); - - updateLightsTexture(): void; - - getBlock(block?: number): Node<"ivec4">; - - setSize(width: number, height: number): this; -} - -export default TiledLightsNode; - -export const tiledLights: (maxLights?: number, tileSize?: number) => TiledLightsNode; diff --git a/types/three/examples/jsm/tsl/math/curlNoise.d.ts b/types/three/examples/jsm/tsl/math/curlNoise.d.ts new file mode 100644 index 00000000000000..f1f8d2ed645d3a --- /dev/null +++ b/types/three/examples/jsm/tsl/math/curlNoise.d.ts @@ -0,0 +1,38 @@ +import { Node, Vector3, Vector4 } from "three/webgpu"; + +/** + * Permutation polynomial for noise generation. + * + * @tsl + * @function + * @param {Node} x - Input vector. + * @return {Node} Permuted vector. + */ +export const permute: (x: Node<"vec4"> | Vector4) => Node<"vec4">; +/** + * 3D Simplex noise implementation in TSL. + * + * @tsl + * @function + * @param {Node} v - Input coordinate vector. + * @return {Node} Simplex noise value. + */ +export const snoise: (v: Node<"vec3"> | Vector3) => Node<"float">; +/** + * 3D Simplex noise vector. Returns a vec3 containing three independent noise samples. + * + * @tsl + * @function + * @param {Node} x - Input coordinate vector. + * @return {Node} Vector of three noise values. + */ +export const snoiseVec3: (x: Node<"vec3"> | Vector3) => Node<"vec3">; +/** + * 3D Curl noise in TSL. Generates a divergence-free vector field from simplex noise. + * + * @tsl + * @function + * @param {Node} p - Input coordinate vector. + * @return {Node} Curl noise vector. + */ +export const curlNoise: (p: Node<"vec3"> | Vector3) => Node<"vec3">; diff --git a/types/three/examples/jsm/tsl/utils/GroundedSkybox.d.ts b/types/three/examples/jsm/tsl/utils/GroundedSkybox.d.ts new file mode 100644 index 00000000000000..0853163b60f54b --- /dev/null +++ b/types/three/examples/jsm/tsl/utils/GroundedSkybox.d.ts @@ -0,0 +1,17 @@ +import { Node } from "three/webgpu"; + +/** + * @module GroundedSkybox + * @three_import import { getGroundProjectedNormal } from 'three/addons/tsl/utils/GroundedSkybox.js'; + */ +/** + * Projects the world position onto a sphere whose bottom is clipped by a ground disk, + * then returns a vector usable for sampling an environment cube map. + * + * @tsl + * @function + * @param {Node} radiusNode - The radius of the projection sphere. Must be large enough to ensure the scene's camera stays inside. + * @param {Node} heightNode - The height is how far the camera that took the photo was above the ground. A larger value will magnify the downward part of the image. + * @return {Node} A direction vector for sampling the environment cube map. + */ +export const getGroundProjectedNormal: (radiusNode: Node<"float">, heightNode: Node<"float">) => Node<"vec3">; diff --git a/types/three/examples/jsm/tsl/utils/RNoise.d.ts b/types/three/examples/jsm/tsl/utils/RNoise.d.ts new file mode 100644 index 00000000000000..645822e466796e --- /dev/null +++ b/types/three/examples/jsm/tsl/utils/RNoise.d.ts @@ -0,0 +1,12 @@ +import { UniformNode, Vector2 } from "three/webgpu"; + +/** + * Returns a TSL function that samples texture-free analytic R² noise. + * Index 0 uses continuous screen pixels; other indices tile-shift with an R² + * sequence into a 64×64 period. Values are four independent R² dimensions + * hashed from the sample coordinates. + * + * @param {UniformNode} resolution + * @param {number} [seed=0] - Added to the coordinate hash so each pass gets an independent R² phase. + */ +export function bindAnalyticNoise(resolution: UniformNode<"vec2", Vector2>, seed?: number): () => void; diff --git a/types/three/examples/jsm/tsl/utils/SpecularHelpers.d.ts b/types/three/examples/jsm/tsl/utils/SpecularHelpers.d.ts new file mode 100644 index 00000000000000..5369ca99bb7820 --- /dev/null +++ b/types/three/examples/jsm/tsl/utils/SpecularHelpers.d.ts @@ -0,0 +1,20 @@ +/** + * Specular / microfacet BRDF helpers: VNDF sampling, GTR distribution, Smith geometry, + * Fresnel, reflection importance sampling, parallax-corrected ray-length terms, and + * equirectangular environment sampling / MIS helpers. + * Pure TSL functions of their inputs (no scene/camera state). + */ +/** + * Sentinel ray length the SSR pass writes for environment misses (no screen-space hit), set far above + * any real hit distance so a single magnitude test separates misses from hits and survives `.max( 0 )`. + * + * @type {number} + */ +export const ENV_RAY_LENGTH: number; +/** + * Classification threshold for {@link ENV_RAY_LENGTH}: above this is an env miss, below a real hit. + * An order of magnitude under the sentinel, robust to fp16 storage and bilinear blending at borders. + * + * @type {number} + */ +export const ENV_RAY_LENGTH_THRESHOLD: number; diff --git a/types/three/examples/jsm/webxr/WebGLXRFallback.d.ts b/types/three/examples/jsm/webxr/WebGLXRFallback.d.ts new file mode 100644 index 00000000000000..1c7c067d906c5a --- /dev/null +++ b/types/three/examples/jsm/webxr/WebGLXRFallback.d.ts @@ -0,0 +1,14 @@ +import { WebGPURenderer } from "three/webgpu"; + +/** + * Sets up a construction-time WebGL fallback for WebGPU XR examples. + * + * @param {WebGPURenderer} renderer - The initial renderer. + * @param {Function} createFallbackRenderer - A function that returns a new renderer with a WebGL backend. + * @param {Function} onFallback - A function that installs the new renderer in the app. + */ +export function setupWebGLXRFallback( + renderer: WebGPURenderer, + createFallbackRenderer: (renderer: WebGPURenderer) => WebGPURenderer, + onFallback?: (fallbackRenderer: WebGPURenderer, renderer: WebGPURenderer) => Promise | void, +): void; diff --git a/types/three/package.json b/types/three/package.json index fae70643eb4c01..fc1125abbfaf38 100644 --- a/types/three/package.json +++ b/types/three/package.json @@ -1,7 +1,7 @@ { "private": true, "name": "@types/three", - "version": "0.184.9999", + "version": "0.185.9999", "projects": [ "https://threejs.org/" ], diff --git a/types/three/src/Three.TSL.d.ts b/types/three/src/Three.TSL.d.ts index 796ce8c80b4fd0..acd4a55d937673 100644 --- a/types/three/src/Three.TSL.d.ts +++ b/types/three/src/Three.TSL.d.ts @@ -47,6 +47,7 @@ export const addNodeElement: typeof TSL.addNodeElement; export const agxToneMapping: typeof TSL.agxToneMapping; export const all: typeof TSL.all; export const alphaT: typeof TSL.alphaT; +export const ambientOcclusion: typeof TSL.ambientOcclusion; export const and: typeof TSL.and; export const anisotropy: typeof TSL.anisotropy; export const anisotropyB: typeof TSL.anisotropyB; @@ -54,7 +55,6 @@ export const anisotropyT: typeof TSL.anisotropyT; export const any: typeof TSL.any; export const append: typeof TSL.append; export const array: typeof TSL.array; -export const arrayBuffer: typeof TSL.arrayBuffer; export const asin: typeof TSL.asin; export const asinh: typeof TSL.asinh; export const assign: typeof TSL.assign; @@ -177,6 +177,7 @@ export const dynamicBufferAttribute: typeof TSL.dynamicBufferAttribute; export const element: typeof TSL.element; export const emissive: typeof TSL.emissive; export const equal: typeof TSL.equal; +export const equirectDirection: typeof TSL.equirectDirection; export const equirectUV: typeof TSL.equirectUV; export const exp: typeof TSL.exp; export const exp2: typeof TSL.exp2; @@ -320,7 +321,6 @@ export const min: typeof TSL.min; export const mix: typeof TSL.mix; export const mixElement: typeof TSL.mixElement; export const mod: typeof TSL.mod; -export const modInt: typeof TSL.modInt; export const modelDirection: typeof TSL.modelDirection; export const modelNormalMatrix: typeof TSL.modelNormalMatrix; export const modelPosition: typeof TSL.modelPosition; @@ -378,6 +378,7 @@ export const mx_worley_noise_float: typeof TSL.mx_worley_noise_float; export const mx_worley_noise_vec2: typeof TSL.mx_worley_noise_vec2; export const mx_worley_noise_vec3: typeof TSL.mx_worley_noise_vec3; export const negate: typeof TSL.negate; +export const negateOnBackSide: typeof TSL.negateOnBackSide; export const neutralToneMapping: typeof TSL.neutralToneMapping; export const nodeArray: typeof TSL.nodeArray; export const nodeImmutable: typeof TSL.nodeImmutable; @@ -419,9 +420,12 @@ export const oscTriangle: typeof TSL.oscTriangle; export const output: typeof TSL.output; export const outputStruct: typeof TSL.outputStruct; export const overloadingFn: typeof TSL.overloadingFn; +export const overrideNode: typeof TSL.overrideNode; +export const overrideNodes: typeof TSL.overrideNodes; export const packHalf2x16: typeof TSL.packHalf2x16; export const packSnorm2x16: typeof TSL.packSnorm2x16; export const packUnorm2x16: typeof TSL.packUnorm2x16; +export const packNormalToRGB: typeof TSL.packNormalToRGB; export const parabola: typeof TSL.parabola; export const parallaxDirection: typeof TSL.parallaxDirection; export const parallaxUV: typeof TSL.parallaxUV; @@ -518,7 +522,7 @@ export const stepElement: typeof TSL.stepElement; export const storage: typeof TSL.storage; export const storageBarrier: typeof TSL.storageBarrier; export const storageTexture: typeof TSL.storageTexture; -export const string: typeof TSL.string; +export const storageTexture3D: typeof TSL.storageTexture3D; export const struct: typeof TSL.struct; export const sub: typeof TSL.sub; export const subgroupAdd: typeof TSL.subgroupAdd; @@ -568,6 +572,8 @@ export const toneMappingExposure: typeof TSL.toneMappingExposure; export const toonOutlinePass: typeof TSL.toonOutlinePass; export const transformDirection: typeof TSL.transformDirection; export const transformNormal: typeof TSL.transformNormal; +export const transformNormalByInverseViewMatrix: typeof TSL.transformNormalByInverseViewMatrix; +export const transformNormalByViewMatrix: typeof TSL.transformNormalByViewMatrix; export const transformNormalToView: typeof TSL.transformNormalToView; export const transformedClearcoatNormalView: typeof TSL.transformedClearcoatNormalView; export const transformedNormalView: typeof TSL.transformedNormalView; @@ -589,6 +595,7 @@ export const uniformTexture: typeof TSL.uniformTexture; export const unpackHalf2x16: typeof TSL.unpackHalf2x16; export const unpackSnorm2x16: typeof TSL.unpackSnorm2x16; export const unpackUnorm2x16: typeof TSL.unpackUnorm2x16; +export const unpackRGBToNormal: typeof TSL.unpackRGBToNormal; export const unpremultiplyAlpha: typeof TSL.unpremultiplyAlpha; export const userData: typeof TSL.userData; export const uv: typeof TSL.uv; diff --git a/types/three/src/Three.WebGPU.Nodes.d.ts b/types/three/src/Three.WebGPU.Nodes.d.ts index c8e003076f7881..3139398e180fd5 100644 --- a/types/three/src/Three.WebGPU.Nodes.d.ts +++ b/types/three/src/Three.WebGPU.Nodes.d.ts @@ -8,11 +8,11 @@ export { default as Lighting } from "./renderers/common/Lighting.js"; export { default as PostProcessing } from "./renderers/common/PostProcessing.js"; export { default as QuadMesh } from "./renderers/common/QuadMesh.js"; export { default as ReadbackBuffer } from "./renderers/common/ReadbackBuffer.js"; -export type { default as Renderer } from "./renderers/common/Renderer.js"; +export type { default as Renderer, RendererParameters } from "./renderers/common/Renderer.js"; export { default as RenderPipeline } from "./renderers/common/RenderPipeline.js"; export { default as WebGLBackend } from "./renderers/webgl-fallback/WebGLBackend.js"; export { default as WebGPUBackend } from "./renderers/webgpu/WebGPUBackend.js"; -export { default as WebGPURenderer } from "./renderers/webgpu/WebGPURenderer.Nodes.js"; +export { default as WebGPURenderer, WebGPURendererParameters } from "./renderers/webgpu/WebGPURenderer.Nodes.js"; import * as RendererUtils from "./renderers/common/RendererUtils.js"; export { RendererUtils }; export { default as IESSpotLight } from "./lights/webgpu/IESSpotLight.js"; diff --git a/types/three/src/Three.WebGPU.d.ts b/types/three/src/Three.WebGPU.d.ts index 9dad07692baaf7..6ef9efdceded68 100644 --- a/types/three/src/Three.WebGPU.d.ts +++ b/types/three/src/Three.WebGPU.d.ts @@ -1,19 +1,19 @@ export * from "./Three.Core.js"; export * from "./materials/nodes/NodeMaterials.js"; -export type { default as Backend } from "./renderers/common/Backend.js"; +export { default as Backend } from "./renderers/common/Backend.js"; export { default as BundleGroup } from "./renderers/common/BundleGroup.js"; export { default as PMREMGenerator } from "./renderers/common/extras/PMREMGenerator.js"; export { default as Lighting } from "./renderers/common/Lighting.js"; export { default as PostProcessing } from "./renderers/common/PostProcessing.js"; export { default as QuadMesh } from "./renderers/common/QuadMesh.js"; export { default as ReadbackBuffer } from "./renderers/common/ReadbackBuffer.js"; -export type { default as Renderer } from "./renderers/common/Renderer.js"; +export { default as Renderer, RendererParameters } from "./renderers/common/Renderer.js"; export { default as RenderPipeline } from "./renderers/common/RenderPipeline.js"; export { default as WebGLCapabilities } from "./renderers/webgl-fallback/utils/WebGLCapabilities.js"; export { default as WebGLBackend } from "./renderers/webgl-fallback/WebGLBackend.js"; export { default as WebGPUBackend } from "./renderers/webgpu/WebGPUBackend.js"; -export { default as WebGPURenderer } from "./renderers/webgpu/WebGPURenderer.js"; +export { default as WebGPURenderer, WebGPURendererParameters } from "./renderers/webgpu/WebGPURenderer.js"; import * as RendererUtils from "./renderers/common/RendererUtils.js"; export { RendererUtils }; export { default as IESSpotLight } from "./lights/webgpu/IESSpotLight.js"; @@ -35,5 +35,7 @@ export { default as StorageInstancedBufferAttribute } from "./renderers/common/S export { default as StorageTexture } from "./renderers/common/StorageTexture.js"; export { default as GLSLNodeBuilder } from "./renderers/webgl-fallback/nodes/GLSLNodeBuilder.js"; export { default as BasicNodeLibrary } from "./renderers/webgpu/nodes/BasicNodeLibrary.js"; +export { default as StandardNodeLibrary } from "./renderers/webgpu/nodes/StandardNodeLibrary.js"; +export { default as WGSLNodeBuilder } from "./renderers/webgpu/nodes/WGSLNodeBuilder.js"; import * as TSL from "./nodes/TSL.js"; export { TSL }; diff --git a/types/three/src/animation/AnimationClip.d.ts b/types/three/src/animation/AnimationClip.d.ts index 859483c29eb11f..ab2ee91d7c6c55 100644 --- a/types/three/src/animation/AnimationClip.d.ts +++ b/types/three/src/animation/AnimationClip.d.ts @@ -86,16 +86,6 @@ export class AnimationClip { fps: number, noLoop: boolean, ): Array; - /** - * Parses the `animation.hierarchy` format and returns a new animation clip. - * - * @static - * @deprecated since r175. - * @param {Object} animation - A serialized animation clip as JSON. - * @param {Array} bones - An array of bones. - * @return {?AnimationClip} The new animation clip. - */ - static parseAnimation(animation: AnimationClipJSON, bones: Array): AnimationClip | null; /** * Constructs a new animation clip. * diff --git a/types/three/src/cameras/Camera.d.ts b/types/three/src/cameras/Camera.d.ts index 1015d405641150..10a8794103c02a 100644 --- a/types/three/src/cameras/Camera.d.ts +++ b/types/three/src/cameras/Camera.d.ts @@ -37,6 +37,6 @@ export class Camera extends Object3D { * @default false */ get reversedDepth(): boolean; - copy(source: Camera, recursive?: boolean): this; clone(): this; + copy(source: Camera, recursive?: boolean): this; } diff --git a/types/three/src/core/InterleavedBuffer.d.ts b/types/three/src/core/InterleavedBuffer.d.ts index ffdd95e2de948d..004492fc02061c 100644 --- a/types/three/src/core/InterleavedBuffer.d.ts +++ b/types/three/src/core/InterleavedBuffer.d.ts @@ -104,7 +104,7 @@ export class InterleavedBuffer { * @param offset index of the {@link BufferAttribute.array | array} at which to start copying. Expects a `Integer`. Default `0`. * @throws `RangeError` When {@link offset} is negative or is too large. */ - set(value: ArrayLike, offset: number): this; + set(value: ArrayLike, offset?: number): this; /** * Set {@link BufferAttribute.usage | usage} diff --git a/types/three/src/core/Object3D.d.ts b/types/three/src/core/Object3D.d.ts index 7f7abdc9927f67..984aae83354677 100644 --- a/types/three/src/core/Object3D.d.ts +++ b/types/three/src/core/Object3D.d.ts @@ -669,11 +669,15 @@ export class Object3D ext updateMatrixWorld(force?: boolean): void; /** - * Updates the global transform of the object. - * @param updateParents Recursively updates global transform of ancestors. - * @param updateChildren Recursively updates global transform of descendants. + * An alternative version of {@link Object3D#updateMatrixWorld} with more control over the + * update of ancestor and descendant nodes. + * + * @param {boolean} [updateParents=false] Whether ancestor nodes should be updated or not. + * @param {boolean} [updateChildren=false] Whether descendant nodes should be updated or not. + * @param {boolean} [force=false] - When set to `true`, a recomputation of world matrices is forced even + * when {@link Object3D#matrixWorldNeedsUpdate} is `false`. */ - updateWorldMatrix(updateParents: boolean, updateChildren: boolean): void; + updateWorldMatrix(updateParents: boolean, updateChildren: boolean, force?: boolean): void; /** * Convert the object to three.js {@link https://github.com/mrdoob/three.js/wiki/JSON-Object-Scene-format-4 | JSON Object/Scene format}. diff --git a/types/three/src/core/RenderTarget.d.ts b/types/three/src/core/RenderTarget.d.ts index 075f08a84b8b7b..f4039c1e5cb95e 100644 --- a/types/three/src/core/RenderTarget.d.ts +++ b/types/three/src/core/RenderTarget.d.ts @@ -17,6 +17,7 @@ export interface RenderTargetOptions extends TextureParameters { count?: number | undefined; depth?: number | undefined; multiview?: boolean | undefined; + useArrayDepthTexture?: boolean | undefined; } export interface RenderTargetEventMap { @@ -77,6 +78,16 @@ export class RenderTarget< */ multiview: boolean; + /** + * Whether to create the depth texture as an array texture for per-layer depth testing. + * This is separate from multiview so layered render targets can use array depth without + * the multiview extension. + * + * @type {boolean} + * @default false + */ + useArrayDepthTexture: boolean; + constructor(width?: number, height?: number, options?: RenderTargetOptions); get texture(): TTexture; diff --git a/types/three/src/core/Timer.d.ts b/types/three/src/core/Timer.d.ts index 4dec67b8b55d20..b33a3ace23a439 100644 --- a/types/three/src/core/Timer.d.ts +++ b/types/three/src/core/Timer.d.ts @@ -63,7 +63,7 @@ declare class Timer { /** * Can be used to free all internal resources. Usually called when the timer instance isn't required anymore. */ - dispose(): this; + dispose(): void; /** * Updates the internal state of the timer. This method should be called once per simulation step and before you diff --git a/types/three/src/core/UniformsGroup.d.ts b/types/three/src/core/UniformsGroup.d.ts index 7e6b6c3543eb05..5e52a77a6534d4 100644 --- a/types/three/src/core/UniformsGroup.d.ts +++ b/types/three/src/core/UniformsGroup.d.ts @@ -31,7 +31,7 @@ export class UniformsGroup - extends EventDispatcher -{ +declare abstract class Controls< + TEventMap extends ControlsEventMap = ControlsEventMap, + TObject extends Object3D = Object3D, +> extends EventDispatcher { /** * The 3D object that is managed by the controls. */ - object: Object3D; + object: TObject; /** * The HTML element used for event listeners. If not provided via the constructor, {@link .connect} must be called @@ -30,7 +31,7 @@ declare abstract class Controls} + * @default null */ - subPaths: Path[]; - + subPaths: Array; /** - * The current {@link THREE.Path | Path} that is being generated. - * @defaultValue `null` + * The current path that is being generated. + * + * @type {?Path} + * @default null */ - readonly currentPath: Path | null; - + currentPath: Path | null; /** - * {@link THREE.Color | Color} of the shape, by default set to white _(0xffffff)_. - * @defaultValue `new THREE.Color()` + * An object that can be used to store custom data about the shape path. + * Mainly used by SVGLoader to store style information. + * + * @type {Object} */ - color: Color; - + userData: Record; /** - * Starts a new {@link THREE.Path | Path} and calls {@link THREE.Path.moveTo | Path.moveTo}( x, y ) on that {@link THREE.Path | Path} - * @remarks - * Also points {@link ShapePath.currentPath | currentPath} to that {@link THREE.Path | Path}. - * @param x Expects a `Float` - * @param y Expects a `Float` + * Creates a new path and moves it current point to the given one. + * + * @param {number} x - The x coordinate. + * @param {number} y - The y coordinate. + * @return {ShapePath} A reference to this shape path. */ moveTo(x: number, y: number): this; - /** - * This creates a line from the {@link ShapePath.currentPath | currentPath}'s offset to X and Y and updates the offset to X and Y. - * @param x Expects a `Float` - * @param y Expects a `Float` + * Adds an instance of {@link LineCurve} to the path by connecting + * the current point with the given one. + * + * @param {number} x - The x coordinate of the end point. + * @param {number} y - The y coordinate of the end point. + * @return {ShapePath} A reference to this shape path. */ lineTo(x: number, y: number): this; - /** - * This creates a quadratic curve from the {@link ShapePath.currentPath | currentPath}'s - * offset to _x_ and _y_ with _cpX_ and _cpY_ as control point and updates the {@link ShapePath.currentPath | currentPath}'s offset to _x_ and _y_. - * @param cpX Expects a `Float` - * @param cpY Expects a `Float` - * @param x Expects a `Float` - * @param y Expects a `Float` + * Adds an instance of {@link QuadraticBezierCurve} to the path by connecting + * the current point with the given one. + * + * @param {number} aCPx - The x coordinate of the control point. + * @param {number} aCPy - The y coordinate of the control point. + * @param {number} aX - The x coordinate of the end point. + * @param {number} aY - The y coordinate of the end point. + * @return {ShapePath} A reference to this shape path. */ quadraticCurveTo(aCPx: number, aCPy: number, aX: number, aY: number): this; - /** - * This creates a bezier curve from the {@link ShapePath.currentPath | currentPath}'s - * offset to _x_ and _y_ with _cp1X_, _cp1Y_ and _cp2X_, _cp2Y_ as control points and - * updates the {@link ShapePath.currentPath | currentPath}'s offset to _x_ and _y_. - * @param cp1X Expects a `Float` - * @param cp1Y Expects a `Float` - * @param cp2X Expects a `Float` - * @param cp2Y Expects a `Float` - * @param x Expects a `Float` - * @param y Expects a `Float` + * Adds an instance of {@link CubicBezierCurve} to the path by connecting + * the current point with the given one. + * + * @param {number} aCP1x - The x coordinate of the first control point. + * @param {number} aCP1y - The y coordinate of the first control point. + * @param {number} aCP2x - The x coordinate of the second control point. + * @param {number} aCP2y - The y coordinate of the second control point. + * @param {number} aX - The x coordinate of the end point. + * @param {number} aY - The y coordinate of the end point. + * @return {ShapePath} A reference to this shape path. */ bezierCurveTo(aCP1x: number, aCP1y: number, aCP2x: number, aCP2y: number, aX: number, aY: number): this; - /** - * Connects a new {@link THREE.SplineCurve | SplineCurve} onto the {@link ShapePath.currentPath | currentPath}. - * @param points An array of {@link THREE.Vector2 | Vector2}s + * Adds an instance of {@link SplineCurve} to the path by connecting + * the current point with the given list of points. + * + * @param {Array} pts - An array of points in 2D space. + * @return {ShapePath} A reference to this shape path. */ - splineThru(pts: Vector2[]): this; - + splineThru(pts: Array): this; /** - * Converts the {@link ShapePath.subPaths | subPaths} array into an array of Shapes - * @remarks - * By default solid shapes are defined clockwise (CW) and holes are defined counterclockwise (CCW) - * If isCCW is set to true, then those are flipped. - * @param isCCW Changes how solids and holes are generated + * Converts the paths into an array of shapes. + * + * @return {Array} An array of shapes. */ - toShapes(isCCW: boolean): Shape[]; + toShapes(): Array; } diff --git a/types/three/src/loaders/DataTextureLoader.d.ts b/types/three/src/loaders/DataTextureLoader.d.ts index 0cc8d7475342bd..5fe9b0d33800fb 100644 --- a/types/three/src/loaders/DataTextureLoader.d.ts +++ b/types/three/src/loaders/DataTextureLoader.d.ts @@ -1,14 +1,48 @@ -import { DataTexture } from "../textures/DataTexture.js"; +import { + ColorSpace, + MagnificationTextureFilter, + MinificationTextureFilter, + PixelFormat, + TextureDataType, + Wrapping, +} from "../constants.js"; +import { TypedArray } from "../core/BufferAttribute.js"; +import { CompressedTextureMipmap } from "../textures/CompressedTexture.js"; +import { CubeTexture } from "../textures/CubeTexture.js"; +import { DataTexture, DataTextureImageData } from "../textures/DataTexture.js"; import { Loader } from "./Loader.js"; import { LoadingManager } from "./LoadingManager.js"; -export class DataTextureLoader extends Loader { +export interface DataTextureLoaderTexData { + image?: DataTextureImageData | undefined; + width?: number | undefined; + height?: number | undefined; + data?: TypedArray | undefined; + format?: PixelFormat | undefined; + type?: TextureDataType | undefined; + flipY?: boolean | undefined; + wrapS?: Wrapping | undefined; + wrapT?: Wrapping | undefined; + anisotropy?: number | undefined; + generateMipmaps?: boolean | undefined; + colorSpace?: ColorSpace | undefined; + magFilter?: MagnificationTextureFilter | undefined; + minFilter?: MinificationTextureFilter | undefined; + mipmaps?: CompressedTextureMipmap[] | CubeTexture[] | HTMLCanvasElement[] | undefined; + mipmapCount?: number | undefined; +} + +export abstract class DataTextureLoader extends Loader { constructor(manager?: LoadingManager); load( url: string, - onLoad?: (data: DataTexture, texData: object) => void, + onLoad?: (data: DataTexture, texData: DataTextureLoaderTexData) => void, onProgress?: (event: ProgressEvent) => void, onError?: (err: unknown) => void, ): DataTexture; + + abstract parse(buffer: ArrayBuffer): DataTextureLoaderTexData; + + createDataTexture(buffer: ArrayBuffer): DataTexture; } diff --git a/types/three/src/loaders/MaterialLoader.d.ts b/types/three/src/loaders/MaterialLoader.d.ts index 742c22a04442bd..89951b24e4e1a4 100644 --- a/types/three/src/loaders/MaterialLoader.d.ts +++ b/types/three/src/loaders/MaterialLoader.d.ts @@ -18,4 +18,12 @@ export class MaterialLoader extends Loader { createMaterialFromType(type: string): Material; static createMaterialFromType(type: string): Material; + + /** + * Registers the given material at the internal material library. + * + * @param type The material type. + * @param materialClass The material class. + */ + static registerMaterial(type: string, materialClass: new() => Material): void; } diff --git a/types/three/src/materials/LineBasicMaterial.d.ts b/types/three/src/materials/LineBasicMaterial.d.ts index 32ebeefc7c12c1..905aaafe6157a7 100644 --- a/types/three/src/materials/LineBasicMaterial.d.ts +++ b/types/three/src/materials/LineBasicMaterial.d.ts @@ -13,6 +13,11 @@ export interface LineBasicMaterialProperties extends MaterialProperties { * Sets the color of the lines using data from a texture. The texture map * color is modulated by the diffuse `color`. * + * `map` represents color data, and the texture must be assigned a + * {@link Texture#colorSpace}. Most `map` textures set + * `texture.colorSpace = SRGBColorSpace`. + * + * @type {?Texture} * @default null */ map: Texture | null; diff --git a/types/three/src/materials/Material.d.ts b/types/three/src/materials/Material.d.ts index 67ee2cbe3d8f47..5a3ccb0aa87e26 100644 --- a/types/three/src/materials/Material.d.ts +++ b/types/three/src/materials/Material.d.ts @@ -23,7 +23,7 @@ import { WebGLProgramParametersWithUniforms } from "../renderers/webgl/WebGLProg import { WebGLRenderer } from "../renderers/WebGLRenderer.js"; import { Scene } from "../scenes/Scene.js"; import { SourceJSON } from "../textures/Source.js"; -import { TextureJSON } from "../textures/Texture.js"; +import { Texture, TextureJSON } from "../textures/Texture.js"; export interface MaterialProperties { /** @@ -612,6 +612,14 @@ export class Material ext * @see {@link ObjectLoader#parse} */ toJSON(meta?: JSONMeta): MaterialJSON; + /** + * Deserializes the material from the given JSON. + * + * @param {Object} json - The JSON holding the serialized material. + * @param {Object} textures - A dictionary holding textures referenced by the material. + * @return {Material} A reference to this material. + */ + fromJSON(json: MaterialJSON, textures: Record): this; /** * Returns a new material with copied values from this instance. * diff --git a/types/three/src/materials/MeshBasicMaterial.d.ts b/types/three/src/materials/MeshBasicMaterial.d.ts index cfe54992a11131..a36b4e9c97a207 100644 --- a/types/three/src/materials/MeshBasicMaterial.d.ts +++ b/types/three/src/materials/MeshBasicMaterial.d.ts @@ -16,12 +16,23 @@ export interface MeshBasicMaterialProperties extends MaterialProperties { * with {@link Material#transparent} or {@link Material#alphaTest}. The texture map * color is modulated by the diffuse `color`. * + * `map` represents color data, and the texture must be assigned a + * {@link Texture#colorSpace}. Most `map` textures set + * `texture.colorSpace = SRGBColorSpace`. + * + * @type {?Texture} * @default null */ map: Texture | null; /** * The light map. Requires a second set of UVs. * + * `lightMap` represents pre-baked illuminance data, and the texture must be assigned + * a {@link Texture#colorSpace}. Most `lightMap` textures set + * `texture.colorSpace = LinearSRGBColorSpace` and use float-type formats + * such as `.exr` or `.hdr`. + * + * @type {?Texture} * @default null */ lightMap: Texture | null; @@ -35,6 +46,10 @@ export interface MeshBasicMaterialProperties extends MaterialProperties { * The red channel of this texture is used as the ambient occlusion map. * Requires a second set of UVs. * + * `aoMap` represents non-color data. Any texture assigned must have + * `texture.colorSpace = NoColorSpace` (default). + * + * @type {?Texture} * @default null */ aoMap: Texture | null; @@ -49,6 +64,11 @@ export interface MeshBasicMaterialProperties extends MaterialProperties { /** * Specular map used by the material. * + * `specularMap` represents color data, and the texture must be assigned a + * {@link Texture#colorSpace}. Most `specularMap` textures set + * `texture.colorSpace = SRGBColorSpace`. + * + * @type {?Texture} * @default null */ specularMap: Texture | null; @@ -62,12 +82,22 @@ export interface MeshBasicMaterialProperties extends MaterialProperties { * green in DXT-compressed and uncompressed RGB 565 formats. Luminance-only and * luminance/alpha textures will also still work as expected. * + * `alphaMap` represents non-color data. Any texture assigned must have + * `texture.colorSpace = NoColorSpace` (default). + * + * @type {?Texture} * @default null */ alphaMap: Texture | null; /** * The environment map. * + * `envMap` represents luminance data, and the texture must be assigned + * a {@link Texture#colorSpace}. Most `envMap` textures set + * `texture.colorSpace = LinearSRGBColorSpace` and use float-type formats + * such as `.exr` or `.hdr`. + * + * @type {?Texture} * @default null */ envMap: Texture | null; diff --git a/types/three/src/materials/MeshDepthMaterial.d.ts b/types/three/src/materials/MeshDepthMaterial.d.ts index 0ac60817ab3471..9c4d2b586eed78 100644 --- a/types/three/src/materials/MeshDepthMaterial.d.ts +++ b/types/three/src/materials/MeshDepthMaterial.d.ts @@ -13,6 +13,11 @@ export interface MeshDepthMaterialProperties extends MaterialProperties { * The color map. May optionally include an alpha channel, typically combined * with {@link Material#transparent} or {@link Material#alphaTest}. * + * `map` represents color data, and the texture must be assigned a + * {@link Texture#colorSpace}. Most `map` textures set + * `texture.colorSpace = SRGBColorSpace`. + * + * @type {?Texture} * @default null */ map: Texture | null; @@ -26,6 +31,10 @@ export interface MeshDepthMaterialProperties extends MaterialProperties { * green in DXT-compressed and uncompressed RGB 565 formats. Luminance-only and * luminance/alpha textures will also still work as expected. * + * `alphaMap` represents non-color data. Any texture assigned must have + * `texture.colorSpace = NoColorSpace` (default). + * + * @type {?Texture} * @default null */ alphaMap: Texture | null; @@ -37,6 +46,10 @@ export interface MeshDepthMaterialProperties extends MaterialProperties { * of each pixel (white being the highest) is mapped against, and * repositions, the vertices of the mesh. * + * `displacementMap` represents non-color data. Any texture assigned must have + * `texture.colorSpace = NoColorSpace` (default). + * + * @type {?Texture} * @default null */ displacementMap: Texture | null; diff --git a/types/three/src/materials/MeshDistanceMaterial.d.ts b/types/three/src/materials/MeshDistanceMaterial.d.ts index b704fc907bbcdf..43f9128e3f0674 100644 --- a/types/three/src/materials/MeshDistanceMaterial.d.ts +++ b/types/three/src/materials/MeshDistanceMaterial.d.ts @@ -6,6 +6,11 @@ export interface MeshDistanceMaterialProperties extends MaterialProperties { * The color map. May optionally include an alpha channel, typically combined * with {@link Material#transparent} or {@link Material#alphaTest}. * + * `map` represents color data, and the texture must be assigned a + * {@link Texture#colorSpace}. Most `map` textures set + * `texture.colorSpace = SRGBColorSpace`. + * + * @type {?Texture} * @default null */ map: Texture | null; @@ -19,6 +24,10 @@ export interface MeshDistanceMaterialProperties extends MaterialProperties { * green in DXT-compressed and uncompressed RGB 565 formats. Luminance-only and * luminance/alpha textures will also still work as expected. * + * `alphaMap` represents non-color data. Any texture assigned must have + * `texture.colorSpace = NoColorSpace` (default). + * + * @type {?Texture} * @default null */ alphaMap: Texture | null; @@ -30,6 +39,10 @@ export interface MeshDistanceMaterialProperties extends MaterialProperties { * of each pixel (white being the highest) is mapped against, and * repositions, the vertices of the mesh. * + * `displacementMap` represents non-color data. Any texture assigned must have + * `texture.colorSpace = NoColorSpace` (default). + * + * @type {?Texture} * @default null */ displacementMap: Texture | null; diff --git a/types/three/src/materials/MeshLambertMaterial.d.ts b/types/three/src/materials/MeshLambertMaterial.d.ts index fb4fc9625c7562..15f8d91b82a463 100644 --- a/types/three/src/materials/MeshLambertMaterial.d.ts +++ b/types/three/src/materials/MeshLambertMaterial.d.ts @@ -17,12 +17,23 @@ export interface MeshLambertMaterialProperties extends MaterialProperties { * with {@link Material#transparent} or {@link Material#alphaTest}. The texture map * color is modulated by the diffuse `color`. * + * `map` represents color data, and the texture must be assigned a + * {@link Texture#colorSpace}. Most `map` textures set + * `texture.colorSpace = SRGBColorSpace`. + * + * @type {?Texture} * @default null */ map: Texture | null; /** * The light map. Requires a second set of UVs. * + * `lightMap` represents pre-baked illuminance data, and the texture must be assigned + * a {@link Texture#colorSpace}. Most `lightMap` textures set + * `texture.colorSpace = LinearSRGBColorSpace` and use float-type formats + * such as `.exr` or `.hdr`. + * + * @type {?Texture} * @default null */ lightMap: Texture | null; @@ -36,6 +47,10 @@ export interface MeshLambertMaterialProperties extends MaterialProperties { * The red channel of this texture is used as the ambient occlusion map. * Requires a second set of UVs. * + * `aoMap` represents non-color data. Any texture assigned must have + * `texture.colorSpace = NoColorSpace` (default). + * + * @type {?Texture} * @default null */ aoMap: Texture | null; @@ -65,6 +80,11 @@ export interface MeshLambertMaterialProperties extends MaterialProperties { * emissive color and the emissive intensity. If you have an emissive map, * be sure to set the emissive color to something other than black. * + * `emissiveMap` represents color data, and the texture must be assigned a + * {@link Texture#colorSpace}. Most `emissiveMap` textures set + * `texture.colorSpace = SRGBColorSpace`. + * + * @type {?Texture} * @default null */ emissiveMap: Texture | null; @@ -74,6 +94,10 @@ export interface MeshLambertMaterialProperties extends MaterialProperties { * the geometry of the object, only the lighting. If a normal map is defined * this will be ignored. * + * `bumpMap` represents non-color data. Any texture assigned must have + * `texture.colorSpace = NoColorSpace` (default). + * + * @type {?Texture} * @default null */ bumpMap: Texture | null; @@ -91,6 +115,10 @@ export interface MeshLambertMaterialProperties extends MaterialProperties { * convention, the `y` component of `normalScale` should be negated to compensate * for the different handedness. * + * `normalMap` represents non-color data. Any texture assigned must have + * `texture.colorSpace = NoColorSpace` (default). + * + * @type {?Texture} * @default null */ normalMap: Texture | null; @@ -112,8 +140,14 @@ export interface MeshLambertMaterialProperties extends MaterialProperties { * displaced vertices can cast shadows, block other objects, and otherwise * act as real geometry. The displacement texture is an image where the value * of each pixel (white being the highest) is mapped against, and - * repositions, the vertices of the mesh. + * repositions, the vertices of the mesh. For best results, pair a + * displacement map with a matching normal map, since the renderer can + * not recompute surface normals from the displaced vertices. + * + * `displacementMap` represents non-color data. Any texture assigned must have + * `texture.colorSpace = NoColorSpace` (default). * + * @type {?Texture} * @default null */ displacementMap: Texture | null; @@ -136,6 +170,11 @@ export interface MeshLambertMaterialProperties extends MaterialProperties { /** * Specular map used by the material. * + * `specularMap` represents color data, and the texture must be assigned a + * {@link Texture#colorSpace}. Most `specularMap` textures set + * `texture.colorSpace = SRGBColorSpace`. + * + * @type {?Texture} * @default null */ specularMap: Texture | null; @@ -149,12 +188,22 @@ export interface MeshLambertMaterialProperties extends MaterialProperties { * green in DXT-compressed and uncompressed RGB 565 formats. Luminance-only and * luminance/alpha textures will also still work as expected. * + * `alphaMap` represents non-color data. Any texture assigned must have + * `texture.colorSpace = NoColorSpace` (default). + * + * @type {?Texture} * @default null */ alphaMap: Texture | null; /** * The environment map. * + * `envMap` represents luminance data, and the texture must be assigned + * a {@link Texture#colorSpace}. Most `envMap` textures set + * `texture.colorSpace = LinearSRGBColorSpace` and use float-type formats + * such as `.exr` or `.hdr`. + * + * @type {?Texture} * @default null */ envMap: Texture | null; diff --git a/types/three/src/materials/MeshMatcapMaterial.d.ts b/types/three/src/materials/MeshMatcapMaterial.d.ts index 313abd6eed0888..cd386a253ed81d 100644 --- a/types/three/src/materials/MeshMatcapMaterial.d.ts +++ b/types/three/src/materials/MeshMatcapMaterial.d.ts @@ -14,6 +14,13 @@ export interface MeshMatcapMaterialProperties extends MaterialProperties { /** * The matcap map. * + * `matcap` represents luminance data, and the texture must be assigned + * a {@link Texture#colorSpace}. HDR `matcap` textures (e.g. `.exr`) + * typically set `texture.colorSpace = LinearSRGBColorSpace`, while LDR + * `matcap` textures (e.g. `.png`, `.jpg`, `.webp`) typically set + * `texture.colorSpace = SRGBColorSpace`. + * + * @type {?Texture} * @default null */ matcap: Texture | null; @@ -22,6 +29,11 @@ export interface MeshMatcapMaterialProperties extends MaterialProperties { * with {@link Material#transparent} or {@link Material#alphaTest}. The texture map * color is modulated by the diffuse `color`. * + * `map` represents color data, and the texture must be assigned a + * {@link Texture#colorSpace}. Most `map` textures set + * `texture.colorSpace = SRGBColorSpace`. + * + * @type {?Texture} * @default null */ map: Texture | null; @@ -31,6 +43,10 @@ export interface MeshMatcapMaterialProperties extends MaterialProperties { * the geometry of the object, only the lighting. If a normal map is defined * this will be ignored. * + * `bumpMap` represents non-color data. Any texture assigned must have + * `texture.colorSpace = NoColorSpace` (default). + * + * @type {?Texture} * @default null */ bumpMap: Texture | null; @@ -48,6 +64,10 @@ export interface MeshMatcapMaterialProperties extends MaterialProperties { * convention, the `y` component of `normalScale` should be negated to compensate * for the different handedness. * + * `normalMap` represents non-color data. Any texture assigned must have + * `texture.colorSpace = NoColorSpace` (default). + * + * @type {?Texture} * @default null */ normalMap: Texture | null; @@ -69,8 +89,14 @@ export interface MeshMatcapMaterialProperties extends MaterialProperties { * displaced vertices can cast shadows, block other objects, and otherwise * act as real geometry. The displacement texture is an image where the value * of each pixel (white being the highest) is mapped against, and - * repositions, the vertices of the mesh. + * repositions, the vertices of the mesh. For best results, pair a + * displacement map with a matching normal map, since the renderer can + * not recompute surface normals from the displaced vertices. + * + * `displacementMap` represents non-color data. Any texture assigned must have + * `texture.colorSpace = NoColorSpace` (default). * + * @type {?Texture} * @default null */ displacementMap: Texture | null; @@ -100,6 +126,10 @@ export interface MeshMatcapMaterialProperties extends MaterialProperties { * green in DXT-compressed and uncompressed RGB 565 formats. Luminance-only and * luminance/alpha textures will also still work as expected. * + * `alphaMap` represents non-color data. Any texture assigned must have + * `texture.colorSpace = NoColorSpace` (default). + * + * @type {?Texture} * @default null */ alphaMap: Texture | null; diff --git a/types/three/src/materials/MeshNormalMaterial.d.ts b/types/three/src/materials/MeshNormalMaterial.d.ts index 2428b5bd015856..43310f9766098c 100644 --- a/types/three/src/materials/MeshNormalMaterial.d.ts +++ b/types/three/src/materials/MeshNormalMaterial.d.ts @@ -10,6 +10,10 @@ export interface MeshNormalMaterialProperties extends MaterialProperties { * the geometry of the object, only the lighting. If a normal map is defined * this will be ignored. * + * `bumpMap` represents non-color data. Any texture assigned must have + * `texture.colorSpace = NoColorSpace` (default). + * + * @type {?Texture} * @default null */ bumpMap: Texture | null; @@ -27,6 +31,10 @@ export interface MeshNormalMaterialProperties extends MaterialProperties { * convention, the `y` component of `normalScale` should be negated to compensate * for the different handedness. * + * `normalMap` represents non-color data. Any texture assigned must have + * `texture.colorSpace = NoColorSpace` (default). + * + * @type {?Texture} * @default null */ normalMap: Texture | null; @@ -48,7 +56,9 @@ export interface MeshNormalMaterialProperties extends MaterialProperties { * displaced vertices can cast shadows, block other objects, and otherwise * act as real geometry. The displacement texture is an image where the value * of each pixel (white being the highest) is mapped against, and - * repositions, the vertices of the mesh. + * repositions, the vertices of the mesh. For best results, pair a + * displacement map with a matching normal map, since the renderer can + * not recompute surface normals from the displaced vertices. * * @default null */ diff --git a/types/three/src/materials/MeshPhongMaterial.d.ts b/types/three/src/materials/MeshPhongMaterial.d.ts index 20a882b8d7cf94..2ef81d856d65a4 100644 --- a/types/three/src/materials/MeshPhongMaterial.d.ts +++ b/types/three/src/materials/MeshPhongMaterial.d.ts @@ -29,12 +29,23 @@ export interface MeshPhongMaterialProperties extends MaterialProperties { * with {@link Material#transparent} or {@link Material#alphaTest}. The texture map * color is modulated by the diffuse `color`. * + * `map` represents color data, and the texture must be assigned a + * {@link Texture#colorSpace}. Most `map` textures set + * `texture.colorSpace = SRGBColorSpace`. + * + * @type {?Texture} * @default null */ map: Texture | null; /** * The light map. Requires a second set of UVs. * + * `lightMap` represents pre-baked illuminance data, and the texture must be assigned + * a {@link Texture#colorSpace}. Most `lightMap` textures set + * `texture.colorSpace = LinearSRGBColorSpace` and use float-type formats + * such as `.exr` or `.hdr`. + * + * @type {?Texture} * @default null */ lightMap: Texture | null; @@ -48,6 +59,10 @@ export interface MeshPhongMaterialProperties extends MaterialProperties { * The red channel of this texture is used as the ambient occlusion map. * Requires a second set of UVs. * + * `aoMap` represents non-color data. Any texture assigned must have + * `texture.colorSpace = NoColorSpace` (default). + * + * @type {?Texture} * @default null */ aoMap: Texture | null; @@ -77,6 +92,11 @@ export interface MeshPhongMaterialProperties extends MaterialProperties { * emissive color and the emissive intensity. If you have an emissive map, * be sure to set the emissive color to something other than black. * + * `emissiveMap` represents color data, and the texture must be assigned a + * {@link Texture#colorSpace}. Most `emissiveMap` textures set + * `texture.colorSpace = SRGBColorSpace`. + * + * @type {?Texture} * @default null */ emissiveMap: Texture | null; @@ -86,6 +106,10 @@ export interface MeshPhongMaterialProperties extends MaterialProperties { * the geometry of the object, only the lighting. If a normal map is defined * this will be ignored. * + * `bumpMap` represents non-color data. Any texture assigned must have + * `texture.colorSpace = NoColorSpace` (default). + * + * @type {?Texture} * @default null */ bumpMap: Texture | null; @@ -103,6 +127,10 @@ export interface MeshPhongMaterialProperties extends MaterialProperties { * convention, the `y` component of `normalScale` should be negated to compensate * for the different handedness. * + * `normalMap` represents non-color data. Any texture assigned must have + * `texture.colorSpace = NoColorSpace` (default). + * + * @type {?Texture} * @default null */ normalMap: Texture | null; @@ -124,8 +152,14 @@ export interface MeshPhongMaterialProperties extends MaterialProperties { * displaced vertices can cast shadows, block other objects, and otherwise * act as real geometry. The displacement texture is an image where the value * of each pixel (white being the highest) is mapped against, and - * repositions, the vertices of the mesh. + * repositions, the vertices of the mesh. For best results, pair a + * displacement map with a matching normal map, since the renderer can + * not recompute surface normals from the displaced vertices. + * + * `displacementMap` represents non-color data. Any texture assigned must have + * `texture.colorSpace = NoColorSpace` (default). * + * @type {?Texture} * @default null */ displacementMap: Texture | null; @@ -150,6 +184,11 @@ export interface MeshPhongMaterialProperties extends MaterialProperties { * highlight contributes and how much of the environment map affects the * surface. * + * `specularMap` represents color data, and the texture must be assigned a + * {@link Texture#colorSpace}. Most `specularMap` textures set + * `texture.colorSpace = SRGBColorSpace`. + * + * @type {?Texture} * @default null */ specularMap: Texture | null; @@ -163,12 +202,22 @@ export interface MeshPhongMaterialProperties extends MaterialProperties { * green in DXT-compressed and uncompressed RGB 565 formats. Luminance-only and * luminance/alpha textures will also still work as expected. * + * `alphaMap` represents non-color data. Any texture assigned must have + * `texture.colorSpace = NoColorSpace` (default). + * + * @type {?Texture} * @default null */ alphaMap: Texture | null; /** * The environment map. * + * `envMap` represents luminance data, and the texture must be assigned + * a {@link Texture#colorSpace}. Most `envMap` textures set + * `texture.colorSpace = LinearSRGBColorSpace` and use float-type formats + * such as `.exr` or `.hdr`. + * + * @type {?Texture} * @default null */ envMap: Texture | null; diff --git a/types/three/src/materials/MeshPhysicalMaterial.d.ts b/types/three/src/materials/MeshPhysicalMaterial.d.ts index 5dc1ad6e43dd7a..581d5b3a5dd004 100644 --- a/types/three/src/materials/MeshPhysicalMaterial.d.ts +++ b/types/three/src/materials/MeshPhysicalMaterial.d.ts @@ -18,6 +18,10 @@ export interface MeshPhysicalMaterialProperties extends MeshStandardMaterialProp * bitangent space, to be rotated by `anisotropyRotation`. The blue channel * contains strength as `[0, 1]` to be multiplied by `anisotropy`. * + * `anisotropyMap` represents non-color data. Any texture assigned must have + * `texture.colorSpace = NoColorSpace` (default). + * + * @type {?Texture} * @default null */ anisotropyMap: Texture | null; @@ -25,6 +29,10 @@ export interface MeshPhysicalMaterialProperties extends MeshStandardMaterialProp * The red channel of this texture is multiplied against `clearcoat`, * for per-pixel control over a coating's intensity. * + * `clearcoatMap` represents non-color data. Any texture assigned must have + * `texture.colorSpace = NoColorSpace` (default). + * + * @type {?Texture} * @default null */ clearcoatMap: Texture | null; @@ -38,6 +46,10 @@ export interface MeshPhysicalMaterialProperties extends MeshStandardMaterialProp * The green channel of this texture is multiplied against * `clearcoatRoughness`, for per-pixel control over a coating's roughness. * + * `clearcoatRoughnessMap` represents non-color data. Any texture assigned must have + * `texture.colorSpace = NoColorSpace` (default). + * + * @type {?Texture} * @default null */ clearcoatRoughnessMap: Texture | null; @@ -51,6 +63,10 @@ export interface MeshPhysicalMaterialProperties extends MeshStandardMaterialProp /** * Can be used to enable independent normals for the clear coat layer. * + * `clearcoatNormalMap` represents non-color data. Any texture assigned must have + * `texture.colorSpace = NoColorSpace` (default). + * + * @type {?Texture} * @default null */ clearcoatNormalMap: Texture | null; @@ -76,6 +92,10 @@ export interface MeshPhysicalMaterialProperties extends MeshStandardMaterialProp * The red channel of this texture is multiplied against `iridescence`, for per-pixel * control over iridescence. * + * `iridescenceMap` represents non-color data. Any texture assigned must have + * `texture.colorSpace = NoColorSpace` (default). + * + * @type {?Texture} * @default null */ iridescenceMap: Texture | null; @@ -100,6 +120,10 @@ export interface MeshPhysicalMaterialProperties extends MeshStandardMaterialProp * - `1.0` in the green channel will result in thickness equal to second element of the array. * - Values in-between will linearly interpolate between the elements of the array. * + * `iridescenceThicknessMap` represents non-color data. Any texture assigned must have + * `texture.colorSpace = NoColorSpace` (default). + * + * @type {?Texture} * @default null */ iridescenceThicknessMap: Texture | null; @@ -113,6 +137,11 @@ export interface MeshPhysicalMaterialProperties extends MeshStandardMaterialProp * The RGB channels of this texture are multiplied against `sheenColor`, for per-pixel control * over sheen tint. * + * `sheenColorMap` represents color data, and the texture must be assigned a + * {@link Texture#colorSpace}. Most `sheenColorMap` textures set + * `texture.colorSpace = SRGBColorSpace`. + * + * @type {?Texture} * @default null */ sheenColorMap: Texture | null; @@ -126,6 +155,10 @@ export interface MeshPhysicalMaterialProperties extends MeshStandardMaterialProp * The alpha channel of this texture is multiplied against `sheenRoughness`, for per-pixel control * over sheen roughness. * + * `sheenRoughnessMap` represents non-color data. Any texture assigned must have + * `texture.colorSpace = NoColorSpace` (default). + * + * @type {?Texture} * @default null */ sheenRoughnessMap: Texture | null; @@ -133,6 +166,10 @@ export interface MeshPhysicalMaterialProperties extends MeshStandardMaterialProp * The red channel of this texture is multiplied against `transmission`, for per-pixel control over * optical transparency. * + * `transmissionMap` represents non-color data. Any texture assigned must have + * `texture.colorSpace = NoColorSpace` (default). + * + * @type {?Texture} * @default null */ transmissionMap: Texture | null; @@ -148,6 +185,10 @@ export interface MeshPhysicalMaterialProperties extends MeshStandardMaterialProp * A texture that defines the thickness, stored in the green channel. This will * be multiplied by `thickness`. * + * `thicknessMap` represents non-color data. Any texture assigned must have + * `texture.colorSpace = NoColorSpace` (default). + * + * @type {?Texture} * @default null */ thicknessMap: Texture | null; @@ -177,6 +218,10 @@ export interface MeshPhysicalMaterialProperties extends MeshStandardMaterialProp * The alpha channel of this texture is multiplied against `specularIntensity`, * for per-pixel control over specular intensity. * + * `specularIntensityMap` represents non-color data. Any texture assigned must have + * `texture.colorSpace = NoColorSpace` (default). + * + * @type {?Texture} * @default null */ specularIntensityMap: Texture | null; @@ -190,6 +235,11 @@ export interface MeshPhysicalMaterialProperties extends MeshStandardMaterialProp * The RGB channels of this texture are multiplied against `specularColor`, * for per-pixel control over specular color. * + * `specularColorMap` represents color data, and the texture must be assigned a + * {@link Texture#colorSpace}. Most `specularColorMap` textures set + * `texture.colorSpace = SRGBColorSpace`. + * + * @type {?Texture} * @default null */ specularColorMap: Texture | null; diff --git a/types/three/src/materials/MeshStandardMaterial.d.ts b/types/three/src/materials/MeshStandardMaterial.d.ts index 839ae2c3481455..0d5318e22a658a 100644 --- a/types/three/src/materials/MeshStandardMaterial.d.ts +++ b/types/three/src/materials/MeshStandardMaterial.d.ts @@ -34,12 +34,23 @@ export interface MeshStandardMaterialProperties extends MaterialProperties { * with {@link Material#transparent} or {@link Material#alphaTest}. The texture map * color is modulated by the diffuse `color`. * + * `map` represents color data, and the texture must be assigned a + * {@link Texture#colorSpace}. Most `map` textures set + * `texture.colorSpace = SRGBColorSpace`. + * + * @type {?Texture} * @default null */ map: Texture | null; /** * The light map. Requires a second set of UVs. * + * `lightMap` represents pre-baked illuminance data, and the texture must be assigned + * a {@link Texture#colorSpace}. Most `lightMap` textures set + * `texture.colorSpace = LinearSRGBColorSpace` and use float-type formats + * such as `.exr` or `.hdr`. + * + * @type {?Texture} * @default null */ lightMap: Texture | null; @@ -53,6 +64,10 @@ export interface MeshStandardMaterialProperties extends MaterialProperties { * The red channel of this texture is used as the ambient occlusion map. * Requires a second set of UVs. * + * `aoMap` represents non-color data. Any texture assigned must have + * `texture.colorSpace = NoColorSpace` (default). + * + * @type {?Texture} * @default null */ aoMap: Texture | null; @@ -82,6 +97,11 @@ export interface MeshStandardMaterialProperties extends MaterialProperties { * emissive color and the emissive intensity. If you have an emissive map, * be sure to set the emissive color to something other than black. * + * `emissiveMap` represents color data, and the texture must be assigned a + * {@link Texture#colorSpace}. Most `emissiveMap` textures set + * `texture.colorSpace = SRGBColorSpace`. + * + * @type {?Texture} * @default null */ emissiveMap: Texture | null; @@ -91,6 +111,10 @@ export interface MeshStandardMaterialProperties extends MaterialProperties { * the geometry of the object, only the lighting. If a normal map is defined * this will be ignored. * + * `bumpMap` represents non-color data. Any texture assigned must have + * `texture.colorSpace = NoColorSpace` (default). + * + * @type {?Texture} * @default null */ bumpMap: Texture | null; @@ -108,6 +132,10 @@ export interface MeshStandardMaterialProperties extends MaterialProperties { * convention, the `y` component of `normalScale` should be negated to compensate * for the different handedness. * + * `normalMap` represents non-color data. Any texture assigned must have + * `texture.colorSpace = NoColorSpace` (default). + * + * @type {?Texture} * @default null */ normalMap: Texture | null; @@ -129,8 +157,14 @@ export interface MeshStandardMaterialProperties extends MaterialProperties { * displaced vertices can cast shadows, block other objects, and otherwise * act as real geometry. The displacement texture is an image where the value * of each pixel (white being the highest) is mapped against, and - * repositions, the vertices of the mesh. + * repositions, the vertices of the mesh. For best results, pair a + * displacement map with a matching normal map, since the renderer can + * not recompute surface normals from the displaced vertices. * + * `displacementMap` represents non-color data. Any texture assigned must have + * `texture.colorSpace = NoColorSpace` (default). + * + * @type {?Texture} * @default null */ displacementMap: Texture | null; @@ -154,6 +188,10 @@ export interface MeshStandardMaterialProperties extends MaterialProperties { * The green channel of this texture is used to alter the roughness of the * material. * + * `roughnessMap` represents non-color data. Any texture assigned must have + * `texture.colorSpace = NoColorSpace` (default). + * + * @type {?Texture} * @default null */ roughnessMap: Texture | null; @@ -161,6 +199,10 @@ export interface MeshStandardMaterialProperties extends MaterialProperties { * The blue channel of this texture is used to alter the metalness of the * material. * + * `metalnessMap` represents non-color data. Any texture assigned must have + * `texture.colorSpace = NoColorSpace` (default). + * + * @type {?Texture} * @default null */ metalnessMap: Texture | null; @@ -174,6 +216,10 @@ export interface MeshStandardMaterialProperties extends MaterialProperties { * green in DXT-compressed and uncompressed RGB 565 formats. Luminance-only and * luminance/alpha textures will also still work as expected. * + * `alphaMap` represents non-color data. Any texture assigned must have + * `texture.colorSpace = NoColorSpace` (default). + * + * @type {?Texture} * @default null */ alphaMap: Texture | null; @@ -181,6 +227,12 @@ export interface MeshStandardMaterialProperties extends MaterialProperties { * The environment map. To ensure a physically correct rendering, environment maps * are internally pre-processed with {@link PMREMGenerator}. * + * `envMap` represents luminance data, and the texture must be assigned + * a {@link Texture#colorSpace}. Most `envMap` textures set + * `texture.colorSpace = LinearSRGBColorSpace` and use float-type formats + * such as `.exr` or `.hdr`. + * + * @type {?Texture} * @default null */ envMap: Texture | null; diff --git a/types/three/src/materials/MeshToonMaterial.d.ts b/types/three/src/materials/MeshToonMaterial.d.ts index 7e70be5c3197cd..558b45faa2790c 100644 --- a/types/three/src/materials/MeshToonMaterial.d.ts +++ b/types/three/src/materials/MeshToonMaterial.d.ts @@ -16,6 +16,11 @@ export interface MeshToonMaterialProperties extends MaterialProperties { * with {@link Material#transparent} or {@link Material#alphaTest}. The texture map * color is modulated by the diffuse `color`. * + * `map` represents color data, and the texture must be assigned a + * {@link Texture#colorSpace}. Most `map` textures set + * `texture.colorSpace = SRGBColorSpace`. + * + * @type {?Texture} * @default null */ map: Texture | null; @@ -24,12 +29,22 @@ export interface MeshToonMaterialProperties extends MaterialProperties { * {@link Texture#minFilter} and {@link Texture#magFilter} to {@link NearestFilter} * when using this type of texture. * + * `gradientMap` represents non-color data. Any texture assigned must have + * `texture.colorSpace = NoColorSpace` (default). + * + * @type {?Texture} * @default null */ gradientMap: Texture | null; /** * The light map. Requires a second set of UVs. * + * `lightMap` represents pre-baked illuminance data, and the texture must be assigned + * a {@link Texture#colorSpace}. Most `lightMap` textures set + * `texture.colorSpace = LinearSRGBColorSpace` and use float-type formats + * such as `.exr` or `.hdr`. + * + * @type {?Texture} * @default null */ lightMap: Texture | null; @@ -43,6 +58,10 @@ export interface MeshToonMaterialProperties extends MaterialProperties { * The red channel of this texture is used as the ambient occlusion map. * Requires a second set of UVs. * + * `aoMap` represents non-color data. Any texture assigned must have + * `texture.colorSpace = NoColorSpace` (default). + * + * @type {?Texture} * @default null */ aoMap: Texture | null; @@ -72,6 +91,11 @@ export interface MeshToonMaterialProperties extends MaterialProperties { * emissive color and the emissive intensity. If you have an emissive map, * be sure to set the emissive color to something other than black. * + * `emissiveMap` represents color data, and the texture must be assigned a + * {@link Texture#colorSpace}. Most `emissiveMap` textures set + * `texture.colorSpace = SRGBColorSpace`. + * + * @type {?Texture} * @default null */ emissiveMap: Texture | null; @@ -81,6 +105,10 @@ export interface MeshToonMaterialProperties extends MaterialProperties { * the geometry of the object, only the lighting. If a normal map is defined * this will be ignored. * + * `bumpMap` represents non-color data. Any texture assigned must have + * `texture.colorSpace = NoColorSpace` (default). + * + * @type {?Texture} * @default null */ bumpMap: Texture | null; @@ -98,6 +126,10 @@ export interface MeshToonMaterialProperties extends MaterialProperties { * convention, the `y` component of `normalScale` should be negated to compensate * for the different handedness. * + * `normalMap` represents non-color data. Any texture assigned must have + * `texture.colorSpace = NoColorSpace` (default). + * + * @type {?Texture} * @default null */ normalMap: Texture | null; @@ -119,8 +151,14 @@ export interface MeshToonMaterialProperties extends MaterialProperties { * displaced vertices can cast shadows, block other objects, and otherwise * act as real geometry. The displacement texture is an image where the value * of each pixel (white being the highest) is mapped against, and - * repositions, the vertices of the mesh. + * repositions, the vertices of the mesh. For best results, pair a + * displacement map with a matching normal map, since the renderer can + * not recompute surface normals from the displaced vertices. * + * `displacementMap` represents non-color data. Any texture assigned must have + * `texture.colorSpace = NoColorSpace` (default). + * + * @type {?Texture} * @default null */ displacementMap: Texture | null; @@ -150,6 +188,10 @@ export interface MeshToonMaterialProperties extends MaterialProperties { * green in DXT-compressed and uncompressed RGB 565 formats. Luminance-only and * luminance/alpha textures will also still work as expected. * + * `alphaMap` represents non-color data. Any texture assigned must have + * `texture.colorSpace = NoColorSpace` (default). + * + * @type {?Texture} * @default null */ alphaMap: Texture | null; diff --git a/types/three/src/materials/PointsMaterial.d.ts b/types/three/src/materials/PointsMaterial.d.ts index 3cdc56177b09a4..4c873f686b6d64 100644 --- a/types/three/src/materials/PointsMaterial.d.ts +++ b/types/three/src/materials/PointsMaterial.d.ts @@ -14,6 +14,11 @@ export interface PointsMaterialProperties extends MaterialProperties { * with {@link Material#transparent} or {@link Material#alphaTest}. The texture map * color is modulated by the diffuse `color`. * + * `map` represents color data, and the texture must be assigned a + * {@link Texture#colorSpace}. Most `map` textures set + * `texture.colorSpace = SRGBColorSpace`. + * + * @type {?Texture} * @default null */ map: Texture | null; @@ -27,6 +32,10 @@ export interface PointsMaterialProperties extends MaterialProperties { * green in DXT-compressed and uncompressed RGB 565 formats. Luminance-only and * luminance/alpha textures will also still work as expected. * + * `alphaMap` represents non-color data. Any texture assigned must have + * `texture.colorSpace = NoColorSpace` (default). + * + * @type {?Texture} * @default null */ alphaMap: Texture | null; diff --git a/types/three/src/materials/ShaderMaterial.d.ts b/types/three/src/materials/ShaderMaterial.d.ts index 4ef9641d09047f..3bde9954c9de6e 100644 --- a/types/three/src/materials/ShaderMaterial.d.ts +++ b/types/three/src/materials/ShaderMaterial.d.ts @@ -7,6 +7,7 @@ import { Vector2Tuple } from "../math/Vector2.js"; import { Vector3Tuple } from "../math/Vector3.js"; import { Vector4Tuple } from "../math/Vector4.js"; import { IUniform } from "../renderers/shaders/UniformsLib.js"; +import { Texture } from "../textures/Texture.js"; import { MapColorPropertiesToColorRepresentations, Material, MaterialJSON, MaterialProperties } from "./Material.js"; export interface ShaderMaterialProperties extends MaterialProperties { @@ -258,6 +259,7 @@ export class ShaderMaterial extends Material { readonly isShaderMaterial: boolean; setValues(values?: ShaderMaterialParameters): void; toJSON(meta?: JSONMeta): ShaderMaterialJSON; + fromJSON(json: MaterialJSON, textures: Record): this; } // eslint-disable-next-line @typescript-eslint/no-empty-interface diff --git a/types/three/src/materials/SpriteMaterial.d.ts b/types/three/src/materials/SpriteMaterial.d.ts index e5fff0a18235f8..03abf16df2a9c5 100644 --- a/types/three/src/materials/SpriteMaterial.d.ts +++ b/types/three/src/materials/SpriteMaterial.d.ts @@ -14,6 +14,11 @@ export interface SpriteMaterialProperties extends MaterialProperties { * with {@link Material#transparent} or {@link Material#alphaTest}. The texture map * color is modulated by the diffuse `color`. * + * `map` represents color data, and the texture must be assigned a + * {@link Texture#colorSpace}. Most `map` textures set + * `texture.colorSpace = SRGBColorSpace`. + * + * @type {?Texture} * @default null */ map: Texture | null; @@ -27,6 +32,10 @@ export interface SpriteMaterialProperties extends MaterialProperties { * green in DXT-compressed and uncompressed RGB 565 formats. Luminance-only and * luminance/alpha textures will also still work as expected. * + * `alphaMap` represents non-color data. Any texture assigned must have + * `texture.colorSpace = NoColorSpace` (default). + * + * @type {?Texture} * @default null */ alphaMap: Texture | null; diff --git a/types/three/src/materials/nodes/Line2NodeMaterial.d.ts b/types/three/src/materials/nodes/Line2NodeMaterial.d.ts index 443dc719c10784..15c5fe4e0c8738 100644 --- a/types/three/src/materials/nodes/Line2NodeMaterial.d.ts +++ b/types/three/src/materials/nodes/Line2NodeMaterial.d.ts @@ -7,44 +7,52 @@ export interface Line2NodeMaterialNodeProperties extends NodeMaterialNodePropert /** * The dash offset. * + * @type {number} * @default 0 */ dashOffset: number; - /** - * Defines the lines color. - * - * @default null - */ - lineColorNode: Node | null; /** * Defines the offset. * + * @type {?Node} * @default null */ offsetNode: Node | null; /** * Defines the dash scale. * + * @type {?Node} * @default null */ dashScaleNode: Node | null; /** * Defines the dash size. * + * @type {?Node} * @default null */ dashSizeNode: Node | null; /** * Defines the gap size. * + * @type {?Node} * @default null */ gapSizeNode: Node | null; + set lineColorNode(value: Node | null); + /** + * Defines the lines color. + * + * @deprecated since r185. Use {@link NodeMaterial#colorNode} instead. + * @type {?Node} + */ + get lineColorNode(): Node | null; set worldUnits(value: boolean); /** * Whether the lines should sized in world units or not. * When set to `false` the unit is pixel. * + * @type {boolean} * @default false */ get worldUnits(): boolean; @@ -67,6 +75,8 @@ export interface Line2NodeMaterialParameters /** * This node material can be used to render lines with a size larger than one * by representing them as instanced meshes. + * + * @augments NodeMaterial */ declare class Line2NodeMaterial extends NodeMaterial { /** @@ -78,17 +88,12 @@ declare class Line2NodeMaterial extends NodeMaterial { /** * This flag can be used for type testing. * + * @type {boolean} + * @readonly * @default true */ readonly isLine2NodeMaterial: boolean; setValues(values?: Line2NodeMaterialParameters): void; - /** - * Copies the properties of the given material to this instance. - * - * @param {Line2NodeMaterial} source - The material to copy. - * @return {Line2NodeMaterial} A reference to this material. - */ - copy(source: Line2NodeMaterial): this; } // eslint-disable-next-line @typescript-eslint/no-empty-interface diff --git a/types/three/src/materials/nodes/NodeMaterial.d.ts b/types/three/src/materials/nodes/NodeMaterial.d.ts index ee26ad9e902b14..e84b00a8a57d1b 100644 --- a/types/three/src/materials/nodes/NodeMaterial.d.ts +++ b/types/three/src/materials/nodes/NodeMaterial.d.ts @@ -4,6 +4,7 @@ import LightingModel from "../../nodes/core/LightingModel.js"; import MRTNode from "../../nodes/core/MRTNode.js"; import Node from "../../nodes/core/Node.js"; import NodeBuilder from "../../nodes/core/NodeBuilder.js"; +import LightingNode from "../../nodes/lighting/LightingNode.js"; import LightsNode from "../../nodes/lighting/LightsNode.js"; import { MapColorPropertiesToColorRepresentations, Material, MaterialParameters } from "../Material.js"; import NodeMaterialObserver from "./manager/NodeMaterialObserver.js"; @@ -21,14 +22,6 @@ export interface NodeMaterialNodeProperties { * @default false */ lights: boolean; - /** - * Whether this material uses hardware clipping or not. - * This property is managed by the engine and should not be - * modified by apps. - * - * @default false - */ - hardwareClipping: boolean; /** * Node materials which set their `lights` property to `true` * are affected by all lights of the scene. Sometimes selective @@ -416,9 +409,16 @@ declare class NodeMaterial extends Material { * Setups the lights node based on the scene, environment and material. * * @param {NodeBuilder} builder - The current node builder. - * @return {LightsNode} The lights node. + * @return {LightingNode} The lights node. + */ + setupMaterialLightings(builder: NodeBuilder): LightingNode[]; + /** + * Setups the ambient occlusion node from the material. + * + * @param {NodeBuilder} builder - The current node builder. + * @return {Node} The ambient occlusion node. */ - setupLights(builder: NodeBuilder): LightsNode; + setupAmbientOcclusion(builder: NodeBuilder): Node; /** * This method should be implemented by most derived materials * since it defines the material's lighting model. @@ -454,6 +454,26 @@ declare class NodeMaterial extends Material { /** * Setups the output node. * + * This method can be implemented by derived materials to extend the functionality + * of the material's output or replace it altogether. + * + * ```js + * class ColoredShadowMaterial extends MeshPhongNodeMaterial { + * constructor( parameters ) { + * super( parameters ); + * this._shadeColor = uniform( new Color( parameters.shadeColor ?? 0xff0000 ) ); + * } + * + * setupOutput( builder, outputNode ) { + * // Modify the native output of the MeshPhongNodeMaterial fragment shader + * const brightness = min( outputNode.r, 1.0 ); + * const mixedColor = mix( this._shadeColor, diffuseColor.rgb, brightness ); + * // Return new output back into NodeMaterial flow + * return super.setupOutput( builder, vec4( mixedColor, outputNode.a ) ); + * } + * } + * ``` + * * @param {NodeBuilder} builder - The current node builder. * @param {Node} outputNode - The existing output node. * @return {Node} The output node. @@ -468,12 +488,12 @@ declare class NodeMaterial extends Material { */ setDefaultValues(material: Material): void; /** - * Copies the properties of the given node material to this instance. + * Copies the common properties of the given material to this instance. * - * @param {NodeMaterial} source - The material to copy. + * @param {Material} source - The material to copy. * @return {NodeMaterial} A reference to this node material. */ - copy(source: NodeMaterial): this; + copy(source: Material): this; } // eslint-disable-next-line @typescript-eslint/no-empty-interface diff --git a/types/three/src/materials/nodes/manager/NodeMaterialObserver.d.ts b/types/three/src/materials/nodes/manager/NodeMaterialObserver.d.ts index 1d8ce8a058d45c..c6e0e7b5112e70 100644 --- a/types/three/src/materials/nodes/manager/NodeMaterialObserver.d.ts +++ b/types/three/src/materials/nodes/manager/NodeMaterialObserver.d.ts @@ -1,12 +1,5 @@ -import { BufferAttribute } from "../../../core/BufferAttribute.js"; -import { BufferGeometry } from "../../../core/BufferGeometry.js"; -import { Light } from "../../../lights/Light.js"; import NodeBuilder from "../../../nodes/core/NodeBuilder.js"; -import NodeFrame from "../../../nodes/core/NodeFrame.js"; -import LightsNode from "../../../nodes/lighting/LightsNode.js"; import Renderer from "../../../renderers/common/Renderer.js"; -import RenderObject from "../../../renderers/common/RenderObject.js"; -import { Material } from "../../Material.js"; /** * This class is used by {@link WebGPURenderer} as management component. @@ -20,13 +13,6 @@ declare class NodeMaterialObserver { * @param {NodeBuilder} builder - The node builder. */ constructor(builder: NodeBuilder); - /** - * A node material can be used by more than one render object so the - * monitor must maintain a list of render objects. - * - * @type {WeakMap} - */ - renderObjects: WeakMap; /** * Whether the material uses node objects or not. * @@ -52,13 +38,6 @@ declare class NodeMaterialObserver { * @default 0 */ renderId: number; - /** - * Returns `true` if the given render object is verified for the first time of this observer. - * - * @param {RenderObject} renderObject - The render object. - * @return {boolean} Whether the given render object is verified for the first time of this observer. - */ - firstInitialization(renderObject: RenderObject): boolean; /** * Returns `true` if the current rendering produces motion vectors. * @@ -66,21 +45,6 @@ declare class NodeMaterialObserver { * @return {boolean} Whether the current rendering produces motion vectors or not. */ needsVelocity(renderer: Renderer): boolean; - /** - * Returns monitoring data for the given render object. - * - * @param {RenderObject} renderObject - The render object. - * @return {Object} The monitoring data. - */ - getRenderObjectData(renderObject: RenderObject): unknown; - /** - * Returns an attribute data structure holding the attributes versions for - * monitoring. - * - * @param {Object} attributes - The geometry attributes. - * @return {Object} An object for monitoring the versions of attributes. - */ - getAttributesData(attributes: Record): unknown; /** * Returns `true` if the node builder's material uses * node properties. @@ -89,54 +53,6 @@ declare class NodeMaterialObserver { * @return {boolean} Whether the node builder's material uses node properties or not. */ containsNode(builder: NodeBuilder): boolean; - /** - * Returns a geometry data structure holding the geometry property values for - * monitoring. - * - * @param {BufferGeometry} geometry - The geometry. - * @return {Object} An object for monitoring geometry properties. - */ - getGeometryData(geometry: BufferGeometry): unknown; - /** - * Returns a material data structure holding the material property values for - * monitoring. - * - * @param {Material} material - The material. - * @return {Object} An object for monitoring material properties. - */ - getMaterialData(material: Material): unknown; - /** - * Returns `true` if the given render object has not changed its state. - * - * @param {RenderObject} renderObject - The render object. - * @param {Array} lightsData - The current material lights. - * @param {number} renderId - The current render ID. - * @return {boolean} Whether the given render object has changed its state or not. - */ - equals(renderObject: RenderObject, lightsData: Light[], renderId: number): boolean; - /** - * Returns the lights data for the given material lights. - * - * @param {Array} materialLights - The material lights. - * @return {Array} The lights data for the given material lights. - */ - getLightsData(materialLights: Light[]): unknown[]; - /** - * Returns the lights for the given lights node and render ID. - * - * @param {LightsNode} lightsNode - The lights node. - * @param {number} renderId - The render ID. - * @return {Array} The lights for the given lights node and render ID. - */ - getLights(lightsNode: LightsNode, renderId: number): unknown[]; - /** - * Checks if the given render object requires a refresh. - * - * @param {RenderObject} renderObject - The render object. - * @param {NodeFrame} nodeFrame - The current node frame. - * @return {boolean} Whether the given render object requires a refresh or not. - */ - needsRefresh(renderObject: RenderObject, nodeFrame: NodeFrame): boolean; } export default NodeMaterialObserver; diff --git a/types/three/src/math/Box2.d.ts b/types/three/src/math/Box2.d.ts index de05083d0ee4b8..9c73a2b17cb511 100644 --- a/types/three/src/math/Box2.d.ts +++ b/types/three/src/math/Box2.d.ts @@ -1,4 +1,4 @@ -import { Vector2 } from "./Vector2.js"; +import { Vector2, Vector2Like } from "./Vector2.js"; // Math ////////////////////////////////////////////////////////////////////////////////// @@ -16,7 +16,7 @@ export class Box2 { max: Vector2; set(min: Vector2, max: Vector2): Box2; - setFromPoints(points: Vector2[]): Box2; + setFromPoints(points: Vector2Like[]): Box2; setFromCenterAndSize(center: Vector2, size: Vector2): Box2; clone(): this; copy(box: Box2): this; @@ -24,7 +24,7 @@ export class Box2 { isEmpty(): boolean; getCenter(target: Vector2): Vector2; getSize(target: Vector2): Vector2; - expandByPoint(point: Vector2): Box2; + expandByPoint(point: Vector2Like): Box2; expandByVector(vector: Vector2): Box2; expandByScalar(scalar: number): Box2; containsPoint(point: Vector2): boolean; diff --git a/types/three/src/math/Box3.d.ts b/types/three/src/math/Box3.d.ts index 91560bdc771fe2..0daa1204c949f4 100644 --- a/types/three/src/math/Box3.d.ts +++ b/types/three/src/math/Box3.d.ts @@ -4,67 +4,303 @@ import { Matrix4 } from "./Matrix4.js"; import { Plane } from "./Plane.js"; import { Sphere } from "./Sphere.js"; import { Triangle } from "./Triangle.js"; -import { Vector3 } from "./Vector3.js"; +import { Vector3, type Vector3Like } from "./Vector3.js"; +/** + * Represents an axis-aligned bounding box (AABB) in 3D space. + */ export class Box3 { + /** + * Constructs a new bounding box. + * + * @param {Vector3} [min=(Infinity,Infinity,Infinity)] - A vector representing the lower boundary of the box. + * @param {Vector3} [max=(-Infinity,-Infinity,-Infinity)] - A vector representing the upper boundary of the box. + */ constructor(min?: Vector3, max?: Vector3); - /** - * @default new THREE.Vector3( + Infinity, + Infinity, + Infinity ) + * This flag can be used for type testing. + * + * @type {boolean} + * @readonly + * @default true + */ + readonly isBox3: boolean; + /** + * The lower boundary of the box. + * + * @type {Vector3} */ min: Vector3; - /** - * @default new THREE.Vector3( - Infinity, - Infinity, - Infinity ) + * The upper boundary of the box. + * + * @type {Vector3} */ max: Vector3; - readonly isBox3: true; - + /** + * Sets the lower and upper boundaries of this box. + * Please note that this method only copies the values from the given objects. + * + * @param {Vector3} min - The lower boundary of the box. + * @param {Vector3} max - The upper boundary of the box. + * @return {Box3} A reference to this bounding box. + */ set(min: Vector3, max: Vector3): this; + /** + * Sets the upper and lower bounds of this box so it encloses the position data + * in the given array. + * + * @param {Array} array - An array holding 3D position data. + * @return {Box3} A reference to this bounding box. + */ setFromArray(array: ArrayLike): this; - setFromBufferAttribute(bufferAttribute: BufferAttribute): this; - setFromPoints(points: Vector3[]): this; + /** + * Sets the upper and lower bounds of this box so it encloses the position data + * in the given buffer attribute. + * + * @param {BufferAttribute} attribute - A buffer attribute holding 3D position data. + * @return {Box3} A reference to this bounding box. + */ + setFromBufferAttribute(attribute: BufferAttribute): this; + /** + * Sets the upper and lower bounds of this box so it encloses the position data + * in the given array. + * + * @param {Array} points - An array holding 3D position data as instances of {@link Vector3}. + * @return {Box3} A reference to this bounding box. + */ + setFromPoints(points: Array): this; + /** + * Centers this box on the given center vector and sets this box's width, height and + * depth to the given size values. + * + * @param {Vector3} center - The center of the box. + * @param {Vector3} size - The x, y and z dimensions of the box. + * @return {Box3} A reference to this bounding box. + */ setFromCenterAndSize(center: Vector3, size: Vector3): this; + /** + * Computes the world-axis-aligned bounding box for the given 3D object + * (including its children), accounting for the object's, and children's, + * world transforms. The function may result in a larger box than strictly necessary. + * + * Note: To compute the correct bounding box, make sure the given 3D object + * has an up-to-date world matrix that reflects the current transformation of its + * ancestor nodes. Call `object.updateWorldMatrix( true, false )` beforehand if + * you're unsure. + * + * @param {Object3D} object - The 3D object to compute the bounding box for. + * @param {boolean} [precise=false] - If set to `true`, the method computes the smallest + * world-axis-aligned bounding box at the expense of more computation. + * @return {Box3} A reference to this bounding box. + */ setFromObject(object: Object3D, precise?: boolean): this; + /** + * Returns a new box with copied values from this instance. + * + * @return {Box3} A clone of this instance. + */ clone(): this; + /** + * Copies the values of the given box to this instance. + * + * @param {Box3} box - The box to copy. + * @return {Box3} A reference to this bounding box. + */ copy(box: Box3): this; + /** + * Makes this box empty which means in encloses a zero space in 3D. + * + * @return {Box3} A reference to this bounding box. + */ makeEmpty(): this; + /** + * Returns true if this box includes zero points within its bounds. + * Note that a box with equal lower and upper bounds still includes one + * point, the one both bounds share. + * + * @return {boolean} Whether this box is empty or not. + */ isEmpty(): boolean; + /** + * Returns the center point of this box. + * + * @param {Vector3} target - The target vector that is used to store the method's result. + * @return {Vector3} The center point. + */ getCenter(target: Vector3): Vector3; + /** + * Returns the dimensions of this box. + * + * @param {Vector3} target - The target vector that is used to store the method's result. + * @return {Vector3} The size. + */ getSize(target: Vector3): Vector3; - expandByPoint(point: Vector3): this; + /** + * Expands the boundaries of this box to include the given point. + * + * @param {Vector3} point - The point that should be included by the bounding box. + * @return {Box3} A reference to this bounding box. + */ + expandByPoint(point: Vector3Like): this; + /** + * Expands this box equilaterally by the given vector. The width of this + * box will be expanded by the x component of the vector in both + * directions. The height of this box will be expanded by the y component of + * the vector in both directions. The depth of this box will be + * expanded by the z component of the vector in both directions. + * + * @param {Vector3} vector - The vector that should expand the bounding box. + * @return {Box3} A reference to this bounding box. + */ expandByVector(vector: Vector3): this; + /** + * Expands each dimension of the box by the given scalar. If negative, the + * dimensions of the box will be contracted. + * + * @param {number} scalar - The scalar value that should expand the bounding box. + * @return {Box3} A reference to this bounding box. + */ expandByScalar(scalar: number): this; + /** + * Expands the boundaries of this box to include the given 3D object and + * its children, accounting for the object's, and children's, world + * transforms. The function may result in a larger box than strictly + * necessary (unless the precise parameter is set to true). + * + * @param {Object3D} object - The 3D object that should expand the bounding box. + * @param {boolean} precise - If set to `true`, the method expands the bounding box + * as little as necessary at the expense of more computation. + * @return {Box3} A reference to this bounding box. + */ expandByObject(object: Object3D, precise?: boolean): this; + /** + * Returns `true` if the given point lies within or on the boundaries of this box. + * + * @param {Vector3} point - The point to test. + * @return {boolean} Whether the bounding box contains the given point or not. + */ containsPoint(point: Vector3): boolean; + /** + * Returns `true` if this bounding box includes the entirety of the given bounding box. + * If this box and the given one are identical, this function also returns `true`. + * + * @param {Box3} box - The bounding box to test. + * @return {boolean} Whether the bounding box contains the given bounding box or not. + */ containsBox(box: Box3): boolean; + /** + * Returns a point as a proportion of this box's width, height and depth. + * + * @param {Vector3} point - A point in 3D space. + * @param {Vector3} target - The target vector that is used to store the method's result. + * @return {Vector3} A point as a proportion of this box's width, height and depth. + */ getParameter(point: Vector3, target: Vector3): Vector3; + /** + * Returns `true` if the given bounding box intersects with this bounding box. + * + * @param {Box3} box - The bounding box to test. + * @return {boolean} Whether the given bounding box intersects with this bounding box. + */ intersectsBox(box: Box3): boolean; + /** + * Returns `true` if the given bounding sphere intersects with this bounding box. + * + * @param {Sphere} sphere - The bounding sphere to test. + * @return {boolean} Whether the given bounding sphere intersects with this bounding box. + */ intersectsSphere(sphere: Sphere): boolean; + /** + * Returns `true` if the given plane intersects with this bounding box. + * + * @param {Plane} plane - The plane to test. + * @return {boolean} Whether the given plane intersects with this bounding box. + */ intersectsPlane(plane: Plane): boolean; + /** + * Returns `true` if the given triangle intersects with this bounding box. + * + * @param {Triangle} triangle - The triangle to test. + * @return {boolean} Whether the given triangle intersects with this bounding box. + */ intersectsTriangle(triangle: Triangle): boolean; + /** + * Clamps the given point within the bounds of this box. + * + * @param {Vector3} point - The point to clamp. + * @param {Vector3} target - The target vector that is used to store the method's result. + * @return {Vector3} The clamped point. + */ clampPoint(point: Vector3, target: Vector3): Vector3; + /** + * Returns the euclidean distance from any edge of this box to the specified point. If + * the given point lies inside of this box, the distance will be `0`. + * + * @param {Vector3} point - The point to compute the distance to. + * @return {number} The euclidean distance. + */ distanceToPoint(point: Vector3): number; + /** + * Returns a bounding sphere that encloses this bounding box. + * + * @param {Sphere} target - The target sphere that is used to store the method's result. + * @return {Sphere} The bounding sphere that encloses this bounding box. + */ getBoundingSphere(target: Sphere): Sphere; + /** + * Computes the intersection of this bounding box and the given one, setting the upper + * bound of this box to the lesser of the two boxes' upper bounds and the + * lower bound of this box to the greater of the two boxes' lower bounds. If + * there's no overlap, makes this box empty. + * + * @param {Box3} box - The bounding box to intersect with. + * @return {Box3} A reference to this bounding box. + */ intersect(box: Box3): this; + /** + * Computes the union of this box and another and the given one, setting the upper + * bound of this box to the greater of the two boxes' upper bounds and the + * lower bound of this box to the lesser of the two boxes' lower bounds. + * + * @param {Box3} box - The bounding box that will be unioned with this instance. + * @return {Box3} A reference to this bounding box. + */ union(box: Box3): this; + /** + * Transforms this bounding box by the given 4x4 transformation matrix. + * + * @param {Matrix4} matrix - The transformation matrix. + * @return {Box3} A reference to this bounding box. + */ applyMatrix4(matrix: Matrix4): this; - translate(offset: Vector3): this; - equals(box: Box3): boolean; /** - * @deprecated Use {@link Box3#isEmpty .isEmpty()} instead. + * Adds the given offset to both the upper and lower bounds of this bounding box, + * effectively moving it in 3D space. + * + * @param {Vector3} offset - The offset that should be used to translate the bounding box. + * @return {Box3} A reference to this bounding box. */ - empty(): any; + translate(offset: Vector3): this; /** - * @deprecated Use {@link Box3#intersectsBox .intersectsBox()} instead. + * Returns `true` if this bounding box is equal with the given one. + * + * @param {Box3} box - The box to test for equality. + * @return {boolean} Whether this bounding box is equal with the given one. */ - isIntersectionBox(b: any): any; + equals(box: Box3): boolean; /** - * @deprecated Use {@link Box3#intersectsSphere .intersectsSphere()} instead. + * Returns a serialized structure of the bounding box. + * + * @return {Object} Serialized structure with fields representing the object state. */ - isIntersectionSphere(s: any): any; - toJSON(): Box3JSON; + /** + * Returns a serialized structure of the bounding box. + * + * @param {Object} json - The serialized json to set the box from. + * @return {Box3} A reference to this bounding box. + */ fromJSON(json: Box3JSON): this; } diff --git a/types/three/src/math/Color.d.ts b/types/three/src/math/Color.d.ts index eb40c9aaba30bf..ab553ef27d94fc 100644 --- a/types/three/src/math/Color.d.ts +++ b/types/three/src/math/Color.d.ts @@ -230,8 +230,8 @@ export class Color { */ setFromVector3(vector: Vector3): this; - setScalar(scalar: number): Color; - setHex(hex: number, colorSpace?: string): Color; + setScalar(scalar: number): this; + setHex(hex: number, colorSpace?: string): this; /** * Sets this color from RGB values. @@ -239,7 +239,7 @@ export class Color { * @param g Green channel value between 0 and 1. * @param b Blue channel value between 0 and 1. */ - setRGB(r: number, g: number, b: number, colorSpace?: string): Color; + setRGB(r: number, g: number, b: number, colorSpace?: string): this; /** * Sets this color from HSL values. @@ -249,20 +249,20 @@ export class Color { * @param s Saturation value channel between 0 and 1. * @param l Value channel value between 0 and 1. */ - setHSL(h: number, s: number, l: number, colorSpace?: string): Color; + setHSL(h: number, s: number, l: number, colorSpace?: string): this; /** * Sets this color from a CSS context style string. * @param contextStyle Color in CSS context style format. */ - setStyle(style: string, colorSpace?: string): Color; + setStyle(style: string, colorSpace?: string): this; /** * Sets this color from a color name. * Faster than {@link Color#setStyle .setStyle()} method if you don't need the other CSS-style formats. * @param style Color name in X11 format. */ - setColorName(style: string, colorSpace?: string): Color; + setColorName(style: string, colorSpace?: string): this; /** * Clones this color. @@ -279,23 +279,23 @@ export class Color { * Copies given color making conversion from `SRGBColorSpace` to `LinearSRGBColorSpace`. * @param color Color to copy. */ - copySRGBToLinear(color: Color): Color; + copySRGBToLinear(color: Color): this; /** * Copies given color making conversion from `LinearSRGBColorSpace` to `SRGBColorSpace`. * @param color Color to copy. */ - copyLinearToSRGB(color: Color): Color; + copyLinearToSRGB(color: Color): this; /** * Converts this color from `SRGBColorSpace` to `LinearSRGBColorSpace`. */ - convertSRGBToLinear(): Color; + convertSRGBToLinear(): this; /** * Converts this color from `LinearSRGBColorSpace` to `SRGBColorSpace`. */ - convertLinearToSRGB(): Color; + convertLinearToSRGB(): this; /** * Returns the hexadecimal value of this color. diff --git a/types/three/src/math/FrustumArray.d.ts b/types/three/src/math/FrustumArray.d.ts index 7e179fb4a622e2..3edb6fa87fc473 100644 --- a/types/three/src/math/FrustumArray.d.ts +++ b/types/three/src/math/FrustumArray.d.ts @@ -6,22 +6,81 @@ import { Box3 } from "./Box3.js"; import { Sphere } from "./Sphere.js"; import { Vector3 } from "./Vector3.js"; -declare class FrustumArray { +/** + * FrustumArray is used to determine if an object is visible in at least one camera + * from an array of cameras. This is particularly useful for multi-view renderers. + */ +export class FrustumArray { + /** + * The coordinate system to use. + * + * @type {WebGLCoordinateSystem|WebGPUCoordinateSystem} + * @default WebGLCoordinateSystem + */ coordinateSystem: CoordinateSystem; - - constructor(); - - intersectsObject(object: Object3D, cameraArray: ArrayCamera): boolean; - - intersectsSprite(sprite: Sprite, cameraArray: ArrayCamera): boolean; - - intersectsSprite(sphere: Sphere, cameraArray: ArrayCamera): boolean; - - intersectsBox(box: Box3, cameraArray: ArrayCamera): boolean; - - containsPoint(point: Vector3, cameraArray: ArrayCamera): boolean; - + /** + * Computes and caches a frustum for each camera of the given array camera. + * + * @param {ArrayCamera} cameraArray - The array camera whose sub-cameras define the frustums. + * @return {FrustumArray} A reference to this frustum array. + */ + setFromArrayCamera(cameraArray: ArrayCamera): FrustumArray; + /** + * Returns `true` if the 3D object's bounding sphere is intersecting any cached frustum. + * + * {@link FrustumArray#setFromArrayCamera} must be called once per render before this method. + * + * @param {Object3D} object - The 3D object to test. + * @return {boolean} Whether the 3D object is visible in any camera. + */ + intersectsObject(object: Object3D): boolean; + /** + * Returns `true` if the given sprite is intersecting any cached frustum. + * + * {@link FrustumArray#setFromArrayCamera} must be called once per render before this method. + * + * @param {Sprite} sprite - The sprite to test. + * @return {boolean} Whether the sprite is visible in any camera. + */ + intersectsSprite(sprite: Sprite): boolean; + /** + * Returns `true` if the given bounding sphere is intersecting any cached frustum. + * + * {@link FrustumArray#setFromArrayCamera} must be called once per render before this method. + * + * @param {Sphere} sphere - The bounding sphere to test. + * @return {boolean} Whether the sphere is visible in any camera. + */ + intersectsSphere(sphere: Sphere): boolean; + /** + * Returns `true` if the given bounding box is intersecting any cached frustum. + * + * {@link FrustumArray#setFromArrayCamera} must be called once per render before this method. + * + * @param {Box3} box - The bounding box to test. + * @return {boolean} Whether the box is visible in any camera. + */ + intersectsBox(box: Box3): boolean; + /** + * Returns `true` if the given point lies within any cached frustum. + * + * {@link FrustumArray#setFromArrayCamera} must be called once per render before this method. + * + * @param {Vector3} point - The point to test. + * @return {boolean} Whether the point is visible in any camera. + */ + containsPoint(point: Vector3): boolean; + /** + * Copies the values of the given frustum array to this instance. + * + * @param {FrustumArray} frustumArray - The frustum array to copy. + * @return {FrustumArray} A reference to this frustum array. + */ + copy(source: FrustumArray): this; + /** + * Returns a new frustum array with copied values from this instance. + * + * @return {FrustumArray} A clone of this instance. + */ clone(): FrustumArray; } - -export { FrustumArray }; diff --git a/types/three/src/math/Interpolant.d.ts b/types/three/src/math/Interpolant.d.ts index 9d2b1aced3ea47..3acabddddbe68a 100644 --- a/types/three/src/math/Interpolant.d.ts +++ b/types/three/src/math/Interpolant.d.ts @@ -1,10 +1,113 @@ -export abstract class Interpolant { - constructor(parameterPositions: any, sampleValues: any, sampleSize: number, resultBuffer?: any); +import { TypedArray } from "../core/BufferAttribute.js"; - parameterPositions: any; - sampleValues: any; - valueSize: number; - resultBuffer: any; - - evaluate(time: number): any; +/** + * Abstract base class of interpolants over parametric samples. + * + * The parameter domain is one dimensional, typically the time or a path + * along a curve defined by the data. + * + * The sample values can have any dimensionality and derived classes may + * apply special interpretations to the data. + * + * This class provides the interval seek in a Template Method, deferring + * the actual interpolation to derived classes. + * + * Time complexity is O(1) for linear access crossing at most two points + * and O(log N) for random access, where N is the number of positions. + * + * References: {@link http://www.oodesign.com/template-method-pattern.html} + * + * @abstract + */ +export abstract class Interpolant { + /** + * Constructs a new interpolant. + * + * @param {TypedArray} parameterPositions - The parameter positions hold the interpolation factors. + * @param {TypedArray} sampleValues - The sample values. + * @param {number} sampleSize - The sample size + * @param {TypedArray} [resultBuffer] - The result buffer. + */ + constructor( + parameterPositions: TypedArray, + sampleValues: TypedArray, + sampleSize: number, + resultBuffer?: TypedArray, + ); + /** + * The parameter positions. + * + * @type {TypedArray} + */ + parameterPositions: TypedArray; + /** + * The result buffer. + * + * @type {TypedArray} + */ + resultBuffer: TypedArray; + /** + * The sample values. + * + * @type {TypedArray} + */ + sampleValues: TypedArray; + /** + * The value size. + * + * @type {TypedArray} + */ + valueSize: TypedArray; + /** + * The interpolation settings. + * + * @type {?Object} + * @default null + */ + settings: TSettings | null; + /** + * The default settings object. + * + * @type {Object} + */ + DefaultSettings_: TSettings; + /** + * Evaluate the interpolant at position `t`. + * + * @param {number} t - The interpolation factor. + * @return {TypedArray} The result buffer. + */ + evaluate(t: number): TypedArray; + /** + * Returns the interpolation settings. + * + * @return {Object} The interpolation settings. + */ + getSettings_(): unknown; + /** + * Copies a sample value to the result buffer. + * + * @param {number} index - An index into the sample value buffer. + * @return {TypedArray} The result buffer. + */ + copySampleValue_(index: number): TypedArray; + /** + * Copies a sample value to the result buffer. + * + * @abstract + * @param {number} i1 - An index into the sample value buffer. + * @param {number} t0 - The previous interpolation factor. + * @param {number} t - The current interpolation factor. + * @param {number} t1 - The next interpolation factor. + * @return {TypedArray} The result buffer. + */ + abstract interpolate_(i1: number, t0: number, t: number, t1: number): TypedArray; + /** + * Optional method that is executed when the interval has changed. + * + * @param {number} i1 - An index into the sample value buffer. + * @param {number} t0 - The previous interpolation factor. + * @param {number} t - The current interpolation factor. + */ + intervalChanged_(i1: number, t0: number, t: number): void; } diff --git a/types/three/src/math/Matrix3.d.ts b/types/three/src/math/Matrix3.d.ts index 0b593fcb81193f..46aef20cf34253 100644 --- a/types/three/src/math/Matrix3.d.ts +++ b/types/three/src/math/Matrix3.d.ts @@ -99,10 +99,19 @@ export class Matrix3 { setUvTransform(tx: number, ty: number, sx: number, sy: number, rotation: number, cx: number, cy: number): this; + /** + * @deprecated Use .makeScale() instead. + */ scale(sx: number, sy: number): this; + /** + * @deprecated Use .makeRotation() instead. + */ rotate(theta: number): this; + /** + * @deprecated Use .makeTranslation() instead. + */ translate(tx: number, ty: number): this; /** diff --git a/types/three/src/math/Matrix4.d.ts b/types/three/src/math/Matrix4.d.ts index 458d7e4d7b2d36..d3f35995c254d6 100644 --- a/types/three/src/math/Matrix4.d.ts +++ b/types/three/src/math/Matrix4.d.ts @@ -24,38 +24,69 @@ export type Matrix4Tuple = [ ]; /** - * A 4x4 Matrix. + * Represents a 4x4 matrix. * - * @example - * // Simple rig for rotating around 3 axes + * The most common use of a 4x4 matrix in 3D computer graphics is as a transformation matrix. + * For an introduction to transformation matrices as used in WebGL, check out [this tutorial](https://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices) + * + * This allows a 3D vector representing a point in 3D space to undergo + * transformations such as translation, rotation, shear, scale, reflection, + * orthogonal or perspective projection and so on, by being multiplied by the + * matrix. This is known as `applying` the matrix to the vector. + * + * A Note on Row-Major and Column-Major Ordering: + * + * The constructor and {@link Matrix3#set} method take arguments in + * [row-major](https://en.wikipedia.org/wiki/Row-_and_column-major_order#Column-major_order) + * order, while internally they are stored in the {@link Matrix3#elements} array in column-major order. + * This means that calling: + * ```js * const m = new THREE.Matrix4(); - * const m1 = new THREE.Matrix4(); - * const m2 = new THREE.Matrix4(); - * const m3 = new THREE.Matrix4(); - * const alpha = 0; - * const beta = Math.PI; - * const gamma = Math.PI/2; - * m1.makeRotationX( alpha ); - * m2.makeRotationY( beta ); - * m3.makeRotationZ( gamma ); - * m.multiplyMatrices( m1, m2 ); - * m.multiply( m3 ); + * m.set( 11, 12, 13, 14, + * 21, 22, 23, 24, + * 31, 32, 33, 34, + * 41, 42, 43, 44 ); + * ``` + * will result in the elements array containing: + * ```js + * m.elements = [ 11, 21, 31, 41, + * 12, 22, 32, 42, + * 13, 23, 33, 43, + * 14, 24, 34, 44 ]; + * ``` + * and internally all calculations are performed using column-major ordering. + * However, as the actual ordering makes no difference mathematically and + * most people are used to thinking about matrices in row-major order, the + * three.js documentation shows matrices in row-major order. Just bear in + * mind that if you are reading the source code, you'll have to take the + * transpose of any matrices outlined here to make sense of the calculations. */ export class Matrix4 { - readonly isMatrix4: true; - - /** - * Array with matrix values. - * @default [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] - */ - elements: Matrix4Tuple; - /** - * Creates an identity matrix. + * Constructs a new 4x4 matrix. This constructor + * initializes the matrix as an identity matrix. */ constructor(); /** - * Creates a 4x4 matrix with the given arguments in row-major order. + * Constructs a new 4x4 matrix. The arguments are supposed to be + * in row-major order. + * + * @param {number} [n11] - 1-1 matrix element. + * @param {number} [n12] - 1-2 matrix element. + * @param {number} [n13] - 1-3 matrix element. + * @param {number} [n14] - 1-4 matrix element. + * @param {number} [n21] - 2-1 matrix element. + * @param {number} [n22] - 2-2 matrix element. + * @param {number} [n23] - 2-3 matrix element. + * @param {number} [n24] - 2-4 matrix element. + * @param {number} [n31] - 3-1 matrix element. + * @param {number} [n32] - 3-2 matrix element. + * @param {number} [n33] - 3-3 matrix element. + * @param {number} [n34] - 3-4 matrix element. + * @param {number} [n41] - 4-1 matrix element. + * @param {number} [n42] - 4-2 matrix element. + * @param {number} [n43] - 4-3 matrix element. + * @param {number} [n44] - 4-4 matrix element. */ constructor( n11: number, @@ -75,9 +106,33 @@ export class Matrix4 { n43: number, n44: number, ); - /** - * Sets all fields of this matrix. + * A column-major list of matrix values. + * + * @type {Array} + */ + elements: Matrix4Tuple; + /** + * Sets the elements of the matrix.The arguments are supposed to be + * in row-major order. + * + * @param {number} [n11] - 1-1 matrix element. + * @param {number} [n12] - 1-2 matrix element. + * @param {number} [n13] - 1-3 matrix element. + * @param {number} [n14] - 1-4 matrix element. + * @param {number} [n21] - 2-1 matrix element. + * @param {number} [n22] - 2-2 matrix element. + * @param {number} [n23] - 2-3 matrix element. + * @param {number} [n24] - 2-4 matrix element. + * @param {number} [n31] - 3-1 matrix element. + * @param {number} [n32] - 3-2 matrix element. + * @param {number} [n33] - 3-3 matrix element. + * @param {number} [n34] - 3-4 matrix element. + * @param {number} [n41] - 4-1 matrix element. + * @param {number} [n42] - 4-2 matrix element. + * @param {number} [n43] - 4-3 matrix element. + * @param {number} [n44] - 4-4 matrix element. + * @return {Matrix4} A reference to this matrix. */ set( n11: number, @@ -97,146 +152,303 @@ export class Matrix4 { n43: number, n44: number, ): this; - /** - * Resets this matrix to identity. + * Sets this matrix to the 4x4 identity matrix. + * + * @return {Matrix4} A reference to this matrix. */ identity(): this; - + /** + * Returns a matrix with copied values from this instance. + * + * @return {Matrix4} A clone of this instance. + */ clone(): Matrix4; - + /** + * Copies the values of the given matrix to this instance. + * + * @param {Matrix4} m - The matrix to copy. + * @return {Matrix4} A reference to this matrix. + */ copy(m: Matrix4): this; - + /** + * Copies the translation component of the given matrix + * into this matrix's translation component. + * + * @param {Matrix4} m - The matrix to copy the translation component. + * @return {Matrix4} A reference to this matrix. + */ copyPosition(m: Matrix4): this; - /** - * Set the upper 3x3 elements of this matrix to the values of the Matrix3 m. + * Set the upper 3x3 elements of this matrix to the values of given 3x3 matrix. + * + * @param {Matrix3} m - The 3x3 matrix. + * @return {Matrix4} A reference to this matrix. */ setFromMatrix3(m: Matrix3): this; - + /** + * Extracts the basis of this matrix into the three axis vectors provided. + * + * @param {Vector3} xAxis - The basis's x axis. + * @param {Vector3} yAxis - The basis's y axis. + * @param {Vector3} zAxis - The basis's z axis. + * @return {Matrix4} A reference to this matrix. + */ extractBasis(xAxis: Vector3, yAxis: Vector3, zAxis: Vector3): this; - + /** + * Sets the given basis vectors to this matrix. + * + * @param {Vector3} xAxis - The basis's x axis. + * @param {Vector3} yAxis - The basis's y axis. + * @param {Vector3} zAxis - The basis's z axis. + * @return {Matrix4} A reference to this matrix. + */ makeBasis(xAxis: Vector3, yAxis: Vector3, zAxis: Vector3): this; - /** - * Copies the rotation component of the supplied matrix m into this matrix rotation component. + * Extracts the rotation component of the given matrix + * into this matrix's rotation component. + * + * Note: This method does not support reflection matrices. + * + * @param {Matrix4} m - The matrix. + * @return {Matrix4} A reference to this matrix. */ extractRotation(m: Matrix4): this; - + /** + * Sets the rotation component (the upper left 3x3 matrix) of this matrix to + * the rotation specified by the given Euler angles. The rest of + * the matrix is set to the identity. Depending on the {@link Euler#order}, + * there are six possible outcomes. See [this page](https://en.wikipedia.org/wiki/Euler_angles#Rotation_matrix) + * for a complete list. + * + * @param {Euler} euler - The Euler angles. + * @return {Matrix4} A reference to this matrix. + */ makeRotationFromEuler(euler: Euler): this; - + /** + * Sets the rotation component of this matrix to the rotation specified by + * the given Quaternion as outlined [here](https://en.wikipedia.org/wiki/Rotation_matrix#Quaternion) + * The rest of the matrix is set to the identity. + * + * @param {Quaternion} q - The Quaternion. + * @return {Matrix4} A reference to this matrix. + */ makeRotationFromQuaternion(q: Quaternion): this; - /** - * Sets the rotation component of the transformation matrix, looking from [eye]{@link Vector3} towards - * [target]{@link Vector3}, and oriented by the up-direction [up]{@link Vector3}. + * Sets the rotation component of the transformation matrix, looking from `eye` towards + * `target`, and oriented by the up-direction. + * + * @param {Vector3} eye - The eye vector. + * @param {Vector3} target - The target vector. + * @param {Vector3} up - The up vector. + * @return {Matrix4} A reference to this matrix. */ lookAt(eye: Vector3, target: Vector3, up: Vector3): this; - /** - * Multiplies this matrix by m. + * Post-multiplies this matrix by the given 4x4 matrix. + * + * @param {Matrix4} m - The matrix to multiply with. + * @return {Matrix4} A reference to this matrix. */ multiply(m: Matrix4): this; - + /** + * Pre-multiplies this matrix by the given 4x4 matrix. + * + * @param {Matrix4} m - The matrix to multiply with. + * @return {Matrix4} A reference to this matrix. + */ premultiply(m: Matrix4): this; - /** - * Sets this matrix to a x b. + * Multiples the given 4x4 matrices and stores the result + * in this matrix. + * + * @param {Matrix4} a - The first matrix. + * @param {Matrix4} b - The second matrix. + * @return {Matrix4} A reference to this matrix. */ multiplyMatrices(a: Matrix4, b: Matrix4): this; - /** - * Multiplies this matrix by s. + * Multiplies every component of the matrix by the given scalar. + * + * @param {number} s - The scalar. + * @return {Matrix4} A reference to this matrix. */ multiplyScalar(s: number): this; - /** - * Computes determinant of this matrix. - * Based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm + * Computes and returns the determinant of this matrix. + * + * Based on the method outlined [here](http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.html). + * + * @return {number} The determinant. */ determinant(): number; - /** - * Transposes this matrix. + * Computes and returns the determinant of the 4x4 matrix, but assumes the + * matrix is affine, saving some computations. + * + * For affine matrices (like an object's world matrix), this value equals the + * full 4x4 {@link Matrix4#determinant} but is cheaper to compute. + * + * Assumes the bottom row is [0, 0, 0, 1]. + * + * @return {number} The determinant of the matrix. + */ + determinantAffine(): number; + /** + * Transposes this matrix in place. + * + * @return {Matrix4} A reference to this matrix. */ transpose(): this; - /** - * Sets the position component for this matrix from vector v. + * Sets the position component for this matrix from the given vector, + * without affecting the rest of the matrix. + * + * @param {number|Vector3} v - The vector object. + * @return {Matrix4} A reference to this matrix. */ setPosition(v: Vector3): this; + /** + * Sets the position component for this matrix from the given vector, + * without affecting the rest of the matrix. + * + * @param {number} x - The x component of the vector. + * @param {number} y - The y component of the vector. + * @param {number} z - The z component of the vector. + * @return {Matrix4} A reference to this matrix. + */ setPosition(x: number, y: number, z: number): this; - /** - * Inverts this matrix. + * Inverts this matrix, using the [analytic method](https://en.wikipedia.org/wiki/Invertible_matrix#Analytic_solution). + * You can not invert with a determinant of zero. If you attempt this, the method produces + * a zero matrix instead. + * + * @return {Matrix4} A reference to this matrix. */ invert(): this; - /** - * Multiplies the columns of this matrix by vector v. + * Multiplies the columns of this matrix by the given vector. + * + * @param {Vector3} v - The scale vector. + * @return {Matrix4} A reference to this matrix. */ scale(v: Vector3): this; - + /** + * Gets the maximum scale value of the three axes. + * + * @return {number} The maximum scale. + */ getMaxScaleOnAxis(): number; - /** - * Sets this matrix as translation transform. + * Sets this matrix as a translation transform from the given vector. + * + * @param {Vector3} v - A translation vector. + * @return {Matrix4} A reference to this matrix. */ makeTranslation(v: Vector3): this; + /** + * Sets this matrix as a translation transform from the given vector. + * + * @param {number} x - The amount to translate in the X axis. + * @param {number} y - The amount to translate in the Y axis. + * @param {number} z - The amount to translate in the z axis. + * @return {Matrix4} A reference to this matrix. + */ makeTranslation(x: number, y: number, z: number): this; - /** - * Sets this matrix as rotation transform around x axis by theta radians. + * Sets this matrix as a rotational transformation around the X axis by + * the given angle. * - * @param theta Rotation angle in radians. + * @param {number} theta - The rotation in radians. + * @return {Matrix4} A reference to this matrix. */ makeRotationX(theta: number): this; - /** - * Sets this matrix as rotation transform around y axis by theta radians. + * Sets this matrix as a rotational transformation around the Y axis by + * the given angle. * - * @param theta Rotation angle in radians. + * @param {number} theta - The rotation in radians. + * @return {Matrix4} A reference to this matrix. */ makeRotationY(theta: number): this; - /** - * Sets this matrix as rotation transform around z axis by theta radians. + * Sets this matrix as a rotational transformation around the Z axis by + * the given angle. * - * @param theta Rotation angle in radians. + * @param {number} theta - The rotation in radians. + * @return {Matrix4} A reference to this matrix. */ makeRotationZ(theta: number): this; - /** - * Sets this matrix as rotation transform around axis by angle radians. - * Based on http://www.gamedev.net/reference/articles/article1199.asp. + * Sets this matrix as a rotational transformation around the given axis by + * the given angle. + * + * This is a somewhat controversial but mathematically sound alternative to + * rotating via Quaternions. See the discussion [here](https://www.gamedev.net/articles/programming/math-and-physics/do-we-really-need-quaternions-r1199). * - * @param axis Rotation axis. - * @param angle Rotation angle in radians. + * @param {Vector3} axis - The normalized rotation axis. + * @param {number} angle - The rotation in radians. + * @return {Matrix4} A reference to this matrix. */ makeRotationAxis(axis: Vector3, angle: number): this; - /** - * Sets this matrix as scale transform. + * Sets this matrix as a scale transformation. + * + * @param {number} x - The amount to scale in the X axis. + * @param {number} y - The amount to scale in the Y axis. + * @param {number} z - The amount to scale in the Z axis. + * @return {Matrix4} A reference to this matrix. */ makeScale(x: number, y: number, z: number): this; - /** - * Sets this matrix as shear transform. + * Sets this matrix as a shear transformation. + * + * @param {number} xy - The amount to shear X by Y. + * @param {number} xz - The amount to shear X by Z. + * @param {number} yx - The amount to shear Y by X. + * @param {number} yz - The amount to shear Y by Z. + * @param {number} zx - The amount to shear Z by X. + * @param {number} zy - The amount to shear Z by Y. + * @return {Matrix4} A reference to this matrix. */ makeShear(xy: number, xz: number, yx: number, yz: number, zx: number, zy: number): this; - /** - * Sets this matrix to the transformation composed of translation, rotation and scale. + * Sets this matrix to the transformation composed of the given position, + * rotation (Quaternion) and scale. + * + * @param {Vector3} position - The position vector. + * @param {Quaternion} quaternion - The rotation as a Quaternion. + * @param {Vector3} scale - The scale vector. + * @return {Matrix4} A reference to this matrix. */ compose(position: Vector3, quaternion: Quaternion, scale: Vector3): this; - /** - * Decomposes this matrix into it's position, quaternion and scale components. + * Decomposes this matrix into its position, rotation and scale components + * and provides the result in the given objects. + * + * Note: Not all matrices are decomposable in this way. For example, if an + * object has a non-uniformly scaled parent, then the object's world matrix + * may not be decomposable, and this method may not be appropriate. + * + * @param {Vector3} position - The position vector. + * @param {Quaternion} quaternion - The rotation as a Quaternion. + * @param {Vector3} scale - The scale vector. + * @return {Matrix4} A reference to this matrix. */ decompose(position: Vector3, quaternion: Quaternion, scale: Vector3): this; - /** - * Creates a perspective projection matrix. + * Creates a perspective projection matrix. This is used internally by + * {@link PerspectiveCamera#updateProjectionMatrix}. + + * @param {number} left - Left boundary of the viewing frustum at the near plane. + * @param {number} right - Right boundary of the viewing frustum at the near plane. + * @param {number} top - Top boundary of the viewing frustum at the near plane. + * @param {number} bottom - Bottom boundary of the viewing frustum at the near plane. + * @param {number} near - The distance from the camera to the near plane. + * @param {number} far - The distance from the camera to the far plane. + * @param {(WebGLCoordinateSystem|WebGPUCoordinateSystem)} [coordinateSystem=WebGLCoordinateSystem] - The coordinate system. + * @param {boolean} [reversedDepth=false] - Whether to use a reversed depth. + * @return {Matrix4} A reference to this matrix. */ makePerspective( left: number, @@ -248,9 +460,19 @@ export class Matrix4 { coordinateSystem?: CoordinateSystem, reversedDepth?: boolean, ): this; - /** - * Creates an orthographic projection matrix. + * Creates a orthographic projection matrix. This is used internally by + * {@link OrthographicCamera#updateProjectionMatrix}. + + * @param {number} left - Left boundary of the viewing frustum at the near plane. + * @param {number} right - Right boundary of the viewing frustum at the near plane. + * @param {number} top - Top boundary of the viewing frustum at the near plane. + * @param {number} bottom - Bottom boundary of the viewing frustum at the near plane. + * @param {number} near - The distance from the camera to the near plane. + * @param {number} far - The distance from the camera to the far plane. + * @param {(WebGLCoordinateSystem|WebGPUCoordinateSystem)} [coordinateSystem=WebGLCoordinateSystem] - The coordinate system. + * @param {boolean} [reversedDepth=false] - Whether to use a reversed depth. + * @return {Matrix4} A reference to this matrix. */ makeOrthographic( left: number, @@ -262,26 +484,28 @@ export class Matrix4 { coordinateSystem?: CoordinateSystem, reversedDepth?: boolean, ): this; - - equals(matrix: Matrix4): boolean; - /** - * Sets the values of this matrix from the provided array or array-like. - * @param array the source array or array-like. - * @param offset (optional) offset into the array-like. Default is 0. + * Returns `true` if this matrix is equal with the given one. + * + * @param {Matrix4} matrix - The matrix to test for equality. + * @return {boolean} Whether this matrix is equal with the given one. */ - fromArray(array: ArrayLike, offset?: number): this; - + equals(matrix: Matrix4): boolean; /** - * Writes the elements of this matrix to an array in - * {@link https://en.wikipedia.org/wiki/Row-_and_column-major_order#Column-major_order column-major} format. + * Sets the elements of the matrix from the given array. + * + * @param {Array} array - The matrix elements in column-major order. + * @param {number} [offset=0] - Index of the first element in the array. + * @return {Matrix4} A reference to this matrix. */ - toArray(): Matrix4Tuple; + fromArray(array: ArrayLike, offset?: number): this; /** - * Writes the elements of this matrix to an array in - * {@link https://en.wikipedia.org/wiki/Row-_and_column-major_order#Column-major_order column-major} format. - * @param array array to store the resulting vector in. - * @param offset (optional) offset in the array at which to put the result. + * Writes the elements of this matrix to the given array. If no array is provided, + * the method returns a new instance. + * + * @param {Array} [array=[]] - The target array holding the matrix elements in column-major order. + * @param {number} [offset=0] - Index of the first element in the array. + * @return {Array} The matrix elements in column-major order. */ - toArray>(array: TArray, offset?: number): TArray; + toArray = Matrix4Tuple>(array?: TArray, offset?: number): TArray; } diff --git a/types/three/src/math/Vector3.d.ts b/types/three/src/math/Vector3.d.ts index 43dc5629b55127..224a925887e7ca 100644 --- a/types/three/src/math/Vector3.d.ts +++ b/types/three/src/math/Vector3.d.ts @@ -50,7 +50,7 @@ export class Vector3 { /** * Sets value of this vector. */ - set(x: number, y: number, z: number): this; + set(x: number, y: number, z?: number): this; /** * Sets all values of this vector. @@ -216,7 +216,7 @@ export class Vector3 { crossVectors(a: Vector3Like, b: Vector3Like): this; projectOnVector(v: Vector3): this; projectOnPlane(planeNormal: Vector3): this; - reflect(vector: Vector3Like): this; + reflect(normal: Vector3Like): this; angleTo(v: Vector3): number; /** diff --git a/types/three/src/math/interpolants/BezierInterpolant.d.ts b/types/three/src/math/interpolants/BezierInterpolant.d.ts index f1d9cac02ff0f5..44d0c82c2776c0 100644 --- a/types/three/src/math/interpolants/BezierInterpolant.d.ts +++ b/types/three/src/math/interpolants/BezierInterpolant.d.ts @@ -1,7 +1,23 @@ +import { TypedArray } from "../../core/BufferAttribute.js"; import { Interpolant } from "../Interpolant.js"; +/** + * A Bezier interpolant using cubic Bezier curves with 2D control points. + * + * This interpolant supports the COLLADA/Maya style of Bezier animation where + * each keyframe has explicit in/out tangent control points specified as + * 2D coordinates (time, value). + * + * Tangent data is read from `inTangents` and `outTangents` on the interpolant + * (populated by `KeyframeTrack.InterpolantFactoryMethodBezier`). + * + * For a track with N keyframes and stride S: + * - Each tangent array has N * S * 2 values + * - Layout: [k0_c0_time, k0_c0_value, k0_c1_time, k0_c1_value, ..., k0_cS_time, k0_cS_value, + * k1_c0_time, k1_c0_value, ...] + * + * @augments Interpolant + */ export class BezierInterpolant extends Interpolant { - constructor(parameterPositions: any, samplesValues: any, sampleSize: number, resultBuffer?: any); - - interpolate_(i1: number, t0: number, t: number, t1: number): any; + interpolate_(i1: number, t0: number, t: number, t1: number): TypedArray; } diff --git a/types/three/src/math/interpolants/CubicInterpolant.d.ts b/types/three/src/math/interpolants/CubicInterpolant.d.ts index 282b98d7ef6ae3..d63a0b40cd84e6 100644 --- a/types/three/src/math/interpolants/CubicInterpolant.d.ts +++ b/types/three/src/math/interpolants/CubicInterpolant.d.ts @@ -1,7 +1,22 @@ +import { InterpolationEndingModes } from "../../constants.js"; +import { TypedArray } from "../../core/BufferAttribute.js"; import { Interpolant } from "../Interpolant.js"; -export class CubicInterpolant extends Interpolant { - constructor(parameterPositions: any, samplesValues: any, sampleSize: number, resultBuffer?: any); +export interface CubicInterpolantSettings { + endingStart: InterpolationEndingModes; + endingEnd: InterpolationEndingModes; +} - interpolate_(i1: number, t0: number, t: number, t1: number): any; +/** + * Fast and simple cubic spline interpolant. + * + * It was derived from a Hermitian construction setting the first derivative + * at each sample position to the linear slope between neighboring positions + * over their parameter interval. + * + * @augments Interpolant + */ +export class CubicInterpolant extends Interpolant { + intervalChanged_(i1: number, t0: number, t1: number): void; + interpolate_(i1: number, t0: number, t: number, t1: number): TypedArray; } diff --git a/types/three/src/math/interpolants/DiscreteInterpolant.d.ts b/types/three/src/math/interpolants/DiscreteInterpolant.d.ts index 28bd458b89c23f..d4578f77826917 100644 --- a/types/three/src/math/interpolants/DiscreteInterpolant.d.ts +++ b/types/three/src/math/interpolants/DiscreteInterpolant.d.ts @@ -1,7 +1,12 @@ +import { TypedArray } from "../../core/BufferAttribute.js"; import { Interpolant } from "../Interpolant.js"; +/** + * Interpolant that evaluates to the sample value at the position preceding + * the parameter. + * + * @augments Interpolant + */ export class DiscreteInterpolant extends Interpolant { - constructor(parameterPositions: any, samplesValues: any, sampleSize: number, resultBuffer?: any); - - interpolate_(i1: number, t0: number, t: number, t1: number): any; + interpolate_(i1: number): TypedArray; } diff --git a/types/three/src/math/interpolants/LinearInterpolant.d.ts b/types/three/src/math/interpolants/LinearInterpolant.d.ts index e6ff11c0b2d98b..1a486f84ef04ce 100644 --- a/types/three/src/math/interpolants/LinearInterpolant.d.ts +++ b/types/three/src/math/interpolants/LinearInterpolant.d.ts @@ -1,7 +1,11 @@ +import { TypedArray } from "../../core/BufferAttribute.js"; import { Interpolant } from "../Interpolant.js"; +/** + * A basic linear interpolant. + * + * @augments Interpolant + */ export class LinearInterpolant extends Interpolant { - constructor(parameterPositions: any, samplesValues: any, sampleSize: number, resultBuffer?: any); - - interpolate_(i1: number, t0: number, t: number, t1: number): any; + interpolate_(i1: number, t0: number, t: number, t1: number): TypedArray; } diff --git a/types/three/src/math/interpolants/QuaternionLinearInterpolant.d.ts b/types/three/src/math/interpolants/QuaternionLinearInterpolant.d.ts index dccb6697617448..73a3211b06d8ff 100644 --- a/types/three/src/math/interpolants/QuaternionLinearInterpolant.d.ts +++ b/types/three/src/math/interpolants/QuaternionLinearInterpolant.d.ts @@ -1,7 +1,11 @@ +import { TypedArray } from "../../core/BufferAttribute.js"; import { Interpolant } from "../Interpolant.js"; +/** + * Spherical linear unit quaternion interpolant. + * + * @augments Interpolant + */ export class QuaternionLinearInterpolant extends Interpolant { - constructor(parameterPositions: any, samplesValues: any, sampleSize: number, resultBuffer?: any); - - interpolate_(i1: number, t0: number, t: number, t1: number): any; + interpolate_(i1: number, t0: number, t: number, t1: number): TypedArray; } diff --git a/types/three/src/nodes/Nodes.d.ts b/types/three/src/nodes/Nodes.d.ts index a03534360e492d..0bb64c0da0253b 100644 --- a/types/three/src/nodes/Nodes.d.ts +++ b/types/three/src/nodes/Nodes.d.ts @@ -21,13 +21,7 @@ export { export { default as MRTNode } from "./core/MRTNode.js"; export { default as Node, NodeJSONInputData, NodeJSONIntermediateOutputData } from "./core/Node.js"; export { default as NodeAttribute } from "./core/NodeAttribute.js"; -export { - BuildStageOption, - default as NodeBuilder, - FlowData, - NodeBuilderContext, - NodeData, -} from "./core/NodeBuilder.js"; +export { default as NodeBuilder } from "./core/NodeBuilder.js"; export { default as NodeCache } from "./core/NodeCache.js"; export { default as NodeCode } from "./core/NodeCode.js"; export { default as NodeError } from "./core/NodeError.js"; @@ -37,6 +31,7 @@ export { default as NodeUniform } from "./core/NodeUniform.js"; export { default as NodeVar } from "./core/NodeVar.js"; export { default as NodeVarying } from "./core/NodeVarying.js"; export { default as OutputStructNode } from "./core/OutputStructNode.js"; +export { default as OverrideContextNode } from "./core/OverrideContextNode.js"; export { default as ParameterNode } from "./core/ParameterNode.js"; export { default as PropertyNode } from "./core/PropertyNode.js"; export { default as StackNode } from "./core/StackNode.js"; @@ -54,25 +49,21 @@ import * as NodeUtils from "./core/NodeUtils.js"; export { NodeUtils }; // accessors -export { default as BatchNode } from "./accessors/BatchNode.js"; export { default as BufferAttributeNode } from "./accessors/BufferAttributeNode.js"; export { default as BufferNode } from "./accessors/BufferNode.js"; export { default as BuiltinNode } from "./accessors/BuiltinNode.js"; export { default as ClippingNode } from "./accessors/ClippingNode.js"; export { default as CubeTextureNode } from "./accessors/CubeTextureNode.js"; -export { default as InstancedMeshNode } from "./accessors/InstancedMeshNode.js"; -export { default as InstanceNode } from "./accessors/InstanceNode.js"; export { default as MaterialNode, MaterialNodeScope } from "./accessors/MaterialNode.js"; export { default as MaterialReferenceNode } from "./accessors/MaterialReferenceNode.js"; export { default as ModelNode } from "./accessors/ModelNode.js"; -export { default as MorphNode } from "./accessors/MorphNode.js"; export { default as Object3DNode } from "./accessors/Object3DNode.js"; export { default as PointUVNode } from "./accessors/PointUVNode.js"; export { default as ReferenceBaseNode } from "./accessors/ReferenceBaseNode.js"; export { default as ReferenceNode } from "./accessors/ReferenceNode.js"; export { default as RendererReferenceNode } from "./accessors/RendererReferenceNode.js"; -export { default as SkinningNode } from "./accessors/SkinningNode.js"; export { default as StorageBufferNode } from "./accessors/StorageBufferNode.js"; +export { default as StorageTexture3DNode } from "./accessors/StorageTexture3DNode.js"; export { default as StorageTextureNode } from "./accessors/StorageTextureNode.js"; export { default as Texture3DNode } from "./accessors/Texture3DNode.js"; export { default as TextureNode } from "./accessors/TextureNode.js"; @@ -166,7 +157,7 @@ export { default as MaxMipLevelNode } from "./utils/MaxMipLevelNode.js"; export { default as MemberNode } from "./utils/MemberNode.js"; export { default as ReflectorNode, ReflectorNodeParameters } from "./utils/ReflectorNode.js"; export { default as RotateNode } from "./utils/RotateNode.js"; -export { default as RTTNode, RTTNodeOptions } from "./utils/RTTNode.js"; +export { default as RTTNode } from "./utils/RTTNode.js"; export { default as SampleNode } from "./utils/SampleNode.js"; export { default as SetNode } from "./utils/SetNode.js"; export { default as SplitNode } from "./utils/SplitNode.js"; diff --git a/types/three/src/nodes/TSL.d.ts b/types/three/src/nodes/TSL.d.ts index e14e0ea22ae487..f96ea47f821e48 100644 --- a/types/three/src/nodes/TSL.d.ts +++ b/types/three/src/nodes/TSL.d.ts @@ -10,6 +10,7 @@ export * from "./core/IndexNode.js"; export * from "./core/IsolateNode.js"; export * from "./core/MRTNode.js"; export * from "./core/OutputStructNode.js"; +export * from "./core/OverrideContextNode.js"; export * from "./core/ParameterNode.js"; export * from "./core/PropertyNode.js"; export * from "./core/StackNode.js"; @@ -55,21 +56,20 @@ export * from "./tsl/TSLBase.js"; // accessors export * from "./accessors/AccessorsUtils.js"; export * from "./accessors/Arrays.js"; -export * from "./accessors/BatchNode.js"; +export * from "./accessors/Batch.js"; export * from "./accessors/Bitangent.js"; export * from "./accessors/BufferAttributeNode.js"; export * from "./accessors/BufferNode.js"; export * from "./accessors/BuiltinNode.js"; export * from "./accessors/Camera.js"; export * from "./accessors/CubeTextureNode.js"; -export * from "./accessors/InstancedMeshNode.js"; -export * from "./accessors/InstanceNode.js"; +export * from "./accessors/Instance.js"; export * from "./accessors/MaterialNode.js"; export * from "./accessors/MaterialProperties.js"; export * from "./accessors/MaterialReferenceNode.js"; export * from "./accessors/ModelNode.js"; export * from "./accessors/ModelViewProjectionNode.js"; -export * from "./accessors/MorphNode.js"; +export * from "./accessors/Morph.js"; export * from "./accessors/Normal.js"; export * from "./accessors/Object3DNode.js"; export * from "./accessors/PointUVNode.js"; @@ -78,8 +78,9 @@ export * from "./accessors/ReferenceNode.js"; export * from "./accessors/ReflectVector.js"; export * from "./accessors/RendererReferenceNode.js"; export * from "./accessors/SceneProperties.js"; -export * from "./accessors/SkinningNode.js"; +export * from "./accessors/Skinning.js"; export * from "./accessors/StorageBufferNode.js"; +export * from "./accessors/StorageTexture3DNode.js"; export * from "./accessors/StorageTextureNode.js"; export * from "./accessors/Tangent.js"; export * from "./accessors/Texture3DNode.js"; @@ -99,6 +100,7 @@ export * from "./display/ColorAdjustment.js"; export * from "./display/ColorSpaceNode.js"; export * from "./display/FrontFacingNode.js"; export * from "./display/NormalMapNode.js"; +export * from "./display/PremultiplyAlphaFunctions.js"; export * from "./display/RenderOutputNode.js"; export * from "./display/ScreenNode.js"; export * from "./display/ToneMappingNode.js"; diff --git a/types/three/src/nodes/accessors/Batch.d.ts b/types/three/src/nodes/accessors/Batch.d.ts new file mode 100644 index 00000000000000..c40e0be334ebfb --- /dev/null +++ b/types/three/src/nodes/accessors/Batch.d.ts @@ -0,0 +1,19 @@ +import { BatchedMesh } from "../../objects/BatchedMesh.js"; +import VaryingNode from "../core/VaryingNode.js"; + +/** + * TSL object representing a varying property for the batching color vector. + * + * @type {VaryingNode} + */ +export const batchColor: VaryingNode<"vec4">; +/** + * TSL function representing the vertex shader batching setup. + * Applies the batch transformation matrix to positionLocal, normalLocal, and tangentLocal. + * Also assigns the batch color if a color texture is present. + * + * @tsl + * @function + * @param {BatchedMesh} batchMesh - The batched mesh. + */ +export const batch: (batchMesh: BatchedMesh) => void; diff --git a/types/three/src/nodes/accessors/BatchNode.d.ts b/types/three/src/nodes/accessors/BatchNode.d.ts deleted file mode 100644 index ef0812031fa5aa..00000000000000 --- a/types/three/src/nodes/accessors/BatchNode.d.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { BatchedMesh } from "../../objects/BatchedMesh.js"; -import Node from "../core/Node.js"; - -export default class BatchNode extends Node { - batchMesh: BatchedMesh; - - batchingIdNode: Node | null; - - constructor(batchMesh: BatchedMesh); -} - -export const batch: (batchMesh: BatchedMesh) => BatchNode; diff --git a/types/three/src/nodes/accessors/Instance.d.ts b/types/three/src/nodes/accessors/Instance.d.ts new file mode 100644 index 00000000000000..01b282ac14ef9a --- /dev/null +++ b/types/three/src/nodes/accessors/Instance.d.ts @@ -0,0 +1,34 @@ +import { InstancedBufferAttribute } from "../../core/InstancedBufferAttribute.js"; +import { InstancedMesh } from "../../objects/InstancedMesh.js"; +import StorageInstancedBufferAttribute from "../../renderers/common/StorageInstancedBufferAttribute.js"; +import VaryingNode from "../core/VaryingNode.js"; + +/** + * TSL object representing a varying property for the instanced color vector. + * + * @type {VaryingNode} + */ +export const instanceColor: VaryingNode<"vec3">; +/** + * TSL function representing the standard instancing vertex shader setup. + * Transforms positionLocal and normalLocal, and assigns varying color in-place. + * + * @tsl + * @function + * @param {number} count - The instance count. + * @param {InstancedBufferAttribute|StorageInstancedBufferAttribute} matrices - The instanced transformation matrices. + * @param {?InstancedBufferAttribute|StorageInstancedBufferAttribute} [colors=null] - The optional instanced colors. + */ +export const instance: ( + count: number, + matrices: InstancedBufferAttribute | StorageInstancedBufferAttribute, + colors?: InstancedBufferAttribute | StorageInstancedBufferAttribute | null, +) => void; +/** + * TSL wrapper for applying instanced mesh rendering setup. + * + * @tsl + * @function + * @param {InstancedMesh} instancedMesh - The instanced mesh. + */ +export const instancedMesh: (instancedMesh: InstancedMesh) => void; diff --git a/types/three/src/nodes/accessors/InstanceNode.d.ts b/types/three/src/nodes/accessors/InstanceNode.d.ts deleted file mode 100644 index 450e8dda226562..00000000000000 --- a/types/three/src/nodes/accessors/InstanceNode.d.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { InstancedBufferAttribute } from "../../core/InstancedBufferAttribute.js"; -import { InstancedInterleavedBuffer } from "../../core/InstancedInterleavedBuffer.js"; -import StorageInstancedBufferAttribute from "../../renderers/common/StorageInstancedBufferAttribute.js"; -import Node from "../core/Node.js"; - -export default class InstanceNode extends Node { - count: number; - instanceMatrix: InstancedBufferAttribute | StorageInstancedBufferAttribute; - instanceColor: InstancedBufferAttribute | StorageInstancedBufferAttribute | null; - - instanceMatrixNode: Node | null; - instanceColorNode: Node | null; - - buffer: InstancedInterleavedBuffer | null; - bufferColor: InstancedBufferAttribute | null; - - previousInstancedMatrixNode: Node | null; - - constructor( - count: number, - instanceMatrix: InstancedBufferAttribute | StorageInstancedBufferAttribute, - instanceColor?: InstancedBufferAttribute | StorageInstancedBufferAttribute | null, - ); -} - -export const instance: ( - count: number, - instanceMatrix: InstancedBufferAttribute | StorageInstancedBufferAttribute, - instanceColor?: InstancedBufferAttribute | StorageInstancedBufferAttribute | null, -) => InstanceNode; diff --git a/types/three/src/nodes/accessors/InstancedMeshNode.d.ts b/types/three/src/nodes/accessors/InstancedMeshNode.d.ts deleted file mode 100644 index b6ce8ffcc346b4..00000000000000 --- a/types/three/src/nodes/accessors/InstancedMeshNode.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { InstancedMesh } from "../../objects/InstancedMesh.js"; -import InstanceNode from "./InstanceNode.js"; - -declare class InstancedMeshNode extends InstanceNode { - constructor(instanceMesh: InstancedMesh); -} - -export default InstancedMeshNode; - -export const instancedMesh: (instancedMesh: InstancedMesh) => InstancedMeshNode; diff --git a/types/three/src/nodes/accessors/MaterialNode.d.ts b/types/three/src/nodes/accessors/MaterialNode.d.ts index d008ae55ebb6a8..433586ec27f2d3 100644 --- a/types/three/src/nodes/accessors/MaterialNode.d.ts +++ b/types/three/src/nodes/accessors/MaterialNode.d.ts @@ -40,87 +40,94 @@ export type MaterialNodeScope = | typeof MaterialNode.AO | typeof MaterialNode.REFRACTION_RATIO; -export default class MaterialNode extends Node { - static ALPHA_TEST: "alphaTest"; - static COLOR: "color"; - static OPACITY: "opacity"; - static SHININESS: "shininess"; - static SPECULAR: "specular"; - static SPECULAR_STRENGTH: "specularStrength"; - static SPECULAR_INTENSITY: "specularIntensity"; - static SPECULAR_COLOR: "specularColor"; - static REFLECTIVITY: "reflectivity"; - static ROUGHNESS: "roughness"; - static METALNESS: "metalness"; - static NORMAL: "normal"; - static CLEARCOAT: "clearcoat"; - static CLEARCOAT_ROUGHNESS: "clearcoatRoughness"; - static CLEARCOAT_NORMAL: "clearcoatNormal"; - static EMISSIVE: "emissive"; - static ROTATION: "rotation"; - static SHEEN: "sheen"; - static SHEEN_ROUGHNESS: "sheenRoughness"; - static ANISOTROPY: "anisotropy"; - static IRIDESCENCE: "iridescence"; - static IRIDESCENCE_IOR: "iridescenceIOR"; - static IRIDESCENCE_THICKNESS: "iridescenceThickness"; - static IOR: "ior"; - static TRANSMISSION: "transmission"; - static THICKNESS: "thickness"; - static ATTENUATION_DISTANCE: "attenuationDistance"; - static ATTENUATION_COLOR: "attenuationColor"; - static LINE_SCALE: "scale"; - static LINE_DASH_SIZE: "dashSize"; - static LINE_GAP_SIZE: "gapSize"; - static LINE_WIDTH: "linewidth"; - static LINE_DASH_OFFSET: "dashOffset"; - static POINT_SIZE: "size"; - static DISPERSION: "dispersion"; - static LIGHT_MAP: "light"; - static AO: "ao"; - static REFRACTION_RATIO: "refractionRatio"; - +interface MaterialNodeInterface { scope: MaterialNodeScope; - constructor(scope?: MaterialNodeScope); } -export const materialAlphaTest: MaterialNode; -export const materialColor: MaterialNode; -export const materialShininess: MaterialNode; -export const materialEmissive: MaterialNode; -export const materialOpacity: MaterialNode; -export const materialSpecular: MaterialNode; +declare const MaterialNode: { + new(scope: MaterialNodeScope): MaterialNode; + + ALPHA_TEST: "alphaTest"; + COLOR: "color"; + OPACITY: "opacity"; + SHININESS: "shininess"; + SPECULAR: "specular"; + SPECULAR_STRENGTH: "specularStrength"; + SPECULAR_INTENSITY: "specularIntensity"; + SPECULAR_COLOR: "specularColor"; + REFLECTIVITY: "reflectivity"; + ROUGHNESS: "roughness"; + METALNESS: "metalness"; + NORMAL: "normal"; + CLEARCOAT: "clearcoat"; + CLEARCOAT_ROUGHNESS: "clearcoatRoughness"; + CLEARCOAT_NORMAL: "clearcoatNormal"; + EMISSIVE: "emissive"; + ROTATION: "rotation"; + SHEEN: "sheen"; + SHEEN_ROUGHNESS: "sheenRoughness"; + ANISOTROPY: "anisotropy"; + IRIDESCENCE: "iridescence"; + IRIDESCENCE_IOR: "iridescenceIOR"; + IRIDESCENCE_THICKNESS: "iridescenceThickness"; + IOR: "ior"; + TRANSMISSION: "transmission"; + THICKNESS: "thickness"; + ATTENUATION_DISTANCE: "attenuationDistance"; + ATTENUATION_COLOR: "attenuationColor"; + LINE_SCALE: "scale"; + LINE_DASH_SIZE: "dashSize"; + LINE_GAP_SIZE: "gapSize"; + LINE_WIDTH: "linewidth"; + LINE_DASH_OFFSET: "dashOffset"; + POINT_SIZE: "size"; + DISPERSION: "dispersion"; + LIGHT_MAP: "light"; + AO: "ao"; + REFRACTION_RATIO: "refractionRatio"; +}; + +type MaterialNode = MaterialNodeInterface & Node; + +export default MaterialNode; + +export const materialAlphaTest: MaterialNode<"float">; +export const materialColor: MaterialNode<"vec3">; +export const materialShininess: MaterialNode<"float">; +export const materialEmissive: MaterialNode<"vec3">; +export const materialOpacity: MaterialNode<"float">; +export const materialSpecular: MaterialNode<"vec3">; -export const materialSpecularIntensity: MaterialNode; -export const materialSpecularColor: MaterialNode; +export const materialSpecularIntensity: MaterialNode<"float">; +export const materialSpecularColor: MaterialNode<"vec3">; -export const materialSpecularStrength: MaterialNode; -export const materialReflectivity: MaterialNode; -export const materialRoughness: MaterialNode; -export const materialMetalness: MaterialNode; -export const materialNormal: Node; -export const materialClearcoat: MaterialNode; -export const materialClearcoatRoughness: MaterialNode; -export const materialClearcoatNormal: Node; -export const materialRotation: MaterialNode; -export const materialSheen: MaterialNode; -export const materialSheenRoughness: MaterialNode; -export const materialAnisotropy: MaterialNode; -export const materialIridescence: MaterialNode; -export const materialIridescenceIOR: MaterialNode; -export const materialIridescenceThickness: MaterialNode; -export const materialTransmission: MaterialNode; -export const materialThickness: MaterialNode; -export const materialIOR: MaterialNode; -export const materialAttenuationDistance: MaterialNode; -export const materialAttenuationColor: MaterialNode; -export const materialLineScale: MaterialNode; -export const materialLineDashSize: MaterialNode; -export const materialLineGapSize: MaterialNode; -export const materialLineWidth: MaterialNode; -export const materialLineDashOffset: MaterialNode; -export const materialPointSize: MaterialNode; -export const materialDispersion: MaterialNode; -export const materialLightMap: MaterialNode; -export const materialAO: MaterialNode; -export const materialAnisotropyVector: MaterialNode; +export const materialSpecularStrength: MaterialNode<"float">; +export const materialReflectivity: MaterialNode<"float">; +export const materialRoughness: MaterialNode<"float">; +export const materialMetalness: MaterialNode<"float">; +export const materialNormal: MaterialNode<"vec3">; +export const materialClearcoat: MaterialNode<"float">; +export const materialClearcoatRoughness: MaterialNode<"float">; +export const materialClearcoatNormal: MaterialNode<"vec3">; +export const materialRotation: MaterialNode<"float">; +export const materialSheen: MaterialNode<"vec3">; +export const materialSheenRoughness: MaterialNode<"float">; +export const materialAnisotropy: MaterialNode<"vec2">; +export const materialIridescence: MaterialNode<"float">; +export const materialIridescenceIOR: MaterialNode<"float">; +export const materialIridescenceThickness: MaterialNode<"float">; +export const materialTransmission: MaterialNode<"float">; +export const materialThickness: MaterialNode<"float">; +export const materialIOR: MaterialNode<"float">; +export const materialAttenuationDistance: MaterialNode<"float">; +export const materialAttenuationColor: MaterialNode<"vec3">; +export const materialLineScale: MaterialNode<"float">; +export const materialLineDashSize: MaterialNode<"float">; +export const materialLineGapSize: MaterialNode<"float">; +export const materialLineWidth: MaterialNode<"float">; +export const materialLineDashOffset: MaterialNode<"float">; +export const materialPointSize: MaterialNode<"float">; +export const materialDispersion: MaterialNode<"float">; +export const materialLightMap: MaterialNode<"vec3">; +export const materialAO: MaterialNode<"float">; +export const materialAnisotropyVector: Node<"vec2">; diff --git a/types/three/src/nodes/accessors/Morph.d.ts b/types/three/src/nodes/accessors/Morph.d.ts new file mode 100644 index 00000000000000..d42ee3bb86f383 --- /dev/null +++ b/types/three/src/nodes/accessors/Morph.d.ts @@ -0,0 +1,11 @@ +import { Mesh } from "../../objects/Mesh.js"; + +/** + * TSL function representing the vertex shader morph targets blend setup. + * Dynamically computes morph targets weights and updates positionLocal and normalLocal in-place. + * + * @tsl + * @function + * @param {Mesh} mesh - The mesh. + */ +export const morphReference: (mesh: Mesh) => void; diff --git a/types/three/src/nodes/accessors/MorphNode.d.ts b/types/three/src/nodes/accessors/MorphNode.d.ts deleted file mode 100644 index 7fcf9729da13e6..00000000000000 --- a/types/three/src/nodes/accessors/MorphNode.d.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { Mesh } from "../../objects/Mesh.js"; -import Node from "../core/Node.js"; -import UniformNode from "../core/UniformNode.js"; - -declare class MorphNode extends Node { - mesh: Mesh; - morphBaseInfluence: UniformNode<"float", number>; - - constructor(mesh: Mesh); -} - -export default MorphNode; - -export const morphReference: (mesh: Mesh) => MorphNode; diff --git a/types/three/src/nodes/accessors/Skinning.d.ts b/types/three/src/nodes/accessors/Skinning.d.ts new file mode 100644 index 00000000000000..2cce66e17ea9b6 --- /dev/null +++ b/types/three/src/nodes/accessors/Skinning.d.ts @@ -0,0 +1,23 @@ +import { Vector3 } from "../../math/Vector3.js"; +import { SkinnedMesh } from "../../objects/SkinnedMesh.js"; +import Node from "../core/Node.js"; + +/** + * TSL function representing the standard skeletal animation vertex shader setup. + * Transforms positionLocal, normalLocal, and tangentLocal in-place. + * + * @tsl + * @function + * @param {SkinnedMesh} skinnedMesh - The skinned mesh. + */ +export const skinning: (skinnedMesh: SkinnedMesh) => void; +/** + * TSL function that computes skeletal animation for custom compute passes. + * + * @tsl + * @function + * @param {SkinnedMesh} skinnedMesh - The skinned mesh. + * @param {Node} [toPosition=null] - The target position node to assign. + * @returns {Node} The computed skinned position node. + */ +export const computeSkinning: (skinnedMesh: SkinnedMesh, toPosition?: Node<"vec3"> | Vector3 | null) => void; diff --git a/types/three/src/nodes/accessors/SkinningNode.d.ts b/types/three/src/nodes/accessors/SkinningNode.d.ts deleted file mode 100644 index 57a22e986261e6..00000000000000 --- a/types/three/src/nodes/accessors/SkinningNode.d.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { SkinnedMesh } from "../../objects/SkinnedMesh.js"; -import Node from "../core/Node.js"; -import NodeBuilder from "../core/NodeBuilder.js"; - -export default class SkinningNode extends Node { - skinnedMesh: SkinnedMesh; - - skinIndexNode: Node; - skinWeightNode: Node; - - bindMatrixNode: Node; - bindMatrixInverseNode: Node; - boneMatricesNode: Node; - positionNode: Node; - toPositionNode: Node; - previousBoneMatricesNode: Node | null; - - constructor(skinnedMesh: SkinnedMesh); - - getSkinnedPosition(boneMatrices?: Node, position?: Node): Node; - - getSkinnedNormalAndTangent( - boneMatrices?: Node, - normal?: Node, - tangent?: Node, - ): { skinNormal: Node; skinTangent: Node }; - - getPreviousSkinnedPosition(builder: NodeBuilder): Node; -} - -export const skinning: (skinnedMesh: SkinnedMesh) => SkinningNode; -export const computeSkinning: (skinnedMesh: SkinnedMesh, toPosition?: Node | null) => SkinningNode; diff --git a/types/three/src/nodes/accessors/StorageBufferNode.d.ts b/types/three/src/nodes/accessors/StorageBufferNode.d.ts index f819d249b09ad5..4715bdb6e152bb 100644 --- a/types/three/src/nodes/accessors/StorageBufferNode.d.ts +++ b/types/three/src/nodes/accessors/StorageBufferNode.d.ts @@ -47,32 +47,29 @@ type StorageBufferNode = export default StorageBufferNode; +type StorageNodeType = + | "float" + | "uint" + | "int" + | "vec2" + | "uvec2" + | "ivec2" + | "vec3" + | "uvec3" + | "ivec3" + | "vec4" + | "uvec4" + | "ivec4" + | "mat2" + | "mat3" + | "mat4"; + interface Storage { - ( - value: StorageBufferAttribute | StorageInstancedBufferAttribute | BufferAttribute, - type: "float", - count: number, - ): StorageBufferNode<"float">; - ( - value: StorageBufferAttribute | StorageInstancedBufferAttribute | BufferAttribute, - type: "uint", - count: number, - ): StorageBufferNode<"uint">; - ( + ( value: StorageBufferAttribute | StorageInstancedBufferAttribute | BufferAttribute, - type: "vec2", + type: TNodeType, count: number, - ): StorageBufferNode<"vec2">; - ( - value: StorageBufferAttribute | StorageInstancedBufferAttribute | BufferAttribute, - type: "vec3", - count: number, - ): StorageBufferNode<"vec3">; - ( - value: StorageBufferAttribute | StorageInstancedBufferAttribute | BufferAttribute, - type: "vec4", - count: number, - ): StorageBufferNode<"vec4">; + ): StorageBufferNode; ( value: StorageBufferAttribute | StorageInstancedBufferAttribute | BufferAttribute, type: Struct, @@ -81,3 +78,5 @@ interface Storage { } export const storage: Storage; + +export {}; diff --git a/types/three/src/nodes/accessors/StorageTexture3DNode.d.ts b/types/three/src/nodes/accessors/StorageTexture3DNode.d.ts new file mode 100644 index 00000000000000..b6a32b14848b5c --- /dev/null +++ b/types/three/src/nodes/accessors/StorageTexture3DNode.d.ts @@ -0,0 +1,17 @@ +import Storage3DTexture from "../../renderers/common/Storage3DTexture.js"; +import Node from "../core/Node.js"; +import StorageTextureNode from "./StorageTextureNode.js"; + +declare class StorageTexture3DNode extends StorageTextureNode { + readonly isStorageTexture3DNode: boolean; + + constructor(value: Storage3DTexture, uvNode?: Node<"vec3"> | null, storeNode?: Node | null); +} + +export default StorageTexture3DNode; + +export const storageTexture3D: ( + value: Storage3DTexture, + uvNode?: Node<"vec3"> | null, + storeNode?: Node | null, +) => StorageTexture3DNode; diff --git a/types/three/src/nodes/accessors/StorageTextureNode.d.ts b/types/three/src/nodes/accessors/StorageTextureNode.d.ts index 98c1ad33116f7b..3fa1efe3f6ed58 100644 --- a/types/three/src/nodes/accessors/StorageTextureNode.d.ts +++ b/types/three/src/nodes/accessors/StorageTextureNode.d.ts @@ -1,4 +1,4 @@ -import { Texture } from "../../textures/Texture.js"; +import StorageTexture from "../../renderers/common/StorageTexture.js"; import { NodeAccess } from "../core/constants.js"; import Node from "../core/Node.js"; import NodeBuilder from "../core/NodeBuilder.js"; @@ -14,7 +14,7 @@ export default class StorageTextureNode extends TextureNode { access: NodeAccess; constructor( - value: Texture, + value: StorageTexture, uvNode?: Node | null, storeNode?: Node | null, ); @@ -29,17 +29,19 @@ export default class StorageTextureNode extends TextureNode { toWriteOnly(): this; + store(uvNode: Node, storeNode?: Node | null): StorageTextureNode; + generateStore(builder: NodeBuilder): void; } export const storageTexture: ( - value: Texture, + value: StorageTexture, uvNode?: Node | null, storeNode?: Node, ) => StorageTextureNode; export const textureStore: ( - value: Texture | StorageTextureNode, + value: StorageTexture | StorageTextureNode, uvNode?: Node | null, storeNode?: Node, ) => StorageTextureNode; diff --git a/types/three/src/nodes/accessors/TextureNode.d.ts b/types/three/src/nodes/accessors/TextureNode.d.ts index 1fbe8efe828616..e2ed0eb54dc838 100644 --- a/types/three/src/nodes/accessors/TextureNode.d.ts +++ b/types/three/src/nodes/accessors/TextureNode.d.ts @@ -2,7 +2,7 @@ import { Texture } from "../../textures/Texture.js"; import Node from "../core/Node.js"; import UniformNode from "../core/UniformNode.js"; -interface TextureNodeInterface { +interface TextureNodeInterface { readonly isTextureNode: true; uvNode: Node<"vec2"> | Node<"vec3"> | null; @@ -11,6 +11,7 @@ interface TextureNodeInterface { compareNode: Node | null; depthNode: Node | null; gradNode: Node | null; + gatherNode: Node<"int"> | null; sampler: boolean; updateMatrix: boolean; @@ -23,25 +24,29 @@ interface TextureNodeInterface { getSampler(): boolean; - sample(uvNode: Node): Node; + sample(uvNode: Node): this; - load(uvNode: Node): Node; + load(uvNode: Node): this; - blur(amountNode: Node): Node; + blur(amountNode: Node): this; - level(levelNode: Node): Node; + level(levelNode: Node): this; size(levelNode: Node): Node; - bias(biasNode: Node): Node; + bias(biasNode: Node): this; getBase(): TextureNode; - compare(compareNode: Node): Node; + compare(compareNode: Node<"float"> | number): this; - grad(gradeNodeX: Node, gradeNodeY: Node): TextureNode; + grad(gradeNodeX: Node, gradeNodeY: Node): this; - depth(depthNode: Node): TextureNode; + gather(gatherNode?: Node<"int"> | number): this; + + depth(depthNode: Node): this; + + offset(offsetNode: Node<"ivec2">): this; clone(): this; } @@ -55,7 +60,7 @@ declare const TextureNode: { ): TextureNode; }; -type TextureNode = TextureNodeInterface & UniformNode; +type TextureNode = TextureNodeInterface & UniformNode; export default TextureNode; diff --git a/types/three/src/nodes/core/ArrayNode.d.ts b/types/three/src/nodes/core/ArrayNode.d.ts index cad55888430445..1b82d4de1ddd0b 100644 --- a/types/three/src/nodes/core/ArrayNode.d.ts +++ b/types/three/src/nodes/core/ArrayNode.d.ts @@ -1,25 +1,33 @@ import Node from "./Node.js"; import TempNode from "./TempNode.js"; -declare class ArrayNode extends TempNode { +export interface ArrayNodeInterface { count: number; - values: Node[]; + values: Node[] | null; readonly isArrayNode: true; - - constructor(nodeType: string, count: number, values: Node[]); } +declare const ArrayNode: { + new( + nodeType: TNodeType | null, + count: number, + values?: Node[] | null, + ): ArrayNode; +}; + +type ArrayNode = TempNode & ArrayNodeInterface; + export default ArrayNode; interface ArrayFunction { - (values: Node[]): ArrayNode; - (nodeType: string, count: number): ArrayNode; + (values: Node[]): ArrayNode; + (nodeType: TNodeType, count: number): ArrayNode; } export const array: ArrayFunction; declare module "./Node.js" { - interface NodeElements { - toArray: (count: number) => ArrayNode; + interface NodeExtensions { + toArray: (count: number) => ArrayNode; } } diff --git a/types/three/src/nodes/core/ContextNode.d.ts b/types/three/src/nodes/core/ContextNode.d.ts index bad9872febaaff..8d209fcafb4c3d 100644 --- a/types/three/src/nodes/core/ContextNode.d.ts +++ b/types/three/src/nodes/core/ContextNode.d.ts @@ -1,16 +1,15 @@ import { Light } from "../../lights/Light.js"; import Node from "./Node.js"; -import { NodeBuilderContext } from "./NodeBuilder.js"; declare class ContextNodeInterface extends Node { readonly isContextNode: true; node: Node | null; - value: NodeBuilderContext; + value: unknown; } declare const ContextNode: { - new(node?: Node | null, value?: NodeBuilderContext): ContextNode; + new(node?: Node | null, value?: unknown): ContextNode; }; type ContextNode = ContextNodeInterface & Node; @@ -18,8 +17,8 @@ type ContextNode = ContextNodeInterface & Node; export default ContextNode; interface ContextFunction { - (value?: NodeBuilderContext): ContextNode; - (node: Node, value?: NodeBuilderContext): ContextNode; + (value?: unknown): ContextNode; + (node: Node, value?: unknown): ContextNode; } export const context: ContextFunction; @@ -39,7 +38,7 @@ export function label(node: Node, label: string): Node { - context: (context?: NodeBuilderContext) => ContextNode; + context: (context?: unknown) => ContextNode; /** * @deprecated "label()" has been deprecated. Use "setName()" instead. diff --git a/types/three/src/nodes/core/LightingModel.d.ts b/types/three/src/nodes/core/LightingModel.d.ts index cb894c04eee863..6fe8f9756a54ab 100644 --- a/types/three/src/nodes/core/LightingModel.d.ts +++ b/types/three/src/nodes/core/LightingModel.d.ts @@ -25,6 +25,8 @@ declare class LightingModel { direct(lightData: LightingModelDirectInput, builder: NodeBuilder): void; directRectArea(lightData: LightingModelDirectRectAreaInput, builder: NodeBuilder): void; indirect(builder: NodeBuilder): void; + indirectDiffuse(builder: NodeBuilder): void; + indirectSpecular(builder: NodeBuilder): void; ambientOcclusion(builder: NodeBuilder): void; } diff --git a/types/three/src/nodes/core/Node.d.ts b/types/three/src/nodes/core/Node.d.ts index 20d5046366db35..162515f6d8467c 100644 --- a/types/three/src/nodes/core/Node.d.ts +++ b/types/three/src/nodes/core/Node.d.ts @@ -154,30 +154,6 @@ declare class NodeClass * @default true */ readonly isNode: boolean; - /** - * The cache key of this node. - * - * @private - * @type {?number} - * @default null - */ - private _cacheKey; - /** - * The UUID of the node. - * - * @type {string} - * @default null - * @private - */ - private _uuid; - /** - * The cache key's version. - * - * @private - * @type {number} - * @default 0 - */ - private _cacheKeyVersion; /** * The unique ID of the node. * @@ -238,7 +214,7 @@ declare class NodeClass * @param {Function} callback - The update method. * @return {Node} A reference to this node. */ - onFrameUpdate(callback: (this: this, frame: NodeFrame) => void): this; + onFrameUpdate(callback: (this: this, frame: NodeFrame) => unknown): this; /** * Convenient method for defining {@link Node#update}. Similar to {@link Node#onUpdate}, but * this method automatically sets the update type to `RENDER`. @@ -246,7 +222,7 @@ declare class NodeClass * @param {Function} callback - The update method. * @return {Node} A reference to this node. */ - onRenderUpdate(callback: (this: this, frame: NodeFrame) => void): this; + onRenderUpdate(callback: (this: this, frame: NodeFrame) => unknown): this; /** * Convenient method for defining {@link Node#update}. Similar to {@link Node#onUpdate}, but * this method automatically sets the update type to `OBJECT`. @@ -254,7 +230,7 @@ declare class NodeClass * @param {Function} callback - The update method. * @return {Node} A reference to this node. */ - onObjectUpdate(callback: (this: this, frame: NodeFrame) => void): this; + onObjectUpdate(callback: (this: this, frame: NodeFrame) => unknown): this; /** * Convenient method for defining {@link Node#updateReference}. * @@ -297,14 +273,6 @@ declare class NodeClass * @param {traverseCallback} callback - A callback that is executed per node. */ traverse(callback: (node: Node) => void): void; - /** - * Returns the child nodes of this node. - * - * @private - * @param {Set} [ignores=new Set()] - A set of nodes to ignore during the search to avoid circular references. - * @returns {Array} An array of objects describing the child nodes. - */ - private _getChildren; /** * Returns the cache key for this node. * @@ -389,7 +357,8 @@ declare class NodeClass * This method is used during the build process of a node and ensures * equal nodes are not built multiple times but just once. For example if * `attribute( 'uv' )` is used multiple times by the user, the build - * process makes sure to process just the first node. + * process makes sure to process just the first node. It also handles + * node overrides if an override context is set. * * @param {NodeBuilder} builder - The current node builder. * @return {Node} The shared node if possible. Otherwise `this` is returned. @@ -563,6 +532,18 @@ export interface ColorExtensions { export interface FloatVecExtensions { } +export interface FloatOrVecExtensions { +} + +export interface IntOrVecExtensions { +} + +export interface UintOrVecExtensions { +} + +export interface BoolOrVecExtensions { +} + export interface Mat2Extensions { } @@ -579,36 +560,54 @@ type Node = & NodeClass & NodeElements & (unknown extends TNodeType ? {} : NodeExtensions) - & (TNodeType extends "float" ? NumOrBoolExtensions<"float"> & FloatExtensions & NumExtensions<"float"> - : TNodeType extends "int" - ? NumOrBoolExtensions<"int"> & IntExtensions & NumExtensions<"int"> & IntegerExtensions<"int"> - : TNodeType extends "uint" - ? NumOrBoolExtensions<"uint"> & UintExtensions & NumExtensions<"uint"> & IntegerExtensions<"uint"> - : TNodeType extends "bool" ? NumOrBoolExtensions<"bool"> & BoolExtensions + & (TNodeType extends "float" + ? NumOrBoolExtensions<"float"> & FloatExtensions & NumExtensions<"float"> & FloatOrVecExtensions<"float"> + : TNodeType extends "int" ? + & NumOrBoolExtensions<"int"> + & IntExtensions + & NumExtensions<"int"> + & IntegerExtensions<"int"> + & IntOrVecExtensions<"int"> + : TNodeType extends "uint" ? + & NumOrBoolExtensions<"uint"> + & UintExtensions + & NumExtensions<"uint"> + & IntegerExtensions<"uint"> + & IntOrVecExtensions<"uint"> + : TNodeType extends "bool" ? NumOrBoolExtensions<"bool"> & BoolExtensions & BoolOrVecExtensions<"bool"> : TNodeType extends "vec2" ? & NumOrBoolVec2Extensions<"float"> & Vec2Extensions & NumVec2Extensions<"float"> & FloatVecExtensions<"vec2"> - : TNodeType extends "ivec2" ? NumOrBoolVec2Extensions<"int"> & NumVec2Extensions<"int"> - : TNodeType extends "uvec2" ? NumOrBoolVec2Extensions<"uint"> & NumVec2Extensions<"uint"> - : TNodeType extends "bvec2" ? NumOrBoolVec2Extensions<"bool"> + & FloatOrVecExtensions<"vec2"> + : TNodeType extends "ivec2" + ? NumOrBoolVec2Extensions<"int"> & NumVec2Extensions<"int"> & IntOrVecExtensions<"ivec2"> + : TNodeType extends "uvec2" + ? NumOrBoolVec2Extensions<"uint"> & NumVec2Extensions<"uint"> & IntOrVecExtensions<"uvec2"> + : TNodeType extends "bvec2" ? NumOrBoolVec2Extensions<"bool"> & BoolOrVecExtensions<"bvec2"> : TNodeType extends "vec3" ? & NumOrBoolVec3Extensions<"float"> & Vec3Extensions & NumVec3Extensions<"float"> & FloatVecExtensions<"vec3"> - : TNodeType extends "ivec3" ? NumOrBoolVec3Extensions<"int"> & NumVec3Extensions<"int"> - : TNodeType extends "uvec3" ? NumOrBoolVec3Extensions<"uint"> & NumVec3Extensions<"uint"> - : TNodeType extends "bvec3" ? NumOrBoolVec3Extensions<"bool"> + & FloatOrVecExtensions<"vec3"> + : TNodeType extends "ivec3" + ? NumOrBoolVec3Extensions<"int"> & NumVec3Extensions<"int"> & IntOrVecExtensions<"ivec3"> + : TNodeType extends "uvec3" + ? NumOrBoolVec3Extensions<"uint"> & NumVec3Extensions<"uint"> & IntOrVecExtensions<"uvec3"> + : TNodeType extends "bvec3" ? NumOrBoolVec3Extensions<"bool"> & BoolOrVecExtensions<"bvec3"> : TNodeType extends "vec4" ? & NumOrBoolVec4Extensions<"float"> & Vec4Extensions & NumVec4Extensions<"float"> & FloatVecExtensions<"vec4"> - : TNodeType extends "ivec4" ? NumOrBoolVec4Extensions<"int"> & NumVec4Extensions<"int"> - : TNodeType extends "uvec4" ? NumOrBoolVec4Extensions<"uint"> & NumVec4Extensions<"uint"> - : TNodeType extends "bvec4" ? NumOrBoolVec4Extensions<"bool"> + & FloatOrVecExtensions<"vec4"> + : TNodeType extends "ivec4" + ? NumOrBoolVec4Extensions<"int"> & NumVec4Extensions<"int"> & IntOrVecExtensions<"ivec4"> + : TNodeType extends "uvec4" + ? NumOrBoolVec4Extensions<"uint"> & NumVec4Extensions<"uint"> & IntOrVecExtensions<"uvec4"> + : TNodeType extends "bvec4" ? NumOrBoolVec4Extensions<"bool"> & BoolOrVecExtensions<"bvec4"> : TNodeType extends "color" ? ColorExtensions : TNodeType extends "mat2" ? Mat2Extensions & MatExtensions<"mat2"> : TNodeType extends "mat3" ? Mat3Extensions & MatExtensions<"mat3"> diff --git a/types/three/src/nodes/core/NodeBuilder.d.ts b/types/three/src/nodes/core/NodeBuilder.d.ts index ca5c836a47772d..9046d36ce790da 100644 --- a/types/three/src/nodes/core/NodeBuilder.d.ts +++ b/types/three/src/nodes/core/NodeBuilder.d.ts @@ -2,143 +2,11 @@ import { BufferGeometry } from "../../core/BufferGeometry.js"; import { Object3D } from "../../core/Object3D.js"; import { Material } from "../../materials/Material.js"; import Renderer from "../../renderers/common/Renderer.js"; -import { Texture } from "../../textures/Texture.js"; -import LightsNode from "../lighting/LightsNode.js"; -import { NodeShaderStage } from "./constants.js"; -import Node from "./Node.js"; -import NodeAttribute from "./NodeAttribute.js"; -import NodeCache from "./NodeCache.js"; -import NodeParser from "./NodeParser.js"; -import NodeUniform from "./NodeUniform.js"; -import NodeVar from "./NodeVar.js"; -import NodeVarying from "./NodeVarying.js"; -import StackNode from "./StackNode.js"; - -export type BuildStageOption = "construct" | "analyze" | "generate"; - -export interface FlowData { - code: string; -} - -export interface NodeData { - vertex: { [key: string]: unknown }; - fragment: { [key: string]: unknown }; - compute: { [key: string]: unknown }; -} - -export interface NodeBuilderContext { - [key: string]: unknown; -} export default abstract class NodeBuilder { object: Object3D; material: Material; geometry: BufferGeometry; renderer: Renderer; - parser: NodeParser; - - nodes: Node[]; - updateNodes: Node[]; - hashNodes: { [hash: string]: Node }; - - lightsNode: LightsNode; - fogNode: Node; - - vertexShader: string; - fragmentShader: string; - computeShader: string; - - cache: NodeCache; - globalCache: NodeCache; - - /** - * @TODO used to be missing. check the actual type later - */ - flowsData: any; - - shaderStage: NodeShaderStage | null; - buildStage: BuildStageOption | null; - stack: StackNode; - - setHashNode(node: Node, hash: string): void; - addNode(node: Node): void; - get currentNode(): Node; - isFilteredTexture(texture: Texture): boolean; - getMethod(method: string): string; - getNodeFromHash(hash: string): Node; - - addFlow(shaderStage: NodeShaderStage, node: Node): Node; - - setContext(context: NodeBuilderContext): void; - getContext(): NodeBuilderContext; - setCache(cache: NodeCache): void; - getCache(): NodeCache; - getCacheFromNode(node: Node, parent?: boolean): NodeCache; - isAvailable(name: string): boolean; - - abstract getInstanceIndex(): string; - - abstract getDrawIndex(): string | null; - - abstract getFrontFacing(): string; - - abstract getFragCoord(): string; - - isFlipY(): boolean; - - // @TODO: rename to .generateConst() - getConst(type: string, value?: unknown): Node; - getType(type: string): string; - - generateMethod(method: string): string; - - getAttribute(name: string, type: string): NodeAttribute; - - getPropertyName(node: NodeVar | NodeUniform, shaderStage: NodeShaderStage): string; - isVector(type: string): boolean; - - isMatrix(type: string): boolean; - isReference(type: string): boolean; - getElementType(type: string): string | null; - getComponentType(type: string): string | null; - getVectorType(type: string): string; - getTypeFromLength(length: number): string; - getTypeLength(type: string): number; - getVectorFromMatrix(type: string): string; - getDataFromNode(node: Node, shaderStage?: NodeShaderStage): NodeData; - getNodeProperties(node: Node, shaderStage?: NodeShaderStage): { [key: string]: unknown }; - getUniformFromNode( - node: Node, - type: string, - shaderStage?: NodeShaderStage, - name?: string | null, - ): NodeUniform; - getVarFromNode(node: Node, type: string, shaderStage?: NodeShaderStage): NodeVar; - getVaryFromNode(node: Node, type: string): NodeVarying; - getCodeFromNode(node: Node, type: string, shaderStage?: NodeShaderStage): string; - addFlowCode(code: string): void; - getFlowData(node: Node, shaderStage: NodeShaderStage): FlowData; - flowNode(node: Node): FlowData; - flowChildNode(node: Node, output?: string | null): FlowData; - flowNodeFromShaderStage( - shaderStage: NodeShaderStage, - node: Node, - output?: string | null, - propertyName?: string, - ): FlowData; - hasGeometryAttribute(name: string): boolean; - abstract getAttributes(shaderStage: NodeShaderStage): string; - abstract getVaryings(shaderStage: NodeShaderStage): string; - getVars(shaderStage: NodeShaderStage): string; - abstract getUniforms(stage: NodeShaderStage): string; - getCodes(shaderStage: NodeShaderStage): string; - getHash(): string; - setShaderStage(shaderStage: NodeShaderStage): void; - getShaderStage(): NodeShaderStage; - setBuildStage(buildStage: BuildStageOption): void; - getBuildStage(): BuildStageOption; - abstract buildCode(): void; - build(): this; - format(snippet: string, fromType: string, toType: string): string; - getSignature(): string; + context: unknown; } diff --git a/types/three/src/nodes/core/OverrideContextNode.d.ts b/types/three/src/nodes/core/OverrideContextNode.d.ts new file mode 100644 index 00000000000000..8744ebb44a6aac --- /dev/null +++ b/types/three/src/nodes/core/OverrideContextNode.d.ts @@ -0,0 +1,92 @@ +import ContextNode from "./ContextNode.js"; +import Node from "./Node.js"; +import NodeBuilder from "./NodeBuilder.js"; + +/** + * A specialized context node designed to override specific target nodes within a + * node sub-graph or flow. This allows replacing specific inputs (e.g., normal + * and position vectors) dynamically during compilation for a specific flow node, + * without having to reconstruct or duplicate the source nodes. + * + * ```js + * // Method chaining example: + * node.overrideNode( positionLocal, () => positionLocal.add( vec3( 1, 0, 0 ) ) ); + * + * // Context assignment example: + * material.contextNode = overrideNode( positionLocal, () => positionLocal.add( vec3( 1, 0, 0 ) ) ); + * ``` + * + * @augments ContextNode + */ +declare class OverrideContextNode extends ContextNode { + /** + * Constructs a new override context node. + * + * @param {Map} overrideNodes - A map mapping target nodes to their respective override callback functions. + * @param {Node|null} [flowNode=null] - The node whose context should be modified. + */ + constructor(overrideNodes: Map Node>, flowNode?: Node | null); + /** + * This flag can be used for type testing. + * + * @type {boolean} + * @readonly + * @default true + */ + readonly isOverrideContextNode: boolean; +} + +export default OverrideContextNode; + +/** + * TSL function for creating an `OverrideContextNode` to override a single target node. + * + * ```js + * material.contextNode = overrideNode( positionLocal, ( builder ) => positionLocal.add( vec3( 1, 0, 0 ) ) ); + * ``` + * + * @tsl + * @function + * @param {Node} targetNode - The target node that should be overridden. + * @param {Function|Node|null} [callback=null] - A callback function returning the overriding node (which receives the builder as its argument), or the overriding node itself. + * @param {Node|null} [flowNode=null] - The node whose context should be modified. + * @return {OverrideContextNode} The created override context node. + */ +export function overrideNode( + targetNode: Node, + callback?: ((nodeBuilder: NodeBuilder) => Node) | Node | null, + flowNode?: Node | null, +): OverrideContextNode; + +/** + * TSL function for creating an `OverrideContextNode` to override multiple target nodes. + * + * ```js + * material.contextNode = overrideNodes( [ + * [ positionView, customPositionView ], + * [ positionViewDirection, ( builder ) => customPositionViewDirection ] + * ] ); + * ``` + * + * @tsl + * @function + * @param {Map|Array>} overrides - The overrides mapping target nodes to callback functions or overriding nodes. + * @param {Node|null} [flowNode=null] - The node whose context should be modified. + * @return {OverrideContextNode} The created override context node. + */ +export function overrideNodes( + overrides: + | Map Node) | Node | null> + | Array<[Node, ((nodeBuilder: NodeBuilder) => Node) | Node | null]>, + flowNode?: Node | null, +): OverrideContextNode; + +declare module "./Node.js" { + interface NodeElements { + overrideNodes: ( + overrides: + | Map Node) | Node | null> + | Array<[Node, ((nodeBuilder: NodeBuilder) => Node) | Node | null]>, + ) => OverrideContextNode; + } +} diff --git a/types/three/src/nodes/core/PropertyNode.d.ts b/types/three/src/nodes/core/PropertyNode.d.ts index 2dbdb817c8f7c5..fbe7674a1f1df6 100644 --- a/types/three/src/nodes/core/PropertyNode.d.ts +++ b/types/three/src/nodes/core/PropertyNode.d.ts @@ -3,6 +3,7 @@ import Node from "./Node.js"; interface PropertyNodeInterface { name: string | null; varying: boolean; + placeholderNode: Node; readonly isPropertyNode: true; } @@ -12,6 +13,7 @@ declare const PropertyNode: { nodeType: TNodeType, name?: string | null, varying?: boolean, + placeholderNode?: Node | null, ): PropertyNode; }; @@ -19,8 +21,16 @@ type PropertyNode = Node & PropertyNodeInterface; export default PropertyNode; -export const property: (type: TNodeType, name?: string | null) => PropertyNode; -export const varyingProperty: (type: TNodeType, name?: string | null) => PropertyNode; +export const property: ( + type: TNodeType, + name?: string | null, + placeholderNode?: Node | null, +) => PropertyNode; +export const varyingProperty: ( + type: TNodeType, + name?: string | null, + placeholderNode?: Node | null, +) => PropertyNode; export const diffuseColor: PropertyNode<"vec4">; export const diffuseContribution: PropertyNode<"vec3">; @@ -52,3 +62,4 @@ export const thickness: PropertyNode<"float">; export const attenuationDistance: PropertyNode<"float">; export const attenuationColor: PropertyNode<"color">; export const dispersion: PropertyNode<"float">; +export const ambientOcclusion: PropertyNode<"float">; diff --git a/types/three/src/nodes/core/StructNode.d.ts b/types/three/src/nodes/core/StructNode.d.ts index 83ff8f95cac80f..7173a8167458be 100644 --- a/types/three/src/nodes/core/StructNode.d.ts +++ b/types/three/src/nodes/core/StructNode.d.ts @@ -13,8 +13,6 @@ export interface Struct { (): StructNode; (values: Node[]): StructNode; (...values: Node[]): StructNode; - layout: StructTypeNode; - isStruct: true; } export const struct: (membersLayout: MembersLayout, name?: string | null) => Struct; diff --git a/types/three/src/nodes/core/StructTypeNode.d.ts b/types/three/src/nodes/core/StructTypeNode.d.ts index ba42ffabbf7bb5..fe539643b010a2 100644 --- a/types/three/src/nodes/core/StructTypeNode.d.ts +++ b/types/three/src/nodes/core/StructTypeNode.d.ts @@ -43,12 +43,13 @@ declare class StructTypeNode extends Node { * @readonly * @default true */ - readonly isStructLayoutNode: boolean; + readonly isStructTypeNode: boolean; /** - * Returns the length of the struct. - * The length is calculated by summing the lengths of the struct's members. + * Returns the length of the struct in 4-byte elements (e.g. float or int components). + * The length is calculated by summing the lengths of the struct's members, accounting for memory alignment. + * To get the size in bytes, multiply the returned value by 4. * - * @returns {number} The length of the struct. + * @returns {number} The length of the struct in 4-byte elements. */ getLength(): number; } diff --git a/types/three/src/nodes/core/UniformNode.d.ts b/types/three/src/nodes/core/UniformNode.d.ts index a4886ff4de4c4b..86b9ce66e02169 100644 --- a/types/three/src/nodes/core/UniformNode.d.ts +++ b/types/three/src/nodes/core/UniformNode.d.ts @@ -71,9 +71,17 @@ declare class UniformNodeClass extends InputNode { * @return {string} The uniform hash. */ getUniformHash(builder: NodeBuilder): string; - onUpdate(callback: (frame: NodeFrame, self: this) => TValue | undefined, updateType: NodeUpdateType): this; + onUpdate( + callback: (this: this, frame: NodeFrame, self: this) => TValue | undefined, + updateType: NodeUpdateType, + ): this; getInputType(builder: NodeBuilder): string; generate(builder: NodeBuilder, output: string | null): string; + + // In UniformNode, callbacks provided to onUpdate-related functions are called with `this` as the last parameter: + onFrameUpdate(callback: (this: this, frame: NodeFrame, self: this) => TValue | undefined): this; + onRenderUpdate(callback: (this: this, frame: NodeFrame, self: this) => TValue | undefined): this; + onObjectUpdate(callback: (this: this, frame: NodeFrame, self: this) => TValue | undefined): this; } declare const UniformNode: { @@ -90,16 +98,45 @@ type UniformNode = UniformNodeClass & InputNode(type: TNodeType): UniformNode; (value: number, type?: "float"): UniformNode<"float", number>; - (value: boolean): UniformNode<"bool", boolean>; - (value: Vector2): UniformNode<"vec2", Vector2>; - (value: Vector3): UniformNode<"vec3", Vector3>; - (value: Vector4): UniformNode<"vec4", Vector4>; - (value: Matrix2): UniformNode<"mat2", Matrix2>; - (value: Matrix3): UniformNode<"mat3", Matrix3>; - (value: Matrix4): UniformNode<"mat4", Matrix4>; - (value: Color): UniformNode<"color", Color>; + (value: number, type: "int"): UniformNode<"int", number>; + (value: number, type: "uint"): UniformNode<"uint", number>; + (value: boolean, type?: "bool"): UniformNode<"bool", boolean>; + (value: Vector2, type?: "vec2"): UniformNode<"vec2", Vector2>; + (value: Vector2, type: "ivec2"): UniformNode<"ivec2", Vector2>; + (value: Vector2, type: "uvec2"): UniformNode<"uvec2", Vector2>; + (value: Vector3, type?: "vec3"): UniformNode<"vec3", Vector3>; + (value: Vector3, type: "ivec3"): UniformNode<"ivec3", Vector3>; + (value: Vector3, type: "uvec3"): UniformNode<"uvec3", Vector3>; + (value: Vector4, type?: "vec4"): UniformNode<"vec4", Vector4>; + (value: Vector4, type: "ivec4"): UniformNode<"ivec4", Vector4>; + (value: Vector4, type: "uvec4"): UniformNode<"uvec4", Vector4>; + (value: Matrix2, type?: "mat2"): UniformNode<"mat2", Matrix2>; + (value: Matrix3, type?: "mat3"): UniformNode<"mat3", Matrix3>; + (value: Matrix4, type?: "mat4"): UniformNode<"mat4", Matrix4>; + (value: Color, type?: "color"): UniformNode<"color", Color>; (value: InputNode): UniformNode; (value: VarNode>): UniformNode; } @@ -113,3 +150,5 @@ interface Uniform { * @returns {UniformNode} */ export declare const uniform: Uniform; + +export {}; diff --git a/types/three/src/nodes/display/BlendModes.d.ts b/types/three/src/nodes/display/BlendModes.d.ts index ddd05ed4836378..45ea0d385a721c 100644 --- a/types/three/src/nodes/display/BlendModes.d.ts +++ b/types/three/src/nodes/display/BlendModes.d.ts @@ -1,15 +1,76 @@ +import { Color } from "../../math/Color.js"; +import { Vector3 } from "../../math/Vector3.js"; +import { Vector4 } from "../../math/Vector4.js"; import Node from "../core/Node.js"; -export const blendBurn: (base: Node, blend: Node) => Node<"vec3">; +type ColorParameter = Node<"float"> | number | Node<"vec3"> | Vector3 | Node<"color"> | Color | Node<"vec4"> | Vector4; -export const blendDodge: (base: Node, blend: Node) => Node<"vec3">; +/** + * Represents a "Color Burn" blend mode. + * + * It's designed to darken the base layer's colors based on the color of the blend layer. + * It significantly increases the contrast of the base layer, making the colors more vibrant and saturated. + * The darker the color in the blend layer, the stronger the darkening and contrast effect on the base layer. + * + * @tsl + * @function + * @param {Node} base - The base color. + * @param {Node} blend - The blend color. A white (#ffffff) blend color does not alter the base color. + * @return {Node} The result. + */ +export const blendBurn: (base: ColorParameter, blend: ColorParameter) => Node<"vec3">; +/** + * Represents a "Color Dodge" blend mode. + * + * It's designed to lighten the base layer's colors based on the color of the blend layer. + * It significantly increases the brightness of the base layer, making the colors lighter and more vibrant. + * The brighter the color in the blend layer, the stronger the lightening and contrast effect on the base layer. + * + * @tsl + * @function + * @param {Node} base - The base color. + * @param {Node} blend - The blend color. A black (#000000) blend color does not alter the base color. + * @return {Node} The result. + */ +export const blendDodge: (base: ColorParameter, blend: ColorParameter) => Node<"vec3">; +/** + * Represents a "Screen" blend mode. + * + * Similar to `blendDodge()`, this mode also lightens the base layer's colors based on the color of the blend layer. + * The "Screen" blend mode is better for general brightening whereas the "Dodge" results in more subtle and nuanced + * effects. + * + * @tsl + * @function + * @param {Node} base - The base color. + * @param {Node} blend - The blend color. A black (#000000) blend color does not alter the base color. + * @return {Node} The result. + */ +export const blendScreen: (base: ColorParameter, blend: ColorParameter) => Node<"vec3">; +/** + * Represents a "Overlay" blend mode. + * + * It's designed to increase the contrast of the base layer based on the color of the blend layer. + * It amplifies the existing colors and contrast in the base layer, making lighter areas lighter and darker areas darker. + * The color of the blend layer significantly influences the resulting contrast and color shift in the base layer. + * + * @tsl + * @function + * @param {Node} base - The base color. + * @param {Node} blend - The blend color + * @return {Node} The result. + */ +export const blendOverlay: (base: ColorParameter, blend: ColorParameter) => Node<"vec3">; +/** + * This function blends two color based on their alpha values by replicating the behavior of `THREE.NormalBlending`. + * It assumes both input colors have non-premultiplied alpha. + * + * @tsl + * @function + * @param {Node} base - The base color. + * @param {Node} blend - The blend color + * @return {Node} The result. + */ +export const blendColor: (base: ColorParameter, blend: ColorParameter) => Node<"vec4">; -export const blendScreen: (base: Node, blend: Node) => Node<"vec3">; - -export const blendOverlay: (base: Node, blend: Node) => Node<"vec3">; - -export const blendColor: (base: Node, blend: Node) => Node<"vec4">; - -export const premultiplyAlpha: (color: Node) => Node<"vec4">; - -export const unpremultiplyAlpha: (color: Node) => Node<"vec4">; +export {}; diff --git a/types/three/src/nodes/display/FrontFacingNode.d.ts b/types/three/src/nodes/display/FrontFacingNode.d.ts index 39238ce68b79a9..1c2b47fbc0d6a0 100644 --- a/types/three/src/nodes/display/FrontFacingNode.d.ts +++ b/types/three/src/nodes/display/FrontFacingNode.d.ts @@ -1,12 +1,71 @@ +import { Vector3 } from "../../math/Vector3.js"; import Node from "../core/Node.js"; +/** + * This node can be used to evaluate whether a primitive is front or back facing. + * + * @augments Node + */ declare class FrontFacingNode extends Node<"bool"> { - isFrontFacingNode: true; + /** + * Constructs a new front facing node. + */ constructor(); + /** + * This flag can be used for type testing. + * + * @type {boolean} + * @readonly + * @default true + */ + readonly isFrontFacingNode: boolean; } export default FrontFacingNode; +/** + * TSL object that represents whether a primitive is front or back facing + * + * @tsl + * @type {FrontFacingNode} + */ export const frontFacing: FrontFacingNode; -export const faceDirection: Node; -export const directionToFaceDirection: (direction: Node) => Node; +/** + * TSL object that represents the front facing status as a number instead of a bool. + * `1` means front facing, `-1` means back facing. + * + * @tsl + * @type {Node} + */ +export const faceDirection: Node<"float">; +/** + * Negates a vector if the rendering occurs on the back side of a face, + * based on the material's side configuration. + * + * - If the material's side is `BackSide`, the vector is inverted (negated). + * - If the material's side is `DoubleSide`, the vector is multiplied by `faceDirection` + * (negated only for back-facing fragments). + * - If the material's side is `FrontSide` (default), the vector remains unchanged. + * + * @tsl + * @function + * @param {Node} vector - The vector to process. + * @returns {Node} The processed vector. + */ +export const negateOnBackSide: (vector: Node<"vec3"> | Vector3) => Node<"vec3">; +/** + * Negates a vector if the rendering occurs on the back side of a face, + * based on the material's side configuration. + * + * - If the material's side is `BackSide`, the vector is inverted (negated). + * - If the material's side is `DoubleSide`, the vector is multiplied by `faceDirection` + * (negated only for back-facing fragments). + * - If the material's side is `FrontSide` (default), the vector remains unchanged. + * + * @tsl + * @function + * @deprecated since r185. Use {@link negateOnBackSide} instead. + * @param {Node} vector - The vector to convert. + * @returns {Node} The converted vector. + */ +export const directionToFaceDirection: (vector: Node<"vec3"> | Vector3) => Node<"vec3">; diff --git a/types/three/src/nodes/display/PassNode.d.ts b/types/three/src/nodes/display/PassNode.d.ts index 2d35bcce45dcd5..afa2c193fac4a8 100644 --- a/types/three/src/nodes/display/PassNode.d.ts +++ b/types/three/src/nodes/display/PassNode.d.ts @@ -94,8 +94,6 @@ declare class PassNode extends TempNode<"vec4"> { setViewport(x: number, y: number, width: number, height: number): void; setViewport(x: Vector4): void; - setPixelRatio(pixelRatio: number): void; - dispose(): void; static COLOR: "color"; diff --git a/types/three/src/nodes/display/PremultiplyAlphaFunctions.d.ts b/types/three/src/nodes/display/PremultiplyAlphaFunctions.d.ts new file mode 100644 index 00000000000000..036dfa5d3be900 --- /dev/null +++ b/types/three/src/nodes/display/PremultiplyAlphaFunctions.d.ts @@ -0,0 +1,37 @@ +import { Color } from "../../math/Color.js"; +import { Vector3 } from "../../math/Vector3.js"; +import { Vector4 } from "../../math/Vector4.js"; +import Node from "../core/Node.js"; + +type ColorParameter = Node<"float"> | number | Node<"vec3"> | Vector3 | Node<"color"> | Color | Node<"vec4"> | Vector4; + +/** + * Premultiplies the RGB channels of a color by its alpha channel. + * + * This function is useful for converting a non-premultiplied alpha color + * into a premultiplied alpha format, where the RGB values are scaled + * by the alpha value. Premultiplied alpha is often used in graphics + * rendering for certain operations, such as compositing and image processing. + * + * @tsl + * @function + * @param {Node} color - The input color with non-premultiplied alpha. + * @return {Node} The color with premultiplied alpha. + */ +export const premultiplyAlpha: (color: ColorParameter) => Node<"vec4">; +/** + * Unpremultiplies the RGB channels of a color by its alpha channel. + * + * This function is useful for converting a premultiplied alpha color + * back into a non-premultiplied alpha format, where the RGB values are + * divided by the alpha value. Unpremultiplied alpha is often used in graphics + * rendering for certain operations, such as compositing and image processing. + * + * @tsl + * @function + * @param {Node} color - The input color with premultiplied alpha. + * @return {Node} The color with non-premultiplied alpha. + */ +export const unpremultiplyAlpha: (color: ColorParameter) => Node<"vec4">; + +export {}; diff --git a/types/three/src/nodes/gpgpu/AtomicFunctionNode.d.ts b/types/three/src/nodes/gpgpu/AtomicFunctionNode.d.ts index b247b2b7f7a402..17fab186050257 100644 --- a/types/three/src/nodes/gpgpu/AtomicFunctionNode.d.ts +++ b/types/three/src/nodes/gpgpu/AtomicFunctionNode.d.ts @@ -11,73 +11,81 @@ export type AtomicMethod = | typeof AtomicFunctionNode.ATOMIC_OR | typeof AtomicFunctionNode.ATOMIC_XOR; -declare class AtomicFunctionNode extends Node { +interface AtomicFunctionNodeInterface { method: AtomicMethod; pointerNode: Node; - valueNode: Node; + valueNode: Node | null; parents: boolean; - - constructor(method: AtomicMethod, pointerNode: Node, valueNode: Node); - - static ATOMIC_LOAD: "atomicLoad"; - static ATOMIC_STORE: "atomicStore"; - static ATOMIC_ADD: "atomicAdd"; - static ATOMIC_SUB: "atomicSub"; - static ATOMIC_MAX: "atomicMax"; - static ATOMIC_MIN: "atomicMin"; - static ATOMIC_AND: "atomicAnd"; - static ATOMIC_OR: "atomicOr"; - static ATOMIC_XOR: "atomicXor"; } +declare const AtomicFunctionNode: { + new( + method: AtomicMethod, + pointerNode: Node, + valueNode: Node | null, + ): AtomicFunctionNode; + + ATOMIC_LOAD: "atomicLoad"; + ATOMIC_STORE: "atomicStore"; + ATOMIC_ADD: "atomicAdd"; + ATOMIC_SUB: "atomicSub"; + ATOMIC_MAX: "atomicMax"; + ATOMIC_MIN: "atomicMin"; + ATOMIC_AND: "atomicAnd"; + ATOMIC_OR: "atomicOr"; + ATOMIC_XOR: "atomicXor"; +}; + +export type AtomicFunctionNode = Node & AtomicFunctionNodeInterface; + export default AtomicFunctionNode; -export const atomicFunc: ( +export const atomicFunc: ( method: AtomicMethod, - pointerNode: Node, - valueNode: Node, -) => AtomicFunctionNode; + pointerNode: Node, + valueNode: Node | null, +) => AtomicFunctionNode; -export const atomicLoad: ( - pointerNode: Node, -) => AtomicFunctionNode; +export const atomicLoad: ( + pointerNode: Node, +) => AtomicFunctionNode; -export const atomicStore: ( - pointerNode: Node, +export const atomicStore: ( + pointerNode: Node, valueNode: Node | number, -) => AtomicFunctionNode; +) => AtomicFunctionNode; -export const atomicAdd: ( - pointerNode: Node, +export const atomicAdd: ( + pointerNode: Node, valueNode: Node | number, -) => AtomicFunctionNode; +) => AtomicFunctionNode; -export const atomicSub: ( - pointerNode: Node, +export const atomicSub: ( + pointerNode: Node, valueNode: Node | number, -) => AtomicFunctionNode; +) => AtomicFunctionNode; -export const atomicMax: ( - pointerNode: Node, +export const atomicMax: ( + pointerNode: Node, valueNode: Node, -) => AtomicFunctionNode; +) => AtomicFunctionNode; -export const atomicMin: ( - pointerNode: Node, +export const atomicMin: ( + pointerNode: Node, valueNode: Node, -) => AtomicFunctionNode; +) => AtomicFunctionNode; -export const atomicAnd: ( - pointerNode: Node, +export const atomicAnd: ( + pointerNode: Node, valueNode: Node, -) => AtomicFunctionNode; +) => AtomicFunctionNode; -export const atomicOr: ( - pointerNode: Node, +export const atomicOr: ( + pointerNode: Node, valueNode: Node, -) => AtomicFunctionNode; +) => AtomicFunctionNode; -export const atomicXor: ( - pointerNode: Node, +export const atomicXor: ( + pointerNode: Node, valueNode: Node, -) => AtomicFunctionNode; +) => AtomicFunctionNode; diff --git a/types/three/src/nodes/lighting/LightingContextNode.d.ts b/types/three/src/nodes/lighting/LightingContextNode.d.ts index ce2d027ad73f03..d443e56e59f009 100644 --- a/types/three/src/nodes/lighting/LightingContextNode.d.ts +++ b/types/three/src/nodes/lighting/LightingContextNode.d.ts @@ -1,6 +1,7 @@ import ContextNode from "../core/ContextNode.js"; import LightingModel, { LightingModelReflectedLight } from "../core/LightingModel.js"; import Node from "../core/Node.js"; +import LightingNode from "./LightingNode.js"; import LightsNode from "./LightsNode.js"; export interface LightingContext { @@ -9,18 +10,21 @@ export interface LightingContext { iblIrradiance: Node; ambientOcclusion: Node; reflectedLight: LightingModelReflectedLight; + materialLightings: LightingNode[]; backdrop: Node; backdropAlpha: Node; } export default class LightingContextNode extends ContextNode { - lightingModelNode: LightingModel | null; + lightingModel: LightingModel | null; + materialLightings: LightingNode[]; backdropNode: Node | null; backdropAlphaNode: Node | null; constructor( lightsNode: LightsNode, lightingModel?: LightingModel | null, + materialLightings?: LightingNode[], backdropNode?: Node | null, backdropAlphaNode?: Node | null, ); @@ -30,5 +34,8 @@ export default class LightingContextNode extends ContextNode { export const lightingContext: ( node: LightsNode, - lightingModelNode?: LightingModel, + lightingModel?: LightingModel | null, + materialLightings?: LightingNode[], + backdropNode?: Node | null, + backdropAlphaNode?: Node | null, ) => LightingContextNode; diff --git a/types/three/src/nodes/lighting/LightsNode.d.ts b/types/three/src/nodes/lighting/LightsNode.d.ts index b7387a2efe6469..02da38c8f69722 100644 --- a/types/three/src/nodes/lighting/LightsNode.d.ts +++ b/types/three/src/nodes/lighting/LightsNode.d.ts @@ -18,13 +18,13 @@ export interface DirectRectAreaLightData { } declare class LightsNode extends Node { - totalDiffuseNode: Node; - totalSpecularNode: Node; - outgoingLightNode: Node; + totalDiffuseNode: Node<"vec3">; + totalSpecularNode: Node<"vec3">; + outgoingLightNode: Node<"vec3">; constructor(); - setupLightsNode(builder: NodeBuilder): void; + setupLightsNode(builder: NodeBuilder): LightingNode[]; setupDirectLight(builder: NodeBuilder, lightNode: Node, lightData: DirectLightData): void; diff --git a/types/three/src/nodes/math/MathNode.d.ts b/types/three/src/nodes/math/MathNode.d.ts index 13f9f34e28c647..cdfa2ff736b655 100644 --- a/types/three/src/nodes/math/MathNode.d.ts +++ b/types/three/src/nodes/math/MathNode.d.ts @@ -1,3 +1,7 @@ +import { Color } from "../../math/Color.js"; +import { Matrix2 } from "../../math/Matrix2.js"; +import { Matrix3 } from "../../math/Matrix3.js"; +import { Matrix4 } from "../../math/Matrix4.js"; import { Vector2 } from "../../math/Vector2.js"; import { Vector3 } from "../../math/Vector3.js"; import { Vector4 } from "../../math/Vector4.js"; @@ -143,17 +147,33 @@ export default class MathNode extends TempNode { } type FloatOrNumber = Node<"float"> | number; -type IntOrNumber = Node<"int"> | number; type FloatVector = Node<"vec2"> | Node<"vec3"> | Node<"vec4">; type FloatVectorOrNumber = FloatOrNumber | Node<"vec2"> | Node<"vec3"> | Node<"vec4">; -type BoolVector = Node<"bvec2"> | Node<"bvec3"> | Node<"bvec4">; +type NumberVectorOrNumber = + | FloatVectorOrNumber + | Node<"int"> + | Node<"uint"> + | Node<"ivec2"> + | Node<"ivec3"> + | Node<"ivec4"> + | Node<"uvec2"> + | Node<"uvec3"> + | Node<"uvec4">; -type Matrix = Node<"mat2"> | Node<"mat3"> | Node<"mat4">; +type Vec2 = Node<"vec2"> | Vector2; +type Vec3 = Node<"vec3"> | Vector3 | Node<"color"> | Color; +type Vec4 = Node<"vec4"> | Vector4; -type Vec2OrLessOrFloat = FloatOrNumber | Node<"vec2">; -type Vec3OrLessOrFloat = Vec2OrLessOrFloat | Node<"vec3">; -type Vec4OrLessOrFloat = Vec3OrLessOrFloat | Node<"vec4">; +type Vec2OrFloat = Vec2 | FloatOrNumber; +type Vec3OrFloat = Vec3 | FloatOrNumber; +type Vec4OrFloat = Vec4 | FloatOrNumber; + +type Mat2 = Node<"mat2"> | Matrix2; +type Mat3 = Node<"mat3"> | Matrix3; +type Mat4 = Node<"mat4"> | Matrix4; + +type Matrix = Mat2 | Mat3 | Mat4; export const EPSILON: Node<"float">; export const INFINITY: Node<"float">; @@ -168,62 +188,52 @@ export const TWO_PI: Node<"float">; export const HALF_PI: Node<"float">; -export const all: (x: BoolVector) => Node<"bool">; -export const any: (x: BoolVector) => Node<"bool">; +type BoolOrVector = Node<"bool"> | boolean | Node<"bvec2"> | Node<"bvec3"> | Node<"bvec4">; + +export const all: (x: BoolOrVector) => Node<"bool">; +export const any: (x: BoolOrVector) => Node<"bool">; declare module "../core/Node.js" { - interface BvecExtensions { + interface BoolOrVecExtensions { all: () => Node<"bool">; any: () => Node<"bool">; } } -interface UnaryFunction { +interface UnaryFloatVecFunction { (x: FloatOrNumber): Node<"float">; -} -export const radians: UnaryFunction; -export const degrees: UnaryFunction; -export const exp: UnaryFunction; -export const exp2: UnaryFunction; -export const log: UnaryFunction; -export const log2: UnaryFunction; -export const sqrt: UnaryFunction; -export const inverseSqrt: UnaryFunction; -declare module "../core/Node.js" { - interface FloatExtensions { - radians: () => Node<"float">; - degrees: () => Node<"float">; - exp: () => Node<"float">; - exp2: () => Node<"float">; - log: () => Node<"float">; - log2: () => Node<"float">; - sqrt: () => Node<"float">; - inverseSqrt: () => Node<"float">; - } -} - -interface FloorCeil { - (x: FloatOrNumber): Node<"float">; - (x: Node<"vec2">): Node<"vec2">; - (x: Node<"vec3">): Node<"vec3">; - (x: Node<"vec4">): Node<"vec4">; -} -export const floor: FloorCeil; -export const ceil: FloorCeil; -declare module "../core/Node.js" { - interface FloatExtensions { - floor: () => Node<"float">; - ceil: () => Node<"float">; - } - interface FloatVecExtensions { - floor: () => Node; - ceil: () => Node; + (x: Vec2): Node<"vec2">; + (x: Vec3): Node<"vec3">; + (x: Vec4): Node<"vec4">; +} +export const radians: UnaryFloatVecFunction; +export const degrees: UnaryFloatVecFunction; +export const exp: UnaryFloatVecFunction; +export const exp2: UnaryFloatVecFunction; +export const log: UnaryFloatVecFunction; +export const log2: UnaryFloatVecFunction; +export const sqrt: UnaryFloatVecFunction; +export const inverseSqrt: UnaryFloatVecFunction; +export const floor: UnaryFloatVecFunction; +export const ceil: UnaryFloatVecFunction; +declare module "../core/Node.js" { + interface FloatOrVecExtensions { + radians: () => Node; + degrees: () => Node; + exp: () => Node; + exp2: () => Node; + log: () => Node; + log2: () => Node; + sqrt: () => Node; + inverseSqrt: () => Node; + floor: () => Node; + ceil: () => Node; } } interface Normalize { - (x: Node<"vec2"> | Vector2): Node<"vec2">; - (x: Node<"vec3"> | Vector3): Node<"vec3">; - (x: Node<"vec4"> | Vector4): Node<"vec4">; + (x: Vec2): Node<"vec2">; + (x: Vec3): Node<"vec3">; + (x: Vec4): Node<"vec4">; } export const normalize: Normalize; declare module "../core/Node.js" { @@ -232,205 +242,181 @@ declare module "../core/Node.js" { } } -interface Fract { - (x: FloatOrNumber): Node<"float">; - (x: Node<"vec2">): Node<"vec2">; - (x: Node<"vec3">): Node<"vec3">; - (x: Node<"vec4">): Node<"vec4">; -} -export const fract: Fract; +interface ArcTanFunction { + (y: FloatOrNumber, x?: FloatOrNumber): Node<"float">; + (y: Vec2OrFloat, x?: Vec2OrFloat): Node<"vec2">; + (y: Vec3OrFloat, x?: Vec3OrFloat): Node<"vec3">; + (y: Vec4OrFloat, x?: Vec4OrFloat): Node<"vec4">; +} + +export const fract: UnaryFloatVecFunction; +export const sin: UnaryFloatVecFunction; +export const sinh: UnaryFloatVecFunction; +export const cos: UnaryFloatVecFunction; +export const cosh: UnaryFloatVecFunction; +export const tan: UnaryFloatVecFunction; +export const tanh: UnaryFloatVecFunction; +export const asin: UnaryFloatVecFunction; +export const asinh: UnaryFloatVecFunction; +export const acos: UnaryFloatVecFunction; +export const acosh: UnaryFloatVecFunction; +export const atan: ArcTanFunction; +export const atanh: UnaryFloatVecFunction; + declare module "../core/Node.js" { - interface FloatExtensions { - fract: () => Node<"float">; - } - interface FloatVecExtensions { - fract: () => Node; + interface FloatOrVecExtensions { + fract: () => Node; + sin: () => Node; + sinh: () => Node; + cos: () => Node; + cosh: () => Node; + tan: () => Node; + tanh: () => Node; + asin: () => Node; + asinh: () => Node; + acos: () => Node; + acosh: () => Node; + atanh: () => Node; } } -interface TrigonometricFunction { - (x: FloatOrNumber): Node<"float">; - (x: Node<"vec2">): Node<"vec2">; - (x: Node<"vec3">): Node<"vec3">; - (x: Node<"vec4">): Node<"vec4">; -} -interface ArcTanFunction { - (y: FloatOrNumber, x?: FloatOrNumber): Node<"float">; - (y: Node<"vec2">, x?: Vec2OrLessOrFloat): Node<"vec2">; - (y: Node<"vec3">, x?: Vec3OrLessOrFloat): Node<"vec3">; - (y: Node<"vec4">, x?: Vec4OrLessOrFloat): Node<"vec4">; -} -export const sin: TrigonometricFunction; -export const sinh: TrigonometricFunction; -export const cos: TrigonometricFunction; -export const cosh: TrigonometricFunction; -export const tan: TrigonometricFunction; -export const tanh: TrigonometricFunction; -export const asin: TrigonometricFunction; -export const asinh: TrigonometricFunction; -export const acos: TrigonometricFunction; -export const acosh: TrigonometricFunction; -export const atan: ArcTanFunction; -export const atanh: TrigonometricFunction; declare module "../core/Node.js" { interface FloatExtensions { - sin: () => Node<"float">; - sinh: () => Node<"float">; - cos: () => Node<"float">; - cosh: () => Node<"float">; - tan: () => Node<"float">; - tanh: () => Node<"float">; - asin: () => Node<"float">; - asinh: () => Node<"float">; - acos: () => Node<"float">; - acosh: () => Node<"float">; atan: (x?: FloatOrNumber) => Node<"float">; - atanh: () => Node<"float">; - } - interface FloatVecExtensions { - sin: () => Node; - sinh: () => Node; - cos: () => Node; - cosh: () => Node; - tan: () => Node; - tanh: () => Node; - asin: () => Node; - asinh: () => Node; - acos: () => Node; - acosh: () => Node; - atanh: () => Node; } interface Vec2Extensions { - atan: (x?: Vec2OrLessOrFloat) => Node<"vec2">; + atan: (x?: Vec2OrFloat) => Node<"vec2">; } interface Vec3Extensions { - atan: (x?: Vec3OrLessOrFloat) => Node<"vec3">; + atan: (x?: Vec3OrFloat) => Node<"vec3">; } interface Vec4Extensions { - atan: (x?: Vec4OrLessOrFloat) => Node<"vec4">; + atan: (x?: Vec4OrFloat) => Node<"vec4">; } } -interface Abs { +interface UnaryNumVecFunction { (x: FloatOrNumber): Node<"float">; - (x: Node<"vec2">): Node<"vec2">; - (x: Node<"vec3">): Node<"vec3">; - (x: Node<"vec4">): Node<"vec4">; - (x: IntOrNumber): Node<"int">; + (x: Node<"int">): Node<"int">; + (x: Node<"uint">): Node<"uint">; + (x: Vec2): Node<"vec2">; + (x: Node<"ivec2">): Node<"ivec2">; + (x: Node<"uvec2">): Node<"uvec2">; + (x: Vec3): Node<"vec3">; + (x: Node<"ivec3">): Node<"ivec3">; + (x: Node<"uvec3">): Node<"uvec3">; + (x: Vec4): Node<"vec4">; + (x: Node<"ivec4">): Node<"ivec4">; + (x: Node<"uvec4">): Node<"uvec4">; } -export const abs: Abs; + +export const abs: UnaryNumVecFunction; declare module "../core/Node.js" { - interface FloatExtensions { - abs: () => Node<"float">; + interface FloatOrVecExtensions { + abs: () => Node; } - interface IntExtensions { - abs: () => Node<"int">; + interface IntOrVecExtensions { + abs: () => Node; } - interface FloatVecExtensions { - abs: () => Node; + interface UintOrVecExtensions { + abs: () => Node; } } -interface Sign { +interface SignFunction { (x: FloatOrNumber): Node<"float">; - (x: Node<"vec2">): Node<"vec2">; - (x: Node<"vec3">): Node<"vec3">; - (x: Node<"vec4">): Node<"vec4">; + (x: Node<"int">): Node<"int">; + (x: Vec2): Node<"vec2">; + (x: Node<"ivec2">): Node<"ivec2">; + (x: Vec3): Node<"vec3">; + (x: Node<"ivec3">): Node<"ivec3">; + (x: Vec4): Node<"vec4">; + (x: Node<"ivec4">): Node<"ivec4">; } -export const sign: Sign; +export const sign: SignFunction; declare module "../core/Node.js" { - interface FloatExtensions { - sign: () => Node<"float">; + interface FloatOrVecExtensions { + sign: () => Node; } - interface FloatVecExtensions { - sign: () => Node; + interface IntOrVecExtensions { + sign: () => Node; } } -export const length: (x: FloatVector | Node) => Node<"float">; +export const length: (x: NumberVectorOrNumber) => Node<"float">; declare module "../core/Node.js" { - interface FloatVecExtensions { + interface FloatOrVecExtensions { + length: () => Node<"float">; + } + interface IntOrVecExtensions { length: () => Node<"float">; } } -interface Negate { +interface NegateFunction { (x: FloatOrNumber): Node<"float">; - (x: Node<"vec2">): Node<"vec2">; - (x: Node<"vec3">): Node<"vec3">; - (x: Node<"vec4">): Node<"vec4">; + (x: Node<"int">): Node<"int">; + (x: Vec2): Node<"vec2">; + (x: Node<"ivec2">): Node<"ivec2">; + (x: Vec3): Node<"vec3">; + (x: Node<"ivec3">): Node<"ivec3">; + (x: Vec4): Node<"vec4">; + (x: Node<"ivec4">): Node<"ivec4">; } -export const negate: Negate; +export const negate: NegateFunction; declare module "../core/Node.js" { - interface FloatExtensions { - negate: () => Node<"float">; + interface FloatOrVecExtensions { + negate: () => Node; } - interface FloatVecExtensions { - negate: () => Node; + interface IntOrVecExtensions { + negate: () => Node; } } -interface OneMinus { - (x: FloatOrNumber): Node<"float">; - (x: Node<"vec2">): Node<"vec2">; - (x: Node<"vec3">): Node<"vec3">; - (x: Node<"vec4">): Node<"vec4">; -} -export const oneMinus: OneMinus; +export const oneMinus: UnaryFloatVecFunction; declare module "../core/Node.js" { - interface FloatExtensions { - oneMinus: () => Node<"float">; - } - interface FloatVecExtensions { - oneMinus: () => Node; + interface FloatOrVecExtensions { + oneMinus: () => Node; } } -interface Derivative { - (x: Node<"vec2">): Node<"vec2">; - (x: Node<"vec3">): Node<"vec3">; - (x: Node<"vec4">): Node<"vec4">; -} -export const dFdx: Derivative; -export const dFdy: Derivative; +export const dFdx: UnaryFloatVecFunction; +export const dFdy: UnaryFloatVecFunction; declare module "../core/Node.js" { - interface FloatVecExtensions { - dFdx: () => Node; - dFdy: () => Node; + interface FloatOrVecExtensions { + dFdx: () => Node; + dFdy: () => Node; } } -export const round: (x: FloatOrNumber) => Node<"float">; -export const reciprocal: (x: FloatOrNumber) => Node<"float">; -export const trunc: (x: FloatOrNumber) => Node<"float">; +export const round: UnaryNumVecFunction; declare module "../core/Node.js" { - interface FloatExtensions { - round: () => Node<"float">; - reciprocal: () => Node<"float">; - trunc: () => Node<"float">; + interface FloatOrVecExtensions { + round: () => Node; + } + interface IntOrVecExtensions { + round: () => Node; + } + interface UintOrVecExtensions { + round: () => Node; } } -interface Fwidth { - (x: FloatOrNumber): Node<"float">; - (x: Node<"vec2">): Node<"vec2">; - (x: Node<"vec3">): Node<"vec3">; - (x: Node<"vec4">): Node<"vec4">; -} -export const fwidth: Fwidth; +export const reciprocal: UnaryFloatVecFunction; +export const trunc: UnaryFloatVecFunction; +export const fwidth: UnaryFloatVecFunction; declare module "../core/Node.js" { - interface FloatExtensions { - fwidth: () => Node<"float">; - } - interface FloatVecExtensions { - fwidth: () => Node; + interface FloatOrVecExtensions { + reciprocal: () => Node; + trunc: () => Node; + fwidth: () => Node; } } interface Transpose { - (x: Node<"mat2">): Node<"mat2">; - (x: Node<"mat3">): Node<"mat3">; - (x: Node<"mat4">): Node<"mat4">; + (x: Mat2): Node<"mat2">; + (x: Mat3): Node<"mat3">; + (x: Mat4): Node<"mat4">; } export const transpose: Transpose; declare module "../core/Node.js" { @@ -447,9 +433,9 @@ declare module "../core/Node.js" { } interface Inverse { - (x: Node<"mat2">): Node<"mat2">; - (x: Node<"mat3">): Node<"mat3">; - (x: Node<"mat4">): Node<"mat4">; + (x: Mat2): Node<"mat2">; + (x: Mat3): Node<"mat3">; + (x: Mat4): Node<"mat4">; } export const inverse: Inverse; declare module "../core/Node.js" { @@ -458,31 +444,32 @@ declare module "../core/Node.js" { } } +// TODO Allow int/uint interface MinMax { (x: FloatOrNumber, y: FloatOrNumber, ...params: FloatOrNumber[]): Node<"float">; - (x: Vec2OrLessOrFloat, y: Vec2OrLessOrFloat, ...params: Vec2OrLessOrFloat[]): Node<"vec2">; - (x: Vec3OrLessOrFloat, y: Vec3OrLessOrFloat, ...params: Vec3OrLessOrFloat[]): Node<"vec3">; - (x: Vec4OrLessOrFloat, y: Vec4OrLessOrFloat, ...params: Vec4OrLessOrFloat[]): Node<"vec4">; + (x: Vec2OrFloat, y: Vec2OrFloat, ...params: Vec2OrFloat[]): Node<"vec2">; + (x: Vec3OrFloat, y: Vec3OrFloat, ...params: Vec3OrFloat[]): Node<"vec3">; + (x: Vec4OrFloat, y: Vec4OrFloat, ...params: Vec4OrFloat[]): Node<"vec4">; } export const min: MinMax; export const max: MinMax; interface MinMaxFloatExtension { (y: FloatOrNumber, ...params: FloatOrNumber[]): Node<"float">; - (y: Vec2OrLessOrFloat, ...params: Vec2OrLessOrFloat[]): Node<"vec2">; - (y: Vec3OrLessOrFloat, ...params: Vec3OrLessOrFloat[]): Node<"vec3">; - (y: Vec4OrLessOrFloat, ...params: Vec4OrLessOrFloat[]): Node<"vec4">; + (y: Vec2OrFloat, ...params: Vec2OrFloat[]): Node<"vec2">; + (y: Vec3OrFloat, ...params: Vec3OrFloat[]): Node<"vec3">; + (y: Vec4OrFloat, ...params: Vec4OrFloat[]): Node<"vec4">; } interface MinMaxVec2Extension { - (y: Vec2OrLessOrFloat, ...params: Vec2OrLessOrFloat[]): Node<"vec2">; - (y: Vec3OrLessOrFloat, ...params: Vec3OrLessOrFloat[]): Node<"vec3">; - (y: Vec4OrLessOrFloat, ...params: Vec4OrLessOrFloat[]): Node<"vec4">; + (y: Vec2OrFloat, ...params: Vec2OrFloat[]): Node<"vec2">; + (y: Vec3OrFloat, ...params: Vec3OrFloat[]): Node<"vec3">; + (y: Vec4OrFloat, ...params: Vec4OrFloat[]): Node<"vec4">; } interface MinMaxVec3Extension { - (y: Vec3OrLessOrFloat, ...params: Vec3OrLessOrFloat[]): Node<"vec3">; - (y: Vec4OrLessOrFloat, ...params: Vec4OrLessOrFloat[]): Node<"vec4">; + (y: Vec3OrFloat, ...params: Vec3OrFloat[]): Node<"vec3">; + (y: Vec4OrFloat, ...params: Vec4OrFloat[]): Node<"vec4">; } interface MinMaxVec4Extension { - (y: Vec4OrLessOrFloat, ...params: Vec4OrLessOrFloat[]): Node<"vec4">; + (y: Vec4OrFloat, ...params: Vec4OrFloat[]): Node<"vec4">; } declare module "../core/Node.js" { interface FloatExtensions { @@ -503,25 +490,28 @@ declare module "../core/Node.js" { } } -export const step: (x: FloatOrNumber, y: FloatOrNumber) => Node<"float">; +interface Step { + (edge: FloatOrNumber, x: FloatOrNumber): Node<"float">; + (edge: Vec2OrFloat, x: Vec2OrFloat): Node<"vec2">; + (edge: Vec3OrFloat, x: Vec3OrFloat): Node<"vec3">; + (edge: Vec4OrFloat, x: Vec4OrFloat): Node<"vec4">; +} +export const step: Step; interface Reflect { - (I: Vec2OrLessOrFloat, N: Vec2OrLessOrFloat): Node<"vec2">; - (I: Vec3OrLessOrFloat, N: Vec3OrLessOrFloat): Node<"vec3">; - (I: Vec4OrLessOrFloat, N: Vec4OrLessOrFloat): Node<"vec4">; + (I: Vec2OrFloat, N: Vec2OrFloat): Node<"vec2">; + (I: Vec3OrFloat, N: Vec3OrFloat): Node<"vec3">; + (I: Vec4OrFloat, N: Vec4OrFloat): Node<"vec4">; } export const reflect: Reflect; interface ReflectVec2Extension { - (N: Vec2OrLessOrFloat): Node<"vec2">; - (N: Vec3OrLessOrFloat): Node<"vec3">; - (N: Vec4OrLessOrFloat): Node<"vec4">; + (N: Vec2OrFloat): Node<"vec2">; } interface ReflectVec3Extension { - (N: Vec3OrLessOrFloat): Node<"vec3">; - (N: Vec4OrLessOrFloat): Node<"vec4">; + (N: Vec3OrFloat): Node<"vec3">; } interface ReflectVec4Extension { - (N: Vec4OrLessOrFloat): Node<"vec4">; + (N: Vec4OrFloat): Node<"vec4">; } declare module "../core/Node.js" { interface Vec2Extensions { @@ -537,38 +527,33 @@ declare module "../core/Node.js" { export const distance: (x: FloatVectorOrNumber, y: FloatVectorOrNumber) => Node<"float">; declare module "../core/Node.js" { - interface FloatExtensions { - distance: (y: FloatVectorOrNumber) => Node<"float">; - } - interface FloatVecExtensions { + interface FloatOrVecExtensions { distance: (y: FloatVectorOrNumber) => Node<"float">; } } +// TODO Allow int/uint interface Difference { (x: FloatOrNumber, y: FloatOrNumber): Node<"float">; - (x: Vec2OrLessOrFloat, y: Vec2OrLessOrFloat): Node<"vec2">; - (x: Vec3OrLessOrFloat, y: Vec3OrLessOrFloat): Node<"vec3">; - (x: Vec4OrLessOrFloat, y: Vec4OrLessOrFloat): Node<"vec4">; + (x: Vec2OrFloat, y: Vec2OrFloat): Node<"vec2">; + (x: Vec3OrFloat, y: Vec3OrFloat): Node<"vec3">; + (x: Vec4OrFloat, y: Vec4OrFloat): Node<"vec4">; } export const difference: Difference; interface DifferenceFloatExtension { (y: FloatOrNumber): Node<"float">; - (y: Vec2OrLessOrFloat): Node<"vec2">; - (y: Vec3OrLessOrFloat): Node<"vec3">; - (y: Vec4OrLessOrFloat): Node<"vec4">; + (y: Vec2OrFloat): Node<"vec2">; + (y: Vec3OrFloat): Node<"vec3">; + (y: Vec4OrFloat): Node<"vec4">; } interface DifferenceVec2Extension { - (y: Vec2OrLessOrFloat): Node<"vec2">; - (y: Vec3OrLessOrFloat): Node<"vec3">; - (y: Vec4OrLessOrFloat): Node<"vec4">; + (y: Vec2OrFloat): Node<"vec2">; } interface DifferenceVec3Extension { - (y: Vec3OrLessOrFloat): Node<"vec3">; - (y: Vec4OrLessOrFloat): Node<"vec4">; + (y: Vec3OrFloat): Node<"vec3">; } interface DifferenceVec4Extension { - (y: Vec4OrLessOrFloat): Node<"vec4">; + (y: Vec4OrFloat): Node<"vec4">; } declare module "../core/Node.js" { interface FloatExtensions { @@ -585,6 +570,7 @@ declare module "../core/Node.js" { } } +// TODO Allow int/uint export const dot: (x: FloatVector, y: FloatVector) => Node<"float">; declare module "../core/Node.js" { interface FloatVecExtensions { @@ -592,55 +578,95 @@ declare module "../core/Node.js" { } } -export const cross: (x: Node<"vec3">, y: Node<"vec3">) => Node<"vec3">; +export const cross: (x: Vec3, y: Vec3) => Node<"vec3">; declare module "../core/Node.js" { interface Vec3Extensions { - cross: (y: Node<"vec3">) => Node<"vec3">; + cross: (y: Vec3) => Node<"vec3">; } } interface Pow { (x: FloatOrNumber, y: FloatOrNumber): Node<"float">; - (x: Node<"vec2">, y: Node<"vec2">): Node<"vec2">; - (x: Node<"vec3">, y: Node<"vec3">): Node<"vec3">; - (x: Node<"vec4">, y: Node<"vec4">): Node<"vec4">; + (x: Vec2OrFloat, y: Vec2OrFloat): Node<"vec2">; + (x: Vec3OrFloat, y: Vec3OrFloat): Node<"vec3">; + (x: Vec4OrFloat, y: Vec4OrFloat): Node<"vec4">; +} +export const pow: Pow; +interface PowFloatExtension { + (y: FloatOrNumber): Node<"float">; + (y: Vec2OrFloat): Node<"vec2">; + (y: Vec3OrFloat): Node<"vec3">; + (y: Vec4OrFloat): Node<"vec4">; +} +interface PowVec2Extension { + (y: Vec2OrFloat): Node<"vec2">; +} +interface PowVec3Extension { + (y: Vec3OrFloat): Node<"vec3">; +} +interface PowVec4Extension { + (y: Vec4OrFloat): Node<"vec4">; } -export const pow: (x: FloatOrNumber, y: FloatOrNumber) => Node<"float">; declare module "../core/Node.js" { interface FloatExtensions { - pow: (y: FloatOrNumber) => Node<"float">; + pow: PowFloatExtension; } - interface FloatVecExtensions { - pow: (y: Node) => Node; + interface Vec2Extensions { + pow: PowVec2Extension; + } + interface Vec3Extensions { + pow: PowVec3Extension; + } + interface Vec4Extensions { + pow: PowVec4Extension; } } interface PowConstant { (x: FloatOrNumber): Node<"float">; - (x: Node<"vec2">): Node<"vec2">; - (x: Node<"vec3">): Node<"vec3">; - (x: Node<"vec4">): Node<"vec4">; + (x: Vec2): Node<"vec2">; + (x: Vec3): Node<"vec3">; + (x: Vec4): Node<"vec4">; } export const pow2: PowConstant; export const pow3: PowConstant; export const pow4: PowConstant; declare module "../core/Node.js" { - interface FloatExtensions { - pow2: () => Node<"float">; - pow3: () => Node<"float">; - pow4: () => Node<"float">; + interface FloatOrVecExtensions { + pow2: () => Node; + pow3: () => Node; + pow4: () => Node; } - interface FloatVecExtensions { - pow2: () => Node; - pow3: () => Node; - pow4: () => Node; +} + +interface TransformDirection { + (direction: Vec3, matrix: Mat3 | Mat4): Node<"vec3">; + (matrix: Mat3 | Mat4, direction: Vec3): Node<"vec3">; +} + +export const transformDirection: TransformDirection; +declare module "../core/Node.js" { + interface Vec3Extensions { + transformDirection: (matrix: Mat3 | Mat4) => Node<"vec3">; + } + interface Mat3Extensions { + transformDirection: (direction: Vec3) => Node<"vec3">; + } + interface Mat4Extensions { + transformDirection: (direction: Vec3) => Node<"vec3">; } } -export const transformDirection: (direction: Node<"vec3">, matrix: Node<"mat3"> | Node<"mat4">) => Node<"vec3">; +interface TransformNormalByViewMatrix { + (normal: Vec3, viewMatrix: Mat3 | Mat4): Node<"vec3">; +} + +export const transformNormalByViewMatrix: TransformNormalByViewMatrix; +export const transformNormalByInverseViewMatrix: TransformNormalByViewMatrix; declare module "../core/Node.js" { interface Vec3Extensions { - transformDirection: (matrix: Node<"mat3"> | Node<"mat4">) => Node<"vec3">; + transformNormalByViewMatrix: (matrix: Mat3 | Mat4) => Node<"vec3">; + transformNormalByInverseViewMatrix: (matrix: Mat3 | Mat4) => Node<"vec3">; } } @@ -660,36 +686,34 @@ declare module "../core/Node.js" { interface Mix { (a: FloatOrNumber, b: FloatOrNumber, t: FloatOrNumber): Node<"float">; - (a: Vec2OrLessOrFloat, b: Vec2OrLessOrFloat, t: FloatOrNumber): Node<"vec2">; - (a: Vec3OrLessOrFloat | Node<"color">, b: Vec3OrLessOrFloat | Node<"color">, t: FloatOrNumber): Node<"vec3">; - (a: Vec4OrLessOrFloat, b: Vec4OrLessOrFloat, t: FloatOrNumber): Node<"vec4">; + (a: Vec2OrFloat, b: Vec2OrFloat, t: FloatOrNumber): Node<"vec2">; + (a: Vec3OrFloat, b: Vec3OrFloat, t: FloatOrNumber): Node<"vec3">; + (a: Vec4OrFloat | Vec3, b: Vec4OrFloat | Vec3, t: FloatOrNumber): Node<"vec4">; } export const mix: Mix; +// TODO Allow int/uint interface Clamp { (value: FloatOrNumber, low?: FloatOrNumber, high?: FloatOrNumber): Node<"float">; - (value: Vec2OrLessOrFloat, low?: Vec2OrLessOrFloat, high?: Vec2OrLessOrFloat): Node<"vec2">; - (value: Vec3OrLessOrFloat, low?: Vec3OrLessOrFloat, high?: Vec3OrLessOrFloat): Node<"vec3">; - (value: Vec4OrLessOrFloat, low?: Vec4OrLessOrFloat, high?: Vec4OrLessOrFloat): Node<"vec4">; + (value: Vec2OrFloat, low?: Vec2OrFloat, high?: Vec2OrFloat): Node<"vec2">; + (value: Vec3OrFloat, low?: Vec3OrFloat, high?: Vec3OrFloat): Node<"vec3">; + (value: Vec4OrFloat, low?: Vec4OrFloat, high?: Vec4OrFloat): Node<"vec4">; } export const clamp: Clamp; interface ClampFloatExtension { (low?: FloatOrNumber, high?: FloatOrNumber): Node<"float">; - (low?: Vec2OrLessOrFloat, high?: Vec2OrLessOrFloat): Node<"vec2">; - (low?: Vec3OrLessOrFloat, high?: Vec3OrLessOrFloat): Node<"vec3">; - (low?: Vec4OrLessOrFloat, high?: Vec4OrLessOrFloat): Node<"vec4">; + (low?: Vec2OrFloat, high?: Vec2OrFloat): Node<"vec2">; + (low?: Vec3OrFloat, high?: Vec3OrFloat): Node<"vec3">; + (low?: Vec4OrFloat, high?: Vec4OrFloat): Node<"vec4">; } interface ClampVec2Extension { - (low?: Vec2OrLessOrFloat, high?: Vec2OrLessOrFloat): Node<"vec2">; - (low?: Vec3OrLessOrFloat, high?: Vec3OrLessOrFloat): Node<"vec3">; - (low?: Vec4OrLessOrFloat, high?: Vec4OrLessOrFloat): Node<"vec4">; + (low?: Vec2OrFloat, high?: Vec2OrFloat): Node<"vec2">; } interface ClampVec3Extension { - (low?: Vec3OrLessOrFloat, high?: Vec3OrLessOrFloat): Node<"vec3">; - (low?: Vec4OrLessOrFloat, high?: Vec4OrLessOrFloat): Node<"vec4">; + (low?: Vec3OrFloat, high?: Vec3OrFloat): Node<"vec3">; } interface ClampVec4Extension { - (low?: Vec4OrLessOrFloat, high?: Vec4OrLessOrFloat): Node<"vec4">; + (low?: Vec4OrFloat, high?: Vec4OrFloat): Node<"vec4">; } declare module "../core/Node.js" { interface FloatExtensions { @@ -708,37 +732,31 @@ declare module "../core/Node.js" { interface Saturate { (value: FloatOrNumber): Node<"float">; - (value: Node<"vec2">): Node<"vec2">; - (value: Node<"vec3">): Node<"vec3">; - (value: Node<"vec4">): Node<"vec4">; + (value: Vec2): Node<"vec2">; + (value: Vec3): Node<"vec3">; + (value: Vec4): Node<"vec4">; } export const saturate: Saturate; declare module "../core/Node.js" { - interface FloatExtensions { - saturate: () => Node<"float">; - } - interface FloatVecExtensions { - saturate: () => Node; + interface FloatOrVecExtensions { + saturate: () => Node; } } interface Refract { - (I: Vec2OrLessOrFloat, N: Vec2OrLessOrFloat, ratio: FloatOrNumber): Node<"vec2">; - (I: Vec3OrLessOrFloat, N: Vec3OrLessOrFloat, ratio: FloatOrNumber): Node<"vec3">; - (I: Vec4OrLessOrFloat, N: Vec4OrLessOrFloat, ratio: FloatOrNumber): Node<"vec4">; + (I: Vec2OrFloat, N: Vec2OrFloat, ratio: FloatOrNumber): Node<"vec2">; + (I: Vec3OrFloat, N: Vec3OrFloat, ratio: FloatOrNumber): Node<"vec3">; + (I: Vec4OrFloat, N: Vec4OrFloat, ratio: FloatOrNumber): Node<"vec4">; } export const refract: Refract; interface RefractVec2Extension { - (N: Vec2OrLessOrFloat, ratio: FloatOrNumber): Node<"vec2">; - (N: Vec3OrLessOrFloat, ratio: FloatOrNumber): Node<"vec3">; - (N: Vec4OrLessOrFloat, ratio: FloatOrNumber): Node<"vec4">; + (N: Vec2OrFloat, ratio: FloatOrNumber): Node<"vec2">; } interface RefractVec3Extension { - (N: Vec3OrLessOrFloat, ratio: FloatOrNumber): Node<"vec3">; - (N: Vec4OrLessOrFloat, ratio: FloatOrNumber): Node<"vec4">; + (N: Vec3OrFloat, ratio: FloatOrNumber): Node<"vec3">; } interface RefractVec4Extension { - (N: Vec4OrLessOrFloat, ratio: FloatOrNumber): Node<"vec4">; + (N: Vec4OrFloat, ratio: FloatOrNumber): Node<"vec4">; } declare module "../core/Node.js" { interface Vec2Extensions { @@ -754,26 +772,26 @@ declare module "../core/Node.js" { interface Smoothstep { (low: FloatOrNumber, high: FloatOrNumber, x: FloatOrNumber): Node<"float">; + (low: Vec2OrFloat, high: Vec2OrFloat, x: Vec2OrFloat): Node<"vec2">; + (low: Vec3OrFloat, high: Vec3OrFloat, x: Vec3OrFloat): Node<"vec3">; + (low: Vec4OrFloat, high: Vec4OrFloat, x: Vec4OrFloat): Node<"vec4">; } export const smoothstep: Smoothstep; interface FaceForward { - (N: Vec2OrLessOrFloat, I: Vec2OrLessOrFloat, Nref: Vec2OrLessOrFloat): Node<"vec2">; - (N: Vec3OrLessOrFloat, I: Vec3OrLessOrFloat, Nref: Vec3OrLessOrFloat): Node<"vec3">; - (N: Vec4OrLessOrFloat, I: Vec4OrLessOrFloat, Nref: Vec4OrLessOrFloat): Node<"vec4">; + (N: Vec2OrFloat, I: Vec2OrFloat, Nref: Vec2OrFloat): Node<"vec2">; + (N: Vec3OrFloat, I: Vec3OrFloat, Nref: Vec3OrFloat): Node<"vec3">; + (N: Vec4OrFloat, I: Vec4OrFloat, Nref: Vec4OrFloat): Node<"vec4">; } export const faceForward: FaceForward; interface FaceForwardVec2Extension { - (I: Vec2OrLessOrFloat, Nref: Vec2OrLessOrFloat): Node<"vec2">; - (I: Vec3OrLessOrFloat, Nref: Vec3OrLessOrFloat): Node<"vec3">; - (I: Vec4OrLessOrFloat, Nref: Vec4OrLessOrFloat): Node<"vec4">; + (I: Vec2OrFloat, Nref: Vec2OrFloat): Node<"vec2">; } interface FaceForwardVec3Extension { - (N: Vec3OrLessOrFloat, ratio: Vec3OrLessOrFloat): Node<"vec3">; - (N: Vec4OrLessOrFloat, ratio: Vec4OrLessOrFloat): Node<"vec4">; + (N: Vec3OrFloat, ratio: Vec3OrFloat): Node<"vec3">; } interface FaceForwardVec4Extension { - (N: Vec4OrLessOrFloat, ratio: Vec4OrLessOrFloat): Node<"vec4">; + (N: Vec4OrFloat, ratio: Vec4OrFloat): Node<"vec4">; } declare module "../core/Node.js" { interface Vec2Extensions { @@ -787,7 +805,7 @@ declare module "../core/Node.js" { } } -export const rand: (uv: Node<"vec2">) => Node<"float">; +export const rand: (uv: Vec2) => Node<"float">; declare module "../core/Node.js" { interface Vec2Extensions { rand: () => Node<"float">; @@ -796,16 +814,16 @@ declare module "../core/Node.js" { interface MixElement { (t: FloatOrNumber, e1: FloatOrNumber, e2: FloatOrNumber): Node<"float">; - (t: FloatOrNumber, e1: Vec2OrLessOrFloat, e2: Vec2OrLessOrFloat): Node<"vec2">; - (t: FloatOrNumber, e1: Vec3OrLessOrFloat | Node<"color">, e2: Vec3OrLessOrFloat | Node<"color">): Node<"vec3">; - (t: FloatOrNumber, e1: Vec4OrLessOrFloat, e2: Vec4OrLessOrFloat): Node<"vec4">; + (t: FloatOrNumber, e1: Vec2OrFloat, e2: Vec2OrFloat): Node<"vec2">; + (t: FloatOrNumber, e1: Vec3OrFloat, e2: Vec3OrFloat): Node<"vec3">; + (t: FloatOrNumber, e1: Vec4OrFloat | Vec3, e2: Vec4OrFloat | Vec3): Node<"vec4">; } export const mixElement: MixElement; interface MixExtension { (e1: FloatOrNumber, e2: FloatOrNumber): Node<"float">; - (e1: Vec2OrLessOrFloat, e2: Vec2OrLessOrFloat): Node<"vec2">; - (e1: Vec3OrLessOrFloat | Node<"color">, e2: Vec3OrLessOrFloat | Node<"color">): Node<"vec3">; - (e1: Vec4OrLessOrFloat | Node<"color">, e2: Vec4OrLessOrFloat | Node<"color">): Node<"vec4">; + (e1: Vec2OrFloat, e2: Vec2OrFloat): Node<"vec2">; + (e1: Vec3OrFloat, e2: Vec3OrFloat): Node<"vec3">; + (e1: Vec4OrFloat | Vec3, e2: Vec4OrFloat | Vec3): Node<"vec4">; } declare module "../core/Node.js" { interface FloatExtensions { @@ -815,22 +833,58 @@ declare module "../core/Node.js" { interface SmoothstepElement { (x: FloatOrNumber, low: FloatOrNumber, high: FloatOrNumber): Node<"float">; + (x: Vec2OrFloat, low: Vec2OrFloat, high: Vec2OrFloat): Node<"vec2">; + (x: Vec3OrFloat, low: Vec3OrFloat, high: Vec3OrFloat): Node<"vec3">; + (x: Vec4OrFloat, low: Vec4OrFloat, high: Vec4OrFloat): Node<"vec4">; } export const smoothstepElement: SmoothstepElement; -interface SmoothstepExtension { +interface SmoothstepFloatExtension { (low: FloatOrNumber, high: FloatOrNumber): Node<"float">; } +interface SmoothstepVec2Extension { + (low: Vec2OrFloat, high: Vec2OrFloat): Node<"vec2">; +} +interface SmoothstepVec3Extension { + (low: Vec3OrFloat, high: Vec3OrFloat): Node<"vec3">; +} +interface SmoothstepVec4Extension { + (low: Vec4OrFloat, high: Vec4OrFloat): Node<"vec4">; +} declare module "../core/Node.js" { interface FloatExtensions { - smoothstep: SmoothstepExtension; + smoothstep: SmoothstepFloatExtension; + } + interface Vec2Extensions { + smoothstep: SmoothstepVec2Extension; + } + interface Vec3Extensions { + smoothstep: SmoothstepVec3Extension; + } + interface Vec4Extensions { + smoothstep: SmoothstepVec4Extension; } } -export const stepElement: (x: FloatOrNumber, edge: FloatOrNumber) => Node<"float">; +interface StepElement { + (x: FloatOrNumber, edge: FloatOrNumber): Node<"float">; + (x: Vec2OrFloat, edge: Vec2OrFloat): Node<"vec2">; + (x: Vec3OrFloat, edge: Vec3OrFloat): Node<"vec3">; + (x: Vec4OrFloat, edge: Vec4OrFloat): Node<"vec4">; +} +export const stepElement: StepElement; declare module "../core/Node.js" { interface FloatExtensions { step: (edge: FloatOrNumber) => Node<"float">; } + interface Vec2Extensions { + step: (edge: Vec2OrFloat) => Node<"vec2">; + } + interface Vec3Extensions { + step: (edge: Vec3OrFloat) => Node<"vec3">; + } + interface Vec4Extensions { + step: (edge: Vec4OrFloat) => Node<"vec4">; + } } // GLSL alias function diff --git a/types/three/src/nodes/math/OperatorNode.d.ts b/types/three/src/nodes/math/OperatorNode.d.ts index 3aae9a650e2932..b15b69d536e916 100644 --- a/types/three/src/nodes/math/OperatorNode.d.ts +++ b/types/three/src/nodes/math/OperatorNode.d.ts @@ -1,3 +1,10 @@ +import { Color } from "../../math/Color.js"; +import { Matrix2 } from "../../math/Matrix2.js"; +import { Matrix3 } from "../../math/Matrix3.js"; +import { Matrix4 } from "../../math/Matrix4.js"; +import { Vector2 } from "../../math/Vector2.js"; +import { Vector3 } from "../../math/Vector3.js"; +import { Vector4 } from "../../math/Vector4.js"; import Node, { IntegerType, NumType } from "../core/Node.js"; import TempNode from "../core/TempNode.js"; @@ -32,9 +39,27 @@ export default class OperatorNode extends TempNode { constructor(op: OperatorNodeOp, ...params: [Node, Node, ...Node[]]); } -type Vec2OrLess = Node<"vec2">; -type Vec3OrLess = Vec2OrLess | Node<"vec3">; -type Vec4OrLess = Vec3OrLess | Node<"vec4">; +type FloatOrNumber = Node<"float"> | number; + +type AnyNumber = Node<"float"> | Node<"int"> | Node<"uint"> | number; + +type Vec2 = Node<"vec2"> | Vector2; +type Vec3 = Node<"vec3"> | Vector3 | Node<"color"> | Color; +type Vec4 = Node<"vec4"> | Vector4; + +type Vec2OrFloat = Vec2 | FloatOrNumber; +type Vec3OrFloat = Vec3 | FloatOrNumber; +type Vec4OrFloat = Vec4 | FloatOrNumber; + +type Vec2OrLess = Vec2; +type Vec3OrLess = Vec2OrLess | Vec3; +type Vec4OrLess = Vec3OrLess | Vec4; + +type Mat2 = Node<"mat2"> | Matrix2; +type Mat3 = Node<"mat3"> | Matrix3; +type Mat4 = Node<"mat4"> | Matrix4; + +type Bool = Node<"bool"> | boolean; interface NumberToVec { float: "vec"; @@ -46,122 +71,221 @@ type NumberToVec2 = `${NumberToVec[TNum]}2`; type NumberToVec3 = `${NumberToVec[TNum]}3`; type NumberToVec4 = `${NumberToVec[TNum]}4`; -type Number = AnyNumber; // FIXME Number | number +type Number = Node | number; type Vec2OrLessOrNumber = Number | Node>; type Vec3OrLessOrNumber = Vec2OrLessOrNumber | Node>; type Vec4OrLessOrNumber = Vec3OrLessOrNumber | Node>; -type AnyNumber = Node<"float"> | Node<"int"> | Node<"uint"> | number; +interface NodeParameterForNumType { + float: Node<"float"> | Node<"int"> | Node<"uint">; + int: Node<"int">; + uint: Node<"uint">; +} +type NumberParameterForNumType = NodeParameterForNumType[TNum] | number; + +interface Vec2NodeParameterForNumType { + float: Node<"vec2"> | Node<"ivec2"> | Node<"uvec2">; + int: Node<"ivec2">; + uint: Node<"uvec2">; +} +type Vec2OrLessOrNumberParameterForNumType = + | Vec2NodeParameterForNumType[TNum] + | NumberParameterForNumType; + +interface Vec3NodeParameterForNumType { + float: Node<"vec3"> | Node<"ivec3"> | Node<"uvec3">; + int: Node<"ivec3">; + uint: Node<"uvec3">; +} +type Vec3OrLessOrNumberParameterForNumType = + | Vec3NodeParameterForNumType[TNum] + | Vec2OrLessOrNumberParameterForNumType; + +interface Vec4NodeParameterForNumType { + float: Node<"vec4"> | Node<"ivec4"> | Node<"uvec4">; + int: Node<"ivec4">; + uint: Node<"uvec4">; +} +type Vec4OrLessOrNumberParameterForNumType = + | Vec4NodeParameterForNumType[TNum] + | Vec3OrLessOrNumberParameterForNumType; // add/sub/mul/div // add/sub/mul/div numbers and/or vecs // Every parameter gets converted to the longest type // If the parameters are the same length, it gets converted to the first type -// FIXME We handle the case of converting number types, but not converting between vectors of different number types interface AddSubMulDivNumberVec { - (a: Number, b: AnyNumber, ...params: AnyNumber[]): Node; + (a: Number, b: NumberParameterForNumType, ...params: NumberParameterForNumType[]): Node; ( a: Vec2OrLessOrNumber, - b: Vec2OrLessOrNumber, - ...params: Vec2OrLessOrNumber[] + b: Vec2OrLessOrNumberParameterForNumType, + ...params: Vec2OrLessOrNumberParameterForNumType[] ): Node>; ( a: Vec3OrLessOrNumber, - b: Vec3OrLessOrNumber, - ...params: Vec3OrLessOrNumber[] + b: Vec3OrLessOrNumberParameterForNumType, + ...params: Vec3OrLessOrNumberParameterForNumType[] ): Node>; ( a: Vec4OrLessOrNumber, - b: Vec4OrLessOrNumber, - ...params: Vec4OrLessOrNumber[] + b: Vec4OrLessOrNumberParameterForNumType, + ...params: Vec4OrLessOrNumberParameterForNumType[] ): Node>; } interface AddSubMulDivNumberVecNumExtensions { - (b: AnyNumber, ...params: AnyNumber[]): Node; - (b: Vec2OrLessOrNumber, ...params: Vec2OrLessOrNumber[]): Node>; - (b: Vec3OrLessOrNumber, ...params: Vec3OrLessOrNumber[]): Node>; - (b: Vec4OrLessOrNumber, ...params: Vec4OrLessOrNumber[]): Node>; + (b: NumberParameterForNumType, ...params: NumberParameterForNumType[]): Node; + ( + b: Vec2OrLessOrNumberParameterForNumType, + ...params: Vec2OrLessOrNumberParameterForNumType[] + ): Node>; + ( + b: Vec3OrLessOrNumberParameterForNumType, + ...params: Vec3OrLessOrNumberParameterForNumType[] + ): Node>; + ( + b: Vec4OrLessOrNumberParameterForNumType, + ...params: Vec4OrLessOrNumberParameterForNumType[] + ): Node>; } -interface AddSubMulDivNumberVecNumberAssignExtensions { +interface AddSubMulDivNumberVecNumberAssignExtensions { ( - b: Vec4OrLessOrNumber<"float"> | Vec4OrLessOrNumber<"int"> | Vec4OrLessOrNumber<"uint">, - ...params: (Vec4OrLessOrNumber<"float"> | Vec4OrLessOrNumber<"int"> | Vec4OrLessOrNumber<"uint">)[] + b: Vec4OrLessOrNumberParameterForNumType, + ...params: Vec4OrLessOrNumberParameterForNumType[] ): this; } interface AddSubMulDivNumberVecVec2Extensions { - (b: Vec2OrLessOrNumber, ...params: Vec2OrLessOrNumber[]): Node>; - (b: Vec3OrLessOrNumber, ...params: Vec3OrLessOrNumber[]): Node>; - (b: Vec4OrLessOrNumber, ...params: Vec4OrLessOrNumber[]): Node>; + ( + b: Vec2OrLessOrNumberParameterForNumType, + ...params: Vec2OrLessOrNumberParameterForNumType[] + ): Node>; + ( + b: Vec3OrLessOrNumberParameterForNumType, + ...params: Vec3OrLessOrNumberParameterForNumType[] + ): Node>; + ( + b: Vec4OrLessOrNumberParameterForNumType, + ...params: Vec4OrLessOrNumberParameterForNumType[] + ): Node>; } interface AddSubMulDivNumberVecVec2AssignExtensions { - (b: Vec4OrLessOrNumber, ...params: Vec4OrLessOrNumber[]): this; + (b: Vec4OrLessOrNumberParameterForNumType, ...params: Vec4OrLessOrNumberParameterForNumType[]): this; } interface AddSubMulDivNumberVecVec3Extensions { - (b: Vec3OrLessOrNumber, ...params: Vec3OrLessOrNumber[]): Node>; - (b: Vec4OrLessOrNumber, ...params: Vec4OrLessOrNumber[]): Node>; + ( + b: Vec3OrLessOrNumberParameterForNumType, + ...params: Vec3OrLessOrNumberParameterForNumType[] + ): Node>; + ( + b: Vec4OrLessOrNumberParameterForNumType, + ...params: Vec4OrLessOrNumberParameterForNumType[] + ): Node>; } interface AddSubMulDivNumberVecVec3AssignExtensions { - (b: Vec4OrLessOrNumber, ...params: Vec4OrLessOrNumber[]): this; + (b: Vec4OrLessOrNumberParameterForNumType, ...params: Vec4OrLessOrNumberParameterForNumType[]): this; } interface AddSubMulDivNumberVecVec4Extensions { - (b: Vec4OrLessOrNumber, ...params: Vec4OrLessOrNumber[]): Node>; + ( + b: Vec4OrLessOrNumberParameterForNumType, + ...params: Vec4OrLessOrNumberParameterForNumType[] + ): Node>; } interface AddSubMulDivNumberVecVec4AssignExtensions { - (b: Vec4OrLessOrNumber, ...params: Vec4OrLessOrNumber[]): this; + (b: Vec4OrLessOrNumberParameterForNumType, ...params: Vec4OrLessOrNumberParameterForNumType[]): this; } // add/sub/mul mats interface AddSubMulMat { - (a: Node<"mat2">, b: Node<"mat2">): Node<"mat2">; - (a: Node<"mat3">, b: Node<"mat3">): Node<"mat3">; - (a: Node<"mat4">, b: Node<"mat4">): Node<"mat4">; + (a: Mat2, b: Mat2, ...params: Mat2[]): Node<"mat2">; + (a: Mat3, b: Mat3, ...params: Mat3[]): Node<"mat3">; + (a: Mat4, b: Mat4, ...params: Mat4[]): Node<"mat4">; } interface AddSubMulMat2Extensions { - (b: Node<"mat2">): Node<"mat2">; + (b: Mat2): Node<"mat2">; } interface AddSubMulMat2AssignExtensions { - (b: Node<"mat2">): this; + (b: Mat2): this; } interface AddSubMulMat3Extensions { - (b: Node<"mat3">): Node<"mat3">; + (b: Mat3): Node<"mat3">; } interface AddSubMulMat3AssignExtensions { - (b: Node<"mat3">): this; + (b: Mat3): this; } interface AddSubMulMat4Extensions { - (b: Node<"mat4">): Node<"mat4">; + (b: Mat4): Node<"mat4">; } interface AddSubMulMat4AssignExtensions { - (b: Node<"mat3">): this; + (b: Mat3): this; +} + +// mut mats and nums + +interface MulMatNum { + (a: Mat2, b: AnyNumber): Node<"mat2">; + (a: Mat3, b: AnyNumber): Node<"mat3">; + (a: Mat4, b: AnyNumber): Node<"mat4">; + (a: AnyNumber, b: Mat2): Node<"mat2">; + (a: AnyNumber, b: Mat3): Node<"mat3">; + (a: AnyNumber, b: Mat4): Node<"mat4">; +} + +interface MulMatNumNumExtensions { + (b: Mat2): Node<"mat2">; + (b: Mat3): Node<"mat3">; + (b: Mat4): Node<"mat4">; +} + +interface MulMatNumMat2Extensions { + (b: AnyNumber): Node<"mat2">; +} + +interface MulMatNumMat3Extensions { + (b: AnyNumber): Node<"mat3">; +} + +interface MulMatNumMat4Extensions { + (b: AnyNumber): Node<"mat4">; +} + +interface MulMatNumMat2AssignExtensions { + (b: AnyNumber): this; +} + +interface MulMatNumMat3AssignExtensions { + (b: AnyNumber): this; +} + +interface MulMatNumMat4AssignExtensions { + (b: AnyNumber): this; } // mut mats and vecs // The vec parameter gets converted to matrix length interface MulMatVec { - (a: Node<"mat2">, b: Vec4OrLess): Node<"vec2">; - (a: Node<"mat3">, b: Vec4OrLess): Node<"vec3">; - (a: Node<"mat4">, b: Vec4OrLess): Node<"vec4">; - (a: Vec4OrLess, b: Node<"mat2">): Node<"vec2">; - (a: Vec4OrLess, b: Node<"mat3">): Node<"vec3">; - (a: Vec4OrLess, b: Node<"mat4">): Node<"vec4">; + (a: Mat2, b: Vec4OrLess): Node<"vec2">; + (a: Mat3, b: Vec4OrLess): Node<"vec3">; + (a: Mat4, b: Vec4OrLess): Node<"vec4">; + (a: Vec4OrLess, b: Mat2): Node<"vec2">; + (a: Vec4OrLess, b: Mat3): Node<"vec3">; + (a: Vec4OrLess, b: Mat4): Node<"vec4">; } interface MulVecMatMat2Extensions { @@ -177,9 +301,9 @@ interface MulVecMatMat4Extensions { } interface MulVecMatVecExtensions { - (b: Node<"mat2">): Node<"vec2">; - (b: Node<"mat3">): Node<"vec3">; - (b: Node<"mat4">): Node<"vec4">; + (b: Mat2): Node<"vec2">; + (b: Mat3): Node<"vec3">; + (b: Mat4): Node<"vec4">; } // Exports @@ -197,10 +321,16 @@ interface Mul AddSubMulDivNumberVec<"int">, AddSubMulDivNumberVec<"uint">, AddSubMulMat, + MulMatNum, MulMatVec { } +interface MulNumExtension + extends AddSubMulDivNumberVecNumExtensions, MulMatNumNumExtensions +{ +} + interface MulVec2Extensions extends AddSubMulDivNumberVecVec2Extensions, MulVecMatVecExtensions { @@ -216,13 +346,22 @@ interface MulVec4Extensions { } -interface MulMat2Extensions extends AddSubMulMat2Extensions, MulVecMatMat2Extensions { +interface MulMat2Extensions extends AddSubMulMat2Extensions, MulMatNumMat2Extensions, MulVecMatMat2Extensions { +} + +interface MulMat3Extensions extends AddSubMulMat3Extensions, MulMatNumMat3Extensions, MulVecMatMat3Extensions { +} + +interface MulMat4Extensions extends AddSubMulMat4Extensions, MulMatNumMat4Extensions, MulVecMatMat4Extensions { +} + +interface MulMat2AssignExtensions extends AddSubMulMat2AssignExtensions, MulMatNumMat2AssignExtensions { } -interface MulMat3Extensions extends AddSubMulMat3Extensions, MulVecMatMat3Extensions { +interface MulMat3AssignExtensions extends AddSubMulMat3AssignExtensions, MulMatNumMat3AssignExtensions { } -interface MulMat4Extensions extends AddSubMulMat4Extensions, MulVecMatMat4Extensions { +interface MulMat4AssignExtensions extends AddSubMulMat4AssignExtensions, MulMatNumMat4AssignExtensions { } export const mul: Mul; @@ -239,13 +378,13 @@ declare module "../core/Node.js" { interface NumExtensions { add: AddSubMulDivNumberVecNumExtensions; sub: AddSubMulDivNumberVecNumExtensions; - mul: AddSubMulDivNumberVecNumExtensions; + mul: MulNumExtension; div: AddSubMulDivNumberVecNumExtensions; - addAssign: AddSubMulDivNumberVecNumberAssignExtensions; - subAssign: AddSubMulDivNumberVecNumberAssignExtensions; - mulAssign: AddSubMulDivNumberVecNumberAssignExtensions; - divAssign: AddSubMulDivNumberVecNumberAssignExtensions; + addAssign: AddSubMulDivNumberVecNumberAssignExtensions; + subAssign: AddSubMulDivNumberVecNumberAssignExtensions; + mulAssign: AddSubMulDivNumberVecNumberAssignExtensions; + divAssign: AddSubMulDivNumberVecNumberAssignExtensions; } interface Vec2Extensions { @@ -313,7 +452,7 @@ declare module "../core/Node.js" { addAssign: AddSubMulMat2AssignExtensions; subAssign: AddSubMulMat2AssignExtensions; - mulAssign: AddSubMulMat2AssignExtensions; + mulAssign: MulMat2AssignExtensions; } interface Mat3Extensions { @@ -323,7 +462,7 @@ declare module "../core/Node.js" { addAssign: AddSubMulMat3AssignExtensions; subAssign: AddSubMulMat3AssignExtensions; - mulAssign: AddSubMulMat3AssignExtensions; + mulAssign: MulMat3AssignExtensions; } interface Mat4Extensions { @@ -333,7 +472,7 @@ declare module "../core/Node.js" { addAssign: AddSubMulMat4AssignExtensions; subAssign: AddSubMulMat4AssignExtensions; - mulAssign: AddSubMulMat4AssignExtensions; + mulAssign: MulMat4AssignExtensions; } } @@ -382,6 +521,10 @@ declare module "../core/Node.js" { interface ComparisonOperator { (a: Number<"float">, b: Number<"float">): Node<"bool">; (a: Number<"int"> | Number<"uint">, b: Number<"int"> | Number<"uint">): Node<"bool">; + // TODO Accept non-float vectors + (a: Vec2OrFloat, b: Vec2OrFloat): Node<"bvec2">; + (a: Vec3OrFloat, b: Vec3OrFloat): Node<"bvec3">; + (a: Vec4OrFloat, b: Vec4OrFloat): Node<"bvec4">; } export const equal: ComparisonOperator; export const notEqual: ComparisonOperator; @@ -393,6 +536,15 @@ export const greaterThanEqual: ComparisonOperator; interface ComparisonOperatorNumExtensions { (b: Number): Node<"bool">; } +interface ComparisonOperatorVec2Extensions { + (b: Vec2OrFloat): Node<"bvec2">; +} +interface ComparisonOperatorVec3Extensions { + (b: Vec3OrFloat): Node<"bvec3">; +} +interface ComparisonOperatorVec4Extensions { + (b: Vec4OrFloat): Node<"bvec4">; +} declare module "../core/Node.js" { interface FloatExtensions { @@ -421,29 +573,66 @@ declare module "../core/Node.js" { lessThanEqual: (b: Number<"int"> | Number<"uint">) => Node<"bool">; greaterThanEqual: (b: Number<"int"> | Number<"uint">) => Node<"bool">; } + + interface Vec2Extensions { + equal: ComparisonOperatorVec2Extensions; + notEqual: ComparisonOperatorVec2Extensions; + lessThan: ComparisonOperatorVec2Extensions; + greaterThan: ComparisonOperatorVec2Extensions; + lessThanEqual: ComparisonOperatorVec2Extensions; + greaterThanEqual: ComparisonOperatorVec2Extensions; + } + + interface Vec3Extensions { + equal: ComparisonOperatorVec3Extensions; + notEqual: ComparisonOperatorVec3Extensions; + lessThan: ComparisonOperatorVec3Extensions; + greaterThan: ComparisonOperatorVec3Extensions; + lessThanEqual: ComparisonOperatorVec3Extensions; + greaterThanEqual: ComparisonOperatorVec3Extensions; + } + + interface Vec4Extensions { + equal: ComparisonOperatorVec4Extensions; + notEqual: ComparisonOperatorVec4Extensions; + lessThan: ComparisonOperatorVec4Extensions; + greaterThan: ComparisonOperatorVec4Extensions; + lessThanEqual: ComparisonOperatorVec4Extensions; + greaterThanEqual: ComparisonOperatorVec4Extensions; + } } // and/or/not/xor interface AndOr { - (a: Node<"bool">, b: Node<"bool">, ...params: Node<"bool">[]): Node<"bool">; + (a: Bool, b: Bool, ...params: Bool[]): Node<"bool">; } export const and: AndOr; export const or: AndOr; interface AndOrBoolExtensions { - (b: Node<"bool">, ...params: Node<"bool">[]): Node<"bool">; + (b: Bool, ...params: Bool[]): Node<"bool">; } -export const not: (a: Node<"bool">) => Node<"bool">; -export const xor: (a: Node<"bool">, b: Node<"bool">) => Node<"bool">; +interface NotFunction { + (a: Bool): Node<"bool">; + (a: Node<"bvec2">): Node<"bvec2">; + (a: Node<"bvec3">): Node<"bvec3">; + (a: Node<"bvec4">): Node<"bvec4">; +} +export const not: NotFunction; + +export const xor: (a: Bool, b: Bool) => Node<"bool">; declare module "../core/Node.js" { interface BoolExtensions { and: AndOrBoolExtensions; or: AndOrBoolExtensions; - not: () => Node<"bool">; - xor: (b: Node<"bool">) => Node<"bool">; + xor: (b: Bool) => Node<"bool">; + } + + interface BoolOrVecExtensions { + not: () => Node; } } @@ -517,22 +706,4 @@ declare module "../core/Node.js" { } } -/** - * @deprecated "modInt()" is deprecated. Use "mod( int( ... ) )" instead. - */ -export const modInt: Mod; - -declare module "../core/Node.js" { - interface NumExtensions { - /** - * @deprecated "modInt()" is deprecated. Use "mod( int( ... ) )" instead. - */ - modInt: (b: Number) => Node; - /** - * @deprecated "modInt()" is deprecated. Use "mod( int( ... ) )" instead. - */ - modIntAssign: (b: Number) => this; - } -} - export {}; diff --git a/types/three/src/nodes/tsl/TSLCore.d.ts b/types/three/src/nodes/tsl/TSLCore.d.ts index 61edb02287e644..ca0b09f290b8ac 100644 --- a/types/three/src/nodes/tsl/TSLCore.d.ts +++ b/types/three/src/nodes/tsl/TSLCore.d.ts @@ -5,11 +5,13 @@ import { Matrix4 } from "../../math/Matrix4.js"; import { Vector2 } from "../../math/Vector2.js"; import { Vector3 } from "../../math/Vector3.js"; import { Vector4 } from "../../math/Vector4.js"; +import ArrayNode from "../core/ArrayNode.js"; import ConstNode from "../core/ConstNode.js"; -import Node, { MatType, NumOrBoolType } from "../core/Node.js"; +import Node, { NumOrBoolType } from "../core/Node.js"; import NodeBuilder from "../core/NodeBuilder.js"; import StackNode from "../core/StackNode.js"; import VarNode from "../core/VarNode.js"; +import ArrayElementNode from "../utils/ArrayElementNode.js"; import ConvertNode from "../utils/ConvertNode.js"; import JoinNode from "../utils/JoinNode.js"; @@ -1743,6 +1745,8 @@ export function nodeProxyIntent>( factor: unknown, ): (...params: ProxiedTuple>>) => ConstructedNode; +export const nodeProxyConstructor: unknown; + interface FullLayout { name: string; type: string; @@ -1977,7 +1981,9 @@ interface Vec3Function { (value: Vector3): VarNode<"vec3", ConstNode<"vec3", Vector3>>; // ConvertNode (node: ScalarNode): VarNode<"vec3", ConvertNode<"vec3">>; - (node: Node<"vec3"> | Node<"ivec3"> | Node<"uvec3"> | Node<"bvec3">): VarNode<"vec3", ConvertNode<"vec3">>; + ( + node: Node<"vec3"> | Node<"ivec3"> | Node<"uvec3"> | Node<"bvec3"> | Node<"vec4">, + ): VarNode<"vec3", ConvertNode<"vec3">>; // The fall-through branch will be triggered if there is more than one parameter, and one of the parameters is an // object @@ -2082,7 +2088,7 @@ interface Vec4Function { (x: Scalar, y: Scalar, zw: Node<"vec2"> | Vector2): VarNode<"vec4", JoinNode<"vec4">>; (xy: Node<"vec2"> | Vector2, zw: Node<"vec2"> | Vector2): VarNode<"vec4", JoinNode<"vec4">>; (xy: Node<"vec2"> | Vector2, z: Scalar, w: Scalar): VarNode<"vec4", JoinNode<"vec4">>; - (xyz: Node<"vec3"> | Node<"color"> | Vector3 | Color, w: Scalar): VarNode<"vec4", JoinNode<"vec4">>; + (xyz: Node<"vec3"> | Node<"color"> | Vector3 | Color | Node<"vec4">, w: Scalar): VarNode<"vec4", JoinNode<"vec4">>; (x: Scalar, yzw: Node<"vec3"> | Node<"color"> | Vector3 | Color): VarNode<"vec4", JoinNode<"vec4">>; } @@ -2354,9 +2360,6 @@ interface Mat4Function { export const mat4: Mat4Function; -export const string: unknown; -export const arrayBuffer: unknown; - declare module "../core/Node.js" { interface ColorExtensions { toColor: () => VarNode<"color", ConvertNode<"color">>; @@ -2398,14 +2401,18 @@ declare module "../core/Node.js" { } } -export const element: (node: Node, indexNode: Node) => Node; +export const element: (node: ArrayNode, indexNode: Node | number) => ArrayElementNode; export const convert: (node: Node, types: string) => Node; export const split: (node: Node, channels?: string) => Node; +declare module "../core/ArrayNode.js" { + interface ArrayNodeInterface { + element: (indexNode: Node | number) => ArrayElementNode; + } +} + declare module "../core/Node.js" { interface NodeElements { - element: (indexNode: Node) => Node; - convert: (types: string) => Node; } } diff --git a/types/three/src/nodes/utils/ArrayElementNode.d.ts b/types/three/src/nodes/utils/ArrayElementNode.d.ts index b93aa33802f8d2..334be5ad2d98c3 100644 --- a/types/three/src/nodes/utils/ArrayElementNode.d.ts +++ b/types/three/src/nodes/utils/ArrayElementNode.d.ts @@ -1,14 +1,15 @@ +import ArrayNode from "../core/ArrayNode.js"; import Node from "../core/Node.js"; -interface ArrayElementNodeInterface { - node: Node; +interface ArrayElementNodeInterface { + node: ArrayNode; indexNode: Node; } declare const ArrayElementNode: { - new(node: Node, indexNode: Node): ArrayElementNode; + new(node: ArrayNode, indexNode: Node): ArrayElementNode; }; -type ArrayElementNode = Node & ArrayElementNodeInterface; +type ArrayElementNode = Node & ArrayElementNodeInterface; export default ArrayElementNode; diff --git a/types/three/src/nodes/utils/EquirectUV.d.ts b/types/three/src/nodes/utils/EquirectUV.d.ts index 1107bf8d0233da..33fd196c9581e5 100644 --- a/types/three/src/nodes/utils/EquirectUV.d.ts +++ b/types/three/src/nodes/utils/EquirectUV.d.ts @@ -1,3 +1,33 @@ +import { Vector2 } from "../../math/Vector2.js"; +import { Vector3 } from "../../math/Vector3.js"; import Node from "../core/Node.js"; -export const equirectUV: (dirNode?: Node) => Node; +/** + * TSL function for creating an equirect uv node. + * + * Can be used to compute texture coordinates for projecting an + * equirectangular texture onto a mesh for using it as the scene's + * background. + * + * ```js + * scene.backgroundNode = texture( equirectTexture, equirectUV() ); + * ``` + * + * @tsl + * @function + * @param {?Node} [direction=positionWorldDirection] - A direction vector for sampling which is by default `positionWorldDirection`. + * @returns {Node} + */ +export const equirectUV: (direction?: Node<"vec3"> | Vector3) => Node<"vec2">; +/** + * TSL function for creating an equirect direction node. + * + * Can be used to compute a direction vector from the given equirectangular + * UV coordinates. + * + * @tsl + * @function + * @param {?Node} [uv=UV()] - The equirectangular UV coordinates. + * @returns {Node} The computed direction vector. + */ +export const equirectDirection: (uv?: Node<"vec2"> | Vector2) => Node<"vec3">; diff --git a/types/three/src/nodes/utils/Packing.d.ts b/types/three/src/nodes/utils/Packing.d.ts index 91b1b3fcde917a..715e29cd38658a 100644 --- a/types/three/src/nodes/utils/Packing.d.ts +++ b/types/three/src/nodes/utils/Packing.d.ts @@ -1,5 +1,52 @@ +import { Vector2 } from "../../math/Vector2.js"; +import { Vector3 } from "../../math/Vector3.js"; import Node from "../core/Node.js"; -export const directionToColor: (node: Node) => Node<"vec3">; -export const colorToDirection: (node: Node) => Node<"vec3">; -export const unpackNormal: (xy: Node) => Node<"vec3">; +/** + * Packs a normal vector into a color value. + * + * @tsl + * @function + * @param {Node} node - The direction to pack. + * @return {Node} The color. + */ +export const packNormalToRGB: (node: Node<"vec3"> | Vector3) => Node<"vec3">; + +/** + * Unpacks a color value into a normal vector. + * + * @tsl + * @function + * @param {Node} node - The color to unpack. + * @return {Node} The direction. + */ +export const unpackRGBToNormal: (node: Node<"vec3"> | Node<"vec4"> | Vector3) => Node<"vec3">; + +/** + * Unpacks a tangent space normal, reconstructing the Z component by projecting the X,Y coordinates onto the hemisphere. + * The X,Y coordinates are expected to be in the [-1, 1] range. + * + * @tsl + * @function + * @param {Node} xy - The X,Y coordinates of the normal. + * @return {Node} The resulting normal. + */ +export const unpackNormal: (xy: Node<"vec2"> | Vector2) => Node<"vec3">; + +/** + * @tsl + * @function + * @deprecated since r185. Use {@link packNormalToRGB} instead. + * @param {Node} node - The direction to pack. + * @returns {Node} + */ +export const directionToColor: (node: Node<"vec3"> | Vector3) => Node<"vec3">; + +/** + * @tsl + * @function + * @deprecated since r185. Use {@link unpackRGBToNormal} instead. + * @param {Node} node - The color to unpack. + * @returns {Node} + */ +export const colorToDirection: (node: Node<"vec3"> | Node<"vec4"> | Vector3) => Node<"vec3">; diff --git a/types/three/src/nodes/utils/RTTNode.d.ts b/types/three/src/nodes/utils/RTTNode.d.ts index 11b91bcca94f01..6d12d2dfce60ce 100644 --- a/types/three/src/nodes/utils/RTTNode.d.ts +++ b/types/three/src/nodes/utils/RTTNode.d.ts @@ -1,12 +1,7 @@ -import { TextureDataType } from "../../constants.js"; -import { RenderTarget } from "../../core/RenderTarget.js"; +import { RenderTarget, RenderTargetOptions } from "../../core/RenderTarget.js"; import TextureNode from "../accessors/TextureNode.js"; import Node from "../core/Node.js"; -export interface RTTNodeOptions { - type: TextureDataType; -} - declare class RTTNode extends TextureNode { readonly isRTTNode: true; @@ -19,15 +14,15 @@ declare class RTTNode extends TextureNode { textureNeedsUpdate: boolean; autoUpdate: boolean; - pixelRatio?: number; - - constructor(node: Node, width?: number | null, height?: number | null, options?: RTTNodeOptions); + constructor(node: Node, width?: number | null, height?: number | null, options?: RenderTargetOptions); get autoResize(): boolean; setSize(width: number | null, height: number | null): void; - setPixelRatio(pixelRatio: number): void; + setResolutionScale(resolutionScale: number): this; + + getResolutionScale(): number; } export default RTTNode; @@ -36,11 +31,11 @@ export const rtt: ( node: Node, width?: number | null, height?: number | null, - options?: RTTNodeOptions, + options?: RenderTargetOptions, ) => RTTNode; export const convertToTexture: ( node: Node, width?: number | null, height?: number | null, - options?: RTTNodeOptions, + options?: RenderTargetOptions, ) => RTTNode; diff --git a/types/three/src/nodes/utils/Remap.d.ts b/types/three/src/nodes/utils/Remap.d.ts index c863be94bd1f60..bb592c8439c7fe 100644 --- a/types/three/src/nodes/utils/Remap.d.ts +++ b/types/three/src/nodes/utils/Remap.d.ts @@ -1,36 +1,223 @@ +import { Color } from "../../math/Color.js"; +import { Vector2 } from "../../math/Vector2.js"; +import { Vector3 } from "../../math/Vector3.js"; +import { Vector4 } from "../../math/Vector4.js"; import Node from "../core/Node.js"; -export const remap: ( - node: Node<"float">, - inLowNode: Node<"float"> | number, - inHighNode: Node<"float"> | number, - outLowNode?: Node<"float"> | number, - outHighNode?: Node<"float"> | number, - doClamp?: Node<"bool"> | boolean, -) => Node<"float">; -export const remapClamp: ( - node: Node<"float">, - inLowNode: Node<"float"> | number, - inHighNode: Node<"float"> | number, - outLowNode?: Node<"float"> | number, - outHighNode?: Node<"float"> | number, -) => Node<"float">; +type FloatOrNumber = Node<"float"> | number; +type Boolean = Node<"bool"> | boolean; + +type Vec2 = Node<"vec2"> | Vector2; +type Vec3 = Node<"vec3"> | Vector3 | Node<"color"> | Color; +type Vec4 = Node<"vec4"> | Vector4; + +type Vec2OrFloat = Vec2 | FloatOrNumber; +type Vec3OrFloat = Vec3 | FloatOrNumber; +type Vec4OrFloat = Vec4 | FloatOrNumber; + +interface RemapFunction { + ( + node: FloatOrNumber, + inLowNode: FloatOrNumber, + inHighNode: FloatOrNumber, + outLowNode?: FloatOrNumber, + outHighNode?: FloatOrNumber, + doClamp?: Boolean, + ): Node<"float">; + ( + node: Vec2OrFloat, + inLowNode: Vec2OrFloat, + inHighNode: Vec2OrFloat, + outLowNode?: Vec2OrFloat, + outHighNode?: Vec2OrFloat, + doClamp?: Boolean, + ): Node<"vec2">; + ( + node: Vec3OrFloat, + inLowNode: Vec3OrFloat, + inHighNode: Vec3OrFloat, + outLowNode?: Vec3OrFloat, + outHighNode?: Vec3OrFloat, + doClamp?: Boolean, + ): Node<"vec3">; + ( + node: Vec4OrFloat, + inLowNode: Vec4OrFloat, + inHighNode: Vec4OrFloat, + outLowNode?: Vec4OrFloat, + outHighNode?: Vec4OrFloat, + doClamp?: Boolean, + ): Node<"vec4">; +} + +export const remap: RemapFunction; + +interface RemapClampFunction { + ( + node: FloatOrNumber, + inLowNode: FloatOrNumber, + inHighNode: FloatOrNumber, + outLowNode?: FloatOrNumber, + outHighNode?: FloatOrNumber, + ): Node<"float">; + ( + node: Vec2OrFloat, + inLowNode: Vec2OrFloat, + inHighNode: Vec2OrFloat, + outLowNode?: Vec2OrFloat, + outHighNode?: Vec2OrFloat, + ): Node<"vec2">; + ( + node: Vec3OrFloat, + inLowNode: Vec3OrFloat, + inHighNode: Vec3OrFloat, + outLowNode?: Vec3OrFloat, + outHighNode?: Vec3OrFloat, + ): Node<"vec3">; + ( + node: Vec4OrFloat, + inLowNode: Vec4OrFloat, + inHighNode: Vec4OrFloat, + outLowNode?: Vec4OrFloat, + outHighNode?: Vec4OrFloat, + ): Node<"vec4">; +} + +export const remapClamp: RemapClampFunction; + +interface RemapFloatExtension { + ( + inLowNode: FloatOrNumber, + inHighNode: FloatOrNumber, + outLowNode?: FloatOrNumber, + outHighNode?: FloatOrNumber, + doClamp?: Boolean, + ): Node<"float">; + ( + inLowNode: Vec2OrFloat, + inHighNode: Vec2OrFloat, + outLowNode?: Vec2OrFloat, + outHighNode?: Vec2OrFloat, + doClamp?: Boolean, + ): Node<"vec2">; + ( + inLowNode: Vec3OrFloat, + inHighNode: Vec3OrFloat, + outLowNode?: Vec3OrFloat, + outHighNode?: Vec3OrFloat, + doClamp?: Boolean, + ): Node<"vec3">; + ( + inLowNode: Vec4OrFloat, + inHighNode: Vec4OrFloat, + outLowNode?: Vec4OrFloat, + outHighNode?: Vec4OrFloat, + doClamp?: Boolean, + ): Node<"vec4">; +} + +interface RemapClampFloatExtension { + ( + inLowNode: FloatOrNumber, + inHighNode: FloatOrNumber, + outLowNode?: FloatOrNumber, + outHighNode?: FloatOrNumber, + ): Node<"float">; + ( + inLowNode: Vec2OrFloat, + inHighNode: Vec2OrFloat, + outLowNode?: Vec2OrFloat, + outHighNode?: Vec2OrFloat, + ): Node<"vec2">; + ( + inLowNode: Vec3OrFloat, + inHighNode: Vec3OrFloat, + outLowNode?: Vec3OrFloat, + outHighNode?: Vec3OrFloat, + ): Node<"vec3">; + ( + inLowNode: Vec4OrFloat, + inHighNode: Vec4OrFloat, + outLowNode?: Vec4OrFloat, + outHighNode?: Vec4OrFloat, + ): Node<"vec4">; +} + +interface RemapVec2Extension { + ( + inLowNode: Vec2OrFloat, + inHighNode: Vec2OrFloat, + outLowNode?: Vec2OrFloat, + outHighNode?: Vec2OrFloat, + doClamp?: Boolean, + ): Node<"vec2">; +} + +interface RemapClampVec2Extension { + ( + inLowNode: Vec2OrFloat, + inHighNode: Vec2OrFloat, + outLowNode?: Vec2OrFloat, + outHighNode?: Vec2OrFloat, + ): Node<"vec2">; +} + +interface RemapVec3Extension { + ( + inLowNode: Vec3OrFloat, + inHighNode: Vec3OrFloat, + outLowNode?: Vec3OrFloat, + outHighNode?: Vec3OrFloat, + doClamp?: Boolean, + ): Node<"vec3">; +} + +interface RemapClampVec3Extension { + ( + inLowNode: Vec3OrFloat, + inHighNode: Vec3OrFloat, + outLowNode?: Vec3OrFloat, + outHighNode?: Vec3OrFloat, + doClamp?: Boolean, + ): Node<"vec3">; +} + +interface RemapVec4Extension { + ( + inLowNode: Vec4OrFloat, + inHighNode: Vec4OrFloat, + outLowNode?: Vec4OrFloat, + outHighNode?: Vec4OrFloat, + doClamp?: Boolean, + ): Node<"vec4">; +} + +interface RemapClampVec4Extension { + ( + inLowNode: Vec4OrFloat, + inHighNode: Vec4OrFloat, + outLowNode?: Vec4OrFloat, + outHighNode?: Vec4OrFloat, + ): Node<"vec4">; +} declare module "../core/Node.js" { interface FloatExtensions { - remap: ( - inLowNode: Node<"float"> | number, - inHighNode: Node<"float"> | number, - outLowNode?: Node<"float"> | number, - outHighNode?: Node<"float"> | number, - doClamp?: Node<"bool"> | boolean, - ) => Node<"float">; - - remapClamp: ( - inLowNode: Node<"float"> | number, - inHighNode: Node<"float"> | number, - outLowNode?: Node<"float"> | number, - outHighNode?: Node<"float"> | number, - ) => Node<"float">; + remap: RemapFloatExtension; + remapClamp: RemapClampFloatExtension; + } + interface Vec2Extensions { + remap: RemapVec2Extension; + remapClamp: RemapClampVec2Extension; + } + interface Vec3Extensions { + remap: RemapVec3Extension; + remapClamp: RemapClampVec3Extension; + } + interface Vec4Extensions { + remap: RemapVec4Extension; + remapClamp: RemapClampVec4Extension; } } + +export {}; diff --git a/types/three/src/nodes/utils/SampleNode.d.ts b/types/three/src/nodes/utils/SampleNode.d.ts index 77e4eb2430582d..dcdeae37092c85 100644 --- a/types/three/src/nodes/utils/SampleNode.d.ts +++ b/types/three/src/nodes/utils/SampleNode.d.ts @@ -1,16 +1,26 @@ import Node from "../core/Node.js"; -declare class SampleNode extends Node { - callback: (uv: Node) => Node; - uvNode: Node | null; +declare interface SampleNodeInterface { + callback: (uv: Node<"vec2">) => Node; + uvNode: Node<"vec2"> | null; - readonly isSampleNode: true; + readonly isSampleNode: boolean; - constructor(callback: (uv: Node) => Node, uvNode?: Node | null); - - sample(uv: Node): Node; + sample(uv: Node<"vec2">): Node; } +declare const SampleNode: { + new( + callback: (uv: Node<"vec2">) => Node, + uvNode?: Node<"vec2"> | null, + ): SampleNode; +}; + +type SampleNode = SampleNodeInterface & Node; + export default SampleNode; -export const sample: (callback: (uv: Node) => Node, uv?: Node | null) => SampleNode; +export const sample: ( + callback: (uv: Node<"vec2">) => Node, + uvNode?: Node<"vec2"> | null, +) => SampleNode; diff --git a/types/three/src/objects/BatchedMesh.d.ts b/types/three/src/objects/BatchedMesh.d.ts index 98389b10522d8a..b4032efe8c632c 100644 --- a/types/three/src/objects/BatchedMesh.d.ts +++ b/types/three/src/objects/BatchedMesh.d.ts @@ -127,7 +127,7 @@ declare class BatchedMesh extends Mesh { * Frees the GPU-related resources allocated by this instance. Call this method whenever this instance is no longer * used in your app. */ - dispose(): this; + dispose(): void; /** * Takes a sort a function that is run before render. The function takes a list of instances to sort and a camera. diff --git a/types/three/src/objects/InstancedMesh.d.ts b/types/three/src/objects/InstancedMesh.d.ts index 30b91c707aab2f..1ae604a6155c88 100644 --- a/types/three/src/objects/InstancedMesh.d.ts +++ b/types/three/src/objects/InstancedMesh.d.ts @@ -54,14 +54,6 @@ export class InstancedMesh< */ instanceMatrix: InstancedBufferAttribute; - /** - * Represents the local transformation of all instances of the previous frame. - * Required for computing velocity. Maintained in {@link InstanceNode}. - * - * @default null - */ - previousInstancedMatrix: InstancedBufferAttribute | null; - /** * Represents the colors of all instances. * You have to set {@link InstancedBufferAttribute.needsUpdate | .instanceColor.needsUpdate()} flag to `true` if you modify instanced data via {@link setColorAt | .setColorAt()}. diff --git a/types/three/src/objects/Skeleton.d.ts b/types/three/src/objects/Skeleton.d.ts index 3ee3bc3282aea7..14aa9d2d0a5a02 100644 --- a/types/three/src/objects/Skeleton.d.ts +++ b/types/three/src/objects/Skeleton.d.ts @@ -63,8 +63,6 @@ export class Skeleton { */ boneMatrices: Float32Array | null; - previousBoneMatrices: Float32Array | null; - /** * The {@link THREE.DataTexture | DataTexture} holding the bone data when using a vertex texture. */ diff --git a/types/three/src/renderers/common/Animation.d.ts b/types/three/src/renderers/common/Animation.d.ts deleted file mode 100644 index 8ca0265bec5174..00000000000000 --- a/types/three/src/renderers/common/Animation.d.ts +++ /dev/null @@ -1,102 +0,0 @@ -import Info from "./Info.js"; -import NodeManager from "./nodes/NodeManager.js"; -import Renderer from "./Renderer.js"; - -export interface AnimationContext { - requestAnimationFrame(callback: FrameRequestCallback, xrFrame?: XRFrame): number; - cancelAnimationFrame(handle: number): void; -} - -/** - * This module manages the internal animation loop of the renderer. - * - * @private - */ -declare class Animation { - /** - * Constructs a new animation loop management component. - * - * @param {Renderer} renderer - A reference to the main renderer. - * @param {NodeManager} nodes - Renderer component for managing nodes related logic. - * @param {Info} info - Renderer component for managing metrics and monitoring data. - */ - constructor(renderer: Renderer, nodes: NodeManager, info: Info); - /** - * A reference to the main renderer. - * - * @type {Renderer} - */ - renderer: Renderer; - /** - * Renderer component for managing nodes related logic. - * - * @type {NodeManager} - */ - nodes: NodeManager; - /** - * Renderer component for managing metrics and monitoring data. - * - * @type {Info} - */ - info: Info; - /** - * A reference to the context from `requestAnimationFrame()` can - * be called (usually `window`). - * - * @type {?(Window|XRSession)} - */ - _context: AnimationContext | null; - /** - * The user-defined animation loop. - * - * @type {?Function} - * @default null - */ - _animationLoop: ((time: DOMHighResTimeStamp, xrFrame?: XRFrame) => void) | null; - /** - * The requestId which is returned from the `requestAnimationFrame()` call. - * Can be used to cancel the stop the animation loop. - * - * @type {?number} - * @default null - */ - _requestId: number | null; - /** - * Starts the internal animation loop. - */ - start(): void; - /** - * Stops the internal animation loop. - */ - stop(): void; - /** - * Returns the user-level animation loop. - * - * @return {?Function} The animation loop. - */ - getAnimationLoop(): ((time: DOMHighResTimeStamp, xrFrame?: XRFrame) => void) | null; - /** - * Defines the user-level animation loop. - * - * @param {?Function} callback - The animation loop. - */ - setAnimationLoop(callback: ((time: DOMHighResTimeStamp, xrFrame?: XRFrame) => void) | null): void; - /** - * Returns the animation context. - * - * @return {Window|XRSession} The animation context. - */ - getContext(): AnimationContext; - /** - * Defines the context in which `requestAnimationFrame()` is executed. - * - * @param {Window|XRSession} context - The context to set. - */ - setContext(context: AnimationContext): void; - /** - * Frees all internal resources and stops the animation loop. - */ - dispose(): void; -} - -export default Animation; diff --git a/types/three/src/renderers/common/Attributes.d.ts b/types/three/src/renderers/common/Attributes.d.ts deleted file mode 100644 index 0bf0f2bdcd72fc..00000000000000 --- a/types/three/src/renderers/common/Attributes.d.ts +++ /dev/null @@ -1,59 +0,0 @@ -import { BufferAttribute } from "../../core/BufferAttribute.js"; -import { InterleavedBuffer } from "../../core/InterleavedBuffer.js"; -import { InterleavedBufferAttribute } from "../../core/InterleavedBufferAttribute.js"; -import Backend from "./Backend.js"; -import DataMap from "./DataMap.js"; -import Info from "./Info.js"; - -/** - * This renderer module manages geometry attributes. - * - * @private - * @augments DataMap - */ -declare class Attributes extends DataMap { - /** - * Constructs a new attribute management component. - * - * @param {Backend} backend - The renderer's backend. - * @param {Info} info - Renderer component for managing metrics and monitoring data. - */ - constructor(backend: Backend, info: Info); - /** - * The renderer's backend. - * - * @type {Backend} - */ - backend: Backend; - /** - * Renderer component for managing metrics and monitoring data. - * - * @type {Info} - */ - info: Info; - /** - * Deletes the data for the given attribute. - * - * @param {BufferAttribute} attribute - The attribute. - * @return {?Object} The deleted attribute data. - */ - delete(attribute: BufferAttribute | InterleavedBufferAttribute): unknown; - /** - * Updates the given attribute. This method creates attribute buffers - * for new attributes and updates data for existing ones. - * - * @param {BufferAttribute} attribute - The attribute to update. - * @param {number} type - The attribute type. - */ - update(attribute: BufferAttribute | InterleavedBufferAttribute, type: number): void; - /** - * Utility method for handling interleaved buffer attributes correctly. - * To process them, their `InterleavedBuffer` is returned. - * - * @param {BufferAttribute} attribute - The attribute. - * @return {BufferAttribute|InterleavedBuffer} - */ - _getBufferAttribute(attribute: BufferAttribute | InterleavedBufferAttribute): BufferAttribute | InterleavedBuffer; -} - -export default Attributes; diff --git a/types/three/src/renderers/common/Backend.d.ts b/types/three/src/renderers/common/Backend.d.ts index 37571640ec4629..7fa507cb5f25a3 100644 --- a/types/three/src/renderers/common/Backend.d.ts +++ b/types/three/src/renderers/common/Backend.d.ts @@ -1,7 +1,6 @@ import { CoordinateSystem } from "../../constants.js"; import NodeBuilder from "../../nodes/core/NodeBuilder.js"; import Renderer from "./Renderer.js"; -import RenderObject from "./RenderObject.js"; declare module "../../core/Object3D.js" { interface Object3D { @@ -27,6 +26,4 @@ export default abstract class Backend { abstract get coordinateSystem(): CoordinateSystem; getDomElement(): HTMLCanvasElement | OffscreenCanvas; - - createNodeBuilder(renderObject: RenderObject, renderer: Renderer): NodeBuilder; } diff --git a/types/three/src/renderers/common/Background.d.ts b/types/three/src/renderers/common/Background.d.ts deleted file mode 100644 index ce09898e932cad..00000000000000 --- a/types/three/src/renderers/common/Background.d.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { Scene } from "../../scenes/Scene.js"; -import DataMap from "./DataMap.js"; -import NodeManager from "./nodes/NodeManager.js"; -import RenderContext from "./RenderContext.js"; -import Renderer from "./Renderer.js"; -import RenderList from "./RenderList.js"; - -/** - * This renderer module manages the background. - * - * @private - * @augments DataMap - */ -declare class Background extends DataMap { - /** - * Constructs a new background management component. - * - * @param {Renderer} renderer - The renderer. - * @param {NodeManager} nodes - Renderer component for managing nodes related logic. - */ - constructor(renderer: Renderer, nodes: NodeManager); - /** - * The renderer. - * - * @type {Renderer} - */ - renderer: Renderer; - /** - * Renderer component for managing nodes related logic. - * - * @type {NodeManager} - */ - nodes: NodeManager; - /** - * Updates the background for the given scene. Depending on how `Scene.background` - * or `Scene.backgroundNode` are configured, this method might configure a simple clear - * or add a mesh to the render list for rendering the background as a textured plane - * or skybox. - * - * @param {Scene} scene - The scene. - * @param {RenderList} renderList - The current render list. - * @param {RenderContext} renderContext - The current render context. - */ - update(scene: Scene, renderList: RenderList, renderContext: RenderContext): void; -} - -export default Background; diff --git a/types/three/src/renderers/common/BindGroup.d.ts b/types/three/src/renderers/common/BindGroup.d.ts deleted file mode 100644 index 53b54c202b40ac..00000000000000 --- a/types/three/src/renderers/common/BindGroup.d.ts +++ /dev/null @@ -1,39 +0,0 @@ -import Binding from "./Binding.js"; - -/** - * A bind group represents a collection of bindings and thus a collection - * or resources. Bind groups are assigned to pipelines to provide them - * with the required resources (like uniform buffers or textures). - * - * @private - */ -declare class BindGroup { - /** - * Constructs a new bind group. - * - * @param {string} name - The bind group's name. - * @param {Array} bindings - An array of bindings. - * @param {number} index - The group index. - */ - constructor(name?: string, bindings?: Binding[], index?: number); - /** - * The bind group's name. - * - * @type {string} - */ - name: string; - /** - * An array of bindings. - * - * @type {Array} - */ - bindings: Binding[]; - /** - * The group's ID. - * - * @type {number} - */ - id: number; -} - -export default BindGroup; diff --git a/types/three/src/renderers/common/Binding.d.ts b/types/three/src/renderers/common/Binding.d.ts deleted file mode 100644 index d876c3b7e4759c..00000000000000 --- a/types/three/src/renderers/common/Binding.d.ts +++ /dev/null @@ -1,50 +0,0 @@ -/** - * A binding represents the connection between a resource (like a texture, sampler - * or uniform buffer) and the resource definition in a shader stage. - * - * This module is an abstract base class for all concrete bindings types. - * - * @abstract - * @private - */ -declare class Binding { - /** - * Constructs a new binding. - * - * @param {string} [name=''] - The binding's name. - */ - constructor(name?: string); - /** - * The binding's name. - * - * @type {string} - */ - name: string; - /** - * A bitmask that defines in what shader stages the - * binding's resource is accessible. - * - * @type {number} - */ - visibility: number; - /** - * Makes sure binding's resource is visible for the given shader stage. - * - * @param {number} visibility - The shader stage. - */ - setVisibility(visibility: number): void; - /** - * The shader stages in which the binding's resource is visible. - * - * @return {number} The visibility bitmask. - */ - getVisibility(): number; - /** - * Clones the binding. - * - * @return {Binding} The cloned binding. - */ - clone(): Binding; -} - -export default Binding; diff --git a/types/three/src/renderers/common/Bindings.d.ts b/types/three/src/renderers/common/Bindings.d.ts deleted file mode 100644 index 5631ef45c44d68..00000000000000 --- a/types/three/src/renderers/common/Bindings.d.ts +++ /dev/null @@ -1,132 +0,0 @@ -import ComputeNode from "../../nodes/gpgpu/ComputeNode.js"; -import Attributes from "./Attributes.js"; -import Backend from "./Backend.js"; -import BindGroup from "./BindGroup.js"; -import DataMap from "./DataMap.js"; -import Info from "./Info.js"; -import NodeManager from "./nodes/NodeManager.js"; -import Pipelines from "./Pipelines.js"; -import RenderObject from "./RenderObject.js"; -import Textures from "./Textures.js"; - -/** - * This renderer module manages the bindings of the renderer. - * - * @private - * @augments DataMap - */ -declare class Bindings extends DataMap { - /** - * Constructs a new bindings management component. - * - * @param {Backend} backend - The renderer's backend. - * @param {NodeManager} nodes - Renderer component for managing nodes related logic. - * @param {Textures} textures - Renderer component for managing textures. - * @param {Attributes} attributes - Renderer component for managing attributes. - * @param {Pipelines} pipelines - Renderer component for managing pipelines. - * @param {Info} info - Renderer component for managing metrics and monitoring data. - */ - constructor( - backend: Backend, - nodes: NodeManager, - textures: Textures, - attributes: Attributes, - pipelines: Pipelines, - info: Info, - ); - /** - * The renderer's backend. - * - * @type {Backend} - */ - backend: Backend; - /** - * Renderer component for managing textures. - * - * @type {Textures} - */ - textures: Textures; - /** - * Renderer component for managing pipelines. - * - * @type {Pipelines} - */ - pipelines: Pipelines; - /** - * Renderer component for managing attributes. - * - * @type {Attributes} - */ - attributes: Attributes; - /** - * Renderer component for managing nodes related logic. - * - * @type {NodeManager} - */ - nodes: NodeManager; - /** - * Renderer component for managing metrics and monitoring data. - * - * @type {Info} - */ - info: Info; - /** - * Returns the bind groups for the given render object. - * - * @param {RenderObject} renderObject - The render object. - * @return {Array} The bind groups. - */ - getForRender(renderObject: RenderObject): BindGroup[]; - /** - * Returns the bind groups for the given compute node. - * - * @param {Node} computeNode - The compute node. - * @return {Array} The bind groups. - */ - getForCompute(computeNode: ComputeNode): BindGroup[]; - /** - * Updates the bindings for the given compute node. - * - * @param {Node} computeNode - The compute node. - */ - updateForCompute(computeNode: ComputeNode): void; - /** - * Updates the bindings for the given render object. - * - * @param {RenderObject} renderObject - The render object. - */ - updateForRender(renderObject: RenderObject): void; - /** - * Deletes the bindings for the given compute node. - * - * @param {Node} computeNode - The compute node. - */ - deleteForCompute(computeNode: ComputeNode): void; - /** - * Deletes the bindings for the given renderObject node. - * - * @param {RenderObject} renderObject - The renderObject. - */ - deleteForRender(renderObject: RenderObject): void; - /** - * Updates the given array of bindings. - * - * @param {Array} bindings - The bind groups. - */ - _updateBindings(bindings: BindGroup[]): void; - /** - * Initializes the given bind group. - * - * @param {BindGroup} bindGroup - The bind group to initialize. - */ - _init(bindGroup: BindGroup): void; - /** - * Updates the given bind group. - * - * @param {BindGroup} bindGroup - The bind group to update. - * @param {Array} bindings - The bind groups. - */ - _update(bindGroup: BindGroup, bindings: BindGroup[]): void; -} - -export default Bindings; diff --git a/types/three/src/renderers/common/Buffer.d.ts b/types/three/src/renderers/common/Buffer.d.ts deleted file mode 100644 index 4e8832b45f8eb4..00000000000000 --- a/types/three/src/renderers/common/Buffer.d.ts +++ /dev/null @@ -1,90 +0,0 @@ -import { TypedArray } from "../../core/BufferAttribute.js"; -import Binding from "./Binding.js"; - -/** - * Represents a buffer binding type. - * - * @private - * @abstract - * @augments Binding - */ -declare class Buffer extends Binding { - /** - * Constructs a new buffer. - * - * @param {string} name - The buffer's name. - * @param {TypedArray} [buffer=null] - The buffer. - */ - constructor(name: string, buffer?: TypedArray); - /** - * This flag can be used for type testing. - * - * @type {boolean} - * @readonly - * @default true - */ - readonly isBuffer: boolean; - /** - * The bytes per element. - * - * @type {number} - */ - bytesPerElement: number; - /** - * A reference to the internal buffer. - * - * @private - * @type {TypedArray} - */ - private _buffer; - /** - * An array of update ranges. - * - * @private - * @type {Array<{start: number, count: number}>} - */ - private _updateRanges; - /** - * The array of update ranges. - * - * @type {Array<{start: number, count: number}>} - */ - get updateRanges(): Array<{ - start: number; - count: number; - }>; - /** - * Adds an update range. - * - * @param {number} start - The start index. - * @param {number} count - The number of elements. - */ - addUpdateRange(start: number, count: number): void; - /** - * Clears all update ranges. - */ - clearUpdateRanges(): void; - /** - * The buffer's byte length. - * - * @type {number} - * @readonly - */ - get byteLength(): number; - /** - * A reference to the internal buffer. - * - * @type {Float32Array} - * @readonly - */ - get buffer(): TypedArray; - /** - * Updates the binding. - * - * @return {boolean} Whether the buffer has been updated and must be - * uploaded to the GPU. - */ - update(): boolean; -} - -export default Buffer; diff --git a/types/three/src/renderers/common/CanvasTarget.d.ts b/types/three/src/renderers/common/CanvasTarget.d.ts index 6df109fb2c42fd..58a9c909ce47b0 100644 --- a/types/three/src/renderers/common/CanvasTarget.d.ts +++ b/types/three/src/renderers/common/CanvasTarget.d.ts @@ -31,49 +31,6 @@ declare class CanvasTarget} - */ - weakMaps: { - [x: number]: WeakMap; - }; - /** - * Returns the Weak Map for the given keys. - * - * @param {Array} keys - List of keys. - * @return {WeakMap} The weak map. - */ - _getWeakMap(keys: object[]): WeakMap; - /** - * Returns the value for the given array of keys. - * - * @param {Array} keys - List of keys. - * @return {any} The value. Returns `undefined` if no value was found. - */ - get(keys: object[]): unknown; - /** - * Sets the value for the given keys. - * - * @param {Array} keys - List of keys. - * @param {any} value - The value to set. - * @return {ChainMap} A reference to this Chain Map. - */ - set(keys: object[], value: unknown): ChainMap; - /** - * Deletes a value for the given keys. - * - * @param {Array} keys - The keys. - * @return {boolean} Returns `true` if the value has been removed successfully and `false` if the value has not be found. - */ - delete(keys: object[]): boolean; -} - -export default ChainMap; diff --git a/types/three/src/renderers/common/ClippingContext.d.ts b/types/three/src/renderers/common/ClippingContext.d.ts index e0848b1d4d60a7..b6f1a53c4ac964 100644 --- a/types/three/src/renderers/common/ClippingContext.d.ts +++ b/types/three/src/renderers/common/ClippingContext.d.ts @@ -48,6 +48,12 @@ declare class ClippingContext { * @default false */ shadowPass: boolean; + /** + * The view matrix. + * + * @type {Matrix4} + */ + viewMatrix: Matrix4; /** * The view normal matrix. * @@ -79,7 +85,6 @@ declare class ClippingContext { * @readonly */ readonly parentVersion: number | null; - viewMatrix?: Matrix4; /** * Projects the given source clipping planes and writes the result into the * destination array. diff --git a/types/three/src/renderers/common/Color4.d.ts b/types/three/src/renderers/common/Color4.d.ts deleted file mode 100644 index 884b1f02fbe57b..00000000000000 --- a/types/three/src/renderers/common/Color4.d.ts +++ /dev/null @@ -1,55 +0,0 @@ -import { Color, ColorRepresentation } from "../../math/Color.js"; - -/** - * A four-component version of {@link Color} which is internally - * used by the renderer to represents clear color with alpha as - * one object. - * - * @private - * @augments Color - */ -declare class Color4 extends Color { - /** - * Constructs a new four-component color. - * You can pass a single THREE.Color, hex or - * string argument to this constructor. - */ - constructor(color?: ColorRepresentation); - /** - * Constructs a new four-component color. - * - * @param {number} [r=1] - The red value. - * @param {number} [g=1] - The green value. - * @param {number} [b=1] - The blue value. - * @param {number} [a=1] - The alpha value. - */ - constructor(r: number, g: number, b: number, a?: number); - a: number; - /** - * Overwrites the default to honor alpha. - * You can also pass a single THREE.Color, hex or - * string argument to this method. - * - * @param {number|string|Color} r - The red value. - * @param {number} [g] - The green value. - * @param {number} [b] - The blue value. - * @param {number} [a=1] - The alpha value. - * @return {Color4} A reference to this object. - */ - set(...args: [color: ColorRepresentation] | [r: number, g: number, b: number, a?: number]): this; - /** - * Overwrites the default to honor alpha. - * - * @param {Color4} color - The color to copy. - * @return {Color4} A reference to this object. - */ - copy(color: Color4): this; - /** - * Overwrites the default to honor alpha. - * - * @return {Color4} The cloned color. - */ - clone(): this; -} - -export default Color4; diff --git a/types/three/src/renderers/common/ComputePipeline.d.ts b/types/three/src/renderers/common/ComputePipeline.d.ts deleted file mode 100644 index 72fabace32dd86..00000000000000 --- a/types/three/src/renderers/common/ComputePipeline.d.ts +++ /dev/null @@ -1,34 +0,0 @@ -import Pipeline from "./Pipeline.js"; -import ProgrammableStage from "./ProgrammableStage.js"; - -/** - * Class for representing compute pipelines. - * - * @private - * @augments Pipeline - */ -declare class ComputePipeline extends Pipeline { - /** - * Constructs a new compute pipeline. - * - * @param {string} cacheKey - The pipeline's cache key. - * @param {ProgrammableStage} computeProgram - The pipeline's compute shader. - */ - constructor(cacheKey: string, computeProgram: ProgrammableStage); - /** - * The pipeline's compute shader. - * - * @type {ProgrammableStage} - */ - computeProgram: ProgrammableStage; - /** - * This flag can be used for type testing. - * - * @type {boolean} - * @readonly - * @default true - */ - readonly isComputePipeline: boolean; -} - -export default ComputePipeline; diff --git a/types/three/src/renderers/common/CubeRenderTarget.d.ts b/types/three/src/renderers/common/CubeRenderTarget.d.ts index 6f129a159024e7..2cb1f6aec8d886 100644 --- a/types/three/src/renderers/common/CubeRenderTarget.d.ts +++ b/types/three/src/renderers/common/CubeRenderTarget.d.ts @@ -1,4 +1,5 @@ import { RenderTarget, RenderTargetOptions } from "../../core/RenderTarget.js"; +import { CubeTexture } from "../../textures/CubeTexture.js"; import { Texture } from "../../textures/Texture.js"; import Renderer from "./Renderer.js"; @@ -8,7 +9,7 @@ import Renderer from "./Renderer.js"; * * @augments RenderTarget */ -declare class CubeRenderTarget extends RenderTarget { +declare class CubeRenderTarget extends RenderTarget { /** * Constructs a new cube render target. * diff --git a/types/three/src/renderers/common/DataMap.d.ts b/types/three/src/renderers/common/DataMap.d.ts deleted file mode 100644 index fb9571fa09f6ce..00000000000000 --- a/types/three/src/renderers/common/DataMap.d.ts +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Data structure for the renderer. It is intended to manage - * data of objects in dictionaries. - * - * @private - */ -declare class DataMap { - /** - * `DataMap` internally uses a weak map - * to manage its data. - * - * @type {WeakMap} - */ - data: WeakMap; - /** - * Returns the dictionary for the given object. - * - * @param {Object} object - The object. - * @return {Object} The dictionary. - */ - get(object: object): unknown; - /** - * Deletes the dictionary for the given object. - * - * @param {Object} object - The object. - * @return {?Object} The deleted dictionary. - */ - delete(object: object): unknown | null; - /** - * Returns `true` if the given object has a dictionary defined. - * - * @param {Object} object - The object to test. - * @return {boolean} Whether a dictionary is defined or not. - */ - has(object: object): boolean; - /** - * Frees internal resources. - */ - dispose(): void; -} - -export default DataMap; diff --git a/types/three/src/renderers/common/Geometries.d.ts b/types/three/src/renderers/common/Geometries.d.ts deleted file mode 100644 index 74ab02700d1849..00000000000000 --- a/types/three/src/renderers/common/Geometries.d.ts +++ /dev/null @@ -1,111 +0,0 @@ -import { BufferAttribute } from "../../core/BufferAttribute.js"; -import { BufferGeometry } from "../../core/BufferGeometry.js"; -import Attributes from "./Attributes.js"; -import { AttributeType } from "./Constants.js"; -import DataMap from "./DataMap.js"; -import Info from "./Info.js"; -import RenderObject from "./RenderObject.js"; - -/** - * This renderer module manages geometries. - * - * @private - * @augments DataMap - */ -declare class Geometries extends DataMap { - /** - * Constructs a new geometry management component. - * - * @param {Attributes} attributes - Renderer component for managing attributes. - * @param {Info} info - Renderer component for managing metrics and monitoring data. - */ - constructor(attributes: Attributes, info: Info); - /** - * Renderer component for managing attributes. - * - * @type {Attributes} - */ - attributes: Attributes; - /** - * Renderer component for managing metrics and monitoring data. - * - * @type {Info} - */ - info: Info; - /** - * Weak Map for managing attributes for wireframe rendering. - * - * @type {WeakMap} - */ - wireframes: WeakMap; - /** - * This Weak Map is used to make sure buffer attributes are - * updated only once per render call. - * - * @type {WeakMap} - */ - attributeCall: WeakMap; - /** - * Stores the event listeners attached to geometries. - * - * @private - * @type {Map} - */ - private _geometryDisposeListeners; - /** - * Returns `true` if the given render object has an initialized geometry. - * - * @param {RenderObject} renderObject - The render object. - * @return {boolean} Whether if the given render object has an initialized geometry or not. - */ - has(renderObject: RenderObject): boolean; - /** - * Prepares the geometry of the given render object for rendering. - * - * @param {RenderObject} renderObject - The render object. - */ - updateForRender(renderObject: RenderObject): void; - /** - * Initializes the geometry of the given render object. - * - * @param {RenderObject} renderObject - The render object. - */ - initGeometry(renderObject: RenderObject): void; - /** - * Updates the geometry attributes of the given render object. - * - * @param {RenderObject} renderObject - The render object. - */ - updateAttributes(renderObject: RenderObject): void; - /** - * Updates the given attribute. - * - * @param {BufferAttribute} attribute - The attribute to update. - * @param {number} type - The attribute type. - */ - updateAttribute(attribute: BufferAttribute, type: AttributeType): void; - /** - * Returns the indirect buffer attribute of the given render object. - * - * @param {RenderObject} renderObject - The render object. - * @return {?BufferAttribute} The indirect attribute. `null` if no indirect drawing is used. - */ - getIndirect(renderObject: RenderObject): BufferAttribute | null; - /** - * Returns the byte offset into the indirect attribute buffer of the given render object. - * - * @param {RenderObject} renderObject - The render object. - * @return {number} The byte offset into the indirect attribute buffer. - */ - getIndirectOffset(renderObject: RenderObject): number; - /** - * Returns the index of the given render object's geometry. This is implemented - * in a method to return a wireframe index if necessary. - * - * @param {RenderObject} renderObject - The render object. - * @return {?BufferAttribute} The index. Returns `null` for non-indexed geometries. - */ - getIndex(renderObject: RenderObject): BufferAttribute | null; -} - -export default Geometries; diff --git a/types/three/src/renderers/common/Info.d.ts b/types/three/src/renderers/common/Info.d.ts index 8649d9a5840b6b..f3704a297e4df6 100644 --- a/types/three/src/renderers/common/Info.d.ts +++ b/types/three/src/renderers/common/Info.d.ts @@ -1,7 +1,6 @@ import { BufferAttribute } from "../../core/BufferAttribute.js"; import { Object3D } from "../../core/Object3D.js"; import { Texture } from "../../textures/Texture.js"; -import ProgrammableStage from "./ProgrammableStage.js"; import ReadbackBuffer from "./ReadbackBuffer.js"; /** @@ -79,50 +78,47 @@ declare class Info { * * @type {Object} * @readonly - * @property {number} geometries - The number of active geometries. - * @property {number} textures - The number of active textures. * @property {number} attributes - The number of active attributes. + * @property {number} attributesSize - The memory size of active attributes in bytes. + * @property {number} geometries - The number of active geometries. * @property {number} indexAttributes - The number of active index attributes. - * @property {number} storageAttributes - The number of active storage attributes. + * @property {number} indexAttributesSize - The memory size of active index attributes in bytes. * @property {number} indirectStorageAttributes - The number of active indirect storage attributes. - * @property {number} readbackBuffers - The number of active readback buffers. + * @property {number} indirectStorageAttributesSize - The memory size of active indirect storage attributes in bytes. * @property {number} programs - The number of active programs. + * @property {number} programsSize - The memory size of active programs in bytes. + * @property {number} readbackBuffers - The number of active readback buffers. + * @property {number} readbackBuffersSize - The memory size of active readback buffers in bytes. * @property {number} renderTargets - The number of active renderTargets. - * @property {number} total - The total memory size in bytes. - * @property {number} texturesSize - The memory size of active textures in bytes. - * @property {number} attributesSize - The memory size of active attributes in bytes. - * @property {number} indexAttributesSize - The memory size of active index attributes in bytes. + * @property {number} storageAttributes - The number of active storage attributes. * @property {number} storageAttributesSize - The memory size of active storage attributes in bytes. - * @property {number} indirectStorageAttributesSize - The memory size of active indirect storage attributes in bytes. - * @property {number} readbackBuffersSize - The memory size of active readback buffers in bytes. - * @property {number} programsSize - The memory size of active programs in bytes. + * @property {number} textures - The number of active textures. + * @property {number} texturesSize - The memory size of active textures in bytes. + * @property {number} uniformBuffers - The number of active uniform buffers. + * @property {number} uniformBuffersSize - The memory size of active uniform buffers in bytes. + * @property {number} total - The total memory size in bytes. */ readonly memory: { - geometries: number; - textures: number; attributes: number; + attributesSize: number; + geometries: number; indexAttributes: number; - storageAttributes: number; + indexAttributesSize: number; indirectStorageAttributes: number; - readbackBuffers: number; + indirectStorageAttributesSize: number; programs: number; + programsSize: number; + readbackBuffers: number; + readbackBuffersSize: number; renderTargets: number; - total: number; - texturesSize: number; - attributesSize: number; - indexAttributesSize: number; + storageAttributes: number; storageAttributesSize: number; - indirectStorageAttributesSize: number; - readbackBuffersSize: number; - programsSize: number; + textures: number; + texturesSize: number; + uniformBuffers: number; + uniformBuffersSize: number; + total: number; }; - /** - * Map for storing calculated byte sizes of tracked objects. - * - * @type {Map} - * @private - */ - private memoryMap; /** * This method should be executed per draw call and updates the corresponding metrics. * @@ -151,14 +147,6 @@ declare class Info { * @param {Texture} texture */ destroyTexture(texture: Texture): void; - /** - * Tracks attribute memory explicitly, updating counts and byte tracking. - * - * @param {BufferAttribute} attribute - * @param {string} type - type of attribute - * @private - */ - private _createAttribute; /** * Tracks a regular attribute memory explicitly. * @@ -201,34 +189,6 @@ declare class Info { * @param {ReadbackBuffer} readbackBuffer - The readback buffer to track. */ destroyReadbackBuffer(readbackBuffer: ReadbackBuffer): void; - /** - * Tracks program memory explicitly, updating counts and byte tracking. - * - * @param {ProgrammableStage} program - The program to track. - */ - createProgram(program: ProgrammableStage): void; - /** - * Tracks program memory explicitly, updating counts and byte tracking. - * - * @param {Object} program - The program to track. - */ - destroyProgram(program: ProgrammableStage): void; - /** - * Calculates the memory size of a texture in bytes. - * - * @param {Texture} texture - The texture to calculate the size for. - * @return {number} The calculated size in bytes. - * @private - */ - private _getTextureMemorySize; - /** - * Calculates the memory size of an attribute in bytes. - * - * @param {BufferAttribute} attribute - The attribute to calculate the size for. - * @return {number} The calculated size in bytes. - * @private - */ - private _getAttributeMemorySize; } export default Info; diff --git a/types/three/src/renderers/common/InspectorBase.d.ts b/types/three/src/renderers/common/InspectorBase.d.ts index 5e6fcf68ecb5a2..b45122f358976a 100644 --- a/types/three/src/renderers/common/InspectorBase.d.ts +++ b/types/three/src/renderers/common/InspectorBase.d.ts @@ -19,13 +19,6 @@ export interface InspectorBaseEventMap { declare class InspectorBase extends EventDispatcher { - /** - * The renderer associated with this inspector. - * - * @type {WebGLRenderer} - * @private - */ - private _renderer; /** * The current frame being processed. * diff --git a/types/three/src/renderers/common/Lighting.d.ts b/types/three/src/renderers/common/Lighting.d.ts index 6570d9c3b78fce..0f755df2c550f6 100644 --- a/types/three/src/renderers/common/Lighting.d.ts +++ b/types/three/src/renderers/common/Lighting.d.ts @@ -1,11 +1,55 @@ -import { Object3D } from "../../core/Object3D.js"; import { Light } from "../../lights/Light.js"; -import LightsNode from "../../nodes/lighting/LightsNode.js"; +import { LightsNode } from "../../nodes/Nodes.js"; +import { Scene } from "../../scenes/Scene.js"; +/** + * This renderer module manages the lights nodes which are unique + * per scene and camera combination. + * + * The lights node itself is later configured in the render list + * with the actual lights from the scene. + * + * @private + */ declare class Lighting { - createNode(lights?: Light[]): LightsNode; - - getNode(scene: Object3D): LightsNode; + /** + * Whether this lighting manager is enabled or not. + * + * @type {boolean} + * @default true + */ + enabled: boolean; + /** + * Creates a new lights node for the given array of lights. + * + * @param {Array} lights - The render object. + * @return {LightsNode} The lights node. + */ + createNode(lights?: Array): LightsNode; + /** + * Returns a lights node for the given scene. + * + * @param {Scene} scene - The scene. + * @return {LightsNode} The lights node. + */ + getNode(scene: Scene): LightsNode; + /** + * Saves the current lights of the scene's lights node so they can be restored + * in {@link Lighting#finishRender}. Must be paired with a `finishRender()` call + * to avoid memory leaks. + * + * Nested render calls might mutate the lights array so a save/restore is required + * for each render call. + * + * @param {Scene} scene - The scene. + */ + beginRender(scene: Scene): void; + /** + * Restores the lights saved by the matching {@link Lighting#beginRender} call. + * + * @param {Scene} scene - The scene. + */ + finishRender(scene: Scene): void; } export default Lighting; diff --git a/types/three/src/renderers/common/Pipeline.d.ts b/types/three/src/renderers/common/Pipeline.d.ts deleted file mode 100644 index 16708fb9463937..00000000000000 --- a/types/three/src/renderers/common/Pipeline.d.ts +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Abstract class for representing pipelines. - * - * @private - * @abstract - */ -declare class Pipeline { - /** - * Constructs a new pipeline. - * - * @param {string} cacheKey - The pipeline's cache key. - */ - constructor(cacheKey: string); - /** - * The pipeline's cache key. - * - * @type {string} - */ - cacheKey: string; - /** - * How often the pipeline is currently in use. - * - * @type {number} - * @default 0 - */ - usedTimes: number; -} - -export default Pipeline; diff --git a/types/three/src/renderers/common/Pipelines.d.ts b/types/three/src/renderers/common/Pipelines.d.ts deleted file mode 100644 index 30bcb0ce3fc646..00000000000000 --- a/types/three/src/renderers/common/Pipelines.d.ts +++ /dev/null @@ -1,186 +0,0 @@ -import ComputeNode from "../../nodes/gpgpu/ComputeNode.js"; -import Backend from "./Backend.js"; -import BindGroup from "./BindGroup.js"; -import Bindings from "./Bindings.js"; -import ComputePipeline from "./ComputePipeline.js"; -import DataMap from "./DataMap.js"; -import Info from "./Info.js"; -import NodeManager from "./nodes/NodeManager.js"; -import Pipeline from "./Pipeline.js"; -import ProgrammableStage from "./ProgrammableStage.js"; -import RenderObject from "./RenderObject.js"; -import RenderObjectPipeline from "./RenderObjectPipeline.js"; - -/** - * This renderer module manages the pipelines of the renderer. - * - * @private - * @augments DataMap - */ -declare class Pipelines extends DataMap { - /** - * Constructs a new pipeline management component. - * - * @param {Backend} backend - The renderer's backend. - * @param {NodeManager} nodes - Renderer component for managing nodes related logic. - * @param {Info} info - Renderer component for managing metrics and monitoring data. - */ - constructor(backend: Backend, nodes: NodeManager, info: Info); - /** - * The renderer's backend. - * - * @type {Backend} - */ - backend: Backend; - /** - * Renderer component for managing nodes related logic. - * - * @type {NodeManager} - */ - nodes: NodeManager; - /** - * Renderer component for managing metrics and monitoring data. - * - * @type {Info} - */ - info: Info; - /** - * A references to the bindings management component. - * This reference will be set inside the `Bindings` - * constructor. - * - * @type {?Bindings} - * @default null - */ - bindings: Bindings | null; - /** - * Internal cache for maintaining pipelines. - * The key of the map is a cache key, the value the pipeline. - * - * @type {Map} - */ - caches: Map; - /** - * This dictionary maintains for each shader stage type (vertex, - * fragment and compute) the programmable stage objects which - * represent the actual shader code. - * - * @type {Object>} - */ - programs: { - vertex: Map; - fragment: Map; - compute: Map; - }; - /** - * Returns a compute pipeline for the given compute node. - * - * @param {Node} computeNode - The compute node. - * @param {Array} bindings - The bindings. - * @return {ComputePipeline} The compute pipeline. - */ - getForCompute(computeNode: ComputeNode, bindings: BindGroup[]): ComputePipeline; - /** - * Returns a render pipeline for the given render object. - * - * @param {RenderObject} renderObject - The render object. - * @param {?Array} [promises=null] - An array of compilation promises which is only relevant in context of `Renderer.compileAsync()`. - * @return {RenderObjectPipeline} The render pipeline. - */ - getForRender(renderObject: RenderObject, promises?: Promise[] | null): RenderObjectPipeline; - /** - * Checks if the render pipeline for the given render object is ready for drawing. - * Returns false if the GPU pipeline is still being compiled asynchronously. - * - * @param {RenderObject} renderObject - The render object. - * @return {boolean} True if the pipeline is ready for drawing. - */ - isReady(renderObject: RenderObject): boolean; - /** - * Deletes the pipeline for the given render object. - * - * @param {RenderObject} object - The render object. - * @return {?Object} The deleted dictionary. - */ - delete(object: RenderObject): unknown; - /** - * Updates the pipeline for the given render object. - * - * @param {RenderObject} renderObject - The render object. - */ - updateForRender(renderObject: RenderObject): void; - /** - * Returns a compute pipeline for the given parameters. - * - * @private - * @param {Node} computeNode - The compute node. - * @param {ProgrammableStage} stageCompute - The programmable stage representing the compute shader. - * @param {string} cacheKey - The cache key. - * @param {Array} bindings - The bindings. - * @return {ComputePipeline} The compute pipeline. - */ - private _getComputePipeline; - /** - * Returns a render pipeline for the given parameters. - * - * @private - * @param {RenderObject} renderObject - The render object. - * @param {ProgrammableStage} stageVertex - The programmable stage representing the vertex shader. - * @param {ProgrammableStage} stageFragment - The programmable stage representing the fragment shader. - * @param {string} cacheKey - The cache key. - * @param {?Array} promises - An array of compilation promises which is only relevant in context of `Renderer.compileAsync()`. - * @return {RenderObjectPipeline} The render pipeline. - */ - private _getRenderPipeline; - /** - * Computes a cache key representing a compute pipeline. - * - * @private - * @param {Node} computeNode - The compute node. - * @param {ProgrammableStage} stageCompute - The programmable stage representing the compute shader. - * @return {string} The cache key. - */ - private _getComputeCacheKey; - /** - * Computes a cache key representing a render pipeline. - * - * @private - * @param {RenderObject} renderObject - The render object. - * @param {ProgrammableStage} stageVertex - The programmable stage representing the vertex shader. - * @param {ProgrammableStage} stageFragment - The programmable stage representing the fragment shader. - * @return {string} The cache key. - */ - private _getRenderCacheKey; - /** - * Releases the given pipeline. - * - * @private - * @param {Pipeline} pipeline - The pipeline to release. - */ - private _releasePipeline; - /** - * Releases the shader program. - * - * @private - * @param {Object} program - The shader program to release. - */ - private _releaseProgram; - /** - * Returns `true` if the compute pipeline for the given compute node requires an update. - * - * @private - * @param {Node} computeNode - The compute node. - * @return {boolean} Whether the compute pipeline for the given compute node requires an update or not. - */ - private _needsComputeUpdate; - /** - * Returns `true` if the render pipeline for the given render object requires an update. - * - * @private - * @param {RenderObject} renderObject - The render object. - * @return {boolean} Whether the render object for the given render object requires an update or not. - */ - private _needsRenderUpdate; -} - -export default Pipelines; diff --git a/types/three/src/renderers/common/ProgrammableStage.d.ts b/types/three/src/renderers/common/ProgrammableStage.d.ts deleted file mode 100644 index 281619ac8b0f59..00000000000000 --- a/types/three/src/renderers/common/ProgrammableStage.d.ts +++ /dev/null @@ -1,73 +0,0 @@ -import NodeAttribute from "../../nodes/core/NodeAttribute.js"; - -/** - * Class for representing programmable stages which are vertex, - * fragment or compute shaders. Unlike fixed-function states (like blending), - * they represent the programmable part of a pipeline. - * - * @private - */ -declare class ProgrammableStage { - /** - * Constructs a new programmable stage. - * - * @param {string} code - The shader code. - * @param {('vertex'|'fragment'|'compute')} stage - The type of stage. - * @param {string} name - The name of the shader. - * @param {?Array} [transforms=null] - The transforms (only relevant for compute stages with WebGL 2 which uses Transform Feedback). - * @param {?Array} [attributes=null] - The attributes (only relevant for compute stages with WebGL 2 which uses Transform Feedback). - */ - constructor( - code: string, - stage: "vertex" | "fragment" | "compute", - name: string, - transforms?: unknown[] | null, - attributes?: NodeAttribute[] | null, - ); - /** - * The id of the programmable stage. - * - * @type {number} - */ - id: number; - /** - * The shader code. - * - * @type {string} - */ - code: string; - /** - * The type of stage. - * - * @type {string} - */ - stage: "vertex" | "fragment" | "compute"; - /** - * The name of the stage. - * This is used for debugging purposes. - * - * @type {string} - */ - name: string; - /** - * The transforms (only relevant for compute stages with WebGL 2 which uses Transform Feedback). - * - * @type {?Array} - */ - transforms: unknown[] | null; - /** - * The attributes (only relevant for compute stages with WebGL 2 which uses Transform Feedback). - * - * @type {?Array} - */ - attributes: NodeAttribute[] | null; - /** - * How often the programmable stage is currently in use. - * - * @type {number} - * @default 0 - */ - usedTimes: number; -} - -export default ProgrammableStage; diff --git a/types/three/src/renderers/common/RenderBundle.d.ts b/types/three/src/renderers/common/RenderBundle.d.ts deleted file mode 100644 index d8dbbf152fa298..00000000000000 --- a/types/three/src/renderers/common/RenderBundle.d.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { Camera } from "../../cameras/Camera.js"; -import BundleGroup from "./BundleGroup.js"; -import RenderContext from "./RenderContext.js"; - -/** - * This module is used to represent render bundles inside the renderer - * for further processing. - * - * @private - */ -declare class RenderBundle { - /** - * Constructs a new bundle group. - * - * @param {BundleGroup} bundleGroup - The bundle group. - * @param {Camera} camera - The camera the bundle group is rendered with. - * @param {RenderContext} renderContext - The render context the bundle is rendered with. - */ - constructor(bundleGroup: BundleGroup, camera: Camera, renderContext: RenderContext); - bundleGroup: BundleGroup; - camera: Camera; - renderContext: RenderContext; -} - -export default RenderBundle; diff --git a/types/three/src/renderers/common/RenderBundles.d.ts b/types/three/src/renderers/common/RenderBundles.d.ts deleted file mode 100644 index 9d2b31b4a652d1..00000000000000 --- a/types/three/src/renderers/common/RenderBundles.d.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { Camera } from "../../cameras/Camera.js"; -import BundleGroup from "./BundleGroup.js"; -import ChainMap from "./ChainMap.js"; -import RenderBundle from "./RenderBundle.js"; -import RenderContext from "./RenderContext.js"; - -/** - * This renderer module manages render bundles. - * - * @private - */ -declare class RenderBundles { - /** - * A chain map for maintaining the render bundles. - * - * @type {ChainMap} - */ - bundles: ChainMap; - /** - * Returns a render bundle for the given bundle group and camera. - * - * @param {BundleGroup} bundleGroup - The bundle group. - * @param {Camera} camera - The camera the bundle group is rendered with. - * @param {RenderContext} renderContext - The render context the bundle is rendered with. - * @return {RenderBundle} The render bundle. - */ - get(bundleGroup: BundleGroup, camera: Camera, renderContext: RenderContext): RenderBundle; - /** - * Frees all internal resources. - */ - dispose(): void; -} - -export default RenderBundles; diff --git a/types/three/src/renderers/common/RenderContext.d.ts b/types/three/src/renderers/common/RenderContext.d.ts deleted file mode 100644 index 324b834bfae1f9..00000000000000 --- a/types/three/src/renderers/common/RenderContext.d.ts +++ /dev/null @@ -1,235 +0,0 @@ -import { Camera } from "../../cameras/Camera.js"; -import { RenderTarget } from "../../core/RenderTarget.js"; -import { Vector4 } from "../../math/Vector4.js"; -import MRTNode from "../../nodes/core/MRTNode.js"; -import { DepthTexture } from "../../textures/DepthTexture.js"; -import { Texture } from "../../textures/Texture.js"; -import ClippingContext from "./ClippingContext.js"; - -/** - * Any render or compute command is executed in a specific context that defines - * the state of the renderer and its backend. Typical examples for such context - * data are the current clear values or data from the active framebuffer. This - * module is used to represent these contexts as objects. - * - * @private - */ -declare class RenderContext { - /** - * The context's ID. - * - * @type {number} - */ - id: number; - /** - * The MRT configuration. - * - * @type {?MRTNode} - * @default null - */ - mrt: MRTNode | null; - /** - * Whether the current active framebuffer has a color attachment. - * - * @type {boolean} - * @default true - */ - color: boolean; - /** - * Whether the color attachment should be cleared or not. - * - * @type {boolean} - * @default true - */ - clearColor: boolean; - /** - * The clear color value. - * - * @type {Object} - * @default true - */ - clearColorValue: { - r: number; - g: number; - b: number; - a: number; - }; - /** - * Whether the current active framebuffer has a depth attachment. - * - * @type {boolean} - * @default true - */ - depth: boolean; - /** - * Whether the depth attachment should be cleared or not. - * - * @type {boolean} - * @default true - */ - clearDepth: boolean; - /** - * The clear depth value. - * - * @type {number} - * @default 1 - */ - clearDepthValue: number; - /** - * Whether the current active framebuffer has a stencil attachment. - * - * @type {boolean} - * @default false - */ - stencil: boolean; - /** - * Whether the stencil attachment should be cleared or not. - * - * @type {boolean} - * @default true - */ - clearStencil: boolean; - /** - * The clear stencil value. - * - * @type {number} - * @default 1 - */ - clearStencilValue: number; - /** - * By default the viewport encloses the entire framebuffer If a smaller - * viewport is manually defined, this property is to `true` by the renderer. - * - * @type {boolean} - * @default false - */ - viewport: boolean; - /** - * The viewport value. This value is in physical pixels meaning it incorporates - * the renderer's pixel ratio. The viewport property of render targets or - * the renderer is in logical pixels. - * - * @type {Vector4} - */ - viewportValue: Vector4; - /** - * When the scissor test is active and scissor rectangle smaller than the - * framebuffers dimensions, this property is to `true` by the renderer. - * - * @type {boolean} - * @default false - */ - scissor: boolean; - /** - * The scissor rectangle. - * - * @type {Vector4} - */ - scissorValue: Vector4; - /** - * The active render target. - * - * @type {?RenderTarget} - * @default null - */ - renderTarget: RenderTarget | null; - /** - * The textures of the active render target. - * `null` when no render target is set. - * - * @type {?Array} - * @default null - */ - textures: Texture[] | null; - /** - * The depth texture of the active render target. - * `null` when no render target is set. - * - * @type {?DepthTexture} - * @default null - */ - depthTexture: DepthTexture | null; - /** - * The active cube face. - * - * @type {number} - * @default 0 - */ - activeCubeFace: number; - /** - * The active mipmap level. - * - * @type {number} - * @default 0 - */ - activeMipmapLevel: number; - /** - * The number of MSAA samples. This value is always `1` when - * MSAA isn't used. - * - * @type {number} - * @default 1 - */ - sampleCount: number; - /** - * The active render target's width in physical pixels. - * - * @type {number} - * @default 0 - */ - width: number; - /** - * The active render target's height in physical pixels. - * - * @type {number} - * @default 0 - */ - height: number; - /** - * The occlusion query count. - * - * @type {number} - * @default 0 - */ - occlusionQueryCount: number; - /** - * The current clipping context. - * - * @type {?ClippingContext} - * @default null - */ - clippingContext: ClippingContext | null; - /** - * The current camera. - * - * @type {?Camera} - * @default null - */ - camera: Camera | null; - /** - * This flag can be used for type testing. - * - * @type {boolean} - * @readonly - * @default true - */ - readonly isRenderContext: boolean; - /** - * Returns the cache key of this render context. - * - * @return {number} The cache key. - */ - getCacheKey(): number; -} - -/** - * Computes a cache key for the given render context. This key - * should identify the render target state so it is possible to - * configure the correct attachments in the respective backend. - * - * @param {RenderContext} renderContext - The render context. - * @return {number} The cache key. - */ -export function getCacheKey(renderContext: RenderContext): number; - -export default RenderContext; diff --git a/types/three/src/renderers/common/RenderContexts.d.ts b/types/three/src/renderers/common/RenderContexts.d.ts deleted file mode 100644 index 423b904fc083e2..00000000000000 --- a/types/three/src/renderers/common/RenderContexts.d.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { RenderTarget } from "../../core/RenderTarget.js"; -import MRTNode from "../../nodes/core/MRTNode.js"; -import RenderContext from "./RenderContext.js"; -import Renderer from "./Renderer.js"; - -/** - * This module manages the render contexts of the renderer. - * - * @private - */ -declare class RenderContexts { - /** - * Constructs a new render context management component. - * - * @param {Renderer} renderer - The renderer. - */ - constructor(renderer: Renderer); - /** - * The renderer. - * - * @type {Renderer} - */ - renderer: Renderer; - /** - * A dictionary that manages render contexts. - * - * @type {Object} - */ - _renderContexts: { - [x: string]: RenderContext; - }; - /** - * Returns a render context for the given scene, camera and render target. - * - * @param {?RenderTarget} [renderTarget=null] - The active render target. - * @param {?MRTNode} [mrt=null] - The MRT configuration - * @param {?number} [callDepth=0] - The call depth of the renderer. - * @return {RenderContext} The render context. - */ - get(renderTarget?: RenderTarget | null, mrt?: MRTNode | null, callDepth?: number | null): RenderContext; - /** - * Frees internal resources. - */ - dispose(): void; -} - -export default RenderContexts; diff --git a/types/three/src/renderers/common/RenderList.d.ts b/types/three/src/renderers/common/RenderList.d.ts deleted file mode 100644 index 1840d42d00f16a..00000000000000 --- a/types/three/src/renderers/common/RenderList.d.ts +++ /dev/null @@ -1,226 +0,0 @@ -import { Camera } from "../../cameras/Camera.js"; -import { BufferGeometry, GeometryGroup } from "../../core/BufferGeometry.js"; -import { Object3D } from "../../core/Object3D.js"; -import { Light } from "../../lights/Light.js"; -import { Material } from "../../materials/Material.js"; -import LightsNode from "../../nodes/lighting/LightsNode.js"; -import { Scene } from "../../scenes/Scene.js"; -import BundleGroup from "./BundleGroup.js"; -import ClippingContext from "./ClippingContext.js"; -import Lighting from "./Lighting.js"; - -export interface Bundle { - bundleGroup: BundleGroup; - camera: Camera; - renderList: RenderList; -} - -export interface RenderItem { - id: number | null; - object: Object3D | null; - geometry: BufferGeometry | null; - material: Material | null; - groupOrder: number | null; - renderOrder: number | null; - z: number | null; - group: GeometryGroup | null; - clippingContext: ClippingContext | null; -} - -/** - * When the renderer analyzes the scene at the beginning of a render call, - * it stores 3D object for further processing in render lists. Depending on the - * properties of a 3D objects (like their transformation or material state), the - * objects are maintained in ordered lists for the actual rendering. - * - * Render lists are unique per scene and camera combination. - * - * @private - * @augments Pipeline - */ -declare class RenderList { - /** - * Constructs a render list. - * - * @param {Lighting} lighting - The lighting management component. - * @param {Scene} scene - The scene. - * @param {Camera} camera - The camera the scene is rendered with. - */ - constructor(lighting: Lighting, scene: Scene, camera: Camera); - /** - * 3D objects are transformed into render items and stored in this array. - * - * @type {Array} - */ - renderItems: RenderItem[]; - /** - * The current render items index. - * - * @type {number} - * @default 0 - */ - renderItemsIndex: number; - /** - * A list with opaque render items. - * - * @type {Array} - */ - opaque: RenderItem[]; - /** - * A list with transparent render items which require - * double pass rendering (e.g. transmissive objects). - * - * @type {Array} - */ - transparentDoublePass: RenderItem[]; - /** - * A list with transparent render items. - * - * @type {Array} - */ - transparent: RenderItem[]; - /** - * A list with transparent render bundle data. - * - * @type {Array} - */ - bundles: Bundle[]; - /** - * The render list's lights node. This node is later - * relevant for the actual analytical light nodes which - * compute the scene's lighting in the shader. - * - * @type {LightsNode} - */ - lightsNode: LightsNode; - /** - * The scene's lights stored in an array. This array - * is used to setup the lights node. - * - * @type {Array} - */ - lightsArray: Light[]; - /** - * The scene. - * - * @type {Scene} - */ - scene: Scene; - /** - * The camera the scene is rendered with. - * - * @type {Camera} - */ - camera: Camera; - /** - * How many objects perform occlusion query tests. - * - * @type {number} - * @default 0 - */ - occlusionQueryCount: number; - /** - * This method is called right at the beginning of a render call - * before the scene is analyzed. It prepares the internal data - * structures for the upcoming render lists generation. - * - * @return {RenderList} A reference to this render list. - */ - begin(): this; - /** - * Returns a render item for the giving render item state. The state is defined - * by a series of object-related parameters. - * - * The method avoids object creation by holding render items and reusing them in - * subsequent render calls (just with different property values). - * - * @param {Object3D} object - The 3D object. - * @param {BufferGeometry} geometry - The 3D object's geometry. - * @param {Material} material - The 3D object's material. - * @param {number} groupOrder - The current group order. - * @param {number} z - Th 3D object's depth value (z value in clip space). - * @param {?number} group - {?Object} group - Only relevant for objects using multiple materials. This represents a group entry from the respective `BufferGeometry`. - * @param {ClippingContext} clippingContext - The current clipping context. - * @return {Object} The render item. - */ - getNextRenderItem( - object: Object3D, - geometry: BufferGeometry, - material: Material, - groupOrder: number, - z: number, - group: GeometryGroup | null, - clippingContext: ClippingContext, - ): RenderItem; - /** - * Pushes the given object as a render item to the internal render lists. - * The selected lists depend on the object properties. - * - * @param {Object3D} object - The 3D object. - * @param {BufferGeometry} geometry - The 3D object's geometry. - * @param {Material} material - The 3D object's material. - * @param {number} groupOrder - The current group order. - * @param {number} z - Th 3D object's depth value (z value in clip space). - * @param {?number} group - {?Object} group - Only relevant for objects using multiple materials. This represents a group entry from the respective `BufferGeometry`. - * @param {ClippingContext} clippingContext - The current clipping context. - */ - push( - object: Object3D, - geometry: BufferGeometry, - material: Material, - groupOrder: number, - z: number, - group: GeometryGroup | null, - clippingContext: ClippingContext, - ): void; - /** - * Inserts the given object as a render item at the start of the internal render lists. - * The selected lists depend on the object properties. - * - * @param {Object3D} object - The 3D object. - * @param {BufferGeometry} geometry - The 3D object's geometry. - * @param {Material} material - The 3D object's material. - * @param {number} groupOrder - The current group order. - * @param {number} z - Th 3D object's depth value (z value in clip space). - * @param {?number} group - {?Object} group - Only relevant for objects using multiple materials. This represents a group entry from the respective `BufferGeometry`. - * @param {ClippingContext} clippingContext - The current clipping context. - */ - unshift( - object: Object3D, - geometry: BufferGeometry, - material: Material, - groupOrder: number, - z: number, - group: GeometryGroup | null, - clippingContext: ClippingContext, - ): void; - /** - * Pushes render bundle group data into the render list. - * - * @param {Object} group - Bundle group data. - */ - pushBundle(group: Bundle): void; - /** - * Pushes a light into the render list. - * - * @param {Light} light - The light. - */ - pushLight(light: Light): void; - /** - * Sorts the internal render lists. - * - * @param {?function(any, any): number} customOpaqueSort - A custom sort function for opaque objects. - * @param {?function(any, any): number} customTransparentSort - A custom sort function for transparent objects. - */ - sort( - customOpaqueSort: ((a: RenderItem, b: RenderItem) => number) | null, - customTransparentSort: ((a: RenderItem, b: RenderItem) => number) | null, - ): void; - /** - * This method performs finalizing tasks right after the render lists - * have been generated. - */ - finish(): void; -} - -export default RenderList; diff --git a/types/three/src/renderers/common/RenderLists.d.ts b/types/three/src/renderers/common/RenderLists.d.ts deleted file mode 100644 index 8a53d17a003e0c..00000000000000 --- a/types/three/src/renderers/common/RenderLists.d.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { Camera } from "../../cameras/Camera.js"; -import { Scene } from "../../scenes/Scene.js"; -import ChainMap from "./ChainMap.js"; -import Lighting from "./Lighting.js"; -import RenderList from "./RenderList.js"; - -/** - * This renderer module manages the render lists which are unique - * per scene and camera combination. - * - * @private - */ -declare class RenderLists { - /** - * Constructs a render lists management component. - * - * @param {Lighting} lighting - The lighting management component. - */ - constructor(lighting: Lighting); - /** - * The lighting management component. - * - * @type {Lighting} - */ - lighting: Lighting; - /** - * The internal chain map which holds the render lists. - * - * @type {ChainMap} - */ - lists: ChainMap; - /** - * Returns a render list for the given scene and camera. - * - * @param {Scene} scene - The scene. - * @param {Camera} camera - The camera. - * @return {RenderList} The render list. - */ - get(scene: Scene, camera: Camera): RenderList; - /** - * Frees all internal resources. - */ - dispose(): void; -} - -export default RenderLists; diff --git a/types/three/src/renderers/common/RenderObject.d.ts b/types/three/src/renderers/common/RenderObject.d.ts deleted file mode 100644 index 3e83d59e47a4bc..00000000000000 --- a/types/three/src/renderers/common/RenderObject.d.ts +++ /dev/null @@ -1,448 +0,0 @@ -import { Camera } from "../../cameras/Camera.js"; -import { BufferAttribute } from "../../core/BufferAttribute.js"; -import { BufferGeometry } from "../../core/BufferGeometry.js"; -import { InterleavedBuffer } from "../../core/InterleavedBuffer.js"; -import { Object3D } from "../../core/Object3D.js"; -import { Material } from "../../materials/Material.js"; -import NodeMaterialObserver from "../../materials/nodes/manager/NodeMaterialObserver.js"; -import LightsNode from "../../nodes/lighting/LightsNode.js"; -import { Scene } from "../../scenes/Scene.js"; -import BindGroup from "./BindGroup.js"; -import BundleGroup from "./BundleGroup.js"; -import ClippingContext from "./ClippingContext.js"; -import Geometries from "./Geometries.js"; -import NodeBuilderState from "./nodes/NodeBuilderState.js"; -import NodeManager from "./nodes/NodeManager.js"; -import RenderContext from "./RenderContext.js"; -import Renderer from "./Renderer.js"; -import RenderPipeline from "./RenderPipeline.js"; - -/** - * A render object is the renderer's representation of single entity that gets drawn - * with a draw command. There is no unique mapping of render objects to 3D objects in the - * scene since render objects also depend from the used material, the current render context - * and the current scene's lighting. - * - * In general, the basic process of the renderer is: - * - * - Analyze the 3D objects in the scene and generate render lists containing render items. - * - Process the render lists by calling one or more render commands for each render item. - * - For each render command, request a render object and perform the draw. - * - * The module provides an interface to get data required for the draw command like the actual - * draw parameters or vertex buffers. It also holds a series of caching related methods since - * creating render objects should only be done when necessary. - * - * @private - */ -declare class RenderObject { - /** - * Constructs a new render object. - * - * @param {NodeManager} nodes - Renderer component for managing nodes related logic. - * @param {Geometries} geometries - Renderer component for managing geometries. - * @param {Renderer} renderer - The renderer. - * @param {Object3D} object - The 3D object. - * @param {Material} material - The 3D object's material. - * @param {Scene} scene - The scene the 3D object belongs to. - * @param {Camera} camera - The camera the object should be rendered with. - * @param {LightsNode} lightsNode - The lights node. - * @param {RenderContext} renderContext - The render context. - * @param {ClippingContext} clippingContext - The clipping context. - */ - constructor( - nodes: NodeManager, - geometries: Geometries, - renderer: Renderer, - object: Object3D, - material: Material, - scene: Scene, - camera: Camera, - lightsNode: LightsNode, - renderContext: RenderContext, - clippingContext: ClippingContext, - ); - id: number; - /** - * Renderer component for managing nodes related logic. - * - * @type {NodeManager} - * @private - */ - private _nodes; - /** - * Renderer component for managing geometries. - * - * @type {Geometries} - * @private - */ - private _geometries; - /** - * The renderer. - * - * @type {Renderer} - */ - renderer: Renderer; - /** - * The 3D object. - * - * @type {Object3D} - */ - object: Object3D; - /** - * The 3D object's material. - * - * @type {Material} - */ - material: Material; - /** - * The scene the 3D object belongs to. - * - * @type {Scene} - */ - scene: Scene; - /** - * The camera the 3D object should be rendered with. - * - * @type {Camera} - */ - camera: Camera; - /** - * The lights node. - * - * @type {LightsNode} - */ - lightsNode: LightsNode; - /** - * The render context. - * - * @type {RenderContext} - */ - context: RenderContext; - /** - * The 3D object's geometry. - * - * @type {BufferGeometry} - */ - geometry: BufferGeometry; - /** - * The render object's version. - * - * @type {number} - */ - version: number; - /** - * The draw range of the geometry. - * - * @type {?Object} - * @default null - */ - drawRange: { - start: number; - count: number; - } | null; - /** - * An array holding the buffer attributes - * of the render object. This entails attribute - * definitions on geometry and node level. - * - * @type {?Array} - * @default null - */ - attributes: BufferAttribute[] | null; - /** - * An object holding the version of the - * attributes. The keys are the attribute names - * and the values are the attribute versions. - * - * @type {?Object} - * @default null - */ - attributesId: { - [x: string]: number; - } | null; - /** - * A reference to a render pipeline the render - * object is processed with. - * - * @type {RenderPipeline} - * @default null - */ - pipeline: RenderPipeline; - /** - * Only relevant for objects using - * multiple materials. This represents a group entry - * from the respective `BufferGeometry`. - * - * @type {?{start: number, count: number}} - * @default null - */ - group: { - start: number; - count: number; - } | null; - /** - * An array holding the vertex buffers which can - * be buffer attributes but also interleaved buffers. - * - * @type {?Array} - * @default null - */ - vertexBuffers: Array | null; - /** - * The parameters for the draw command. - * - * @type {?Object} - * @default null - */ - drawParams: { - vertexCount: number; - firstVertex: number; - instanceCount: number; - firstInstance: number; - } | null; - /** - * If this render object is used inside a render bundle, - * this property points to the respective bundle group. - * - * @type {?BundleGroup} - * @default null - */ - bundle: BundleGroup | null; - /** - * The clipping context. - * - * @type {ClippingContext} - */ - clippingContext: ClippingContext; - /** - * The clipping context's cache key. - * - * @type {string} - */ - clippingContextCacheKey: string; - /** - * The initial node cache key. - * - * @type {number} - */ - initialNodesCacheKey: number; - /** - * The initial cache key. - * - * @type {number} - */ - initialCacheKey: number; - /** - * The node builder state. - * - * @type {?NodeBuilderState} - * @private - * @default null - */ - private _nodeBuilderState; - /** - * An array of bindings. - * - * @type {?Array} - * @private - * @default null - */ - private _bindings; - /** - * Reference to the node material observer. - * - * @type {?NodeMaterialObserver} - * @private - * @default null - */ - private _monitor; - /** - * An event listener which is defined by `RenderObjects`. It performs - * clean up tasks when `dispose()` on this render object. - * - * @method - */ - onDispose: (() => void) | null; - /** - * This flag can be used for type testing. - * - * @type {boolean} - * @readonly - * @default true - */ - readonly isRenderObject: boolean; - /** - * An event listener which is executed when `dispose()` is called on - * the material of this render object. - * - * @method - */ - onMaterialDispose: () => void; - /** - * An event listener which is executed when `dispose()` is called on - * the geometry of this render object. - * - * @method - */ - onGeometryDispose: () => void; - /** - * Updates the clipping context. - * - * @param {ClippingContext} context - The clipping context to set. - */ - updateClipping(context: ClippingContext): void; - /** - * Whether the clipping requires an update or not. - * - * @type {boolean} - * @readonly - */ - get clippingNeedsUpdate(): boolean; - /** - * The number of clipping planes defined in context of hardware clipping. - * - * @type {number} - * @readonly - */ - get hardwareClippingPlanes(): number; - /** - * Returns the node builder state of this render object. - * - * @return {NodeBuilderState} The node builder state. - */ - getNodeBuilderState(): NodeBuilderState; - /** - * Returns the node material observer of this render object. - * - * @return {NodeMaterialObserver} The node material observer. - */ - getMonitor(): NodeMaterialObserver; - /** - * Returns an array of bind groups of this render object. - * - * @return {Array} The bindings. - */ - getBindings(): BindGroup[]; - /** - * Returns a binding group by group name of this render object. - * - * @param {string} name - The name of the binding group. - * @return {?BindGroup} The bindings. - */ - getBindingGroup(name: string): BindGroup | null; - /** - * Returns the index of the render object's geometry. - * - * @return {?BufferAttribute} The index. Returns `null` for non-indexed geometries. - */ - getIndex(): BufferAttribute | null; - /** - * Returns the indirect buffer attribute. - * - * @return {?BufferAttribute} The indirect attribute. `null` if no indirect drawing is used. - */ - getIndirect(): BufferAttribute | null; - /** - * Returns the byte offset into the indirect attribute buffer. - * - * @return {number|Array} The byte offset into the indirect attribute buffer. - */ - getIndirectOffset(): number | number[]; - /** - * Returns an array that acts as a key for identifying the render object in a chain map. - * - * @return {Array} An array with object references. - */ - getChainArray(): unknown[]; - /** - * This method is used when the geometry of a 3D object has been exchanged and the - * respective render object now requires an update. - * - * @param {BufferGeometry} geometry - The geometry to set. - */ - setGeometry(geometry: BufferGeometry): void; - /** - * Returns the buffer attributes of the render object. The returned array holds - * attribute definitions on geometry and node level. - * - * @return {Array} An array with buffer attributes. - */ - getAttributes(): BufferAttribute[]; - /** - * Returns the vertex buffers of the render object. - * - * @return {Array} An array with buffer attribute or interleaved buffers. - */ - getVertexBuffers(): Array; - /** - * Returns the draw parameters for the render object. - * - * @return {?{vertexCount: number, firstVertex: number, instanceCount: number, firstInstance: number}} The draw parameters. - */ - getDrawParameters(): { - vertexCount: number; - firstVertex: number; - instanceCount: number; - firstInstance: number; - } | null; - /** - * Returns the render object's geometry cache key. - * - * The geometry cache key is part of the material cache key. - * - * @return {string} The geometry cache key. - */ - getGeometryCacheKey(): string; - /** - * Returns the render object's material cache key. - * - * The material cache key is part of the render object cache key. - * - * @return {number} The material cache key. - */ - getMaterialCacheKey(): number; - /** - * Whether the geometry requires an update or not. - * - * @type {boolean} - * @readonly - */ - get needsGeometryUpdate(): boolean; - /** - * Whether the render object requires an update or not. - * - * Note: There are two distinct places where render objects are checked for an update. - * - * 1. In `RenderObjects.get()` which is executed when the render object is request. This - * method checks the `needsUpdate` flag and recreates the render object if necessary. - * 2. In `Renderer._renderObjectDirect()` right after getting the render object via - * `RenderObjects.get()`. The render object's NodeMaterialObserver is then used to detect - * a need for a refresh due to material, geometry or object related value changes. - * - * TODO: Investigate if it's possible to merge both steps so there is only a single place - * that performs the 'needsUpdate' check. - * - * @type {boolean} - * @readonly - */ - get needsUpdate(): boolean; - /** - * Returns the dynamic cache key which represents a key that is computed per draw command. - * - * @return {number} The cache key. - */ - getDynamicCacheKey(): number; - /** - * Returns the render object's cache key. - * - * @return {number} The cache key. - */ - getCacheKey(): number; - /** - * Frees internal resources. - */ - dispose(): void; -} - -export default RenderObject; diff --git a/types/three/src/renderers/common/RenderObjectPipeline.d.ts b/types/three/src/renderers/common/RenderObjectPipeline.d.ts deleted file mode 100644 index 927aa7189568bd..00000000000000 --- a/types/three/src/renderers/common/RenderObjectPipeline.d.ts +++ /dev/null @@ -1,33 +0,0 @@ -import Pipeline from "./Pipeline.js"; -import ProgrammableStage from "./ProgrammableStage.js"; - -/** - * Class for representing render pipelines. - * - * @private - * @augments Pipeline - */ -declare class RenderObjectPipeline extends Pipeline { - /** - * Constructs a new render object pipeline. - * - * @param {string} cacheKey - The pipeline's cache key. - * @param {ProgrammableStage} vertexProgram - The pipeline's vertex shader. - * @param {ProgrammableStage} fragmentProgram - The pipeline's fragment shader. - */ - constructor(cacheKey: string, vertexProgram: ProgrammableStage, fragmentProgram: ProgrammableStage); - /** - * The pipeline's vertex shader. - * - * @type {ProgrammableStage} - */ - vertexProgram: ProgrammableStage; - /** - * The pipeline's fragment shader. - * - * @type {ProgrammableStage} - */ - fragmentProgram: ProgrammableStage; -} - -export default RenderObjectPipeline; diff --git a/types/three/src/renderers/common/RenderObjects.d.ts b/types/three/src/renderers/common/RenderObjects.d.ts deleted file mode 100644 index d4d44eb9576fd0..00000000000000 --- a/types/three/src/renderers/common/RenderObjects.d.ts +++ /dev/null @@ -1,151 +0,0 @@ -import { Camera } from "../../cameras/Camera.js"; -import { Object3D } from "../../core/Object3D.js"; -import { Material } from "../../materials/Material.js"; -import LightsNode from "../../nodes/lighting/LightsNode.js"; -import { Scene } from "../../scenes/Scene.js"; -import Bindings from "./Bindings.js"; -import ChainMap from "./ChainMap.js"; -import ClippingContext from "./ClippingContext.js"; -import Geometries from "./Geometries.js"; -import Info from "./Info.js"; -import NodeManager from "./nodes/NodeManager.js"; -import Pipelines from "./Pipelines.js"; -import RenderContext from "./RenderContext.js"; -import Renderer from "./Renderer.js"; -import RenderObject from "./RenderObject.js"; - -/** - * This module manages the render objects of the renderer. - * - * @private - */ -declare class RenderObjects { - /** - * Constructs a new render object management component. - * - * @param {Renderer} renderer - The renderer. - * @param {NodeManager} nodes - Renderer component for managing nodes related logic. - * @param {Geometries} geometries - Renderer component for managing geometries. - * @param {Pipelines} pipelines - Renderer component for managing pipelines. - * @param {Bindings} bindings - Renderer component for managing bindings. - * @param {Info} info - Renderer component for managing metrics and monitoring data. - */ - constructor( - renderer: Renderer, - nodes: NodeManager, - geometries: Geometries, - pipelines: Pipelines, - bindings: Bindings, - info: Info, - ); - /** - * The renderer. - * - * @type {Renderer} - */ - renderer: Renderer; - /** - * Renderer component for managing nodes related logic. - * - * @type {NodeManager} - */ - nodes: NodeManager; - /** - * Renderer component for managing geometries. - * - * @type {Geometries} - */ - geometries: Geometries; - /** - * Renderer component for managing pipelines. - * - * @type {Pipelines} - */ - pipelines: Pipelines; - /** - * Renderer component for managing bindings. - * - * @type {Bindings} - */ - bindings: Bindings; - /** - * Renderer component for managing metrics and monitoring data. - * - * @type {Info} - */ - info: Info; - /** - * A dictionary that manages render contexts in chain maps - * for each pass ID. - * - * @type {Object} - */ - chainMaps: { - [x: string]: ChainMap; - }; - /** - * Returns a render object for the given object and state data. - * - * @param {Object3D} object - The 3D object. - * @param {Material} material - The 3D object's material. - * @param {Scene} scene - The scene the 3D object belongs to. - * @param {Camera} camera - The camera the 3D object should be rendered with. - * @param {LightsNode} lightsNode - The lights node. - * @param {RenderContext} renderContext - The render context. - * @param {ClippingContext} clippingContext - The clipping context. - * @param {string} [passId] - An optional ID for identifying the pass. - * @return {RenderObject} The render object. - */ - get( - object: Object3D, - material: Material, - scene: Scene, - camera: Camera, - lightsNode: LightsNode, - renderContext: RenderContext, - clippingContext: ClippingContext, - passId?: string, - ): RenderObject; - /** - * Returns a chain map for the given pass ID. - * - * @param {string} [passId='default'] - The pass ID. - * @return {ChainMap} The chain map. - */ - getChainMap(passId?: string): ChainMap; - /** - * Frees internal resources. - */ - dispose(): void; - /** - * Factory method for creating render objects with the given list of parameters. - * - * @param {NodeManager} nodes - Renderer component for managing nodes related logic. - * @param {Geometries} geometries - Renderer component for managing geometries. - * @param {Renderer} renderer - The renderer. - * @param {Object3D} object - The 3D object. - * @param {Material} material - The object's material. - * @param {Scene} scene - The scene the 3D object belongs to. - * @param {Camera} camera - The camera the object should be rendered with. - * @param {LightsNode} lightsNode - The lights node. - * @param {RenderContext} renderContext - The render context. - * @param {ClippingContext} clippingContext - The clipping context. - * @param {string} [passId] - An optional ID for identifying the pass. - * @return {RenderObject} The render object. - */ - createRenderObject( - nodes: NodeManager, - geometries: Geometries, - renderer: Renderer, - object: Object3D, - material: Material, - scene: Scene, - camera: Camera, - lightsNode: LightsNode, - renderContext: RenderContext, - clippingContext: ClippingContext, - passId?: string, - ): RenderObject; -} - -export default RenderObjects; diff --git a/types/three/src/renderers/common/Renderer.d.ts b/types/three/src/renderers/common/Renderer.d.ts index efa5ad32a65290..33d265f837c634 100644 --- a/types/three/src/renderers/common/Renderer.d.ts +++ b/types/three/src/renderers/common/Renderer.d.ts @@ -7,12 +7,13 @@ import { RenderTarget } from "../../core/RenderTarget.js"; import { Material } from "../../materials/Material.js"; import { Box2 } from "../../math/Box2.js"; import { Box3 } from "../../math/Box3.js"; -import { ColorRepresentation } from "../../math/Color.js"; +import { Color, ColorRepresentation } from "../../math/Color.js"; import { Vector2 } from "../../math/Vector2.js"; import { Vector3 } from "../../math/Vector3.js"; import { Vector4 } from "../../math/Vector4.js"; import ContextNode from "../../nodes/core/ContextNode.js"; import MRTNode from "../../nodes/core/MRTNode.js"; +import Node from "../../nodes/core/Node.js"; import ComputeNode from "../../nodes/gpgpu/ComputeNode.js"; import LightsNode from "../../nodes/lighting/LightsNode.js"; import { Scene } from "../../scenes/Scene.js"; @@ -21,16 +22,22 @@ import { Texture } from "../../textures/Texture.js"; import Backend from "./Backend.js"; import CanvasTarget from "./CanvasTarget.js"; import ClippingContext from "./ClippingContext.js"; -import Color4 from "./Color4.js"; import IndirectStorageBufferAttribute from "./IndirectStorageBufferAttribute.js"; import Info from "./Info.js"; import InspectorBase from "./InspectorBase.js"; import Lighting from "./Lighting.js"; import NodeLibrary from "./nodes/NodeLibrary.js"; import ReadbackBuffer from "./ReadbackBuffer.js"; -import { RenderItem } from "./RenderList.js"; import XRManager from "./XRManager.js"; +declare module "../../scenes/Scene.js" { + interface Scene { + environmentNode?: Node<"vec3"> | null | undefined; + backgroundNode?: Node | null | undefined; + fogNode?: Node | null | undefined; + } +} + interface DeviceLostInfo { api: "WebGL" | "WebGPU"; message: string; @@ -51,6 +58,18 @@ export interface RendererParameters { multiview?: boolean | undefined; } +export interface RenderItem { + id: number | null; + object: Object3D | null; + geometry: BufferGeometry | null; + material: Material | null; + groupOrder: number | null; + renderOrder: number | null; + z: number | null; + group: GeometryGroup | null; + clippingContext: ClippingContext | null; +} + /** * Base class for renderers. */ @@ -227,287 +246,6 @@ declare class Renderer { * @type {Lighting} */ lighting: Lighting; - /** - * The number of MSAA samples. - * - * @private - * @type {number} - * @default 0 - */ - private _samples; - /** - * Callback when the canvas has been resized. - * - * @private - */ - private _onCanvasTargetResize; - /** - * The canvas target for rendering. - * - * @private - * @type {CanvasTarget} - */ - private _canvasTarget; - /** - * The inspector provides information about the internal renderer state. - * - * @private - * @type {InspectorBase} - */ - private _inspector; - /** - * This callback function can be used to provide a fallback backend, if the primary backend can't be targeted. - * - * @private - * @type {?Function} - */ - private _getFallback; - /** - * A reference to a renderer module for managing shader attributes. - * - * @private - * @type {?Attributes} - * @default null - */ - private _attributes; - /** - * A reference to a renderer module for managing geometries. - * - * @private - * @type {?Geometries} - * @default null - */ - private _geometries; - /** - * A reference to a renderer module for managing node related logic. - * - * @private - * @type {?NodeManager} - * @default null - */ - private _nodes; - /** - * A reference to a renderer module for managing the internal animation loop. - * - * @private - * @type {?Animation} - * @default null - */ - private _animation; - /** - * A reference to a renderer module for managing shader program bindings. - * - * @private - * @type {?Bindings} - * @default null - */ - private _bindings; - /** - * A reference to a renderer module for managing render objects. - * - * @private - * @type {?RenderObjects} - * @default null - */ - private _objects; - /** - * A reference to a renderer module for managing render and compute pipelines. - * - * @private - * @type {?Pipelines} - * @default null - */ - private _pipelines; - /** - * A reference to a renderer module for managing render bundles. - * - * @private - * @type {?RenderBundles} - * @default null - */ - private _bundles; - /** - * A reference to a renderer module for managing render lists. - * - * @private - * @type {?RenderLists} - * @default null - */ - private _renderLists; - /** - * A reference to a renderer module for managing render contexts. - * - * @private - * @type {?RenderContexts} - * @default null - */ - private _renderContexts; - /** - * A reference to a renderer module for managing textures. - * - * @private - * @type {?Textures} - * @default null - */ - private _textures; - /** - * A reference to a renderer module for backgrounds. - * - * @private - * @type {?Background} - * @default null - */ - private _background; - /** - * Cache for the fullscreen quad. - * This fullscreen quad is used for internal render passes - * like the tone mapping and color space output pass. - * - * @private - * @type {Map} - */ - private _quadCache; - /** - * A reference to the current render context. - * - * @private - * @type {?RenderContext} - * @default null - */ - private _currentRenderContext; - /** - * A custom sort function for the opaque render list. - * - * @private - * @type {?Function} - * @default null - */ - private _opaqueSort; - /** - * A custom sort function for the transparent render list. - * - * @private - * @type {?Function} - * @default null - */ - private _transparentSort; - /** - * Cache of framebuffer targets per canvas target. - * - * @private - * @type {Map} - */ - private _frameBufferTargets; - /** - * The clear color value. - * - * @private - * @type {Color4} - */ - private _clearColor; - /** - * The clear depth value. - * - * @private - * @type {number} - * @default 1 - */ - private _clearDepth; - /** - * The clear stencil value. - * - * @private - * @type {number} - * @default 0 - */ - private _clearStencil; - /** - * The current render target. - * - * @private - * @type {?RenderTarget} - * @default null - */ - private _renderTarget; - /** - * The active cube face. - * - * @private - * @type {number} - * @default 0 - */ - private _activeCubeFace; - /** - * The active mipmap level. - * - * @private - * @type {number} - * @default 0 - */ - private _activeMipmapLevel; - /** - * The current output render target. - * - * @private - * @type {?RenderTarget} - * @default null - */ - private _outputRenderTarget; - /** - * The MRT setting. - * - * @private - * @type {?MRTNode} - * @default null - */ - private _mrt; - /** - * This function defines how a render object is going - * to be rendered. - * - * @private - * @type {?Function} - * @default null - */ - private _renderObjectFunction; - /** - * Used to keep track of the current render object function. - * - * @private - * @type {?Function} - * @default null - */ - private _currentRenderObjectFunction; - /** - * Used to keep track of the current render bundle. - * - * @private - * @type {?RenderBundle} - * @default null - */ - private _currentRenderBundle; - /** - * Next to `_renderObjectFunction()`, this function provides another hook - * for influencing the render process of a render object. It is meant for internal - * use and only relevant for `compileAsync()` right now. Instead of using - * the default logic of `_renderObjectDirect()` which actually draws the render object, - * a different function might be used which performs no draw but just the node - * and pipeline updates. - * - * @private - * @type {Function} - */ - private _handleObjectFunction; - /** - * Indicates whether the device has been lost or not. In WebGL terms, the device - * lost is considered as a context lost. When this is set to `true`, rendering - * isn't possible anymore. - * - * @private - * @type {boolean} - * @default false - */ - private _isDeviceLost; /** * A callback function that defines what should happen when a device/context lost occurs. * @@ -515,55 +253,24 @@ declare class Renderer { */ onDeviceLost: (info: DeviceLostInfo) => void; /** - * Defines the type of output buffers. The default `HalfFloatType` is recommend for - * best quality. To save memory and bandwidth, `UnsignedByteType` might be used. - * This will reduce rendering quality though. - * - * @private - * @type {number} - * @default HalfFloatType - */ - private _outputBufferType; - /** - * A cache for shadow nodes per material - * - * @private - * @type {WeakMap} - */ - private _cacheShadowNodes; - /** - * Whether the renderer has been initialized or not. + * A callback function that defines what should happen when an uncaptured + * backend error is reported (e.g. a WebGPU validation/out-of-memory/internal + * error raised outside an error scope). Applications can override this to + * surface errors in their own UI without letting them escalate to a device + * loss. The default implementation logs to the console. * - * @private - * @type {boolean} - * @default false - */ - private _initialized; - /** - * The call depth of the renderer. Counts the number of - * nested render calls. - * - * @private - * @type {number} - * @default - 1 - */ - private _callDepth; - /** - * A reference to the promise which initializes the renderer. - * - * @private - * @type {?Promise} - * @default null + * @type {Function} */ - private _initPromise; + onError: (errorMessage: string) => void; /** - * An array of compilation promises which are used in `compileAsync()`. + * When an override material is in use, this property points to the current + * source material during the rendering of a render object. * * @private - * @type {?Array} + * @type {?Material} * @default null */ - private _compilationPromises; + private _currentSourceMaterial; /** * Whether the renderer should render transparent render objects or not. * @@ -760,22 +467,6 @@ declare class Renderer { * @return {number} The output buffer type. */ getColorBufferType(): TextureDataType; - /** - * Default implementation of the device lost callback. - * - * @private - * @param {Object} info - Information about the context lost. - */ - private _onDeviceLost; - /** - * Renders the given render bundle. - * - * @private - * @param {Object} bundle - Render bundle data. - * @param {Scene} sceneRef - The scene the render bundle belongs to. - * @param {LightsNode} lightsNode - The lights node. - */ - private _renderBundle; /** * Renders the scene or 3D object with the given camera. This method can only be called * if the renderer has been initialized. When using `render()` inside an animation loop, @@ -799,33 +490,6 @@ declare class Renderer { * @return {boolean} Whether the renderer has been initialized or not. */ get initialized(): boolean; - /** - * Returns an internal render target which is used when computing the output tone mapping - * and color space conversion. Unlike in `WebGLRenderer`, this is done in a separate render - * pass and not inline to achieve more correct results. - * - * @private - * @return {?RenderTarget} The render target. The method returns `null` if no output conversion should be applied. - */ - private _getFrameBufferTarget; - /** - * Renders the scene or 3D object with the given camera. - * - * @private - * @param {Object3D} scene - The scene or 3D object to render. - * @param {Camera} camera - The camera to render the scene with. - * @param {boolean} [useFrameBufferTarget=true] - Whether to use a framebuffer target or not. - * @return {RenderContext} The current render context. - */ - private _renderScene; - _setXRLayerSize(width: number, height: number): void; - /** - * The output pass performs tone mapping and color space conversion. - * - * @private - * @param {RenderTarget} renderTarget - The current render target. - */ - private _renderOutput; /** * Returns the maximum available anisotropy for texture filtering. * @@ -1011,7 +675,7 @@ declare class Renderer { * @param {Color} target - The method writes the result in this target object. * @return {Color} The clear color. */ - getClearColor(target: Color4): Color4; + getClearColor(target: Color): Color; /** * Defines the clear color and optionally the clear alpha. * @@ -1207,12 +871,6 @@ declare class Renderer { * @return {CanvasTarget} The current canvas target. */ getCanvasTarget(): CanvasTarget; - /** - * Resets the renderer to the initial state before WebXR started. - * - * @private - */ - private _resetXRState; /** * Callback for {@link Renderer#setRenderObjectFunction}. * @@ -1397,58 +1055,6 @@ declare class Renderer { textureIndex?: number, faceIndex?: number, ): Promise; - /** - * Analyzes the given 3D object's hierarchy and builds render lists from the - * processed hierarchy. - * - * @private - * @param {Object3D} object - The 3D object to process (usually a scene). - * @param {Camera} camera - The camera the object is rendered with. - * @param {number} groupOrder - The group order is derived from the `renderOrder` of groups and is used to group 3D objects within groups. - * @param {RenderList} renderList - The current render list. - * @param {ClippingContext} clippingContext - The current clipping context. - */ - private _projectObject; - /** - * Renders the given render bundles. - * - * @private - * @param {Array} bundles - Array with render bundle data. - * @param {Scene} sceneRef - The scene the render bundles belong to. - * @param {LightsNode} lightsNode - The current lights node. - */ - private _renderBundles; - /** - * Renders the transparent objects from the given render lists. - * - * @private - * @param {Array} renderList - The transparent render list. - * @param {Array} doublePassList - The list of transparent objects which require a double pass (e.g. because of transmission). - * @param {Camera} camera - The camera the render list should be rendered with. - * @param {Scene} scene - The scene the render list belongs to. - * @param {LightsNode} lightsNode - The current lights node. - */ - private _renderTransparents; - /** - * Renders the objects from the given render list. - * - * @private - * @param {Array} renderList - The render list. - * @param {Camera} camera - The camera the render list should be rendered with. - * @param {Scene} scene - The scene the render list belongs to. - * @param {LightsNode} lightsNode - The current lights node. - * @param {?string} [passId=null] - An optional ID for identifying the pass. - */ - private _renderObjects; - /** - * Retrieves shadow nodes for the given material. This is used to setup shadow passes. - * The result is cached per material and updated when the material's version changes. - * - * @private - * @param {Material} material - * @returns {Object} - The shadow nodes for the material. - */ - private _getShadowNodes; /** * This method represents the default render object function that manages the render lifecycle * of the object. @@ -1481,36 +1087,6 @@ declare class Renderer { * @return {boolean} Whether the compatibility is supported or not. */ hasCompatibility(name: string): boolean; - /** - * This method represents the default `_handleObjectFunction` implementation which creates - * a render object from the given data and performs the draw command with the selected backend. - * - * @private - * @param {Object3D} object - The 3D object. - * @param {Material} material - The object's material. - * @param {Scene} scene - The scene the 3D object belongs to. - * @param {Camera} camera - The camera the object should be rendered with. - * @param {LightsNode} lightsNode - The current lights node. - * @param {?{start: number, count: number}} group - Only relevant for objects using multiple materials. This represents a group entry from the respective `BufferGeometry`. - * @param {ClippingContext} clippingContext - The clipping context. - * @param {string} [passId] - An optional ID for identifying the pass. - */ - private _renderObjectDirect; - /** - * A different implementation for `_handleObjectFunction` which only makes sure the object is ready for rendering. - * Used in `compileAsync()`. - * - * @private - * @param {Object3D} object - The 3D object. - * @param {Material} material - The object's material. - * @param {Scene} scene - The scene the 3D object belongs to. - * @param {Camera} camera - The camera the object should be rendered with. - * @param {LightsNode} lightsNode - The current lights node. - * @param {?{start: number, count: number}} group - Only relevant for objects using multiple materials. This represents a group entry from the respective `BufferGeometry`. - * @param {ClippingContext} clippingContext - The clipping context. - * @param {string} [passId] - An optional ID for identifying the pass. - */ - private _createObjectPipeline; /** * Alias for `compileAsync()`. * diff --git a/types/three/src/renderers/common/RendererUtils.d.ts b/types/three/src/renderers/common/RendererUtils.d.ts index 5a25a27894ac12..9b095989bd0d77 100644 --- a/types/three/src/renderers/common/RendererUtils.d.ts +++ b/types/three/src/renderers/common/RendererUtils.d.ts @@ -11,7 +11,6 @@ import LightsNode from "../../nodes/lighting/LightsNode.js"; import { Scene } from "../../scenes/Scene.js"; import { CubeTexture } from "../../textures/CubeTexture.js"; import { Texture } from "../../textures/Texture.js"; -import Color4 from "./Color4.js"; import Renderer from "./Renderer.js"; // renderer state @@ -36,7 +35,7 @@ export interface RendererState { | null; pixelRatio: number; mrt: MRTNode | null; - clearColor: Color4; + clearColor: Color; clearAlpha: number; autoClear: boolean; scissorTest: boolean; diff --git a/types/three/src/renderers/common/SampledTexture.d.ts b/types/three/src/renderers/common/SampledTexture.d.ts deleted file mode 100644 index 919a93c44a912d..00000000000000 --- a/types/three/src/renderers/common/SampledTexture.d.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { Texture } from "../../textures/Texture.js"; -import Sampler from "./Sampler.js"; - -declare class SampledTexture extends Sampler { - id: number; - - store: boolean; - - mipLevel: number; - - readonly isSampledTexture: true; - - constructor(name: string, texture: Texture | null); -} - -declare class SampledArrayTexture extends SampledTexture { - readonly isSampledArrayTexture: true; -} - -declare class Sampled3DTexture extends SampledTexture { - readonly isSampled3DTexture: true; -} - -declare class SampledCubeTexture extends SampledTexture { - readonly isSampledCubeTexture: true; -} - -export { Sampled3DTexture, SampledArrayTexture, SampledCubeTexture, SampledTexture }; diff --git a/types/three/src/renderers/common/Sampler.d.ts b/types/three/src/renderers/common/Sampler.d.ts deleted file mode 100644 index 8fbf5ece809c8c..00000000000000 --- a/types/three/src/renderers/common/Sampler.d.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { Texture } from "../../textures/Texture.js"; -import Binding from "./Binding.js"; - -declare class Sampler extends Binding { - version: number; - - generation: number | null; - - samplerKey: string; - - readonly isSampler: true; - - constructor(name: string, texture: Texture | null); - - set texture(value: Texture | null); - get texture(): Texture | null; -} - -export default Sampler; diff --git a/types/three/src/renderers/common/Textures.d.ts b/types/three/src/renderers/common/Textures.d.ts deleted file mode 100644 index 1dc6d85fad6f97..00000000000000 --- a/types/three/src/renderers/common/Textures.d.ts +++ /dev/null @@ -1,125 +0,0 @@ -import { RenderTarget } from "../../core/RenderTarget.js"; -import { Vector3 } from "../../math/Vector3.js"; -import { Texture } from "../../textures/Texture.js"; -import Backend from "./Backend.js"; -import DataMap from "./DataMap.js"; -import Info from "./Info.js"; -import Renderer from "./Renderer.js"; - -interface TextureOptions { - width?: number; - height?: number; - depth?: number; - needsMipmaps?: boolean; - levels?: number; -} - -/** - * This module manages the textures of the renderer. - * - * @private - * @augments DataMap - */ -declare class Textures extends DataMap { - /** - * Constructs a new texture management component. - * - * @param {Renderer} renderer - The renderer. - * @param {Backend} backend - The renderer's backend. - * @param {Info} info - Renderer component for managing metrics and monitoring data. - */ - constructor(renderer: Renderer, backend: Backend, info: Info); - /** - * The renderer. - * - * @type {Renderer} - */ - renderer: Renderer; - /** - * The backend. - * - * @type {Backend} - */ - backend: Backend; - /** - * Renderer component for managing metrics and monitoring data. - * - * @type {Info} - */ - info: Info; - /** - * Updates the given render target. Based on the given render target configuration, - * it updates the texture states representing the attachments of the framebuffer. - * - * @param {RenderTarget} renderTarget - The render target to update. - * @param {number} [activeMipmapLevel=0] - The active mipmap level. - */ - updateRenderTarget(renderTarget: RenderTarget, activeMipmapLevel?: number): void; - /** - * Updates the given texture. Depending on the texture state, this method - * triggers the upload of texture data to the GPU memory. If the texture data are - * not yet ready for the upload, it uses default texture data for as a placeholder. - * - * @param {Texture} texture - The texture to update. - * @param {Object} [options={}] - The options. - */ - updateTexture(texture: Texture, options?: TextureOptions): void; - /** - * Updates the sampler for the given texture. This method has no effect - * for the WebGL backend since it has no concept of samplers. Texture - * parameters are configured with the `texParameter()` command for each - * texture. - * - * In WebGPU, samplers are objects like textures and it's possible to share - * them when the texture parameters match. - * - * @param {Texture} texture - The texture to update the sampler for. - * @return {string} The current sampler key. - */ - updateSampler(texture: Texture): string; - /** - * Computes the size of the given texture and writes the result - * into the target vector. This vector is also returned by the - * method. - * - * If no texture data are available for the compute yet, the method - * returns default size values. - * - * @param {Texture} texture - The texture to compute the size for. - * @param {Vector3} target - The target vector. - * @return {Vector3} The target vector. - */ - getSize(texture: Texture, target?: Vector3): Vector3; - /** - * Computes the number of mipmap levels for the given texture. - * - * @param {Texture} texture - The texture. - * @param {number} width - The texture's width. - * @param {number} height - The texture's height. - * @return {number} The number of mipmap levels. - */ - getMipLevels(texture: Texture, width: number, height: number): number; - /** - * Returns `true` if the given texture makes use of mipmapping. - * - * @param {Texture} texture - The texture. - * @return {boolean} Whether mipmaps are required or not. - */ - needsMipmaps(texture: Texture): boolean; - /** - * Frees internal resources when the given render target isn't - * required anymore. - * - * @param {RenderTarget} renderTarget - The render target to destroy. - */ - _destroyRenderTarget(renderTarget: RenderTarget): void; - /** - * Frees internal resource when the given texture isn't - * required anymore. - * - * @param {Texture} texture - The texture to destroy. - */ - _destroyTexture(texture: Texture): void; -} - -export default Textures; diff --git a/types/three/src/renderers/common/TimestampQueryPool.d.ts b/types/three/src/renderers/common/TimestampQueryPool.d.ts index f34d38405325f8..22d8868acf95e9 100644 --- a/types/three/src/renderers/common/TimestampQueryPool.d.ts +++ b/types/three/src/renderers/common/TimestampQueryPool.d.ts @@ -91,7 +91,7 @@ declare abstract class TimestampQueryPool { * @param {string} uid - A unique identifier for the render context. * @return {boolean} True if a timestamp is available, false otherwise. */ - hasTimestamp(uid: string): boolean; + hasTimestampQuery(uid: string): boolean; /** * Allocate queries for a specific uid. * diff --git a/types/three/src/renderers/common/Uniform.d.ts b/types/three/src/renderers/common/Uniform.d.ts deleted file mode 100644 index 4e947de1014170..00000000000000 --- a/types/three/src/renderers/common/Uniform.d.ts +++ /dev/null @@ -1,262 +0,0 @@ -import { Color } from "../../math/Color.js"; -import { Matrix2 } from "../../math/Matrix2.js"; -import { Matrix3 } from "../../math/Matrix3.js"; -import { Matrix4 } from "../../math/Matrix4.js"; -import { Vector2 } from "../../math/Vector2.js"; -import { Vector3 } from "../../math/Vector3.js"; -import { Vector4 } from "../../math/Vector4.js"; - -/** - * Represents a Number uniform. - * - * @private - * @augments Uniform - */ -export class NumberUniform extends Uniform { - /** - * Constructs a new Number uniform. - * - * @param {string} name - The uniform's name. - * @param {number} value - The uniform's value. - */ - constructor(name: string, value?: number); - /** - * This flag can be used for type testing. - * - * @type {boolean} - * @readonly - * @default true - */ - readonly isNumberUniform: boolean; -} -/** - * Represents a Vector2 uniform. - * - * @private - * @augments Uniform - */ -export class Vector2Uniform extends Uniform { - /** - * Constructs a new Number uniform. - * - * @param {string} name - The uniform's name. - * @param {Vector2} value - The uniform's value. - */ - constructor(name: string, value?: Vector2); - /** - * This flag can be used for type testing. - * - * @type {boolean} - * @readonly - * @default true - */ - readonly isVector2Uniform: boolean; -} -/** - * Represents a Vector3 uniform. - * - * @private - * @augments Uniform - */ -export class Vector3Uniform extends Uniform { - /** - * Constructs a new Number uniform. - * - * @param {string} name - The uniform's name. - * @param {Vector3} value - The uniform's value. - */ - constructor(name: string, value?: Vector3); - /** - * This flag can be used for type testing. - * - * @type {boolean} - * @readonly - * @default true - */ - readonly isVector3Uniform: boolean; -} -/** - * Represents a Vector4 uniform. - * - * @private - * @augments Uniform - */ -export class Vector4Uniform extends Uniform { - /** - * Constructs a new Number uniform. - * - * @param {string} name - The uniform's name. - * @param {Vector4} value - The uniform's value. - */ - constructor(name: string, value?: Vector4); - /** - * This flag can be used for type testing. - * - * @type {boolean} - * @readonly - * @default true - */ - readonly isVector4Uniform: boolean; -} -/** - * Represents a Color uniform. - * - * @private - * @augments Uniform - */ -export class ColorUniform extends Uniform { - /** - * Constructs a new Number uniform. - * - * @param {string} name - The uniform's name. - * @param {Color} value - The uniform's value. - */ - constructor(name: string, value?: Color); - /** - * This flag can be used for type testing. - * - * @type {boolean} - * @readonly - * @default true - */ - readonly isColorUniform: boolean; -} -/** - * Represents a Matrix2 uniform. - * - * @private - * @augments Uniform - */ -export class Matrix2Uniform extends Uniform { - /** - * Constructs a new Number uniform. - * - * @param {string} name - The uniform's name. - * @param {Matrix2} value - The uniform's value. - */ - constructor(name: string, value?: Matrix2); - /** - * This flag can be used for type testing. - * - * @type {boolean} - * @readonly - * @default true - */ - readonly isMatrix2Uniform: boolean; -} -/** - * Represents a Matrix3 uniform. - * - * @private - * @augments Uniform - */ -export class Matrix3Uniform extends Uniform { - /** - * Constructs a new Number uniform. - * - * @param {string} name - The uniform's name. - * @param {Matrix3} value - The uniform's value. - */ - constructor(name: string, value?: Matrix3); - /** - * This flag can be used for type testing. - * - * @type {boolean} - * @readonly - * @default true - */ - readonly isMatrix3Uniform: boolean; -} -/** - * Represents a Matrix4 uniform. - * - * @private - * @augments Uniform - */ -export class Matrix4Uniform extends Uniform { - /** - * Constructs a new Number uniform. - * - * @param {string} name - The uniform's name. - * @param {Matrix4} value - The uniform's value. - */ - constructor(name: string, value?: Matrix4); - /** - * This flag can be used for type testing. - * - * @type {boolean} - * @readonly - * @default true - */ - readonly isMatrix4Uniform: boolean; -} -/** - * Abstract base class for uniforms. - * - * @abstract - * @private - */ -declare class Uniform { - /** - * Constructs a new uniform. - * - * @param {string} name - The uniform's name. - * @param {any} value - The uniform's value. - */ - constructor(name: string, value: TValue); - /** - * The uniform's name. - * - * @type {string} - */ - name: string; - /** - * The uniform's value. - * - * @type {any} - */ - value: TValue; - /** - * Used to build the uniform buffer according to the STD140 layout. - * Derived uniforms will set this property to a data type specific - * value. - * - * @type {number} - */ - boundary: number; - /** - * The item size. Derived uniforms will set this property to a data - * type specific value. - * - * @type {number} - */ - itemSize: number; - /** - * This property is set by {@link UniformsGroup} and marks - * the start position in the uniform buffer. - * - * @type {number} - */ - offset: number; - /** - * This property is set by {@link UniformsGroup} and marks - * the index position in the uniform array. - * - * @type {number} - */ - index: number; - /** - * Sets the uniform's value. - * - * @param {any} value - The value to set. - */ - setValue(value: TValue): void; - /** - * Returns the uniform's value. - * - * @return {any} The value. - */ - getValue(): TValue; -} - -export type { Uniform }; diff --git a/types/three/src/renderers/common/UniformBuffer.d.ts b/types/three/src/renderers/common/UniformBuffer.d.ts deleted file mode 100644 index c6088e81aed414..00000000000000 --- a/types/three/src/renderers/common/UniformBuffer.d.ts +++ /dev/null @@ -1,20 +0,0 @@ -import Buffer from "./Buffer.js"; - -/** - * Represents a uniform buffer binding type. - * - * @private - * @augments Buffer - */ -declare class UniformBuffer extends Buffer { - /** - * This flag can be used for type testing. - * - * @type {boolean} - * @readonly - * @default true - */ - readonly isUniformBuffer: boolean; -} - -export default UniformBuffer; diff --git a/types/three/src/renderers/common/UniformsGroup.d.ts b/types/three/src/renderers/common/UniformsGroup.d.ts deleted file mode 100644 index 5813e3470cea2e..00000000000000 --- a/types/three/src/renderers/common/UniformsGroup.d.ts +++ /dev/null @@ -1,152 +0,0 @@ -import { - ColorNodeUniform, - Matrix3NodeUniform, - Matrix4NodeUniform, - NodeUniformGPU, - NumberNodeUniform, - Vector2NodeUniform, - Vector3NodeUniform, - Vector4NodeUniform, -} from "./nodes/NodeUniform.js"; -import { Uniform } from "./Uniform.js"; -import UniformBuffer from "./UniformBuffer.js"; - -/** - * This class represents a uniform buffer binding but with - * an API that allows to maintain individual uniform objects. - * - * @private - * @augments UniformBuffer - */ -declare class UniformsGroup extends UniformBuffer { - /** - * Constructs a new uniforms group. - * - * @param {string} name - The group's name. - */ - constructor(name: string); - /** - * This flag can be used for type testing. - * - * @type {boolean} - * @readonly - * @default true - */ - readonly isUniformsGroup: boolean; - /** - * An array with the raw uniform values. - * - * @private - * @type {?Array} - * @default null - */ - private _values; - /** - * An array of uniform objects. - * - * The order of uniforms in this array must match the order of uniforms in the shader. - * - * @type {Array} - */ - uniforms: NodeUniformGPU[]; - /** - * A cache for the uniform update ranges. - * - * @private - * @type {Map} - */ - private _updateRangeCache; - /** - * Adds a uniform's update range to this buffer. - * - * @param {Uniform} uniform - The uniform. - */ - addUniformUpdateRange(uniform: Uniform): void; - /** - * Adds a uniform to this group. - * - * @param {Uniform} uniform - The uniform to add. - * @return {UniformsGroup} A reference to this group. - */ - addUniform(uniform: NodeUniformGPU): this; - /** - * Removes a uniform from this group. - * - * @param {Uniform} uniform - The uniform to remove. - * @return {UniformsGroup} A reference to this group. - */ - removeUniform(uniform: NodeUniformGPU): this; - /** - * An array with the raw uniform values. - * - * @type {Array} - */ - get values(): number[]; - /** - * Updates a given uniform by calling an update method matching - * the uniforms type. - * - * @param {Uniform} uniform - The uniform to update. - * @return {boolean} Whether the uniform has been updated or not. - */ - updateByType(uniform: NodeUniformGPU): boolean; - /** - * Updates a given Number uniform. - * - * @param {NumberUniform} uniform - The Number uniform. - * @return {boolean} Whether the uniform has been updated or not. - */ - updateNumber(uniform: NumberNodeUniform): boolean; - /** - * Updates a given Vector2 uniform. - * - * @param {Vector2Uniform} uniform - The Vector2 uniform. - * @return {boolean} Whether the uniform has been updated or not. - */ - updateVector2(uniform: Vector2NodeUniform): boolean; - /** - * Updates a given Vector3 uniform. - * - * @param {Vector3Uniform} uniform - The Vector3 uniform. - * @return {boolean} Whether the uniform has been updated or not. - */ - updateVector3(uniform: Vector3NodeUniform): boolean; - /** - * Updates a given Vector4 uniform. - * - * @param {Vector4Uniform} uniform - The Vector4 uniform. - * @return {boolean} Whether the uniform has been updated or not. - */ - updateVector4(uniform: Vector4NodeUniform): boolean; - /** - * Updates a given Color uniform. - * - * @param {ColorUniform} uniform - The Color uniform. - * @return {boolean} Whether the uniform has been updated or not. - */ - updateColor(uniform: ColorNodeUniform): boolean; - /** - * Updates a given Matrix3 uniform. - * - * @param {Matrix3Uniform} uniform - The Matrix3 uniform. - * @return {boolean} Whether the uniform has been updated or not. - */ - updateMatrix3(uniform: Matrix3NodeUniform): boolean; - /** - * Updates a given Matrix4 uniform. - * - * @param {Matrix4Uniform} uniform - The Matrix4 uniform. - * @return {boolean} Whether the uniform has been updated or not. - */ - updateMatrix4(uniform: Matrix4NodeUniform): boolean; - /** - * Returns a typed array that matches the given data type. - * - * @private - * @param {string} type - The data type. - * @return {TypedArray} The typed array. - */ - private _getBufferForType; -} - -export default UniformsGroup; diff --git a/types/three/src/renderers/common/XRManager.d.ts b/types/three/src/renderers/common/XRManager.d.ts index f25f0ba5feaa76..a39eeebed441c6 100644 --- a/types/three/src/renderers/common/XRManager.d.ts +++ b/types/three/src/renderers/common/XRManager.d.ts @@ -9,9 +9,7 @@ import { Quaternion } from "../../math/Quaternion.js"; import { Vector3 } from "../../math/Vector3.js"; import { Mesh } from "../../objects/Mesh.js"; import { XRGripSpace, XRHandSpace, XRTargetRaySpace } from "../webxr/WebXRController.js"; -import QuadMesh from "./QuadMesh.js"; import Renderer from "./Renderer.js"; -import { XRRenderTarget } from "./XRRenderTarget.js"; export interface XRManagerEventMap { sessionstart: {}; @@ -25,11 +23,11 @@ export interface LayerAttributes { stencil?: boolean | undefined; } +interface XRGPUBinding {} + /** * The XR manager is built on top of the WebXR Device API to - * manage XR sessions with `WebGPURenderer`. - * - * XR is currently only supported with a WebGL 2 backend. + * manage XR sessions with renderer backends. * * @augments EventDispatcher */ @@ -63,291 +61,6 @@ declare class XRManager * @default true */ cameraAutoUpdate: boolean; - /** - * The renderer. - * - * @private - * @type {Renderer} - */ - private _renderer; - /** - * Represents the camera for the left eye. - * - * @private - * @type {PerspectiveCamera} - */ - private _cameraL; - /** - * Represents the camera for the right eye. - * - * @private - * @type {PerspectiveCamera} - */ - private _cameraR; - /** - * A list of cameras used for rendering the XR views. - * - * @private - * @type {Array} - */ - private _cameras; - /** - * The main XR camera. - * - * @private - * @type {ArrayCamera} - */ - private _cameraXR; - /** - * The current near value of the XR camera. - * - * @private - * @type {?number} - * @default null - */ - private _currentDepthNear; - /** - * The current far value of the XR camera. - * - * @private - * @type {?number} - * @default null - */ - private _currentDepthFar; - /** - * A list of WebXR controllers requested by the application. - * - * @private - * @type {Array} - */ - private _controllers; - /** - * A list of XR input source. Each input source belongs to - * an instance of WebXRController. - * - * @private - * @type {Array} - */ - private _controllerInputSources; - /** - * The XR render target that represents the rendering destination - * during an active XR session. - * - * @private - * @type {?RenderTarget} - * @default null - */ - private _xrRenderTarget; - /** - * An array holding all the non-projection layers - * - * @private - * @type {Array} - * @default [] - */ - private _layers; - /** - * Whether the XR session uses layers. - * - * @private - * @type {boolean} - * @default false - */ - private _sessionUsesLayers; - /** - * Whether the device supports binding gl objects. - * - * @private - * @type {boolean} - * @readonly - */ - private readonly _supportsGlBinding; - /** - * Helper function to create native WebXR Layer. - * - * @private - * @type {Function} - */ - private _createXRLayer; - /** - * The current WebGL context. - * - * @private - * @type {?WebGL2RenderingContext} - * @default null - */ - private _gl; - /** - * The current animation context. - * - * @private - * @type {?Window} - * @default null - */ - private _currentAnimationContext; - /** - * The current animation loop. - * - * @private - * @type {?Function} - * @default null - */ - private _currentAnimationLoop; - /** - * The current pixel ratio. - * - * @private - * @type {?number} - * @default null - */ - private _currentPixelRatio; - /** - * The current size of the renderer's canvas - * in logical pixel unit. - * - * @private - * @type {Vector2} - */ - private _currentSize; - /** - * The default event listener for handling events inside a XR session. - * - * @private - * @type {Function} - */ - private _onSessionEvent; - /** - * The event listener for handling the end of a XR session. - * - * @private - * @type {Function} - */ - private _onSessionEnd; - /** - * The event listener for handling the `inputsourceschange` event. - * - * @private - * @type {Function} - */ - private _onInputSourcesChange; - /** - * The animation loop which is used as a replacement for the default - * animation loop of the application. It is only used when a XR session - * is active. - * - * @private - * @type {Function} - */ - private _onAnimationFrame; - /** - * The current XR reference space. - * - * @private - * @type {?XRReferenceSpace} - * @default null - */ - private _referenceSpace; - /** - * The current XR reference space type. - * - * @private - * @type {XRReferenceSpaceType} - * @default 'local-floor' - */ - private _referenceSpaceType; - /** - * A custom reference space defined by the application. - * - * @private - * @type {?XRReferenceSpace} - * @default null - */ - private _customReferenceSpace; - /** - * The framebuffer scale factor. - * - * @private - * @type {number} - * @default 1 - */ - private _framebufferScaleFactor; - /** - * The foveation factor. - * - * @private - * @type {number} - * @default 1 - */ - private _foveation; - /** - * A reference to the current XR session. - * - * @private - * @type {?XRSession} - * @default null - */ - private _session; - /** - * A reference to the current XR base layer. - * - * @private - * @type {?XRWebGLLayer} - * @default null - */ - private _glBaseLayer; - /** - * A reference to the current XR binding. - * - * @private - * @type {?XRWebGLBinding} - * @default null - */ - private _glBinding; - /** - * A reference to the current XR projection layer. - * - * @private - * @type {?XRProjectionLayer} - * @default null - */ - private _glProjLayer; - /** - * A reference to the current XR frame. - * - * @private - * @type {?XRFrame} - * @default null - */ - private _xrFrame; - /** - * Whether the browser supports the APIs necessary to use XRProjectionLayers. - * - * Note: this does not represent XRSession explicitly requesting - * `'layers'` as a feature - see `_sessionUsesLayers` and #30112 - * - * @private - * @type {boolean} - * @readonly - */ - private readonly _supportsLayers; - /** - * Whether the usage of multiview has been requested by the application or not. - * - * @private - * @type {boolean} - * @default false - * @readonly - */ - private readonly _useMultiviewIfPossible; - /** - * Whether the usage of multiview is actually enabled. This flag only evaluates to `true` - * if multiview has been requested by the application and the `OVR_multiview2` is available. - * - * @private - * @type {boolean} - * @readonly - */ - private readonly _useMultiview; /** * Returns an instance of `THREE.Group` that represents the transformation * of a XR controller in target ray space. The requested controller is defined @@ -378,7 +91,7 @@ declare class XRManager /** * Returns the foveation value. * - * @return {number|undefined} The foveation value. Returns `undefined` if no base or projection layer is defined. + * @return {number|undefined} The foveation value. */ getFoveation(): number | undefined; /** @@ -440,6 +153,15 @@ declare class XRManager * @return {'opaque'|'additive'|'alpha-blend'|undefined} The environment blend mode. Returns `undefined` when used outside of a XR session. */ getEnvironmentBlendMode(): XREnvironmentBlendMode | undefined; + /** + * Returns the current base layer. + * + * This is an `XRProjectionLayer` when the targeted XR device supports the + * WebXR Layers API, or an `XRWebGLLayer` otherwise. + * + * @return {?(XRWebGLLayer|XRProjectionLayer)} The XR base layer. + */ + getBaseLayer(): (XRWebGLLayer | XRProjectionLayer) | null; /** * Returns the current XR binding. * @@ -449,6 +171,25 @@ declare class XRManager * @return {?XRWebGLBinding} The XR binding. Returns `null` if one cannot be created. */ getBinding(): XRWebGLBinding | null; + /** + * Applies WebXR fixed foveation to the internal post-processing render target + * used by the first XR render pass before compositing into a projection layer. + * + * Browser-side `XRWebGLBinding.foveateBoundTexture()` failures are treated as + * non-fatal so they do not interrupt rendering. + * + * @param {RenderTarget} renderTarget - The internal render target. + */ + foveateBoundTexture(renderTarget: RenderTarget): void; + /** + * Returns the current XR WebGPU binding. + * + * Creates a new binding if needed and the browser is + * capable of doing so. + * + * @return {?XRGPUBinding} The XR WebGPU binding. Returns `null` if one cannot be created. + */ + getWebGPUBinding(): XRGPUBinding | null; /** * Returns the current XR frame. * @@ -544,14 +285,6 @@ declare class XRManager * @param {PerspectiveCamera} camera - The camera. */ updateCamera(camera: PerspectiveCamera): void; - /** - * Returns a WebXR controller for the given controller index. - * - * @private - * @param {number} index - The controller index. - * @return {WebXRController} The XR controller. - */ - private _getController; } export default XRManager; diff --git a/types/three/src/renderers/common/XRRenderTarget.d.ts b/types/three/src/renderers/common/XRRenderTarget.d.ts deleted file mode 100644 index 2c8ff28a1e339b..00000000000000 --- a/types/three/src/renderers/common/XRRenderTarget.d.ts +++ /dev/null @@ -1,67 +0,0 @@ -import { RenderTarget, RenderTargetOptions } from "../../core/RenderTarget.js"; - -/** - * A special type of render target that is used when rendering - * with the WebXR Device API. - * - * @private - * @augments RenderTarget - */ -export class XRRenderTarget extends RenderTarget { - /** - * Constructs a new XR render target. - * - * @param {number} [width=1] - The width of the render target. - * @param {number} [height=1] - The height of the render target. - * @param {Object} [options={}] - The configuration options. - */ - constructor(width?: number, height?: number, options?: RenderTargetOptions); - /** - * This flag can be used for type testing. - * - * @type {boolean} - * @readonly - * @default true - */ - readonly isXRRenderTarget: boolean; - /** - * Whether the attachments of the render target - * are defined by external textures. This flag is - * set to `true` when using the WebXR Layers API. - * - * @private - * @type {boolean} - * @default false - */ - private _hasExternalTextures; - /** - * Whether a depth buffer should automatically be allocated - * for this XR render target or not. - * - * Allocating a depth buffer is the default behavior of XR render - * targets. However, when using the WebXR Layers API, this flag - * must be set to `false` when the `ignoreDepthValues` property of - * the projection layers evaluates to `false`. - * - * Reference: {@link https://www.w3.org/TR/webxrlayers-1/#dom-xrprojectionlayer-ignoredepthvalues}. - * - * @private - * @type {boolean} - * @default true - */ - private _autoAllocateDepthBuffer; - /** - * Whether this render target is associated with a XRWebGLLayer. - * - * A XRWebGLLayer points to an opaque framebuffer. Basically, - * this means that you don't have access to its bound color, - * stencil and depth buffers. We need to handle this framebuffer - * differently since its textures are always bound. - * - * @private - * @type {boolean} - * @default false - */ - private _isOpaqueFramebuffer; - copy(source: XRRenderTarget): this; -} diff --git a/types/three/src/renderers/common/nodes/NodeBuilderState.d.ts b/types/three/src/renderers/common/nodes/NodeBuilderState.d.ts deleted file mode 100644 index 828ecb286b92f7..00000000000000 --- a/types/three/src/renderers/common/nodes/NodeBuilderState.d.ts +++ /dev/null @@ -1,121 +0,0 @@ -import NodeMaterialObserver from "../../../materials/nodes/manager/NodeMaterialObserver.js"; -import Node from "../../../nodes/core/Node.js"; -import NodeAttribute from "../../../nodes/core/NodeAttribute.js"; -import BindGroup from "../BindGroup.js"; - -/** - * This module represents the state of a node builder after it was - * used to build the nodes for a render object. The state holds the - * results of the build for further processing in the renderer. - * - * Render objects with identical cache keys share the same node builder state. - * - * @private - */ -declare class NodeBuilderState { - /** - * Constructs a new node builder state. - * - * @param {string} vertexShader - The native vertex shader code. - * @param {string} fragmentShader - The native fragment shader code. - * @param {string} computeShader - The native compute shader code. - * @param {Array} nodeAttributes - An array of node attributes. - * @param {Array} bindings - An array of bind groups. - * @param {Array} updateNodes - An array of nodes that implement their `update()` method. - * @param {Array} updateBeforeNodes - An array of nodes that implement their `updateBefore()` method. - * @param {Array} updateAfterNodes - An array of nodes that implement their `updateAfter()` method. - * @param {NodeMaterialObserver} observer - A node material observer. - * @param {Array} transforms - An array with transform attribute objects. Only relevant when using compute shaders with WebGL 2. - */ - constructor( - vertexShader: string, - fragmentShader: string, - computeShader: string, - nodeAttributes: NodeAttribute[], - bindings: BindGroup[], - updateNodes: Node[], - updateBeforeNodes: Node[], - updateAfterNodes: Node[], - observer: NodeMaterialObserver, - transforms?: unknown[], - ); - /** - * The native vertex shader code. - * - * @type {string} - */ - vertexShader: string; - /** - * The native fragment shader code. - * - * @type {string} - */ - fragmentShader: string; - /** - * The native compute shader code. - * - * @type {string} - */ - computeShader: string; - /** - * An array with transform attribute objects. - * Only relevant when using compute shaders with WebGL 2. - * - * @type {Array} - */ - transforms: unknown[]; - /** - * An array of node attributes representing - * the attributes of the shaders. - * - * @type {Array} - */ - nodeAttributes: NodeAttribute[]; - /** - * An array of bind groups representing the uniform or storage - * buffers, texture or samplers of the shader. - * - * @type {Array} - */ - bindings: BindGroup[]; - /** - * An array of nodes that implement their `update()` method. - * - * @type {Array} - */ - updateNodes: Node[]; - /** - * An array of nodes that implement their `updateBefore()` method. - * - * @type {Array} - */ - updateBeforeNodes: Node[]; - /** - * An array of nodes that implement their `updateAfter()` method. - * - * @type {Array} - */ - updateAfterNodes: Node[]; - /** - * A node material observer. - * - * @type {NodeMaterialObserver} - */ - observer: NodeMaterialObserver; - /** - * How often this state is used by render objects. - * - * @type {number} - */ - usedTimes: number; - /** - * This method is used to create a array of bind groups based - * on the existing bind groups of this state. Shared groups are - * not cloned. - * - * @return {Array} A array of bind groups. - */ - createBindings(): BindGroup[]; -} - -export default NodeBuilderState; diff --git a/types/three/src/renderers/common/nodes/NodeLibrary.d.ts b/types/three/src/renderers/common/nodes/NodeLibrary.d.ts index 019d66f29e59e8..bd54195252d8e4 100644 --- a/types/three/src/renderers/common/nodes/NodeLibrary.d.ts +++ b/types/three/src/renderers/common/nodes/NodeLibrary.d.ts @@ -1,10 +1,3 @@ -import { ToneMapping } from "../../../constants.js"; -import { Light } from "../../../lights/Light.js"; -import { Material } from "../../../materials/Material.js"; -import NodeMaterial from "../../../materials/nodes/NodeMaterial.js"; -import Node from "../../../nodes/core/Node.js"; -import AnalyticLightNode from "../../../nodes/lighting/AnalyticLightNode.js"; - /** * The purpose of a node library is to assign node implementations * to existing library features. In `WebGPURenderer` lights, materials @@ -14,116 +7,6 @@ import AnalyticLightNode from "../../../nodes/lighting/AnalyticLightNode.js"; * @private */ declare class NodeLibrary { - /** - * A weak map that maps lights to light nodes. - * - * @type {WeakMap} - */ - lightNodes: WeakMap<{ - new(): Light; - }, { - new(light: Light): AnalyticLightNode; - }>; - /** - * A map that maps materials to node materials. - * - * @type {Map} - */ - materialNodes: Map; - /** - * A map that maps tone mapping techniques (constants) - * to tone mapping node functions. - * - * @type {Map} - */ - toneMappingNodes: Map Node>; - /** - * Returns a matching node material instance for the given material object. - * - * This method also assigns/copies the properties of the given material object - * to the node material. This is done to make sure the current material - * configuration carries over to the node version. - * - * @param {Material} material - A material. - * @return {NodeMaterial} The corresponding node material. - */ - fromMaterial(material: Material): NodeMaterial; - /** - * Adds a tone mapping node function for a tone mapping technique (constant). - * - * @param {Function} toneMappingNode - The tone mapping node function. - * @param {number} toneMapping - The tone mapping. - */ - addToneMapping(toneMappingNode: (color: Node, exposure: Node) => Node, toneMapping: ToneMapping): void; - /** - * Returns a tone mapping node function for a tone mapping technique (constant). - * - * @param {number} toneMapping - The tone mapping. - * @return {?Function} The tone mapping node function. Returns `null` if no node function is found. - */ - getToneMappingFunction(toneMapping: ToneMapping): ((color: Node, exposure: Node) => Node) | null; - /** - * Returns a node material class definition for a material type. - * - * @param {string} materialType - The material type. - * @return {?NodeMaterial.constructor} The node material class definition. Returns `null` if no node material is found. - */ - getMaterialNodeClass(materialType: string): (new() => NodeMaterial) | null; - /** - * Adds a node material class definition for a given material type. - * - * @param {NodeMaterial.constructor} materialNodeClass - The node material class definition. - * @param {string} materialClassType - The material type. - */ - addMaterial(materialNodeClass: { - new(): NodeMaterial; - }, materialClassType: string): void; - /** - * Returns a light node class definition for a light class definition. - * - * @param {Light.constructor} light - The light class definition. - * @return {?AnalyticLightNode.constructor} The light node class definition. Returns `null` if no light node is found. - */ - getLightNodeClass(light: { - new(): Light; - }): - | ({ - new(light: Light): AnalyticLightNode; - }) - | null; - /** - * Adds a light node class definition for a given light class definition. - * - * @param {AnalyticLightNode.constructor} lightNodeClass - The light node class definition. - * @param {Light.constructor} lightClass - The light class definition. - */ - addLight(lightNodeClass: { - new(light: TLight): AnalyticLightNode; - }, lightClass: { - new(): TLight; - }): void; - /** - * Adds a node class definition for the given type to the provided type library. - * - * @param {Node.constructor} nodeClass - The node class definition. - * @param {number|string} type - The object type. - * @param {Map} library - The type library. - */ - addType(nodeClass: TNodeClass, type: TType, library: Map): void; - /** - * Adds a node class definition for the given class definition to the provided type library. - * - * @param {Node.constructor} nodeClass - The node class definition. - * @param {Node.constructor} baseClass - The class definition. - * @param {WeakMap} library - The type library. - */ - addClass( - nodeClass: TNodeClass, - baseClass: TBaseClass, - library: WeakMap, - ): void; } export default NodeLibrary; diff --git a/types/three/src/renderers/common/nodes/NodeManager.d.ts b/types/three/src/renderers/common/nodes/NodeManager.d.ts deleted file mode 100644 index 2acfc45023f4f3..00000000000000 --- a/types/three/src/renderers/common/nodes/NodeManager.d.ts +++ /dev/null @@ -1,309 +0,0 @@ -import { Camera } from "../../../cameras/Camera.js"; -import { Object3D } from "../../../core/Object3D.js"; -import { Material } from "../../../materials/Material.js"; -import Node from "../../../nodes/core/Node.js"; -import NodeFrame from "../../../nodes/core/NodeFrame.js"; -import ComputeNode from "../../../nodes/gpgpu/ComputeNode.js"; -import LightsNode from "../../../nodes/lighting/LightsNode.js"; -import { Scene } from "../../../scenes/Scene.js"; -import { Texture } from "../../../textures/Texture.js"; -import Backend from "../Backend.js"; -import ChainMap from "../ChainMap.js"; -import DataMap from "../DataMap.js"; -import Renderer from "../Renderer.js"; -import RenderObject from "../RenderObject.js"; -import NodeBuilderState from "./NodeBuilderState.js"; -import NodeUniformsGroup from "./NodeUniformsGroup.js"; - -declare module "../../../scenes/Scene.js" { - interface Scene { - environmentNode?: Node<"vec3"> | null | undefined; - backgroundNode?: Node | null | undefined; - fogNode?: Node | null | undefined; - } -} - -/** - * This renderer module manages node-related objects and is the - * primary interface between the renderer and the node system. - * - * @private - * @augments DataMap - */ -declare class NodeManager extends DataMap { - /** - * Constructs a new nodes management component. - * - * @param {Renderer} renderer - The renderer. - * @param {Backend} backend - The renderer's backend. - */ - constructor(renderer: Renderer, backend: Backend); - /** - * The renderer. - * - * @type {Renderer} - */ - renderer: Renderer; - /** - * The renderer's backend. - * - * @type {Backend} - */ - backend: Backend; - /** - * The node frame. - * - * @type {Renderer} - */ - nodeFrame: NodeFrame; - /** - * A cache for managing node builder states. - * - * @type {Map} - */ - nodeBuilderCache: Map; - /** - * A cache for managing data cache key data. - * - * @type {ChainMap} - */ - callHashCache: ChainMap; - /** - * A cache for managing node uniforms group data. - * - * @type {ChainMap} - */ - groupsData: ChainMap; - /** - * Queue for pending async builds to limit concurrent compilation. - * - * @private - * @type {Array} - */ - private _buildQueue; - /** - * Whether an async build is currently in progress. - * - * @private - * @type {boolean} - */ - private _buildInProgress; - /** - * A cache for managing node objects of - * scene properties like fog or environments. - * - * @type {Object} - */ - cacheLib: { - [x: string]: WeakMap; - }; - /** - * Returns `true` if the given node uniforms group must be updated or not. - * - * @param {NodeUniformsGroup} nodeUniformsGroup - The node uniforms group. - * @return {boolean} Whether the node uniforms group requires an update or not. - */ - updateGroup(nodeUniformsGroup: NodeUniformsGroup): boolean; - /** - * Returns the cache key for the given render object. - * - * @param {RenderObject} renderObject - The render object. - * @return {number} The cache key. - */ - getForRenderCacheKey(renderObject: RenderObject): number; - /** - * Creates a node builder configured for the given render object and material. - * - * @private - * @param {RenderObject} renderObject - The render object. - * @param {Material} material - The material to use. - * @return {NodeBuilder} The configured node builder. - */ - private _createNodeBuilder; - /** - * Returns a node builder state for the given render object. - * - * @param {RenderObject} renderObject - The render object. - * @param {boolean} [useAsync=false] - Whether to use async build with yielding. - * @return {NodeBuilderState|Promise} The node builder state (or Promise if async). - */ - getForRender(renderObject: RenderObject, useAsync?: boolean): NodeBuilderState | Promise; - /** - * Async version of getForRender() that yields to main thread during build. - * Use this in compileAsync() to prevent blocking the main thread. - * - * @param {RenderObject} renderObject - The render object. - * @return {Promise} A promise that resolves to the node builder state. - */ - getForRenderAsync(renderObject: RenderObject): Promise; - /** - * Returns nodeBuilderState if ready, null if pending async build. - * Queues async build on first call for cache miss. - * Use this in render() path to enable non-blocking compilation. - * - * @param {RenderObject} renderObject - The render object. - * @return {?NodeBuilderState} The node builder state, or null if still building. - */ - getForRenderDeferred(renderObject: RenderObject): NodeBuilderState | null; - /** - * Processes the build queue one item at a time. - * This ensures builds don't all run simultaneously and freeze the main thread. - * - * @private - */ - private _processBuildQueue; - /** - * Deletes the given object from the internal data map - * - * @param {any} object - The object to delete. - * @return {?Object} The deleted dictionary. - */ - delete(object: unknown): unknown | null; - /** - * Returns a node builder state for the given compute node. - * - * @param {Node} computeNode - The compute node. - * @return {NodeBuilderState} The node builder state. - */ - getForCompute(computeNode: ComputeNode): NodeBuilderState; - /** - * Creates a node builder state for the given node builder. - * - * @private - * @param {NodeBuilder} nodeBuilder - The node builder. - * @return {NodeBuilderState} The node builder state. - */ - private _createNodeBuilderState; - /** - * Returns an environment node for the current configured - * scene environment. - * - * @param {Scene} scene - The scene. - * @return {Node} A node representing the current scene environment. - */ - getEnvironmentNode(scene: Scene): Node; - /** - * Returns a background node for the current configured - * scene background. - * - * @param {Scene} scene - The scene. - * @return {Node} A node representing the current scene background. - */ - getBackgroundNode(scene: Scene): Node; - /** - * Returns a fog node for the current configured scene fog. - * - * @param {Scene} scene - The scene. - * @return {Node} A node representing the current scene fog. - */ - getFogNode(scene: Scene): Node; - /** - * Returns a cache key for the given scene and lights node. - * This key is used by `RenderObject` as a part of the dynamic - * cache key (a key that must be checked every time the render - * objects is drawn). - * - * @param {Scene} scene - The scene. - * @param {LightsNode} lightsNode - The lights node. - * @return {number} The cache key. - */ - getCacheKey(scene: Scene, lightsNode: LightsNode): number; - /** - * A boolean that indicates whether tone mapping should be enabled - * or not. - * - * @type {boolean} - */ - get isToneMappingState(): boolean; - /** - * If a scene background is configured, this method makes sure to - * represent the background with a corresponding node-based implementation. - * - * @param {Scene} scene - The scene. - */ - updateBackground(scene: Scene): void; - /** - * This method is part of the caching of nodes which are used to represents the - * scene's background, fog or environment. - * - * @param {string} type - The type of object to cache. - * @param {Object} object - The object. - * @param {Function} callback - A callback that produces a node representation for the given object. - * @param {boolean} [forceUpdate=false] - Whether an update should be enforced or not. - * @return {Node} The node representation. - */ - getCacheNode(type: string, object: object, callback: () => Node | undefined, forceUpdate?: boolean): Node; - /** - * If a scene fog is configured, this method makes sure to - * represent the fog with a corresponding node-based implementation. - * - * @param {Scene} scene - The scene. - */ - updateFog(scene: Scene): void; - /** - * If a scene environment is configured, this method makes sure to - * represent the environment with a corresponding node-based implementation. - * - * @param {Scene} scene - The scene. - */ - updateEnvironment(scene: Scene): void; - getNodeFrame( - renderer?: Renderer, - scene?: Scene | null, - object?: Object3D | null, - camera?: Camera | null, - material?: Material | null, - ): NodeFrame; - getNodeFrameForRender(renderObject: RenderObject): NodeFrame; - /** - * Returns the current output cache key. - * - * @return {string} The output cache key. - */ - getOutputCacheKey(): string; - /** - * Returns a node that represents the output configuration (tone mapping and - * color space) for the current target. - * - * @param {Texture} outputTarget - The output target. - * @return {Node} The output node. - */ - getOutputNode(outputTarget: Texture): Node; - /** - * Triggers the call of `updateBefore()` methods - * for all nodes of the given render object. - * - * @param {RenderObject} renderObject - The render object. - */ - updateBefore(renderObject: RenderObject): void; - /** - * Triggers the call of `updateAfter()` methods - * for all nodes of the given render object. - * - * @param {RenderObject} renderObject - The render object. - */ - updateAfter(renderObject: RenderObject): void; - /** - * Triggers the call of `update()` methods - * for all nodes of the given compute node. - * - * @param {Node} computeNode - The compute node. - */ - updateForCompute(computeNode: ComputeNode): void; - /** - * Triggers the call of `update()` methods - * for all nodes of the given render object. - * - * @param {RenderObject} renderObject - The render object. - */ - updateForRender(renderObject: RenderObject): void; - /** - * Returns `true` if the given render object requires a refresh. - * - * @param {RenderObject} renderObject - The render object. - * @return {boolean} Whether the given render object requires a refresh or not. - */ - needsRefresh(renderObject: RenderObject): boolean; -} - -export default NodeManager; diff --git a/types/three/src/renderers/common/nodes/NodeSampledTexture.d.ts b/types/three/src/renderers/common/nodes/NodeSampledTexture.d.ts deleted file mode 100644 index 881eb9c6a18b9e..00000000000000 --- a/types/three/src/renderers/common/nodes/NodeSampledTexture.d.ts +++ /dev/null @@ -1,29 +0,0 @@ -import TextureNode from "../../../nodes/accessors/TextureNode.js"; -import UniformGroupNode from "../../../nodes/core/UniformGroupNode.js"; -import { SampledTexture } from "../SampledTexture.js"; - -type GPUStorageTextureAccess = "read-only" | "read-write" | "write-only"; - -declare class NodeSampledTexture extends SampledTexture { - textureNode: TextureNode | undefined; - groupNode: UniformGroupNode; - - access: "read-write" | "read-only" | "write-only"; - - constructor( - name: string, - textureNode: TextureNode | undefined, - groupNode: UniformGroupNode, - access?: GPUStorageTextureAccess | null, - ); -} - -declare class NodeSampledCubeTexture extends NodeSampledTexture { - readonly isSampledCubeTexture: true; -} - -declare class NodeSampledTexture3D extends NodeSampledTexture { - readonly isSampledTexture3D: true; -} - -export { NodeSampledCubeTexture, NodeSampledTexture, NodeSampledTexture3D }; diff --git a/types/three/src/renderers/common/nodes/NodeSampler.d.ts b/types/three/src/renderers/common/nodes/NodeSampler.d.ts deleted file mode 100644 index 60db177d5887fc..00000000000000 --- a/types/three/src/renderers/common/nodes/NodeSampler.d.ts +++ /dev/null @@ -1,12 +0,0 @@ -import TextureNode from "../../../nodes/accessors/TextureNode.js"; -import UniformGroupNode from "../../../nodes/core/UniformGroupNode.js"; -import Sampler from "../Sampler.js"; - -declare class NodeSampler extends Sampler { - textureNode: TextureNode | undefined; - groupNode: UniformGroupNode; - constructor(name: string, textureNode: TextureNode | undefined, groupNode: UniformGroupNode); - update(): void; -} - -export default NodeSampler; diff --git a/types/three/src/renderers/common/nodes/NodeUniform.d.ts b/types/three/src/renderers/common/nodes/NodeUniform.d.ts deleted file mode 100644 index a01bb19a5d5afd..00000000000000 --- a/types/three/src/renderers/common/nodes/NodeUniform.d.ts +++ /dev/null @@ -1,250 +0,0 @@ -import { Color } from "../../../math/Color.js"; -import { Matrix2 } from "../../../math/Matrix2.js"; -import { Matrix3 } from "../../../math/Matrix3.js"; -import { Matrix4 } from "../../../math/Matrix4.js"; -import { Vector2 } from "../../../math/Vector2.js"; -import { Vector3 } from "../../../math/Vector3.js"; -import { Vector4 } from "../../../math/Vector4.js"; -import NodeUniform from "../../../nodes/core/NodeUniform.js"; -import { - ColorUniform, - Matrix2Uniform, - Matrix3Uniform, - Matrix4Uniform, - NumberUniform, - Vector2Uniform, - Vector3Uniform, - Vector4Uniform, -} from "../Uniform.js"; - -/** - * A special form of Number uniform binding type. - * It's value is managed by a node object. - * - * @private - * @augments NumberUniform - */ -export class NumberNodeUniform extends NumberUniform { - /** - * Constructs a new node-based Number uniform. - * - * @param {NodeUniform} nodeUniform - The node uniform. - */ - constructor(nodeUniform: NodeUniform); - /** - * The node uniform. - * - * @type {NodeUniform} - */ - nodeUniform: NodeUniform; - /** - * Overwritten to return the value of the node uniform. - * - * @return {number} The value. - */ - getValue(): number; - /** - * Returns the node uniform data type. - * - * @return {string} The data type. - */ - getType(): string; -} -/** - * A special form of Vector2 uniform binding type. - * It's value is managed by a node object. - * - * @private - * @augments Vector2Uniform - */ -export class Vector2NodeUniform extends Vector2Uniform { - /** - * Constructs a new node-based Vector2 uniform. - * - * @param {NodeUniform} nodeUniform - The node uniform. - */ - constructor(nodeUniform: NodeUniform); - /** - * The node uniform. - * - * @type {NodeUniform} - */ - nodeUniform: NodeUniform; - /** - * Returns the node uniform data type. - * - * @return {string} The data type. - */ - getType(): string; -} -/** - * A special form of Vector3 uniform binding type. - * It's value is managed by a node object. - * - * @private - * @augments Vector3Uniform - */ -export class Vector3NodeUniform extends Vector3Uniform { - /** - * Constructs a new node-based Vector3 uniform. - * - * @param {NodeUniform} nodeUniform - The node uniform. - */ - constructor(nodeUniform: NodeUniform); - /** - * The node uniform. - * - * @type {NodeUniform} - */ - nodeUniform: NodeUniform; - /** - * Returns the node uniform data type. - * - * @return {string} The data type. - */ - getType(): string; -} -/** - * A special form of Vector4 uniform binding type. - * It's value is managed by a node object. - * - * @private - * @augments Vector4Uniform - */ -export class Vector4NodeUniform extends Vector4Uniform { - /** - * Constructs a new node-based Vector4 uniform. - * - * @param {NodeUniform} nodeUniform - The node uniform. - */ - constructor(nodeUniform: NodeUniform); - /** - * The node uniform. - * - * @type {NodeUniform} - */ - nodeUniform: NodeUniform; - /** - * Returns the node uniform data type. - * - * @return {string} The data type. - */ - getType(): string; -} -/** - * A special form of Color uniform binding type. - * It's value is managed by a node object. - * - * @private - * @augments ColorUniform - */ -export class ColorNodeUniform extends ColorUniform { - /** - * Constructs a new node-based Color uniform. - * - * @param {NodeUniform} nodeUniform - The node uniform. - */ - constructor(nodeUniform: NodeUniform); - /** - * The node uniform. - * - * @type {NodeUniform} - */ - nodeUniform: NodeUniform; - /** - * Returns the node uniform data type. - * - * @return {string} The data type. - */ - getType(): string; -} -/** - * A special form of Matrix2 uniform binding type. - * It's value is managed by a node object. - * - * @private - * @augments Matrix2Uniform - */ -export class Matrix2NodeUniform extends Matrix2Uniform { - /** - * Constructs a new node-based Matrix2 uniform. - * - * @param {NodeUniform} nodeUniform - The node uniform. - */ - constructor(nodeUniform: NodeUniform); - /** - * The node uniform. - * - * @type {NodeUniform} - */ - nodeUniform: NodeUniform; - /** - * Returns the node uniform data type. - * - * @return {string} The data type. - */ - getType(): string; -} -/** - * A special form of Matrix3 uniform binding type. - * It's value is managed by a node object. - * - * @private - * @augments Matrix3Uniform - */ -export class Matrix3NodeUniform extends Matrix3Uniform { - /** - * Constructs a new node-based Matrix3 uniform. - * - * @param {NodeUniform} nodeUniform - The node uniform. - */ - constructor(nodeUniform: NodeUniform); - /** - * The node uniform. - * - * @type {NodeUniform} - */ - nodeUniform: NodeUniform; - /** - * Returns the node uniform data type. - * - * @return {string} The data type. - */ - getType(): string; -} -/** - * A special form of Matrix4 uniform binding type. - * It's value is managed by a node object. - * - * @private - * @augments Matrix4Uniform - */ -export class Matrix4NodeUniform extends Matrix4Uniform { - /** - * Constructs a new node-based Matrix4 uniform. - * - * @param {NodeUniform} nodeUniform - The node uniform. - */ - constructor(nodeUniform: NodeUniform); - /** - * The node uniform. - * - * @type {NodeUniform} - */ - nodeUniform: NodeUniform; - /** - * Returns the node uniform data type. - * - * @return {string} The data type. - */ - getType(): string; -} - -export type NodeUniformGPU = - | NumberNodeUniform - | Vector2NodeUniform - | Vector3NodeUniform - | Vector4NodeUniform - | ColorNodeUniform - | Matrix3NodeUniform - | Matrix4NodeUniform; diff --git a/types/three/src/renderers/common/nodes/NodeUniformsGroup.d.ts b/types/three/src/renderers/common/nodes/NodeUniformsGroup.d.ts deleted file mode 100644 index 8dfe5e108e578b..00000000000000 --- a/types/three/src/renderers/common/nodes/NodeUniformsGroup.d.ts +++ /dev/null @@ -1,41 +0,0 @@ -import UniformGroupNode from "../../../nodes/core/UniformGroupNode.js"; -import UniformsGroup from "../UniformsGroup.js"; - -/** - * A special form of uniforms group that represents - * the individual uniforms as node-based uniforms. - * - * @private - * @augments UniformsGroup - */ -declare class NodeUniformsGroup extends UniformsGroup { - /** - * Constructs a new node-based uniforms group. - * - * @param {string} name - The group's name. - * @param {UniformGroupNode} groupNode - The uniform group node. - */ - constructor(name: string, groupNode: UniformGroupNode); - /** - * The group's ID. - * - * @type {number} - */ - id: number; - /** - * The uniform group node. - * - * @type {UniformGroupNode} - */ - groupNode: UniformGroupNode; - /** - * This flag can be used for type testing. - * - * @type {boolean} - * @readonly - * @default true - */ - readonly isNodeUniformsGroup: boolean; -} - -export default NodeUniformsGroup; diff --git a/types/three/src/renderers/webgl-fallback/WebGLBackend.d.ts b/types/three/src/renderers/webgl-fallback/WebGLBackend.d.ts index 74f01173ec8515..31f456c9fe3641 100644 --- a/types/three/src/renderers/webgl-fallback/WebGLBackend.d.ts +++ b/types/three/src/renderers/webgl-fallback/WebGLBackend.d.ts @@ -8,7 +8,7 @@ export interface WebGLBackendParameters extends BackendParameters { export default class WebGLBackend extends Backend { readonly isWebGLBackend: boolean; - constructor(parameters?: BackendParameters); + constructor(parameters?: WebGLBackendParameters); get coordinateSystem(): CoordinateSystem; diff --git a/types/three/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.d.ts b/types/three/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.d.ts index 1f275bbb6db1c7..185451ef2048f0 100644 --- a/types/three/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.d.ts +++ b/types/three/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.d.ts @@ -1,19 +1,9 @@ import { Object3D } from "../../../core/Object3D.js"; -import { NodeShaderStage } from "../../../nodes/core/constants.js"; import NodeBuilder from "../../../nodes/core/NodeBuilder.js"; import Renderer from "../../common/Renderer.js"; declare class GLSLNodeBuilder extends NodeBuilder { constructor(object: Object3D, renderer: Renderer); - - getUniforms(shaderStage: NodeShaderStage): string; - getAttributes(shaderStage: NodeShaderStage): string; - getVaryings(shaderStage: NodeShaderStage): string; - getInstanceIndex(): string; - getDrawIndex(): string | null; - getFrontFacing(): string; - getFragCoord(): string; - buildCode(): void; } export default GLSLNodeBuilder; diff --git a/types/three/src/renderers/webgl/WebGLPrograms.d.ts b/types/three/src/renderers/webgl/WebGLPrograms.d.ts index 56d9c6fab984fb..2145a2399fe756 100644 --- a/types/three/src/renderers/webgl/WebGLPrograms.d.ts +++ b/types/three/src/renderers/webgl/WebGLPrograms.d.ts @@ -152,6 +152,8 @@ export interface WebGLProgramParameters { skinning: boolean; + hasPositionAttribute: boolean; + morphTargets: boolean; morphNormals: boolean; morphColors: boolean; diff --git a/types/three/src/renderers/webgl/WebGLRenderLists.d.ts b/types/three/src/renderers/webgl/WebGLRenderLists.d.ts index e9215cddd4d2fb..fa7ab3da2b3508 100644 --- a/types/three/src/renderers/webgl/WebGLRenderLists.d.ts +++ b/types/three/src/renderers/webgl/WebGLRenderLists.d.ts @@ -52,7 +52,11 @@ export class WebGLRenderList { z: number, group: Group | null, ): void; - sort(opaqueSort: (a: any, b: any) => number, transparentSort: (a: any, b: any) => number): void; + sort( + opaqueSort: (a: any, b: any) => number, + transparentSort: (a: any, b: any) => number, + reversedDepth: boolean, + ): void; finish(): void; } diff --git a/types/three/src/renderers/webgl/WebGLState.d.ts b/types/three/src/renderers/webgl/WebGLState.d.ts index 43f01659afcc8f..8e46bc7d3f58f5 100644 --- a/types/three/src/renderers/webgl/WebGLState.d.ts +++ b/types/three/src/renderers/webgl/WebGLState.d.ts @@ -76,6 +76,8 @@ declare class WebGLState { activeTexture(webglSlot: number): void; bindTexture(webglType: number, webglTexture: WebGLTexture, webglSlot?: number): void; unbindTexture(): void; + pixelStorei(name: GLenum, value: GLint | GLboolean): void; + getParameter(name: GLenum): unknown; // Same interface as https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/compressedTexImage2D compressedTexImage2D( diff --git a/types/three/src/renderers/webgpu/nodes/StandardNodeLibrary.d.ts b/types/three/src/renderers/webgpu/nodes/StandardNodeLibrary.d.ts index 5715e3fa3425ce..bb2ebee4980628 100644 --- a/types/three/src/renderers/webgpu/nodes/StandardNodeLibrary.d.ts +++ b/types/three/src/renderers/webgpu/nodes/StandardNodeLibrary.d.ts @@ -18,7 +18,6 @@ import NodeLibrary from "../../common/nodes/NodeLibrary.js"; * used in {@link WebGPURenderer}. It maps lights, tone mapping * techniques and materials to node-based implementations. * - * @private * @augments NodeLibrary */ declare class StandardNodeLibrary extends NodeLibrary { diff --git a/types/three/src/renderers/webgpu/nodes/WGSLNodeBuilder.d.ts b/types/three/src/renderers/webgpu/nodes/WGSLNodeBuilder.d.ts index f3dd9efbaa2ffd..5f05a8bab3d943 100644 --- a/types/three/src/renderers/webgpu/nodes/WGSLNodeBuilder.d.ts +++ b/types/three/src/renderers/webgpu/nodes/WGSLNodeBuilder.d.ts @@ -1,125 +1,9 @@ -import CodeNode from "../../../nodes/code/CodeNode.js"; -import { NodeShaderStage } from "../../../nodes/core/constants.js"; +import { Object3D } from "../../../core/Object3D.js"; import NodeBuilder from "../../../nodes/core/NodeBuilder.js"; -import NodeUniform from "../../../nodes/core/NodeUniform.js"; -import NodeVar from "../../../nodes/core/NodeVar.js"; -import StructTypeNode from "../../../nodes/core/StructTypeNode.js"; -import { ShaderNode } from "../../../nodes/tsl/TSLCore.js"; -import { Texture } from "../../../textures/Texture.js"; -import NodeUniformsGroup from "../../common/nodes/NodeUniformsGroup.js"; +import Renderer from "../../common/Renderer.js"; -type BuiltinStage = NodeShaderStage | "attribute" | "output"; -interface BuiltinType { - name: string; - property: string; - type: string; +declare class WGSLNodeBuilder extends NodeBuilder { + constructor(object: Object3D, renderer: Renderer); } -export default class WGSLNodeBuilder extends NodeBuilder { - builtins: { [key in BuiltinStage]: Map }; - uniformGroups: { [key in NodeShaderStage]: NodeUniformsGroup }; - - _generateTextureSample( - texture: Texture, - textureProperty: string, - uvSnippet: string, - depthSnippet: string | null, - shaderStage: NodeShaderStage, - ): string; - _generateVideoSample(textureProperty: string, uvSnippet: string, shaderStage: NodeShaderStage): string; - _generateTextureSampleLevel( - texture: Texture, - textureProperty: string, - uvSnippet: string, - levelSnippet: string, - depthSnippet: string | null, - shaderStage: NodeShaderStage, - ): string; - generateTextureLod(texture: Texture, textureProperty: string, uvSnippet: string, levelSnippet: string): string; - generateTextureLoad( - texture: Texture, - textureProperty: string, - uvIndexSnippet: string, - depthSnippet: string | null, - shaderStage: NodeShaderStage, - ): string; - generateTextureStore( - texture: Texture, - textureProperty: string, - uvIndexSnippet: string, - depthSnippet: string | null, - valueSnippet: string, - ): string; - isUnfilterable(texture: Texture): boolean; - generateTexture( - texture: Texture, - textureProperty: string, - uvSnippet: string, - depthSnippet: string | null, - shaderStage: NodeShaderStage, - ): string; - generateTextureGrad( - texture: Texture, - textureProperty: string, - uvSnippet: string, - gradSnippet: string[], - depthSnippet: string | null, - shaderStage: NodeShaderStage, - ): string; - generateTextureCompare( - texture: Texture, - textureProperty: string, - uvSnippet: string, - compareSnippet: String, - shaderStage: NodeShaderStage, - ): string; - generateTextureLevel( - texture: Texture, - textureProperty: string, - uvSnippet: string, - levelSnippet: string, - depthSnippet: string | null, - shaderStage: NodeShaderStage, - ): string; - - getPropertyName(node: NodeVar | NodeUniform, shaderStage: NodeShaderStage): string; - - getOutputStructName(): string; - - _getUniformGroupCount(shaderStage: NodeShaderStage): number; - - getFunctionOperator(op: string): string | null; - // getStorageAccess(node: StorageTextureNode | StorageBufferNode): string; - - getBuiltin(name: string, property: string, type: string, shaderStage: BuiltinStage): string; - getVertexIndex(): string; - getInstanceIndex(): string; - getDrawIndex(): null; - - buildFunctionCode(shaderNode: ShaderNode): string; - - getFragDepth(): string; - getFragCoord(): string; - getFrontFacing(): string; - - getBuiltins(shaderStage: BuiltinStage): string; - getAttributes(shaderStage: NodeShaderStage): string; - - getStructMembers(struct: StructTypeNode): string; - getStructs(shaderStage: NodeShaderStage): string; - - getVar(type: string, name: string): string; - getVars(shaderStage: NodeShaderStage): string; - getVaryings(shaderStage: NodeShaderStage): string; - getUniforms(shaderStage: NodeShaderStage): string; - buildCode(): void; - getMethod(method: string, output?: string | null): string; - - _getWGSLMethod(method: string): CodeNode | string; - _include(name: string): CodeNode; - _getWGSLVertexCode(shaderData: { [key: string]: string }): string; - _getWGSLFragmentCode(shaderData: { [key: string]: string }): string; - _getWGSLComputeCode(shaderData: { [key: string]: string }, workgroupSize: string): string; - _getWGSLStruct(name: string, vars: string): string; - _getWGSLStructBinding(name: string, vars: string, access: string, binding: number, group: number): string; -} +export default WGSLNodeBuilder; diff --git a/types/three/src/renderers/webgpu/nodes/WGSLNodeFunction.d.ts b/types/three/src/renderers/webgpu/nodes/WGSLNodeFunction.d.ts deleted file mode 100644 index 6476dd12258712..00000000000000 --- a/types/three/src/renderers/webgpu/nodes/WGSLNodeFunction.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import NodeFunction from "../../../nodes/core/NodeFunction.js"; - -export default class WGSLNodeFunction extends NodeFunction { - constructor(source: string); - getCode(name?: string): string; -} diff --git a/types/three/src/renderers/webgpu/nodes/WGSLNodeParser.d.ts b/types/three/src/renderers/webgpu/nodes/WGSLNodeParser.d.ts deleted file mode 100644 index 6fceb3911018e1..00000000000000 --- a/types/three/src/renderers/webgpu/nodes/WGSLNodeParser.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import NodeParser from "../../../nodes/core/NodeParser.js"; -import WGSLNodeFunction from "./WGSLNodeFunction.js"; - -export default class WGSLNodeParser extends NodeParser { - parseFunction(source: string): WGSLNodeFunction; -} diff --git a/types/three/src/textures/CubeDepthTexture.d.ts b/types/three/src/textures/CubeDepthTexture.d.ts index 9997be9eeb7d71..ebc952c305aed9 100644 --- a/types/three/src/textures/CubeDepthTexture.d.ts +++ b/types/three/src/textures/CubeDepthTexture.d.ts @@ -6,10 +6,9 @@ import { TextureDataType, Wrapping, } from "../constants.js"; -import { DepthTextureImageData } from "./DepthTexture.js"; -import { Texture } from "./Texture.js"; +import { DepthTexture, DepthTextureImageData } from "./DepthTexture.js"; -declare class CubeDepthTexture extends Texture { +declare class CubeDepthTexture extends DepthTexture { readonly isCubeDepthTexture: true; readonly isCubeTexture: true; diff --git a/types/three/src/textures/DataTexture.d.ts b/types/three/src/textures/DataTexture.d.ts index 6789450f8a3e79..4928b5a0ea9a5f 100644 --- a/types/three/src/textures/DataTexture.d.ts +++ b/types/three/src/textures/DataTexture.d.ts @@ -1,4 +1,5 @@ import { + ColorSpace, MagnificationTextureFilter, Mapping, MinificationTextureFilter, @@ -63,7 +64,7 @@ export class DataTexture extends Texture { magFilter?: MagnificationTextureFilter, minFilter?: MinificationTextureFilter, anisotropy?: number, - colorSpace?: string, + colorSpace?: ColorSpace, ); /** diff --git a/types/three/src/textures/DepthTexture.d.ts b/types/three/src/textures/DepthTexture.d.ts index 63dbe3650352ef..5212e49eb77d8a 100644 --- a/types/three/src/textures/DepthTexture.d.ts +++ b/types/three/src/textures/DepthTexture.d.ts @@ -15,7 +15,7 @@ import { Texture } from "./Texture.js"; * @see {@link https://threejs.org/docs/index.html#api/en/textures/DepthTexture | Official Documentation} * @see {@link https://github.com/mrdoob/three.js/blob/master/src/textures/DepthTexture.js | Source} */ -export class DepthTexture extends Texture { +export class DepthTexture extends Texture { /** * Create a new instance of {@link DepthTexture} * @param width Width of the texture. @@ -31,8 +31,8 @@ export class DepthTexture extends Texture { * @param {number} [depth=1] - The depth of the texture. */ constructor( - width: number, - height: number, + width?: number, + height?: number, type?: TextureDataType, mapping?: Mapping, wrapS?: Wrapping, @@ -99,7 +99,7 @@ export class DepthTexture extends Texture { } export interface DepthTextureImageData { - width: number; - height: number; + width: number | undefined; + height: number | undefined; depth: number; } diff --git a/types/three/test/unit/examples/jsm/controls/OrbitControls.ts b/types/three/test/unit/examples/jsm/controls/OrbitControls.ts new file mode 100644 index 00000000000000..885e3dd89a3158 --- /dev/null +++ b/types/three/test/unit/examples/jsm/controls/OrbitControls.ts @@ -0,0 +1,27 @@ +import * as THREE from "three"; + +import { OrbitControls } from "three/addons/controls/OrbitControls.js"; + +/** + * Generic camera type inference + */ + +// PerspectiveCamera is inferred as TCamera +const c0 = new OrbitControls(new THREE.PerspectiveCamera()); +c0.object; // $ExpectType PerspectiveCamera + +// OrthographicCamera is inferred as TCamera +const c2 = new OrbitControls(new THREE.OrthographicCamera()); +c2.object; // $ExpectType OrthographicCamera + +/** + * Explicit type argument + */ +const c1 = new OrbitControls(new THREE.PerspectiveCamera()); +c1.object; // $ExpectType PerspectiveCamera + +/** + * Default type (backward compatibility): Camera + */ +const c3: OrbitControls = new OrbitControls(new THREE.PerspectiveCamera()); +c3.object; // $ExpectType Camera diff --git a/types/three/test/unit/src/textures/CubeDepthTexture.ts b/types/three/test/unit/src/textures/CubeDepthTexture.ts index 2c7255b4ebe535..e82d8bc8c4b338 100644 --- a/types/three/test/unit/src/textures/CubeDepthTexture.ts +++ b/types/three/test/unit/src/textures/CubeDepthTexture.ts @@ -3,4 +3,5 @@ import * as THREE from "three"; const texture = new THREE.CubeDepthTexture(512); texture.isCubeDepthTexture; // $ExpectType true texture.isCubeTexture; // $ExpectType true +texture.isDepthTexture; // $ExpectType true texture.images; // $ExpectType CubeDepthTextureImageData diff --git a/types/three/tsconfig.json b/types/three/tsconfig.json index d6421e3a1e85c8..efb69c66391870 100644 --- a/types/three/tsconfig.json +++ b/types/three/tsconfig.json @@ -28,6 +28,7 @@ "test/integration/webxr-cube.ts", "test/unit/examples/jsm/exporters/PLYExporter.ts", "test/unit/examples/jsm/exporters/STLExporter.ts", + "test/unit/examples/jsm/controls/OrbitControls.ts", "test/unit/examples/jsm/helpers/ViewHelper.ts", "test/unit/examples/jsm/libs/lil-gui.ts", "test/unit/examples/jsm/libs/tween.ts",