Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ContextNode: Rename .context -> .value #1191

Merged
merged 4 commits into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions src-testing/changes.patch
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ index 6cffa933..5d5cc161 100644

addNodeClass('FunctionNode', FunctionNode);
diff --git a/src-testing/src/nodes/core/ContextNode.ts b/src-testing/src/nodes/core/ContextNode.ts
index fcd488eb..84e3c972 100644
index 674f1cda..cfb748a8 100644
--- a/src-testing/src/nodes/core/ContextNode.ts
+++ b/src-testing/src/nodes/core/ContextNode.ts
@@ -1,8 +1,14 @@
Expand All @@ -436,19 +436,19 @@ index fcd488eb..84e3c972 100644
+import NodeBuilder from './NodeBuilder.js';

-class ContextNode extends Node {
- constructor(node, context = {}) {
- constructor(node, value = {}) {
+class ContextNode<TContext> extends Node {
+ readonly isContextNode: true;
+
+ node: Node;
+ context: TContext;
+ value: TContext;
+
+ constructor(node: Node, context: TContext = {} as TContext) {
+ constructor(node: Node, value: TContext = {} as TContext) {
super();

this.isContextNode = true;
@@ -11,15 +17,15 @@ class ContextNode extends Node {
this.context = context;
this.value = value;
}

- getNodeType(builder) {
Expand All @@ -465,7 +465,7 @@ index fcd488eb..84e3c972 100644
+ setup(builder: NodeBuilder) {
const previousContext = builder.getContext();

builder.setContext({ ...builder.context, ...this.context });
builder.setContext({ ...builder.context, ...this.value });
@@ -31,7 +37,7 @@ class ContextNode extends Node {
return node;
}
Expand All @@ -474,7 +474,7 @@ index fcd488eb..84e3c972 100644
+ generate(builder: NodeBuilder, output?: string | null) {
const previousContext = builder.getContext();

builder.setContext({ ...builder.context, ...this.context });
builder.setContext({ ...builder.context, ...this.value });
@@ -47,7 +53,7 @@ class ContextNode extends Node {
export default ContextNode;

Expand Down Expand Up @@ -2518,10 +2518,10 @@ index 9417df5a..43761555 100644

const getViewZ = builder.context.getViewZ;
diff --git a/src-testing/src/nodes/lighting/LightingContextNode.ts b/src-testing/src/nodes/lighting/LightingContextNode.ts
index 02a8b51f..1d11c859 100644
index a6262f9a..22657e2e 100644
--- a/src-testing/src/nodes/lighting/LightingContextNode.ts
+++ b/src-testing/src/nodes/lighting/LightingContextNode.ts
@@ -1,9 +1,31 @@
@@ -1,9 +1,30 @@
import ContextNode from '../core/ContextNode.js';
-import { addNodeClass } from '../core/Node.js';
-import { addNodeElement, nodeProxy, float, vec3 } from '../shadernode/ShaderNode.js';
Expand All @@ -2547,17 +2547,16 @@ index 02a8b51f..1d11c859 100644
+}
+
+class LightingContextNode extends ContextNode<LightingContext> {
+ // lightingModel;
+ backdropNode: Node | null;
+ backdropAlphaNode: Node | null;
+
+ _context: LightingContext | null;
+ _value: LightingContext | null;
+
+ constructor(node: Node, lightingModel = null, backdropNode = null, backdropAlphaNode = null) {
super(node);

this.lightingModel = lightingModel;
@@ -28,7 +50,7 @@ class LightingContextNode extends ContextNode {
@@ -28,7 +49,7 @@ class LightingContextNode extends ContextNode {
indirectSpecular,
};

Expand All @@ -2566,14 +2565,14 @@ index 02a8b51f..1d11c859 100644
radiance: vec3().temp('radiance'),
irradiance: vec3().temp('irradiance'),
iblIrradiance: vec3().temp('iblIrradiance'),
@@ -41,7 +63,7 @@ class LightingContextNode extends ContextNode {
@@ -41,7 +62,7 @@ class LightingContextNode extends ContextNode {
return context;
}

- setup(builder) {
+ setup(builder: NodeBuilder) {
this.context = this._context || (this._context = this.getContext());
this.context.lightingModel = this.lightingModel || builder.context.lightingModel;
this.value = this._value || (this._value = this.getContext());
this.value.lightingModel = this.lightingModel || builder.context.lightingModel;

diff --git a/src-testing/src/nodes/lighting/LightsNode.ts b/src-testing/src/nodes/lighting/LightsNode.ts
index 9a41cc7d..df337a72 100644
Expand Down
13 changes: 8 additions & 5 deletions types/three/src/nodes/core/ContextNode.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ import { NodeRepresentation, ShaderNodeObject } from "../shadernode/ShaderNode.j
import Node from "./Node.js";
import { NodeBuilderContext } from "./NodeBuilder.js";

export default class ContextNode extends Node {
isContextNode: true;
declare class ContextNode extends Node {
readonly isContextNode: true;

node: Node;
context: NodeBuilderContext;
value: NodeBuilderContext;

constructor(node: Node, context: NodeBuilderContext);
constructor(node: Node, value?: NodeBuilderContext);
}

export const context: (node: NodeRepresentation, context: NodeBuilderContext) => ShaderNodeObject<ContextNode>;
export default ContextNode;

export const context: (node: NodeRepresentation, context?: NodeBuilderContext) => ShaderNodeObject<ContextNode>;
export const label: (node: NodeRepresentation, label: string) => ShaderNodeObject<ContextNode>;

declare module "../shadernode/ShaderNode.js" {
Expand Down
Loading