Skip to content

Commit 42f9251

Browse files
author
takuma-hmng8
committed
3.6
1 parent 03089f4 commit 42f9251

File tree

33 files changed

+1061
-221
lines changed

33 files changed

+1061
-221
lines changed
File renamed without changes.
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
"use client";
2+
3+
import * as THREE from "three";
4+
import { use, useCallback, useEffect, useMemo, useRef } from "react";
5+
import {
6+
useFrame,
7+
useThree,
8+
extend,
9+
useLoader,
10+
Size,
11+
} from "@react-three/fiber";
12+
import {
13+
useCreateMorphParticles,
14+
MORPHPARTICLES_PARAMS,
15+
MorphParticlesParams,
16+
useBeat,
17+
} from "@/packages/use-shader-fx/src";
18+
import { FxMaterial, FxMaterialProps } from "./FxMaterial";
19+
import GUI from "lil-gui";
20+
import { useGUI } from "@/utils/useGUI";
21+
import { OrbitControls } from "@react-three/drei";
22+
23+
extend({ FxMaterial });
24+
25+
const CONFIG: MorphParticlesParams = structuredClone(MORPHPARTICLES_PARAMS);
26+
const setGUI = (gui: GUI) => {
27+
gui.add(CONFIG, "blurAlpha", 0, 1, 0.01);
28+
gui.add(CONFIG, "blurRadius", 0, 2, 0.01);
29+
gui.add(CONFIG, "pointSize", 0.01, 2, 0.01);
30+
gui.addColor(CONFIG, "color0");
31+
gui.addColor(CONFIG, "color1");
32+
gui.addColor(CONFIG, "color2");
33+
gui.addColor(CONFIG, "color3");
34+
gui.add(CONFIG, "wobbleStrength", 0, 10, 0.01);
35+
gui.add(CONFIG, "wobblePositionFrequency", 0, 10, 0.01);
36+
gui.add(CONFIG, "wobbleTimeFrequency", 0, 10, 0.01);
37+
gui.add(CONFIG, "warpStrength", 0, 10, 0.01);
38+
gui.add(CONFIG, "warpPositionFrequency", 0, 10, 0.01);
39+
gui.add(CONFIG, "warpTimeFrequency", 0, 10, 0.01);
40+
};
41+
const setConfig = () => {
42+
return {
43+
...CONFIG,
44+
} as MorphParticlesParams;
45+
};
46+
47+
/*===============================================
48+
TODO
49+
- useMorphParticles
50+
v morphする
51+
- tjの40
52+
v picture
53+
v 全体にマップするtexture
54+
v particleにマップするtexture
55+
-
56+
- wobble
57+
- 4Dノイズかける(時間が入るから)
58+
- wobble3Dの仕組みを利用する
59+
v color
60+
v 4色双線形補間
61+
v particleのサイズ
62+
v 球体にするレベル
63+
===============================================*/
64+
65+
export const Playground = () => {
66+
const updateGUI = useGUI(setGUI);
67+
const ref = useRef<FxMaterialProps>();
68+
const [funkun, funkunAlpha] = useLoader(THREE.TextureLoader, [
69+
"/funkun.jpg",
70+
"/funkun-alpha.jpg",
71+
]);
72+
const { size, viewport, gl } = useThree();
73+
74+
const morphList = [
75+
new THREE.PlaneGeometry(5, 5, 100, 100).attributes.position
76+
.array as Float32Array,
77+
new THREE.TorusGeometry(2.5, 1, 50, 30).attributes.position
78+
.array as Float32Array,
79+
];
80+
81+
const [updatePoints, points] = useCreateMorphParticles({
82+
scene: false,
83+
size,
84+
dpr: viewport.dpr,
85+
geometry: new THREE.IcosahedronGeometry(2.5, 50),
86+
// positions: morphList,
87+
// geometry: new THREE.PlaneGeometry(5, 5, 100, 100),
88+
});
89+
const beat = useBeat(140, "easeOutCubic");
90+
useFrame((props) => {
91+
const b = beat(props.clock);
92+
updatePoints(props, {
93+
...setConfig(),
94+
// picture: funkun,
95+
// alphaPicture: funkunAlpha,
96+
map: funkun,
97+
alphaMap: funkunAlpha,
98+
beat: b.beat,
99+
morphProgress: Math.max(Math.sin(props.clock.getElapsedTime() / 2), 0),
100+
});
101+
updateGUI();
102+
});
103+
104+
return (
105+
<mesh>
106+
<OrbitControls />
107+
<primitive object={points.points} />
108+
</mesh>
109+
);
110+
};
File renamed without changes.
File renamed without changes.

