——>广告推广里跳跳鱼首页的3d图形有源码嘛?

V DDJJWW  (UID: 680) [复制链接]
帖子链接已复制到剪贴板
帖子已经有人评论啦,不支持删除!

902 4

求一下

这家伙太懒了,什么也没留下。
已有评论 ( 4 )
  • 头像
    Cow (UID: 5154)
    1楼

    ᅟᅠ        ‌‍‎‏ 

  • 头像
    Cow (UID: 5154)
    2楼

    我发给你

  • 头像
    Cow (UID: 5154)
    3楼
    react组件名 blob.tsx  放到你的项目里面就行
     
    import { useRef, useEffect, useState } from "react";
    import { createNoise3D } from "simplex-noise";
    import * as THREE from "three";
     
    const Blob = () => {
      const containerRef = useRef<HTMLDivElement>(null);
      const [speed] = useState<number>(50);
      const [spikes] = useState<number>(0.8);
      const [processing] = useState<number>(1);

     

      useEffect(() => {
        if (!containerRef.current) return;

     

        let renderer: THREE.WebGLRenderer;
        let camera: THREE.PerspectiveCamera;
        let scene: THREE.Scene;
        let sphere: THREE.Mesh;
        let animationFrameId: number;
     
        const init = () => {
          const container = containerRef.current;
          if (!container) return;
     
          const canvas = document.createElement("canvas");
          container.appendChild(canvas);
     
          renderer = new THREE.WebGLRenderer({
            canvas,
            antialias: true,
            alpha: true,
          });
     
          renderer.setSize(window.innerWidth, window.innerHeight);
          renderer.setPixelRatio(window.devicePixelRatio || 1);
     
          scene = new THREE.Scene();
     
          camera = new THREE.PerspectiveCamera(
            45,
            window.innerWidth / window.innerHeight,
            0.1,
            1000
          );
          camera.position.z = 3.5;
     
          const geometry = new THREE.SphereGeometry(0.8, 128, 128);
          const material = new THREE.MeshPhongMaterial({
            color: 0xffffff,
            shininess: 100,
            emissive: 0x404040,
            transparent: true,
            opacity: 0.5,
          });
     
          sphere = new THREE.Mesh(geometry, material);
          scene.add(sphere);
     
     
          const lightTop = new THREE.DirectionalLight(0xffffff, 3);
          lightTop.position.set(0, 500, 200);
          lightTop.castShadow = true;
          scene.add(lightTop);
     
          const lightBottom = new THREE.DirectionalLight(0xffffff, 2);
          lightBottom.position.set(0, -500, 400);
          lightBottom.castShadow = true;
          scene.add(lightBottom);
     
          const ambientLight = new THREE.AmbientLight(0x798296);
          scene.add(ambientLight);
     
          const simplex = createNoise3D();
          const update = () => {
            const time = performance.now() * 0.00001 * speed * processing ** 3;
            const spikesValue = spikes * processing;
     
            if (sphere.geometry instanceof THREE.BufferGeometry) {
              const positionAttribute = sphere.geometry.attributes.position;
              const positions = positionAttribute.array;
     
              for (let i = 0; i < positions.length; i += 3) {
                const x = positions[i];
                const y = positions[i + 1];
                const z = positions[i + 2];
     
                const vertex = new THREE.Vector3(x, y, z).normalize();
                const noiseValue =
                  0.3 *
                  simplex(
                    vertex.x * spikesValue,
                    vertex.y * spikesValue,
                    vertex.z * spikesValue + time
                  );
                vertex.multiplyScalar(1 + noiseValue);
     
                positions[i] = vertex.x;
                positions[i + 1] = vertex.y;
                positions[i + 2] = vertex.z;
              }
     
              positionAttribute.needsUpdate = true;
              sphere.geometry.computeVertexNormals();
              sphere.geometry.attributes.normal.needsUpdate = true;
            } else {
              console.error(
                "sphere.geometry is not an instance of THREE.BufferGeometry"
              );
            }
          };
     
          const animate = () => {
            update();
            renderer.render(scene, camera);
            animationFrameId = requestAnimationFrame(animate);
          };

     

          animationFrameId = requestAnimationFrame(animate);
        };
     
        const onWindowResize = () => {
          const width = window.innerWidth;
          const height = window.innerHeight;
     
          renderer.setSize(width, height);
     
          camera.aspect = width / height;
          camera.updateProjectionMatrix();
     
          const aspectRatio = width / height;
          camera.position.z = 3.5 / aspectRatio < 3.5 ? 3.5 : 3.5 / aspectRatio;
        };

     

        init();
        onWindowResize();
     
        window.addEventListener("resize", onWindowResize);
     
        return () => {
          window.removeEventListener("resize", onWindowResize);
          if (animationFrameId) {
            cancelAnimationFrame(animationFrameId);
          }
          if (containerRef.current?.firstChild) {
            containerRef.current.removeChild(containerRef.current.firstChild);
          }
     
          if (sphere) {
            sphere.geometry.dispose();
            (sphere.material as THREE.Material).dispose();
          }
          if (scene) {
            scene.clear();
          }
          if (renderer) {
            renderer.dispose();
          }
        };
      }, [speed, spikes, processing]);
     
      return (
        <div className="fixed inset-0 -z-10">
          <div ref={containerRef} className="w-full h-full" id="canvas-container" />
        </div>
      );
    };

     

    export default Blob;

     

  • 头像
    V DDJJWW (UID: 680)
    4楼
    Cow 我发给你

    谢谢你,我只会简单的html+js+php,你发的有点难,我需要ds一下嘛?

域名市场
   域名载入中...
创建新帖
自助推广购买广告位
确认删除
确定要删除这篇帖子吗?删除后将无法恢复。
删除成功
帖子已成功删除,页面将自动刷新。
删除失败
删除帖子时发生错误,请稍后再试。