Skip to content

Commit

Permalink
Use built Node.d.ts (#984)
Browse files Browse the repository at this point in the history
* Add examples

* Update patch

* Add examples

* Update Node.d.ts

* Delete examples

* Update

* Add examples

* Update patch

* Update Node.d.ts

* Update
  • Loading branch information
Methuselah96 authored May 25, 2024
1 parent bd39bd7 commit 050fd8f
Show file tree
Hide file tree
Showing 17 changed files with 382 additions and 160 deletions.
261 changes: 236 additions & 25 deletions examples-jsm/changes.patch

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions types/three/examples/jsm/nodes/accessors/BufferNode.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { NodeTypeOption } from "../core/Node.js";
import UniformNode from "../core/UniformNode.js";
import { NodeOrType, ShaderNodeObject } from "../shadernode/ShaderNode.js";

Expand All @@ -8,7 +7,7 @@ export default class BufferNode extends UniformNode<unknown> {
bufferType: string;
bufferCount: number;

constructor(value: unknown, bufferType: NodeTypeOption, bufferCount?: number);
constructor(value: unknown, bufferType: string, bufferCount?: number);
}

export const buffer: (
Expand Down
8 changes: 4 additions & 4 deletions types/three/examples/jsm/nodes/accessors/ReferenceNode.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Node, { NodeTypeOption } from "../core/Node.js";
import Node from "../core/Node.js";
import { NodeOrType, NodeRepresentation, ShaderNodeObject } from "../shadernode/ShaderNode.js";

export default class ReferenceNode<T> extends Node {
property: string;

uniformType: NodeTypeOption;
uniformType: string;

object: T;
count: number | null;
Expand All @@ -13,9 +13,9 @@ export default class ReferenceNode<T> extends Node {
reference: T | null;
node: Node | null;

constructor(property: string, uniformType: NodeTypeOption, object?: T | null, count?: number | null);
constructor(property: string, uniformType: string, object?: T | null, count?: number | null);

setNodeType(uniformType: NodeTypeOption): void;
setNodeType(uniformType: string): void;
}

export const reference: <T>(name: string, nodeOrType: NodeOrType, object: T) => ShaderNodeObject<ReferenceNode<T>>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import Renderer from "../../renderers/common/Renderer.js";
import { NodeTypeOption } from "../core/Node.js";
import { ShaderNodeObject } from "../shadernode/ShaderNode.js";
import ReferenceNode from "./ReferenceNode.js";

export default class RendererReferenceNode extends ReferenceNode<Renderer> {
renderer: Renderer | null;

constructor(property: string, inputType: NodeTypeOption, renderer?: Renderer | null);
constructor(property: string, inputType: string, renderer?: Renderer | null);
}

export const rendererReference: (
name: string,
type: NodeTypeOption,
type: string,
renderer?: Renderer | null,
) => ShaderNodeObject<RendererReferenceNode>;
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import StorageBufferAttribute from "../../renderers/common/StorageBufferAttribute.js";
import StorageInstancedBufferAttribute from "../../renderers/common/StorageInstancedBufferAttribute.js";
import { NodeTypeOption } from "../core/Node.js";
import { NodeOrType, NodeRepresentation, ShaderNodeObject } from "../shadernode/ShaderNode.js";
import StorageArrayElementNode from "../utils/StoargeArrayElementNode.js";
import BufferNode from "./BufferNode.js";
Expand All @@ -11,7 +10,7 @@ export default class StorageBufferNode extends BufferNode {

constructor(
value: StorageBufferAttribute | StorageInstancedBufferAttribute,
bufferType: NodeTypeOption,
bufferType: string,
bufferCount?: number,
);

Expand Down
5 changes: 2 additions & 3 deletions types/three/examples/jsm/nodes/accessors/UserDataNode.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { NodeTypeOption } from "../core/Node.js";
import { ShaderNodeObject } from "../shadernode/ShaderNode.js";
import ReferenceNode from "./ReferenceNode.js";

export type NodeUserData = Record<string, any>;

export default class UserDataNode extends ReferenceNode<NodeUserData> {
userData: NodeUserData | null;
constructor(property: string, inputType: NodeTypeOption, userData?: NodeUserData | null);
constructor(property: string, inputType: string, userData?: NodeUserData | null);
}

export const userData: (
name: string,
inputType: NodeTypeOption,
inputType: string,
userData?: NodeUserData,
) => ShaderNodeObject<UserDataNode>;
5 changes: 2 additions & 3 deletions types/three/examples/jsm/nodes/code/ExpressionNode.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { NodeTypeOption } from "../core/Node.js";
import TempNode from "../core/TempNode.js";
import { ShaderNodeObject } from "../shadernode/ShaderNode.js";

export default class ExpressionNode extends TempNode {
snipped: string; /* sic */
constructor(snipped?: string, nodeType?: NodeTypeOption);
constructor(snipped?: string, nodeType?: string);
}

export const expression: (snipped?: string, nodeType?: NodeTypeOption) => ShaderNodeObject<ExpressionNode>;
export const expression: (snipped?: string, nodeType?: string) => ShaderNodeObject<ExpressionNode>;
6 changes: 3 additions & 3 deletions types/three/examples/jsm/nodes/core/AttributeNode.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { NodeRepresentation, ShaderNodeObject } from "../shadernode/ShaderNode.js";
import Node, { NodeTypeOption } from "./Node.js";
import Node from "./Node.js";
import NodeBuilder from "./NodeBuilder.js";

export default class AttributeNode extends Node {
defaultNode: Node | null;

constructor(attributeName: string, nodeType?: NodeTypeOption | null, defaultNode?: Node | null);
constructor(attributeName: string, nodeType?: string | null, defaultNode?: Node | null);

setAttributeName(attributeName: string): this;

Expand All @@ -14,6 +14,6 @@ export default class AttributeNode extends Node {

export const attribute: (
name: string,
nodeType?: NodeTypeOption | null,
nodeType?: string | null,
defaultNode?: NodeRepresentation,
) => ShaderNodeObject<AttributeNode>;
3 changes: 1 addition & 2 deletions types/three/examples/jsm/nodes/core/ConstNode.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import InputNode from "./InputNode.js";
import { NodeTypeOption } from "./Node.js";
import NodeBuilder from "./NodeBuilder.js";

export default class ConstNode<Value> extends InputNode<Value> {
isConstNode: true;
constructor(value: Value, nodeType?: NodeTypeOption | null);
constructor(value: Value, nodeType?: string | null);

generateConst(builder: NodeBuilder): string;
}
4 changes: 2 additions & 2 deletions types/three/examples/jsm/nodes/core/InputNode.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Node, { NodeTypeOption } from "./Node.js";
import Node from "./Node.js";
import NodeBuilder from "./NodeBuilder.js";

export type Precision = "low" | "medium" | "high";
Expand All @@ -8,7 +8,7 @@ export default abstract class InputNode<Value> extends Node {
value: Value;
precision: Precision | null;

constructor(value: Value, nodeType?: NodeTypeOption | null);
constructor(value: Value, nodeType?: string | null);

getInputType(builder: NodeBuilder): string | null;
setPrecision(precision: Precision): this;
Expand Down
171 changes: 94 additions & 77 deletions types/three/examples/jsm/nodes/core/Node.d.ts
Original file line number Diff line number Diff line change
@@ -1,98 +1,115 @@
import { EventDispatcher } from "three";
import { NodeUpdateType } from "./constants.js";
import NodeBuilder from "./NodeBuilder.js";
import NodeFrame from "./NodeFrame.js";

export type NodeTypeOption =
| "bool"
| "int"
| "float"
| "vec2"
| "vec3"
| "vec4"
| "mat2"
| "mat3"
| "mat4"
| "code" /* CodeNode */
| "color" /* NodeUtis.getValueType */
| "uint"
| "int" /* NodeBuilder.getComponentType */
| "void"
| "property"
| "sampler"
| "texture"
| "cubeTexture" /* NodeBuilder.isReference */
| "ivec2"
| "uvec2"
| "bvec2" /* ShaderNodeBaseElements */
| "ivec3"
| "uvec3"
| "bvec3"
| "ivec4"
| "uvec4"
| "bvec4"
| "imat3"
| "umat3"
| "bmat3"
| "imat4"
| "umat4"
| "bmat4";

export default abstract class Node {
nodeType: NodeTypeOption | null;

interface NodeJSONMeta {
textures: {
[key: string]: unknown;
};
images: {
[key: string]: unknown;
};
nodes: {
[key: string]: NodeJSONIntermediateOutputData;
};
}
interface NodeJSONMetadata {
version: number;
type: "Node";
generator: "Node.toJSON";
}
interface NodeJSONInputNodes {
[property: string]:
| string[]
| {
[index: string]: string | undefined;
}
| string
| undefined;
}
interface NodeJSONInputData {
inputNodes?: NodeJSONInputNodes | undefined;
meta: {
textures: {
[key: string]: unknown;
};
nodes: {
[key: string]: Node;
};
};
}
interface NodeJSONInputData {
uuid: string;
type: string | undefined;
metadata?: NodeJSONMetadata;
inputNodes?: NodeJSONInputNodes | undefined;
}
interface NodeJSONIntermediateOutputData {
uuid: string;
type: string | undefined;
meta?: NodeJSONMeta | undefined;
metadata?: NodeJSONMetadata;
inputNodes?: NodeJSONInputNodes | undefined;
textures?: unknown[];
images?: unknown[];
nodes?: NodeJSONIntermediateOutputData[];
}
interface NodeJSONOutputData {
uuid: string;
type: string | undefined;
metadata?: NodeJSONMetadata;
inputNodes?: NodeJSONInputNodes | undefined;
textures?: unknown[];
images?: unknown[];
nodes?: NodeJSONOutputData[];
}
declare class Node extends EventDispatcher<{
dispose: {};
}> {
nodeType: string | null;
updateType: NodeUpdateType;
updateBeforeType: NodeUpdateType;

uuid: string;

version: number;

_cacheKey: string | null;
_cacheKeyVersion: number;
readonly isNode: true;

readonly id: number;

constructor(nodeType?: NodeTypeOption | null);

self?: this;
constructor(nodeType?: null);
set needsUpdate(value: boolean);

get type(): number;

get type(): string | undefined;
onUpdate(callback: (this: this, frame: NodeFrame) => void, updateType: NodeUpdateType): this;
onFrameUpdate(callback: (this: this, frame: NodeFrame) => void): this;
onRenderUpdate(callback: (this: this, frame: NodeFrame) => void): this;
onObjectUpdate(callback: (this: this, frame: NodeFrame) => void): this;
onReference(callback: (this: this, frame: NodeBuilder | NodeFrame) => this): this;
getSelf(): this;
updateReference(state: NodeBuilder | NodeFrame): this;
isGlobal(builder: NodeBuilder): boolean;

getChildren(): Node[];

getChildren(): Generator<Node, void, unknown>;
dispose(): void;
traverse(callback: (node: Node) => void): void;
getCacheKey(force?: boolean): string;

getHash(builder: NodeBuilder): string;

getUpdateType(): NodeUpdateType;

getUpdateBeforeType(): NodeUpdateType;

getElementType(builder: NodeBuilder): NodeTypeOption | null;

getNodeType(builder: NodeBuilder, output?: string | null): NodeTypeOption | null;

getReference(builder: NodeBuilder): Node;

getElementType(builder: NodeBuilder): "bool" | "int" | "float" | "vec2" | "vec3" | "vec4" | "uint" | null;
getNodeType(builder: NodeBuilder): string | null;
getShared(builder: NodeBuilder): Node;
setup(builder: NodeBuilder): Node | null;

construct(builder: NodeBuilder): Node | null;
increaseUsage(builder: NodeBuilder): number;

analyze(builder: NodeBuilder): void;

generate(builder: NodeBuilder, output?: string | null): string;

generate(builder: NodeBuilder, output?: string | null): string | null | undefined;
updateBefore(frame: NodeFrame): void;

/** This method must be overriden when {@link updateType} !== 'none' */
update(frame: NodeFrame): void;

build(builder: NodeBuilder, output?: string | null): string;

serialize(json: unknown): void;

deserialize(json: unknown): void;

toJSON(meta?: string | { textures: {}; images: {}; nodes: {} }): unknown;
build(builder: NodeBuilder, output?: string | null): string | null;
getSerializeChildren(): Generator<import("./NodeUtils.js").NodeChild, void, unknown>;
serialize(json: NodeJSONIntermediateOutputData): void;
deserialize(json: NodeJSONInputData): void;
toJSON(meta?: NodeJSONMeta | string): NodeJSONOutputData;
}
export default Node;
export declare function addNodeClass(type: string, nodeClass: typeof Node): void;
export declare function createNodeFromType(type: string): Node | undefined;
Loading

0 comments on commit 050fd8f

Please sign in to comment.