Liveweave: Generative AI Web Editor & HTML/CSS/JS Playground
Initializing
Liveweave
Web
expand_more
home
Home
Palette
Color Explorer
arrow_outward
Polyline
Graphics Editor
arrow_outward
frame_source
Python Playground
arrow_outward
build
Tools
expand_more
restart_alt
Load "Hello Weaver!"
post_add
Generate Lorem ipsum...
code
Format HTML
code_blocks
Format CSS
data_object
Format JavaScript
library_add
Library
expand_more
A
Algolia JS
Animate CSS
Apex Charts JS
B
Bulma CSS
Bootstrap
C
Chart JS
Chartist
Create JS
D
D3
Dojo
F
Foundation
Fullpage JS
G
Granim JS
Google Charts
H
Halfmoon
J
jQuery
M
Materialize
Moment JS
Masonry JS
Milligram CSS
P
Pure CSS
Primer CSS
Popper JS
Pattern CSS
Picnic CSS
R
React JS
Raphael JS
Raisin CSS
S
Semantic UI
Skeleton CSS
Spectre CSS
Tachyons CSS
T
Tailwind
Three JS
U
UI Kit
Vis JS
W
Water CSS
download
Download
expand_more
developer_mode
Download as HTML
folder_zip
Download as .ZIP
cloud_upload
Fork
account_circle
Login
settings
Settings
expand_more
Editor font
14
px
A
A
Night mode
Line number
Mini map
Word wrap
sync_alt
Reset Settings
smart_display
Run
left_panel_close
AI Assistant
dashboard
All
HTML
CSS
JS
visibility
Preview
bolt
Live Preview
terminal
JS Console
<!DOCTYPE html> <html> <head> <title>3D structure playground</title> </head> <body> <!-- Start your code here --> <div class="studio"> <header class="topbar"> <div class="brand"> <div class="brand-mark">S<span>■</span></div> <div> <div class="brand-name">STRUCTURE</div> <div class="brand-sub">GENERATIVE ARCHITECTURE STUDIO</div> </div> </div> <div class="top-center"> <span class="live-dot"></span> PROCEDURAL MODE </div> <div class="top-actions"> <button class="top-btn" id="resetBtn">↺ Reset</button> <button class="export-btn" id="exportBtn">↓ Export PNG</button> </div> </header> <main class="workspace"> <section class="viewport-panel"> <div class="canvas-head"> <div> <div class="eyebrow">DESIGN WORKSPACE / 001</div> <h1>Architectural study <span id="projectNumber">01</span></h1> </div> <div class="canvas-meta"> <span id="objectCount">0 OBJECTS</span> <span class="meta-divider"></span> <span>3D PERSPECTIVE</span> </div> </div> <div id="viewport"> <div class="viewport-label">STRUCTURE / 001</div> <div class="viewport-hint">DRAG TO ROTATE <span>·</span> SCROLL TO ZOOM</div> <div class="loading" id="loading">BUILDING YOUR STRUCTURE…</div> </div> <div class="canvas-footer"> <div class="axis-legend"> <span><i class="axis-x"></i> X AXIS</span> <span><i class="axis-y"></i> Y AXIS</span> <span><i class="axis-z"></i> Z AXIS</span> </div> <div class="canvas-footer-right"> <span>ORTHOGRAPHIC-INSPIRED VIEW</span> <span class="footer-separator">/</span> <span id="materialLabel">CONCRETE</span> </div> </div> </section> <aside class="controls"> <div class="panel-heading"> <div> <div class="eyebrow">PARAMETRIC DESIGN</div> <h2>Configuration</h2> </div> <div class="panel-icon">⌘</div> </div> <div class="control-section"> <div class="section-title"><span>01</span> FORM & MASSING</div> <div class="control-row"> <label for="widthControl">Width <output id="widthValue">7</output></label> <input id="widthControl" type="range" min="3" max="10" value="7"> </div> <div class="control-row"> <label for="depthControl">Depth <output id="depthValue">6</output></label> <input id="depthControl" type="range" min="3" max="10" value="6"> </div> <div class="control-row"> <label for="heightControl">Height <output id="heightValue">6</output></label> <input id="heightControl" type="range" min="2" max="10" value="6"> </div> <div class="control-row"> <label for="densityControl">Building density <output id="densityValue">75%</output></label> <input id="densityControl" type="range" min="25" max="100" value="75"> </div> </div> <div class="control-section"> <div class="section-title"><span>02</span> COMPOSITION</div> <div class="toggle-row"> <div> <div class="toggle-title">Symmetrical layout</div> <div class="toggle-desc">Mirror the building composition</div> </div> <label class="switch"> <input type="checkbox" id="symmetryControl" checked> <span class="switch-track"></span> </label> </div> <div class="control-row"> <label for="variationControl">Variation <output id="variationValue">55%</output></label> <input id="variationControl" type="range" min="0" max="100" value="55"> </div> </div> <div class="control-section"> <div class="section-title"><span>03</span> MATERIALS</div> <div class="material-options"> <button class="material-option active" data-material="concrete"> <span class="swatch concrete-swatch"></span> <span>Concrete</span> </button> <button class="material-option" data-material="glass"> <span class="swatch glass-swatch"></span> <span>Glass</span> </button> <button class="material-option" data-material="metal"> <span class="swatch metal-swatch"></span> <span>Metal</span> </button> <button class="material-option" data-material="monochrome"> <span class="swatch mono-swatch"></span> <span>Mono</span> </button> </div> </div> <div class="control-section"> <div class="section-title"><span>04</span> LIGHTING</div> <div class="control-row"> <label for="lightControl">Light intensity <output id="lightValue">75%</output></label> <input id="lightControl" type="range" min="10" max="150" value="75"> </div> </div> <div class="generate-area"> <button class="generate-btn" id="generateBtn"> <span class="generate-icon">✳</span> GENERATE STRUCTURE <span class="generate-arrow">↗</span> </button> <div class="generate-caption">Create a new procedural architectural composition</div> </div> <div class="panel-bottom"> <span>STRUCTURE STUDIO</span> <span>V 1.0.0</span> </div> </aside> </main> </div> <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script> <!-- End your code here --> </body> </html>
@import url('https://fonts.googleapis.com/css2?family=DM+Mono:wght@400;500&family=Manrope:wght@400;500;600;700;800&display=swap'); :root { --bg: #101113; --panel: #17191c; --line: #292c30; --text: #e9e9e6; --muted: #777c82; --accent: #d5b98c; } * { box-sizing: border-box; } body { margin: 0; background: var(--bg); color: var(--text); font-family: 'Manrope', sans-serif; } button, input { font: inherit; } button { cursor: pointer; } .studio { min-height: 760px; height: 100vh; display: flex; flex-direction: column; overflow: hidden; background: var(--bg); } .topbar { height: 72px; flex-shrink: 0; display: flex; align-items: center; justify-content: space-between; padding: 0 30px; border-bottom: 1px solid var(--line); background: #141619; } .brand { display: flex; align-items: center; gap: 12px; } .brand-mark { width: 35px; height: 35px; display: grid; place-items: center; border: 1px solid #77736a; color: var(--accent); font-size: 20px; font-weight: 800; } .brand-mark span { font-size: 9px; vertical-align: top; } .brand-name { font-size: 13px; font-weight: 800; letter-spacing: 2.4px; } .brand-sub, .eyebrow, .top-center, .canvas-meta, .viewport-label, .viewport-hint, .canvas-footer, .section-title, .panel-bottom, .generate-caption { font-family: 'DM Mono', monospace; } .brand-sub { margin-top: 4px; color: var(--muted); font-size: 8px; letter-spacing: 1.1px; } .top-center { display: flex; align-items: center; gap: 9px; color: #999e9e; font-size: 9px; letter-spacing: 1.5px; } .live-dot { width: 6px; height: 6px; border-radius: 50%; background: #9cba8b; box-shadow: 0 0 9px #9cba8b; } .top-actions { display: flex; align-items: center; gap: 10px; } .top-btn, .export-btn { border: 1px solid var(--line); background: transparent; color: #c4c6c6; padding: 10px 14px; font-size: 10px; letter-spacing: .4px; transition: .2s; } .top-btn:hover { border-color: #777; color: white; } .export-btn { background: var(--accent); color: #171716; border-color: var(--accent); font-weight: 800; } .export-btn:hover { background: #e5cda8; } .workspace { min-height: 0; flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 310px; } .viewport-panel { min-width: 0; display: flex; flex-direction: column; padding: 25px 28px 17px; } .canvas-head { display: flex; justify-content: space-between; align-items: end; gap: 15px; margin-bottom: 19px; } .eyebrow { color: #888d91; font-size: 9px; letter-spacing: 1.5px; } .canvas-head h1 { margin: 8px 0 0; font-size: clamp(19px, 2vw, 25px); font-weight: 500; letter-spacing: -.8px; } .canvas-head h1 span { color: #747a7e; font-size: 13px; font-family: 'DM Mono', monospace; vertical-align: middle; margin-left: 5px; } .canvas-meta { display: flex; gap: 12px; align-items: center; color: #858a8e; font-size: 8px; letter-spacing: 1px; white-space: nowrap; padding-bottom: 4px; } .meta-divider { height: 12px; width: 1px; background: #3b3e41; } #viewport { position: relative; flex: 1; min-height: 350px; overflow: hidden; border: 1px solid #2b2e31; background: radial-gradient(ellipse at 50% 43%, #27292b 0%, #1b1d1f 43%, #151719 100%); cursor: grab; } #viewport:active { cursor: grabbing; } #viewport canvas { display: block; width: 100%; height: 100%; outline: none; } .viewport-label, .viewport-hint { position: absolute; z-index: 2; pointer-events: none; color: #777d80; font-size: 8px; letter-spacing: 1.2px; } .viewport-label { top: 17px; left: 18px; } .viewport-hint { bottom: 17px; left: 18px; color: #777d80; } .viewport-hint span { color: var(--accent); padding: 0 5px; } .loading { position: absolute; inset: 0; display: grid; place-items: center; z-index: 4; background: #17191c; color: var(--accent); font: 10px 'DM Mono', monospace; letter-spacing: 2px; transition: opacity .4s; } .loading.hidden { opacity: 0; pointer-events: none; } .canvas-footer { display: flex; justify-content: space-between; gap: 10px; padding-top: 14px; color: #777d80; font-size: 8px; letter-spacing: .8px; } .axis-legend, .canvas-footer-right { display: flex; align-items: center; gap: 14px; } .axis-legend span { display: flex; align-items: center; gap: 6px; } .axis-legend i { width: 7px; height: 7px; display: inline-block; } .axis-x { background: #bd746d; } .axis-y { background: #83a98a; } .axis-z { background: #789bc3; } .footer-separator { color: #414549; } .controls { display: flex; flex-direction: column; min-height: 0; padding: 25px 22px 0; border-left: 1px solid var(--line); background: var(--panel); overflow-y: auto; } .panel-heading { display: flex; justify-content: space-between; align-items: center; padding-bottom: 22px; border-bottom: 1px solid var(--line); } .panel-heading h2 { margin: 7px 0 0; font-size: 17px; font-weight: 600; } .panel-icon { width: 30px; height: 30px; display: grid; place-items: center; border: 1px solid #34383c; color: var(--accent); font-size: 15px; } .control-section { padding: 20px 0; border-bottom: 1px solid var(--line); } .section-title { margin-bottom: 19px; color: #d2d2cd; font-size: 9px; letter-spacing: 1.2px; } .section-title span { color: var(--accent); margin-right: 8px; } .control-row { margin-bottom: 17px; } .control-row:last-child { margin-bottom: 0; } .control-row label { display: flex; justify-content: space-between; align-items: center; color: #b9bcbf; font-size: 10px; margin-bottom: 10px; } .control-row output { color: var(--accent); font: 10px 'DM Mono', monospace; } input[type="range"] { appearance: none; width: 100%; height: 3px; border-radius: 0; background: #414549; outline: none; cursor: pointer; } input[type="range"]::-webkit-slider-thumb { appearance: none; width: 11px; height: 11px; border-radius: 50%; background: var(--accent); border: 2px solid #282a2b; box-shadow: 0 0 0 1px var(--accent); } input[type="range"]::-moz-range-thumb { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); border: 2px solid #282a2b; } .toggle-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; } .toggle-title { font-size: 10px; color: #c3c5c5; } .toggle-desc { margin-top: 4px; color: #777d80; font-size: 9px; } .switch { position: relative; width: 34px; height: 19px; } .switch input { opacity: 0; width: 0; height: 0; } .switch-track { position: absolute; inset: 0; background: #414549; border-radius: 20px; cursor: pointer; transition: .2s; } .switch-track:before { content: ""; position: absolute; width: 13px; height: 13px; left: 3px; top: 3px; border-radius: 50%; background: #b7b9b9; transition: .2s; } .switch input:checked + .switch-track { background: #7c725e; } .switch input:checked + .switch-track:before { transform: translateX(15px); background: #f0d8ae; } .material-options { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; } .material-option { display: flex; align-items: center; gap: 8px; padding: 9px 8px; border: 1px solid #34383c; background: #1b1e21; color: #aeb2b3; font-size: 9px; text-align: left; transition: .2s; } .material-option:hover { border-color: #777; } .material-option.active { border-color: var(--accent); color: #e8d5b8; background: #25231f; } .swatch { width: 15px; height: 15px; border: 1px solid #ffffff30; display: inline-block; } .concrete-swatch { background: #aaa69d; } .glass-swatch { background: linear-gradient(135deg, #a5c4c5, #465f70); } .metal-swatch { background: linear-gradient(135deg, #d1d2d0, #55595d); } .mono-swatch { background: linear-gradient(135deg, #eee, #555); } .generate-area { padding: 21px 0 18px; } .generate-btn { width: 100%; min-height: 43px; display: flex; align-items: center; justify-content: space-between; padding: 0 12px; border: 0; background: var(--accent); color: #1b1a17; font-size: 9px; font-weight: 800; letter-spacing: .8px; transition: .2s; } .generate-btn:hover { background: #e7cda6; transform: translateY(-1px); } .generate-icon { font-size: 16px; } .generate-arrow { font-size: 15px; } .generate-caption { margin-top: 10px; color: #73797d; font-size: 8px; line-height: 1.6; } .panel-bottom { margin-top: auto; padding: 14px 0 17px; display: flex; justify-content: space-between; color: #666d71; font-size: 8px; letter-spacing: .8px; border-top: 1px solid var(--line); } @media (max-width: 850px) { .workspace { grid-template-columns: minmax(0, 1fr) 275px; } .viewport-panel { padding: 20px 17px 14px; } .controls { padding: 20px 17px 0; } .topbar { padding: 0 18px; } .top-center { display: none; } } @media (max-width: 650px) { .studio { height: auto; min-height: 100vh; overflow: visible; } .topbar { height: 62px; padding: 0 13px; } .brand-sub { display: none; } .brand-name { font-size: 11px; } .top-btn { display: none; } .export-btn { padding: 9px 10px; font-size: 9px; } .workspace { display: flex; flex-direction: column; } .viewport-panel { min-height: 540px; padding: 19px 13px 13px; } #viewport { min-height: 390px; } .canvas-head { align-items: start; } .canvas-meta { font-size: 7px; gap: 7px; padding-top: 5px; } .canvas-footer { font-size: 7px; } .axis-legend, .canvas-footer-right { gap: 8px; } .controls { overflow: visible; border-left: 0; border-top: 1px solid var(--line); padding: 20px 18px 0; } .panel-bottom { margin-top: 5px; } }
(() => { const viewport = document.getElementById('viewport'); if (!viewport || typeof THREE === 'undefined') { console.error('STRUCTURE requires Three.js.'); return; } const $ = id => document.getElementById(id); const settings = { width: 7, depth: 6, height: 6, density: 75, variation: 55, symmetry: true, material: 'concrete', light: 75 }; let scene, camera, renderer, buildingGroup; let directionalLight, ambientLight; let projectNumber = 1; let objectCount = 0; let isDragging = false; let previousPointer = { x: 0, y: 0 }; let rotation = { x: -0.35, y: 0.55 }; let cameraDistance = 19; let target = new THREE.Vector3(0, 2, 0); let currentSeed = 0; const materials = { concrete: [ 0xb8b2a7, 0x9d9a91, 0xc4beb2, 0x888982, 0xaaa69c ], glass: [ 0x799aa3, 0x9db7b9, 0x536f7c, 0xadc4c4, 0x6f8992 ], metal: [ 0x9da1a2, 0x737b80, 0xc2c4c0, 0x5d6469, 0xa8a9a5 ], monochrome: [ 0xe0e0dc, 0xa3a4a2, 0x777a7b, 0x55595c, 0xc5c6c3 ] }; function random() { // Seeded random number generator currentSeed = (currentSeed * 1664525 + 1013904223) % 4294967296; return currentSeed / 4294967296; } function init() { scene = new THREE.Scene(); scene.background = new THREE.Color(0x191b1d); camera = new THREE.PerspectiveCamera( 38, viewport.clientWidth / viewport.clientHeight, 0.1, 150 ); renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false, preserveDrawingBuffer: true }); renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2)); renderer.setSize(viewport.clientWidth, viewport.clientHeight); renderer.shadowMap.enabled = true; renderer.shadowMap.type = THREE.PCFSoftShadowMap; renderer.outputEncoding = THREE.sRGBEncoding; renderer.toneMapping = THREE.ACESFilmicToneMapping; renderer.toneMappingExposure = 1.15; viewport.appendChild(renderer.domElement); ambientLight = new THREE.HemisphereLight(0xd9d4ca, 0x303236, 1.35); scene.add(ambientLight); directionalLight = new THREE.DirectionalLight(0xffe4bd, 2.2); directionalLight.position.set(-7, 13, 9); directionalLight.castShadow = true; directionalLight.shadow.mapSize.set(2048, 2048); directionalLight.shadow.camera.left = -15; directionalLight.shadow.camera.right = 15; directionalLight.shadow.camera.top = 15; directionalLight.shadow.camera.bottom = -15; directionalLight.shadow.bias = -0.0005; scene.add(directionalLight); const fillLight = new THREE.DirectionalLight(0x9bb8d0, 0.55); fillLight.position.set(8, 6, -8); scene.add(fillLight); const ground = new THREE.Mesh( new THREE.PlaneGeometry(200, 200), new THREE.MeshStandardMaterial({ color: 0x1a1c1e, roughness: 0.95 }) ); ground.rotation.x = -Math.PI / 2; ground.position.y = -0.06; ground.receiveShadow = true; scene.add(ground); const grid = new THREE.GridHelper(60, 60, 0x34383a, 0x292d30); grid.position.y = -0.045; grid.material.transparent = true; grid.material.opacity = 0.42; scene.add(grid); buildingGroup = new THREE.Group(); scene.add(buildingGroup); updateCamera(); generateBuilding(); bindControls(); resize(); window.addEventListener('resize', resize); animate(); setTimeout(() => $('loading').classList.add('hidden'), 500); } function makeMaterial(color) { const glass = settings.material === 'glass'; const metal = settings.material === 'metal'; return new THREE.MeshStandardMaterial({ color, roughness: glass ? 0.2 : metal ? 0.28 : 0.82, metalness: metal ? 0.78 : glass ? 0.25 : 0.06, transparent: glass, opacity: glass ? 0.82 : 1 }); } function addBox(x, y, z, w, h, d, color, group = buildingGroup) { const geometry = new THREE.BoxGeometry(w, h, d); const mesh = new THREE.Mesh(geometry, makeMaterial(color)); mesh.position.set(x, y + h / 2, z); mesh.castShadow = true; mesh.receiveShadow = true; group.add(mesh); objectCount++; return mesh; } function addSlab(x, y, z, w, d, color) { return addBox(x, y, z, w, 0.12, d, color); } function generateBuilding() { while (buildingGroup.children.length) { const child = buildingGroup.children.pop(); if (child.geometry) child.geometry.dispose(); if (child.material) child.material.dispose(); } objectCount = 0; currentSeed = Math.floor(Math.random() * 1000000000); const W = settings.width; const D = settings.depth; const H = settings.height; const colors = materials[settings.material]; const cell = 1.15; const floorHeight = 0.85; const gap = 0.08; const startX = -((W - 1) * cell) / 2; const startZ = -((D - 1) * cell) / 2; // Foundation platform addBox(0, -0.16, 0, W * cell + 0.5, 0.22, D * cell + 0.5, 0x555653); const occupancy = []; for (let x = 0; x < W; x++) { occupancy[x] = []; for (let z = 0; z < D; z++) { const edgeDistance = Math.min(x, z, W - 1 - x, D - 1 - z); const centrality = 1 - edgeDistance / Math.max(1, Math.min(W, D) / 2); const chance = settings.density / 100; let occupied = random() < chance; if (settings.symmetry) { const mirrorX = Math.min(x, W - 1 - x); const mirrorZ = Math.min(z, D - 1 - z); const key = `${mirrorX}-${mirrorZ}`; if (!occupancy._mirror) occupancy._mirror = {}; if (occupancy._mirror[key] === undefined) { occupancy._mirror[key] = random() < chance; } occupied = occupancy._mirror[key]; } // Keep a strong central core if (centrality < 0.35) occupied = true; let levels = Math.max(1, Math.round( H * (0.35 + random() * 0.65) )); const variation = settings.variation / 100; levels = Math.round( H * (1 - variation) * 0.65 + levels * variation ); levels = Math.max(1, Math.min(H, levels)); occupancy[x][z] = { occupied, levels }; } } // Create massing for (let x = 0; x < W; x++) { for (let z = 0; z < D; z++) { const cellData = occupancy[x][z]; if (!cellData.occupied) continue; const px = startX + x * cell; const pz = startZ + z * cell; const levels = cellData.levels; const color = colors[Math.floor(random() * colors.length)]; // Stacked floor volumes for (let floor = 0; floor < levels; floor++) { const inset = floor > 0 && random() < 0.16 ? 0.08 : 0; const width = cell - gap - inset; const depth = cell - gap - inset; const y = floor * floorHeight; addBox( px, y, pz, width, floorHeight - 0.09, depth, color ); // Fine floor plate accents if (floor > 0 && random() < 0.36) { addSlab( px, y - 0.07, pz, width + 0.06, depth + 0.06, colors[(Math.floor(random() * colors.length) + 1) % colors.length] ); } } // Occasional rooftop caps if (random() < 0.34) { addSlab( px, levels * floorHeight - 0.04, pz, cell * 0.9, cell * 0.9, colors[Math.floor(random() * colors.length)] ); } } } // Add a few connecting bridges and architectural overhangs const bridgeCount = Math.max(2, Math.floor(W * D * 0.09)); for (let i = 0; i < bridgeCount; i++) { const x = Math.floor(random() * (W - 1)); const z = Math.floor(random() * D); const a = occupancy[x][z]; const b = occupancy[x + 1][z]; if (a.occupied && b.occupied && random() > 0.35) { const y = Math.min(a.levels, b.levels) * floorHeight - 0.12; const px = startX + (x + 0.5) * cell; const pz = startZ + z * cell; addBox(px, y, pz, cell * 0.95, 0.16, 0.28, colors[1]); } } // A central vertical architectural core const coreHeight = H * floorHeight * 0.9; addBox( 0, 0, 0, 0.36, coreHeight, 0.36, settings.material === 'glass' ? 0x9ab8bd : 0x6b6c68 ); $('objectCount').textContent = `${objectCount} OBJECTS`; $('projectNumber').textContent = String(projectNumber).padStart(2, '0'); $('materialLabel').textContent = settings.material.toUpperCase(); } function updateCamera() { const radius = cameraDistance; const phi = Math.PI / 2 - rotation.x; const theta = rotation.y; camera.position.set( target.x + radius * Math.sin(phi) * Math.sin(theta), target.y + radius * Math.cos(phi), target.z + radius * Math.sin(phi) * Math.cos(theta) ); camera.lookAt(target); } function resize() { if (!renderer || !camera) return; const width = viewport.clientWidth; const height = viewport.clientHeight; if (!width || !height) return; camera.aspect = width / height; camera.updateProjectionMatrix(); renderer.setSize(width, height); } function updateLighting() { const intensity = settings.light / 75; directionalLight.intensity = 2.2 * intensity; ambientLight.intensity = 1.35 * intensity; } function bindSlider(id, key, output, suffix = '') { const control = $(id); control.addEventListener('input', () => { settings[key] = Number(control.value); $(output).textContent = control.value + suffix; if (key === 'light') { updateLighting(); } else { generateBuilding(); } }); } function bindControls() { bindSlider('widthControl', 'width', 'widthValue'); bindSlider('depthControl', 'depth', 'depthValue'); bindSlider('heightControl', 'height', 'heightValue'); bindSlider('densityControl', 'density', 'densityValue', '%'); bindSlider('variationControl', 'variation', 'variationValue', '%'); bindSlider('lightControl', 'light', 'lightValue', '%'); $('symmetryControl').addEventListener('change', event => { settings.symmetry = event.target.checked; generateBuilding(); }); document.querySelectorAll('.material-option').forEach(button => { button.addEventListener('click', () => { document.querySelectorAll('.material-option').forEach(item => item.classList.remove('active') ); button.classList.add('active'); settings.material = button.dataset.material; generateBuilding(); }); }); $('generateBtn').addEventListener('click', () => { projectNumber++; generateBuilding(); }); $('resetBtn').addEventListener('click', resetSettings); $('exportBtn').addEventListener('click', exportImage); viewport.addEventListener('pointerdown', event => { isDragging = true; previousPointer = { x: event.clientX, y: event.clientY }; viewport.setPointerCapture(event.pointerId); }); viewport.addEventListener('pointermove', event => { if (!isDragging) return; const dx = event.clientX - previousPointer.x; const dy = event.clientY - previousPointer.y; previousPointer = { x: event.clientX, y: event.clientY }; rotation.y += dx * 0.008; rotation.x += dy * 0.006; rotation.x = Math.max(-1.05, Math.min(0.85, rotation.x)); updateCamera(); }); viewport.addEventListener('pointerup', () => isDragging = false); viewport.addEventListener('pointercancel', () => isDragging = false); viewport.addEventListener('wheel', event => { event.preventDefault(); cameraDistance += event.deltaY * 0.012; cameraDistance = Math.max(8, Math.min(38, cameraDistance)); updateCamera(); }, { passive: false }); } function resetSettings() { Object.assign(settings, { width: 7, depth: 6, height: 6, density: 75, variation: 55, symmetry: true, material: 'concrete', light: 75 }); const values = { widthControl: 7, depthControl: 6, heightControl: 6, densityControl: 75, variationControl: 55, lightControl: 75 }; Object.entries(values).forEach(([id, value]) => { $(id).value = value; }); $('widthValue').textContent = '7'; $('depthValue').textContent = '6'; $('heightValue').textContent = '6'; $('densityValue').textContent = '75%'; $('variationValue').textContent = '55%'; $('lightValue').textContent = '75%'; $('symmetryControl').checked = true; document.querySelectorAll('.material-option').forEach(button => { button.classList.toggle('active', button.dataset.material === 'concrete'); }); rotation = { x: -0.35, y: 0.55 }; cameraDistance = 19; updateCamera(); updateLighting(); projectNumber++; generateBuilding(); } function exportImage() { renderer.render(scene, camera); const link = document.createElement('a'); link.download = `structure-${String(projectNumber).padStart(2, '0')}.png`; link.href = renderer.domElement.toDataURL('image/png'); link.click(); } function animate() { requestAnimationFrame(animate); renderer.render(scene, camera); } init(); })();
terminal
JavaScript Console
Preview
Clear
close
›
Run