Generátor 360° Ozvučnice - Celulárny Mandelbulb
body { margin: 0; overflow: hidden; background: #151618; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; color: white; }
#canvas-container { width: 100vw; height: 100vh; position: absolute; top: 0; left: 0; }
#gui-container { position: absolute; top: 15px; right: 15px; z-index: 10; }
#stats-panel {
position: absolute; bottom: 20px; left: 20px; z-index: 10;
background: rgba(15, 15, 20, 0.85); border-left: 3px solid #bf00ff;
padding: 15px 20px; border-radius: 4px; box-shadow: 0 4px 15px rgba(0,0,0,0.5);
backdrop-filter: blur(5px); width: 260px; pointer-events: none;
}
.stat-row { display: flex; justify-content: space-between; margin-bottom: 8px; font-size: 13px; }
.stat-label { color: #8899aa; }
.stat-value { font-weight: bold; font-family: monospace; font-size: 14px; }
h3 { margin: 0 0 15px 0; font-size: 14px; text-transform: uppercase; letter-spacing: 1px; color: #bf00ff; border-bottom: 1px solid #333; padding-bottom: 5px; }
{
"imports": {
"three": "https://unpkg.com/three@0.160.0/build/three.module.js",
"three/addons/": "https://unpkg.com/three@0.160.0/examples/jsm/"
}
}
Live Akustické Dáta
Základný objem:
-- L
Základná Šírka:
-- mm
Celková Výška:
-- mm
Architektúra:
Celulárna fúzia
import * as THREE from 'three';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
import { RoomEnvironment } from 'three/addons/environments/RoomEnvironment.js';
import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
// --- 1. ZÁKLADNÉ NASTAVENIE SCÉNY ---
const container = document.getElementById('canvas-container');
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x151618, 0.015);
const camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 100);
camera.position.set(0, 1.5, 6);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.2;
container.appendChild(renderer.domElement);
const controls = new OrbitControls(camera, renderer.domElement);
controls.enableDamping = true;
controls.autoRotate = false;
controls.target.set(0, 1.5, 0);
const pmremGenerator = new THREE.PMREMGenerator(renderer);
scene.environment = pmremGenerator.fromScene(new RoomEnvironment(), 0.04).texture;
const lightGroup = new THREE.Group();
scene.add(lightGroup);
const keyLight = new THREE.DirectionalLight(0xffffff, 2.0);
keyLight.position.set(3, 5, 3);
lightGroup.add(keyLight);
const rimLight = new THREE.DirectionalLight(0xbf00ff, 2.0);
rimLight.position.set(-3, 2, -4);
lightGroup.add(rimLight);
const bottomLight = new THREE.PointLight(0xffaa00, 1.5, 5);
bottomLight.position.set(0, -1, 0);
scene.add(bottomLight);
const productGroup = new THREE.Group();
scene.add(productGroup);
// --- 2. VIZUÁLNY REFERENČNÝ MENIČ ---
const driverGroup = new THREE.Group();
const frameMesh = new THREE.Mesh(
new THREE.CylinderGeometry(0.55, 0.55, 0.02, 64),
new THREE.MeshStandardMaterial({ color: 0x111111, roughness: 0.8 })
);
frameMesh.position.y = 0.01;
const coneMesh = new THREE.Mesh(
new THREE.ConeGeometry(0.46, 0.25, 64),
new THREE.MeshStandardMaterial({ color: 0x050505, roughness: 0.9 })
);
coneMesh.rotation.x = Math.PI;
coneMesh.position.y = -0.105;
const magnetMesh = new THREE.Mesh(
new THREE.CylinderGeometry(0.35, 0.35, 0.3, 32),
new THREE.MeshStandardMaterial({ color: 0x222222, metalness: 0.5 })
);
magnetMesh.position.y = 0.17;
const plugMesh = new THREE.Mesh(
new THREE.ConeGeometry(0.08, 0.15, 32),
new THREE.MeshStandardMaterial({ color: 0x333333, metalness: 0.8, roughness: 0.2 })
);
plugMesh.rotation.x = Math.PI;
plugMesh.position.y = -0.1;
driverGroup.add(frameMesh);
driverGroup.add(coneMesh);
driverGroup.add(magnetMesh);
driverGroup.add(plugMesh);
productGroup.add(driverGroup);
const wireMesh = new THREE.Mesh(
new THREE.CylinderGeometry(0.04, 0.04, 5, 16),
new THREE.MeshStandardMaterial({ color: 0x050505, roughness: 0.9 })
);
productGroup.add(wireMesh);
// --- 3. PARAMETRE ---
const params = {
seed: 847291,
color: 0xc4c4c4,
autoColor: false,
colorSpeed: 0.002,
roughness: 0.35,
metalness: 0.15,
autoMorph: false,
morphSpeed: 0.08,
rotationSpeed: 0.005,
lightRotationSpeed: 0.003,
// NOVÉ: Celulárne a Mandelbulb parametre
cellIntensity: 0.25, // Sila 3D deformácie (hĺbka pórov/záhybov)
cellScale: 4.5, // Veľkosť buniek (menšie číslo = obrovské pláty, väčšie = drobné detaily)
cellOctaves: 4, // Počet vrstiev zvrásnenia (1 = hladké vlny, 5 = mikroskopické detaily)
generate: function() {
params.seed = Math.floor(Math.random() * 10000000);
gui.controllersRecursive().forEach(c => c.updateDisplay());
setTargetShape(params.seed);
}
};
const material = new THREE.MeshStandardMaterial({
color: params.color,
roughness: params.roughness,
metalness: params.metalness,
side: THREE.DoubleSide,
flatShading: false // Plynulé tiene na fraktáloch
});
let speakerMesh = new THREE.Mesh(new THREE.BufferGeometry(), material);
productGroup.add(speakerMesh);
// --- 4. MATEMATIKA: 2D BÁZA + 3D BUNKOVÁ DEFORMÁCIA ---
let currentPoints = [];
let targetPoints = [];
let isMorphing = false;
let lastAutoMorph = 0;
// Na 3D fraktály potrebujeme hustú mriežku bodov
const PROFILE_POINTS = 100;
const RADIAL_SEGMENTS = 160;
function mulberry32(a) {
return function() {
var t = a += 0x6D2B79F5;
t = Math.imul(t ^ t >>> 15, t | 1);
t ^= t + Math.imul(t ^ t >>> 7, t | 61);
return ((t ^ t >>> 14) >>> 0) / 4294967296;
}
}
// Vygeneruje základný hladký tvar (Bézierova kvapka/vajíčko)
function generateBaseBezier(seed) {
const rand = mulberry32(seed);
const wallThickness = 0.05;
const driverR = 0.5;
const H = 1.2 + rand() * 1.5;
const maxR = 1.0 + rand() * 1.8;
const path = new THREE.CurvePath();
const type = Math.floor(rand() * 3);
const ptStart = new THREE.Vector2(driverR + wallThickness, 0);
const ptTop = new THREE.Vector2(0.04, H);
let ptMid, cp1, cp2, cp3, cp4;
if (type === 0) {
ptMid = new THREE.Vector2(maxR, H * 0.3);
cp1 = new THREE.Vector2(driverR + 0.1, H * 0.1);
cp2 = new THREE.Vector2(maxR, H * 0.1);
cp3 = new THREE.Vector2(maxR, H * 0.6);
cp4 = new THREE.Vector2(0.2, H * 0.8);
} else if (type === 1) {
ptMid = new THREE.Vector2(maxR, H * 0.5);
cp1 = new THREE.Vector2(maxR * 0.5, 0);
cp2 = new THREE.Vector2(maxR, H * 0.2);
cp3 = new THREE.Vector2(maxR, H * 0.8);
cp4 = new THREE.Vector2(0.04, H * 0.8);
} else {
ptMid = new THREE.Vector2(maxR, H * 0.7);
cp1 = new THREE.Vector2(driverR + 0.2, H * 0.4);
cp2 = new THREE.Vector2(maxR, H * 0.5);
cp3 = new THREE.Vector2(maxR, H * 0.85);
cp4 = new THREE.Vector2(maxR * 0.3, H * 0.95);
}
const curve1 = new THREE.CubicBezierCurve(ptStart, cp1, cp2, ptMid);
const curve2 = new THREE.CubicBezierCurve(ptMid, cp3, cp4, ptTop);
path.add(curve1); path.add(curve2);
return path.getPoints(PROFILE_POINTS);
}
// NOVÁ FUNKCIA: 3D Gyroid / Bunkové Zvrásnenie (Math.abs simuluje záhyby)
function getCellularDisplacement(x, y, z, seedOffset) {
let d = 0;
let amp = 1.0;
// Posun v priestore na základe seedu, aby bol každý tvar iný
let pX = x * params.cellScale + seedOffset;
let pY = y * params.cellScale - seedOffset;
let pZ = z * params.cellScale + seedOffset * 0.5;
for(let i = 0; i < params.cellOctaves; i++) {
// Trik pre bunkovú/gyroid štruktúru:
let n = Math.sin(pX)*Math.cos(pY) + Math.sin(pY)*Math.cos(pZ) + Math.sin(pZ)*Math.cos(pX);
// Math.abs() zmení vlnu na ostré hrebene a hlboké "póry"
d += Math.abs(n) * amp;
amp *= 0.5;
pX *= 2.0; pY *= 2.0; pZ *= 2.0;
// Rotácia 3D priestoru = organické vetvenie buniek
let tx = pX, ty = pY;
pX = 0.8*tx - 0.6*ty;
pY = 0.6*tx + 0.8*ty;
}
return d;
}
function calculateVolume(points) {
let vol = 0;
for(let i = 0; i < points.length - 1; i++) {
let r1 = Math.max(0, points[i].x - 0.05);
let r2 = Math.max(0, points[i+1].x - 0.05);
let h = points[i+1].y - points[i].y;
vol += (Math.PI * h / 3.0) * (r1*r1 + r1*r2 + r2*r2);
}
return vol;
}
function setTargetShape(seed) {
let basePoints = generateBaseBezier(seed);
const minVol = 0.5;
let currentVol = calculateVolume(basePoints);
if (currentVol < minVol) {
const scale = Math.sqrt(minVol / currentVol);
for(let i = 1; i { if(p.x > maxX) maxX = p.x; if(p.y > maxY) maxY = p.y; });
document.getElementById('ui-width').innerText = (maxX * 2 * 100).toFixed(0) + " mm";
document.getElementById('ui-height').innerText = (maxY * 100).toFixed(0) + " mm";
wireMesh.position.y = maxY + 2.5;
if (currentPoints.length === 0) {
currentPoints = targetPoints.map(p => p.clone());
rebuildMesh(currentPoints);
} else {
isMorphing = true;
}
}
// REVOLÚCIA: Aplikácia fraktálov v plnom 3D priestore po vygenerovaní základného Lath geometrie
function rebuildMesh(pointsArray) {
// 1. Vytvoríme základný rotačný objekt
let geo = new THREE.LatheGeometry(pointsArray, RADIAL_SEGMENTS);
// 2. Extrahujeme 3D body a upravíme ich jeden po druhom
if (params.cellIntensity > 0) {
const pos = geo.attributes.position;
const maxY = pointsArray[pointsArray.length - 1].y;
// Získame numerický seed pre konkrétny tvar posunu
const rand = mulberry32(params.seed);
const seedOffset = rand() * 100;
for (let i = 0; i 0.01) {
let r = Math.sqrt(x*x + z*z);
if(r > 0.0) {
// Vektor smerujúci von zo stredu
let nx = x / r;
let nz = z / r;
// Získame hodnotu fraktálu pre túto 3D súradnicu
let disp = getCellularDisplacement(x, y, z, seedOffset);
// Trochu matematickej mágie na stiahnutie hodnôt dovnútra a von
disp = (disp - 0.8) * params.cellIntensity * envelope;
// Posunieme bod po jeho radiále a trochu aj po vertikále pre extra pokrčenie
pos.setX(i, x + nx * disp);
pos.setZ(i, z + nz * disp);
pos.setY(i, y + (Math.cos(disp * 5) * 0.05 * envelope * params.cellIntensity));
}
}
}
// VEĽMI DÔLEŽITÉ: Prepočítať normály tieňov pre nové hrbole!
geo.computeVertexNormals();
}
speakerMesh.geometry.dispose();
speakerMesh.geometry = geo;
}
// --- 5. GUI NASTAVENIA ---
const gui = new GUI({ container: document.getElementById('gui-container'), width: 320 });
gui.title("Ovládanie");
gui.add(params, 'seed', 1, 10000000, 1).name('Architektonický Seed').onChange(v => setTargetShape(v)).listen();
gui.add(params, 'generate').name('🎲 Generovať Novú Formu');
gui.add(params, 'autoMorph').name('✨ Auto-Prehrávanie');
const fractalFolder = gui.addFolder('Mandelbulb / Bunková Mriežka');
fractalFolder.add(params, 'cellIntensity', 0, 0.8).name('Hĺbka Pórov/Buniek').onChange(() => rebuildMesh(currentPoints));
fractalFolder.add(params, 'cellScale', 1, 15).name('Hustota Mriežky').onChange(() => rebuildMesh(currentPoints));
fractalFolder.add(params, 'cellOctaves', 1, 6, 1).name('Detailnosť Zvrásnenia').onChange(() => rebuildMesh(currentPoints));
fractalFolder.open();
const movementFolder = gui.addFolder('Pohyb');
movementFolder.add(params, 'rotationSpeed', 0, 0.05).name('Rotácia objektu');
movementFolder.add(params, 'lightRotationSpeed', 0, 0.05).name('Rotácia svetiel');
const matFolder = gui.addFolder('Materiál (Porcelán / Kosť)');
matFolder.add(params, 'autoColor').name('🌈 Auto Dúha');
matFolder.addColor(params, 'color').name('Farba').onChange(v => material.color.setHex(v));
matFolder.add(params, 'roughness', 0, 1).name('Matnosť').onChange(v => material.roughness = v);
matFolder.add(params, 'metalness', 0, 1).name('Kovovosť').onChange(v => material.metalness = v);
setTargetShape(params.seed);
// --- 6. ANIMAČNÁ SLUČKA ---
window.addEventListener('resize', () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
let hueOffset = 0;
function animate() {
requestAnimationFrame(animate);
controls.update();
productGroup.rotation.y += params.rotationSpeed;
lightGroup.rotation.y += params.lightRotationSpeed;
if (params.autoColor) {
hueOffset += params.colorSpeed;
material.color.setHSL(hueOffset % 1, 0.7, 0.6);
}
if (isMorphing) {
let done = true;
for (let i = 0; i 0.001) {
done = false;
}
}
rebuildMesh(currentPoints);
if (done) isMorphing = false;
}
if (params.autoMorph && !isMorphing) {
const now = Date.now();
if (now - lastAutoMorph > 2500) {
params.generate();
lastAutoMorph = now;
}
}
renderer.render(scene, camera);
}
animate();