Skip to content

Commit 037679f

Browse files
author
takuma-hmng8
committed
domSyncerにrotationを追加
1 parent 2bd2bdc commit 037679f

File tree

10 files changed

+21
-7
lines changed

10 files changed

+21
-7
lines changed

app/domSyncer/DomSyncer.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ export const DomSyncer = ({ state }: { state: number }) => {
6262
setDomSyncer({
6363
dom: domArr.current,
6464
boderRadius: [...Array(domArr.current.length)].map((_, i) => i * 50.0),
65+
rotation: [...Array(domArr.current.length)].map(
66+
(_, i) => new THREE.Euler(0.0, 0.0, i * 0.1)
67+
),
6568
onIntersect: [...Array(domArr.current.length)].map(
6669
(_, i) => (entry) => {
6770
if (

packages/use-shader-fx/build/use-shader-fx.js

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/use-shader-fx/build/use-shader-fx.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/use-shader-fx/build/use-shader-fx.umd.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ void main() {
496496
alpha *= textureAlpha;
497497
498498
gl_FragColor = vec4(textureColor, alpha);
499-
}`;const Je=({params:n,size:i,scene:r})=>{r.children.length>0&&(r.children.forEach(e=>{e instanceof t.Mesh&&(e.geometry.dispose(),e.material.dispose())}),r.remove(...r.children)),n.texture.forEach((e,o)=>{const s=new t.Mesh(new t.PlaneGeometry(1,1),new t.ShaderMaterial({vertexShader:Ye,fragmentShader:qe,transparent:!0,uniforms:{u_texture:{value:e},u_textureResolution:{value:new t.Vector2(0,0)},u_resolution:{value:new t.Vector2(0,0)},u_borderRadius:{value:n.boderRadius[o]?n.boderRadius[o]:0}}}));r.add(s)})},Ke=()=>{const n=u.useRef([]),i=u.useRef([]);return u.useCallback(({isIntersectingRef:e,isIntersectingOnceRef:o,params:s})=>{n.current.length>0&&n.current.forEach((a,l)=>{a.unobserve(i.current[l])}),i.current=[],n.current=[];const c=new Array(s.dom.length).fill(!1);e.current=[...c],o.current=[...c],s.dom.forEach((a,l)=>{const d=m=>{m.forEach(g=>{s.onIntersect[l]&&s.onIntersect[l](g),e.current[l]=g.isIntersecting})},f=new IntersectionObserver(d,{rootMargin:"0px",threshold:0});f.observe(a),n.current.push(f),i.current.push(a)})},[])},Ze=({params:n,size:i,resolutionRef:r,scene:e,isIntersectingRef:o})=>{e.children.forEach((s,c)=>{const a=n.dom[c];if(!a)throw new Error("DOM is null.");if(o.current[c]){const l=a.getBoundingClientRect();if(s.scale.set(l.width,l.height,1),s.position.set(l.left+l.width*.5-i.width*.5,-l.top-l.height*.5+i.height*.5,0),s instanceof t.Mesh){const d=s.material;v(d,"u_texture",n.texture[c]),v(d,"u_textureResolution",n.resolution[c]),v(d,"u_resolution",r.current.set(l.width,l.height)),v(d,"u_borderRadius",n.boderRadius[c]?n.boderRadius[c]:0)}}})},Qe=()=>{const n=u.useRef([]),i=u.useRef([]),r=u.useCallback((e,o=!1)=>{n.current.forEach((c,a)=>{c&&(i.current[a]=!0)});const s=o?[...i.current]:[...n.current];return e<0?s:s[e]},[]);return{isIntersectingRef:n,isIntersectingOnceRef:i,isIntersecting:r}},J={texture:[],dom:[],resolution:[],boderRadius:[],onIntersect:[]},en=({size:n,dpr:i},r=[])=>{const e=u.useMemo(()=>new t.Scene,[]),o=_(n),[s,c]=C({scene:e,camera:o,size:n,dpr:i,isSizeUpdate:!0}),[a,l]=P(J),d=u.useRef(new t.Vector2(0,0)),[f,m]=u.useState(!0);u.useEffect(()=>{m(!0)},r);const g=Ke(),{isIntersectingOnceRef:h,isIntersectingRef:x,isIntersecting:y}=Qe();return[u.useCallback((w,M)=>{const{gl:D,size:A}=w;return M&&l(M),He(a),f&&(Je({params:a,size:A,scene:e}),g({isIntersectingRef:x,isIntersectingOnceRef:h,params:a}),m(!1)),Ze({params:a,size:A,resolutionRef:d,scene:e,isIntersectingRef:x}),c(D)},[c,l,g,f,e,a,h,x]),l,{scene:e,camera:o,renderTarget:s,isIntersecting:y}]};var nn=`precision mediump float;
499+
}`;const Je=({params:n,size:i,scene:r})=>{r.children.length>0&&(r.children.forEach(e=>{e instanceof t.Mesh&&(e.geometry.dispose(),e.material.dispose())}),r.remove(...r.children)),n.texture.forEach((e,o)=>{const s=new t.Mesh(new t.PlaneGeometry(1,1),new t.ShaderMaterial({vertexShader:Ye,fragmentShader:qe,transparent:!0,uniforms:{u_texture:{value:e},u_textureResolution:{value:new t.Vector2(0,0)},u_resolution:{value:new t.Vector2(0,0)},u_borderRadius:{value:n.boderRadius[o]?n.boderRadius[o]:0}}}));r.add(s)})},Ke=()=>{const n=u.useRef([]),i=u.useRef([]);return u.useCallback(({isIntersectingRef:e,isIntersectingOnceRef:o,params:s})=>{n.current.length>0&&n.current.forEach((a,l)=>{a.unobserve(i.current[l])}),i.current=[],n.current=[];const c=new Array(s.dom.length).fill(!1);e.current=[...c],o.current=[...c],s.dom.forEach((a,l)=>{const d=m=>{m.forEach(g=>{s.onIntersect[l]&&s.onIntersect[l](g),e.current[l]=g.isIntersecting})},f=new IntersectionObserver(d,{rootMargin:"0px",threshold:0});f.observe(a),n.current.push(f),i.current.push(a)})},[])},Ze=({params:n,size:i,resolutionRef:r,scene:e,isIntersectingRef:o})=>{e.children.forEach((s,c)=>{const a=n.dom[c];if(!a)throw new Error("DOM is null.");if(o.current[c]){const l=a.getBoundingClientRect();if(s.scale.set(l.width,l.height,1),s.position.set(l.left+l.width*.5-i.width*.5,-l.top-l.height*.5+i.height*.5,0),n.rotation[c]&&s.rotation.copy(n.rotation[c]),s instanceof t.Mesh){const d=s.material;v(d,"u_texture",n.texture[c]),v(d,"u_textureResolution",n.resolution[c]),v(d,"u_resolution",r.current.set(l.width,l.height)),v(d,"u_borderRadius",n.boderRadius[c]?n.boderRadius[c]:0)}}})},Qe=()=>{const n=u.useRef([]),i=u.useRef([]),r=u.useCallback((e,o=!1)=>{n.current.forEach((c,a)=>{c&&(i.current[a]=!0)});const s=o?[...i.current]:[...n.current];return e<0?s:s[e]},[]);return{isIntersectingRef:n,isIntersectingOnceRef:i,isIntersecting:r}},J={texture:[],dom:[],resolution:[],boderRadius:[],rotation:[],onIntersect:[]},en=({size:n,dpr:i},r=[])=>{const e=u.useMemo(()=>new t.Scene,[]),o=_(n),[s,c]=C({scene:e,camera:o,size:n,dpr:i,isSizeUpdate:!0}),[a,l]=P(J),d=u.useRef(new t.Vector2(0,0)),[f,m]=u.useState(!0);u.useEffect(()=>{m(!0)},r);const g=Ke(),{isIntersectingOnceRef:h,isIntersectingRef:x,isIntersecting:y}=Qe();return[u.useCallback((w,M)=>{const{gl:D,size:A}=w;return M&&l(M),He(a),f&&(Je({params:a,size:A,scene:e}),g({isIntersectingRef:x,isIntersectingOnceRef:h,params:a}),m(!1)),Ze({params:a,size:A,resolutionRef:d,scene:e,isIntersectingRef:x}),c(D)},[c,l,g,f,e,a,h,x]),l,{scene:e,camera:o,renderTarget:s,isIntersecting:y}]};var nn=`precision mediump float;
500500
501501
varying vec2 vUv;
502502

packages/use-shader-fx/build/use-shader-fx.umd.cjs.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/use-shader-fx/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/use-shader-fx/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hmng8/use-shader-fx",
3-
"version": "1.0.18",
3+
"version": "1.0.19",
44
"description": "wide variety of shader effects for React",
55
"main": "./build/use-shader-fx.umd.cjs",
66
"module": "./build/use-shader-fx.js",

packages/use-shader-fx/src/hooks/useDomSyncer/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export type DomSyncerParams = {
2020
resolution?: THREE.Vector2[];
2121
/** default:0.0[] */
2222
boderRadius?: number[];
23+
/** the angle you want to rotate */
24+
rotation?: THREE.Euler[];
2325
/** Array of callback functions when crossed */
2426
onIntersect?: ((entry: IntersectionObserverEntry) => void)[];
2527
};
@@ -42,6 +44,7 @@ export const DOMSYNCER_PARAMS: DomSyncerParams = {
4244
dom: [],
4345
resolution: [],
4446
boderRadius: [],
47+
rotation: [],
4548
onIntersect: [],
4649
};
4750

packages/use-shader-fx/src/hooks/useDomSyncer/utils/updateRect.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ export const updateRect = ({
3030
-rect.top - rect.height * 0.5 + size.height * 0.5,
3131
0.0
3232
);
33+
34+
if (params.rotation![i]) {
35+
mesh.rotation.copy(params.rotation![i]);
36+
}
37+
3338
if (mesh instanceof THREE.Mesh) {
3439
const material: DomSyncerMaterial = mesh.material;
3540
setUniform(material, "u_texture", params.texture![i]);

packages/use-shader-fx/types/hooks/useDomSyncer/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export type DomSyncerParams = {
1212
resolution?: THREE.Vector2[];
1313
/** default:0.0[] */
1414
boderRadius?: number[];
15+
/** the angle you want to rotate */
16+
rotation?: THREE.Euler[];
1517
/** Array of callback functions when crossed */
1618
onIntersect?: ((entry: IntersectionObserverEntry) => void)[];
1719
};

0 commit comments

Comments
 (0)