import {runSim} from '../kit/runtime.js'; import {createConsole} from '../green/console.js'; import {makeCursor, makeLabels, PAPER_GREEN, SHIFT} from '../green/look.js'; import {createStage, PAPER} from '../wasp-shared/stage.js'; import {buildCigar} from './cigar.js'; import {makeCigarTour, FLOOR_Y} from './tour.js'; const D2R = Math.PI / 180; Object.assign(PAPER, PAPER_GREEN); const NAV = [['overview', 'Overview'], ['cap', 'Cap'], ['band', 'Band'], ['wrapper', 'Wrapper'], ['binder', 'Binder'], ['filler', 'Filler'], ['foot', 'Foot'], ['exploded', 'Teardown'], ['hero', 'Release']]; const PAGE = { name: 'Torcidora', code: 'CR-7', title: 'Premium Cigar, Taken Apart', date: '2026-11-10', nav: NAV, pills: NAV.slice(1), sub: {overview: ['Whole-leaf corona', 'Hand-rolled construction'], cap: ['Triple cap, clean cut'], band: ['Burgundy + embossed gold'], wrapper: ['Wrapper: 1 leaf, sun-grown'], binder: ['Capote: elastic leaf'], filler: ['Tripa: seco / viso / ligero'], foot: ['Char, ember, mineral ash'], exploded: ['Every layer separated', 'Turntable 325°'], hero: ['Whole leaf, reassembled']}, cards: [{k: 'Heat', kind: 'bar', unit: '°C'}, {k: 'Draw', kind: 'wave', unit: ''}, {k: 'Layers', kind: 'bars', n: 4, unit: ''}, {k: 'Ash', kind: 'bar', unit: '%'}], }; export function makeCigarGreen(TL, {tour = makeCigarTour} = {}) { const T = tour(TL); return async ({canvas, capture}) => { const app = document.getElementById('app'); const st = createStage({canvas, floorY: FLOOR_Y}); const cigar = buildCigar(); st.addBee(cigar); cigar.root.rotation.order = 'YXZ'; const ui = createConsole(app, PAGE); const cursorAt = makeCursor(ui, T.SCRIPT); const labels = makeLabels(st, cigar.anchors, {}); const fit = () => { const k = Math.min(innerWidth / 1600, innerHeight / 900); app.style.transform = `scale(${k})`; }; const resize = () => { fit(); st.resize(1600, 900, capture ? devicePixelRatio || 1 : Math.min(devicePixelRatio || 1, 2)); }; resize(); window.CIGAR = {st, bee: cigar, T}; return {resize, render(t) { const s = T.stateAt(t); cigar.pose(s); const f = s.flight; cigar.root.position.copy(f.pos); cigar.root.rotation.set(f.roll * D2R, (f.yaw + s.turn) * D2R, f.pitch * D2R); const c = s.cam; st.frame({...c, az: c.az * D2R, el: c.el * D2R, sx: c.sx + SHIFT[0], sy: c.sy + SHIFT[1]}, {guides: 0}); const tel = T.telemetry(t, s), opening = Math.max(s.open[s.view] ?? 0, s.explode); ui.update({time: t, dur: TL.duration, status: tel.status, apart: Math.round(opening * 100), view: s.view === 'intro' ? 'overview' : s.view, callouts: labels(tel.labelSet), cursor: cursorAt(t), cards: [ {v: Math.round(540 + 150 * s.ember + 12 * Math.sin(t * 8.7)), bar: .65 + .2 * s.ember}, {v: (1.18 + .12 * Math.sin(t * 2)).toFixed(2), wave: Array.from({length: 70}, (_, i) => .40 * Math.sin(t * 2.1 - i * .11) + .08 * Math.sin(t * 4.4 - i * .33))}, {bars: [1 - s.wrapper * .8, 1 - s.binder * .8, 1 - s.tripa * .75, 1 - s.explode * .85]}, {v: Math.round(100 * (1 - s.ashDrop)), bar: 1 - s.ashDrop}, ]}); return {}; }}; }; } export const runCigarGreen = (TL, title = 'cigar-film', opts = {}) => runSim({duration: TL.duration, fps: 60, theme: 'light', hud: {enabled: false, title, subtitle: ''}, director: {enabled: false}, watermark: ''}, makeCigarGreen(TL, opts));