Skip to content

Commit

Permalink
Update examples (#924)
Browse files Browse the repository at this point in the history
* Update three.js

* Add examples

* Add OutputStructNode

* Fix imports

* Updates

* Update patch

* Delete examples
  • Loading branch information
Methuselah96 authored Apr 25, 2024
1 parent d885b0b commit 1e7f383
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 7 deletions.
61 changes: 61 additions & 0 deletions examples-testing/changes.patch
Original file line number Diff line number Diff line change
Expand Up @@ -14031,6 +14031,67 @@ index 3a13ab5a..2850b1be 100644
gui.add(influences, value, 0, 1, 0.01).name(key.replace('blendShape1.', '')).listen();
}
});
diff --git a/examples-testing/examples/webgpu_multiple_rendertargets_readback.ts b/examples-testing/examples/webgpu_multiple_rendertargets_readback.ts
index 229d64a9..8c9234a1 100644
--- a/examples-testing/examples/webgpu_multiple_rendertargets_readback.ts
+++ b/examples-testing/examples/webgpu_multiple_rendertargets_readback.ts
@@ -26,8 +26,8 @@ import WebGPURenderer from 'three/addons/renderers/webgpu/WebGPURenderer.js';

import QuadMesh from 'three/addons/objects/QuadMesh.js';

-let camera, scene, renderer, torus;
-let quadMesh, renderTarget, readbackTarget, material, readbackMaterial, pixelBuffer, pixelBufferTexture;
+let camera: THREE.PerspectiveCamera, scene: THREE.Scene, renderer: WebGPURenderer, torus: THREE.Mesh;
+let quadMesh: QuadMesh, renderTarget: THREE.RenderTarget, readbackTarget: THREE.RenderTarget, material: ReadGBufferMaterial, readbackMaterial: MeshBasicNodeMaterial, pixelBuffer: Uint8Array, pixelBufferTexture: THREE.DataTexture;

const gui = new GUI();

@@ -38,7 +38,11 @@ const options = {
gui.add(options, 'selection', ['mrt', 'diffuse', 'normal']);

class WriteGBufferMaterial extends NodeMaterial {
- constructor(diffuseTexture) {
+ colorSpaced: boolean;
+
+ diffuseTexture: THREE.Texture;
+
+ constructor(diffuseTexture: THREE.Texture) {
super();

this.lights = false;
@@ -62,7 +66,7 @@ class WriteGBufferMaterial extends NodeMaterial {
}

class ReadGBufferMaterial extends NodeMaterial {
- constructor(tDiffuse, tNormal) {
+ constructor(tDiffuse: THREE.Texture, tNormal: THREE.Texture) {
super();

this.lights = false;
@@ -159,7 +163,7 @@ function onWindowResize() {
renderTarget.setSize(window.innerWidth * dpr, window.innerHeight * dpr);
}

-async function render(time) {
+async function render(time: number) {
torus.rotation.y = (time / 1000) * 0.4;

// render scene into target
@@ -191,12 +195,12 @@ async function readback() {
const selection = options.selection;

if (selection === 'diffuse') {
- pixelBuffer = await renderer.readRenderTargetPixelsAsync(readbackTarget, 0, 0, width, height, 0); // zero is optional
+ pixelBuffer = (await renderer.readRenderTargetPixelsAsync(readbackTarget, 0, 0, width, height, 0)) as Uint8Array; // zero is optional

pixelBufferTexture.image.data = pixelBuffer;
pixelBufferTexture.needsUpdate = true;
} else if (selection === 'normal') {
- pixelBuffer = await renderer.readRenderTargetPixelsAsync(readbackTarget, 0, 0, width, height, 1);
+ pixelBuffer = (await renderer.readRenderTargetPixelsAsync(readbackTarget, 0, 0, width, height, 1)) as Uint8Array;

pixelBufferTexture.image.data = pixelBuffer;
pixelBufferTexture.needsUpdate = true;
diff --git a/examples-testing/examples/webgpu_parallax_uv.ts b/examples-testing/examples/webgpu_parallax_uv.ts
index 2540603f..0d2dd795 100644
--- a/examples-testing/examples/webgpu_parallax_uv.ts
Expand Down
1 change: 1 addition & 0 deletions types/three/examples/jsm/nodes/Nodes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export { default as NodeKeywords } from "./core/NodeKeywords.js";
export { default as NodeUniform } from "./core/NodeUniform.js";
export { default as NodeVar } from "./core/NodeVar.js";
export { default as NodeVarying } from "./core/NodeVarying.js";
export { default as OutputStructNode, outputStruct } from "./core/OutputStructNode.js";
export {
alphaT,
anisotropy,
Expand Down
12 changes: 12 additions & 0 deletions types/three/examples/jsm/nodes/core/OutputStructNode.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ShaderNodeObject } from "../shadernode/ShaderNode.js";
import Node from "./Node.js";

export default class OutputStructNode extends Node {
members: Node[];

readonly isOutputStructNode: true;

constructor(...members: Node[]);
}

export const outputStruct: (...members: Node[]) => ShaderNodeObject<OutputStructNode>;
4 changes: 2 additions & 2 deletions types/three/examples/jsm/renderers/common/Renderer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,9 @@ export default class Renderer {

dispose(): void;

setRenderTarget(renderTarget: RenderTarget, activeCubeFace?: number, activeMipmapLevel?: number): void;
setRenderTarget(renderTarget: RenderTarget | null, activeCubeFace?: number, activeMipmapLevel?: number): void;

getRenderTarget(): RenderTarget;
getRenderTarget(): RenderTarget | null;

setRenderObjectFunction(renderObjectFunction: () => {}): void;

Expand Down
8 changes: 4 additions & 4 deletions types/three/src/textures/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export interface TextureImageData {
readonly data: Uint8ClampedArray;
readonly height: number;
readonly width: number;
data: Uint8Array | Uint8ClampedArray;
height: number;
width: number;
}

export interface Texture3DImageData extends TextureImageData {
readonly depth: number;
depth: number;
}

0 comments on commit 1e7f383

Please sign in to comment.