app/useParticle/Playground.tsx

Lines changed: 0 additions & 176 deletions
This file was deleted.
File renamed without changes.

app/useMorph3D/Playground.tsx renamed to app/useWobble3D/Playground.tsx

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,30 @@ const uniforms = {
2626
uTime: new THREE.Uniform(0),
2727
uPositionFrequency: new THREE.Uniform(0.5),
2828
uTimeFrequency: new THREE.Uniform(0.2),
29-
uStrength: new THREE.Uniform(0.9),
29+
uStrength: new THREE.Uniform(0.1),
3030
uWarpPositionFrequency: new THREE.Uniform(0.2),
3131
uWarpTimeFrequency: new THREE.Uniform(0.2),
3232
uWarpStrength: new THREE.Uniform(0.2),
3333
uColorA: new THREE.Uniform(new THREE.Color("white")),
34-
uColorB: new THREE.Uniform(new THREE.Color("black")),
34+
uColorB: new THREE.Uniform(new THREE.Color("orange")),
3535
uBaloon: new THREE.Uniform(0),
3636
uFx: new THREE.Uniform(new THREE.Texture()),
3737
};
3838

39+
/*===============================================
40+
TODO :
41+
- onbeforeConopileを使って、meshPhusycalMaterialのuniforomsを更新する。
42+
- デフォルトで
43+
- 気が向いたらtoonShaderも追加する?
44+
- isPrimitiveみたいな感じで、Object3Dをsceneに追加しないパターンもつくる。
45+
- Lightとかがあるから、primitiveで使う方がユースケース的にはあるよな
46+
- まあLightもuseEffectとかで追加できるから、isPrimitiveは例外的な使い方としよう。
47+
- r3fはprimitiveをanmount時にsceneから削除するのかな? 追加されてるobjectは自分でdisposeしないといけないのはわかる。
48+
- あと、primitiveの場合は、useFrameとかも使えないのかな?
49+
50+
- 内部的にraycaster使ってonPointerMoveも更新関数に追加するとかありかもね。
51+
===============================================*/
52+
3953
export const Playground = () => {
4054
const { size, viewport, scene: rootScene, camera } = useThree();
4155

@@ -95,34 +109,29 @@ export const Playground = () => {
95109
const beat = useBeat(140);
96110
const updatePointer = usePointer();
97111

98-
const raycaster = useMemo(() => new THREE.Raycaster(), []);
99-
const rayCursor = useRef<THREE.Vector2 | null>(null);
112+
const refPointer = useRef(new THREE.Vector2(0, 0));
113+
const handlePointerMove = (e: any) =>
114+
(refPointer.current = e.uv.multiplyScalar(2).subScalar(1));
100115

101116
useFrame((props) => {
102117
const b = beat(props.clock);
103118
updateFluid(props);
104119
mesh.material.uniforms.uTime.value = b.beat;
105-
106-
raycaster.setFromCamera(props.pointer, camera);
107-
const intersects = raycaster.intersectObject(mesh);
108-
if (intersects.length > 0) {
109-
const uv = intersects[0]?.uv as THREE.Vector2;
110-
if (!uv) return;
111-
rayCursor.current = uv.multiplyScalar(2).subScalar(1);
112-
}
113-
if (rayCursor.current) {
114-
mesh.material.uniforms.uFx.value = updateFluid(props, {
115-
pointerValues: updatePointer(rayCursor.current),
116-
});
117-
}
120+
mesh.material.uniforms.uFx.value = updateFluid(props, {
121+
pointerValues: updatePointer(refPointer.current),
122+
});
118123
});
119124

120125
return (
121126
<mesh>
122127
<ambientLight />
123128
<directionalLight />
124129
<OrbitControls />
125-
<primitive object={mesh} position={[0, 0, 0]} />
130+
<primitive
131+
onPointerMove={handlePointerMove}
132+
object={mesh}
133+
position={[0, 0, 0]}
134+
/>
126135
</mesh>
127136
);
128137
};
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)