diff --git a/examples-testing/changes.patch b/examples-testing/changes.patch index 9e467122b..9193bb48d 100644 --- a/examples-testing/changes.patch +++ b/examples-testing/changes.patch @@ -13549,6 +13549,65 @@ index 3331adc8..17d73367 100644 const time = (currentTime - startTime) / 1000; object.position.y = 0.8; +diff --git a/examples-testing/examples/webgpu_compute_audio.ts b/examples-testing/examples/webgpu_compute_audio.ts +index 4e567e9c..847c42ef 100644 +--- a/examples-testing/examples/webgpu_compute_audio.ts ++++ b/examples-testing/examples/webgpu_compute_audio.ts +@@ -1,17 +1,27 @@ +-import * as THREE from 'three'; +-import { Fn, uniform, instanceIndex, instancedArray, float, texture, screenUV, color } from 'three/tsl'; ++import * as THREE from 'three/webgpu'; ++import { ++ Fn, ++ uniform, ++ instanceIndex, ++ instancedArray, ++ float, ++ texture, ++ screenUV, ++ color, ++ ShaderNodeObject, ++} from 'three/tsl'; + + import { GUI } from 'three/addons/libs/lil-gui.module.min.js'; + +-let camera, scene, renderer; +-let computeNode; +-let waveBuffer, sampleRate; +-let waveArray; +-let currentAudio, currentAnalyser; ++let camera: THREE.PerspectiveCamera, scene: THREE.Scene, renderer: THREE.WebGPURenderer; ++let computeNode: ShaderNodeObject; ++let waveBuffer: Float32Array, sampleRate: number; ++let waveArray: ShaderNodeObject; ++let currentAudio: AudioBufferSourceNode, currentAnalyser: AnalyserNode; + const analyserBuffer = new Uint8Array(1024); +-let analyserTexture; ++let analyserTexture: THREE.DataTexture; + +-const startButton = document.getElementById('startButton'); ++const startButton = document.getElementById('startButton')!; + startButton.addEventListener('click', init); + + async function playAudioBuffer() { +@@ -46,7 +56,7 @@ async function playAudioBuffer() { + } + + async function init() { +- const overlay = document.getElementById('overlay'); ++ const overlay = document.getElementById('overlay')!; + overlay.remove(); + + // audio buffer +@@ -92,7 +102,7 @@ async function init() { + + const time = index.mul(pitch); + +- let wave = originalWave.element(time); ++ let wave: ShaderNodeObject = originalWave.element(time); + + // delay + diff --git a/examples-testing/examples/webgpu_custom_fog_background.ts b/examples-testing/examples/webgpu_custom_fog_background.ts index baca16cb..b01cd750 100644 --- a/examples-testing/examples/webgpu_custom_fog_background.ts diff --git a/examples-testing/index.js b/examples-testing/index.js index b9eac8ec6..2da9bcf93 100644 --- a/examples-testing/index.js +++ b/examples-testing/index.js @@ -44,7 +44,6 @@ const exceptionList = [ 'webgl_worker_offscreencanvas', 'webgpu_backdrop', 'webgpu_backdrop_water', - 'webgpu_compute_audio', 'webgpu_compute_birds', 'webgpu_compute_geometry', 'webgpu_compute_particles', diff --git a/types/three/src/nodes/accessors/Arrays.d.ts b/types/three/src/nodes/accessors/Arrays.d.ts index acf8d9604..2c1289a9d 100644 --- a/types/three/src/nodes/accessors/Arrays.d.ts +++ b/types/three/src/nodes/accessors/Arrays.d.ts @@ -1,6 +1,7 @@ +import { TypedArray } from "../../core/BufferAttribute.js"; import { ShaderNodeObject } from "../tsl/TSLCore.js"; import StorageBufferNode from "./StorageBufferNode.js"; -export const attributeArray: (count: number, type?: string) => ShaderNodeObject; +export const attributeArray: (count: TypedArray | number, type?: string) => ShaderNodeObject; -export const instancedArray: (count: number, type?: string) => ShaderNodeObject; +export const instancedArray: (count: TypedArray | number, type?: string) => ShaderNodeObject; diff --git a/types/three/src/nodes/accessors/BufferNode.d.ts b/types/three/src/nodes/accessors/BufferNode.d.ts index 4db9ccccd..c475362c1 100644 --- a/types/three/src/nodes/accessors/BufferNode.d.ts +++ b/types/three/src/nodes/accessors/BufferNode.d.ts @@ -1,17 +1,17 @@ import UniformNode from "../core/UniformNode.js"; import { NodeOrType, ShaderNodeObject } from "../tsl/TSLCore.js"; -export default class BufferNode extends UniformNode { +export default class BufferNode extends UniformNode { isBufferNode: true; bufferType: string; bufferCount: number; - constructor(value: unknown, bufferType: string, bufferCount?: number); + constructor(value: TValue, bufferType: string, bufferCount?: number); } -export const buffer: ( +export const buffer: ( value: unknown, nodeOrType: NodeOrType, count: number, -) => ShaderNodeObject; +) => ShaderNodeObject>; diff --git a/types/three/src/nodes/accessors/StorageBufferNode.d.ts b/types/three/src/nodes/accessors/StorageBufferNode.d.ts index 0e5790161..6c8b192fb 100644 --- a/types/three/src/nodes/accessors/StorageBufferNode.d.ts +++ b/types/three/src/nodes/accessors/StorageBufferNode.d.ts @@ -5,7 +5,7 @@ import { NodeRepresentation, ShaderNodeObject } from "../tsl/TSLCore.js"; import StorageArrayElementNode from "../utils/StorageArrayElementNode.js"; import BufferNode from "./BufferNode.js"; -export default class StorageBufferNode extends BufferNode { +export default class StorageBufferNode extends BufferNode { readonly isStorageBufferNode: true; access: NodeAccess; diff --git a/types/three/src/nodes/accessors/UniformArrayNode.d.ts b/types/three/src/nodes/accessors/UniformArrayNode.d.ts index c3d4e932e..d3b5bf95d 100644 --- a/types/three/src/nodes/accessors/UniformArrayNode.d.ts +++ b/types/three/src/nodes/accessors/UniformArrayNode.d.ts @@ -7,7 +7,7 @@ declare class UniformArrayElementNode extends ArrayElementNode { constructor(arrayBuffer: Node, indexNode: Node); } -declare class UniformArrayNode extends BufferNode { +declare class UniformArrayNode extends BufferNode { array: unknown[]; elementType: string | null; paddedType: string; diff --git a/types/three/src/nodes/tsl/TSLCore.d.ts b/types/three/src/nodes/tsl/TSLCore.d.ts index 319c32fda..14fe026d5 100644 --- a/types/three/src/nodes/tsl/TSLCore.d.ts +++ b/types/three/src/nodes/tsl/TSLCore.d.ts @@ -172,6 +172,11 @@ type ConstructedNode = T extends new(...args: any[]) => infer R ? (R extends export type NodeOrType = Node | string; +declare class ShaderCallNodeInternal extends Node { +} + +declare class ShaderNodeInternal extends Node {} + export const defined: (v: unknown) => unknown; export const getConstNodeType: (value: NodeOrType) => string | null; @@ -215,20 +220,20 @@ interface Layout { inputs: { name: string; type: string }[]; } -interface ShaderNodeFn> { - (...args: Args): R; - shaderNode: R; - setLayout: (layout: Layout) => ShaderNodeFn; - once: () => ShaderNodeFn; +interface ShaderNodeFn { + (...args: Args): ShaderNodeObject; + shaderNode: ShaderNodeObject; + setLayout: (layout: Layout) => this; + once: () => this; } -export function Fn>(jsFunc: () => R): ShaderNodeFn<[], R>; -export function Fn>( - jsFunc: (args: T) => R, -): ShaderNodeFn, R>; -export function Fn>( - jsFunc: (args: T) => R, -): ShaderNodeFn<[ProxiedObject], R>; +export function Fn(jsFunc: () => void): ShaderNodeFn<[]>; +export function Fn( + jsFunc: (args: T) => void, +): ShaderNodeFn>; +export function Fn( + jsFunc: (args: T) => void, +): ShaderNodeFn<[ProxiedObject]>; /** * @deprecated tslFn() has been renamed to Fn() diff --git a/types/three/src/renderers/common/StorageBufferAttribute.d.ts b/types/three/src/renderers/common/StorageBufferAttribute.d.ts index 2a864f54a..0d2a58691 100644 --- a/types/three/src/renderers/common/StorageBufferAttribute.d.ts +++ b/types/three/src/renderers/common/StorageBufferAttribute.d.ts @@ -3,5 +3,5 @@ import { BufferAttribute, TypedArray } from "../../core/BufferAttribute.js"; export default class StorageBufferAttribute extends BufferAttribute { readonly isStorageBufferAttribute: true; - constructor(array: TypedArray, itemSize: number); + constructor(array: TypedArray | number, itemSize: number); }