Guest User

icon.tsx

a guest
Jan 3rd, 2025
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use client'
  2. import { useGLTF } from '@react-three/drei'
  3. import { useFrame } from '@react-three/fiber'
  4. import { easing } from 'maath'
  5. import { useRef } from 'react'
  6. import { useMousePosition } from 'shared-ui'
  7. import * as THREE from 'three'
  8. import type { GLTF } from 'three-stdlib'
  9.  
  10. type GLTFResult = GLTF & {
  11.   nodes: {
  12.     0: THREE.Mesh
  13.     1: THREE.Mesh
  14.   }
  15.   materials: {}
  16. }
  17.  
  18. const ROTATION_MULTIPLIER = 0.2
  19.  
  20. export function ZOGIcon(props: JSX.IntrinsicElements['group']) {
  21.   const { nodes } = useGLTF('/images/3d-icon.gltf') as GLTFResult
  22.   const groupRef = useRef<THREE.Group>(null)
  23.   const mousePosition = useMousePosition()
  24.  
  25.   useFrame(() => {
  26.     if (groupRef.current) {
  27.       const targetRotationX = -mousePosition.y * ROTATION_MULTIPLIER * 0.5
  28.       const targetRotationY = mousePosition.x * ROTATION_MULTIPLIER * 0.5
  29.       easing.damp(groupRef.current.rotation, 'x', targetRotationX, 0.5)
  30.       easing.damp(groupRef.current.rotation, 'y', targetRotationY, 0.5)
  31.     }
  32.   })
  33.  
  34.   return (
  35.     <>
  36.       {/* <Environment preset="city" /> */}
  37.       <group {...props} ref={groupRef} scale={0.009} position={[0, 0, 0]}>
  38.         <ambientLight intensity={0.5} />
  39.         <directionalLight position={[5, 5, 5]} intensity={0.6} />{' '}
  40.         <group rotation={[0, 0, 0]}>
  41.           <mesh geometry={nodes['1'].geometry} position={[200, 0, 0]} scale={[1, 1, 3]}>
  42.             <meshPhysicalMaterial
  43.               transparent
  44.               opacity={1}
  45.               transmission={1}
  46.               thickness={0.8}
  47.               roughness={0.4}
  48.               clearcoat={1}
  49.               ior={5}
  50.               metalness={0.5}
  51.             />
  52.           </mesh>
  53.           <mesh geometry={nodes['0'].geometry} position={[-310, 0, 0]} scale={[1, 1, 3]}>
  54.             <meshPhysicalMaterial
  55.               transparent
  56.               opacity={1}
  57.               transmission={1}
  58.               thickness={0.8}
  59.               roughness={0.4}
  60.               clearcoat={1}
  61.               ior={5}
  62.               metalness={0.5}
  63.             />
  64.           </mesh>
  65.         </group>
  66.       </group>
  67.     </>
  68.   )
  69. }
  70.  
  71. useGLTF.preload('/images/3d-icon.gltf')
Advertisement
Add Comment
Please, Sign In to add comment