Skip to content

Commit

Permalink
Augment Scene with Node parameters (#1227)
Browse files Browse the repository at this point in the history
* Add src

* Update patch and delete src

* Update declarations
  • Loading branch information
Methuselah96 authored Sep 17, 2024
1 parent c4017d8 commit a6fadb5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
41 changes: 19 additions & 22 deletions src-testing/changes.patch
Original file line number Diff line number Diff line change
Expand Up @@ -6746,10 +6746,10 @@ index d2d92cb2..c022f814 100644
for (const uniform of this.uniforms) {
const node = uniform.nodeUniform.node;
diff --git a/src-testing/src/renderers/common/nodes/Nodes.ts b/src-testing/src/renderers/common/nodes/Nodes.ts
index 7fb333a4..b95f5184 100644
index 7fb333a4..e64d6c57 100644
--- a/src-testing/src/renderers/common/nodes/Nodes.ts
+++ b/src-testing/src/renderers/common/nodes/Nodes.ts
@@ -15,14 +15,67 @@ import {
@@ -15,14 +15,75 @@ import {
normalWorld,
pmremTexture,
viewportUV,
Expand Down Expand Up @@ -6796,6 +6796,14 @@ index 7fb333a4..b95f5184 100644
+ fogNode?: Node | undefined;
+ environment?: Texture | undefined;
+ environmentNode?: Node | undefined;
+}
+
+declare module '../../../scenes/Scene.js' {
+ interface Scene {
+ environmentNode?: Node | null | undefined;
+ backgroundNode?: Node | null | undefined;
+ fogNode?: Node | null | undefined;
+ }
+}

const outputNodeMap = new WeakMap();
Expand All @@ -6819,7 +6827,7 @@ index 7fb333a4..b95f5184 100644
super();

this.renderer = renderer;
@@ -33,7 +86,7 @@ class Nodes extends DataMap {
@@ -33,7 +94,7 @@ class Nodes extends DataMap {
this.groupsData = new ChainMap();
}

Expand All @@ -6828,7 +6836,7 @@ index 7fb333a4..b95f5184 100644
const groupNode = nodeUniformsGroup.groupNode;
const name = groupNode.name;

@@ -73,7 +126,7 @@ class Nodes extends DataMap {
@@ -73,7 +134,7 @@ class Nodes extends DataMap {

// other groups are updated just when groupNode.needsUpdate is true

Expand All @@ -6837,7 +6845,7 @@ index 7fb333a4..b95f5184 100644

let groupData = this.groupsData.get(groupChain);
if (groupData === undefined) this.groupsData.set(groupChain, (groupData = {}));
@@ -87,11 +140,11 @@ class Nodes extends DataMap {
@@ -87,11 +148,11 @@ class Nodes extends DataMap {
return false;
}

Expand All @@ -6851,7 +6859,7 @@ index 7fb333a4..b95f5184 100644
const renderObjectData = this.get(renderObject);

let nodeBuilderState = renderObjectData.nodeBuilderState;
@@ -128,20 +181,20 @@ class Nodes extends DataMap {
@@ -128,20 +189,20 @@ class Nodes extends DataMap {
return nodeBuilderState;
}

Expand All @@ -6877,7 +6885,7 @@ index 7fb333a4..b95f5184 100644
const computeData = this.get(computeNode);

let nodeBuilderState = computeData.nodeBuilderState;
@@ -158,7 +211,7 @@ class Nodes extends DataMap {
@@ -158,7 +219,7 @@ class Nodes extends DataMap {
return nodeBuilderState;
}

Expand All @@ -6886,34 +6894,23 @@ index 7fb333a4..b95f5184 100644
return new NodeBuilderState(
nodeBuilder.vertexShader,
nodeBuilder.fragmentShader,
@@ -173,20 +226,28 @@ class Nodes extends DataMap {
@@ -173,20 +234,20 @@ class Nodes extends DataMap {
);
}

- getEnvironmentNode(scene) {
- return scene.environmentNode || this.get(scene).environmentNode || null;
+ getEnvironmentNode(scene: Scene) {
+ return (
+ (scene as { environmentNode?: Node | null | undefined }).environmentNode ||
+ this.get(scene).environmentNode ||
+ null
+ );
return scene.environmentNode || this.get(scene).environmentNode || null;
}

- getBackgroundNode(scene) {
- return scene.backgroundNode || this.get(scene).backgroundNode || null;
+ getBackgroundNode(scene: Scene) {
+ return (
+ (scene as { backgroundNode?: Node | null | undefined }).backgroundNode ||
+ this.get(scene).backgroundNode ||
+ null
+ );
return scene.backgroundNode || this.get(scene).backgroundNode || null;
}

- getFogNode(scene) {
- return scene.fogNode || this.get(scene).fogNode || null;
+ getFogNode(scene: Scene) {
+ return (scene as { fogNode?: Node | null | undefined }).fogNode || this.get(scene).fogNode || null;
return scene.fogNode || this.get(scene).fogNode || null;
}

- getCacheKey(scene, lightsNode) {
Expand Down
7 changes: 7 additions & 0 deletions types/three/src/renderers/common/nodes/Nodes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ interface SceneData {
environment?: Texture | undefined;
environmentNode?: Node | undefined;
}
declare module "../../../scenes/Scene.js" {
interface Scene {
environmentNode?: Node | null | undefined;
backgroundNode?: Node | null | undefined;
fogNode?: Node | null | undefined;
}
}
declare class Nodes extends DataMap<{
nodeUniformsGroup: {
key: NodeUniformsGroup;
Expand Down

0 comments on commit a6fadb5

Please sign in to comment.