three.js
Orbital Shards
Warm glass shards in orbit around a slow core. Drag to look around. The live example for the three.js guide.
مجوز: CC BY-NC-SA 4.0: ریمیکس با ذکر نام، غیرتجاری، با همین مجوز
دیدن کد
import * as THREE from "three";
import { OrbitControls } from "three/addons/controls/OrbitControls.js";
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(innerWidth, innerHeight);
document.body.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0d0d12);
const camera = new THREE.PerspectiveCamera(45, innerWidth / innerHeight, 0.1, 100);
camera.position.set(0, 1.5, 8);
new OrbitControls(camera, renderer.domElement);
const core = new THREE.Mesh(
new THREE.IcosahedronGeometry(1.3, 1),
new THREE.MeshStandardMaterial({ color: 0xffb454, flatShading: true, roughness: 0.35, metalness: 0.1 })
);
scene.add(core);
const MAXSHARDS = 26;
const shards = [];
const shardMat = new THREE.MeshStandardMaterial({ color: 0x7fd4c9, flatShading: true, roughness: 0.3, metalness: 0.15 });
const shardMat2 = new THREE.MeshStandardMaterial({ color: 0xe9e5da, flatShading: true, roughness: 0.45, metalness: 0.05 });
for (let i = 0; i < MAXSHARDS; i++) {
const s = new THREE.Mesh(new THREE.TetrahedronGeometry(0.32), i % 3 === 0 ? shardMat2 : shardMat);
s.userData = { r: 2.2 + (i % 5) * 0.45, speed: 0.25 + (i % 7) * 0.09, phase: i * 2.39996, tilt: (i % 5 - 2) * 0.22 };
scene.add(s);
shards.push(s);
}
scene.add(new THREE.HemisphereLight(0xffffff, 0x302040, 2.4));
const key = new THREE.DirectionalLight(0xffe0b0, 2.2);
key.position.set(4, 6, 3);
scene.add(key);
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
});
renderer.setAnimationLoop((ms) => {
const t = (ms / 1000) * params.speed;
core.rotation.set(t * 0.22, t * 0.34, 0);
core.scale.setScalar(params.size);
const n = Math.floor(params.shards);
for (let i = 0; i < MAXSHARDS; i++) {
const s = shards[i];
s.visible = i < n;
if (!s.visible) continue;
const u = s.userData;
const a = u.phase + t * u.speed;
s.position.set(Math.cos(a) * u.r, Math.sin(a * 1.3 + u.phase) * u.tilt * 2.2, Math.sin(a) * u.r);
s.rotation.set(a * 1.7, a * 2.3, a);
}
renderer.render(scene, camera);
});