——>广告推广里跳跳鱼首页的3d图形有源码嘛? - 大佬论坛
网站指南
商家中心
域名市场
开源码桶
实用工具
搜索
登录
注册
显示禁闭内容
是否对公众显示此内容
——>广告推广里跳跳鱼首页的3d图形有源码嘛?
DDJJWW
(
UID:
680)
2025-6-28
[复制链接]
帖子链接已复制到剪贴板
帖子已经有人评论啦,不支持删除!
902
4
求一下
这家伙太懒了,什么也没留下。
收藏
投币
×
给楼主投上
1
枚硬币
1硬币
2硬币
确定
当前您的硬币余额:0
评论加载中...
已有评论
(
4
)
只看楼主
倒序
Cow
(
UID:
5154)
2025-6-28
1
楼
ᅟᅠ
Cow
(
UID:
5154)
2025-6-28
2
楼
我发给你
Cow
(
UID:
5154)
2025-6-28
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;
DDJJWW
(
UID:
680)
楼主
2025-6-28
4
楼
Cow
我发给你
谢谢你,我只会简单的html+js+php,你发的有点难,我需要ds一下嘛?
您还未登录
想参与评论?
登录后即可发表评论、回复等操作。
登录
注册账号
域名市场
域名载入中...
创建新帖
DDJJWW
UID:680
104
主题数
1563
评论数
1
粉丝数
自助推广
购买广告位
×
帖子
用户
Google
Bing
搜索历史
清空
猜你想搜
加载中...