From 624708a8e28f701e4ebf5ef8c516e624fc385b41 Mon Sep 17 00:00:00 2001 From: Nathan Bierema Date: Sun, 3 Nov 2024 20:39:33 -0500 Subject: [PATCH] WebGPURenderer: Fix missing updates to geometry attributes (#1329) * Update three.js * Add src * Update patch and delete src * Add src * Update patch and delete src * Update declarations --- src-testing/changes.patch | 41 +++++++++++++------ three.js | 2 +- .../nodes/manager/NodeMaterialObserver.d.ts | 15 +++++++ 3 files changed, 45 insertions(+), 13 deletions(-) diff --git a/src-testing/changes.patch b/src-testing/changes.patch index d9056805e..0e31033c8 100644 --- a/src-testing/changes.patch +++ b/src-testing/changes.patch @@ -1,18 +1,19 @@ diff --git a/src-testing/src/materials/nodes/manager/NodeMaterialObserver.ts b/src-testing/src/materials/nodes/manager/NodeMaterialObserver.ts -index 0e940e65..edbafb5c 100644 +index 8ab1a6d6..dab659ab 100644 --- a/src-testing/src/materials/nodes/manager/NodeMaterialObserver.ts +++ b/src-testing/src/materials/nodes/manager/NodeMaterialObserver.ts -@@ -1,3 +1,9 @@ +@@ -1,3 +1,10 @@ +import NodeBuilder from '../../../nodes/core/NodeBuilder.js'; +import RenderObject from '../../../renderers/common/RenderObject.js'; +import { Matrix4 } from '../../../math/Matrix4.js'; +import { Material } from '../../Material.js'; +import NodeFrame from '../../../nodes/core/NodeFrame.js'; ++import { BufferAttribute } from '../../../core/BufferAttribute.js'; + const refreshUniforms = [ 'alphaMap', 'alphaTest', -@@ -49,10 +55,28 @@ const refreshUniforms = [ +@@ -49,10 +56,33 @@ const refreshUniforms = [ 'thickness', 'transmission', 'transmissionMap', @@ -25,8 +26,13 @@ index 0e940e65..edbafb5c 100644 + [K in RefreshUniform]?: unknown; +}; + ++interface AttributesData { ++ [name: string]: { version: number }; ++} ++ +interface RenderObjectData { + material: MaterialData; ++ geometry: { attributes: AttributesData; indexVersion: number | null; drawRange: { start: number; count: number } }; + worldMatrix: Matrix4; + version?: number; +} @@ -43,7 +49,7 @@ index 0e940e65..edbafb5c 100644 this.renderObjects = new WeakMap(); this.hasNode = this.containsNode(builder); this.hasAnimation = builder.object.isSkinnedMesh === true; -@@ -60,7 +84,7 @@ class NodeMaterialObserver { +@@ -60,7 +90,7 @@ class NodeMaterialObserver { this.renderId = 0; } @@ -52,7 +58,7 @@ index 0e940e65..edbafb5c 100644 const hasInitialized = this.renderObjects.has(renderObject); if (hasInitialized === false) { -@@ -72,7 +96,7 @@ class NodeMaterialObserver { +@@ -72,7 +102,7 @@ class NodeMaterialObserver { return false; } @@ -61,16 +67,27 @@ index 0e940e65..edbafb5c 100644 let data = this.renderObjects.get(renderObject); if (data === undefined) { -@@ -99,7 +123,7 @@ class NodeMaterialObserver { +@@ -106,8 +136,8 @@ class NodeMaterialObserver { return data; } +- getAttributesData(attributes) { +- const attributesData = {}; ++ getAttributesData(attributes: Record) { ++ const attributesData: AttributesData = {}; + + for (const name in attributes) { + const attribute = attributes[name]; +@@ -120,7 +150,7 @@ class NodeMaterialObserver { + return attributesData; + } + - containsNode(builder) { + containsNode(builder: NodeBuilder) { const material = builder.material; for (const property in material) { -@@ -112,8 +136,8 @@ class NodeMaterialObserver { +@@ -133,8 +163,8 @@ class NodeMaterialObserver { return false; } @@ -81,16 +98,16 @@ index 0e940e65..edbafb5c 100644 for (const property of this.refreshUniforms) { const value = material[property]; -@@ -134,7 +158,7 @@ class NodeMaterialObserver { +@@ -155,7 +185,7 @@ class NodeMaterialObserver { return data; } - equals(renderObject) { + equals(renderObject: RenderObject) { - const { object, material } = renderObject; + const { object, material, geometry } = renderObject; const renderObjectData = this.getRenderObjectData(renderObject); -@@ -208,7 +232,7 @@ class NodeMaterialObserver { +@@ -280,7 +310,7 @@ class NodeMaterialObserver { return true; } @@ -7287,7 +7304,7 @@ index f409c2b1..bb53c090 100644 const monitor = renderObject.getMonitor(); diff --git a/src-testing/src/renderers/webgl-fallback/WebGLBackend.ts b/src-testing/src/renderers/webgl-fallback/WebGLBackend.ts -index 3ccf2ce8..eebe741d 100644 +index 3ed6e6a0..e2436879 100644 --- a/src-testing/src/renderers/webgl-fallback/WebGLBackend.ts +++ b/src-testing/src/renderers/webgl-fallback/WebGLBackend.ts @@ -13,6 +13,7 @@ import { WebGLBufferRenderer } from './WebGLBufferRenderer.js'; @@ -7706,7 +7723,7 @@ index b1e72064..40f26bf1 100644 const nodeData = this.getDataFromNode(node, shaderStage, this.globalCache); diff --git a/src-testing/src/renderers/webgpu/WebGPUBackend.ts b/src-testing/src/renderers/webgpu/WebGPUBackend.ts -index af12c87d..80310894 100644 +index c14a3647..3b2d32e7 100644 --- a/src-testing/src/renderers/webgpu/WebGPUBackend.ts +++ b/src-testing/src/renderers/webgpu/WebGPUBackend.ts @@ -947,7 +947,7 @@ class WebGPUBackend extends Backend { diff --git a/three.js b/three.js index 1a6d5e6b0..0e17a92c6 160000 --- a/three.js +++ b/three.js @@ -1 +1 @@ -Subproject commit 1a6d5e6b0126d55b2221bd6cf07406202e7a63d7 +Subproject commit 0e17a92c657be1603d59306044c5a4849cc6cf47 diff --git a/types/three/src/materials/nodes/manager/NodeMaterialObserver.d.ts b/types/three/src/materials/nodes/manager/NodeMaterialObserver.d.ts index b58e1ebd1..d2f8af70b 100644 --- a/types/three/src/materials/nodes/manager/NodeMaterialObserver.d.ts +++ b/types/three/src/materials/nodes/manager/NodeMaterialObserver.d.ts @@ -1,3 +1,4 @@ +import { BufferAttribute } from "../../../core/BufferAttribute.js"; import { Matrix4 } from "../../../math/Matrix4.js"; import NodeBuilder from "../../../nodes/core/NodeBuilder.js"; import NodeFrame from "../../../nodes/core/NodeFrame.js"; @@ -59,8 +60,21 @@ type RefreshUniform = (typeof refreshUniforms)[number]; type MaterialData = { [K in RefreshUniform]?: unknown; }; +interface AttributesData { + [name: string]: { + version: number; + }; +} interface RenderObjectData { material: MaterialData; + geometry: { + attributes: AttributesData; + indexVersion: number | null; + drawRange: { + start: number; + count: number; + }; + }; worldMatrix: Matrix4; version?: number; } @@ -73,6 +87,7 @@ declare class NodeMaterialObserver { constructor(builder: NodeBuilder); firstInitialization(renderObject: RenderObject): boolean; getRenderObjectData(renderObject: RenderObject): RenderObjectData; + getAttributesData(attributes: Record): AttributesData; containsNode(builder: NodeBuilder): boolean; getMaterialData(material: Material): MaterialData; equals(renderObject: RenderObject): boolean;