Skip to content

Commit 3f80f41

Browse files
committed
変数名の変更、postProcessingのrender/init処理の修正
1 parent c72d6a5 commit 3f80f41

File tree

4 files changed

+25
-23
lines changed

4 files changed

+25
-23
lines changed

box/main.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as THREE from "three";
33
import { pass } from "three/tsl";
44
import { dotScreen } from "three/examples/jsm/tsl/display/DotScreenNode.js";
55

6-
const init = () => {
6+
const init = async () => {
77
const app = document.querySelector<HTMLDivElement>("#app");
88
if (!app) {
99
return;
@@ -15,6 +15,7 @@ const init = () => {
1515
camera.position.z = 5;
1616

1717
const renderer = new WebGPURenderer({ antialias: true });
18+
await renderer.init();
1819
renderer.setSize(window.innerWidth, window.innerHeight);
1920
renderer.setPixelRatio(window.devicePixelRatio);
2021

@@ -26,11 +27,11 @@ const init = () => {
2627
scene.add(cube);
2728

2829
// ポストプロセス
29-
const postprocessing = new PostProcessing(renderer);
30+
const postProcessing = new PostProcessing(renderer);
3031
const scenePass = pass(scene, camera);
3132
const scenePassColor = scenePass.getTextureNode();
3233
const dotScreenPass = dotScreen(scenePassColor);
33-
postprocessing.outputNode = dotScreenPass;
34+
postProcessing.outputNode = dotScreenPass;
3435

3536
const handleResize = () => {
3637
camera.aspect = window.innerWidth / window.innerHeight;
@@ -40,13 +41,13 @@ const init = () => {
4041
window.addEventListener("resize", handleResize);
4142

4243
// アニメーションループ
43-
const animate = async () => {
44+
const animate = () => {
4445
requestAnimationFrame(animate);
4546

4647
cube.rotation.x = cube.rotation.x + 0.01;
4748
cube.rotation.y = cube.rotation.y + 0.01;
4849

49-
await postprocessing.renderAsync();
50+
postProcessing.render();
5051
};
5152

5253
animate();

sea/src/three/createScene.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const createFog = (mode: DayMode) => {
4545
* シーンの作成
4646
* @param container
4747
*/
48-
export const createScene = (container: HTMLDivElement) => {
48+
export const createScene = async (container: HTMLDivElement) => {
4949
const params = getParams("day");
5050
const scene = new THREE.Scene();
5151
scene.background = new THREE.Color(params.backgroundColor);
@@ -59,6 +59,7 @@ export const createScene = (container: HTMLDivElement) => {
5959
camera.position.set(0, 8, 30);
6060

6161
const renderer = new WebGPURenderer({ antialias: true });
62+
await renderer.init();
6263
renderer.setSize(window.innerWidth, window.innerHeight);
6364
renderer.setPixelRatio(window.devicePixelRatio);
6465

sea/src/three/initThree.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ const effects: Effect[] = ["none", "chromatic", "bloom", "pixelation", "sepia"]
1313
* Three.jsの初期化
1414
* @param app
1515
*/
16-
export const initThree = (app: HTMLDivElement) => {
17-
const { scene, camera, renderer, onChangeEffectScene } = createScene(app);
16+
export const initThree = async (app: HTMLDivElement) => {
17+
const { scene, camera, renderer, onChangeEffectScene } = await createScene(app);
1818

1919
const sea = createSea();
2020
scene.add(sea);
@@ -25,14 +25,14 @@ export const initThree = (app: HTMLDivElement) => {
2525
const { island, onChangeEffectIsland } = createIsland();
2626
scene.add(island);
2727

28-
const { postprocessing, changePostprocess } = initPostprocess(scene, camera, renderer);
28+
const { postProcessing, changePostprocess } = initPostprocess(scene, camera, renderer);
2929

3030
addGui([changePostprocess, onChangeEffectScene, onChangeEffectIsland, onChangeEffectClouds]);
3131

3232
const clock = new THREE.Clock();
3333

34-
const tick = async () => {
35-
await postprocessing.renderAsync();
34+
const tick = () => {
35+
postProcessing.render();
3636
const elapsedTime = clock.getElapsedTime();
3737
animateSea(elapsedTime);
3838
animateClouds(elapsedTime);
@@ -46,9 +46,9 @@ export const initThree = (app: HTMLDivElement) => {
4646

4747
// GUIの追加
4848
const addGui = (callbacks: ((effect: Effect) => void)[]) => {
49-
const postprocessingFolder = gui.addFolder("Postprocessing");
49+
const postProcessingFolder = gui.addFolder("Post Processing");
5050

51-
postprocessingFolder
51+
postProcessingFolder
5252
.add({ effect: "chromatic" }, "effect", effects)
5353
.name("Effect")
5454
.onChange((value: Effect) => {

sea/src/three/postprocess/initPostprocess.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,37 +14,37 @@ import { createSepia } from "./sepia";
1414
* @param renderer - レンダラー
1515
*/
1616
export const initPostprocess = (scene: THREE.Scene, camera: THREE.PerspectiveCamera, renderer: WebGPURenderer) => {
17-
const postprocessing = new PostProcessing(renderer);
17+
const postProcessing = new PostProcessing(renderer);
1818
const scenePass = pass(scene, camera);
1919
const scenePassColor = scenePass.getTextureNode();
2020
const viewZ = scenePass.getViewZNode();
2121

22-
postprocessing.outputNode = createChromatic(scenePassColor, viewZ);
22+
postProcessing.outputNode = createChromatic(scenePassColor, viewZ);
2323

2424
// ポストプロセスのエフェクトを変更する
2525
const changePostprocess = (effect: Effect) => {
2626
switch (effect) {
2727
case "none":
28-
postprocessing.outputNode = scenePassColor;
28+
postProcessing.outputNode = scenePassColor;
2929
break;
3030
case "chromatic":
31-
postprocessing.outputNode = createChromatic(scenePassColor, viewZ);
31+
postProcessing.outputNode = createChromatic(scenePassColor, viewZ);
3232
break;
3333
case "bloom":
34-
postprocessing.outputNode = createBloom(scenePassColor);
34+
postProcessing.outputNode = createBloom(scenePassColor);
3535
break;
3636
case "pixelation":
37-
postprocessing.outputNode = createPixelation(scene, camera);
37+
postProcessing.outputNode = createPixelation(scene, camera);
3838
break;
3939
case "sepia":
40-
postprocessing.outputNode = createSepia(scenePassColor);
40+
postProcessing.outputNode = createSepia(scenePassColor);
4141
break;
4242
default:
43-
postprocessing.outputNode = scenePassColor;
43+
postProcessing.outputNode = scenePassColor;
4444
break;
4545
}
46-
postprocessing.needsUpdate = true;
46+
postProcessing.needsUpdate = true;
4747
};
4848

49-
return { postprocessing, changePostprocess };
49+
return { postProcessing, changePostprocess };
5050
};

0 commit comments

Comments
 (0)