diff --git a/types/three/examples/jsm/nodes/Nodes.d.ts b/types/three/examples/jsm/nodes/Nodes.d.ts index f49ddd649..6b1f5379a 100644 --- a/types/three/examples/jsm/nodes/Nodes.d.ts +++ b/types/three/examples/jsm/nodes/Nodes.d.ts @@ -365,10 +365,10 @@ export { default as ViewportTextureNode, viewportMipTexture, viewportTexture } f export { default as PassNode, depthPass, pass, PassNodeScope } from "./display/PassNode.js"; // code -export { code, CodeNodeInclude, default as CodeNode } from "./code/CodeNode.js"; +export { code, CodeNodeInclude, default as CodeNode, glsl, js, wgsl } from "./code/CodeNode.js"; export { default as ExpressionNode, expression } from "./code/ExpressionNode.js"; export { call, default as FunctionCallNode } from "./code/FunctionCallNode.js"; -export { default as FunctionNode, Fn, fn, func, FunctionNodeArguments } from "./code/FunctionNode.js"; +export { default as FunctionNode, Fn, FunctionNodeArguments, glslFn, wgslFn } from "./code/FunctionNode.js"; // fog export { default as FogExp2Node, densityFog } from "./fog/FogExp2Node.js"; diff --git a/types/three/examples/jsm/nodes/code/CodeNode.d.ts b/types/three/examples/jsm/nodes/code/CodeNode.d.ts index be80e42ca..558ee9a7f 100644 --- a/types/three/examples/jsm/nodes/code/CodeNode.d.ts +++ b/types/three/examples/jsm/nodes/code/CodeNode.d.ts @@ -10,10 +10,15 @@ export interface CodeNodeInclude { export default class CodeNode extends Node { isCodeNode: true; code: string; - constructor(code?: string, includes?: CodeNodeInclude[]); + language: string; + + constructor(code?: string, includes?: CodeNodeInclude[], language?: string); setIncludes(includes: CodeNodeInclude[]): this; getIncludes(builder: NodeBuilder): CodeNodeInclude[]; } -export const code: (code: string, nodeType?: NodeTypeOption) => ShaderNodeObject; +export const code: (code: string, includes?: CodeNodeInclude[], language?: string) => ShaderNodeObject; +export const js: (src: string, includes?: CodeNodeInclude[]) => ShaderNodeObject; +export const wgsl: (src: string, includes?: CodeNodeInclude[]) => ShaderNodeObject; +export const glsl: (src: string, includes?: CodeNodeInclude[]) => ShaderNodeObject; diff --git a/types/three/examples/jsm/nodes/code/FunctionNode.d.ts b/types/three/examples/jsm/nodes/code/FunctionNode.d.ts index 4a19cf5fb..f44432dce 100644 --- a/types/three/examples/jsm/nodes/code/FunctionNode.d.ts +++ b/types/three/examples/jsm/nodes/code/FunctionNode.d.ts @@ -10,7 +10,7 @@ export type FunctionNodeArguments = Node[] | { [name: string]: Node }; export default class FunctionNode

extends CodeNode { keywords: { [key: string]: Node }; - constructor(code?: string, includes?: CodeNodeInclude[]); + constructor(code?: string, includes?: CodeNodeInclude[], language?: string); getInputs(builder: NodeBuilder): NodeFunctionInput[]; getNodeFunction(builder: NodeBuilder): NodeFunction; @@ -20,13 +20,19 @@ export default class FunctionNode

e export type Fn

= P extends readonly [...unknown[]] ? ProxiedTuple

: readonly [ProxiedObject

]; -export const func:

( +export const nativeFn:

( code: string, includes?: CodeNodeInclude[], + language?: string, // eslint-disable-next-line @definitelytyped/no-unnecessary-generics -) => { call: (...params: Fn

) => ShaderNodeObject }; +) => (...params: Fn

) => ShaderNodeObject; -export const fn:

( +export const glslFn:

( + code: string, + includes?: CodeNodeInclude[], + // eslint-disable-next-line @definitelytyped/no-unnecessary-generics +) => (...params: Fn

) => ShaderNodeObject; +export const wgslFn:

( code: string, includes?: CodeNodeInclude[], // eslint-disable-next-line @definitelytyped/no-unnecessary-generics diff --git a/types/three/test/unit/examples/jsm/nodes/core/FunctionNode.ts b/types/three/test/unit/examples/jsm/nodes/core/FunctionNode.ts index b5bfebb1e..fe0782454 100644 --- a/types/three/test/unit/examples/jsm/nodes/core/FunctionNode.ts +++ b/types/three/test/unit/examples/jsm/nodes/core/FunctionNode.ts @@ -2,7 +2,17 @@ * Various tests of func, fn and call */ -import { call, code, fn, func, FunctionCallNode, FunctionNode, Node, Swizzable, uv } from "three/addons/nodes/Nodes.js"; +import { + call, + code, + FunctionCallNode, + FunctionNode, + glslFn, + Node, + Swizzable, + uv, + wgslFn, +} from "three/addons/nodes/Nodes.js"; import { ProxiedObject } from "three/addons/nodes/shadernode/ShaderNode.js"; @@ -24,23 +34,23 @@ assertSwizzable>(call(someFunc2, { a: 1 })); assertSwizzable>(call(someFunc2, { a: uv() })); assertSwizzable>(call(someFunc2, { a: uv().xy })); -export const mx_cell_noise_float_call = func<[Node]>("float mx_cell_noise_float( vec3 p )", includes); -export const mx_worley_noise_float_call = func<[Node, Node, Node]>( +export const mx_cell_noise_float_call = wgslFn<[Node]>("float mx_cell_noise_float( vec3 p )", includes); +export const mx_worley_noise_float_call = wgslFn<[Node, Node, Node]>( "float mx_worley_noise_float( vec3 p, float jitter, int metric )", includes, ); -export const ab_call = func<{ a: Node; b: Node }>("float mx_cell_noise_float( vec3 p )", includes); +export const ab_call = wgslFn<{ a: Node; b: Node }>("float mx_cell_noise_float( vec3 p )", includes); assertSwizzable(mx_cell_noise_float_call.call(uv())); assertSwizzable(mx_worley_noise_float_call.call(uv(), 1, 1)); assertSwizzable(ab_call.call({ a: 1, b: uv() })); -export const mx_cell_noise_float = fn<[Node]>("float mx_cell_noise_float( vec3 p )", includes); -export const mx_worley_noise_float = fn<[Node, Node, Node]>( +export const mx_cell_noise_float = glslFn<[Node]>("float mx_cell_noise_float( vec3 p )", includes); +export const mx_worley_noise_float = glslFn<[Node, Node, Node]>( "float mx_worley_noise_float( vec3 p, float jitter, int metric )", includes, ); -export const ab = fn<{ a: Node; b: Node }>("float mx_cell_noise_float( vec3 p )", includes); +export const ab = glslFn<{ a: Node; b: Node }>("float mx_cell_noise_float( vec3 p )", includes); assertSwizzable(mx_cell_noise_float(uv())); assertSwizzable(mx_worley_noise_float(uv(), 1, 1));