加载应用…
云澜 Clyune Clyune Component Gallery · 中文

Wireframe Sphere · How it works & code

The regular icosahedron has 20 triangular faces.

Runtime logic

Visiting `/threejs/wire`, DemoHost lazy-loads `demos/kits/kit-three.js` (registry `mod: 'kit-three'`) and calls `mount(host, { variant: 'wire' })`. mount resolves the variant to family `wire`; `withControls` builds the control panel (6 presets + sliders). `createThreeStage` sets up WebGLRenderer, Scene, PerspectiveCamera and OrbitControls, plus the info panel. The family’s `build(S)` initialises state and returns the per-frame callback. Every `requestAnimationFrame`: read controls, advance a speed-scaled clock (dt ≤ 50 ms), run the frame callback; returned readouts go to the info panel. Changing parameters: colour/speed/size apply live; structural ones remount; leaving the page cancels rAF, removes listeners and frees resources.

Environment

Canvas 2D: 2D canvas drawing; WebGL (three.js): WebGL through three.js WebGLRenderer; requestAnimationFrame: Display-synced animation loop; ResizeObserver: Canvas follows container size; Pointer Events: Unified mouse/touch/pen events; devicePixelRatio: Crisp HiDPI rendering (capped at 2×) · react 18.3.1, react-router-dom 6.30.6, vite 5.4.21, three 0.170.0

Dependencies

three 0.170.0, three/addons/controls/OrbitControls.js 0.170.0, react 18.3.1

Imported APIs

withControls — Wraps the demo in the shared control panel (presets, sliders, reset); hot-updates or remounts on change; paramsFromSpec — Turns the spec (colour/speed/size/count/extras) into control-panel parameter definitions; createThreeStage — Shared three.js stage: WebGLRenderer, scene, perspective camera, OrbitControls, auto framing and render loop; addLights — Adds ambient + key + fill lights; THREE — three.js namespace; fmt — Number formatting (fixed decimals); deg — Radians → degrees text; F — Formula block HTML; S.get — Reads current control values; S.onFrame — Registers a per-frame callback; its return value feeds the info panel; THREE.Mesh — Mesh (geometry + material); THREE.IcosahedronGeometry — Icosahedron geometry; THREE.MeshBasicMaterial — Unlit material

Source code

frontend/src/demos/kits/kit-three.js: FAM.wire (L183-L201)

Code walkthrough

L184-184: Control definitions (colour/speed/size/count/extras): Line color, Zoom, Subdivision level d. L185-185: Preset buttons: name → parameter overrides (6). L186-186: 3D framing radius. L187-195: Info-panel content: live rows(v), formula, notes, params, steps. L196-200: Init function: sets up state and returns the per-frame callback: creates three.js objects `Mesh`, `IcosahedronGeometry`, `MeshBasicMaterial`; math via `Math.max`, `Math.min`, `Math.round`, `Math.sin`; returns readouts `th`, `d` to the info panel.

Principles

Each segment: each triangle → 4 A little triangle Euler formula: V - E + F = 2 The regular icosahedron has 20 triangular faces. Divide When you connect the midpoint of each side, a triangle becomes 4 P 1-3, push the new vertebrae to the surface——The more you break down, the closer you get to the ball“Geostationary ball”). No matter how many times it's broken down, the top points − Prism + Noodles Always equals 2, This is cams Euler Formula 。

Open the interactive demo · GitHub