Skip to content

Commit

Permalink
WebGPURenderer: Fix missing updates to geometry attributes (#1329)
Browse files Browse the repository at this point in the history
* Update three.js

* Add src

* Update patch and delete src

* Add src

* Update patch and delete src

* Update declarations
  • Loading branch information
Methuselah96 authored Nov 4, 2024
1 parent 2704c29 commit 624708a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 13 deletions.
41 changes: 29 additions & 12 deletions src-testing/changes.patch
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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;
+}
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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<string, BufferAttribute>) {
+ 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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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 {
Expand Down
15 changes: 15 additions & 0 deletions types/three/src/materials/nodes/manager/NodeMaterialObserver.d.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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;
}
Expand All @@ -73,6 +87,7 @@ declare class NodeMaterialObserver {
constructor(builder: NodeBuilder);
firstInitialization(renderObject: RenderObject): boolean;
getRenderObjectData(renderObject: RenderObject): RenderObjectData;
getAttributesData(attributes: Record<string, BufferAttribute>): AttributesData;
containsNode(builder: NodeBuilder): boolean;
getMaterialData(material: Material): MaterialData;
equals(renderObject: RenderObject): boolean;
Expand Down

0 comments on commit 624708a

Please sign in to comment.