A toolbox of film styles made in code for Claude Code: 66 ready to use, and your own. Each style is a style prompt plus a demo film made entirely in code by Claude Opus 5.5, with no video model. By Lemomo. · 一套用代码做片的风格工具箱:66 种现成风格,也能做出你自己的
JavaScript agent-skillsai-agentsai-short-filmai-videoanimationcanvasclaudeclaude-codeclaude-code-pluginclaude-code-skillcreative-codingffmpegfilmmakingmotion-graphicsopus-5-5prompt-librarytext-to-speechthreejsvideo-productionwebgl
New style: Memphis Diorama (孟菲斯微缩景观), demo Four Seasons in Pomelo Town
Eian2784e8bf3f2d
diff --git a/styles/memphis-diorama/DEMO.md b/styles/memphis-diorama/DEMO.mdnew file mode 100644index 0000000..7409fe1--- /dev/null+++ b/styles/memphis-diorama/DEMO.md@@ -0,0 +1,100 @@+# Memphis Diorama — our demo++One example among many. Don't reuse its story, arc, shots, props or timings.++Demo: *Four Seasons in Pomelo Town* (柚子城的四季, 40 s) · `memphis-diorama.mp4` · source in [`demo/`](demo/)++## Story & structure++One fictional river bend (a river, a bridge, a lane of ten houses, a plaza with one big tree, a lotus pond, fields) goes through spring, summer, autumn and winter in one take, ten seconds each. There is no protagonist: the place is the subject, and the seasons are told only by colour and by small motions.++Every change of season is the same gesture, so the film reads as one piece: **the big tree on the plaza squats down for half a second, springs back, and a wave spreads from it**. Inside the ring the ground, crowns, roofs and water take the next season's colours; as the ring passes, objects act (rows of rape flowers sink, umbrellas open or fold, haystacks pop up, snow starts).++| Season | Time | What changes | Small motions |+|---|---|---|---|+| Spring | 0–10 s | rape fields yellow, paddies flooded sky blue, pink and white blossom with flower dots | petals drift east, kites, swallows, ducks, a boat |+| Summer | 10–20 s | rice green, crowns deep green, three parasols open | a grey-lilac cloud crosses with rain and ripples, then eight lotus flowers open one by one |+| Autumn | 20–30 s | rice gold, grass yellow-green, crowns red, orange and yellow | haystacks pop up field by field, leaves fall, a V of geese flies south-west, swallows leave, lotus wilts |+| Winter | 30–40 s | snow ground, white roofs and haystack caps, pastel crowns with white dots, lilac field ridges | snow, chimney smoke, a snowman appears; from 34 s dusk turns the picture pink-violet and every window and door lamp lights up at its own moment |++ + ++## Shots++One take. The camera orbits the plaza at fov 30°, high and slowly closing in; after 18 s it eases down to 0.3× speed so the pond and the village stay in frame through autumn and winter.++| # | Time | Shot | Camera | Native move / note |+|---|---|---|---|---|+| 1 | 0–1.2 s | the frame grows open on spring | orbit starts, 92 m out, 70 m up | Grow the frame |+| 2 | 1.2–9.3 s | spring: petals, kites, swallows, ducks | slow orbit | Living loop |+| 3 | 8.8–11.9 s | the tree squats (8.8–9.3), springs back, the summer wave spreads | — | Squash and spring → Wave |+| 4 | 11.2–19.2 s | the rain cloud crosses west to east; rain 12.2–17.8 s; lotus 16.6–17.8 s | — | |+| 5 | 18.8–21.9 s | the squat again; the autumn wave | the camera eases to 0.3× speed | Squash and spring → Wave |+| 6 | 21.2–30.6 s | geese cross; haystacks pop 22–27.5 s; leaves fall | slow orbit | |+| 7 | 28.8–31.9 s | the squat again; the winter wave, snow starts behind it | — | Squash and spring → Wave |+| 8 | 32.6 s | a snowman bounces in on the plaza | — | |+| 9 | 33.8–38.3 s | dusk; windows and door lamps light one by one, warm pools on the lane | — | |+| 10 | 39–40 s | the frame draws back in | — | Grow the frame (closing) |++Lines 2 and 3 of the bottom type change at 10.45, 20.45 and 30.45 s, halfway through each wave.++## Score structure++One continuous piece, F major, 96 BPM, a bar = 2.5 s, downbeat of bar 0 at 1.8 s so the three squats land on the downbeats of bars 3, 7 and 11 (9.3, 19.3, 29.3 s). The chords loop Bbmaj7 – C – Am7 – Dm7 (IV–V–iii–vi) once per season and resolve to Fmaj7 at 36.8 s.++- Piano broken chords (left hand root and fifth, right hand eighth notes) run from 0.5 s to the end; the melody is always piano. Phrase A in spring and autumn, a higher phrase B in summer, A again in winter ending on a rising A–C–F.+- Only the thickness of the accompaniment follows the season: spring adds celesta an octave above the melody and a light shaker; summer adds a soft bass line, kick and brushes (kick lowered under the rain); autumn keeps them lighter and doubles the melody on marimba; winter drops the drums, doubles the melody on a music box and holds long bass notes.+- Every squat sounds the same: a soft low thump at the squat (T − 0.42 s), a springy rising "boing" at T, a ten-note harp run up from D, a quiet whoosh.+- Foley, all under the music: swallows and ducks; cicadas, a distant thunder at 11.9 s, rain and drips, celesta for the lotus; leaves, haystack pops, six goose calls panned east to west; wind, a pop for the snowman, twelve celesta *tings* on F-pentatonic notes as the windows light.+- Synthesised in `demo/music.py` (additive piano with two detuned strings and a hammer click, detuned-saw pad, noise reverb); mastered by `core/render/mux.sh` to −14 LUFS.++## Palette & props++- Paper `#FFFCF6`; ink `#25214A`; shadow tint (0.70, 0.58, 0.90); window light `#FFD36E`.+- Seasonal materials, as [spring, summer, autumn, winter]: grass `#9DE8A6 #6FD889 #D6E68E #FBFCFF`; paddy `#A6E3FB #A4E35F #F2C14E #FBFCFF` (striped); rape field `#FFD234` in spring; water `#8ED8F7 #72C9F3 #7BBFE8 #9FD0F4` with a deeper channel; field ridges turn lilac `#DCD0F2` in winter.+- Crowns (five sets): pink `#FFB8D9 → #3CBE7E → #FF6F61 → #E6DCFF`, white `#FFF1F7 → #2FCB7A → #FFD21F → #D6EAFF`, ginkgo, teal and the big tree; each has a lighter lobe set on the sun side, which turns white in winter (snow on the sunny side).+- Houses: wall colours yellow, pink, mint, lilac, peach, white, sky; roofs coral, cobalt, teal, yellow, plum, all white in winter; striped shutters, flower boxes, awnings, door lamps; two-storey houses get a balcony.+- Five crown shapes (cloud, round, egg, three-tier cone, column), reeds with cattails along the banks, a three-arch bridge with red railings, a boat with a striped sail and a rower, three ducks, distant walkers in the lane, two kite flyers.++## End card++None: the frame draws back in at 39 s over the lit dusk village, with the three bottom lines fading out with it.++## Build notes++```+sh styles/memphis-diorama/demo/build.sh+```++Fonts (if missing) → picture at 60 fps with `core/render/video.mjs` (≈ 2.5 min on an M-series Mac, 4 workers) → `music.py` → `mux.sh` (no added grain) → `readcheck.mjs` → poster at 25 s (autumn, the geese over the haystacks) and the four stills above.++| File | What it holds |+|---|---|+| `demo/memphis.js` | the engine (§10 of STYLE.md): flat material and its patterns, wave colour swap, halftone shade, outline pass, grainy frame, bottom type |+| `demo/main.js` | the place, its four seasons, the timeline and the page contract (`render(t)`, `DUR`, `TEXTS(t)`) |+| `demo/people.js` | distant figures and the walk cycle |+| `demo/music.py` | the score and foley, written to `demo/out/mix.wav` |+| `demo/tools/fonts.py` | subsets Noto Sans SC, Inter Tight, IBM Plex Mono to the on-screen characters |++**Seasonal materials.** `S([spring, summer, autumn, winter], { patCols: […] })` in `main.js` makes a `flat()` material that remembers four colours. Each frame, `place(t)` sets `uCol` to the current season and `uCol2` to the next one, and `setSeason(x, z, r)` gives the wave's centre and radius: pixels inside the ring draw `uCol2`. For actions, `at(n, p)` returns how far season *n* has reached position *p* (0 → 1), so anything can grow, fold or fall as the ring passes it.++**A minimal example the demo never draws** (a striped beach hut whose roof turns white when a wave from the sea reaches it):++```js+import * as THREE from 'three';+import { Diorama, flat, mesh, box, setSeason, setHalftone } from './memphis.js';+const dio = new Diorama(document.getElementById('gl'), document.getElementById('c').getContext('2d'));+setHalftone(1);+mesh(new THREE.PlaneGeometry(80, 80).rotateX(-Math.PI / 2), flat('#FFE6BD', { pat: 1, patCol: '#FFD39A', patScale: 1.2 }), 0, 0, 0, dio.scene);+mesh(box(3, 2.4, 2.4), flat('#5CC8FF', { pat: 4, patCol: '#FFFFFF', patScale: 0.4 }), 0, 0, 0, dio.scene);+const roof = flat('#FF5A5F', { col2: '#FFFFFF' });+mesh(new THREE.ConeGeometry(2.4, 1.4, 4).rotateY(Math.PI / 4), roof, 0, 3.1, 0, dio.scene);+window.render = (t) => {+ setSeason(-30, 0, 12 * t); // a wave from the sea, 12 m/s+ dio.cam.position.set(18, 14, 18); dio.cam.lookAt(0, 1, 0); dio.fitShadow(new THREE.Vector3(0, 0, 0), 20);+ dio.render(t, Math.round(t * 60), { text: ['海边小屋 Beach Hut', '', ''] });+};+```++Pitfalls tied to this demo's props: reeds first read as ink scribbles (fixed with thicker stems and no outline); a constant-speed orbit lost the pond after 25 s (fixed by easing the camera down after 18 s); door-lamp light pools on the ground also lit the roofs above them (fixed by moving each pool 2.3 m out onto the lane).diff --git a/styles/memphis-diorama/STYLE.md b/styles/memphis-diorama/STYLE.mdnew file mode 100644index 0000000..085df8d--- /dev/null+++ b/styles/memphis-diorama/STYLE.md@@ -0,0 +1,134 @@+# Memphis Diorama — Style Prompt++> A place built as a tabletop model: on warm white paper an organic, grainy frame grows open, and inside it a small world in flat Memphis colours, ink outlines, hard purple shadows and tiny patterns, full of small motions under a slow camera. Calm, bright and warm; a place you watch, not a story you follow.+> References (grammar only): the Memphis Group, Ettore Sottsass, Nathalie Du Pasquier (saturated primaries next to pastels, dots, zigzags and terrazzo flecks on every surface); architectural and railway-layout models (a whole place seen from above, at once); children's picture-book towns (every window has a flower box, every corner has something going on); risograph halftone (shadow as a field of dots). Use none of their objects, layouts, palettes or music.++## 1. Essence, and what it is not++- **Paper and a grainy frame.** A warm white ground; the picture lives in a rounded, organic frame whose edge dissolves into grain. It grows open from the centre at the start and draws back in at the end.+- **Memphis flat colour.** Saturated primaries plus pastels, flat fills, no gradients; a deep-indigo ink outline; small patterns tiled on surfaces (dots, stripes, zigzags, terrazzo flecks, halftone).+- **The eye of a model-maker.** High three-quarter, top-down or cutaway views. The film always looks at a *place*, never at a person.+- **Small motions everywhere.** Water, wind in trees, cloud shadows, birds, boats, walkers, lights coming on one by one. The place is alive because of them, not because of a protagonist.+- **Three lines of type under the frame**: title / one sentence / small data, under three Memphis marks (a yellow dot, a pink triangle, a blue zigzag).++Not character animation: nobody acts. Code-made faces, gestures, getting in and out of cars always look stiff, so this style never shows them. Not an isometric infographic (that one is cool and diagrammatic; this one has weather, seasons and sound). Not tilt-shift (no photograph, no depth of field: everything is flat and sharp). Not low-poly (no faceted shading or plastic highlights: flat fills, outlines and patterns do the work).++## 2. Materials & rendering++- **Three tones only**: the top face is the brightest, sun-facing sides keep the base colour, the faces turned away drop to about ×0.5–0.95. Hard edges between faces, never smooth shading.+- **Hard shadows**, never blurred, tinted cool purple (shadow ≈ base × (0.70, 0.58, 0.90)); the sun direction never changes within a film.+- **Halftone in the shade**: inside shadows, a staggered grid of lighter dots in world space, like a print. It turns dark areas into texture instead of dirt.+- **Outline as a post pass** from normals and depth: about 2 px deep indigo `#25214A` at 1080p. Light cones, decals, particles (rain, snow, petals, smoke) and thin stems carry no outline; a thin object that is all outline reads as an ink scribble.+- **Patterns belong to the world**: dots and stripes are computed from world coordinates and stay on the object as it moves. Pattern scale grows with distance so far surfaces do not buzz.+- **Detail is built, not textured**: a house is a plinth, plank-striped walls, white corner trims, two roof slabs and a ridge, a gable with a round window, framed windows with shutters and flower boxes, a door with a step, awning and lamp. A tree is a trunk with a branch and a cluster of lobes, plus lighter lobes on the sun side. Water is layered: bank, shallows, a deeper channel, white foam lines at the edges, small white squiggles drifting with the current.+- **Screen space holds only three things**: the grainy frame, the bottom type, explainer callouts.+- **Never**: depth of field, real reflections, bloom, motion blur, volumetric light. A lit lamp is a flat warm colour plus a hard-edged pool of warm light on the ground.+- **Hero objects do not receive shadows** when they pass through shade, or they turn dirty.++## 3. Colour logic++- The ground outside the frame is always warm white `#FFFCF6`; nothing else is drawn there.+- **5–7 saturated hues + 2–3 pastels** carry the picture. Ink `#25214A` is only for outlines, type, tyres and window frames.+- **Cluster colour by area**: neighbouring blocks differ in hue; one colour's share is controlled (a field type at about a third of the ground, not sprinkled at random). Leave large calm areas of one colour (water, a field, a square) so the picture can breathe.+- **Day is bright and warm.** When it gets dark, darken by the scene: a night scene may be dark, but never grey all over.+- **Night is a luminance shift toward violet**, not a general darkening, so yellows don't go olive; every light is the same warm yellow (about `#FFD36E`). **Dusk** adds an orange-pink layer (about `#FF9E7A`) on the way to night.+- **Time and season change the large areas only** (ground, crowns, roofs, water), never the whole palette. Each changing material carries one colour per state; a wave (§8) swaps them.+- Winter does not mean all white: crowns go to pastel lilac, ice blue and mint with white dots, paths stay swept, houses keep their colours.+- Example palette (an example only): yellow `#FFD234`, pink `#FF7EB3`, sky `#5CC8FF`, mint `#5EDFB0`, lilac `#B9A0FF`, peach `#FF9C6B`, cobalt `#2F5BFF`, coral `#FF5A5F`, green `#2FCB7A`.++## 4. Type & subtitles++- **Three centred lines under the frame**: line 1, the title, Chinese and English, weight 600, about 25 px, dark; line 2, one sentence, weight 400, about 18 px, grey; line 3, small data (time, solar term, place, coordinates) in a monospace, about 15 px, light grey. Line 3 may change with the picture.+- The lines fade in and out with the frame and never move. When a line changes, the old one fades away and the new one fades in; line 1 stays.+- Typefaces: Inter Tight for Latin, Noto Sans SC for Chinese, IBM Plex Mono for data (all OFL).+- Usually no voice: the type is the narration. With a voice, use plain bottom subtitles, one Chinese and one English line, no styled caption boxes.+- Hold every line ≥ max(1.8 s, reading time + 0.6 s).+- **Callouts** for explainers: a rounded pill with a leader line and a dot, Chinese main and English small, popping out of the model with a back-ease and fading when done.++## 5. Motion quality++- **60 fps, every frame moves**; no stepping, no jitter. The frame's grain boils at 12 fps, which is the only thing on twos.+- **Shapes may be simple; motion may not.** Everything eases. Vehicles accelerate, brake and nod; turns follow smooth curves, never polylines.+- All natural motion is procedural and looping: water, trees, cloud shadows, leaves, snow, smoke, flocks. Every object has its own phase; nothing marches in step.+- **People are distant decoration**: small, walking a cycle, flying a kite, rowing. No close-ups, no acting, no hand business.+- Things never pop into being: they grow from nothing or bounce in with a back-ease; a change of state is announced by an object **squashing down and springing back** (anticipation, then overshoot).+- What never moves: the frame's position, the type's position, the paper, the sun direction.++## 6. Camera grammar++A vocabulary, not a route. Opening and ending come from the topic.++| Move | What it expresses | Can serve |+|---|---|---|+| High slow orbit or drift | the whole place breathing | time passing; day and night; seasons; a loop |+| Straight-down, slowly turning | a map; order | road networks; fields; coverage; data on a grid |+| Locked three-quarter frame | calm; comparable | before and after; data; several places side by side |+| Lateral move along a cutaway | above and inside at once | how a thing works; underground; under water; inside a building |+| Slow push to one detail | something is happening here | a lit window; a stall; a bird on a roof |+| Following one vehicle | flow; a route | a delivery; a commute; one line joining places |++- **Prefer one continuous take**, slow enough that the viewer can stop and look at any corner. When a long take must hold a composition, ease the camera speed down instead of letting the place drift out of frame.+- The frame is about 1520 × 744 px, a little above centre; the type sits under it and never covers the subject.+- **Transitions**: only three — the frame draws in and grows out again; a wave sweeps across (colour, light, season); the ground is cut open. No white flash, spin or fast hard cut.+- The camera never passes through geometry; to get around something, move in two steps (rise, then travel).++## 7. Sound palette++- **Warm, gentle and continuous**: piano, Rhodes-like electric piano, marimba, celesta, music box, soft synth bass, a warm pad, brushes and shaker. A quiet stretch can be piano and pad alone.+- **One piece, not a medley**: when the place changes (a season, day to night), keep the same harmony and tempo and change only how thick the accompaniment is. A section that stops and a new one that starts sounds broken.+- **Foley is the sound of small things**, kept under the music: birds, ducks, water, a bicycle bell, raindrops, leaves, geese, wind, snow, the click or *ting* of a light coming on. Tuned foley (a light coming on) uses notes of the current chord or its pentatonic scale.+- **The same event always makes the same sound**: if every change of state starts with a squash, every squash gets the same thump, spring and rising harp.+- Silence is allowed, but keep a faint room tone under it.+- Loudness −14 LUFS, true peak ≤ −1 dBTP; fades follow the frame growing open and drawing in. No voice by default.++## 8. Native moves++A menu: use the ones your story needs.++- **Wave.** A ring spreads from one point; everything it passes takes its next state (colours swap per pixel inside the radius; objects grow, open, fall or light up as the ring reaches them). *Fits content like:* night falling street by street; a change of season; a delivery or signal coverage map; power coming back after an outage.+- **Squash and spring.** One landmark squats, springs back, and the change starts from it. Use it to say "this causes that" without a person. *Fits content like:* a fountain that starts the morning; a factory chimney that starts a shift; a station clock that starts the rush hour.+- **Cutaway.** Cut along a line; the near part sinks and slides away to show the section underground, inside a wall or under water. *Fits content like:* how a metro and its pipes work; a tree's roots; what each floor of a building is doing; fish under a pond.+- **Grow the frame.** The organic frame grows from the centre to open, draws back in to close, and can close and reopen as a chapter break. *Fits content like:* an opening; a change of chapter; an ending.+- **Living loop.** Every small motion is periodic, so a passage loops seamlessly. *Fits content like:* a website hero; a screensaver; a livestream background; a live wallpaper.+- **Callout.** A pill label with a leader line pops out of the model. *Fits content like:* explaining a mechanism; labelling data; naming places.++## 9. Pitfalls of the medium++| Pitfall | Fix |+|---|---|+| Code-made people look stiff close up | keep them small and far; no acting |+| Day looks grey, not healing | raise saturation, warm it; shadows go purple, not grey |+| Yellows turn olive at night | shift by luminance toward violet; give warm objects their own night colour |+| Colours sprinkled at random look dirty | cluster by area, control each hue's share |+| Every tree looks the same | at least five crown shapes (round, cone, egg, cloud, column…), lighter lobes on the sun side |+| Thin objects turn into black scribbles | thicker stems, or no outline and a brighter colour |+| Large shadows look like dirt | halftone dots in the shade |+| Far outlines and patterns buzz | less detail far away; pattern scale grows with distance |+| A long take drifts until the subject leaves the frame | ease the camera speed down over time |+| A state change happens "by itself" and feels arbitrary | anticipate it: a squash on one landmark, then the wave from there |+| The camera passes through an object | move in two steps, or remove the blocking tree for that shot |+| The frame is crowded and has no air | keep large quiet areas of colour (water, field, square) |++## 10. Engine++`demo/memphis.js` (three.js r170): `Diorama(glCanvas, ctx2d)` renders at 2× with a normal-and-depth outline pass, composites the grainy organic frame (`grow` opens it) and draws the bottom type (`drawText`). `flat(hex, o)` is the flat material: `pat` (1 dots, 2 diagonal stripes, 3 zigzag, 4 vertical stripes, 5 hatch, 6 horizontal stripes), `patCol`, `patScale`, `lit` (no face tones), `emit`, `win` (facade windows), `nightCol`, `col2` / `patCol2` (the next state for a wave). Globals: `setSeason(x, z, r)` (wave), `setHalftone(1)`, `setNight`, `setDusk`, `setLamps([[x, y, z, r]…])`, `setWave` / `setZone` (lights coming on). Helpers: `mesh`, `box`, `rng`. `demo/people.js` has the distant walker. A minimal example that the demo never draws, and how the demo's seasonal materials work: [DEMO.md](DEMO.md) "Build notes".++## 11. Variation space++You decide the place, the season and time, the camera route, the pace, which native moves, and the palette within §3.++- Structures: **one take that loops** (a square at the same hour every day, ten seconds that join end to start); **the same place in four states** (a market at dawn, noon, dusk, night); **whole view → cutaway → whole view** (a building, then its floors, then the building again with one thing changed).+- Openings: **the frame grows open**; **a place in the dark before dawn lights up**; **a wave sweeps into an already open frame**.+- Endings: **the frame draws back in**; **the lights go out one by one**; **the camera rises until the place is one dot on a map**.++**Use cases** and the order in which information arrives:++1. **A moving scene on a web page** (hero, loading page, 404): first the whole calm place, then one or two small motions that lead the eye; loopable; scroll or the mouse can trigger a light or a change of sky.+2. **Ambient or focus loops** (livestream backgrounds, screensavers, live wallpapers): no type or a single line; the camera almost still; a seamless loop; sound mostly ambience.+3. **Solar terms and seasonal series**: one place, one term or season per part; the colours and small motions change; line 3 carries the term and the date.+4. **How things work**: the whole place → cut open → callouts one step at a time → back to the whole place with the result visible.+5. **City data maps**: map or locked three-quarter view → the data grows out as a wave or as columns → callouts read the values.++---++How our demo was made (story, shots, score, end card, build): [DEMO.md](DEMO.md). Read it after your treatment exists.diff --git a/styles/memphis-diorama/demo/CREDITS b/styles/memphis-diorama/demo/CREDITSnew file mode 100644index 0000000..9abf9cb--- /dev/null+++ b/styles/memphis-diorama/demo/CREDITS@@ -0,0 +1,18 @@+Four Seasons in Pomelo Town (柚子城的四季) — Memphis Diorama (Lemo-Opuscar)++No AI-generated images, no stock footage, no photographs, no samples. Every shape, colour, shadow, pattern, letter+and sound is made by code in this folder: the scene is three.js geometry with a flat ShaderMaterial and an outline+pass (memphis.js, main.js, people.js); the score and the foley are synthesised in numpy / scipy (music.py).++LIBRARIES+- three.js r170 (MIT), from the library's node_modules.+- numpy, scipy (BSD), from the library's .venv.++FONTS (subset by tools/fonts.py from Google Fonts; licence texts are fetched into fonts/)+- Noto Sans SC 400 / 600 — SIL Open Font License 1.1 (fonts/OFL-notosanssc.txt)+- Inter Tight 400 / 600 — SIL Open Font License 1.1 (fonts/OFL-intertight.txt)+- IBM Plex Mono 400 — SIL Open Font License 1.1 (fonts/OFL-ibmplexmono.txt)++PLACE+Pomelo Town (柚子城) is fictional. The solar-term dates on screen (Spring Equinox, Minor Heat, Autumn Equinox,+Major Snow) are the usual calendar dates of the 24 solar terms, rounded to the day.diff --git a/styles/memphis-diorama/demo/build.sh b/styles/memphis-diorama/demo/build.shnew file mode 100755index 0000000..1e0d524--- /dev/null+++ b/styles/memphis-diorama/demo/build.sh@@ -0,0 +1,34 @@+#!/bin/sh+# One command: 《柚子城的四季》 Four Seasons in Pomelo Town (Memphis Diorama demo)+# sh styles/memphis-diorama/demo/build.sh fonts (if missing) -> picture (60 fps) -> score -> master -> reading check -> poster + stills+set -e+HERE=$(cd "$(dirname "$0")" && pwd) # .../<slug>/demo+FILM=$(cd "$HERE/.." && pwd) # .../<slug>+LIB=${LIB:-$(cd "$HERE/../../.." && pwd)} # styles/<slug>/demo -> library root+export LIB+[ -f "$LIB/core/render/video.mjs" ] || { echo "set LIB to the library folder"; exit 1; }+PY="$LIB/.venv/bin/python"+NAME=memphis-diorama+cd "$LIB"++# fonts (gitignored .woff2, subset from Google Fonts, OFL): fetch when any is missing+for f in NotoSansSC-400 NotoSansSC-600 InterTight-400 InterTight-600 IBMPlexMono-400; do+ [ -f "$HERE/fonts/$f.woff2" ] || { "$PY" -I "$HERE/tools/fonts.py" "$HERE"; break; }+done+mkdir -p "$HERE/out" "$HERE/stills"++# picture at 60 fps (the style never drops frames), score, master (no grain: the frame already carries its own)+node core/render/video.mjs "$HERE" --fps 60 --workers 4 --out "$HERE/out/video.mp4"+"$PY" -I "$HERE/music.py"+sh core/render/mux.sh "$HERE/out/video.mp4" "$HERE/out/mix.wav" "$FILM/$NAME.mp4" 60 0++# every bottom line is held long enough to read+node core/render/readcheck.mjs "$HERE" > "$HERE/out/readcheck.txt" && echo "readcheck ok"++# poster (autumn: haystacks and the geese) = gallery style frame; one still per season for DEMO.md+ffmpeg -v error -y -ss 25.0 -i "$FILM/$NAME.mp4" -frames:v 1 -q:v 2 "$FILM/poster.jpg"+cp "$FILM/poster.jpg" "$HERE/stills/styleframe.jpg"+for s in spring:5.0 summer:15.0 squat:19.32 winter:37.6; do+ ffmpeg -v error -y -ss "${s#*:}" -i "$FILM/$NAME.mp4" -frames:v 1 -q:v 3 -vf scale=960:-1 "$HERE/stills/frame_${s%%:*}.jpg"+done+echo "done: $FILM/$NAME.mp4"diff --git a/styles/memphis-diorama/demo/fonts/OFL-ibmplexmono.txt b/styles/memphis-diorama/demo/fonts/OFL-ibmplexmono.txtnew file mode 100644index 0000000..c35c4c6--- /dev/null+++ b/styles/memphis-diorama/demo/fonts/OFL-ibmplexmono.txt@@ -0,0 +1,93 @@+Copyright © 2017 IBM Corp. with Reserved Font Name "Plex"++This Font Software is licensed under the SIL Open Font License, Version 1.1.++This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL+++-----------------------------------------------------------+SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007+-----------------------------------------------------------++PREAMBLE+The goals of the Open Font License (OFL) are to stimulate worldwide+development of collaborative font projects, to support the font creation+efforts of academic and linguistic communities, and to provide a free and+open framework in which fonts may be shared and improved in partnership+with others.++The OFL allows the licensed fonts to be used, studied, modified and+redistributed freely as long as they are not sold by themselves. The+fonts, including any derivative works, can be bundled, embedded,+redistributed and/or sold with any software provided that any reserved+names are not used by derivative works. The fonts and derivatives,+however, cannot be released under any other type of license. The+requirement for fonts to remain under this license does not apply+to any document created using the fonts or their derivatives.++DEFINITIONS+"Font Software" refers to the set of files released by the Copyright+Holder(s) under this license and clearly marked as such. This may+include source files, build scripts and documentation.++"Reserved Font Name" refers to any names specified as such after the+copyright statement(s).++"Original Version" refers to the collection of Font Software components as+distributed by the Copyright Holder(s).++"Modified Version" refers to any derivative made by adding to, deleting,+or substituting -- in part or in whole -- any of the components of the+Original Version, by changing formats or by porting the Font Software to a+new environment.++"Author" refers to any designer, engineer, programmer, technical+writer or other person who contributed to the Font Software.++PERMISSION & CONDITIONS+Permission is hereby granted, free of charge, to any person obtaining+a copy of the Font Software, to use, study, copy, merge, embed, modify,+redistribute, and sell modified and unmodified copies of the Font+Software, subject to the following conditions:++1) Neither the Font Software nor any of its individual components,+in Original or Modified Versions, may be sold by itself.++2) Original or Modified Versions of the Font Software may be bundled,+redistributed and/or sold with any software, provided that each copy+contains the above copyright notice and this license. These can be+included either as stand-alone text files, human-readable headers or+in the appropriate machine-readable metadata fields within text or+binary files as long as those fields can be easily viewed by the user.++3) No Modified Version of the Font Software may use the Reserved Font+Name(s) unless explicit written permission is granted by the corresponding+Copyright Holder. This restriction only applies to the primary font name as+presented to the users.++4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font+Software shall not be used to promote, endorse or advertise any+Modified Version, except to acknowledge the contribution(s) of the+Copyright Holder(s) and the Author(s) or with their explicit written+permission.++5) The Font Software, modified or unmodified, in part or in whole,+must be distributed entirely under this license, and must not be+distributed under any other license. The requirement for fonts to+remain under this license does not apply to any document created+using the Font Software.++TERMINATION+This license becomes null and void if any of the above conditions are+not met.++DISCLAIMER+THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT+OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE+COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,+INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL+DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING+FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM+OTHER DEALINGS IN THE FONT SOFTWARE.diff --git a/styles/memphis-diorama/demo/fonts/OFL-intertight.txt b/styles/memphis-diorama/demo/fonts/OFL-intertight.txtnew file mode 100644index 0000000..18d0da5--- /dev/null+++ b/styles/memphis-diorama/demo/fonts/OFL-intertight.txt@@ -0,0 +1,93 @@+Copyright 2022 The Inter Project Authors (https://github.com/rsms/inter-tight)++This Font Software is licensed under the SIL Open Font License, Version 1.1.+This license is copied below, and is also available with a FAQ at:+https://scripts.sil.org/OFL+++-----------------------------------------------------------+SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007+-----------------------------------------------------------++PREAMBLE+The goals of the Open Font License (OFL) are to stimulate worldwide+development of collaborative font projects, to support the font creation+efforts of academic and linguistic communities, and to provide a free and+open framework in which fonts may be shared and improved in partnership+with others.++The OFL allows the licensed fonts to be used, studied, modified and+redistributed freely as long as they are not sold by themselves. The+fonts, including any derivative works, can be bundled, embedded,+redistributed and/or sold with any software provided that any reserved+names are not used by derivative works. The fonts and derivatives,+however, cannot be released under any other type of license. The+requirement for fonts to remain under this license does not apply+to any document created using the fonts or their derivatives.++DEFINITIONS+"Font Software" refers to the set of files released by the Copyright+Holder(s) under this license and clearly marked as such. This may+include source files, build scripts and documentation.++"Reserved Font Name" refers to any names specified as such after the+copyright statement(s).++"Original Version" refers to the collection of Font Software components as+distributed by the Copyright Holder(s).++"Modified Version" refers to any derivative made by adding to, deleting,+or substituting -- in part or in whole -- any of the components of the+Original Version, by changing formats or by porting the Font Software to a+new environment.++"Author" refers to any designer, engineer, programmer, technical+writer or other person who contributed to the Font Software.++PERMISSION & CONDITIONS+Permission is hereby granted, free of charge, to any person obtaining+a copy of the Font Software, to use, study, copy, merge, embed, modify,+redistribute, and sell modified and unmodified copies of the Font+Software, subject to the following conditions:++1) Neither the Font Software nor any of its individual components,+in Original or Modified Versions, may be sold by itself.++2) Original or Modified Versions of the Font Software may be bundled,+redistributed and/or sold with any software, provided that each copy+contains the above copyright notice and this license. These can be+included either as stand-alone text files, human-readable headers or+in the appropriate machine-readable metadata fields within text or+binary files as long as those fields can be easily viewed by the user.++3) No Modified Version of the Font Software may use the Reserved Font+Name(s) unless explicit written permission is granted by the corresponding+Copyright Holder. This restriction only applies to the primary font name as+presented to the users.++4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font+Software shall not be used to promote, endorse or advertise any+Modified Version, except to acknowledge the contribution(s) of the+Copyright Holder(s) and the Author(s) or with their explicit written+permission.++5) The Font Software, modified or unmodified, in part or in whole,+must be distributed entirely under this license, and must not be+distributed under any other license. The requirement for fonts to+remain under this license does not apply to any document created+using the Font Software.++TERMINATION+This license becomes null and void if any of the above conditions are+not met.++DISCLAIMER+THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT+OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE+COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,+INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL+DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING+FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM+OTHER DEALINGS IN THE FONT SOFTWARE.diff --git a/styles/memphis-diorama/demo/fonts/OFL-notosanssc.txt b/styles/memphis-diorama/demo/fonts/OFL-notosanssc.txtnew file mode 100644index 0000000..1c9f432--- /dev/null+++ b/styles/memphis-diorama/demo/fonts/OFL-notosanssc.txt@@ -0,0 +1,93 @@+Copyright 2014-2021 Adobe (http://www.adobe.com/), with Reserved Font Name 'Source'++This Font Software is licensed under the SIL Open Font License, Version 1.1.+This license is copied below, and is also available with a FAQ at:+https://scripts.sil.org/OFL+++-----------------------------------------------------------+SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007+-----------------------------------------------------------++PREAMBLE+The goals of the Open Font License (OFL) are to stimulate worldwide+development of collaborative font projects, to support the font creation+efforts of academic and linguistic communities, and to provide a free and+open framework in which fonts may be shared and improved in partnership+with others.++The OFL allows the licensed fonts to be used, studied, modified and+redistributed freely as long as they are not sold by themselves. The+fonts, including any derivative works, can be bundled, embedded,+redistributed and/or sold with any software provided that any reserved+names are not used by derivative works. The fonts and derivatives,+however, cannot be released under any other type of license. The+requirement for fonts to remain under this license does not apply+to any document created using the fonts or their derivatives.++DEFINITIONS+"Font Software" refers to the set of files released by the Copyright+Holder(s) under this license and clearly marked as such. This may+include source files, build scripts and documentation.++"Reserved Font Name" refers to any names specified as such after the+copyright statement(s).++"Original Version" refers to the collection of Font Software components as+distributed by the Copyright Holder(s).++"Modified Version" refers to any derivative made by adding to, deleting,+or substituting -- in part or in whole -- any of the components of the+Original Version, by changing formats or by porting the Font Software to a+new environment.++"Author" refers to any designer, engineer, programmer, technical+writer or other person who contributed to the Font Software.++PERMISSION & CONDITIONS+Permission is hereby granted, free of charge, to any person obtaining+a copy of the Font Software, to use, study, copy, merge, embed, modify,+redistribute, and sell modified and unmodified copies of the Font+Software, subject to the following conditions:++1) Neither the Font Software nor any of its individual components,+in Original or Modified Versions, may be sold by itself.++2) Original or Modified Versions of the Font Software may be bundled,+redistributed and/or sold with any software, provided that each copy+contains the above copyright notice and this license. These can be+included either as stand-alone text files, human-readable headers or+in the appropriate machine-readable metadata fields within text or+binary files as long as those fields can be easily viewed by the user.++3) No Modified Version of the Font Software may use the Reserved Font+Name(s) unless explicit written permission is granted by the corresponding+Copyright Holder. This restriction only applies to the primary font name as+presented to the users.++4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font+Software shall not be used to promote, endorse or advertise any+Modified Version, except to acknowledge the contribution(s) of the+Copyright Holder(s) and the Author(s) or with their explicit written+permission.++5) The Font Software, modified or unmodified, in part or in whole,+must be distributed entirely under this license, and must not be+distributed under any other license. The requirement for fonts to+remain under this license does not apply to any document created+using the Font Software.++TERMINATION+This license becomes null and void if any of the above conditions are+not met.++DISCLAIMER+THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT+OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE+COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,+INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL+DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING+FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM+OTHER DEALINGS IN THE FONT SOFTWARE.diff --git a/styles/memphis-diorama/demo/fonts/fonts.css b/styles/memphis-diorama/demo/fonts/fonts.cssnew file mode 100644index 0000000..a9f1d9e--- /dev/null+++ b/styles/memphis-diorama/demo/fonts/fonts.css@@ -0,0 +1,5 @@+@font-face{font-family:'SC';src:url(NotoSansSC-400.woff2) format('woff2');font-weight:400}+@font-face{font-family:'SC';src:url(NotoSansSC-600.woff2) format('woff2');font-weight:600}+@font-face{font-family:'IT';src:url(InterTight-400.woff2) format('woff2');font-weight:400}+@font-face{font-family:'IT';src:url(InterTight-600.woff2) format('woff2');font-weight:600}+@font-face{font-family:'PM';src:url(IBMPlexMono-400.woff2) format('woff2');font-weight:400}diff --git a/styles/memphis-diorama/demo/index.html b/styles/memphis-diorama/demo/index.htmlnew file mode 100644index 0000000..4b4cddc--- /dev/null+++ b/styles/memphis-diorama/demo/index.html@@ -0,0 +1,7 @@+<!doctype html>+<html><head><meta charset="utf-8"><title>Four Seasons in Pomelo Town · Memphis Diorama</title>+<link rel="stylesheet" href="fonts/fonts.css">+<style>html,body{margin:0;background:#FFFCF6;overflow:hidden}#gl{position:absolute;left:-9999px}canvas{display:block}</style>+<script type="importmap">{"imports":{"three":"/node_modules/three/build/three.module.js"}}</script>+</head><body><canvas id="gl" width="1920" height="1080"></canvas><canvas id="c" width="1920" height="1080"></canvas>+<script type="module" src="main.js"></script></body></html>diff --git a/styles/memphis-diorama/demo/main.js b/styles/memphis-diorama/demo/main.jsnew file mode 100644index 0000000..d651118--- /dev/null+++ b/styles/memphis-diorama/demo/main.js@@ -0,0 +1,593 @@+// Four Seasons in Pomelo Town (柚子城的四季): one river bend through four seasons in one take, 10 s each.+// Every change of season starts with the big tree on the plaza squatting down and springing back; a wave spreads from it.+// Page contract (core/README.md): window.READY, window.render(t), window.DUR, window.TEXTS(t).+import * as THREE from 'three';+import { Diorama, setNight, setLamps, setWave, setZone, setDusk, setSeason, setHalftone, flat, mesh, box, rng, clamp01, lerp, INK, FRAME } from './memphis.js';+import { person, walk, limb } from './people.js';++const FPS = 60;+const dio = new Diorama(document.getElementById('gl'), document.getElementById('c').getContext('2d'));+const W = new THREE.Group(); dio.scene.add(W);+const V3 = (x, y, z) => new THREE.Vector3(x, y, z);+const c01 = clamp01;+const io = (x) => { x = c01(x); return x < 0.5 ? 4 * x * x * x : 1 - Math.pow(-2 * x + 2, 3) / 2; };+const sm = (x) => { x = c01(x); return x * x * (3 - 2 * x); };+const seg = (t, a, b) => c01((t - a) / (b - a));+const backOut = (x) => { x = c01(x); const s = 1.9; return 1 + (s + 1) * Math.pow(x - 1, 3) + s * Math.pow(x - 1, 2); };+const R = rng(2026);+const rr = (a, b) => a + (b - a) * R();+const R2 = rng(77), rr2 = (a, b) => a + (b - a) * R2(); // 秋冬新加的东西用另一条随机数,不打乱春夏的构图++// ---------- 四季的颜色:每个会变的材质带一组 [春, 夏, 秋, 冬] ----------+const SEASONAL = [];+function S(cols, o = {}) {+ const pats = o.patCols;+ const m = flat(cols[0], { ...o, patCol: pats ? pats[0] : o.patCol, col2: cols[1], patCol2: pats ? pats[1] : o.patCol });+ m.userData.cols = cols.map((c) => new THREE.Color(c)); if (pats) m.userData.pats = pats.map((c) => new THREE.Color(c));+ SEASONAL.push(m); return m;+}+const cache = new Map();+const M = (hex, o = {}) => { const k = hex + JSON.stringify(o); if (!cache.has(k)) cache.set(k, flat(hex, o)); return cache.get(k); };++const lt = (hex, k) => '#' + new THREE.Color(hex).lerp(new THREE.Color(k > 0 ? '#FFFFFF' : '#3A2F66'), Math.abs(k)).getHexString();+// 树冠:主色 + 朝太阳那侧的亮色团块 + 春天的小花点+const CS = (cols, pats, bloom) => ({ main: S(cols, { pat: 1, patCols: pats, patScale: 0.75 }), hi: S(cols.map((c, i) => (i === 3 ? '#FFFFFF' : lt(c, i === 0 ? 0.3 : 0.17))), { pat: 1, patCols: pats.map((c, i) => (i === 3 ? '#DCE6FA' : lt(c, i === 0 ? 0.28 : 0.15))), patScale: 0.6 }), bloom });+const MAT = {+ grass: S(['#9DE8A6', '#6FD889', '#D6E68E', '#FBFCFF'], { pat: 1, patCols: ['#7DDC8C', '#47B868', '#BCD26E', '#E3EAFA'], patScale: 2.4 }),+ paddy: S(['#A6E3FB', '#A4E35F', '#F2C14E', '#FBFCFF'], { pat: 6, patCols: ['#92E3A0', '#78C93F', '#E0A23A', '#E3EAFA'], patScale: 1.2 }),+ rapeField: S(['#FFD234', '#A4E35F', '#F2C14E', '#FBFCFF'], { pat: 1, patCols: ['#FFF3A6', '#78C93F', '#E0A23A', '#E3EAFA'], patScale: 2.0 }),+ ridge: S(['#FFE6BD', '#FFE6BD', '#F7D49B', '#DCD0F2'], { pat: 1, patCols: ['#FFD39A', '#FFD39A', '#E9B97A', '#CBBDEB'], patScale: 0.8 }),+ rape: S(['#FFD234', '#3CBE7E', '#FFC23A', '#FFFFFF'], { pat: 1, patCols: ['#FFF3A6', '#2FA866', '#F39C12', '#E3EAFA'], patScale: 0.45 }),+ sprout: S(['#B8F07A', '#3CBE7E', '#FFC23A', '#FFFFFF'], { pat: 1, patCols: ['#8FDB55', '#2FA866', '#F39C12', '#E3EAFA'], patScale: 0.45 }),+ water: S(['#8ED8F7', '#72C9F3', '#7BBFE8', '#9FD0F4'], { pat: 1, patCols: ['#B5E7FB', '#9ED9F7', '#A5D2F0', '#D3E9FB'], patScale: 1.5 }),+ deep: S(['#55B6EE', '#3FA2E2', '#4C9BD6', '#79B8EA'], { pat: 1, patCols: ['#7FCBF4', '#62B8EC', '#6FB0E0', '#A9D3F4'], patScale: 1.3 }),+ lane: M('#FFE6BD', { pat: 1, patCol: '#FFD39A', patScale: 1.2 }),+ bank: M('#EFE6F7', { pat: 1, patCol: '#D3CAE8', patScale: 0.45 }),+ trunk: M('#A8705A'),+};+const CROWN = {+ pink: CS(['#FFB8D9', '#3CBE7E', '#FF6F61', '#E6DCFF'], ['#FF8DB5', '#2FA866', '#E8463C', '#FFFFFF'], ['#FFFFFF', '#FF4F93']),+ white: CS(['#FFF1F7', '#2FCB7A', '#FFD21F', '#D6EAFF'], ['#FFC4DA', '#1FA862', '#F3B51A', '#FFFFFF'], ['#FF8DB5', '#FFD234']),+ ginkgo: CS(['#B8F07A', '#2FCB7A', '#FFD21F', '#D3F1E6'], ['#9BE15D', '#1FA862', '#F3B51A', '#FFFFFF']),+ big: CS(['#FF9EC8', '#2FB57A', '#FF7A45', '#EBDDFF'], ['#FF7FAA', '#1F9C64', '#E85A2A', '#FFFFFF'], ['#FFFFFF', '#FF4F93']),+ teal: CS(['#62E0C8', '#14B8A0', '#FF9C6B', '#CDEFF0'], ['#B8F0DC', '#0E9A86', '#FF7A45', '#FFFFFF']),+};++// ---------- 地形:草地 + 弯弯的小河 ----------+const xr = (z) => -8 + 9 * Math.sin(z / 28 + 0.6); // 河中线+const RW = 5.5; // 河半宽+const ground = new THREE.Mesh(new THREE.PlaneGeometry(600, 600).rotateX(-Math.PI / 2), MAT.grass); ground.receiveShadow = true; W.add(ground);+function ribbon(halfW, y, mat, off = 0, wob = 0, z0 = -160, z1 = 160, n = 320) {+ const pos = [], idx = [];+ for (let i = 0; i <= n; i++) { const z = lerp(z0, z1, i / n), x = xr(z) + off + wob * Math.sin(z * 0.9 + off * 3); pos.push(x - halfW, y, z, x + halfW, y, z); }+ for (let i = 0; i < n; i++) { const a = 2 * i; idx.push(a, a + 2, a + 1, a + 1, a + 2, a + 3); }+ const g = new THREE.BufferGeometry(); g.setAttribute('position', new THREE.Float32BufferAttribute(pos, 3)); g.setIndex(idx); g.computeVertexNormals();+ const m = new THREE.Mesh(g, mat); m.receiveShadow = true; W.add(m); return m;+}+ribbon(RW + 1.1, 0.04, MAT.bank);+ribbon(RW, 0.08, MAT.water);+ribbon(RW * 0.42, 0.1, MAT.deep, -0.6, 0.5);+const foamMat = new THREE.MeshBasicMaterial({ color: '#FFFFFF' });+for (const sd of [-1, 1]) ribbon(0.16, 0.11, foamMat, sd * (RW - 0.32), 0.16).userData.noOutline = true;+// 草地:深浅不一的草块,打破大面积的平+{+ const pa = S(['#B3F0A8', '#74DA8E', '#E4EEA2', '#FFFFFF'], { pat: 1, patCols: ['#95E596', '#5ACB7A', '#CCDC80', '#E3EAFA'], patScale: 2.2 });+ const pb = S(['#8EE292', '#54C878', '#F2D27A', '#F2F5FF'], { pat: 1, patCols: ['#74D886', '#3FB868', '#E2BC5E', '#E3EAFA'], patScale: 2.2 });+ for (let i = 0; i < 80; i++) {+ const m = new THREE.Mesh(new THREE.CircleGeometry(rr(3, 8), 28).rotateX(-Math.PI / 2).scale(rr(1, 1.9), 1, rr(0.7, 1.2)), i % 2 ? pa : pb);+ m.position.set(rr(-130, 130), 0.012 + i * 0.0001, rr(-110, 110)); m.rotation.y = rr(0, 6.28); m.receiveShadow = true; W.add(m);+ }+}++// ---------- 田:一格一格,春天油菜花 / 灌水的秧田,夏天全是绿稻子 ----------+const ROWS = [], HAYSPOTS = []; // 每块田的禾苗(春天矮,换季时长高)+function mergeBoxes(list) {+ const pos = [], nor = [], idx = []; let base = 0;+ for (const [w, h, d, x, y, z] of list) {+ const g = new THREE.BoxGeometry(w, h, d); g.translate(x, y + h / 2, z);+ pos.push(...g.attributes.position.array); nor.push(...g.attributes.normal.array);+ for (const k of g.index.array) idx.push(k + base); base += g.attributes.position.count;+ }+ const g = new THREE.BufferGeometry(); g.setAttribute('position', new THREE.Float32BufferAttribute(pos, 3)); g.setAttribute('normal', new THREE.Float32BufferAttribute(nor, 3)); g.setIndex(idx); return g;+}+function plot(x0, z0, w, d, kind, near) {+ mesh(box(w + 0.7, 0.12, d + 0.7), MAT.ridge, x0 + w / 2, 0, z0 + d / 2, W).castShadow = false;+ mesh(box(w, 0.18, d), kind === 'rape' ? MAT.rapeField : MAT.paddy, x0 + w / 2, 0, z0 + d / 2, W).castShadow = false;+ if (near) { HAYSPOTS.push([x0 + w * rr2(0.2, 0.42), z0 + d * rr2(0.3, 0.7)]); if (R2() < 0.55) HAYSPOTS.push([x0 + w * rr2(0.62, 0.8), z0 + d * rr2(0.3, 0.7)]); }+ if (!near || kind !== 'rape') return;+ const rows = []; const n = 3;+ for (let i = 0; i < n; i++) rows.push([w - 1.2, 0.8, 1.3, 0, 0, -d / 2 + (i + 0.5) * d / n]);+ const m = new THREE.Mesh(mergeBoxes(rows), kind === 'rape' ? MAT.rape : MAT.sprout); m.castShadow = m.receiveShadow = true;+ m.position.set(x0 + w / 2, 0.18, z0 + d / 2); W.add(m);+ ROWS.push({ m, kind, p: m.position.clone(), h0: 1.1, h1: 0.001 });+}+const PW = 10, PD = 8;+const avoid = []; // 村子、广场、池塘这些地方不种田+const blocked = (x, z, w, d) => avoid.some(([a, b, c, e]) => x < c && x + w > a && z < e && z + d > b);+avoid.push([5, -22, 76, 27], [18, 5, 66, 30]);+for (let gx = -130; gx < 130; gx += PW + 0.7) for (let gz = -120; gz < 120; gz += PD + 0.7) {+ const cx = gx + PW / 2, cz = gz + PD / 2;+ if (Math.abs(cx - xr(cz)) < RW + 9 || Math.abs(gx + PW - xr(gz + PD) - 0) < 0) continue;+ if (Math.abs(gx - xr(gz)) < RW + 9 || Math.abs(gx + PW - xr(gz)) < RW + 9 || Math.abs(gx - xr(gz + PD)) < RW + 9 || Math.abs(gx + PW - xr(gz + PD)) < RW + 9) continue;+ if (blocked(gx, gz, PW, PD)) continue;+ const near = Math.hypot(cx - 14, cz - 4) < 58;+ const rape = Math.sin(gx * 0.045 + 1.3) + Math.cos(gz * 0.07) > 0.25;+ plot(gx, gz, PW, PD, rape ? 'rape' : 'sprout', near);+}++// ---------- 树 ----------+const TREES = [], BLOOMS = [];+function tree(x, z, kind, cs, s = 1) {+ const g = new THREE.Group(); g.position.set(x, 0, z); g.scale.setScalar(s); W.add(g);+ const th = kind === 'column' ? 1.5 : 2.1;+ mesh(new THREE.CylinderGeometry(0.16, 0.32, th, 8).translate(0, th / 2, 0), MAT.trunk, 0, 0, 0, g);+ const br = mesh(new THREE.CylinderGeometry(0.06, 0.1, 1.0, 6).translate(0, 0.5, 0), MAT.trunk, 0.05, th * 0.55, 0, g); br.rotation.z = -0.75;+ const c = new THREE.Group(); c.position.y = th; g.add(c);+ const lobes = [];+ const L = (geo, mat, px, py, pz) => { const m = mesh(geo, mat, px, py, pz, c); lobes.push(m); return m; };+ if (kind === 'cloud') {+ for (const [dx, dy, dz, r] of [[0, 1.7, 0, 1.45], [1.15, 1.05, 0.35, 1.1], [-1.05, 1.15, -0.3, 1.15], [0.25, 2.5, -0.35, 1.0], [-0.4, 1.0, 0.95, 0.95], [0.6, 1.2, -1.0, 0.9]]) L(new THREE.SphereGeometry(r, 18, 12), cs.main, dx, dy, dz);+ for (const [dx, dy, dz, r] of [[-0.75, 2.35, 0.6, 0.62], [-1.45, 1.6, 0.5, 0.5]]) L(new THREE.SphereGeometry(r, 14, 10), cs.hi, dx, dy, dz);+ }+ if (kind === 'round') { L(new THREE.SphereGeometry(1.85, 22, 14).scale(1, 0.92, 1), cs.main, 0, 1.5, 0); L(new THREE.SphereGeometry(0.85, 14, 10), cs.hi, -0.85, 2.3, 0.78); L(new THREE.SphereGeometry(0.52, 12, 8), cs.hi, -1.48, 1.55, 0.6); }+ if (kind === 'egg') { L(new THREE.SphereGeometry(1.45, 18, 12).scale(0.85, 1.35, 0.85), cs.main, 0, 1.8, 0); L(new THREE.SphereGeometry(0.6, 14, 10).scale(0.85, 1.25, 0.85), cs.hi, -0.55, 2.5, 0.5); }+ if (kind === 'cone') { for (const [r, h, y] of [[1.9, 2.0, 0.9], [1.5, 1.8, 2.0], [1.05, 1.6, 3.0]]) L(new THREE.ConeGeometry(r, h, 18), cs.main, 0, y, 0); L(new THREE.SphereGeometry(0.3, 10, 8), cs.hi, 0, 3.85, 0); }+ if (kind === 'column') { L(new THREE.CapsuleGeometry(0.9, 2.6, 6, 14), cs.main, 0, 2.0, 0); L(new THREE.CapsuleGeometry(0.38, 1.3, 6, 10), cs.hi, -0.55, 2.6, 0.45); }+ if (cs.bloom) for (let i = 0; i < 16; i++) {+ const lb = lobes[i % lobes.length], r = lb.geometry.parameters.radius || 1.2, u = R() * 6.28, v = R() * 1.3 - 0.15;+ const q = V3(Math.cos(u) * Math.cos(v), Math.sin(v), Math.sin(u) * Math.cos(v)).multiplyScalar(r * 0.97).add(lb.position);+ const b = mesh(new THREE.SphereGeometry(0.17, 8, 6), M(cs.bloom[i % 2]), q.x, q.y, q.z, c); b.castShadow = false; BLOOMS.push({ m: b, p: V3(x, 0, z) });+ }+ TREES.push({ g, c, lobes, p: g.position.clone(), crown: cs, ph: R() * 6.28 }); return g;+}+// 河岸:粉、白两种花树交替+for (let z = -110; z < 110; z += 9.5) for (const side of [-1, 1]) {+ if (Math.abs(z + 4) < 6) continue;+ const x = xr(z) + side * (RW + 3.4);+ if (side > 0 && x > 2 && z > -24 && z < 34) continue;+ const pink = (Math.round(z / 9.5) + (side > 0 ? 1 : 0)) % 2 === 0;+ tree(x, z, pink ? 'cloud' : 'round', pink ? CROWN.pink : CROWN.white, rr(0.85, 1.05));+}++// ---------- 村子:一条巷子 + 两排小房子 + 银杏 ----------+const LZ = -4; // 巷子+mesh(box(70, 0.14, 4.2), MAT.lane, 3 + 35, 0, LZ, W).castShadow = false;+const WALLS = ['#FFEFA8', '#FFB8D9', '#5EDFB0', '#B9A0FF', '#FF9C6B', '#FFFFFF', '#5CC8FF'];+const ROOFS = [['#FF5A5F', '#FFE0DF'], ['#2F5BFF', '#FFFFFF'], ['#14B8A0', '#B8F0DC'], ['#FFD234', '#F39C12'], ['#4A4468', '#8D86C0']];+const CHIMNEYS = [], WINS = [], DOORLAMPS = [];+function house(x, z, face, w, d, i) {+ const g = new THREE.Group(); g.position.set(x, 0, z); W.add(g);+ const wc = WALLS[i % WALLS.length], two = i % 3 === 1, h = two ? 6.4 : 4.0, B = 0.45, F = face * (d / 2);+ mesh(box(w + 0.5, B, d + 0.5), M('#DCD4EE', { pat: 1, patCol: '#C9C0E3', patScale: 0.32 }), 0, 0, 0, g); // 台基+ mesh(box(w, h, d), M(wc, { pat: 6, patCol: lt(wc, -0.07), patScale: 0.5 }), 0, B, 0, g); // 墙(横向木板)+ for (const sx of [-1, 1]) for (const sz of [-1, 1]) mesh(box(0.24, h, 0.24), M('#FFFFFF'), sx * (w / 2 - 0.04), B, sz * (d / 2 - 0.04), g);+ // 屋顶:两片坡 + 屋脊 + 山墙+ const [rc, rp] = ROOFS[(i * 3 + 1) % ROOFS.length], run = d / 2 + 0.7, rise = 2.5, Ls = Math.hypot(run, rise), th = Math.atan2(rise, run);+ const roofM = S([rc, rc, rc, '#FFFFFF'], { pat: 6, patCols: [rp, rp, rp, '#E3EAFA'], patScale: 0.55 });+ for (const sd of [-1, 1]) { const sl = mesh(new THREE.BoxGeometry(w + 1.1, 0.3, Ls), roofM, 0, B + h + rise / 2 + 0.05, sd * run / 2, g); sl.rotation.x = sd * th; }+ mesh(new THREE.CylinderGeometry(0.2, 0.2, w + 1.25, 10).rotateZ(Math.PI / 2), M(lt(rc, -0.15)), 0, B + h + rise + 0.12, 0, g);+ const gs = new THREE.Shape(); gs.moveTo(-d / 2, 0); gs.lineTo(d / 2, 0); gs.lineTo(0, rise - 0.15); gs.closePath();+ mesh(new THREE.ExtrudeGeometry(gs, { depth: w - 0.02, bevelEnabled: false }).translate(0, 0, -(w - 0.02) / 2).rotateY(Math.PI / 2), M(wc), 0, B + h, 0, g);+ WINS.push({ m: mesh(new THREE.CircleGeometry(0.42, 18).rotateY(Math.PI / 2), flat('#BFE4FF', { lit: true }), w / 2 + 0.01, B + h + 0.8, 0, g).material, T: 35.4 + rr2(0, 3.0) }); // 山墙小圆窗+ // 窗:白框 + 玻璃 + 彩色百叶 + 花箱+ const shut = ['#2F5BFF', '#FF5A5F', '#14B8A0', '#FFD234', '#FF7EB3'][i % 5];+ const floors = two ? [B + 1.55, B + 4.1] : [B + 1.55];+ for (const fy of floors) for (const sx of [-w / 4 - 0.15, w / 4 + 0.15]) {+ mesh(box(1.25, 1.3, 0.1), M('#FFFFFF'), sx, fy - 0.08, F + face * 0.03, g);+ WINS.push({ m: mesh(box(0.98, 1.05, 0.14), flat('#BFE4FF', { lit: true }), sx, fy + 0.04, F + face * 0.05, g).material, T: 34.9 + rr2(0, 3.4) });+ mesh(box(0.07, 1.05, 0.16), M('#FFFFFF'), sx, fy + 0.04, F + face * 0.06, g);+ for (const ss of [-1, 1]) mesh(box(0.38, 1.15, 0.08), M(shut, { pat: 6, patCol: lt(shut, -0.2), patScale: 0.18 }), sx + ss * 0.85, fy - 0.03, F + face * 0.04, g);+ if (fy < B + 2) {+ mesh(box(1.35, 0.32, 0.45), M('#FFFFFF'), sx, fy - 0.42, F + face * 0.24, g);+ [-0.42, -0.14, 0.14, 0.42].forEach((k, j) => mesh(new THREE.SphereGeometry(0.17, 8, 6), M(['#FF5A5F', '#FFD234', '#FF7EB3', '#7FB2FF'][(i + j) % 4]), sx + k, fy - 0.05, F + face * 0.28, g));+ }+ }+ // 门:门框 + 台阶 + 小雨棚 + 门灯 + 两盆花+ const dc = ['#2F5BFF', '#FF5A5F', '#14B8A0'][i % 3];+ mesh(box(1.25, 2.15, 0.1), M('#FFFFFF'), 0, B, F + face * 0.03, g);+ mesh(box(0.95, 1.95, 0.16), M(dc, { pat: 6, patCol: lt(dc, -0.18), patScale: 0.3 }), 0, B, F + face * 0.05, g);+ mesh(new THREE.SphereGeometry(0.07, 8, 6), M('#FFD234'), 0.3, B + 1.0, F + face * 0.15, g);+ mesh(box(1.6, 0.18, 0.7), M('#DCD4EE'), 0, 0, F + face * 0.5, g);+ const aw = mesh(box(1.7, 0.1, 0.8), M(['#FF5A5F', '#2F5BFF', '#FFD234'][(i + 1) % 3], { pat: 4, patCol: '#FFFFFF', patScale: 0.28 }), 0, B + 2.3, F + face * 0.42, g); aw.rotation.x = face * 0.3;+ DOORLAMPS.push({ m: mesh(new THREE.SphereGeometry(0.16, 10, 8), flat('#FFE38A', { lit: true }), 0.85, B + 2.0, F + face * 0.12, g).material, p: V3(x + 0.85, B + 2.0, z + F + face * 2.3), T: 34.6 + rr2(0, 3.0) });+ for (const sx of [-1.0, 1.0]) { mesh(new THREE.CylinderGeometry(0.22, 0.16, 0.38, 10), M('#FF9C6B'), sx, B, F + face * 0.55, g).geometry.translate(0, 0.19, 0); mesh(new THREE.SphereGeometry(0.32, 10, 8), M('#3CBE7E', { pat: 1, patCol: '#FF7EB3', patScale: 0.18 }), sx, B + 0.62, F + face * 0.55, g); }+ if (two) { // 二楼小阳台+ mesh(box(2.4, 0.16, 0.9), M('#FFFFFF'), 0, B + 3.0, F + face * 0.45, g);+ for (let k = -1.1; k <= 1.11; k += 0.37) mesh(box(0.07, 0.6, 0.07), M('#FFFFFF'), k, B + 3.16, F + face * 0.85, g);+ mesh(box(2.4, 0.08, 0.08), M('#FFFFFF'), 0, B + 3.76, F + face * 0.85, g);+ }+ const ch = mesh(box(0.7, 1.7, 0.7), M('#FF7EB3', { pat: 6, patCol: '#E8679C', patScale: 0.3 }), w / 2 - 1.1, B + h + 1.0, -face * 0.7, g); CHIMNEYS.push(ch);+ mesh(box(0.9, 0.16, 0.9), M('#4A4468'), w / 2 - 1.1, B + h + 2.7, -face * 0.7, g);+ return g;+}+let hi = 0;+for (const x of [12, 21.5, 31, 40.5, 50, 59.5, 69]) house(x, LZ - 7.5, 1, rr(7, 8.4), 6, hi++);+for (const x of [12, 21.5, 69]) house(x, LZ + 7.5, -1, rr(7, 8.4), 6, hi++);+for (let x = 7; x < 74; x += 9.5) { tree(x + 4.7, LZ - 3.2, 'egg', CROWN.ginkgo, 0.75); }+// 小广场 + 大树+const PLAZA = V3(31, 0, 15);+mesh(new THREE.CylinderGeometry(8, 8, 0.14, 40), MAT.lane, PLAZA.x, 0.07, PLAZA.z, W).castShadow = false;+const bigTree = new THREE.Group(); bigTree.position.copy(PLAZA); W.add(bigTree);+mesh(new THREE.CylinderGeometry(0.6, 0.9, 5, 10).translate(0, 2.5, 0), MAT.trunk, 0, 0, 0, bigTree);+const bigC = new THREE.Group(); bigTree.add(bigC);+for (const [dx, dy, dz, r] of [[0, 7.2, 0, 3.6], [2.6, 6.0, 0.8, 2.6], [-2.5, 6.2, -0.6, 2.8], [0.6, 6.0, 2.6, 2.4], [-0.4, 9.2, -0.5, 2.4], [1.8, 8.2, -1.6, 2.0]]) mesh(new THREE.SphereGeometry(r, 22, 16), CROWN.big.main, dx, dy, dz, bigC);+for (const [dx, dy, dz, r] of [[-1.6, 9.0, 1.3, 1.4], [-2.9, 7.4, 1.4, 1.1], [-0.6, 10.6, 0.4, 0.9]]) mesh(new THREE.SphereGeometry(r, 16, 12), CROWN.big.hi, dx, dy, dz, bigC);+for (let i = 0; i < 40; i++) { const u = R() * 6.28, v = R() * 1.3 - 0.2, r = 3.5; const b = mesh(new THREE.SphereGeometry(0.22, 8, 6), M(CROWN.big.bloom[i % 2]), Math.cos(u) * Math.cos(v) * r * 1.05, 7.0 + Math.sin(v) * r, Math.sin(u) * Math.cos(v) * r, bigC); b.castShadow = false; BLOOMS.push({ m: b, p: PLAZA.clone() }); }+TREES.push({ g: bigTree, c: bigC, p: PLAZA.clone(), crown: CROWN.big, ph: 0, big: true });+for (const [x, z] of [[24, 9], [38, 9], [25, 21], [37, 21]]) mesh(box(1.6, 0.5, 0.6), M('#2F5BFF'), x, 0.14, z, W); // 长凳+// 池塘+const POND = V3(54, 0, 18), PR = 7.5;+mesh(new THREE.CylinderGeometry(PR + 0.9, PR + 0.9, 0.16, 48), MAT.bank, POND.x, 0, POND.z, W).castShadow = false;+mesh(new THREE.CylinderGeometry(PR, PR, 0.2, 48), MAT.water, POND.x, 0, POND.z, W).castShadow = false;+mesh(new THREE.CylinderGeometry(PR * 0.55, PR * 0.55, 0.22, 40), MAT.deep, POND.x + 0.6, 0, POND.z - 0.4, W).castShadow = false;+{ const f = new THREE.Mesh(new THREE.RingGeometry(PR - 0.42, PR - 0.16, 64).rotateX(-Math.PI / 2), foamMat); f.position.set(POND.x, 0.115, POND.z); f.userData.noOutline = true; W.add(f); }+const PADS = [], LOTUS = [];+const padMat = S(['#7DDC8C', '#2FB57A', '#C9B04A', '#E3EAFA'], { pat: 1, patCols: ['#5FC874', '#1F9C64', '#A88E35', '#FFFFFF'], patScale: 0.4 });+for (let i = 0; i < 16; i++) {+ const a = rr(0, 6.28), r = Math.sqrt(R()) * (PR - 1.4), x = POND.x + Math.cos(a) * r, z = POND.z + Math.sin(a) * r;+ const pad = mesh(new THREE.CylinderGeometry(0.85, 0.85, 0.06, 20, 1, false, 0.4, 5.6), padMat, x, 0.22, z, W); pad.rotation.y = rr(0, 6.28); pad.castShadow = false;+ PADS.push({ m: pad, p: pad.position.clone(), s0: rr(0.45, 0.6) });+ if (i % 2 === 0) {+ const f = new THREE.Group(); f.position.set(x + 0.2, 0.3, z); f.userData.s = 1.7; W.add(f);+ for (let k = 0; k < 6; k++) { const pt = mesh(new THREE.SphereGeometry(0.42, 12, 8).scale(0.55, 1, 0.35).translate(0, 0.38, 0), M('#FF8DB5', { lit: true }), 0, 0, 0, f); pt.rotation.set(0.5, k * Math.PI / 3, 0, 'YXZ'); }+ mesh(new THREE.CylinderGeometry(0.2, 0.14, 0.2, 12), M('#FFD234', { lit: true }), 0, 0.3, 0, f);+ LOTUS.push({ g: f, p: f.position.clone(), d: i * 0.07 });+ }+}+// 桥:三段,中间拱起+const BZ = LZ, BX = xr(BZ);+const stone = M('#FFF4DD', { pat: 1, patCol: '#F2DFC2', patScale: 0.6 });+for (const [dx, len, rot, y] of [[-6.4, 5.4, 0.16, 0.0], [0, 7.6, 0, 0.86], [6.4, 5.4, -0.16, 0.0]]) {+ const b = mesh(box(len, 0.5, 3.6), stone, BX + dx, y, BZ, W); b.rotation.z = rot; if (rot) b.position.y = 0.43;+}+for (const s of [-1, 1]) for (const [dx, len, rot, y] of [[-6.4, 5.4, 0.16, 0.43], [0, 7.6, 0, 0.86], [6.4, 5.4, -0.16, 0.43]]) { const b = mesh(box(len, 0.14, 0.18), M('#FF5A5F'), BX + dx, y + 1.18, BZ + s * 1.65, W); b.rotation.z = rot; }+for (const s of [-1, 1]) for (let dx = -8; dx <= 8; dx += 2) {+ const y = Math.abs(dx) < 4 ? 1.36 : 1.36 - (Math.abs(dx) - 4) * 0.16 - 0.1;+ mesh(box(0.28, 0.75, 0.28), M('#FF5A5F'), BX + dx, y, BZ + s * 1.65, W);+}+// 小路:巷子 → 广场 → 池塘,路边一簇簇花丛+const BUSHES = [];+{+ const pts = [[24, -2], [27, 8], [38, 18], [46, 19], [50, 26], [44, 36], [30, 42], [14, 44]];+ for (let i = 0; i < pts.length - 1; i++) {+ const [x0, z0] = pts[i], [x1, z1] = pts[i + 1], len = Math.hypot(x1 - x0, z1 - z0);+ const m = mesh(box(len + 2.0, 0.1, 2.0), MAT.lane, (x0 + x1) / 2, 0.02, (z0 + z1) / 2, W); m.rotation.y = -Math.atan2(z1 - z0, x1 - x0); m.castShadow = false;+ }+ const bushA = S(['#FF9EC8', '#3CBE7E', '#FF9C6B', '#FFFFFF'], { pat: 1, patCols: ['#FFFFFF', '#7FB2FF', '#FFD234', '#E3EAFA'], patScale: 0.5 });+ const bushB = S(['#FFE066', '#2FCB7A', '#E85A2A', '#FFFFFF'], { pat: 1, patCols: ['#FF7EB3', '#FF8DB5', '#FFD234', '#E3EAFA'], patScale: 0.5 });+ for (const [x, z, s, b] of [[18, 36, 1.2, 0], [22, 39, 0.9, 1], [36, 34, 1.1, 1], [40, 40, 1.3, 0], [8, 40, 1.0, 0], [52, 34, 1.0, 1], [30, 48, 1.2, 1], [44, 47, 0.9, 0], [12, 30, 0.9, 1], [60, 30, 1.1, 0]]) {+ const g = new THREE.Group(); g.position.set(x, 0, z); g.scale.setScalar(s); W.add(g);+ for (const [dx, dz, r] of [[0, 0, 1.1], [1.0, 0.3, 0.8], [-0.9, 0.2, 0.85], [0.2, -0.8, 0.75]]) mesh(new THREE.SphereGeometry(r, 14, 10).scale(1, 0.75, 1), b ? bushB : bushA, dx, r * 0.6, dz, g);+ BUSHES.push({ g, p: g.position.clone(), ph: R() * 6 });+ }+ tree(4, 34, 'round', CROWN.teal, 1.1); tree(58, 42, 'cone', CROWN.teal, 1.0); tree(26, 52, 'egg', CROWN.ginkgo, 1.0);+}+// 广场的冰室遮阳伞(夏天才撑开)+const UMB = [];+for (const [x, z, col] of [[26, 12, '#FF5A5F'], [36, 13, '#2F5BFF'], [32, 20, '#FFD234']]) {+ const g = new THREE.Group(); g.position.set(x, 0.14, z); W.add(g);+ mesh(new THREE.CylinderGeometry(0.07, 0.07, 2.6, 8).translate(0, 1.3, 0), M(INK), 0, 0, 0, g);+ mesh(new THREE.ConeGeometry(1.7, 0.7, 10).translate(0, 2.75, 0), M(col, { pat: 4, patCol: '#FFFFFF', patScale: 0.5 }), 0, 0, 0, g);+ mesh(new THREE.CylinderGeometry(0.6, 0.6, 0.08, 16), M('#FFFFFF'), 0, 0.9, 0, g);+ UMB.push({ g, p: g.position.clone() });+}++// ---------- 会动的小东西 ----------+// 小船:顺着河慢慢漂+const boat = new THREE.Group(); W.add(boat);+mesh(new THREE.CylinderGeometry(0.9, 0.6, 4.2, 12, 1).rotateZ(Math.PI / 2).scale(1, 0.45, 0.75), M('#FF9C6B'), 0, 0.35, 0, boat);+mesh(new THREE.ConeGeometry(0.9, 0.5, 12, 1, true).rotateX(Math.PI).translate(0, 1.6, 0).scale(1.3, 1, 1), M('#FFD234', { pat: 4, patCol: '#FFFFFF', patScale: 0.4 }), 0.6, 0, 0, boat);+const boatman = person(boat, { col: '#2F5BFF', hat: '#FFD234' }); boatman.g.position.set(-0.9, 0.3, 0); boatman.g.scale.setScalar(0.8);+// 鸭子:池塘里绕圈+const DUCKS = [0, 1, 2].map((i) => {+ const g = new THREE.Group(); W.add(g); g.scale.setScalar(0.9 - i * 0.18);+ mesh(new THREE.SphereGeometry(0.55, 14, 10).scale(1.3, 0.8, 0.9), M('#FFFFFF'), 0, 0.42, 0, g);+ mesh(new THREE.SphereGeometry(0.3, 12, 8), M('#FFFFFF'), 0.62, 0.92, 0, g);+ mesh(new THREE.ConeGeometry(0.12, 0.34, 8).rotateZ(-Math.PI / 2), M('#FF9C6B'), 0.98, 0.9, 0, g);+ return g;+});+// 巷子里散步的人(远景点缀)+const WALKERS = [+ person(W, { col: '#FF5A5F' }), person(W, { col: '#14B8A0' }), person(W, { col: '#B9A0FF', hat: '#FFD234' }),+];+// 放风筝(春):田埂上的人 + 两只风筝+const flyer = person(W, { col: '#FF7EB3', hat: '#2F5BFF' }); flyer.g.position.set(-32, 0.12, 6.35); flyer.g.rotation.y = 0.8;+const KITES = [[-40, 22, -10, '#FF5A5F', '#FFD234'], [-58, 26, 18, '#2F5BFF', '#FF7EB3']].map(([x, y, z, c1, c2], i) => {+ const g = new THREE.Group(); W.add(g);+ const k = mesh(new THREE.OctahedronGeometry(1.6, 0).scale(1, 1.35, 0.12), M(c1, { pat: 4, patCol: c2, patScale: 0.8, lit: true }), 0, 0, 0, g);+ const tail = [0, 1, 2, 3].map((j) => mesh(box(0.5, 0.25, 0.08), M(c2, { lit: true }), 0, -2.6 - j * 0.9, 0, g));+ const line = new THREE.Mesh(new THREE.CylinderGeometry(0.03, 0.03, 1, 4), new THREE.MeshBasicMaterial({ color: INK })); line.userData.noOutline = true; W.add(line);+ return { g, k, tail, line, base: V3(x, y, z), ph: i * 2.1, hand: i === 0 ? null : V3(-60, 1.3, 26) };+});+const flyer2 = person(W, { col: '#FFD234', hat: '#FF5A5F' }); flyer2.g.position.set(-60, 0.12, 27.6);+// 燕子+const SWALLOWS = [0, 1, 2, 3, 4].map((i) => {+ const g = new THREE.Group(); W.add(g); const wm = M(INK);+ const wl = mesh(box(0.15, 0.06, 1.1).translate(0, 0, 0.55), wm, 0, 0, 0, g), wr = mesh(box(0.15, 0.06, 1.1).translate(0, 0, -0.55), wm, 0, 0, 0, g);+ mesh(new THREE.ConeGeometry(0.2, 0.9, 6).rotateZ(-Math.PI / 2), wm, 0, 0, 0, g);+ return { g, wl, wr, r: rr(18, 34), h: rr(10, 16), w: rr(0.35, 0.55) * (i % 2 ? 1 : -1), ph: rr(0, 6.28), c: V3(rr(-30, 30), 0, rr(-10, 25)) };+});+// 花瓣+const pinkTrees = TREES.filter((t) => t.crown === CROWN.pink || t.crown === CROWN.white || t.big);+const petalMat = [new THREE.MeshBasicMaterial({ color: '#FF9EC8', side: THREE.DoubleSide }), new THREE.MeshBasicMaterial({ color: '#FFFFFF', side: THREE.DoubleSide })];+const PETALS = Array.from({ length: 110 }, (_, i) => {+ const m = new THREE.Mesh(new THREE.CircleGeometry(0.32, 6).scale(1, 0.6, 1), petalMat[i % 2]); m.userData.noOutline = true; W.add(m);+ return { m, t: pinkTrees[i % pinkTrees.length], ph: R() * 4, sx: rr(-1, 1), sz: rr(-1, 1) };+});+// 芦苇:河岸、池塘边一丛丛+const REEDS = [];+{+ const reedM = S(['#7ED957', '#2FA866', '#E0B04A', '#C9A27A']);+ const clump = (x, z) => {+ const g = new THREE.Group(); g.position.set(x, 0, z); W.add(g);+ for (let k = 0; k < 6; k++) {+ const hh = rr(1.0, 1.9), st = mesh(new THREE.CylinderGeometry(0.07, 0.11, hh, 6).translate(0, hh / 2, 0), reedM, rr(-0.5, 0.5), 0, rr(-0.5, 0.5), g);+ st.rotation.set(rr(-0.2, 0.2), 0, rr(-0.25, 0.25)); st.castShadow = false; st.userData.noOutline = true;+ if (k < 2) mesh(new THREE.CapsuleGeometry(0.13, 0.4, 4, 8), M('#C98A5E'), 0, hh - 0.05, 0, st);+ }+ REEDS.push({ g, ph: R() * 6.28 });+ };+ for (let z = -100; z < 100; z += rr(4.5, 8)) for (const sd of [-1, 1]) { if (R() < 0.45 || Math.abs(z + 4) < 7) continue; clump(xr(z) + sd * (RW + 0.25), z); }+ for (let k = 0; k < 7; k++) { const a = k / 7 * 6.28 + 0.3; if (k % 3 === 1) continue; clump(POND.x + Math.cos(a) * (PR + 0.2), POND.z + Math.sin(a) * (PR + 0.2)); }+}+// 水面的小波纹:孟菲斯式的白色小曲线,顺流往下+const squigGeo = (() => { const pts = []; for (let i = 0; i <= 8; i++) pts.push(V3((i - 4) * 0.24, 0, Math.sin(i * 1.5) * 0.13)); return new THREE.TubeGeometry(new THREE.CatmullRomCurve3(pts), 28, 0.06, 5); })();+const GLINTS = Array.from({ length: 70 }, () => {+ const m = new THREE.Mesh(squigGeo, foamMat); m.userData.noOutline = true; W.add(m);+ return { m, z0: rr(-110, 110), off: rr(-0.75, 0.75), ph: R(), sp: rr(2.0, 3.0) };+});+const PGL = Array.from({ length: 9 }, (_, i) => { const m = new THREE.Mesh(squigGeo, foamMat); m.userData.noOutline = true; W.add(m); return { m, a: i / 9 * 6.28, r: rr(1.5, PR - 1.5), ph: R() }; });+// 夏天的过云雨:一朵灰紫的云从西往东飘,下面拖着雨丝,水面一圈圈涟漪+const rainCloud = new THREE.Group(); W.add(rainCloud);+for (const [dx, dy, dz, r] of [[0, 0, 0, 7], [6, -1, 2, 5.5], [-6, -1.2, -1, 5.5], [2, 3, -2, 5], [-3, 2, 3, 4.5]]) { const c = mesh(new THREE.SphereGeometry(r, 18, 12).scale(1, 0.62, 0.9), M('#E4DEF6', { lit: true, shadow: false }), dx, dy, dz, rainCloud); c.castShadow = true; c.receiveShadow = false; }+const rainMat = new THREE.MeshBasicMaterial({ color: '#6E9BEA', transparent: true, opacity: 0.85 });+const DROPS = Array.from({ length: 300 }, () => { const m = new THREE.Mesh(new THREE.BoxGeometry(0.14, 2.6, 0.14), rainMat); m.userData.noOutline = true; W.add(m); return { m, dx: rr(-13, 13), dz: rr(-9, 9), ph: R() }; });+const ringMat = new THREE.MeshBasicMaterial({ color: '#FFFFFF', transparent: true, depthWrite: false });+const RINGS = Array.from({ length: 160 }, () => { const m = new THREE.Mesh(new THREE.RingGeometry(0.8, 1, 24).rotateX(-Math.PI / 2), ringMat.clone()); m.userData.noOutline = true; W.add(m); return { m, dx: rr(-13, 13), dz: rr(-9, 9), ph: R() }; });+// 白云(高处慢飘,投下影子)+const CLOUDS = [[-60, 46, -40, 1.0], [40, 52, -70, 1.3], [90, 48, 40, 1.1]].map(([x, y, z, s]) => {+ const g = new THREE.Group(); g.position.set(x, y, z); g.scale.setScalar(s * 4); W.add(g);+ for (const [dx, dy, dz, r] of [[0, 0, 0, 1.4], [1.3, -0.2, 0.2, 1.1], [-1.3, -0.25, 0, 1.0], [0.5, 0.6, -0.2, 0.9]]) { const m = mesh(new THREE.SphereGeometry(r, 18, 12).scale(1, 0.7, 1), M('#FFFFFF', { lit: true, shadow: false }), dx, dy, dz, g); m.receiveShadow = false; }+ return { g, x0: x };+});++// ---------- 秋、冬才出现的东西 ----------+// 稻草垛:秋天收完稻子一垛垛冒出来,冬天顶上积雪+const HAY = [];+{+ const body = M('#FFC23A', { pat: 6, patCol: '#F39C12', patScale: 0.32 });+ const cap = S(['#FFD86B', '#FFD86B', '#FFD86B', '#FFFFFF'], { pat: 6, patCols: ['#F3B51A', '#F3B51A', '#F3B51A', '#DCE6FA'], patScale: 0.32 });+ for (const [px, pz] of HAYSPOTS) {+ const g = new THREE.Group(); g.position.set(px, 0.18, pz); g.rotation.y = rr2(0, 6.28); W.add(g);+ mesh(new THREE.CylinderGeometry(0.95, 1.1, 1.2, 14), body, 0, 0.6, 0, g);+ mesh(new THREE.ConeGeometry(1.25, 1.4, 14), cap, 0, 1.9, 0, g);+ HAY.push({ g, T: 22.0 + rr2(0, 5.5) });+ }+}+// 落叶:秋天从每棵树上飘下来+const leafMat = ['#FF7A45', '#FFD21F', '#FF5A5F', '#FFB020'].map((c) => new THREE.MeshBasicMaterial({ color: c, side: THREE.DoubleSide }));+const LEAVES = Array.from({ length: 160 }, (_, i) => {+ const m = new THREE.Mesh(new THREE.CircleGeometry(0.4, 4).scale(0.7, 1, 1), leafMat[i % 4]); m.userData.noOutline = true; W.add(m);+ return { m, t: TREES[(i * 7) % TREES.length], ph: R2() * 4, sx: rr2(-1, 1), sz: rr2(-1, 1) };+});+// 大雁:排成人字往西南飞+const GEESE = Array.from({ length: 9 }, (_, i) => {+ const g = new THREE.Group(); W.add(g); const m = M(INK);+ const wl = mesh(box(0.22, 0.07, 1.5).translate(0, 0, 0.75), m, 0, 0, 0, g), wr = mesh(box(0.22, 0.07, 1.5).translate(0, 0, -0.75), m, 0, 0, 0, g);+ mesh(new THREE.SphereGeometry(0.3, 10, 6).scale(2.2, 0.8, 0.8), m, 0, 0, 0, g);+ mesh(new THREE.CylinderGeometry(0.08, 0.1, 0.9, 6).rotateZ(Math.PI / 2), m, -0.95, 0.1, 0, g);+ const row = Math.ceil(i / 2), side = i === 0 ? 0 : (i % 2 ? 1 : -1);+ return { g, wl, wr, off: V3(row * 2.6, 0, side * row * 2.1), ph: i * 0.7 };+});+// 雪+const flakeGeo = new THREE.IcosahedronGeometry(0.27, 0), snowMat = new THREE.MeshBasicMaterial({ color: '#FFFFFF' });+const SNOW = Array.from({ length: 1000 }, () => { const m = new THREE.Mesh(flakeGeo, snowMat); m.userData.noOutline = true; W.add(m); return { m, x: rr2(-60, 115), z: rr2(-55, 80), ph: R2(), sp: rr2(0.8, 1.2) }; });+// 烟囱冒烟(冬天)+W.updateMatrixWorld(true);+const SMOKE = CHIMNEYS.flatMap((ch, ci) => {+ const p = ch.getWorldPosition(V3(0, 0, 0));+ return [0, 1, 2, 3].map((k) => { const m = mesh(new THREE.SphereGeometry(0.55, 12, 8), M('#FFFFFF', { lit: true, shadow: false }), p.x, p.y, p.z, W); m.castShadow = false; return { m, p: V3(p.x, p.y + 2.9, p.z), ph: k / 4 + ci * 0.37 }; });+});+// 广场上的雪人+const snowman = new THREE.Group(); snowman.position.set(26.0, 0.14, 18.4); snowman.rotation.y = 0.8; W.add(snowman);+mesh(new THREE.SphereGeometry(1.0, 18, 12), M('#FFFFFF'), 0, 0.9, 0, snowman);+mesh(new THREE.SphereGeometry(0.68, 16, 10), M('#FFFFFF'), 0, 2.2, 0, snowman);+mesh(new THREE.ConeGeometry(0.12, 0.6, 8).rotateX(Math.PI / 2), M('#FF9C6B'), 0, 2.2, 0.9, snowman);+for (const ex of [-0.24, 0.24]) mesh(new THREE.SphereGeometry(0.08, 8, 6), M(INK), ex, 2.42, 0.6, snowman);+mesh(new THREE.TorusGeometry(0.52, 0.15, 8, 20).rotateX(Math.PI / 2), M('#FF5A5F', { pat: 6, patCol: '#FFFFFF', patScale: 0.2 }), 0, 1.66, 0, snowman);+mesh(new THREE.CylinderGeometry(0.66, 0.66, 0.08, 16), M('#2F5BFF'), 0, 2.78, 0, snowman);+mesh(new THREE.CylinderGeometry(0.42, 0.42, 0.62, 16), M('#2F5BFF', { pat: 6, patCol: '#FFD234', patScale: 0.25 }), 0, 3.1, 0, snowman);++// ---------- 时间线 ----------+const DUR = 40;+const WAVES = [+ { t0: 9.3, t1: 11.9, c: [PLAZA.x, PLAZA.z] }, // 春 → 夏:从大树扫开+ { t0: 19.3, t1: 21.9, c: [PLAZA.x, PLAZA.z] }, // 夏 → 秋+ { t0: 29.3, t1: 31.9, c: [PLAZA.x, PLAZA.z] }, // 秋 → 冬:三次都是大树一蹲,波从大树扫开+];+const WAVE_MAX = 240;+function seasonState(t) {+ let i = 0; while (i < WAVES.length && t >= WAVES[i].t1) i++;+ const w = WAVES[i];+ const r = w && t > w.t0 ? WAVE_MAX * io(seg(t, w.t0, w.t1)) : -1;+ return { i, r, c: w ? w.c : [0, 0] };+}+// 某个位置被换季波扫过之后的进度(0 → 1),用于长高、开花、撑伞这些“动作”+const passed = (st, p, len = 1) => { if (st.r < 0) return 0; const d = Math.hypot(p.x - st.c[0], p.z - st.c[1]); return c01((st.r - d) / (16 * len)); };+const CENTER = V3(22, 0, 9);+function camAt(t) {+ // 前 18 秒和春夏版一样;之后镜头慢慢减速到 0.3 倍,秋冬还是同一个构图+ const te = t < 18 ? t : t < 22 ? t - 0.7 * (t - 18) ** 2 / 8 : 20.6 + 0.3 * (t - 22);+ const a = 0.1 + 0.02 * te, Rr = 92 - 0.4 * te, H = 70 - 0.3 * te;+ return { pos: V3(CENTER.x + Math.sin(a) * Rr, H, CENTER.z + Math.cos(a) * Rr), look: CENTER.clone().add(V3(0, 0, 0)), fov: 30 };+}+const TEXT = [+ ['春 · 油菜花开了,水田灌满了 Spring · rapeseed in bloom, paddies filling up', '春分 Spring Equinox · 03.20 柚子城 · 河湾 Pomelo Town · River Bend'],+ ['夏 · 一阵雨过去,荷花开了 Summer · a passing shower, lotus in bloom', '小暑 Minor Heat · 07.07 柚子城 · 河湾 Pomelo Town · River Bend'],+ ['秋 · 稻子黄了,大雁往南飞 Autumn · golden rice, geese flying south', '秋分 Autumn Equinox · 09.22 柚子城 · 河湾 Pomelo Town · River Bend'],+ ['冬 · 下雪了,窗户一盏盏亮起来 Winter · first snow, windows lighting up', '大雪 Major Snow · 12.07 柚子城 · 河湾 Pomelo Town · River Bend'],+];+const TITLE = '柚子城的四季 Four Seasons in Pomelo Town';++setNight(0); setDusk(0); setWave(1e5); setZone([0, 0, 0, 0], 1); setLamps([]); setHalftone(1);+dio.scene.background = new THREE.Color('#8FD6FF');++function place(t) {+ const st = seasonState(t), si = Math.min(st.i, 1);+ // 材质:当前季 → 下一季+ for (const m of SEASONAL) {+ const k = Math.min(st.i, m.userData.cols.length - 1), k2 = Math.min(k + 1, m.userData.cols.length - 1);+ m.uniforms.uCol.value.copy(m.userData.cols[k]); m.uniforms.uCol2.value.copy(m.userData.cols[k2]);+ if (m.userData.pats) { m.uniforms.uPatCol.value.copy(m.userData.pats[k]); m.uniforms.uPatCol2.value.copy(m.userData.pats[k2]); }+ }+ setSeason(st.c[0], st.c[1], st.r);+ const at = (n, p, len) => (st.i >= n ? 1 : st.i === n - 1 ? passed(st, p, len) : 0);+ const summer = (p, len) => at(1, p, len), autumn = (p, len) => at(2, p, len), winter = (p, len) => at(3, p, len);+ const popOf = (p) => [1, 2, 3].reduce((a, n) => a + Math.sin(Math.PI * c01(at(n, p) * 1.4)), 0); // 每道波扫过时弹一下+ // 禾苗:春天油菜高、秧苗矮;波扫过之后一起长成绿稻子(带一点回弹)+ for (const r of ROWS) { const k = summer(r.p); r.m.visible = k < 0.99; r.m.scale.y = lerp(r.h0, r.h1, sm(k)) * (1 + 0.04 * Math.sin(t * 2.2 + r.p.x * 0.3)); }+ // 树:风里轻轻摇;波扫过时弹一下+ for (const tr of TREES) { const pop = tr.big ? 0 : popOf(tr.p) * 0.12; tr.c.rotation.z = (tr.big ? 0.012 : 0.03) * Math.sin(t * 1.3 + tr.ph); tr.c.rotation.x = 0.015 * Math.sin(t * 1.1 + tr.ph * 2); tr.c.scale.setScalar(1 + pop); }+ // 大树往下一蹲(0.5 秒),再弹起来,这一季就变了+ {+ let sy = 1;+ for (const w of WAVES) {+ if (t > w.t0 - 0.5 && t < w.t0) sy = 1 - 0.2 * io(seg(t, w.t0 - 0.5, w.t0));+ else if (t >= w.t0 && t < w.t0 + 0.7) sy = lerp(0.8, 1, backOut(seg(t, w.t0, w.t0 + 0.6)));+ }+ bigTree.scale.set(1 / Math.sqrt(sy), sy, 1 / Math.sqrt(sy));+ }+ // 荷叶长大,雨后荷花开+ for (const p of PADS) { const w = sm(winter(p.p)); p.m.scale.setScalar(Math.max(lerp(p.s0, 1, backOut(summer(p.p))) * (1 - w), 0.001)); p.m.visible = w < 0.99; }+ for (const l of LOTUS) { const wilt = st.i >= 2 ? sm(seg(t, 22.4 + l.d * 3, 23.6 + l.d * 3)) : 0, k = (st.i >= 1 ? backOut(seg(t, 16.6 + l.d, 17.3 + l.d)) : 0) * (1 - wilt); l.g.scale.setScalar(Math.max(k, 0.001) * 1.7); l.g.visible = k > 0.01; l.g.rotation.y = 0.2 * Math.sin(t + l.d * 9); }+ for (const u of UMB) { const k = backOut(c01(summer(u.p) * 1.2 - 0.2)) * (1 - sm(c01(autumn(u.p) * 1.3))); u.g.scale.set(Math.max(k, 0.001), Math.max(k, 0.001), Math.max(k, 0.001)); u.g.visible = k > 0.01; }+ // 小船+ { const z = -70 + 3.4 * t, x = xr(z) + 1.2, z2 = z + 0.5, h = Math.atan2(-(xr(z2) + 1.2 - x), z2 - z); boat.position.set(x, 0.12 + 0.05 * Math.sin(t * 2), z); boat.rotation.set(0.03 * Math.sin(t * 1.7), h - Math.PI / 2, 0); }+ boatman.body.rotation.z = 0.05 * Math.sin(t * 1.6);+ // 鸭子+ DUCKS.forEach((d, i) => { const a = 0.22 * t + i * 0.32, r = 4.6; d.position.set(POND.x + Math.cos(a) * r, 0.1 + 0.03 * Math.sin(t * 3 + i), POND.z + Math.sin(a) * r * 0.8); d.rotation.y = -a - Math.PI / 2 + Math.PI; d.rotation.z = 0.06 * Math.sin(t * 3 + i); });+ // 散步的人+ WALKERS.forEach((p, i) => { const s = ((i * 23 + (i === 1 ? -1 : 1) * 1.15 * t) % 66 + 66) % 66; walk(p, 8 + s, LZ + (i - 1) * 0.9, i === 1 ? Math.PI : 0, t * 2.8 + i); p.g.scale.setScalar(0.9); });+ // 风筝(春天才有,夏天的波扫过来就收了)+ for (const k of KITES) {+ const gone = summer(k.base, 1);+ const p = k.base.clone().add(V3(1.6 * Math.sin(t * 0.8 + k.ph), 1.2 * Math.sin(t * 1.1 + k.ph) + 30 * gone * gone, 0.8 * Math.cos(t * 0.7 + k.ph)));+ k.g.position.copy(p); k.g.rotation.set(0, 0.6, 0.25 * Math.sin(t * 1.3 + k.ph)); k.g.visible = gone < 0.98;+ k.tail.forEach((b, j) => { b.position.x = 0.35 * Math.sin(t * 3 + j * 0.9 + k.ph); b.rotation.z = 0.5 * Math.sin(t * 3 + j); });+ const hand = k.hand || flyer.g.position.clone().add(V3(0, 1.6, 0));+ limb(k.line, hand, p.clone().add(V3(0, -0.4, 0))); k.line.visible = k.g.visible;+ }+ flyer.arms[1].rotation.set(0, 0, -2.4 + 0.1 * Math.sin(t * 1.3)); flyer2.arms[0].rotation.set(0, 0, -2.3 + 0.1 * Math.sin(t * 1.1));+ // 燕子+ for (const s of SWALLOWS) {+ const a = s.ph + s.w * t, p = s.c.clone().add(V3(Math.cos(a) * s.r, s.h + 2 * Math.sin(t * 0.9 + s.ph), Math.sin(a) * s.r * 0.7));+ const away = autumn(p); p.y += 30 * away * away; s.g.visible = away < 0.98; // 秋天的波扫过来,燕子就飞走了+ s.g.position.copy(p); s.g.rotation.y = -a - Math.sign(s.w) * Math.PI / 2 * -1 + (s.w > 0 ? Math.PI : 0); s.g.rotation.x = 0.4 * Math.sign(s.w);+ const f = 0.7 * Math.sin(t * 14 + s.ph); s.wl.rotation.x = f; s.wr.rotation.x = -f;+ }+ // 花瓣:从花树上飘下来,被风往东吹;夏天的波扫过就不再飘+ for (const pe of PETALS) {+ const tp = pe.t.p, u = ((t * 0.28 + pe.ph / 4) % 1), age = u * 4;+ const born = Math.floor(t * 0.28 + pe.ph / 4) * 4; // 这一片在哪个周期出生+ const top = pe.t.big ? 7 : 3.4;+ const pos = V3(tp.x + pe.sx * 2 + age * 2.2 + 0.6 * Math.sin(age * 2.5 + pe.ph), top - age * (top / 4) * 0.95 + 0.25, tp.z + pe.sz * 2 + 0.5 * Math.cos(age * 2 + pe.ph));+ pe.m.position.copy(pos); pe.m.rotation.set(age * 3 + pe.ph, age * 2, age * 1.3);+ pe.m.visible = summer(tp) < 0.02 && t < 9.3 + 2.6;+ }+ // 水面亮光:顺流往下+ for (const g of GLINTS) {+ const u = (t * 0.35 + g.ph) % 1, z = ((g.z0 + g.sp * t + 110) % 220) - 110, x = xr(z) + g.off * RW;+ g.m.position.set(x, 0.13, z); g.m.rotation.y = Math.atan2(-(xr(z + 1) - xr(z)), 1) + Math.PI / 2; g.m.scale.setScalar(Math.max(Math.sin(Math.PI * u), 0.001) * 1.25);+ }+ for (const g of PGL) { const u = (t * 0.3 + g.ph) % 1, a = g.a + 0.05 * t; g.m.position.set(POND.x + Math.cos(a) * g.r, 0.13, POND.z + Math.sin(a) * g.r * 0.9); g.m.rotation.y = -a; g.m.scale.setScalar(Math.max(Math.sin(Math.PI * u), 0.001)); }+ for (const r of REEDS) r.g.rotation.set(0.05 * Math.sin(t * 1.5 + r.ph), 0, 0.07 * Math.sin(t * 1.9 + r.ph));+ for (const b of BLOOMS) { const k = summer(b.p); b.m.scale.setScalar(Math.max(1 - sm(k * 1.6), 0.001)); b.m.visible = k < 0.62; }+ // 雨+ const cloudX = lerp(-100, 110, seg(t, 11.2, 19.2)), cloudZ = 26;+ rainCloud.position.set(cloudX, 17, cloudZ); rainCloud.visible = (st.i >= 1 || t > 11.2) && t < 19.4;+ const raining = st.i >= 1 && t > 12.2 && t < 17.8;+ for (const d of DROPS) {+ const u = (t * 1.6 + d.ph) % 1;+ d.m.position.set(cloudX + d.dx - u * 2.5, 14 - u * 14, cloudZ + d.dz); d.m.rotation.z = 0.11; d.m.visible = raining && d.m.position.y > 0.3;+ }+ for (const r of RINGS) {+ const u = (t * 1.1 + r.ph) % 1, x = cloudX + r.dx, z = cloudZ + r.dz;+ const onRiver = Math.abs(x - xr(z)) < RW - 0.4, onPond = Math.hypot(x - POND.x, z - POND.z) < PR - 0.6;+ r.m.position.set(x, 0.22, z); r.m.scale.setScalar(0.4 + 1.6 * u); r.m.material.opacity = 0.9 * (1 - u);+ r.m.visible = raining && (onRiver || onPond);+ }+ for (const c of CLOUDS) c.g.position.x = c.x0 + 1.2 * t;+ for (const b of BUSHES) { b.g.scale.y = b.g.scale.x * (1 + 0.15 * popOf(b.p)); b.g.rotation.y = 0.04 * Math.sin(t * 1.2 + b.ph); }+ // 秋:稻草垛一垛垛冒出来;落叶;大雁+ for (const h of HAY) { const k = st.i >= 2 ? backOut(seg(t, h.T, h.T + 0.5)) : 0; h.g.scale.setScalar(Math.max(k, 0.001)); h.g.visible = k > 0.01; }+ for (const lf of LEAVES) {+ const tp = lf.t.p, age = ((t * 0.25 + lf.ph / 4) % 1) * 4, top = lf.t.big ? 7 : 3.4;+ lf.m.position.set(tp.x + lf.sx * 2 + age * 1.8 + 0.8 * Math.sin(age * 2.2 + lf.ph), top - age * (top / 4) * 0.95 + 0.25, tp.z + lf.sz * 2 + 0.6 * Math.cos(age * 1.8 + lf.ph));+ lf.m.rotation.set(age * 2.5 + lf.ph, age * 1.7, age);+ lf.m.visible = autumn(tp) > 0.3 && winter(tp) < 0.02;+ }+ {+ const u = seg(t, 21.2, 30.6), lead = V3(lerp(98, -66, u), 15 + 0.6 * Math.sin(t * 0.8), lerp(-22, 12, u)), th = Math.atan2(34, 164);+ for (const gs of GEESE) {+ gs.g.position.copy(lead).add(gs.off.clone().applyAxisAngle(V3(0, 1, 0), th)); gs.g.position.y += 0.3 * Math.sin(t * 1.4 + gs.ph);+ gs.g.rotation.set(0, th, 0); gs.g.visible = u > 0 && u < 1;+ const f = 0.55 * Math.sin(t * 6 + gs.ph); gs.wl.rotation.x = f; gs.wr.rotation.x = -f;+ }+ }+ // 冬:下雪、烟囱冒烟、堆雪人;黄昏,窗户一盏盏亮起来+ for (const s of SNOW) {+ const u = (t * 0.11 * s.sp + s.ph) % 1, y = 32 * (1 - u);+ s.m.position.set(s.x + 1.2 * Math.sin(t * 0.9 + s.ph * 9), y, s.z + 0.8 * Math.cos(t * 0.7 + s.ph * 7));+ s.m.visible = y > 0.2 && winter(s.m.position) > 0;+ }+ for (const pf of SMOKE) {+ const u = (t * 0.33 + pf.ph) % 1, sc = (0.35 + u) * Math.min(1, (1 - u) * 4) * sm(winter(pf.p));+ pf.m.position.set(pf.p.x + u * 2.4 + 0.3 * Math.sin(u * 6 + pf.ph), pf.p.y + u * 4.2, pf.p.z - u * 0.6); pf.m.scale.setScalar(Math.max(sc, 0.001)); pf.m.visible = sc > 0.01;+ }+ { const k = st.i >= 3 ? backOut(seg(t, 32.6, 33.2)) : 0; snowman.scale.setScalar(Math.max(k, 0.001)); snowman.visible = k > 0.01; }+ setNight(0.62 * sm(seg(t, 33.8, 37.2))); setDusk(1 - 0.35 * sm(seg(t, 35.5, 39)));+ for (const w of WINS) { const on = t > w.T; w.m.uniforms.uEmit.value = on ? 1 : 0; w.m.uniforms.uCol.value.set(on ? '#FFD36E' : '#BFE4FF'); }+ const pools = [];+ for (const d of DOORLAMPS) { const on = t > d.T; d.m.uniforms.uEmit.value = on ? 1 : 0; d.m.uniforms.uCol.value.set(on ? '#FFD36E' : '#FFE38A'); if (on) pools.push([d.p.x, d.p.y, d.p.z, 2.6 * backOut(seg(t, d.T, d.T + 0.4))]); }+ setLamps(pools);+ return { st, si };+}++function render(t) {+ const f = Math.round(t * FPS);+ const { st } = place(t);+ const c = camAt(t);+ dio.cam.fov = c.fov; dio.cam.position.copy(c.pos); dio.cam.up.set(0, 1, 0); dio.cam.lookAt(c.look); dio.cam.updateProjectionMatrix();+ dio.fitShadow(V3(22, 0, 9), 100);+ // 字:第二、三行在换季波扫到一半时换+ const SWAPS = [10.45, 20.45, 30.45], near = SWAPS.find((s) => Math.abs(t - s) < 0.45);+ const sw = near !== undefined, ti = SWAPS.filter((s) => t >= s).length;+ let grow = 1e9;+ if (t < 1.2) grow = 1300 * Math.pow(t / 1.2, 0.8);+ else if (t > DUR - 1.0) grow = 1300 * (1 - io((t - (DUR - 1.0)) / 0.95));+ const base = Math.min(sm(seg(t, 0.8, 1.6)), 1 - sm(seg(t, DUR - 1.0, DUR - 0.25)));+ const swapA = sw ? Math.abs(t - near) / 0.45 : 1;+ dio.render(t, f, { grow, text: [TITLE, ...TEXT[ti]], textAlpha: base });+ if (sw) { // 换行时:先把旧字遮淡,再显出新字(第一行不动)+ const g = dio.ctx; g.save(); g.globalAlpha = 1 - swapA; g.fillStyle = '#FFFCF6'; g.fillRect(0, 948, 1920, 60); g.restore();+ }+}+// every on-screen text with its box, for core/render/readcheck.mjs+const textAlphaAt = (t) => Math.min(sm(seg(t, 0.8, 1.6)), 1 - sm(seg(t, DUR - 1.0, DUR - 0.25)));+function TEXTS(t) {+ if (textAlphaAt(t) <= 0) return [];+ const g = dio.ctx, y0 = FRAME.cy + FRAME.hh + 64;+ const tbox = (text, font, dy, size) => { g.save(); g.font = font; const w = g.measureText(text).width; g.restore(); return { x0: 960 - w / 2, x1: 960 + w / 2, y0: y0 + dy - size, y1: y0 + dy + size * 0.3 }; };+ const out = [{ id: 'title', text: TITLE, ...tbox(TITLE, '600 25px IT, SC', 34, 25) }];+ const SWAPS = [10.45, 20.45, 30.45], ti = SWAPS.filter((s) => t >= s).length;+ if (SWAPS.some((s) => Math.abs(t - s) < 0.45)) return out; // lines 2 and 3 are being swapped+ out.push({ id: 'season', text: TEXT[ti][0], ...tbox(TEXT[ti][0], '400 18px IT, SC', 64, 18) });+ out.push({ id: 'info', text: TEXT[ti][1], ...tbox(TEXT[ti][1], '400 15px PM, SC', 91, 15) });+ return out;+}+window.DUR = DUR;+window.render = render;+window.TEXTS = TEXTS;+await Promise.all(['600 25px IT', '400 18px IT', '600 25px SC', '400 18px SC', '400 15px PM'].map((f) => document.fonts.load(f, '柚子城 Aa')));+render(0);+window.READY = true;diff --git a/styles/memphis-diorama/demo/memphis.js b/styles/memphis-diorama/demo/memphis.jsnew file mode 100644index 0000000..d8c1443--- /dev/null+++ b/styles/memphis-diorama/demo/memphis.js@@ -0,0 +1,332 @@+// 孟菲斯微缩景观 Memphis Diorama — 3D 引擎+// 平涂材质(不用光照算明暗,只用固定的面色调 + 硬边深靛阴影 + 世界坐标图案 + 立面窗格),+// 法线/深度描边,颗粒喷漆画框,底部三行字。所有东西都是 t 的确定性函数。+import * as THREE from 'three';++export const W = 1920, H = 1080, SS = 2;+export const INK = '#25214A', PAPER = '#FFFCF6';+export const FRAME = { cx: 960, cy: 468, hw: 760, hh: 372, r: 34 };+export const SUN = new THREE.Vector3(-0.42, 0.78, 0.46).normalize();++// ---------- 随机 ----------+export function rng(a) { return () => { a |= 0; a = a + 0x6D2B79F5 | 0; let t = Math.imul(a ^ a >>> 15, 1 | a); t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t; return ((t ^ t >>> 14) >>> 0) / 4294967296; }; }+export const ease = (x) => x <= 0 ? 0 : x >= 1 ? 1 : x * x * (3 - 2 * x);+export const clamp01 = (x) => Math.max(0, Math.min(1, x));+export const lerp = (a, b, u) => a + (b - a) * u;++// ---------- 平涂材质 ----------+const FLAT_VS = /* glsl */`+varying vec3 vWP;+varying vec3 vWN;+#include <common>+#include <shadowmap_pars_vertex>+void main() {+ #include <beginnormal_vertex>+ #include <defaultnormal_vertex>+ #include <begin_vertex>+ #include <project_vertex>+ #include <worldpos_vertex>+ #include <shadowmap_vertex>+ vWP = (modelMatrix * vec4(transformed, 1.0)).xyz;+ vWN = normalize(mat3(modelMatrix) * objectNormal);+}`;+const FLAT_FS = /* glsl */`+uniform vec3 uCol2, uPatCol2; uniform float uHasC2; uniform vec3 uSeas; uniform float uHT;+uniform vec3 uCol, uPatCol, uInk, uWinDay, uWinLit, uWinDark, uWarm, uNC;+uniform float uPat, uPatScale, uWin, uY0, uY1, uSeed, uEmit, uNight, uShadow, uLit, uHasNC;+uniform vec3 uSun;+uniform vec4 uLamps[48];+uniform float uWave, uZoneLit, uFlash, uDusk, uZA;+uniform vec2 uWaveC;+uniform vec4 uZone;+varying vec3 vWP;+varying vec3 vWN;+#include <common>+#include <packing>+#include <bsdfs>+#include <lights_pars_begin>+#include <shadowmap_pars_fragment>+#include <shadowmask_pars_fragment>+float h21(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }+float aaStep(float e, float x) { float w = fwidth(x) * 0.75; return smoothstep(e - w, e + w, x); }+// 亮灯波 + 银杏巷:波还没扫到的窗不亮;巷子里的窗按随机顺序逐格亮(uZoneLit 0→1)+bool inZone(vec3 p) { return p.x > uZone.x && p.x < uZone.z && p.z > uZone.y && p.z < uZone.w; }+float waveOn(vec3 p, float hsh) {+ float on = step(length(p.xz - uWaveC), uWave);+ if (inZone(p)) on = step(hsh, uZoneLit - 0.001);+ return on;+}+void main() {+ vec3 n = normalize(vWN);+ bool top = n.y > 0.6;+ vec2 puv = abs(n.y) > 0.5 ? vWP.xz : vec2(abs(n.x) > abs(n.z) ? vWP.z : vWP.x, vWP.y);+ puv /= uPatScale;+ // 换季波:波扫过的地方换成下一季的颜色+ bool nxt = uHasC2 > 0.5 && length(vWP.xz - uSeas.xy) < uSeas.z;+ vec3 col = nxt ? uCol2 : uCol, pc = nxt ? uPatCol2 : uPatCol;+ if (uPat > 0.5 && uPat < 1.5) { // 圆点+ vec2 q = puv; q.x += 0.5 * mod(floor(q.y), 2.0);+ float d = length(fract(q) - 0.5);+ col = mix(col, pc, 1.0 - aaStep(0.17, d));+ } else if (uPat > 1.5 && uPat < 2.5) { // 斜条纹+ float s = fract(puv.x + puv.y);+ col = mix(col, pc, 1.0 - aaStep(0.28, abs(s - 0.5)));+ } else if (uPat > 2.5 && uPat < 3.5) { // 折线+ float y = fract(puv.y) - abs(fract(puv.x) - 0.5) * 0.7;+ col = mix(col, pc, 1.0 - aaStep(0.07, abs(fract(y + 0.5) - 0.5)));+ } else if (uPat > 3.5 && uPat < 4.5) { // 竖条纹(遮阳棚)+ float s = fract(puv.x);+ col = mix(col, pc, aaStep(0.5, s));+ } else if (uPat > 5.5 && uPat < 6.5) { // 横条纹(卷帘门)+ col = mix(col, pc, aaStep(0.72, fract(puv.y)));+ } else if (uPat > 4.5 && uPat < 5.5) { // 剖面斜线+ float s = fract((puv.x + puv.y) * 1.0);+ col = mix(col, pc, 1.0 - aaStep(0.08, abs(s - 0.5)));+ }+ // uZA:跟着亮灯波/银杏巷一起开关的灯(路灯头、天窗、串灯)+ bool zoneOff = uZA > 0.5 && waveOn(vWP, h21(floor(vWP.xz * 0.2))) < 0.5;+ bool emit = uEmit > 0.5 && !zoneOff;+ bool useNC = uHasNC > 0.5 && !zoneOff;+ vec3 winCol = vec3(-1.0);+ // 立面窗格+ if (uWin > 0.5 && abs(n.y) < 0.3) {+ float u = abs(n.x) > abs(n.z) ? vWP.z : vWP.x;+ float v = vWP.y - uY0;+ vec2 cell = vec2(u / 2.8, (v - 0.2) / 3.2);+ vec2 f = fract(cell); vec2 id = floor(cell);+ if (v > 3.6 && v < uY1 - uY0 - 0.9) {+ vec2 lo = vec2(0.22, 0.26), hi = vec2(0.78, 0.8);+ float inside = aaStep(lo.x, f.x) * (1.0 - aaStep(hi.x, f.x)) * aaStep(lo.y, f.y) * (1.0 - aaStep(hi.y, f.y));+ float inner = aaStep(lo.x + 0.06, f.x) * (1.0 - aaStep(hi.x - 0.06, f.x)) * aaStep(lo.y + 0.07, f.y) * (1.0 - aaStep(hi.y - 0.07, f.y));+ // 银杏巷来电时每一格都亮(其他地方随机亮一半多)+ float lit = (inZone(vWP) ? 1.0 : step(0.42, h21(id + uSeed + n.xz * 7.0))) * waveOn(vWP, h21(id * 1.37 + uSeed + n.xz * 3.0));+ vec3 glass = mix(uWinDay, lit > 0.5 ? uWinLit : uWinDark, uNight);+ float glint = (1.0 - uNight) * (1.0 - aaStep(0.06, abs(f.x - f.y * 0.6 - 0.2)));+ glass = mix(glass, vec3(1.0), glint * 0.8);+ col = mix(col, uInk, inside * (1.0 - inner));+ col = mix(col, glass, inner);+ if (inner > 0.5 && uNight > 0.5 && lit > 0.5) winCol = glass;+ } else if (v < 3.4 && v > 0.3) { // 底商橱窗+ float sx = fract(u / 5.6);+ float inside = aaStep(0.08, sx) * (1.0 - aaStep(0.92, sx)) * aaStep(0.35, v) * (1.0 - aaStep(2.7, v));+ float inner = aaStep(0.11, sx) * (1.0 - aaStep(0.89, sx)) * aaStep(0.45, v) * (1.0 - aaStep(2.6, v));+ float on = waveOn(vWP, h21(vec2(floor(u / 5.6), uSeed)));+ vec3 glass = mix(uWinDay, on > 0.5 ? uWinLit : uWinDark, uNight);+ col = mix(col, uInk, inside * (1.0 - inner));+ col = mix(col, glass, inner);+ if (inner > 0.5 && uNight > 0.5 && on > 0.5) winCol = glass;+ }+ }+ // 固定面色调:顶面最亮,朝太阳的侧面次之,背阳面和投影一样是"硬阴影"+ float facing = dot(normalize(vec3(n.x, 0.0, n.z) + 1e-5), normalize(vec3(uSun.x, 0.0, uSun.z)));+ float sh = 1.0 - getShadowMask();+ if (!top) sh = max(sh, step(facing, 0.0) * (n.y < 0.6 ? 0.5 : 0.0));+ if (n.y < -0.6) sh = 1.0;+ float tone = top ? 1.0 : 0.95;+ vec3 c = col * (uLit > 0.5 ? 1.0 : tone);+ if (uShadow > 0.5 && !emit) {+ vec3 shc = mix(vec3(1.0), vec3(0.70, 0.58, 0.90), sh);+ // 半调网点:阴影里印一层浅色网点,像印刷品(世界坐标,跟着物体走)+ if (uHT > 0.5 && sh > 0.5) {+ vec2 wq = (abs(n.y) > 0.5 ? vWP.xz : vec2(abs(n.x) > abs(n.z) ? vWP.z : vWP.x, vWP.y)) / 0.38;+ wq.x += 0.5 * mod(floor(wq.y), 2.0);+ float dd = 1.0 - aaStep(0.2, length(fract(wq) - 0.5));+ shc = mix(shc, mix(vec3(1.0), vec3(0.70, 0.58, 0.90), sh * 0.45), dd);+ }+ c *= shc;+ }+ // 夜:整体压暗到深靛,路灯光圈是硬边的暖色圆+ if (useNC) c = mix(c, uNC * (uShadow > 0.5 ? mix(vec3(1.0), vec3(0.8, 0.76, 0.92), sh) : vec3(1.0)), uNight);+ if (uNight > 0.0 && !emit && !useNC) {+ // 夜色:按亮度往靛紫偏,保留一点原色相(避免黄色压暗后发橄榄绿)+ float lum = dot(c, vec3(0.2126, 0.7152, 0.0722));+ vec3 dark = mix(c * vec3(0.25, 0.26, 0.44), lum * vec3(0.24, 0.22, 0.46), 0.6) + vec3(0.008, 0.007, 0.024);+ dark = mix(dark, c * vec3(0.92, 0.55, 0.6) + vec3(0.05, 0.0, 0.03), uDusk); // 黄昏:偏橙粉+ float pool = 0.0;+ for (int i = 0; i < 48; i++) {+ vec4 L = uLamps[i];+ if (L.w <= 0.0) continue;+ float d = length(vWP.xz - L.xz);+ float hFall = 1.0 - clamp((vWP.y - 0.0) / max(L.y, 0.1), 0.0, 1.0) * 0.55;+ pool = max(pool, (1.0 - aaStep(L.w * hFall, d)) * (0.55 + 0.45 * (1.0 - d / L.w)));+ }+ vec3 lamp = c * uWarm * 1.05;+ vec3 nightC = mix(dark, lamp, clamp(pool, 0.0, 1.0) * 0.85);+ c = mix(c, nightC, uNight);+ }+ if (winCol.x >= 0.0) c = winCol;+ if (emit && uFlash > 0.0) c = mix(c, vec3(1.0), uFlash);+ gl_FragColor = vec4(c, 1.0);+}`;++const linear = (hex) => new THREE.Color(hex);+const LAMPS = Array.from({ length: 48 }, () => new THREE.Vector4(0, 0, 0, 0));+const GLOBAL = { uNight: { value: 0 }, uSun: { value: SUN.clone() }, uLamps: { value: LAMPS }, uWave: { value: 1e5 }, uWaveC: { value: new THREE.Vector2() }, uZone: { value: new THREE.Vector4() }, uZoneLit: { value: 1 }, uFlash: { value: 0 }, uDusk: { value: 0 }, uSeas: { value: new THREE.Vector3(0, 0, -1) }, uHT: { value: 0 } };++export function flat(hex, o = {}) {+ const u = THREE.UniformsUtils.merge([THREE.UniformsLib.lights, {+ uCol: { value: linear(hex) }, uPatCol: { value: linear(o.patCol || '#FFFFFF') },+ uCol2: { value: linear(o.col2 || hex) }, uPatCol2: { value: linear(o.patCol2 || o.patCol || '#FFFFFF') }, uHasC2: { value: o.col2 ? 1 : 0 },+ uInk: { value: linear(INK) }, uWinDay: { value: linear('#BFE4FF') }, uWinLit: { value: linear('#FFD36E') }, uWinDark: { value: linear('#2C2752') },+ uWarm: { value: linear('#FFE3A3') },+ uPat: { value: o.pat || 0 }, uPatScale: { value: o.patScale || 1 }, uWin: { value: o.win ? 1 : 0 },+ uY0: { value: o.y0 || 0 }, uY1: { value: o.y1 || 0 }, uSeed: { value: o.seed || 0 },+ uEmit: { value: o.emit ? 1 : 0 }, uNC: { value: linear(o.nightCol || '#000000') }, uHasNC: { value: o.nightCol ? 1 : 0 }, uZA: { value: o.zoneAware ? 1 : 0 }, uShadow: { value: o.shadow === false ? 0 : 1 }, uLit: { value: o.lit ? 1 : 0 },+ }]);+ Object.assign(u, GLOBAL);+ return new THREE.ShaderMaterial({ uniforms: u, vertexShader: FLAT_VS, fragmentShader: FLAT_FS, lights: true });+}+export function setNight(v) { GLOBAL.uNight.value = v; }+export function setWave(r, x = 0, z = 0) { GLOBAL.uWave.value = r; GLOBAL.uWaveC.value.set(x, z); }+export function setZone(z, lit) { GLOBAL.uZone.value.set(z[0], z[1], z[2], z[3]); GLOBAL.uZoneLit.value = lit; }+export function setFlash(v) { GLOBAL.uFlash.value = v; }+export function setDusk(v) { GLOBAL.uDusk.value = v; }+export function setSeason(x, z, r) { GLOBAL.uSeas.value.set(x, z, r); }+export function setHalftone(v) { GLOBAL.uHT.value = v; }+export function setLamps(list) { for (let i = 0; i < 48; i++) { const L = list[i]; LAMPS[i].set(L ? L[0] : 0, L ? L[1] : 0, L ? L[2] : 0, L ? L[3] : 0); } }++// 便捷:带材质的网格,默认投射和接收阴影+export function mesh(geo, mat, x = 0, y = 0, z = 0, parent) {+ const m = new THREE.Mesh(geo, mat); m.position.set(x, y, z); m.castShadow = true; m.receiveShadow = true;+ if (parent) parent.add(m); return m;+}+export function box(w, h, d) { const g = new THREE.BoxGeometry(w, h, d); g.translate(0, h / 2, 0); return g; }++// 文字贴图(招牌)+export function signTex(text, bg, fg, w = 512, h = 160) {+ const c = document.createElement('canvas'); c.width = w; c.height = h; const g = c.getContext('2d');+ g.fillStyle = bg; g.fillRect(0, 0, w, h);+ g.strokeStyle = INK; g.lineWidth = 14; g.strokeRect(7, 7, w - 14, h - 14);+ g.fillStyle = fg; g.font = `600 ${Math.round(h * 0.56)}px SC, sans-serif`; g.textAlign = 'center'; g.textBaseline = 'middle';+ g.fillText(text, w / 2, h / 2 + 4);+ const t = new THREE.CanvasTexture(c); t.colorSpace = THREE.SRGBColorSpace; t.anisotropy = 8; return t;+}++// ---------- 合成:描边 + 颗粒画框 ----------+const COMP_FS = /* glsl */`+uniform sampler2D tCol, tNor, tDep;+uniform vec2 res;+uniform float cn, cf, uT, uSeed, uGrow, uWob;+uniform vec3 uInk, uPaper;+uniform vec4 uFrame;+uniform float uRad;+varying vec2 vUv;+#include <packing>+float h21(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }+float vn(vec2 x) { vec2 i = floor(x), f = fract(x); vec2 u = f * f * (3.0 - 2.0 * f);+ return mix(mix(h21(i), h21(i + vec2(1, 0)), u.x), mix(h21(i + vec2(0, 1)), h21(i + vec2(1, 1)), u.x), u.y); }+float fbm(vec2 x) { return vn(x) * 0.55 + vn(x * 2.1 + 5.0) * 0.3 + vn(x * 4.3 + 9.0) * 0.15; }+float wz(vec2 uv) { float d = texture2D(tDep, uv).x; return 1.0 / max(-perspectiveDepthToViewZ(d, cn, cf), 1e-4); }+vec3 nr(vec2 uv) { return texture2D(tNor, uv).xyz * 2.0 - 1.0; }+float edge(vec2 uv) {+ vec2 px = 1.0 / res; float r = 1.7;+ float w = wz(uv); vec3 n = nr(uv);+ float e = 0.0;+ vec2 ds[2]; ds[0] = vec2(1.0, 0.0); ds[1] = vec2(0.0, 1.0);+ for (int i = 0; i < 2; i++) {+ vec2 o = ds[i] * px * r;+ float wa = wz(uv + o), wb = wz(uv - o);+ float lap = abs(wa + wb - 2.0 * w) / max(w, 1e-5);+ if (lap > 0.06) e = 1.0;+ if (dot(n, nr(uv + o)) < 0.82 || dot(n, nr(uv - o)) < 0.82) e = 1.0;+ }+ return e;+}+void main() {+ vec2 px = 1.0 / res;+ vec3 acc = vec3(0.0);+ for (int j = 0; j < 2; j++) for (int i = 0; i < 2; i++) {+ vec2 uv = vUv + (vec2(float(i), float(j)) - 0.5) * px;+ vec3 c = texture2D(tCol, uv).rgb;+ acc += mix(c, uInk, edge(uv));+ }+ vec3 col = acc * 0.25;+ // 颗粒画框(输出像素坐标,y 向下)+ vec2 p = vec2(vUv.x * ${W}.0, (1.0 - vUv.y) * ${H}.0);+ vec2 q = abs(p - uFrame.xy) - uFrame.zw + uRad;+ float d = length(max(q, 0.0)) + min(max(q.x, q.y), 0.0) - uRad;+ d += (fbm(p / 170.0 + 11.0) - 0.5) * 44.0 + (fbm(p / 38.0 + 2.0) - 0.5) * 11.0;+ float m1 = fbm(p / 140.0 + 40.0) - 0.5;+ float g = h21(p + uSeed * 17.31) * 2.0 - 1.0; g = g * g * g * 40.0;+ float m2 = length((p - uFrame.xy) * vec2(1.0, 1.15)) + (fbm(p / 120.0 + 7.0) - 0.5) * 150.0;+ if (d + uWob * m1 + g >= 0.0 || m2 + g * 1.6 >= uGrow) col = uPaper;+ gl_FragColor = vec4(col, 1.0);+ #include <colorspace_fragment>+}`;++export class Diorama {+ constructor(glCanvas, ctx2d) {+ this.r = new THREE.WebGLRenderer({ canvas: glCanvas, antialias: false, preserveDrawingBuffer: true });+ this.r.setPixelRatio(1); this.r.setSize(W, H, false);+ this.r.shadowMap.enabled = true; this.r.shadowMap.type = THREE.PCFShadowMap;+ this.r.outputColorSpace = THREE.SRGBColorSpace;+ this.ctx = ctx2d;+ this.scene = new THREE.Scene();+ this.cam = new THREE.PerspectiveCamera(30, W / H, 0.5, 1500);+ this.sun = new THREE.DirectionalLight(0xffffff, 1);+ this.sun.castShadow = true; this.sun.shadow.mapSize.set(4096, 4096);+ this.sun.shadow.bias = -0.0004; this.sun.shadow.normalBias = 0.04;+ this.scene.add(this.sun, this.sun.target);+ const opt = { type: THREE.HalfFloatType };+ this.rtCol = new THREE.WebGLRenderTarget(W * SS, H * SS, { ...opt, samples: 4 });+ this.rtNor = new THREE.WebGLRenderTarget(W * SS, H * SS, { ...opt, minFilter: THREE.NearestFilter, magFilter: THREE.NearestFilter, depthTexture: new THREE.DepthTexture(W * SS, H * SS) });+ this.normMat = new THREE.MeshNormalMaterial();+ this.comp = new THREE.ShaderMaterial({+ uniforms: {+ tCol: { value: this.rtCol.texture }, tNor: { value: this.rtNor.texture }, tDep: { value: this.rtNor.depthTexture },+ res: { value: new THREE.Vector2(W * SS, H * SS) }, cn: { value: 0.5 }, cf: { value: 1500 },+ uT: { value: 0 }, uSeed: { value: 0 }, uGrow: { value: 1e9 }, uWob: { value: 0 },+ uInk: { value: linear(INK) }, uPaper: { value: linear(PAPER) },+ uFrame: { value: new THREE.Vector4(FRAME.cx, FRAME.cy, FRAME.hw, FRAME.hh) }, uRad: { value: FRAME.r },+ },+ vertexShader: 'varying vec2 vUv; void main(){ vUv = uv; gl_Position = vec4(position.xy, 0.0, 1.0); }',+ fragmentShader: COMP_FS, depthTest: false, depthWrite: false,+ });+ this.quad = new THREE.Mesh(new THREE.PlaneGeometry(2, 2), this.comp);+ this.quadScene = new THREE.Scene(); this.quadScene.add(this.quad);+ this.quadCam = new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 1);+ }+ // 阴影相机套住镜头看的那一片+ fitShadow(target, radius) {+ const s = this.sun;+ s.target.position.copy(target);+ s.position.copy(target).addScaledVector(SUN, 400);+ const c = s.shadow.camera; c.left = -radius; c.right = radius; c.top = radius; c.bottom = -radius; c.near = 10; c.far = 900;+ c.updateProjectionMatrix();+ }+ // t:秒;frame:帧号(颗粒每 5 帧换一次);grow:开场/结尾的长出半径+ render(t, frame, opts = {}) {+ const r = this.r, cam = this.cam;+ cam.updateMatrixWorld();+ r.setRenderTarget(this.rtCol); r.render(this.scene, cam);+ const hidden = [];+ this.scene.traverse((o) => { if (o.userData.noOutline && o.visible) { o.visible = false; hidden.push(o); } });+ const bg = this.scene.background; this.scene.background = null;+ this.scene.overrideMaterial = this.normMat;+ r.setClearColor(0x8080ff, 1);+ r.setRenderTarget(this.rtNor); r.render(this.scene, cam);+ this.scene.overrideMaterial = null; this.scene.background = bg;+ for (const o of hidden) o.visible = true;+ const u = this.comp.uniforms;+ u.cn.value = cam.near; u.cf.value = cam.far; u.uT.value = t; u.uSeed.value = Math.floor(frame / 5) % 4;+ u.uWob.value = 22 * Math.sin(t * 0.55); u.uGrow.value = opts.grow ?? 1e9;+ r.setRenderTarget(null); r.render(this.quadScene, this.quadCam);+ const g = this.ctx; g.drawImage(r.domElement, 0, 0);+ if (opts.text) drawText(g, opts.text, opts.textAlpha ?? 1);+ }+}++// 底部三行字 + 孟菲斯小标记+export function drawText(g, [l1, l2, l3], a) {+ if (a <= 0) return;+ const y0 = FRAME.cy + FRAME.hh + 64;+ g.save(); g.globalAlpha = a; g.textAlign = 'center'; g.textBaseline = 'alphabetic';+ g.fillStyle = '#2B2840'; g.font = '600 25px IT, SC, sans-serif'; g.fillText(l1, 960, y0 + 34);+ g.fillStyle = '#8D8AA0'; g.font = '400 18px IT, SC, sans-serif'; g.fillText(l2, 960, y0 + 64);+ g.fillStyle = '#B7B4C6'; g.font = '400 15px PM, SC, monospace'; g.fillText(l3, 960, y0 + 91);+ const mx = 960, my = y0;+ g.fillStyle = '#FFC93C'; g.beginPath(); g.arc(mx - 24, my, 5, 0, 7); g.fill();+ g.fillStyle = '#FF7FAA'; g.beginPath(); g.moveTo(mx - 5.5, my + 4.5); g.lineTo(mx, my - 5.5); g.lineTo(mx + 5.5, my + 4.5); g.closePath(); g.fill();+ g.strokeStyle = '#2E5BE6'; g.lineWidth = 2.2; g.lineCap = 'round'; g.beginPath(); g.moveTo(mx + 16, my); g.lineTo(mx + 20, my - 3.5); g.lineTo(mx + 24.5, my + 3.5); g.lineTo(mx + 29, my); g.stroke();+ g.restore();+}diff --git a/styles/memphis-diorama/demo/music.py b/styles/memphis-diorama/demo/music.pynew file mode 100644index 0000000..111596a--- /dev/null+++ b/styles/memphis-diorama/demo/music.py@@ -0,0 +1,286 @@+"""《柚子城的四季》配乐(40 秒):一整首连着的曲子,不按季节分段。全部代码合成。+F 大调,96 BPM,每小节 2.5 秒;和弦一直走 Bbmaj7 – C – Am7 – Dm7(4–5–3–6),每 10 秒一轮。+钢琴分解和弦从头到尾不断,主旋律一直是钢琴;季节只改变伴奏的厚薄:+春只有钢琴 + 铺底 + 钢片琴;夏加贝斯和轻鼓;秋鼓变轻、马林巴叠旋律;冬鼓撤掉、音乐盒叠旋律,最后落到 Fmaj7。+三次换季的声音完全一样:大树一蹲(闷“咚”)→ 弹起来(“啵嘤”)→ 一串往上走的竖琴。+用法(库根目录): .venv/bin/python -I styles/memphis-diorama/demo/music.py → demo/out/mix.wav+"""+import os+import wave+import numpy as np+from scipy import signal++ROOT = os.path.dirname(os.path.abspath(__file__))+SR, DUR = 48000, 40.0+N = int(SR * DUR)+mix = np.zeros((N, 2), np.float32)+rev = np.zeros((N, 2), np.float32)+rng = np.random.default_rng(7)+++def mtof(m):+ return 440.0 * 2 ** ((m - 69) / 12)+++def tt(d):+ return np.arange(int(SR * d)) / SR+++def filt(x, kind, f, order=2):+ return signal.sosfilt(signal.butter(order, f, btype=kind, fs=SR, output="sos"), x).astype(np.float32)+++def noise(d):+ return rng.standard_normal(int(SR * d)).astype(np.float32)+++def add(sig, t, gain=1.0, pan=0.0, send=0.25):+ i = int(t * SR)+ if i >= N or i < 0:+ return+ sig = np.asarray(sig, np.float32)[:N - i] * gain+ l, r = np.cos((pan + 1) * np.pi / 4), np.sin((pan + 1) * np.pi / 4)+ mix[i:i + len(sig), 0] += sig * l; mix[i:i + len(sig), 1] += sig * r+ rev[i:i + len(sig), 0] += sig * l * send; rev[i:i + len(sig), 1] += sig * r * send+++# ---------- 音色 ----------+def piano(m, d=2.6, vel=0.7):+ """加法合成钢琴:两根略微走音的弦、轻微非谐、高次泛音衰减快、琴槌噪声。"""+ f, t = mtof(m), tt(d)+ s = np.zeros_like(t)+ for n in range(1, 10):+ fn = n * f * np.sqrt(1 + 0.00035 * n * n)+ if fn > 14000:+ break+ amp = (1 / n ** 1.1) * (vel ** (0.25 * (n - 1)))+ dec = (1.9 / (1 + 0.55 * (n - 1))) * (330 / f) ** 0.35+ s += amp * (np.sin(2 * np.pi * fn * t) + 0.8 * np.sin(2 * np.pi * fn * 1.0007 * t + n)) * np.exp(-t / dec)+ s += 0.25 * vel * filt(noise(d), "bandpass", [min(f * 2, 4000), min(f * 8, 12000)]) * np.exp(-t / 0.008)+ s *= np.minimum(t / 0.0015, 1) * np.minimum((d - t) / 0.12, 1)+ return filt(s, "lowpass", 2500 + 5000 * vel) * 0.35+++def celesta(m, d=1.8):+ f, t = mtof(m), tt(d)+ return (np.sin(2 * np.pi * f * t) * np.exp(-t / 0.7) + 0.25 * np.sin(2 * np.pi * f * 4 * t) * np.exp(-t / 0.12)) * np.minimum(t / 0.002, 1)+++def musicbox(m, d=2.0):+ f, t = mtof(m), tt(d)+ return (np.sin(2 * np.pi * f * t) * np.exp(-t / 0.9) + 0.35 * np.sin(2 * np.pi * f * 5.95 * t) * np.exp(-t / 0.05) + 0.15 * np.sin(2 * np.pi * f * 3.01 * t) * np.exp(-t / 0.3)) * np.minimum(t / 0.001, 1)+++def marimba(m, d=1.0):+ f, t = mtof(m), tt(d)+ return (np.sin(2 * np.pi * f * t) * np.exp(-t / 0.4) + 0.3 * np.sin(2 * np.pi * f * 3.93 * t) * np.exp(-t / 0.05)) * np.minimum(t / 0.002, 1)+++def harp(m, d=1.6):+ f, t = mtof(m), tt(d)+ s = sum((1 / k ** 1.6) * np.sin(2 * np.pi * f * k * t) * np.exp(-t / (1.0 / k ** 0.6)) for k in range(1, 6))+ return s * np.minimum(t / 0.003, 1)+++def pad(ms, d, cutoff=1100, attack=1.0):+ t = tt(d)+ s = np.zeros_like(t)+ for m in ms:+ for dt in (-0.07, 0.0, 0.07): # 三条略微走音的锯齿,滤掉高频,暖一点+ f = mtof(m) * 2 ** (dt / 12)+ s += 2 * ((f * t + rng.uniform()) % 1) - 1+ s = filt(s / (3 * len(ms)), "lowpass", cutoff, order=4)+ return s * np.minimum(t / attack, 1) * np.minimum((d - t) / attack, 1)+++def bass(m, d=1.0):+ f, t = mtof(m), tt(d)+ s = np.sin(2 * np.pi * f * t) + 0.25 * np.sin(4 * np.pi * f * t) * np.exp(-t / 0.2)+ return s * np.minimum(t / 0.006, 1) * np.exp(-t / 1.2) * np.minimum((d - t) / 0.05, 1)+++def kick():+ t = tt(0.3)+ return np.sin(2 * np.pi * np.cumsum(55 * (1 + 1.8 * np.exp(-t / 0.025))) / SR) * np.exp(-t / 0.11)+++def brush():+ t = tt(0.25)+ return filt(noise(0.25), "bandpass", [1800, 7000]) * np.exp(-t / 0.07) * np.minimum(t / 0.01, 1)+++def shaker():+ t = tt(0.07)+ return filt(noise(0.07), "highpass", 6500) * np.sin(np.pi * t / 0.07) ** 2+++def chirp(f0=4200, d=0.09):+ t = tt(d)+ f = f0 * (1 + 0.35 * np.sin(np.pi * t / d))+ return np.sin(2 * np.pi * np.cumsum(f) / SR) * np.sin(np.pi * t / d) ** 2+++def quack():+ t = tt(0.16)+ s = np.sign(np.sin(2 * np.pi * np.cumsum(520 * (1 - 0.3 * t / 0.16)) / SR))+ return filt(s, "bandpass", [600, 2400]) * np.sin(np.pi * t / 0.16) ** 0.5 * 0.5+++def honk():+ t = tt(0.24)+ s = 2 * ((np.cumsum(360 * (1 - 0.12 * t / 0.24)) / SR) % 1) - 1+ return filt(s, "bandpass", [450, 1800]) * np.sin(np.pi * t / 0.24) ** 0.6+++def pop():+ t = tt(0.12)+ return np.sin(2 * np.pi * np.cumsum(300 + 900 * t / 0.12) / SR) * np.exp(-t / 0.04)+++def whoosh(d, lo=300, hi=2500):+ t = tt(d)+ return filt(noise(d), "bandpass", [lo, hi]) * np.sin(np.pi * t / d) ** 2+++# ---------- 曲子 ----------+BEAT = 0.625+BAR = 2.5+D0 = 1.8 # 第 0 小节的强拍;换季 9.3 / 19.3 / 29.3 正好落在第 3、7、11 小节+BB, C, AM, DM, F = (46, [58, 62, 65, 69]), (48, [55, 60, 64, 67]), (45, [57, 60, 64, 67]), (50, [57, 60, 62, 65]), (41, [57, 60, 64, 65])+PROG = [BB, C, AM, DM] * 3 + [BB, C, F]+bt = lambda k, b=0.0: D0 + k * BAR + b * BEAT++# 开场:画框长出来,铺底 + 一串竖琴把人带进第一小节+add(pad([53, 57, 60, 64], 2.6, 900, 1.0), 0.0, 0.10, send=0.6)+for j, m in enumerate([65, 69, 72, 76, 77, 81]):+ add(harp(m), 0.45 + j * 0.2, 0.09, pan=-0.5 + 0.2 * j, send=0.5)++# 铺底:一直跟着和弦+for k, (root, ch) in enumerate(PROG):+ d = BAR + 0.9 if k < len(PROG) - 1 else 40 - bt(k)+ add(pad(ch, d, 1000 if k < 4 else 1300, 0.6), bt(k) - 0.3, 0.075, send=0.5)++# 钢琴分解和弦:从头到尾不断(左手根音 + 五度,右手八分音符)+for k in range(-1, len(PROG)):+ root, ch = PROG[k] if k >= 0 else F+ last = k == len(PROG) - 1+ for i in range(8):+ t = bt(k, i / 2)+ if t < 0.5 or (last and i > 0):+ continue+ if i == 0:+ add(piano(root, 3.0, 0.5), t, 0.5, pan=-0.35, send=0.3)+ elif i == 4:+ add(piano(root + 7, 2.0, 0.4), t, 0.32, pan=-0.25, send=0.3)+ else:+ m = ch[[0, 1, 2, 3, 2, 1, 2, 3][i]]+ add(piano(m, 1.6, 0.35), t, 0.22 * (0.9 if i % 2 else 1.0), pan=0.1 + 0.08 * (m - 60) / 6, send=0.35)+ if last: # 最后的 Fmaj7:慢慢往上滚+ for j, m in enumerate([53, 57, 60, 64, 65, 69, 72]):+ add(piano(m, 3.5, 0.45), bt(k, 0.5 + j * 0.5), 0.28, pan=-0.3 + 0.1 * j, send=0.5)++# 主旋律(钢琴)+A = [[(0, 77, 1.5), (1.5, 76, 0.5), (2, 74, 1), (3, 72, 1)],+ [(0, 76, 1.5), (1.5, 74, 0.5), (2, 72, 1), (3, 67, 1)],+ [(0, 72, 1), (1, 76, 1), (2, 81, 1.5), (3.5, 79, 0.5)],+ [(0, 77, 1.5), (1.5, 76, 0.5), (2, 74, 2)]]+B = [[(0, 81, 1), (1, 79, 0.5), (1.5, 77, 0.5), (2, 77, 1), (3, 79, 0.5), (3.5, 81, 0.5)],+ [(0, 79, 1.5), (1.5, 76, 0.5), (2, 72, 1), (3, 74, 0.5), (3.5, 76, 0.5)],+ [(0, 76, 1), (1, 81, 1), (2, 84, 1), (3, 81, 0.5), (3.5, 79, 0.5)],+ A[3]]+END = [(0, 69, 1), (1, 72, 1), (2, 77, 4)]+MEL = A + B + A + [A[0], A[1], END]+for k, bar in enumerate(MEL):+ for b, m, d in bar:+ t = bt(k, b)+ dur = max(d * BEAT + 0.8, 1.4) if k < 14 else 4.0+ add(piano(m, dur, 0.75), t, 0.62, pan=0.15, send=0.45)+ # 叠一层,随季节换:春钢片琴;夏不叠(让给鼓);秋马林巴;冬音乐盒+ if k < 4:+ add(celesta(m + 12, 1.6), t, 0.05, pan=0.35, send=0.5)+ elif 8 <= k < 12:+ add(marimba(m, 1.0), t, 0.07, pan=0.3, send=0.35)+ elif k >= 12:+ add(musicbox(m + 12, 2.2), t, 0.06, pan=0.35, send=0.55)++# 贝斯:夏天进来,冬天变成长音+for k in range(4, len(PROG)):+ root, _ = PROG[k]+ if k < 12:+ for b, d in ((0, 1.4), (1.5, 0.5), (2, 1.0), (3.5, 0.5)):+ add(bass(root - 12, d), bt(k, b), 0.30 * (0.85 if b else 1.0), send=0.03)+ else:+ add(bass(root - 12, BAR if k < 14 else 3.2), bt(k), 0.26, send=0.05)+# 一开始就有的轻沙锤,到夏天加踢鼓和刷子;秋天变轻;冬天撤掉+for k in range(0, 12):+ for i in range(8):+ t = bt(k, i / 2)+ g = 0.6 if k < 4 else 1.0 if k < 8 else 0.75+ rainy = 12.3 < t < 17.6+ if k < 11 or i < 4:+ add(shaker(), t, (0.022 if i % 2 else 0.032) * g, pan=0.45, send=0.05)+ if 4 <= k < 11:+ if i in (0, 5):+ add(kick(), t, 0.22 * (0.7 if rainy else 1.0) * (0.8 if k >= 8 else 1.0), send=0.03)+ if i in (2, 6):+ add(brush(), t, 0.05 * (0.8 if k >= 8 else 1.0), pan=0.15, send=0.2)++# ---------- 换季:三次一模一样 ----------+for T in (9.3, 19.3, 29.3):+ tq = tt(0.25)+ add(np.sin(2 * np.pi * np.cumsum(170 - 60 * tq / 0.25) / SR) * np.exp(-tq / 0.08), T - 0.42, 0.22, send=0.2) # 一蹲:闷“咚”+ tb_ = tt(0.5)+ boing = np.sin(2 * np.pi * np.cumsum(330 + 380 * (1 - np.exp(-tb_ / 0.06)) + 25 * np.sin(2 * np.pi * 11 * tb_) * np.exp(-tb_ / 0.2)) / SR) * np.exp(-tb_ / 0.15)+ add(boing, T, 0.10, send=0.3) # 弹起来:“啵嘤”+ for j, m in enumerate([62, 65, 69, 72, 74, 77, 81, 84, 86, 89]):+ add(harp(m, 1.8), T + 0.08 + j * 0.11, 0.075, pan=-0.6 + 0.13 * j, send=0.6) # 一串往上走的竖琴+ add(whoosh(2.4, 500, 4500), T, 0.035, send=0.3)++# ---------- 拟音(都很轻,垫在音乐下面) ----------+# 春:燕子、鸭子+for t in (1.6, 1.75, 3.9, 4.05, 4.2, 6.3, 6.45, 8.1):+ add(chirp(rng.uniform(3800, 5200), 0.08), t, 0.03, pan=rng.uniform(-0.7, 0.7), send=0.3)+add(quack(), 3.3, 0.035, pan=0.6, send=0.2); add(quack(), 3.55, 0.03, pan=0.6, send=0.2); add(quack(), 7.0, 0.03, pan=0.6, send=0.2)+# 夏:蝉、远雷、过云雨、荷花开+tc = tt(8.6)+cic = filt(noise(8.6), "bandpass", [4500, 7000]) * (0.6 + 0.4 * np.sin(2 * np.pi * 38 * tc)) * np.minimum(tc / 1.0, 1) * np.minimum((8.6 - tc) / 1.0, 1)+cic[(tc + 10.8 > 12.2) & (tc + 10.8 < 16.8)] *= 0.25+add(cic, 10.8, 0.012, pan=-0.2, send=0.1)+add(filt(noise(2.5), "lowpass", 120) * np.exp(-tt(2.5) / 0.8) * np.minimum(tt(2.5) / 0.3, 1), 11.9, 0.22, send=0.3)+tr = tt(6.0)+add(filt(noise(6.0), "bandpass", [800, 7000]) * np.minimum(tr / 0.8, 1) * np.minimum((6.0 - tr) / 1.0, 1), 12.1, 0.035, send=0.15)+for t in np.sort(rng.uniform(12.4, 17.6, 50)):+ add(np.sin(2 * np.pi * np.cumsum(np.full(1200, rng.uniform(900, 1700)) * (1 + 0.8 * np.linspace(0, 1, 1200))) / SR) * np.exp(-tt(0.025) / 0.006), t, 0.018, pan=rng.uniform(-0.8, 0.8), send=0.2)+for i in range(8):+ add(celesta([84, 86, 89, 91, 93, 96, 93, 91][i], 1.2), 16.75 + i * 0.14, 0.03, pan=0.5, send=0.5)+# 秋:落叶、稻草垛、大雁+for t in np.sort(rng.uniform(20.8, 29.0, 18)):+ d = rng.uniform(0.25, 0.5)+ add(filt(noise(d), "bandpass", [2500, 7500]) * np.sin(np.pi * tt(d) / d) ** 2, t, 0.018, pan=rng.uniform(-0.8, 0.8), send=0.15)+for t in np.sort(rng.uniform(22.1, 27.4, 10)):+ add(pop(), t, 0.012, pan=rng.uniform(-0.6, 0.6), send=0.2)+for t, p in ((22.2, 0.6), (22.5, 0.55), (23.85, 0.3), (25.35, 0.0), (26.6, -0.3), (28.15, -0.6)):+ add(honk(), t, 0.025, pan=p, send=0.35)+# 冬:风、雪人、窗户一盏盏亮(叮,都在 F 大调五声音阶里)+tw = tt(9.5)+add(filt(noise(9.5), "bandpass", [300, 1400]) * (0.6 + 0.4 * np.sin(2 * np.pi * 0.21 * tw)) * np.minimum(tw / 1.5, 1) * np.minimum((9.5 - tw) / 1.5, 1), 30.3, 0.03, pan=-0.3, send=0.2)+add(pop(), 32.65, 0.02, send=0.2)+for k, t in enumerate(np.sort(rng.uniform(34.7, 38.2, 12))):+ add(celesta([84, 86, 88, 91, 93, 96][k % 6], 1.2), t, 0.025, pan=rng.uniform(-0.6, 0.6), send=0.6)++# ---------- 底噪 + 混响 + 总线 ----------+add(filt(noise(DUR), "lowpass", 500) * 0.4, 0, 0.012, send=0.0)+ir_t = tt(2.6)+ir = rng.standard_normal((len(ir_t), 2)).astype(np.float32) * np.exp(-ir_t / 0.75)[:, None]+for c in range(2):+ ir[:, c] = filt(ir[:, c], "lowpass", 5500); ir[:, c] /= np.sqrt((ir[:, c] ** 2).sum())+pre = int(0.02 * SR)+wet = np.stack([np.concatenate([np.zeros(pre, np.float32), signal.fftconvolve(rev[:, c], ir[:, c])[:N - pre]]) for c in range(2)], 1) * 0.5+out = mix + wet+ta = np.arange(N) / SR+out *= (np.minimum(ta / 0.3, 1) * np.clip((DUR - ta) / 1.2, 0, 1))[:, None]+out = np.tanh(out / np.max(np.abs(out)) * 1.2) / np.tanh(1.2) * 0.89+os.makedirs(os.path.join(ROOT, "out"), exist_ok=True)+with wave.open(os.path.join(ROOT, "out", "mix.wav"), "wb") as w:+ w.setnchannels(2); w.setsampwidth(2); w.setframerate(SR); w.writeframes((out * 32767).astype(np.int16).tobytes())+print("ok")diff --git a/styles/memphis-diorama/demo/people.js b/styles/memphis-diorama/demo/people.jsnew file mode 100644index 0000000..b71e5ea--- /dev/null+++ b/styles/memphis-diorama/demo/people.js@@ -0,0 +1,38 @@+// Distant figures: a capsule body, round head, hat, two legs and two arms. Only a walk cycle and simple poses; never close-ups.+import * as THREE from 'three';+import { flat, mesh } from './memphis.js';++const SKIN = '#FFD9B8';+const cache = new Map();+const M = (hex, o = {}) => { const k = hex + JSON.stringify(o); if (!cache.has(k)) cache.set(k, flat(hex, o)); return cache.get(k); };++export function person(world, o) {+ const g = new THREE.Group(); world.add(g);+ const body = mesh(new THREE.CapsuleGeometry(0.28, 0.55, 6, 14).translate(0, 1.05, 0), M(o.col), 0, 0, 0, g);+ const head = new THREE.Group(); head.position.set(0, 1.72, 0); g.add(head);+ mesh(new THREE.SphereGeometry(0.24, 16, 12), M(SKIN), 0, 0, 0, head);+ if (o.hat) mesh(new THREE.SphereGeometry(0.29, 16, 8, 0, Math.PI * 2, 0, Math.PI / 2), M(o.hat), 0, 0.06, 0, head);+ const legs = [-1, 1].map((s) => mesh(new THREE.CapsuleGeometry(0.09, 0.42, 4, 8).translate(0, -0.3, 0), M('#4A4468'), 0, 0.62, s * 0.13, g));+ const arms = [-1, 1].map((s) => {+ const a = new THREE.Group(); a.position.set(0, 1.36, s * 0.33); g.add(a);+ mesh(new THREE.CapsuleGeometry(0.075, 0.38, 4, 8).translate(0, -0.25, 0), M(o.col), 0, 0, 0, a);+ mesh(new THREE.SphereGeometry(0.085, 10, 8), M(SKIN), 0, -0.5, 0, a);+ return a;+ });+ return { g, body, head, legs, arms, ...o };+}++// Lay a unit-length, y-aligned cylinder between two points (a kite string)+const _up = new THREE.Vector3(0, 1, 0), _d = new THREE.Vector3();+export function limb(m, a, b) {+ _d.subVectors(b, a); const len = _d.length();+ m.position.copy(a).addScaledVector(_d, 0.5); m.quaternion.setFromUnitVectors(_up, _d.normalize()); m.scale.set(1, Math.max(len, 1e-3), 1);+}++// Walk cycle: bob, sway, legs and arms swing; ph is the step phase+export function walk(p, x, z, a, ph) {+ p.g.position.set(x, 0.15 + Math.abs(Math.sin(ph)) * 0.08, z); p.g.rotation.y = -a;+ p.body.rotation.z = Math.sin(ph) * 0.06; p.head.position.y = 1.72 + Math.abs(Math.cos(ph)) * 0.03;+ p.legs[0].rotation.z = Math.sin(ph) * 0.5; p.legs[1].rotation.z = -Math.sin(ph) * 0.5;+ p.arms[0].rotation.set(0, 0, -Math.sin(ph) * 0.45); p.arms[1].rotation.set(0, 0, Math.sin(ph) * 0.45);+}diff --git a/styles/memphis-diorama/demo/stills/frame_spring.jpg b/styles/memphis-diorama/demo/stills/frame_spring.jpgnew file mode 100644index 0000000..d7dc638Binary files /dev/null and b/styles/memphis-diorama/demo/stills/frame_spring.jpg differdiff --git a/styles/memphis-diorama/demo/stills/frame_squat.jpg b/styles/memphis-diorama/demo/stills/frame_squat.jpgnew file mode 100644index 0000000..431245dBinary files /dev/null and b/styles/memphis-diorama/demo/stills/frame_squat.jpg differdiff --git a/styles/memphis-diorama/demo/stills/frame_summer.jpg b/styles/memphis-diorama/demo/stills/frame_summer.jpgnew file mode 100644index 0000000..a620cc6Binary files /dev/null and b/styles/memphis-diorama/demo/stills/frame_summer.jpg differdiff --git a/styles/memphis-diorama/demo/stills/frame_winter.jpg b/styles/memphis-diorama/demo/stills/frame_winter.jpgnew file mode 100644index 0000000..574da2aBinary files /dev/null and b/styles/memphis-diorama/demo/stills/frame_winter.jpg differdiff --git a/styles/memphis-diorama/demo/stills/styleframe.jpg b/styles/memphis-diorama/demo/stills/styleframe.jpgnew file mode 100644index 0000000..f60ef48Binary files /dev/null and b/styles/memphis-diorama/demo/stills/styleframe.jpg differdiff --git a/styles/memphis-diorama/demo/tools/fonts.py b/styles/memphis-diorama/demo/tools/fonts.pynew file mode 100644index 0000000..eabbb23--- /dev/null+++ b/styles/memphis-diorama/demo/tools/fonts.py@@ -0,0 +1,32 @@+"""Subset the film's fonts to the characters it uses (Google Fonts CSS2 API, &text=), all OFL.+usage: python -I tools/fonts.py <demo_dir> -> fonts/*.woff2 + fonts/fonts.css + fonts/OFL-*.txt"""+import sys, os, re, ssl, urllib.request, urllib.parse+D = sys.argv[1]+main = open(os.path.join(D, 'main.js'), encoding='utf-8').read()+src = main[main.index('const TEXT = ['):main.index('const TITLE')] + main[main.index('const TITLE'):].split('\n', 1)[0] # only the on-screen strings+cjk = sorted(set(re.findall(r'[ -〿一-鿿-·°]', src)))+latin = ''.join(chr(c) for c in range(32, 127))+text = ''.join(cjk) + latin+print(len(cjk), 'CJK chars')+UA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120 Safari/537.36'+try:+ import certifi+ CTX = ssl.create_default_context(cafile=certifi.where())+except ImportError:+ CTX = ssl.create_default_context()+get = lambda url: urllib.request.urlopen(urllib.request.Request(url, headers={'User-Agent': UA}), timeout=60, context=CTX).read()+os.makedirs(os.path.join(D, 'fonts'), exist_ok=True)+css = []+for fam, w, alias, out in (('Noto Sans SC', 400, 'SC', 'NotoSansSC-400.woff2'), ('Noto Sans SC', 600, 'SC', 'NotoSansSC-600.woff2'),+ ('Inter Tight', 400, 'IT', 'InterTight-400.woff2'), ('Inter Tight', 600, 'IT', 'InterTight-600.woff2'),+ ('IBM Plex Mono', 400, 'PM', 'IBMPlexMono-400.woff2')):+ c = get('https://fonts.googleapis.com/css2?family=' + urllib.parse.quote(fam) + f':wght@{w}&text=' + urllib.parse.quote(text)).decode()+ urls = re.findall(r'url\((https://[^)]+)\)', c)+ assert len(urls) == 1, c[:400]+ data = get(urls[0]); open(os.path.join(D, 'fonts', out), 'wb').write(data)+ css.append(f"@font-face{{font-family:'{alias}';src:url({out}) format('woff2');font-weight:{w}}}")+ print(out, len(data), 'bytes')+open(os.path.join(D, 'fonts', 'fonts.css'), 'w').write('\n'.join(css) + '\n')+# licence texts from github.com/google/fonts (ofl/<family>/OFL.txt)+for fam, out in (('notosanssc', 'OFL-notosanssc.txt'), ('intertight', 'OFL-intertight.txt'), ('ibmplexmono', 'OFL-ibmplexmono.txt')):+ open(os.path.join(D, 'fonts', out), 'wb').write(get(f'https://raw.githubusercontent.com/google/fonts/main/ofl/{fam}/OFL.txt'))diff --git a/styles/memphis-diorama/poster.jpg b/styles/memphis-diorama/poster.jpgnew file mode 100644index 0000000..f60ef48Binary files /dev/null and b/styles/memphis-diorama/poster.jpg differdiff --git a/styles/memphis-diorama/style.json b/styles/memphis-diorama/style.jsonnew file mode 100644index 0000000..8566255--- /dev/null+++ b/styles/memphis-diorama/style.json@@ -0,0 +1,20 @@+{+ "slug": "memphis-diorama",+ "num": "71",+ "en": "Memphis Diorama",+ "cn": "孟菲斯微缩景观",+ "category_en": "Materials & 3D",+ "category_cn": "材质与 3D",+ "film": "Four Seasons in Pomelo Town",+ "line": "One river bend through spring, summer, autumn and winter in one take; each season starts when the big tree squats and springs back.",+ "line_cn": "同一个河湾一镜到底过完春夏秋冬:大树往下一蹲、再弹起来,就换一季。",+ "uses": [+ "Web hero scenes",+ "Ambient loops",+ "Seasonal series",+ "How things work",+ "City data maps"+ ],+ "frame_sec": 25.0,+ "dur": 40.0+}