From 9a08e072f933fe53498ce9f28f1b1c936a48cadf Mon Sep 17 00:00:00 2001 From: Nathan Bierema Date: Tue, 18 Jun 2024 23:14:49 -0400 Subject: [PATCH] TSL: Fix label() usage in uniform() (#1023) * Update three.js * Add examples * Update patch * Delete examples * Update UniformNode * Add examples * Just buying time Not sustainable * Delete examples * Fix * Fix * Fix --- examples-jsm/changes.patch | 24 ++++--- three.js | 2 +- .../examples/jsm/nodes/core/UniformNode.d.ts | 2 + .../materials/MeshPhongNodeMaterial.d.ts | 5 +- .../materials/MeshPhysicalNodeMaterial.d.ts | 35 +++++----- .../nodes/materials/MeshSSSNodeMaterial.d.ts | 13 ++-- .../materials/MeshStandardNodeMaterial.d.ts | 7 +- .../jsm/nodes/materials/NodeMaterial.d.ts | 65 +++++++++---------- .../nodes/materials/SpriteNodeMaterial.d.ts | 5 +- .../test/unit/src/core/EventDispatcher.ts | 3 - 10 files changed, 81 insertions(+), 80 deletions(-) diff --git a/examples-jsm/changes.patch b/examples-jsm/changes.patch index 3543d8dfd..3bfdd1192 100644 --- a/examples-jsm/changes.patch +++ b/examples-jsm/changes.patch @@ -2266,10 +2266,10 @@ index f8bb2b37..cee70486 100644 } } diff --git a/examples-jsm/examples/nodes/core/UniformNode.ts b/examples-jsm/examples/nodes/core/UniformNode.ts -index 90e86648..78a60c3b 100644 +index 41e523c4..a0c2ae45 100644 --- a/examples-jsm/examples/nodes/core/UniformNode.ts +++ b/examples-jsm/examples/nodes/core/UniformNode.ts -@@ -1,10 +1,17 @@ +@@ -1,10 +1,18 @@ import InputNode from './InputNode.js'; -import { objectGroup } from './UniformGroupNode.js'; -import { addNodeClass } from './Node.js'; @@ -2285,22 +2285,30 @@ index 90e86648..78a60c3b 100644 +class UniformNode extends InputNode { + readonly isUniformNode: true; + ++ name: string; + groupNode: UniformGroupNode; + + constructor(value: TValue, nodeType: string | null = null) { super(value, nodeType); this.isUniformNode = true; -@@ -12,7 +19,7 @@ class UniformNode extends InputNode { +@@ -13,13 +21,13 @@ class UniformNode extends InputNode { this.groupNode = objectGroup; } +- label(name) { ++ label(name: string) { + this.name = name; + + return this; + } + - setGroup(group) { + setGroup(group: UniformGroupNode) { this.groupNode = group; return this; -@@ -22,11 +29,11 @@ class UniformNode extends InputNode { +@@ -29,11 +37,11 @@ class UniformNode extends InputNode { return this.groupNode; } @@ -2314,7 +2322,7 @@ index 90e86648..78a60c3b 100644 const self = this.getSelf(); callback = callback.bind(self); -@@ -40,12 +47,12 @@ class UniformNode extends InputNode { +@@ -47,12 +55,12 @@ class UniformNode extends InputNode { }, updateType); } @@ -2329,16 +2337,16 @@ index 90e86648..78a60c3b 100644 if (sharedNode === undefined) { builder.setHashNode(this, hash); -@@ -58,7 +65,7 @@ class UniformNode extends InputNode { +@@ -65,7 +73,7 @@ class UniformNode extends InputNode { const nodeUniform = builder.getUniformFromNode( sharedNode, sharedNodeType, - builder.shaderStage, + builder.shaderStage!, - builder.context.label, + this.name || builder.context.label, ); const propertyName = builder.getPropertyName(nodeUniform); -@@ -71,11 +78,14 @@ class UniformNode extends InputNode { +@@ -78,11 +86,14 @@ class UniformNode extends InputNode { export default UniformNode; diff --git a/three.js b/three.js index d674e7c67..3556fc5d6 160000 --- a/three.js +++ b/three.js @@ -1 +1 @@ -Subproject commit d674e7c6762ac7236abb5c3fade064bda95fe1b8 +Subproject commit 3556fc5d6986e03bcd4776ee2e89b862ec493c10 diff --git a/types/three/examples/jsm/nodes/core/UniformNode.d.ts b/types/three/examples/jsm/nodes/core/UniformNode.d.ts index 0f4334b84..e28f44567 100644 --- a/types/three/examples/jsm/nodes/core/UniformNode.d.ts +++ b/types/three/examples/jsm/nodes/core/UniformNode.d.ts @@ -6,8 +6,10 @@ import NodeFrame from "./NodeFrame.js"; import UniformGroupNode from "./UniformGroupNode.js"; declare class UniformNode extends InputNode { readonly isUniformNode: true; + name: string; groupNode: UniformGroupNode; constructor(value: TValue, nodeType?: string | null); + label(name: string): this; setGroup(group: UniformGroupNode): this; getGroup(): UniformGroupNode; getUniformHash(builder: NodeBuilder): string; diff --git a/types/three/examples/jsm/nodes/materials/MeshPhongNodeMaterial.d.ts b/types/three/examples/jsm/nodes/materials/MeshPhongNodeMaterial.d.ts index 6698fe0a7..426d6f151 100644 --- a/types/three/examples/jsm/nodes/materials/MeshPhongNodeMaterial.d.ts +++ b/types/three/examples/jsm/nodes/materials/MeshPhongNodeMaterial.d.ts @@ -1,6 +1,5 @@ import { Color, Combine, Euler, MeshPhongMaterialParameters, NormalMapTypes, Texture, Vector2 } from "three"; import Node from "../core/Node.js"; -import { ShaderNodeObject } from "../shadernode/ShaderNode.js"; import NodeMaterial, { NodeMaterialParameters } from "./NodeMaterial.js"; export interface MeshPhongNodeMaterialParameters extends NodeMaterialParameters, MeshPhongMaterialParameters { @@ -9,8 +8,8 @@ export interface MeshPhongNodeMaterialParameters extends NodeMaterialParameters, export default class MeshPhongNodeMaterial extends NodeMaterial { readonly isMeshPhongNodeMaterial: true; - shininessNode: ShaderNodeObject | null; - specularNode: ShaderNodeObject | null; + shininessNode: Node | null; + specularNode: Node | null; // Properties from MeshPhongMaterial readonly isMeshPhongMaterial: true; diff --git a/types/three/examples/jsm/nodes/materials/MeshPhysicalNodeMaterial.d.ts b/types/three/examples/jsm/nodes/materials/MeshPhysicalNodeMaterial.d.ts index 9101caea1..2349b46a1 100644 --- a/types/three/examples/jsm/nodes/materials/MeshPhysicalNodeMaterial.d.ts +++ b/types/three/examples/jsm/nodes/materials/MeshPhysicalNodeMaterial.d.ts @@ -1,7 +1,6 @@ import { Color, MeshPhysicalMaterialParameters, Texture, Vector2 } from "three"; import Node from "../core/Node.js"; -import { ShaderNodeObject } from "../shadernode/ShaderNode.js"; import MeshStandardNodeMaterial, { MeshStandardNodeMaterialParameters } from "./MeshStandardNodeMaterial.js"; export interface MeshPhysicalNodeMaterialParameters @@ -12,29 +11,29 @@ export interface MeshPhysicalNodeMaterialParameters export default class MeshPhysicalNodeMaterial extends MeshStandardNodeMaterial { readonly isMeshPhysicalNodeMaterial: true; - clearcoatNode: ShaderNodeObject | null; - clearcoatRoughnessNode: ShaderNodeObject | null; - clearcoatNormalNode: ShaderNodeObject | null; + clearcoatNode: Node | null; + clearcoatRoughnessNode: Node | null; + clearcoatNormalNode: Node | null; - sheenNode: ShaderNodeObject | null; - sheenRoughnessNode: ShaderNodeObject | null; + sheenNode: Node | null; + sheenRoughnessNode: Node | null; - iridescenceNode: ShaderNodeObject | null; - iridescenceIORNode: ShaderNodeObject | null; - iridescenceThicknessNode: ShaderNodeObject | null; + iridescenceNode: Node | null; + iridescenceIORNode: Node | null; + iridescenceThicknessNode: Node | null; - iorNode: ShaderNodeObject | null; + iorNode: Node | null; - specularIntensityNode: ShaderNodeObject | null; - specularColorNode: ShaderNodeObject | null; + specularIntensityNode: Node | null; + specularColorNode: Node | null; - transmissionNode: ShaderNodeObject | null; - thicknessNode: ShaderNodeObject | null; - attenuationDistanceNode: ShaderNodeObject | null; - attenuationColorNode: ShaderNodeObject | null; - dispersionNode: ShaderNodeObject | null; + transmissionNode: Node | null; + thicknessNode: Node | null; + attenuationDistanceNode: Node | null; + attenuationColorNode: Node | null; + dispersionNode: Node | null; - anisotropyNode: ShaderNodeObject | null; + anisotropyNode: Node | null; // Properties from MeshPhysicalMaterial readonly isMeshPhysicalMaterial: true; diff --git a/types/three/examples/jsm/nodes/materials/MeshSSSNodeMaterial.d.ts b/types/three/examples/jsm/nodes/materials/MeshSSSNodeMaterial.d.ts index 00c594427..8506de76c 100644 --- a/types/three/examples/jsm/nodes/materials/MeshSSSNodeMaterial.d.ts +++ b/types/three/examples/jsm/nodes/materials/MeshSSSNodeMaterial.d.ts @@ -1,15 +1,14 @@ import ConstNode from "../core/ConstNode.js"; import Node from "../core/Node.js"; -import { ShaderNodeObject } from "../shadernode/ShaderNode.js"; import MeshPhysicalNodeMaterial, { MeshPhysicalNodeMaterialParameters } from "./MeshPhysicalNodeMaterial.js"; export default class MeshSSSNodeMaterial extends MeshPhysicalNodeMaterial { - thicknessColorNode: ShaderNodeObject | null; - thicknessDistortionNode: ShaderNodeObject>; - thicknessAmbientNode: ShaderNodeObject>; - thicknessAttenuationNode: ShaderNodeObject>; - thicknessPowerNode: ShaderNodeObject>; - thicknessScaleNode: ShaderNodeObject>; + thicknessColorNode: Node | null; + thicknessDistortionNode: ConstNode; + thicknessAmbientNode: ConstNode; + thicknessAttenuationNode: ConstNode; + thicknessPowerNode: ConstNode; + thicknessScaleNode: ConstNode; constructor(parameters?: MeshPhysicalNodeMaterialParameters); diff --git a/types/three/examples/jsm/nodes/materials/MeshStandardNodeMaterial.d.ts b/types/three/examples/jsm/nodes/materials/MeshStandardNodeMaterial.d.ts index 3a13f7d5f..e109eae1d 100644 --- a/types/three/examples/jsm/nodes/materials/MeshStandardNodeMaterial.d.ts +++ b/types/three/examples/jsm/nodes/materials/MeshStandardNodeMaterial.d.ts @@ -1,6 +1,5 @@ import { Color, Euler, MeshStandardMaterialParameters, NormalMapTypes, Texture, Vector2 } from "three"; import Node from "../core/Node.js"; -import { ShaderNodeObject } from "../shadernode/ShaderNode.js"; import NodeMaterial, { NodeMaterialParameters } from "./NodeMaterial.js"; export interface MeshStandardNodeMaterialParameters extends NodeMaterialParameters, MeshStandardMaterialParameters { @@ -9,10 +8,10 @@ export interface MeshStandardNodeMaterialParameters extends NodeMaterialParamete export default class MeshStandardNodeMaterial extends NodeMaterial { readonly isMeshStandardNodeMaterial: true; - emissiveNode: ShaderNodeObject | null; + emissiveNode: Node | null; - metalnessNode: ShaderNodeObject | null; - roughnessNode: ShaderNodeObject | null; + metalnessNode: Node | null; + roughnessNode: Node | null; // Properties from MeshStandardMaterial readonly isMeshStandardMaterial: true; diff --git a/types/three/examples/jsm/nodes/materials/NodeMaterial.d.ts b/types/three/examples/jsm/nodes/materials/NodeMaterial.d.ts index 23edeab88..fe757681a 100644 --- a/types/three/examples/jsm/nodes/materials/NodeMaterial.d.ts +++ b/types/three/examples/jsm/nodes/materials/NodeMaterial.d.ts @@ -18,7 +18,6 @@ import LightingModel from "../core/LightingModel.js"; import Node from "../core/Node.js"; import NodeBuilder from "../core/NodeBuilder.js"; import LightsNode from "../lighting/LightsNode.js"; -import { ShaderNodeObject } from "../shadernode/ShaderNode.js"; import LineBasicNodeMaterial from "./LineBasicNodeMaterial.js"; import MeshBasicNodeMaterial from "./MeshBasicNodeMaterial.js"; import MeshMatcapNodeMaterial from "./MeshMatcapNodeMaterial.js"; @@ -36,26 +35,26 @@ export interface NodeMaterialParameters extends MaterialParameters { colorSpaced?: boolean | undefined; - lightsNode?: ShaderNodeObject | null | undefined; - envNode?: ShaderNodeObject | null | undefined; - aoNode?: ShaderNodeObject | null | undefined; + lightsNode?: LightsNode | null | undefined; + envNode?: Node | null | undefined; + aoNode?: Node | null | undefined; - colorNode?: ShaderNodeObject | null | undefined; - normalNode?: ShaderNodeObject | null | undefined; - opacityNode?: ShaderNodeObject | null | undefined; - backdropNode?: ShaderNodeObject | null | undefined; - backdropAlphaNode?: ShaderNodeObject | null | undefined; - alphaTestNode?: ShaderNodeObject | null | undefined; + colorNode?: Node | null | undefined; + normalNode?: Node | null | undefined; + opacityNode?: Node | null | undefined; + backdropNode?: Node | null | undefined; + backdropAlphaNode?: Node | null | undefined; + alphaTestNode?: Node | null | undefined; - positionNode?: ShaderNodeObject | null | undefined; + positionNode?: Node | null | undefined; - depthNode?: ShaderNodeObject | null | undefined; - shadowNode?: ShaderNodeObject | null | undefined; + depthNode?: Node | null | undefined; + shadowNode?: Node | null | undefined; - outputNode?: ShaderNodeObject | null | undefined; + outputNode?: Node | null | undefined; - fragmentNode?: ShaderNodeObject | null | undefined; - vertexNode?: ShaderNodeObject | null | undefined; + fragmentNode?: Node | null | undefined; + vertexNode?: Node | null | undefined; } export default class NodeMaterial extends Material { @@ -63,33 +62,33 @@ export default class NodeMaterial extends Material { normals: boolean; - lightsNode: ShaderNodeObject | null; - envNode: ShaderNodeObject | null; - aoNode: ShaderNodeObject | null; + lightsNode: LightsNode | null; + envNode: Node | null; + aoNode: Node | null; - colorNode: ShaderNodeObject | null; - normalNode: ShaderNodeObject | null; - opacityNode: ShaderNodeObject | null; - backdropNode: ShaderNodeObject | null; - backdropAlphaNode: ShaderNodeObject | null; - alphaTestNode: ShaderNodeObject | null; + colorNode: Node | null; + normalNode: Node | null; + opacityNode: Node | null; + backdropNode: Node | null; + backdropAlphaNode: Node | null; + alphaTestNode: Node | null; - positionNode: ShaderNodeObject | null; + positionNode: Node | null; - depthNode: ShaderNodeObject | null; - shadowNode: ShaderNodeObject | null; - shadowPositionNode: ShaderNodeObject | null; + depthNode: Node | null; + shadowNode: Node | null; + shadowPositionNode: Node | null; - outputNode: ShaderNodeObject | null; + outputNode: Node | null; - fragmentNode: ShaderNodeObject | null; - vertexNode: ShaderNodeObject | null; + fragmentNode: Node | null; + vertexNode: Node | null; constructor(); build(builder: NodeBuilder): void; setup(builder: NodeBuilder): void; - setupClipping(builder: NodeBuilder): ShaderNodeObject | null; + setupClipping(builder: NodeBuilder): ClippingNode | null; setupDepth(builder: NodeBuilder): void; setupPosition(builder: NodeBuilder): Node; setupDiffuseColor(builder: NodeBuilder): void; diff --git a/types/three/examples/jsm/nodes/materials/SpriteNodeMaterial.d.ts b/types/three/examples/jsm/nodes/materials/SpriteNodeMaterial.d.ts index d83587ffc..54b79f99c 100644 --- a/types/three/examples/jsm/nodes/materials/SpriteNodeMaterial.d.ts +++ b/types/three/examples/jsm/nodes/materials/SpriteNodeMaterial.d.ts @@ -1,6 +1,5 @@ import { Color, SpriteMaterialParameters, Texture } from "three"; import Node from "../core/Node.js"; -import { ShaderNodeObject } from "../shadernode/ShaderNode.js"; import NodeMaterial, { NodeMaterialParameters } from "./NodeMaterial.js"; export interface SpriteNodeMaterialParameters extends NodeMaterialParameters, SpriteMaterialParameters { @@ -9,8 +8,8 @@ export interface SpriteNodeMaterialParameters extends NodeMaterialParameters, Sp export default class SpriteNodeMaterial extends NodeMaterial { isSpriteNodeMaterial: true; - rotationNode: ShaderNodeObject | null; - scaleNode: ShaderNodeObject | null; + rotationNode: Node | null; + scaleNode: Node | null; // Properties from SpriteMaterial readonly isSpriteMaterial: true; diff --git a/types/three/test/unit/src/core/EventDispatcher.ts b/types/three/test/unit/src/core/EventDispatcher.ts index c6001d58c..32cd43143 100644 --- a/types/three/test/unit/src/core/EventDispatcher.ts +++ b/types/three/test/unit/src/core/EventDispatcher.ts @@ -31,9 +31,6 @@ eveDisForTestEvent.addEventListener("foo", e => { e.type; // $ExpectType "foo" e.target; // $ExpectType EventDispatcher e.foo; // $ExpectType number - - // NOTE: Error in ts lower than 3.9. The minimum typescript version cannot be raised from 3.6 because of the dependency from aframe. - // e.foo; // $ExpectType number // @ts-expect-error e.bar; });