three+react+drei实现三维玻璃弹珠上下起伏动画效果代码
代码语言:html
所属分类:三维
代码描述:three+react+drei实现三维玻璃弹珠上下起伏动画效果代码
代码标签: three react drei 三维 玻璃 弹珠 上下 起伏 动画
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> body, #root { margin: 0; background: #f2f2f5; height: 100vh; } </style> </head> <body translate="no"> <div id="root"></div> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/babel.7.18.13.js"></script> <script type="text/babel" data-presets="react" data-type="module"> import React from 'https://esm.sh/react@18.2.0' import ReactDOM from 'https://esm.sh/react-dom@18.2.0' import { Canvas, useFrame } from 'https://esm.sh/@react-three/fiber@8.15.16' import { Center, Instance, Instances, OrbitControls, MeshTransmissionMaterial, AccumulativeShadows, RandomizedLight, Environment, Lightformer, } from 'https://esm.sh/@react-three/drei@9.99.4' const Grid = ({ number = 23, lineWidth = 0.026, height = 0.5 }) => ( <Instances position={[-1, -1.02, 0]}> <planeGeometry args={[lineWidth, height]} /> <meshBasicMaterial color="#999" /> {Array.from({ length: number }, (_, y) => Array.from({ length: number }, (_, x) => ( <group key={x + ':' + y} position={[x * 2 - Math.floor(number / 2) * 2, -0.01, y * 2 - Math.floor(number / 2) * 2]}> <Instance rotation={[-Math.PI / 2, 0, 0]} /> <Instance rotation={[-Math.PI / 2, 0, Math.PI / 2]} /> </group> )) )} <gridHelper args={[200, 100, '#bbb', '#bbb']} position={[0, -0.01, 0]} /> </Instances> ) function Shape() { const itemsRef = React.useRef([]); React.useEffect(() => { }, []); useFrame((state, delta) => { for (let i = 0; i < itemsRef.current.length; i++) { itemsRef.current[i].position.y = Math.sin((state.clock.elapsedTime + i * 0.5) * 3) * 0.25 + 0.23 ; } }) const config = { "backside": true, "backsideThickness": 0.3, "samples": 16, "resolution": 1024, "transmission": 1, "clearcoat": 0.1, "clearcoatRoughness": 0, "thickness": 0.3, "chromaticAberration": 5, &qu.........完整代码请登录后点击上方下载按钮下载查看
网友评论0