Skip to content

Commit d357c31

Browse files
authored
Merge pull request #92 from FunTechInc/v1.1.10
fix obscurus demo
2 parents a0e1772 + 21ae87b commit d357c31

File tree

33 files changed

+168
-59
lines changed

33 files changed

+168
-59
lines changed

Diff for: app/obscurus/Playground.tsx

+41-5
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,9 @@ const setWobbleConfig = () => {
128128

129129
export const Playground = () => {
130130
useGUI(setGUI);
131-
const [noise] = useLoader(THREE.TextureLoader, ["/noise.jpg"]);
132131
const { size, viewport, camera } = useThree();
132+
const [noise] = useLoader(THREE.TextureLoader, ["/noise.jpg"]);
133133
const [updateWobble, wobble] = useCreateWobble3D({
134-
baseMaterial: THREE.MeshPhysicalMaterial,
135134
geometry: useMemo(() => new THREE.IcosahedronGeometry(2.4, 10), []),
136135
materialParameters: MATERIAL_CONFIG,
137136
});
@@ -141,11 +140,9 @@ export const Playground = () => {
141140
geometry: useMemo(() => new THREE.IcosahedronGeometry(0.8, 10), []),
142141
});
143142
useEffect(() => {
144-
const particleMat = particles.points.material as THREE.ShaderMaterial;
145-
particleMat.blending = THREE.NormalBlending;
143+
particles.points.material.blending = THREE.NormalBlending;
146144
camera.position.z = 8;
147145
}, [noise, updateParticle, particles.points.material, camera]);
148-
149146
useFrame((props) => {
150147
updateWobble(props, {
151148
...setWobbleConfig(),
@@ -171,3 +168,42 @@ export const Playground = () => {
171168
</mesh>
172169
);
173170
};
171+
172+
/*===============================================
173+
simple version
174+
===============================================*/
175+
// export const Playground = () => {
176+
// const { size, viewport, camera } = useThree();
177+
// const [noise] = useLoader(THREE.TextureLoader, ["/noise.jpg"]);
178+
179+
// const [updateWobble, wobble] = useCreateWobble3D({
180+
// baseMaterial: THREE.MeshPhysicalMaterial,
181+
// geometry: useMemo(() => new THREE.IcosahedronGeometry(2.4, 10), []),
182+
// materialParameters: MATERIAL_CONFIG,
183+
// });
184+
// const [updateParticle, particles] = useCreateMorphParticles({
185+
// size,
186+
// dpr: viewport.dpr,
187+
// geometry: useMemo(() => new THREE.IcosahedronGeometry(0.8, 10), []),
188+
// });
189+
190+
// useEffect(() => {
191+
// particles.points.material.blending = THREE.NormalBlending;
192+
// camera.position.z = 8;
193+
// updateWobble(null, WOBBLE_CONFIG);
194+
// updateParticle(null, { ...PARTICLE_CONFIG, alphaMap: noise });
195+
// }, [particles.points.material, camera, updateWobble, updateParticle, noise]);
196+
// useFrame((props) => {
197+
// updateWobble(props);
198+
// updateParticle(props);
199+
// });
200+
201+
// return (
202+
// <mesh>
203+
// <OrbitControls />
204+
// <Environment files={"/snowpark.exr"} background={true} />
205+
// <primitive object={wobble.mesh} />
206+
// <primitive object={particles.points} />
207+
// </mesh>
208+
// );
209+
// };

Diff for: packages/use-shader-fx/build/use-shader-fx.js

+6-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: packages/use-shader-fx/build/use-shader-fx.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: packages/use-shader-fx/build/use-shader-fx.umd.cjs.map

+1-1
Large diffs are not rendered by default.

Diff for: packages/use-shader-fx/package-lock.json

+48-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: packages/use-shader-fx/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@funtech-inc/use-shader-fx",
3-
"version": "1.1.10",
3+
"version": "1.1.11",
44
"description": "⚡️ More FXs, Less GLSL",
55
"main": "./build/use-shader-fx.umd.cjs",
66
"module": "./build/use-shader-fx.js",

Diff for: packages/use-shader-fx/src/fxs/3D/useMorphParticles/index.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
UseCreateMorphParticlesProps,
99
} from "./useCreateMorphParticles";
1010
import { HooksProps3D } from "../types";
11+
import { InteractiveMesh, MorphParticlePoints } from "./utils/useCreateObject";
1112

1213
export type MorphParticlesParams = {
1314
/** progress value to morph vertices,0~1 */
@@ -58,8 +59,8 @@ export type MorphParticlesParams = {
5859

5960
export type MorphParticlesObject = {
6061
scene: THREE.Scene;
61-
points: THREE.Points;
62-
interactiveMesh: THREE.Mesh;
62+
points: MorphParticlePoints;
63+
interactiveMesh: InteractiveMesh;
6364
renderTarget: THREE.WebGLRenderTarget;
6465
output: THREE.Texture;
6566
positions: Float32Array[];

Diff for: packages/use-shader-fx/src/fxs/3D/useMorphParticles/useCreateMorphParticles.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import * as THREE from "three";
22
import { Size, RootState } from "@react-three/fiber";
3-
import { useCreateObject } from "./utils/useCreateObject";
3+
import {
4+
InteractiveMesh,
5+
MorphParticlePoints,
6+
useCreateObject,
7+
} from "./utils/useCreateObject";
48
import { useMaterial } from "./utils/useMaterial";
59
import { MorphParticlesParams } from ".";
610
import { setUniform } from "../../../utils/setUniforms";
@@ -22,11 +26,12 @@ type UpdateUniform = (
2226
props: RootState | null,
2327
params?: MorphParticlesParams
2428
) => void;
29+
2530
type UseCreateMorphParticlesReturn = [
2631
UpdateUniform,
2732
{
28-
points: THREE.Points;
29-
interactiveMesh: THREE.Mesh;
33+
points: MorphParticlePoints;
34+
interactiveMesh: InteractiveMesh;
3035
positions: Float32Array[];
3136
uvs: Float32Array[];
3237
}

Diff for: packages/use-shader-fx/src/fxs/3D/useMorphParticles/utils/useCreateObject.ts

+16-2
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,34 @@ type UseCreateObjectProps = {
88
material: THREE.ShaderMaterial;
99
};
1010

11+
export type MorphParticlePoints = THREE.Points<
12+
THREE.BufferGeometry<THREE.NormalBufferAttributes>,
13+
THREE.ShaderMaterial
14+
>;
15+
export type InteractiveMesh = THREE.Mesh<
16+
THREE.BufferGeometry<THREE.NormalBufferAttributes>,
17+
THREE.ShaderMaterial
18+
>;
19+
1120
export const useCreateObject = ({
1221
scene,
1322
geometry,
1423
material,
1524
}: UseCreateObjectProps) => {
16-
const points = useAddObject(scene, geometry, material, THREE.Points);
25+
const points = useAddObject(
26+
scene,
27+
geometry,
28+
material,
29+
THREE.Points
30+
) as MorphParticlePoints;
1731

1832
// Generate a mesh for pointer
1933
const interactiveMesh = useAddObject(
2034
scene,
2135
useMemo(() => geometry.clone(), [geometry]),
2236
useMemo(() => material.clone(), [material]),
2337
THREE.Mesh
24-
);
38+
) as InteractiveMesh;
2539
interactiveMesh.visible = false;
2640

2741
return {

Diff for: packages/use-shader-fx/src/fxs/3D/useWobble3D/useCreateWobble3D.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export type UseCreateWobble3DProps = {
1919
};
2020

2121
type UpdateUniform = (props: RootState | null, params?: Wobble3DParams) => void;
22-
type UseCreateWobble3DReturn = [
22+
type UseCreateWobble3DReturn<T> = [
2323
UpdateUniform,
2424
{
2525
mesh: THREE.Mesh;
@@ -34,7 +34,7 @@ export const useCreateWobble3D = <T extends WobbleMaterialConstructor>({
3434
materialParameters,
3535
}: UseCreateWobble3DProps &
3636
Create3DHooksProps &
37-
WobbleMaterialProps<T>): UseCreateWobble3DReturn => {
37+
WobbleMaterialProps<T>): UseCreateWobble3DReturn<T> => {
3838
const wobbleGeometry = useMemo(() => {
3939
let geo = geometry || new THREE.IcosahedronGeometry(2, 20);
4040
geo = mergeVertices(geo);
@@ -46,7 +46,7 @@ export const useCreateWobble3D = <T extends WobbleMaterialConstructor>({
4646
materialParameters,
4747
});
4848

49-
const object = useAddObject(scene, wobbleGeometry, material, THREE.Mesh);
49+
const mesh = useAddObject(scene, wobbleGeometry, material, THREE.Mesh);
5050

5151
const updateUniform = useCallback<UpdateUniform>(
5252
(props, params) => {
@@ -102,7 +102,7 @@ export const useCreateWobble3D = <T extends WobbleMaterialConstructor>({
102102
return [
103103
updateUniform,
104104
{
105-
mesh: object,
105+
mesh,
106106
depthMaterial,
107107
},
108108
];

Diff for: packages/use-shader-fx/src/utils/useAddObject.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
import * as THREE from "three";
22
import { useEffect, useMemo } from "react";
33

4-
type Object3DConstructor<T> = new (
4+
type Object3DConstructor<T, M extends THREE.Material> = new (
55
geometry: THREE.BufferGeometry,
6-
material: THREE.Material
6+
material: M
77
) => T;
88

99
/**
1010
* Add geometry and material to Object3D and add them to scene.
1111
*/
12-
export const useAddObject = <T extends THREE.Object3D>(
12+
export const useAddObject = <
13+
T extends THREE.Object3D,
14+
M extends THREE.Material
15+
>(
1316
scene: THREE.Scene | false,
1417
geometry: THREE.BufferGeometry,
15-
material: THREE.Material,
16-
Proto: Object3DConstructor<T>
18+
material: M,
19+
Proto: Object3DConstructor<T, M>
1720
) => {
1821
const object3D = useMemo(() => {
1922
return new Proto(geometry, material);

Diff for: packages/use-shader-fx/types/fxs/3D/useMorphParticles/index.d.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as THREE from "three";
22
import { HooksReturn } from "../../types";
33
import { UseCreateMorphParticlesProps } from "./useCreateMorphParticles";
44
import { HooksProps3D } from "../types";
5+
import { InteractiveMesh, MorphParticlePoints } from "./utils/useCreateObject";
56
export type MorphParticlesParams = {
67
/** progress value to morph vertices,0~1 */
78
morphProgress?: number;
@@ -50,8 +51,8 @@ export type MorphParticlesParams = {
5051
};
5152
export type MorphParticlesObject = {
5253
scene: THREE.Scene;
53-
points: THREE.Points;
54-
interactiveMesh: THREE.Mesh;
54+
points: MorphParticlePoints;
55+
interactiveMesh: InteractiveMesh;
5556
renderTarget: THREE.WebGLRenderTarget;
5657
output: THREE.Texture;
5758
positions: Float32Array[];

Diff for: packages/use-shader-fx/types/fxs/3D/useMorphParticles/useCreateMorphParticles.d.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as THREE from "three";
22
import { Size, RootState } from "@react-three/fiber";
3+
import { InteractiveMesh, MorphParticlePoints } from "./utils/useCreateObject";
34
import { MorphParticlesParams } from ".";
45
import { Create3DHooksProps } from "../types";
56
export type UseCreateMorphParticlesProps = {
@@ -16,8 +17,8 @@ type UpdateUniform = (props: RootState | null, params?: MorphParticlesParams) =>
1617
type UseCreateMorphParticlesReturn = [
1718
UpdateUniform,
1819
{
19-
points: THREE.Points;
20-
interactiveMesh: THREE.Mesh;
20+
points: MorphParticlePoints;
21+
interactiveMesh: InteractiveMesh;
2122
positions: Float32Array[];
2223
uvs: Float32Array[];
2324
}

Diff for: packages/use-shader-fx/types/fxs/3D/useMorphParticles/utils/useCreateObject.d.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ type UseCreateObjectProps = {
44
geometry: THREE.BufferGeometry;
55
material: THREE.ShaderMaterial;
66
};
7+
export type MorphParticlePoints = THREE.Points<THREE.BufferGeometry<THREE.NormalBufferAttributes>, THREE.ShaderMaterial>;
8+
export type InteractiveMesh = THREE.Mesh<THREE.BufferGeometry<THREE.NormalBufferAttributes>, THREE.ShaderMaterial>;
79
export declare const useCreateObject: ({ scene, geometry, material, }: UseCreateObjectProps) => {
8-
points: THREE.Points<THREE.BufferGeometry<THREE.NormalBufferAttributes>, THREE.Material>;
9-
interactiveMesh: THREE.Mesh<THREE.BufferGeometry<THREE.NormalBufferAttributes>, THREE.Material>;
10+
points: MorphParticlePoints;
11+
interactiveMesh: InteractiveMesh;
1012
};
1113
export {};

0 commit comments

Comments
 (0)