@open-take/compositor 0.5.2 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cdp-CzT5BKNY.js +3 -0
- package/dist/cdp-QXbQfXna.js +373 -0
- package/dist/cdp-QXbQfXna.js.map +1 -0
- package/dist/index.d.ts +4327 -195
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +26282 -160
- package/dist/index.js.map +1 -1
- package/dist/server-841PMF2H.js +163 -0
- package/dist/server-841PMF2H.js.map +1 -0
- package/dist/server-C2aVv4-t.js +3 -0
- package/kit/audio.mjs +2366 -0
- package/kit/camera.js +587 -0
- package/kit/cursor.js +264 -0
- package/kit/cut.js +427 -0
- package/kit/draw.js +346 -0
- package/kit/look.js +589 -0
- package/kit/map.js +170 -0
- package/kit/media.js +3568 -0
- package/kit/motion.js +1115 -0
- package/kit/seams.js +1006 -0
- package/kit/stage.js +923 -0
- package/kit/time.js +812 -0
- package/kit/world.js +1072 -0
- package/package.json +7 -3
- package/src/ffmpeg.ts +63 -0
- package/src/film/beats.ts +1285 -0
- package/src/film/carry.ts +221 -0
- package/src/film/changes.ts +330 -0
- package/src/film/check.ts +996 -0
- package/src/film/clock.ts +2530 -0
- package/src/film/components-probe.ts +809 -0
- package/src/film/components.ts +1566 -0
- package/src/film/frames.ts +389 -0
- package/src/film/gallery.ts +3276 -0
- package/src/film/kit.ts +515 -0
- package/src/film/layout.ts +701 -0
- package/src/film/listen.ts +1979 -0
- package/src/film/look.ts +3829 -0
- package/src/film/materials.ts +976 -0
- package/src/film/moving.ts +248 -0
- package/src/film/part-files.ts +729 -0
- package/src/film/picture.ts +74 -0
- package/src/film/probe-text.ts +843 -0
- package/src/film/probe.ts +3456 -0
- package/src/film/provenance.ts +596 -0
- package/src/film/render.ts +2447 -0
- package/src/film/report.ts +1631 -0
- package/src/film/sheet.ts +156 -0
- package/src/film/study-declared.ts +123 -0
- package/src/film/study-picture.ts +791 -0
- package/src/film/study-sound.ts +416 -0
- package/src/film/study.ts +864 -0
- package/src/film/tuning.ts +155 -0
- package/src/film/viewer.ts +174 -0
- package/src/html/cdp.ts +575 -0
- package/src/html/server.ts +208 -0
- package/src/index.ts +202 -0
- package/src/launch-render.ts +3 -2
- package/src/math.ts +3 -3
- package/src/mjpeg-matroska.ts +228 -0
- package/src/render.ts +6 -4
- package/src/state-diff.ts +215 -0
- package/src/state-index.ts +99 -0
- package/src/types.ts +59 -1
- package/starter/PLAN.md +84 -0
- package/starter/START.md +460 -0
- package/starter/lib/anim.js +760 -0
- package/starter/lib/devices.js +1402 -0
- package/starter/lib/handoff.js +421 -0
- package/starter/lib/hud.js +1879 -0
- package/starter/lib/measure.mjs +154 -0
- package/starter/lib/moves.js +1095 -0
- package/starter/lib/palette.mjs +803 -0
- package/starter/lib/physics-seeds.mjs +198 -0
- package/starter/lib/physics.js +738 -0
- package/starter/lib/sampler.mjs +242 -0
- package/starter/lib/solid.js +727 -0
- package/starter/lib/space.js +1227 -0
- package/starter/lib/swarm.js +1398 -0
- package/starter/reference/motion.md +276 -0
- package/starter/reference/structure.md +466 -0
- package/starter/reference/travel/motion.md +433 -0
- package/starter/reference/travel/sound.md +241 -0
- package/starter/reference/travel/structure.md +518 -0
- package/starter/samples/NOTICE.txt +55 -0
- package/starter/samples/celli/celli_24_1.opus +0 -0
- package/starter/samples/celli/celli_24_3.opus +0 -0
- package/starter/samples/celli/celli_28_1.opus +0 -0
- package/starter/samples/celli/celli_28_3.opus +0 -0
- package/starter/samples/celli/celli_31_1.opus +0 -0
- package/starter/samples/celli/celli_31_3.opus +0 -0
- package/starter/samples/celli/celli_35_1.opus +0 -0
- package/starter/samples/celli/celli_35_3.opus +0 -0
- package/starter/samples/celli/celli_38_1.opus +0 -0
- package/starter/samples/celli/celli_38_3.opus +0 -0
- package/starter/samples/celli/celli_41_1.opus +0 -0
- package/starter/samples/celli/celli_41_3.opus +0 -0
- package/starter/samples/celli/celli_45_1.opus +0 -0
- package/starter/samples/celli/celli_45_3.opus +0 -0
- package/starter/samples/celli/celli_48_1.opus +0 -0
- package/starter/samples/celli/celli_48_3.opus +0 -0
- package/starter/samples/celli/celli_52_1.opus +0 -0
- package/starter/samples/celli/celli_52_3.opus +0 -0
- package/starter/samples/celli/celli_55_1.opus +0 -0
- package/starter/samples/celli/celli_55_3.opus +0 -0
- package/starter/samples/celli/celli_59_1.opus +0 -0
- package/starter/samples/celli/celli_59_3.opus +0 -0
- package/starter/samples/celli/celli_62_1.opus +0 -0
- package/starter/samples/celli/celli_62_3.opus +0 -0
- package/starter/samples/celli/celli_65_1.opus +0 -0
- package/starter/samples/celli/celli_65_3.opus +0 -0
- package/starter/samples/crash/crash_f_1.flac +0 -0
- package/starter/samples/crash/crash_fff_1.flac +0 -0
- package/starter/samples/ebass/ebass_0_x.flac +0 -0
- package/starter/samples/ebass/ebass_10_x.flac +0 -0
- package/starter/samples/ebass/ebass_11_x.flac +0 -0
- package/starter/samples/ebass/ebass_1_x.flac +0 -0
- package/starter/samples/ebass/ebass_2_x.flac +0 -0
- package/starter/samples/ebass/ebass_3_x.flac +0 -0
- package/starter/samples/ebass/ebass_4_x.flac +0 -0
- package/starter/samples/ebass/ebass_5_x.flac +0 -0
- package/starter/samples/ebass/ebass_6_x.flac +0 -0
- package/starter/samples/ebass/ebass_7_x.flac +0 -0
- package/starter/samples/ebass/ebass_8_x.flac +0 -0
- package/starter/samples/ebass/ebass_9_x.flac +0 -0
- package/starter/samples/ek_clap/ek_clap_1_1.flac +0 -0
- package/starter/samples/ek_hat/ek_hat_1_1.flac +0 -0
- package/starter/samples/ek_hat/ek_hat_1_2.flac +0 -0
- package/starter/samples/ek_kick/ek_kick_1_1.flac +0 -0
- package/starter/samples/ek_kick/ek_kick_1_2.flac +0 -0
- package/starter/samples/glock/glock_67_x.flac +0 -0
- package/starter/samples/glock/glock_72_x.flac +0 -0
- package/starter/samples/glock/glock_79_x.flac +0 -0
- package/starter/samples/glock/glock_84_x.flac +0 -0
- package/starter/samples/glock/glock_91_x.flac +0 -0
- package/starter/samples/glock/glock_96_x.flac +0 -0
- package/starter/samples/harp/harp_101_f.opus +0 -0
- package/starter/samples/harp/harp_28_f.opus +0 -0
- package/starter/samples/harp/harp_31_mp.opus +0 -0
- package/starter/samples/harp/harp_35_mf.opus +0 -0
- package/starter/samples/harp/harp_38_mf.opus +0 -0
- package/starter/samples/harp/harp_41_mf.opus +0 -0
- package/starter/samples/harp/harp_45_mf.opus +0 -0
- package/starter/samples/harp/harp_48_mf.opus +0 -0
- package/starter/samples/harp/harp_52_mf.opus +0 -0
- package/starter/samples/harp/harp_55_mf.opus +0 -0
- package/starter/samples/harp/harp_59_mf.opus +0 -0
- package/starter/samples/harp/harp_62_mf.opus +0 -0
- package/starter/samples/harp/harp_65_mf.opus +0 -0
- package/starter/samples/harp/harp_69_mf.opus +0 -0
- package/starter/samples/harp/harp_72_mf.opus +0 -0
- package/starter/samples/harp/harp_76_mf.opus +0 -0
- package/starter/samples/harp/harp_79_mf.opus +0 -0
- package/starter/samples/harp/harp_83_mf.opus +0 -0
- package/starter/samples/harp/harp_86_mf.opus +0 -0
- package/starter/samples/harp/harp_89_mf.opus +0 -0
- package/starter/samples/harp/harp_93_mf.opus +0 -0
- package/starter/samples/harp/harp_95_mf.opus +0 -0
- package/starter/samples/harp/harp_98_f.opus +0 -0
- package/starter/samples/manifest.json +2951 -0
- package/starter/samples/marimba/marimba_29_x.flac +0 -0
- package/starter/samples/marimba/marimba_36_x.flac +0 -0
- package/starter/samples/marimba/marimba_43_x.flac +0 -0
- package/starter/samples/marimba/marimba_47_x.flac +0 -0
- package/starter/samples/marimba/marimba_53_x.flac +0 -0
- package/starter/samples/marimba/marimba_60_x.flac +0 -0
- package/starter/samples/marimba/marimba_67_x.flac +0 -0
- package/starter/samples/marimba/marimba_71_x.flac +0 -0
- package/starter/samples/marimba/marimba_77_x.flac +0 -0
- package/starter/samples/marimba/marimba_84_x.flac +0 -0
- package/starter/samples/piano/piano_102_12.opus +0 -0
- package/starter/samples/piano/piano_102_16.opus +0 -0
- package/starter/samples/piano/piano_102_4.opus +0 -0
- package/starter/samples/piano/piano_102_8.opus +0 -0
- package/starter/samples/piano/piano_105_12.opus +0 -0
- package/starter/samples/piano/piano_105_16.opus +0 -0
- package/starter/samples/piano/piano_105_4.opus +0 -0
- package/starter/samples/piano/piano_105_8.opus +0 -0
- package/starter/samples/piano/piano_108_12.opus +0 -0
- package/starter/samples/piano/piano_108_16.opus +0 -0
- package/starter/samples/piano/piano_108_4.opus +0 -0
- package/starter/samples/piano/piano_108_8.opus +0 -0
- package/starter/samples/piano/piano_21_12.opus +0 -0
- package/starter/samples/piano/piano_21_16.opus +0 -0
- package/starter/samples/piano/piano_21_4.opus +0 -0
- package/starter/samples/piano/piano_21_8.opus +0 -0
- package/starter/samples/piano/piano_24_12.opus +0 -0
- package/starter/samples/piano/piano_24_16.opus +0 -0
- package/starter/samples/piano/piano_24_4.opus +0 -0
- package/starter/samples/piano/piano_24_8.opus +0 -0
- package/starter/samples/piano/piano_27_12.opus +0 -0
- package/starter/samples/piano/piano_27_16.opus +0 -0
- package/starter/samples/piano/piano_27_4.opus +0 -0
- package/starter/samples/piano/piano_27_8.opus +0 -0
- package/starter/samples/piano/piano_30_12.opus +0 -0
- package/starter/samples/piano/piano_30_16.opus +0 -0
- package/starter/samples/piano/piano_30_4.opus +0 -0
- package/starter/samples/piano/piano_30_8.opus +0 -0
- package/starter/samples/piano/piano_33_12.opus +0 -0
- package/starter/samples/piano/piano_33_16.opus +0 -0
- package/starter/samples/piano/piano_33_4.opus +0 -0
- package/starter/samples/piano/piano_33_8.opus +0 -0
- package/starter/samples/piano/piano_36_12.opus +0 -0
- package/starter/samples/piano/piano_36_16.opus +0 -0
- package/starter/samples/piano/piano_36_4.opus +0 -0
- package/starter/samples/piano/piano_36_8.opus +0 -0
- package/starter/samples/piano/piano_39_12.opus +0 -0
- package/starter/samples/piano/piano_39_16.opus +0 -0
- package/starter/samples/piano/piano_39_4.opus +0 -0
- package/starter/samples/piano/piano_39_8.opus +0 -0
- package/starter/samples/piano/piano_42_12.opus +0 -0
- package/starter/samples/piano/piano_42_16.opus +0 -0
- package/starter/samples/piano/piano_42_4.opus +0 -0
- package/starter/samples/piano/piano_42_8.opus +0 -0
- package/starter/samples/piano/piano_45_12.opus +0 -0
- package/starter/samples/piano/piano_45_16.opus +0 -0
- package/starter/samples/piano/piano_45_4.opus +0 -0
- package/starter/samples/piano/piano_45_8.opus +0 -0
- package/starter/samples/piano/piano_48_12.opus +0 -0
- package/starter/samples/piano/piano_48_16.opus +0 -0
- package/starter/samples/piano/piano_48_4.opus +0 -0
- package/starter/samples/piano/piano_48_8.opus +0 -0
- package/starter/samples/piano/piano_51_12.opus +0 -0
- package/starter/samples/piano/piano_51_16.opus +0 -0
- package/starter/samples/piano/piano_51_4.opus +0 -0
- package/starter/samples/piano/piano_51_8.opus +0 -0
- package/starter/samples/piano/piano_54_12.opus +0 -0
- package/starter/samples/piano/piano_54_16.opus +0 -0
- package/starter/samples/piano/piano_54_4.opus +0 -0
- package/starter/samples/piano/piano_54_8.opus +0 -0
- package/starter/samples/piano/piano_57_12.opus +0 -0
- package/starter/samples/piano/piano_57_16.opus +0 -0
- package/starter/samples/piano/piano_57_4.opus +0 -0
- package/starter/samples/piano/piano_57_8.opus +0 -0
- package/starter/samples/piano/piano_60_12.opus +0 -0
- package/starter/samples/piano/piano_60_16.opus +0 -0
- package/starter/samples/piano/piano_60_4.opus +0 -0
- package/starter/samples/piano/piano_60_8.opus +0 -0
- package/starter/samples/piano/piano_63_12.opus +0 -0
- package/starter/samples/piano/piano_63_16.opus +0 -0
- package/starter/samples/piano/piano_63_4.opus +0 -0
- package/starter/samples/piano/piano_63_8.opus +0 -0
- package/starter/samples/piano/piano_66_12.opus +0 -0
- package/starter/samples/piano/piano_66_16.opus +0 -0
- package/starter/samples/piano/piano_66_4.opus +0 -0
- package/starter/samples/piano/piano_66_8.opus +0 -0
- package/starter/samples/piano/piano_69_12.opus +0 -0
- package/starter/samples/piano/piano_69_16.opus +0 -0
- package/starter/samples/piano/piano_69_4.opus +0 -0
- package/starter/samples/piano/piano_69_8.opus +0 -0
- package/starter/samples/piano/piano_72_12.opus +0 -0
- package/starter/samples/piano/piano_72_16.opus +0 -0
- package/starter/samples/piano/piano_72_4.opus +0 -0
- package/starter/samples/piano/piano_72_8.opus +0 -0
- package/starter/samples/piano/piano_75_12.opus +0 -0
- package/starter/samples/piano/piano_75_16.opus +0 -0
- package/starter/samples/piano/piano_75_4.opus +0 -0
- package/starter/samples/piano/piano_75_8.opus +0 -0
- package/starter/samples/piano/piano_78_12.opus +0 -0
- package/starter/samples/piano/piano_78_16.opus +0 -0
- package/starter/samples/piano/piano_78_4.opus +0 -0
- package/starter/samples/piano/piano_78_8.opus +0 -0
- package/starter/samples/piano/piano_81_12.opus +0 -0
- package/starter/samples/piano/piano_81_16.opus +0 -0
- package/starter/samples/piano/piano_81_4.opus +0 -0
- package/starter/samples/piano/piano_81_8.opus +0 -0
- package/starter/samples/piano/piano_84_12.opus +0 -0
- package/starter/samples/piano/piano_84_16.opus +0 -0
- package/starter/samples/piano/piano_84_4.opus +0 -0
- package/starter/samples/piano/piano_84_8.opus +0 -0
- package/starter/samples/piano/piano_87_12.opus +0 -0
- package/starter/samples/piano/piano_87_16.opus +0 -0
- package/starter/samples/piano/piano_87_4.opus +0 -0
- package/starter/samples/piano/piano_87_8.opus +0 -0
- package/starter/samples/piano/piano_90_12.opus +0 -0
- package/starter/samples/piano/piano_90_16.opus +0 -0
- package/starter/samples/piano/piano_90_4.opus +0 -0
- package/starter/samples/piano/piano_90_8.opus +0 -0
- package/starter/samples/piano/piano_93_12.opus +0 -0
- package/starter/samples/piano/piano_93_16.opus +0 -0
- package/starter/samples/piano/piano_93_4.opus +0 -0
- package/starter/samples/piano/piano_93_8.opus +0 -0
- package/starter/samples/piano/piano_96_12.opus +0 -0
- package/starter/samples/piano/piano_96_16.opus +0 -0
- package/starter/samples/piano/piano_96_4.opus +0 -0
- package/starter/samples/piano/piano_96_8.opus +0 -0
- package/starter/samples/piano/piano_99_12.opus +0 -0
- package/starter/samples/piano/piano_99_16.opus +0 -0
- package/starter/samples/piano/piano_99_4.opus +0 -0
- package/starter/samples/piano/piano_99_8.opus +0 -0
- package/starter/samples/piano/piano_rel_102_x.opus +0 -0
- package/starter/samples/piano/piano_rel_105_x.opus +0 -0
- package/starter/samples/piano/piano_rel_108_x.opus +0 -0
- package/starter/samples/piano/piano_rel_21_x.opus +0 -0
- package/starter/samples/piano/piano_rel_24_x.opus +0 -0
- package/starter/samples/piano/piano_rel_27_x.opus +0 -0
- package/starter/samples/piano/piano_rel_30_x.opus +0 -0
- package/starter/samples/piano/piano_rel_33_x.opus +0 -0
- package/starter/samples/piano/piano_rel_36_x.opus +0 -0
- package/starter/samples/piano/piano_rel_39_x.opus +0 -0
- package/starter/samples/piano/piano_rel_42_x.opus +0 -0
- package/starter/samples/piano/piano_rel_45_x.opus +0 -0
- package/starter/samples/piano/piano_rel_48_x.opus +0 -0
- package/starter/samples/piano/piano_rel_51_x.opus +0 -0
- package/starter/samples/piano/piano_rel_54_x.opus +0 -0
- package/starter/samples/piano/piano_rel_57_x.opus +0 -0
- package/starter/samples/piano/piano_rel_60_x.opus +0 -0
- package/starter/samples/piano/piano_rel_63_x.opus +0 -0
- package/starter/samples/piano/piano_rel_66_x.opus +0 -0
- package/starter/samples/piano/piano_rel_69_x.opus +0 -0
- package/starter/samples/piano/piano_rel_72_x.opus +0 -0
- package/starter/samples/piano/piano_rel_75_x.opus +0 -0
- package/starter/samples/piano/piano_rel_78_x.opus +0 -0
- package/starter/samples/piano/piano_rel_81_x.opus +0 -0
- package/starter/samples/piano/piano_rel_84_x.opus +0 -0
- package/starter/samples/piano/piano_rel_87_x.opus +0 -0
- package/starter/samples/piano/piano_rel_90_x.opus +0 -0
- package/starter/samples/piano/piano_rel_93_x.opus +0 -0
- package/starter/samples/piano/piano_rel_96_x.opus +0 -0
- package/starter/samples/piano/piano_rel_99_x.opus +0 -0
- package/starter/samples/pizz/pizz_24_2.flac +0 -0
- package/starter/samples/pizz/pizz_28_2.flac +0 -0
- package/starter/samples/pizz/pizz_31_2.flac +0 -0
- package/starter/samples/pizz/pizz_35_2.flac +0 -0
- package/starter/samples/pizz/pizz_38_2.flac +0 -0
- package/starter/samples/pizz/pizz_41_2.flac +0 -0
- package/starter/samples/pizz/pizz_45_2.flac +0 -0
- package/starter/samples/pizz/pizz_48_2.flac +0 -0
- package/starter/samples/pizz/pizz_52_2.flac +0 -0
- package/starter/samples/pizz/pizz_57_2.flac +0 -0
- package/starter/samples/pizz/pizz_60_2.flac +0 -0
- package/starter/samples/pizz/pizz_64_2.flac +0 -0
- package/starter/samples/pizz/pizz_67_2.flac +0 -0
- package/starter/samples/pizz/pizz_71_2.flac +0 -0
- package/starter/samples/pizz/pizz_74_2.flac +0 -0
- package/starter/samples/pk_hat/pk_hat_2_1.flac +0 -0
- package/starter/samples/pk_hat/pk_hat_2_2.flac +0 -0
- package/starter/samples/pk_hat/pk_hat_6_1.flac +0 -0
- package/starter/samples/pk_hat/pk_hat_6_2.flac +0 -0
- package/starter/samples/pk_kick/pk_kick_3_1.flac +0 -0
- package/starter/samples/pk_kick/pk_kick_3_2.flac +0 -0
- package/starter/samples/pk_kick/pk_kick_7_1.flac +0 -0
- package/starter/samples/pk_kick/pk_kick_7_2.flac +0 -0
- package/starter/samples/pk_ohat/pk_ohat_3_1.flac +0 -0
- package/starter/samples/pk_ohat/pk_ohat_3_2.flac +0 -0
- package/starter/samples/pk_ohat/pk_ohat_6_1.flac +0 -0
- package/starter/samples/pk_ohat/pk_ohat_6_2.flac +0 -0
- package/starter/samples/pk_rim/pk_rim_2_1.flac +0 -0
- package/starter/samples/pk_rim/pk_rim_2_2.flac +0 -0
- package/starter/samples/pk_rim/pk_rim_5_1.flac +0 -0
- package/starter/samples/pk_rim/pk_rim_5_2.flac +0 -0
- package/starter/samples/pk_snare/pk_snare_3_1.flac +0 -0
- package/starter/samples/pk_snare/pk_snare_3_2.flac +0 -0
- package/starter/samples/pk_snare/pk_snare_7_1.flac +0 -0
- package/starter/samples/pk_snare/pk_snare_7_2.flac +0 -0
- package/starter/samples/shaker/shaker_1_1.flac +0 -0
- package/starter/samples/shaker/shaker_2_1.flac +0 -0
- package/starter/samples/snap/snap_r_1.flac +0 -0
- package/starter/samples/snap/snap_r_2.flac +0 -0
- package/starter/samples/snap/snap_r_3.flac +0 -0
- package/starter/samples/snap/snap_r_4.flac +0 -0
- package/starter/samples/snap/snap_r_5.flac +0 -0
- package/starter/samples/snap/snap_r_6.flac +0 -0
- package/starter/samples/tom/tom_3_1.flac +0 -0
- package/starter/samples/tom/tom_3_2.flac +0 -0
- package/starter/samples/tom/tom_4_1.flac +0 -0
- package/starter/samples/tom/tom_4_2.flac +0 -0
- package/starter/samples/vibes/vibes_41_1.opus +0 -0
- package/starter/samples/vibes/vibes_41_2.opus +0 -0
- package/starter/samples/vibes/vibes_45_1.opus +0 -0
- package/starter/samples/vibes/vibes_45_2.opus +0 -0
- package/starter/samples/vibes/vibes_48_1.opus +0 -0
- package/starter/samples/vibes/vibes_48_2.opus +0 -0
- package/starter/samples/vibes/vibes_52_1.opus +0 -0
- package/starter/samples/vibes/vibes_52_2.opus +0 -0
- package/starter/samples/vibes/vibes_55_1.opus +0 -0
- package/starter/samples/vibes/vibes_55_2.opus +0 -0
- package/starter/samples/vibes/vibes_59_1.opus +0 -0
- package/starter/samples/vibes/vibes_59_2.opus +0 -0
- package/starter/samples/vibes/vibes_62_1.opus +0 -0
- package/starter/samples/vibes/vibes_62_2.opus +0 -0
- package/starter/samples/vibes/vibes_65_1.opus +0 -0
- package/starter/samples/vibes/vibes_65_2.opus +0 -0
- package/starter/samples/vibes/vibes_69_1.opus +0 -0
- package/starter/samples/vibes/vibes_69_2.opus +0 -0
- package/starter/samples/vibes/vibes_72_1.opus +0 -0
- package/starter/samples/vibes/vibes_72_2.opus +0 -0
- package/starter/samples/vibes/vibes_76_1.opus +0 -0
- package/starter/samples/vibes/vibes_76_2.opus +0 -0
- package/starter/samples/violas/violas_36_1.opus +0 -0
- package/starter/samples/violas/violas_36_2.opus +0 -0
- package/starter/samples/violas/violas_38_1.opus +0 -0
- package/starter/samples/violas/violas_38_2.opus +0 -0
- package/starter/samples/violas/violas_40_1.opus +0 -0
- package/starter/samples/violas/violas_40_2.opus +0 -0
- package/starter/samples/violas/violas_43_1.opus +0 -0
- package/starter/samples/violas/violas_43_2.opus +0 -0
- package/starter/samples/violas/violas_47_1.opus +0 -0
- package/starter/samples/violas/violas_47_2.opus +0 -0
- package/starter/samples/violas/violas_50_1.opus +0 -0
- package/starter/samples/violas/violas_50_2.opus +0 -0
- package/starter/samples/violas/violas_53_1.opus +0 -0
- package/starter/samples/violas/violas_53_2.opus +0 -0
- package/starter/samples/violas/violas_57_1.opus +0 -0
- package/starter/samples/violas/violas_57_2.opus +0 -0
- package/starter/samples/violas/violas_60_1.opus +0 -0
- package/starter/samples/violas/violas_60_2.opus +0 -0
- package/starter/samples/violas/violas_64_1.opus +0 -0
- package/starter/samples/violas/violas_64_2.opus +0 -0
- package/starter/samples/violas/violas_67_1.opus +0 -0
- package/starter/samples/violas/violas_67_2.opus +0 -0
- package/starter/samples/violas/violas_71_1.opus +0 -0
- package/starter/samples/violas/violas_71_2.opus +0 -0
- package/starter/samples/violas/violas_74_1.opus +0 -0
- package/starter/samples/violas/violas_74_2.opus +0 -0
- package/starter/samples/violins/violins_43_1.opus +0 -0
- package/starter/samples/violins/violins_43_2.opus +0 -0
- package/starter/samples/violins/violins_45_1.opus +0 -0
- package/starter/samples/violins/violins_45_2.opus +0 -0
- package/starter/samples/violins/violins_47_1.opus +0 -0
- package/starter/samples/violins/violins_47_2.opus +0 -0
- package/starter/samples/violins/violins_50_1.opus +0 -0
- package/starter/samples/violins/violins_50_2.opus +0 -0
- package/starter/samples/violins/violins_54_1.opus +0 -0
- package/starter/samples/violins/violins_54_2.opus +0 -0
- package/starter/samples/violins/violins_57_1.opus +0 -0
- package/starter/samples/violins/violins_57_2.opus +0 -0
- package/starter/samples/violins/violins_60_1.opus +0 -0
- package/starter/samples/violins/violins_60_2.opus +0 -0
- package/starter/samples/violins/violins_64_1.opus +0 -0
- package/starter/samples/violins/violins_64_2.opus +0 -0
- package/starter/samples/violins/violins_67_1.opus +0 -0
- package/starter/samples/violins/violins_67_2.opus +0 -0
- package/starter/samples/violins/violins_71_1.opus +0 -0
- package/starter/samples/violins/violins_71_2.opus +0 -0
- package/starter/samples/violins/violins_74_1.opus +0 -0
- package/starter/samples/violins/violins_74_2.opus +0 -0
- package/starter/samples/woodblock/woodblock_f_1.flac +0 -0
- package/starter/samples/woodblock/woodblock_f_2.flac +0 -0
|
@@ -0,0 +1,1227 @@
|
|
|
1
|
+
// space.js — a 3D stage for a film page, on three.js: the product's live
|
|
2
|
+
// interface as windows floating in depth over a backdrop, a lens that travels
|
|
3
|
+
// between them with real depth of field, and a cut to a lit object. For the
|
|
4
|
+
// shots of a launch film that tilt, fly through or focus — most "3D" in those
|
|
5
|
+
// films is flat layers scaled apart (anim.js and a 2D camera do that, cheaper
|
|
6
|
+
// and sharper); reach for this when the lens itself has to move in space or
|
|
7
|
+
// the focus has to fall off with distance.
|
|
8
|
+
//
|
|
9
|
+
// Measured on six launch films and tried under `film render`: a window is a
|
|
10
|
+
// live element of the page drawn into WebGL through Chrome's HTML-in-Canvas
|
|
11
|
+
// (its text is typed, its strokes drawn, frame by frame), the lens is a thin
|
|
12
|
+
// lens and a 180° shutter, and one loop of N samples gives depth of field,
|
|
13
|
+
// motion blur and anti-aliasing together — the same t gives the same pixels.
|
|
14
|
+
//
|
|
15
|
+
// import * as THREE from "./kit/three.module.min.js";
|
|
16
|
+
// import { space, riseIn } from "./lib/space.js";
|
|
17
|
+
// const st = space({ three: THREE, canvas: document.querySelector("#gl") });
|
|
18
|
+
// const prompt = st.slab(document.querySelector("#prompt"), { scale: 3 });
|
|
19
|
+
// st.slab(document.querySelector("#board"), { layer: "far", pos: [-700, 220, 80], ry: 15, move: riseIn(3.0) });
|
|
20
|
+
// st.backdrop(myTexture);
|
|
21
|
+
// st.shots([
|
|
22
|
+
// { start: 0, dur: 2.6, from: { pos: [0, 0, 900] }, to: { pos: [0, 0, 860] }, focus: [0, 0, 0], aperture: 13 },
|
|
23
|
+
// { start: 2.6, dur: 2, to: { pos: [-150, 30, 2050], at: [-40, 10, -260] }, ease: "inOut3", aperture: 30 },
|
|
24
|
+
// ]);
|
|
25
|
+
// window.__film = st.film({ duration: 10 }); // before any await: ready, motion, cuts
|
|
26
|
+
// window.__render = async (t) => { setTheDom(t); await st.draw(t); };
|
|
27
|
+
//
|
|
28
|
+
// space(o) the stage: o.three, o.canvas (`<canvas layoutsubtree content="drawable">`
|
|
29
|
+
// with the slabs' elements inside it, each `<div drawable>`: Chrome
|
|
30
|
+
// builds have read either attribute, so carry both), o.width/height
|
|
31
|
+
// (1920×1080), o.samples (draft 8, master 32), o.shutter (0.5 of a
|
|
32
|
+
// frame: 180°; 0 leaves the blur to `film render`)
|
|
33
|
+
// st.scene(name, o) a scene, made or changed ("main" is there; one is drawn at a time, a
|
|
34
|
+
// shot names it): o.clear — its ground colour: 0x…, "#…", a THREE.Color,
|
|
35
|
+
// or (t) => one of those, so it changes over the film with no call
|
|
36
|
+
// from __render — o.update(t, pose), o.finish (solid.js `finish`: bloom
|
|
37
|
+
// and a grade), o.environment. It gives back the scene:
|
|
38
|
+
// .add(obj, layer?) a three object into a layer ("hero") — or one of solid.js's ready
|
|
39
|
+
// objects (a laptop, a desk): its `tick` then runs with the scene
|
|
40
|
+
// .animate((t, at) => …) what its objects are at t: run at every sample's time, as o.update is
|
|
41
|
+
// .clearAt(t), .three, .layer(name), .watch(obj)
|
|
42
|
+
// st.layer(name, scene?) a group: backdrop (z −1900), far (−600), hero (0), near (+190)
|
|
43
|
+
// st.slab(el, o) a live element as a window in depth: o.pos [x,y,z] in its layer
|
|
44
|
+
// (CSS px, y up), o.rx/ry/rz (°), o.scale (texture px per CSS px;
|
|
45
|
+
// ≥ the most it is magnified on screen, 3 for a close-up),
|
|
46
|
+
// o.shadow, o.parent (another slab, or any three object — a lid, a
|
|
47
|
+
// THREE.Group you turn: it rides on it, in its scene),
|
|
48
|
+
// o.move(t) → { x, y, z, rx, ry, rz, scale, opacity } from its home,
|
|
49
|
+
// o.picture (an image used where HTML-in-Canvas is missing). It gives
|
|
50
|
+
// back the slab:
|
|
51
|
+
// .point(x, y, t) a point of the element (its own CSS px, from its top-left) in the
|
|
52
|
+
// space at t — right before the first draw too, on a lid at any angle
|
|
53
|
+
// .toFrame(x, y, t) the same point in the frame, px: where to pin a label, a cursor
|
|
54
|
+
// .station(rect, o) the lens that frames a part of it (rect in its CSS px; o.share of
|
|
55
|
+
// the frame's width, o.yaw/o.pitch off square on): a shot's `to`
|
|
56
|
+
// .group, .mesh, .el, .width, .height
|
|
57
|
+
// st.backdrop(tex, o) a plane behind everything, big enough for a wide lens
|
|
58
|
+
// st.nearLens(o) something passing near the lens: a soft card placed from the lens
|
|
59
|
+
// st.shots([...]) the lens: shots in time (see `rig`); a shot with `cut: true` or
|
|
60
|
+
// another `scene` starts on a hard cut, which no shutter crosses.
|
|
61
|
+
// Three kinds move as lib/moves.js moves a 2D camera, on its maths:
|
|
62
|
+
// { stations: [{ t, to }, …] } (quick to leave, long to slow, never at
|
|
63
|
+
// rest), { momentum: "up", … } (starts on a momentumCut) and
|
|
64
|
+
// { jump: t, to } (a rampJump) — a 3D stretch and a 2.5D one of the
|
|
65
|
+
// same film are timed alike
|
|
66
|
+
// It gives back the lens: `.pose(t)` is where it is, and `.pose(t).shot`
|
|
67
|
+
// the index of the shot t is in — a momentum cut falls between two
|
|
68
|
+
// frames, half a frame before its shot's start, so ask that, not t
|
|
69
|
+
// st.draw(t) the frame at t: textures of what changed, then N samples
|
|
70
|
+
// st.toFrame(p, t) a point of the space in the frame (px), for a label pinned to it —
|
|
71
|
+
// a slab's own point: slab.toFrame(x, y, t)
|
|
72
|
+
// st.travel(t, half) how far the picture moves across [t−half, t+half], px
|
|
73
|
+
// st.film(o) window.__film: { duration, ready, motion, events } — motion is the
|
|
74
|
+
// stage's travel() when o.shutter is 0, else 0, the stage blurring
|
|
75
|
+
// itself; the render measures the DOM outside the canvas on its own
|
|
76
|
+
// and takes the larger, and each draw exposes the share of the
|
|
77
|
+
// shutter the render gives it (window.__filmShare)
|
|
78
|
+
// st.events() the cuts, as { t, kind } for the events file ("cut"; a jump's,
|
|
79
|
+
// "hidden-cut") — st.film() hands them on
|
|
80
|
+
// riseIn(t0, o), float(…) a slab's `move`: rising into place from behind; a slow float
|
|
81
|
+
// eases a shot's eases (fly, station, …); any name lib/anim.js knows works too
|
|
82
|
+
//
|
|
83
|
+
// Text up close: a window's texture is drawn once at o.scale times its CSS
|
|
84
|
+
// size (HTML-in-Canvas rasterises at that size, it does not stretch a 1×
|
|
85
|
+
// picture), and while a window is shown at more than half its texture's
|
|
86
|
+
// pixels the texture is read from its full-size level only — blending in the
|
|
87
|
+
// smaller mip levels is what softened text most (stroke edge 2.15 px against
|
|
88
|
+
// 1.50 px for the same text as DOM; 1.64 px with the full level only).
|
|
89
|
+
//
|
|
90
|
+
// Blur that outruns the samples: N samples of a disk or a smear tens of px
|
|
91
|
+
// wide land px apart, and a sharp texture drawn N times shows N copies. So
|
|
92
|
+
// each frame a slab's texture is read no finer than the mip level blurred by
|
|
93
|
+
// the gap between its copies (`sampleGap`, from its depth against the focus
|
|
94
|
+
// and its travel across the shutter): defocused or fast text smears into one
|
|
95
|
+
// piece. A slab's outline is not softened that way; what passes near the lens
|
|
96
|
+
// gets a pre-blurred soft edge (`softCard`), as nearLens does.
|
|
97
|
+
//
|
|
98
|
+
// What changes over the film is a function of t the stage calls, not a value
|
|
99
|
+
// __render sets: a frame is N samples at N times across the shutter, and the
|
|
100
|
+
// stage places everything again for each. A lid's angle, a light, a colour
|
|
101
|
+
// written from __render(t) is the same in all N — a lid that shuts in 0.3 s
|
|
102
|
+
// then has no blur and the lens does. So: a slab's `move`, a scene's `update`
|
|
103
|
+
// or `.animate`, a ready object's own `open`/`look`, a scene's `clear` as a
|
|
104
|
+
// function. The same holds for slab.point and toFrame: they put the scene as
|
|
105
|
+
// it is at the t they are asked for, so they need no draw first.
|
|
106
|
+
//
|
|
107
|
+
// const main = st.scene("main", { clear: (t) => (t < 15 ? 0x2a211b : 0xe9dfcf) });
|
|
108
|
+
// const lid = new THREE.Group(); main.add(lid);
|
|
109
|
+
// const screen = st.slab(appEl, { parent: lid, shadow: false });
|
|
110
|
+
// main.animate((t) => { lid.rotation.x = -keys(t, [[3, 105], [3.3, 0, "in2"]]) * Math.PI / 180; });
|
|
111
|
+
// const row = screen.station(rectOf(rowEl), { share: 0.6, yaw: -8 }); // a lens on a part of it
|
|
112
|
+
// st.shots([{ start: 0, stations: [{ t: 0, to: screen.station() }, { t: 1.2, to: row }] },
|
|
113
|
+
// { start: 4, dur: 2, momentum: "up", from: wide, to: wide2 }, { jump: 7, to: row }]);
|
|
114
|
+
// label.style.transform = `translate(${screen.toFrame(40, 20, t).join("px,")}px)`;
|
|
115
|
+
// (lib/solid.js has the laptop and the desk ready: `main.add(S.laptop({ open: (t) => … }))`.)
|
|
116
|
+
//
|
|
117
|
+
// Costs, Apple M5 at 1080p: 32 samples 14–30 ms a frame on the GPU; a draft
|
|
118
|
+
// (960×540, 8 samples) about 76 ms a frame through `film render`.
|
|
119
|
+
//
|
|
120
|
+
// Pure functions of t, no clock: `rig`, `handheld`, eases, `shutterTimes`
|
|
121
|
+
// and `cutsOf` also work without three, for planning and tests. Its eases
|
|
122
|
+
// and clamp are lib/anim.js's and its stations, momentum cut and jump
|
|
123
|
+
// lib/moves.js's, which sit beside it.
|
|
124
|
+
|
|
125
|
+
import { bezier, clamp, ease, named } from "./anim.js";
|
|
126
|
+
import { momentumCut, rampJump, stations } from "./moves.js";
|
|
127
|
+
|
|
128
|
+
/** @typedef {[number, number, number]} V3 */
|
|
129
|
+
/** @typedef {(u: number) => number} Ease */
|
|
130
|
+
/**
|
|
131
|
+
* @typedef {object} Pose a lens: where it is, what it looks at, its lens
|
|
132
|
+
* @property {V3} [pos] @property {V3} [at] @property {number} [fov] vertical, degrees @property {number} [roll] degrees
|
|
133
|
+
*/
|
|
134
|
+
/**
|
|
135
|
+
* @typedef {object} Shot
|
|
136
|
+
* @property {number} [start] s (a `jump` shot: 14/24 s before its jump unless given)
|
|
137
|
+
* @property {number} [dur] s (a `jump` shot: 20/24; a `stations` shot needs none — it runs until the next shot)
|
|
138
|
+
* @property {Pose} [from] where the lens starts (default: where the last shot ended, or was when this one starts)
|
|
139
|
+
* @property {Pose} [to] where it ends (a `stations` shot: its last station)
|
|
140
|
+
* @property {{ t: number, to: Pose, accel?: number, decay?: number, settle?: number, creep?: number }[]} [stations] the
|
|
141
|
+
* lens from station to station as lib/moves.js `stations` moves a 2D camera: each leg leaves for its `to` at
|
|
142
|
+
* its t, quick to leave, eleven frames of 24 to slow, then creeping on until the next leaves
|
|
143
|
+
* @property {number} [accel] a `stations` shot: s each leg speeds up over (5.5/24)
|
|
144
|
+
* @property {number} [decay] a `stations` shot: the share of its speed a leg keeps every 1/24 s at first (0.73)
|
|
145
|
+
* @property {number} [settle] a `stations` shot: s from a leg's fastest frame to its creep (11/24)
|
|
146
|
+
* @property {number} [creep] a `stations` shot: the share of a leg left to the drift after it lands (0.02)
|
|
147
|
+
* @property {true | "up" | "down" | "left" | "right" | { dir?: "up" | "down" | "left" | "right" | V3, out?: number, in?: number,
|
|
148
|
+
* outDur?: number, inDur?: number, leave?: Ease | string, resume?: Ease | string }} [momentum]
|
|
149
|
+
* it starts on lib/moves.js's `momentumCut`: the shot before leaves faster every frame, the cut on its
|
|
150
|
+
* fastest, this one carrying on the same way and slowing into its place
|
|
151
|
+
* @property {number} [jump] s: the shot is lib/moves.js's `rampJump` from `from` to `to` — speeding up for
|
|
152
|
+
* 14/24 s, one frame's jump at this time, 6/24 s settling
|
|
153
|
+
* @property {V3[]} [via] points the path passes through on the way
|
|
154
|
+
* @property {Ease | string} [ease] default "inOut3"
|
|
155
|
+
* @property {number | V3 | ((t: number) => number | V3) | { from: V3, to: V3, start: number, dur: number, ease?: Ease | string }} [focus]
|
|
156
|
+
* a distance, a point kept sharp, a function of t, or a pull from one point to another (default: the `at` point)
|
|
157
|
+
* @property {number | ((t: number) => number)} [aperture] the lens's radius in scene units (0: all sharp)
|
|
158
|
+
* @property {number | ((t: number) => { yaw: number, pitch: number, roll: number })} [handheld] amplitude (°) or a handheld()
|
|
159
|
+
* @property {string} [scene] which scene it shows (default "main")
|
|
160
|
+
* @property {boolean} [cut] it starts on a hard cut
|
|
161
|
+
* @property {string} [name]
|
|
162
|
+
*/
|
|
163
|
+
/**
|
|
164
|
+
* @typedef {object} LensAt the lens at t
|
|
165
|
+
* @property {V3} pos @property {V3} at @property {number} fov @property {number} roll
|
|
166
|
+
* @property {number} yaw @property {number} pitch @property {number} focus distance to the plane kept sharp
|
|
167
|
+
* @property {number} aperture @property {string} scene @property {number} shot index of the shot
|
|
168
|
+
*/
|
|
169
|
+
/**
|
|
170
|
+
* @typedef {object} Mark a cut of the lens's own
|
|
171
|
+
* @property {number} t the frame it falls on (s) @property {number} edge where no shutter crosses: t, or half a
|
|
172
|
+
* frame before it for a cut that falls between two frames @property {"cut" | "hidden-cut"} kind
|
|
173
|
+
*/
|
|
174
|
+
|
|
175
|
+
// --- pure: eases, paths, the lens over time ---------------------------------
|
|
176
|
+
|
|
177
|
+
/** @param {number} x */
|
|
178
|
+
const clamp01 = (x) => clamp(x);
|
|
179
|
+
|
|
180
|
+
/** eases by name, for shots: the camera moves of the reels leave gently and
|
|
181
|
+
* land fast then settle ("fly": cubic-bezier(.55,0,.12,1), the spike's
|
|
182
|
+
* fly-to-a-window); "station" accelerates over about a third and settles
|
|
183
|
+
* over two thirds, as stations in long takes did (5–6 frames up, 10–12 down)
|
|
184
|
+
* — but it comes to rest, where the reels' stations never reached zero
|
|
185
|
+
* speed: follow it with a slow drift shot from where it lands
|
|
186
|
+
* @type {Record<string, Ease>} */
|
|
187
|
+
export const eases = {
|
|
188
|
+
linear: (x) => clamp01(x),
|
|
189
|
+
smooth: (x) => { x = clamp01(x); return x * x * (3 - 2 * x); },
|
|
190
|
+
inOut3: (x) => ease.inOut3(clamp01(x)),
|
|
191
|
+
out3: (x) => ease.out3(clamp01(x)),
|
|
192
|
+
in3: (x) => ease.in3(clamp01(x)),
|
|
193
|
+
outExpo: (x) => ease.outExpo(clamp01(x)),
|
|
194
|
+
fly: bezier(0.55, 0, 0.12, 1),
|
|
195
|
+
station: bezier(0.42, 0, 0.18, 1),
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
/** a shot's ease: one of `eases`, any name lib/anim.js knows (its own and GSAP's) or a
|
|
199
|
+
* function, fed the shot's progress held to 0..1 — so an ease that overshoots
|
|
200
|
+
* (back.out) overshoots inside its shot and the lens holds where it ended after it.
|
|
201
|
+
* An unknown name throws here, when the shots are set.
|
|
202
|
+
* @param {Ease | string | undefined} e @returns {Ease} */
|
|
203
|
+
const easeOf = (e) => {
|
|
204
|
+
if (!e) return /** @type {Ease} */ (eases.inOut3);
|
|
205
|
+
const f = typeof e === "function" ? e : (eases[e] ?? named(e));
|
|
206
|
+
return (x) => f(clamp01(x));
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
/** @param {V3} a @param {V3} b @param {number} u @returns {V3} */
|
|
210
|
+
export const lerp3 = (a, b, u) => [a[0] + (b[0] - a[0]) * u, a[1] + (b[1] - a[1]) * u, a[2] + (b[2] - a[2]) * u];
|
|
211
|
+
/** @param {V3} a @param {V3} b */
|
|
212
|
+
const dist3 = (a, b) => Math.hypot(a[0] - b[0], a[1] - b[1], a[2] - b[2]);
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* A point at u (0..1) along a centripetal Catmull-Rom path through `pts`
|
|
216
|
+
* (each stretch between two points an equal share of u, as three's
|
|
217
|
+
* CatmullRomCurve3). Two points: a straight line. A u a little past 0 or 1
|
|
218
|
+
* (an ease that overshoots) carries on along the first or last stretch, as
|
|
219
|
+
* the lens's aim and fov do.
|
|
220
|
+
* @param {V3[]} pts @param {number} u @returns {V3}
|
|
221
|
+
*/
|
|
222
|
+
export function pathAt(pts, u) {
|
|
223
|
+
const n = pts.length;
|
|
224
|
+
if (n === 0) return [0, 0, 0];
|
|
225
|
+
if (n === 1) return /** @type {V3} */ ([...(/** @type {V3} */ (pts[0]))]);
|
|
226
|
+
const f = u * (n - 1);
|
|
227
|
+
const i = Math.max(0, Math.min(n - 2, Math.floor(f)));
|
|
228
|
+
const s = f - i;
|
|
229
|
+
const p1 = /** @type {V3} */ (pts[i]), p2 = /** @type {V3} */ (pts[i + 1]);
|
|
230
|
+
if (n === 2) return lerp3(p1, p2, s);
|
|
231
|
+
// the ends are mirrored, as three does for an open curve
|
|
232
|
+
const p0 = pts[i - 1] ?? lerp3(p1, p2, -1), p3 = pts[i + 2] ?? lerp3(p2, p1, -1);
|
|
233
|
+
const k = (/** @type {V3} */ a, /** @type {V3} */ b) => Math.max(1e-4, Math.sqrt(dist3(a, b)));
|
|
234
|
+
const t0 = 0, t1 = t0 + k(p0, p1), t2 = t1 + k(p1, p2), t3 = t2 + k(p2, p3);
|
|
235
|
+
const t = t1 + (t2 - t1) * s;
|
|
236
|
+
/** @param {V3} a @param {V3} b @param {number} ta @param {number} tb @returns {V3} */
|
|
237
|
+
const mixT = (a, b, ta, tb) => lerp3(a, b, (t - ta) / (tb - ta));
|
|
238
|
+
const a1 = mixT(p0, p1, t0, t1), a2 = mixT(p1, p2, t1, t2), a3 = mixT(p2, p3, t2, t3);
|
|
239
|
+
const b1 = mixT(a1, a2, t0, t2), b2 = mixT(a2, a3, t1, t3);
|
|
240
|
+
return mixT(b1, b2, t1, t2);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Deterministic handheld: sums of sines at incommensurate rates, in degrees,
|
|
245
|
+
* the phases set by `seed` so two shots never shake alike. The amplitudes are
|
|
246
|
+
* chosen by eye, not measured on the reels.
|
|
247
|
+
* @param {number} [amp] degrees (0.12: a lens held still; 0.3: walking)
|
|
248
|
+
* @param {number} [speed] @param {number} [seed]
|
|
249
|
+
*/
|
|
250
|
+
export function handheld(amp = 0.12, speed = 1, seed = 1) {
|
|
251
|
+
const ph = (/** @type {number} */ k) => ((Math.sin(seed * 12.9898 + k * 78.233) * 43758.5453) % 1) * 6.283;
|
|
252
|
+
return (/** @type {number} */ t) => {
|
|
253
|
+
const s = t * speed;
|
|
254
|
+
return {
|
|
255
|
+
yaw: amp * (0.6 * Math.sin(s * 1.31 + ph(1)) + 0.3 * Math.sin(s * 2.73 + ph(2)) + 0.1 * Math.sin(s * 5.9 + ph(3))),
|
|
256
|
+
pitch: amp * (0.6 * Math.sin(s * 1.07 + ph(4)) + 0.3 * Math.sin(s * 2.31 + ph(5)) + 0.1 * Math.sin(s * 6.3 + ph(6))),
|
|
257
|
+
roll: amp * 0.5 * (0.7 * Math.sin(s * 0.83 + ph(7)) + 0.3 * Math.sin(s * 1.9 + ph(8))),
|
|
258
|
+
};
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/** the times hard cuts fall on: a shot with `cut`, or showing another scene than the one before
|
|
263
|
+
* @param {Shot[]} shots @returns {number[]} */
|
|
264
|
+
export function cutsOf(shots) {
|
|
265
|
+
const s = [...shots].sort((a, b) => (a.start ?? 0) - (b.start ?? 0));
|
|
266
|
+
/** @type {number[]} */
|
|
267
|
+
const out = [];
|
|
268
|
+
for (let i = 1; i < s.length; i++) {
|
|
269
|
+
const a = /** @type {Shot} */ (s[i - 1]), b = /** @type {Shot} */ (s[i]);
|
|
270
|
+
if (b.cut || b.momentum || (b.scene ?? "main") !== (a.scene ?? "main")) out.push(b.start ?? 0);
|
|
271
|
+
}
|
|
272
|
+
return out;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// --- the lens's moves, lib/moves.js's own ------------------------------------
|
|
276
|
+
// A 3D shot is driven as a 2.5D layer is: the same functions give the
|
|
277
|
+
// progress, and the lens takes it — so a station, a momentum cut and a ramp
|
|
278
|
+
// jump are timed alike on either side of a film.
|
|
279
|
+
|
|
280
|
+
const POSE_KEYS = /** @type {const} */ (["px", "py", "pz", "ax", "ay", "az", "fov", "roll"]);
|
|
281
|
+
/** a lens as flat numbers, for moves.js `stations` @param {Required<Pose>} p @returns {Record<string, number>} */
|
|
282
|
+
const flatOf = (p) => ({ px: p.pos[0], py: p.pos[1], pz: p.pos[2], ax: p.at[0], ay: p.at[1], az: p.at[2], fov: p.fov, roll: p.roll });
|
|
283
|
+
/** @param {Record<string, number>} c @returns {Required<Pose>} */
|
|
284
|
+
const poseOf = (c) => {
|
|
285
|
+
const [px = 0, py = 0, pz = 0, ax = 0, ay = 0, az = 0, fov = 30, roll = 0] = POSE_KEYS.map((k) => c[k]);
|
|
286
|
+
return { pos: [px, py, pz], at: [ax, ay, az], fov, roll };
|
|
287
|
+
};
|
|
288
|
+
/** the lens's own right and up, from where it is and what it looks at (roll left out)
|
|
289
|
+
* @param {V3} pos @param {V3} at @returns {{ right: V3, up: V3 }} */
|
|
290
|
+
function axesOf(pos, at) {
|
|
291
|
+
const f = [at[0] - pos[0], at[1] - pos[1], at[2] - pos[2]], fl = Math.hypot(f[0] ?? 0, f[1] ?? 0, f[2] ?? 0) || 1;
|
|
292
|
+
const fx = (f[0] ?? 0) / fl, fy = (f[1] ?? 0) / fl, fz = (f[2] ?? 0) / fl;
|
|
293
|
+
// right = forward × world up; looking straight up or down, world x
|
|
294
|
+
let rx = -fz, rz = fx;
|
|
295
|
+
const rl = Math.hypot(rx, rz);
|
|
296
|
+
if (rl < 1e-6) { rx = 1; rz = 0; } else { rx /= rl; rz /= rl; }
|
|
297
|
+
return { right: [rx, 0, rz], up: [-rz * fy, rz * fx - rx * fz, rx * fy] };
|
|
298
|
+
}
|
|
299
|
+
/** how a leg moves, as moves.js `stations` takes it: only what was given
|
|
300
|
+
* @param {{ accel?: number, decay?: number, settle?: number, creep?: number }} o */
|
|
301
|
+
const legOpts = (o) => ({
|
|
302
|
+
...(o.accel != null ? { accel: o.accel } : {}),
|
|
303
|
+
...(o.decay != null ? { decay: o.decay } : {}),
|
|
304
|
+
...(o.settle != null ? { settle: o.settle } : {}),
|
|
305
|
+
...(o.creep != null ? { creep: o.creep } : {}),
|
|
306
|
+
});
|
|
307
|
+
/** the frame a time falls on (moves.js snaps a cut the same way)
|
|
308
|
+
* @param {number} at @param {number} fps */
|
|
309
|
+
const frameAt = (at, fps) => Math.round(at * fps + 1e-9) / fps;
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* The lens through shots, as a function of t. Each shot runs from `from` to
|
|
313
|
+
* `to` (along `via`), eased; before the first shot the lens is at its start,
|
|
314
|
+
* between shots it holds where the last one ended — add a slow drift shot
|
|
315
|
+
* rather than letting it stop: the reels' lens is still for 8–17% of a film.
|
|
316
|
+
*
|
|
317
|
+
* Three kinds of shot move as lib/moves.js moves a 2D camera, on its maths
|
|
318
|
+
* and its measured numbers:
|
|
319
|
+
* { start, stations: [{ t, to }, …] } station to station (`stations`): quick to leave, long to slow,
|
|
320
|
+
* never at rest before the next leg leaves
|
|
321
|
+
* { start, momentum: "up", from, to } starts on a `momentumCut`: the shot before runs out of frame
|
|
322
|
+
* faster every frame, this one carries on and slows. A name is the
|
|
323
|
+
* way the picture travels (as in moves.js; the lens goes the other
|
|
324
|
+
* way, sideways to its aim); a [x, y, z] is the way the lens goes.
|
|
325
|
+
* `out` and `in` are frame px at the depth of the point looked at
|
|
326
|
+
* (128 and 86 of a 1080 frame)
|
|
327
|
+
* { jump: 8.125, to } a `rampJump`: a push that speeds up, jumps in one frame, settles —
|
|
328
|
+
* the lens's distance to `to.at` in log space, as a zoom's scale is
|
|
329
|
+
* A momentum cut and a jump fall between two frames of the film as it is
|
|
330
|
+
* drawn (o.fps, else window.__filmFps, else 60): `marks()` lists them with
|
|
331
|
+
* the plain cuts, `cuts` is where no shutter crosses.
|
|
332
|
+
* @param {Shot[]} shots
|
|
333
|
+
* @param {{ fps?: number | (() => number), height?: number }} [o] height: the frame's, px (1080), for a momentum cut's px
|
|
334
|
+
* @returns {{ pose: (t: number) => LensAt, shots: Shot[], cuts: number[], marks: () => Mark[] }}
|
|
335
|
+
*/
|
|
336
|
+
export function rig(shots, o = {}) {
|
|
337
|
+
const FRAME_H = o.height ?? 1080;
|
|
338
|
+
const fpsNow = () => {
|
|
339
|
+
const f = typeof o.fps === "function" ? o.fps() : (o.fps ?? /** @type {{ __filmFps?: number }} */ (globalThis).__filmFps);
|
|
340
|
+
return typeof f === "number" && f > 0 ? f : 60;
|
|
341
|
+
};
|
|
342
|
+
const s = shots.map((sh) => {
|
|
343
|
+
if (sh.jump == null) return { ...sh, start: sh.start ?? 0, dur: sh.dur ?? 0 };
|
|
344
|
+
return { ...sh, start: sh.start ?? sh.jump - 14 / 24, dur: sh.dur ?? 20 / 24 };
|
|
345
|
+
}).sort((a, b) => a.start - b.start);
|
|
346
|
+
/** @typedef {{ from: Required<Pose>, to: Required<Pose>, pts: V3[], shake: ((t: number) => { yaw: number, pitch: number, roll: number }) | null,
|
|
347
|
+
* shot: typeof s[number], ease: Ease, pull: Ease | null, legs: { t: number, at: Record<string, number>, accel?: number, decay?: number, settle?: number, creep?: number }[] | null,
|
|
348
|
+
* mo: { dir: "up" | "down" | "left" | "right" | V3, out: number, in: number, rest: object } | null }} Prep */
|
|
349
|
+
/** @type {Prep[]} */
|
|
350
|
+
const prep = [];
|
|
351
|
+
/** @type {Required<Pose>} */
|
|
352
|
+
const START = { pos: [0, 0, 1000], at: [0, 0, 0], fov: 30, roll: 0 };
|
|
353
|
+
s.forEach((sh, i) => {
|
|
354
|
+
// from where the last shot ended — a `stations` shot never ends: where it was then
|
|
355
|
+
const before = prep[i - 1];
|
|
356
|
+
const last = !before ? START : before.legs ? plain(before, sh.start) : before.to;
|
|
357
|
+
const from = { ...last, ...(sh.from ?? {}) };
|
|
358
|
+
/** @type {Prep["legs"]} */
|
|
359
|
+
let legs = null;
|
|
360
|
+
let to = { ...from, ...(sh.to ?? {}) };
|
|
361
|
+
if (sh.stations) {
|
|
362
|
+
if (!sh.stations.length) throw new Error("space: a shot's `stations` needs at least one { t, to }");
|
|
363
|
+
let at = from;
|
|
364
|
+
legs = sh.stations.map((st) => {
|
|
365
|
+
at = { ...at, ...st.to };
|
|
366
|
+
return { t: st.t, at: flatOf(at), ...legOpts(st) };
|
|
367
|
+
});
|
|
368
|
+
to = at;
|
|
369
|
+
} else if (!sh.to) throw new Error("space: a shot needs `to` (where the lens ends), or `stations`");
|
|
370
|
+
const hh = sh.handheld;
|
|
371
|
+
const fo = sh.focus;
|
|
372
|
+
const m = sh.momentum;
|
|
373
|
+
const { dir = "up", out = 128, in: inn = 86, ...rest } = m && typeof m === "object" ? m : { dir: typeof m === "string" ? m : undefined };
|
|
374
|
+
prep.push({
|
|
375
|
+
from, to,
|
|
376
|
+
pts: [from.pos, ...(sh.via ?? []), to.pos],
|
|
377
|
+
shake: typeof hh === "function" ? hh : hh ? handheld(hh, 1, i + 1) : null,
|
|
378
|
+
shot: sh,
|
|
379
|
+
ease: easeOf(sh.ease),
|
|
380
|
+
pull: fo && !Array.isArray(fo) && typeof fo === "object" ? easeOf(fo.ease ?? "smooth") : null,
|
|
381
|
+
legs,
|
|
382
|
+
mo: m ? { dir, out, in: inn, rest } : null,
|
|
383
|
+
});
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
/** shot p's lens at t, before any momentum cut moves it @param {Prep} p @param {number} t @returns {Required<Pose>} */
|
|
387
|
+
function plain(p, t) {
|
|
388
|
+
const sh = p.shot;
|
|
389
|
+
if (p.legs) {
|
|
390
|
+
const { leg: _leg, ...c } = stations(t, p.legs, { from: flatOf(p.from), ...legOpts(sh) });
|
|
391
|
+
return poseOf(c);
|
|
392
|
+
}
|
|
393
|
+
let u;
|
|
394
|
+
if (sh.jump != null) {
|
|
395
|
+
// rampJump's progress is the log of a zoom's scale: the lens's distance to what it
|
|
396
|
+
// ends looking at goes the same way, d0 → d1 in log space
|
|
397
|
+
const L = rampJump(t, sh.jump, { fps: fpsNow() }).p;
|
|
398
|
+
const d0 = dist3(p.from.pos, p.to.at), d1 = dist3(p.to.pos, p.to.at);
|
|
399
|
+
u = d0 > 1e-6 && d1 > 1e-6 && Math.abs(d0 - d1) > 1e-6 ? (d0 - d0 * (d1 / d0) ** L) / (d0 - d1) : L;
|
|
400
|
+
} else u = p.ease((t - sh.start) / Math.max(1e-6, sh.dur));
|
|
401
|
+
return {
|
|
402
|
+
pos: pathAt(p.pts, u),
|
|
403
|
+
at: lerp3(p.from.at, p.to.at, u),
|
|
404
|
+
fov: p.from.fov + (p.to.fov - p.from.fov) * u,
|
|
405
|
+
roll: p.from.roll + (p.to.roll - p.from.roll) * u,
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/** the frame a shot's cut falls on, and the half frame before it where its side begins
|
|
410
|
+
* @param {number} at @param {number} fps */
|
|
411
|
+
const between = (at, fps) => { const t = frameAt(at, fps); return { t, edge: t - 0.5 / fps }; };
|
|
412
|
+
/** when shot i takes over @param {number} i @param {number} fps */
|
|
413
|
+
const edgeOf = (i, fps) => {
|
|
414
|
+
const p = /** @type {Prep} */ (prep[i]);
|
|
415
|
+
return i > 0 && p.mo ? between(p.shot.start, fps).edge : p.shot.start;
|
|
416
|
+
};
|
|
417
|
+
|
|
418
|
+
/** how far a momentum cut has carried the lens off its shot's path at t, in the space
|
|
419
|
+
* @param {Prep} p the shot that starts on the cut @param {Required<Pose>} l the lens it moves
|
|
420
|
+
* @param {number} t @param {boolean} leaving l is the shot before @param {number} fps @returns {V3} */
|
|
421
|
+
function carriedBy(p, l, t, leaving, fps) {
|
|
422
|
+
const mo = /** @type {NonNullable<Prep["mo"]>} */ (p.mo);
|
|
423
|
+
// moves.js's own curve, read as shares of `out` and `in`
|
|
424
|
+
const m = momentumCut(t, p.shot.start, { ...mo.rest, dir: "right", out: 1, in: 1, fps });
|
|
425
|
+
const share = leaving ? -m.a.x * mo.out : -m.b.x * mo.in;
|
|
426
|
+
if (!share) return [0, 0, 0];
|
|
427
|
+
const px = (2 * dist3(l.pos, l.at) * Math.tan((l.fov * Math.PI) / 360)) / FRAME_H;
|
|
428
|
+
/** @type {V3} */
|
|
429
|
+
let d;
|
|
430
|
+
if (Array.isArray(mo.dir)) {
|
|
431
|
+
const n = Math.hypot(...mo.dir) || 1;
|
|
432
|
+
d = [-mo.dir[0] / n, -mo.dir[1] / n, -mo.dir[2] / n];
|
|
433
|
+
} else {
|
|
434
|
+
const { right, up } = axesOf(l.pos, l.at);
|
|
435
|
+
d = mo.dir === "up" ? up : mo.dir === "down" ? [-up[0], -up[1], -up[2]] : mo.dir === "left" ? [-right[0], -right[1], -right[2]] : right;
|
|
436
|
+
}
|
|
437
|
+
return [d[0] * share * px, d[1] * share * px, d[2] * share * px];
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/** @param {number} t @returns {LensAt} */
|
|
441
|
+
function pose(t) {
|
|
442
|
+
const fps = fpsNow();
|
|
443
|
+
let k = 0;
|
|
444
|
+
for (let i = 0; i < prep.length; i++) if (t >= edgeOf(i, fps)) k = i;
|
|
445
|
+
const p = prep[k];
|
|
446
|
+
if (!p) return { pos: [0, 0, 1000], at: [0, 0, 0], fov: 30, roll: 0, yaw: 0, pitch: 0, focus: 1000, aperture: 0, scene: "main", shot: 0 };
|
|
447
|
+
const sh = p.shot;
|
|
448
|
+
const l = plain(p, t);
|
|
449
|
+
let { pos, at } = l;
|
|
450
|
+
const { fov, roll } = l;
|
|
451
|
+
// a momentum cut: this shot still landing from one, or leaving into the next
|
|
452
|
+
const next = prep[k + 1];
|
|
453
|
+
for (const [q, leaving] of /** @type {[Prep | undefined, boolean][]} */ ([[k > 0 ? p : undefined, false], [next, true]])) {
|
|
454
|
+
if (!q?.mo) continue;
|
|
455
|
+
const c = carriedBy(q, l, t, leaving, fps);
|
|
456
|
+
pos = [pos[0] + c[0], pos[1] + c[1], pos[2] + c[2]];
|
|
457
|
+
at = [at[0] + c[0], at[1] + c[1], at[2] + c[2]];
|
|
458
|
+
}
|
|
459
|
+
const ap = typeof sh.aperture === "function" ? sh.aperture(t) : (sh.aperture ?? 0);
|
|
460
|
+
const fo = typeof sh.focus === "function" ? sh.focus(t) : sh.focus;
|
|
461
|
+
/** @type {number | V3} */
|
|
462
|
+
let f;
|
|
463
|
+
if (fo && !Array.isArray(fo) && typeof fo === "object") f = lerp3(fo.from, fo.to, (p.pull ?? easeOf(fo.ease ?? "smooth"))((t - fo.start) / Math.max(1e-6, fo.dur)));
|
|
464
|
+
else f = fo ?? at;
|
|
465
|
+
// the distance along the lens's axis to the plane through the point, never under 1
|
|
466
|
+
// (the lens's offset is divided by it)
|
|
467
|
+
const ax = [at[0] - pos[0], at[1] - pos[1], at[2] - pos[2]], al = Math.hypot(ax[0] ?? 0, ax[1] ?? 0, ax[2] ?? 0) || 1;
|
|
468
|
+
const focus = Math.max(1, typeof f === "number" ? f
|
|
469
|
+
: ((f[0] - pos[0]) * (ax[0] ?? 0) + (f[1] - pos[1]) * (ax[1] ?? 0) + (f[2] - pos[2]) * (ax[2] ?? 0)) / al) || 1;
|
|
470
|
+
const sk = p.shake ? p.shake(t) : { yaw: 0, pitch: 0, roll: 0 };
|
|
471
|
+
return { pos, at, fov, roll: roll + sk.roll, yaw: sk.yaw, pitch: sk.pitch, focus, aperture: ap, scene: sh.scene ?? "main", shot: k };
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/** the lens's cuts: a shot marked `cut` or in another scene (on its start), a momentum cut and a
|
|
475
|
+
* jump (between two frames) @returns {Mark[]} */
|
|
476
|
+
function marks() {
|
|
477
|
+
const fps = fpsNow();
|
|
478
|
+
/** @type {Mark[]} */
|
|
479
|
+
const out = [];
|
|
480
|
+
s.forEach((b, i) => {
|
|
481
|
+
const a = s[i - 1];
|
|
482
|
+
if (a && b.momentum) out.push({ ...between(b.start, fps), kind: "cut" });
|
|
483
|
+
else if (a && (b.cut || (b.scene ?? "main") !== (a.scene ?? "main"))) out.push({ t: b.start, edge: b.start, kind: "cut" });
|
|
484
|
+
if (b.jump != null) out.push({ ...between(b.jump, fps), kind: "hidden-cut" });
|
|
485
|
+
});
|
|
486
|
+
return out.sort((x, y) => x.t - y.t);
|
|
487
|
+
}
|
|
488
|
+
return { pose, shots: s, get cuts() { return marks().map((m) => m.edge); }, marks };
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
/** Halton low-discrepancy number i in base b (0..1) @param {number} i @param {number} b */
|
|
492
|
+
export function halton(i, b) {
|
|
493
|
+
let f = 1, r = 0;
|
|
494
|
+
while (i > 0) { f /= b; r += f * (i % b); i = Math.floor(i / b); }
|
|
495
|
+
return r;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
/**
|
|
499
|
+
* When each of n samples of the frame at t is taken: spread through a shutter
|
|
500
|
+
* of `shutter` s centred on t, stratified and shuffled (i·k mod n, k the
|
|
501
|
+
* first of 7, 8, … sharing no factor with n, so every slot is taken once),
|
|
502
|
+
* and held inside [lo, hi) — the shot the frame belongs to — so no sample
|
|
503
|
+
* shows the picture on the other side of a cut.
|
|
504
|
+
* @param {number} t @param {number} n @param {number} shutter s @param {number} [lo] @param {number} [hi]
|
|
505
|
+
* @returns {number[]}
|
|
506
|
+
*/
|
|
507
|
+
export function shutterTimes(t, n, shutter, lo = -Infinity, hi = Infinity) {
|
|
508
|
+
const gcd = (/** @type {number} */ a, /** @type {number} */ b) => { while (b) [a, b] = [b, a % b]; return a; };
|
|
509
|
+
let k = 7;
|
|
510
|
+
while (n > 1 && gcd(k, n) !== 1) k++;
|
|
511
|
+
/** @type {number[]} */
|
|
512
|
+
const out = [];
|
|
513
|
+
for (let i = 0; i < n; i++) {
|
|
514
|
+
const at = t + ((((i * k) % n) + 0.5) / n - 0.5) * shutter;
|
|
515
|
+
out.push(Math.min(hi - 1e-6, Math.max(lo, at)));
|
|
516
|
+
}
|
|
517
|
+
return out;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
/** the run of picture t falls in: from the cut before it to the cut after
|
|
521
|
+
* @param {number} t @param {number[]} cuts @returns {[number, number]} */
|
|
522
|
+
export function runOf(t, cuts) {
|
|
523
|
+
let lo = -Infinity, hi = Infinity;
|
|
524
|
+
for (const c of cuts) {
|
|
525
|
+
if (c <= t) lo = Math.max(lo, c);
|
|
526
|
+
else hi = Math.min(hi, c);
|
|
527
|
+
}
|
|
528
|
+
return [lo, hi];
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
/** a rise into place from behind: back 260 and down 40, fading in over 0.75 s
|
|
532
|
+
* (the spike's windows coming up as the lens pulls back) — a slab's `move`
|
|
533
|
+
* @param {number} t0 @param {{ dz?: number, dy?: number, dur?: number }} [o] */
|
|
534
|
+
export function riseIn(t0, { dz = -260, dy = -40, dur = 0.75 } = {}) {
|
|
535
|
+
return (/** @type {number} */ t) => {
|
|
536
|
+
const u = dur > 0 ? (eases.smooth?.((t - t0) / dur) ?? 0) : t >= t0 ? 1 : 0;
|
|
537
|
+
return { y: dy * (1 - u), z: dz * (1 - u), opacity: u };
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
/** a slow float, a few px on two axes, for things that should never sit dead still
|
|
542
|
+
* @param {number} [ax] @param {number} [ay] @param {number} [seed] */
|
|
543
|
+
export function float(ax = 12, ay = 7, seed = 1) {
|
|
544
|
+
return (/** @type {number} */ t) => ({ x: ax * Math.sin(t * 1.2 + seed * 2.1), y: ay * Math.sin(t * 1.6 + seed * 1.3) });
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* How far apart the copies of a thing are in one frame of n samples, frame
|
|
549
|
+
* px: its blur (a lens's disk of radius `coc`, swept `travel` px across the
|
|
550
|
+
* shutter) shared among the samples. A texture blurred by about this much
|
|
551
|
+
* before it is drawn fills the gaps, so a far defocus or a fast move reads
|
|
552
|
+
* as one smear rather than stacked copies.
|
|
553
|
+
* @param {number} coc @param {number} travel @param {number} n
|
|
554
|
+
*/
|
|
555
|
+
export function sampleGap(coc, travel, n) {
|
|
556
|
+
if (n <= 1) return 0;
|
|
557
|
+
return Math.max(travel / n, Math.sqrt((Math.PI * coc * coc + 2 * coc * travel) / n));
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
/**
|
|
561
|
+
* The finest mip level a texture may be read from so it is blurred by `gap`
|
|
562
|
+
* px, when `texelsPerPx` of its texels fall on one px: 0 (its full level) for
|
|
563
|
+
* a gap under a px — copies that close merge on their own, and text held
|
|
564
|
+
* still stays as sharp as its full level draws it.
|
|
565
|
+
* @param {number} gap @param {number} texelsPerPx
|
|
566
|
+
*/
|
|
567
|
+
export function prefilterLevel(gap, texelsPerPx) {
|
|
568
|
+
const texels = gap * texelsPerPx;
|
|
569
|
+
return gap >= 1 && texels > 1 ? Math.log2(texels) : 0;
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
// --- the stage --------------------------------------------------------------
|
|
573
|
+
|
|
574
|
+
const LAYERS = { backdrop: -1900, far: -600, hero: 0, near: 190 };
|
|
575
|
+
const DEG = Math.PI / 180;
|
|
576
|
+
|
|
577
|
+
/** wait for the canvas's next paint (the snapshot of its drawable children);
|
|
578
|
+
* no timer as a guard: under the film clock a held timer fires within real
|
|
579
|
+
* milliseconds, before the paint, and the texture would show an old snapshot
|
|
580
|
+
* @param {any} canvas */
|
|
581
|
+
function nextPaint(canvas) {
|
|
582
|
+
if (typeof canvas.requestPaint !== "function") return Promise.resolve();
|
|
583
|
+
return new Promise((resolve) => {
|
|
584
|
+
canvas.addEventListener("paint", () => resolve(undefined), { once: true });
|
|
585
|
+
canvas.requestPaint();
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
/**
|
|
590
|
+
* The stage. See the top of this file.
|
|
591
|
+
* @param {{ three: any, canvas: HTMLCanvasElement, width?: number, height?: number,
|
|
592
|
+
* samples?: { draft?: number, master?: number } | number, shutter?: number, near?: number, far?: number,
|
|
593
|
+
* hic?: boolean }} o
|
|
594
|
+
*/
|
|
595
|
+
export function space(o) {
|
|
596
|
+
const T = o.three;
|
|
597
|
+
if (!T) throw new Error("space: needs three — space({ three: THREE, canvas })");
|
|
598
|
+
const canvas = /** @type {any} */ (o.canvas);
|
|
599
|
+
const FW = o.width ?? 1920, FH = o.height ?? 1080, aspect = FW / FH;
|
|
600
|
+
const shutterShare = o.shutter ?? 0.5;
|
|
601
|
+
const renderer = new T.WebGLRenderer({ canvas, antialias: false, preserveDrawingBuffer: true, powerPreference: "high-performance" });
|
|
602
|
+
renderer.autoClear = false;
|
|
603
|
+
renderer.toneMapping = T.NoToneMapping;
|
|
604
|
+
const gl = renderer.getContext();
|
|
605
|
+
const hic = o.hic !== false && typeof gl.texElementSubImage2D === "function";
|
|
606
|
+
|
|
607
|
+
// --- targets and the accumulation ---
|
|
608
|
+
let dpr = 0, W = 0, H = 0;
|
|
609
|
+
/** @type {any} */ let sampleRT = null;
|
|
610
|
+
/** @type {any} */ let accRT = null;
|
|
611
|
+
function ensureSize() {
|
|
612
|
+
const d = window.devicePixelRatio || 1;
|
|
613
|
+
if (d === dpr) return;
|
|
614
|
+
dpr = d;
|
|
615
|
+
renderer.setPixelRatio(d);
|
|
616
|
+
renderer.setSize(FW, FH, false);
|
|
617
|
+
W = Math.round(FW * d); H = Math.round(FH * d);
|
|
618
|
+
sampleRT?.dispose(); accRT?.dispose();
|
|
619
|
+
sampleRT = new T.WebGLRenderTarget(W, H, { type: T.HalfFloatType, depthBuffer: true });
|
|
620
|
+
accRT = new T.WebGLRenderTarget(W, H, { type: T.FloatType, depthBuffer: false });
|
|
621
|
+
}
|
|
622
|
+
const VS = "varying vec2 vUv; void main(){ vUv = uv; gl_Position = vec4(position.xy, 0.0, 1.0); }";
|
|
623
|
+
const accMat = new T.ShaderMaterial({
|
|
624
|
+
uniforms: { map: { value: null }, weight: { value: 1 } }, vertexShader: VS,
|
|
625
|
+
fragmentShader: "uniform sampler2D map; uniform float weight; varying vec2 vUv; void main(){ gl_FragColor = vec4(texture2D(map, vUv).rgb * weight, 1.0); }",
|
|
626
|
+
blending: T.CustomBlending, blendSrc: T.OneFactor, blendDst: T.OneFactor, blendEquation: T.AddEquation, depthTest: false, depthWrite: false,
|
|
627
|
+
});
|
|
628
|
+
// the plain finish: linear to sRGB, nothing else — an interface keeps its colours
|
|
629
|
+
const outMat = new T.ShaderMaterial({
|
|
630
|
+
uniforms: { map: { value: null } }, vertexShader: VS,
|
|
631
|
+
fragmentShader: `uniform sampler2D map; varying vec2 vUv;
|
|
632
|
+
vec3 srgb(vec3 c){ return mix(c*12.92, 1.055*pow(c, vec3(1.0/2.4))-0.055, step(0.0031308, c)); }
|
|
633
|
+
void main(){ gl_FragColor = vec4(srgb(clamp(texture2D(map, vUv).rgb, 0.0, 1.0)), 1.0); }`,
|
|
634
|
+
depthTest: false, depthWrite: false,
|
|
635
|
+
});
|
|
636
|
+
const quad = new T.PlaneGeometry(2, 2);
|
|
637
|
+
const accScene = new T.Scene(); accScene.add(new T.Mesh(quad, accMat));
|
|
638
|
+
const outScene = new T.Scene(); const outQuad = new T.Mesh(quad, outMat); outScene.add(outQuad);
|
|
639
|
+
const ortho = new T.OrthographicCamera(-1, 1, 1, -1, 0, 1);
|
|
640
|
+
const cam = new T.PerspectiveCamera(30, aspect, o.near ?? 10, o.far ?? 40000);
|
|
641
|
+
const NEAR = o.near ?? 10, FAR = o.far ?? 40000;
|
|
642
|
+
|
|
643
|
+
/** a lens pose on three's camera, offset on the lens (lx, ly on the unit disk, times the
|
|
644
|
+
* aperture) with the plane of focus held, and a sub-pixel jitter (jx, jy px)
|
|
645
|
+
* @param {LensAt} p @param {number} [lx] @param {number} [ly] @param {number} [jx] @param {number} [jy] */
|
|
646
|
+
function aim(p, lx = 0, ly = 0, jx = 0, jy = 0) {
|
|
647
|
+
cam.position.set(...p.pos);
|
|
648
|
+
cam.up.set(0, 1, 0);
|
|
649
|
+
cam.lookAt(...p.at);
|
|
650
|
+
cam.rotateY(p.yaw * DEG); cam.rotateX(p.pitch * DEG); cam.rotateZ(p.roll * DEG);
|
|
651
|
+
cam.updateMatrixWorld();
|
|
652
|
+
const right = new T.Vector3().setFromMatrixColumn(cam.matrixWorld, 0);
|
|
653
|
+
const up = new T.Vector3().setFromMatrixColumn(cam.matrixWorld, 1);
|
|
654
|
+
const dx = lx * p.aperture, dy = ly * p.aperture;
|
|
655
|
+
cam.position.addScaledVector(right, dx).addScaledVector(up, dy);
|
|
656
|
+
cam.updateMatrixWorld();
|
|
657
|
+
const h = NEAR * Math.tan((p.fov * DEG) / 2), w = h * aspect;
|
|
658
|
+
const sx = (-dx * NEAR) / p.focus + jx * ((2 * w) / Math.max(1, W));
|
|
659
|
+
const sy = (-dy * NEAR) / p.focus + jy * ((2 * h) / Math.max(1, H));
|
|
660
|
+
cam.near = NEAR; cam.far = FAR; cam.fov = p.fov; cam.aspect = aspect; // read by levels()
|
|
661
|
+
cam.projectionMatrix.makePerspective(-w + sx, w + sx, h + sy, -h + sy, NEAR, FAR);
|
|
662
|
+
cam.projectionMatrixInverse.copy(cam.projectionMatrix).invert();
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
// --- scenes and layers ---
|
|
666
|
+
/** @typedef {number | string | { isColor: true } | ((t: number) => number | string | { isColor: true })} Clear a colour (0x…, "#…", a THREE.Color), or one from film time */
|
|
667
|
+
/** @typedef {(t: number, at: { clear: any, pose: LensAt }) => void} Tick */
|
|
668
|
+
/** @typedef {{ name: string, three: any, clear: Clear, update: ((t: number, p: LensAt) => void) | null, ticks: Tick[], finish: any, layers: Record<string, any>, watch: any[] }} Scene */
|
|
669
|
+
/** @type {Record<string, Scene>} */
|
|
670
|
+
const scenes = {};
|
|
671
|
+
const clearColour = new T.Color();
|
|
672
|
+
/** a scene's ground colour at t (one colour object, read it before the next call)
|
|
673
|
+
* @param {Scene} sc @param {number} t */
|
|
674
|
+
const clearOf = (sc, t) => {
|
|
675
|
+
const c = typeof sc.clear === "function" ? sc.clear(t) : sc.clear;
|
|
676
|
+
return clearColour.set(/** @type {any} */ (c));
|
|
677
|
+
};
|
|
678
|
+
/** @param {string} name @param {{ clear?: Clear, update?: (t: number, p: LensAt) => void, finish?: any, environment?: any, environmentIntensity?: number }} [so] */
|
|
679
|
+
function scene(name, so = {}) {
|
|
680
|
+
if (!scenes[name]) scenes[name] = { name, three: new T.Scene(), clear: 0x0b0d12, update: null, ticks: [], finish: null, layers: {}, watch: [] };
|
|
681
|
+
const sc = scenes[name];
|
|
682
|
+
if (so.clear !== undefined) sc.clear = so.clear;
|
|
683
|
+
if (so.update) sc.update = so.update;
|
|
684
|
+
if (so.finish) sc.finish = so.finish;
|
|
685
|
+
if (so.environment) sc.three.environment = so.environment;
|
|
686
|
+
if (so.environmentIntensity !== undefined) sc.three.environmentIntensity = so.environmentIntensity;
|
|
687
|
+
return {
|
|
688
|
+
name, three: sc.three,
|
|
689
|
+
layer: (/** @type {string} */ l) => layer(l, name),
|
|
690
|
+
/** things whose motion counts in travel(): their bounding boxes' corners are followed */
|
|
691
|
+
watch: (/** @type {any} */ obj) => { sc.watch.push(obj); return obj; },
|
|
692
|
+
/** a three object into a layer — or one of solid.js's ready objects ({ group, tick?, fog? }):
|
|
693
|
+
* its group goes in, its `tick` is run at every sample's time, its fog becomes the scene's */
|
|
694
|
+
add: (/** @type {any} */ obj, /** @type {string} */ l = "hero") => {
|
|
695
|
+
layer(l, name).add(obj?.isObject3D ? obj : obj.group);
|
|
696
|
+
if (!obj?.isObject3D) {
|
|
697
|
+
if (obj.fog) sc.three.fog = obj.fog;
|
|
698
|
+
if (typeof obj.tick === "function") sc.ticks.push(obj.tick);
|
|
699
|
+
}
|
|
700
|
+
return obj;
|
|
701
|
+
},
|
|
702
|
+
/** run fn(t, { clear, pose }) at every sample's time, as well as the scene's `update`:
|
|
703
|
+
* what an object is at t (a lid's angle, a light) belongs here, not in __render */
|
|
704
|
+
animate: (/** @type {Tick} */ fn) => { sc.ticks.push(fn); },
|
|
705
|
+
/** the ground colour at t, a new THREE.Color */
|
|
706
|
+
clearAt: (/** @type {number} */ t) => clearOf(sc, t).clone(),
|
|
707
|
+
};
|
|
708
|
+
}
|
|
709
|
+
/** @param {string} name @param {string} [sceneName] */
|
|
710
|
+
function layer(name, sceneName = "main") {
|
|
711
|
+
scene(sceneName);
|
|
712
|
+
const sc = /** @type {Scene} */ (scenes[sceneName]);
|
|
713
|
+
if (!sc.layers[name]) {
|
|
714
|
+
const g = new T.Group();
|
|
715
|
+
g.name = name;
|
|
716
|
+
g.position.z = /** @type {Record<string, number>} */ (LAYERS)[name] ?? 0;
|
|
717
|
+
sc.three.add(g);
|
|
718
|
+
sc.layers[name] = g;
|
|
719
|
+
}
|
|
720
|
+
return sc.layers[name];
|
|
721
|
+
}
|
|
722
|
+
scene("main");
|
|
723
|
+
|
|
724
|
+
// --- live slabs ---
|
|
725
|
+
/** @typedef {{ el: HTMLElement, w: number, h: number, tw: number, th: number, glTex: any, tex: any, mesh: any, group: any, shadow: any,
|
|
726
|
+
* home: any, homeRot: any, move: ((t: number) => any) | null, dirty: boolean, allocated: boolean, lod: string, picture: string | null, scene: string }} Slab */
|
|
727
|
+
/** @type {Slab[]} */
|
|
728
|
+
const slabs = [];
|
|
729
|
+
const aniso = gl.getExtension("EXT_texture_filter_anisotropic");
|
|
730
|
+
// A slab's texture holds the element as the browser drew it: sRGB, its
|
|
731
|
+
// alpha premultiplied there, so filtering and mip levels blend the way the
|
|
732
|
+
// page composites (no dark fringe round a rounded corner). The shader takes
|
|
733
|
+
// the colour back out, decodes it to linear, and three's premultipliedAlpha
|
|
734
|
+
// multiplies by alpha once (and blends ONE, 1−α): half-white glass over a
|
|
735
|
+
// white card stays white.
|
|
736
|
+
const SLAB_MAP = `#ifdef USE_MAP
|
|
737
|
+
vec4 texel = texture2D( map, vMapUv );
|
|
738
|
+
vec3 c = texel.a > 0.0 ? clamp( texel.rgb / texel.a, 0.0, 1.0 ) : vec3( 0.0 );
|
|
739
|
+
c = mix( c / 12.92, pow( ( c + 0.055 ) / 1.055, vec3( 2.4 ) ), step( 0.04045, c ) );
|
|
740
|
+
diffuseColor *= vec4( c, texel.a );
|
|
741
|
+
#endif`;
|
|
742
|
+
|
|
743
|
+
/** a soft rounded card drawn by code: a blurred shape, for shadows and things near the lens
|
|
744
|
+
* @param {number} w @param {number} h @param {number} blur px @param {string} fill @param {number} [radius] */
|
|
745
|
+
function softCard(w, h, blur, fill, radius = 24) {
|
|
746
|
+
const pad = blur * 3, c = document.createElement("canvas");
|
|
747
|
+
c.width = w + pad * 2; c.height = h + pad * 2;
|
|
748
|
+
const ctx = /** @type {CanvasRenderingContext2D} */ (c.getContext("2d"));
|
|
749
|
+
ctx.filter = `blur(${blur}px)`; ctx.fillStyle = fill;
|
|
750
|
+
ctx.beginPath(); ctx.roundRect(pad, pad, w, h, radius); ctx.fill();
|
|
751
|
+
const tex = new T.CanvasTexture(c); tex.colorSpace = T.SRGBColorSpace;
|
|
752
|
+
return { texture: tex, width: c.width, height: c.height };
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
/**
|
|
756
|
+
* @param {HTMLElement} el a drawable child of the canvas (`<div drawable>` inside `<canvas content="drawable">`)
|
|
757
|
+
* @param {{ layer?: string, scene?: string, pos?: V3, rx?: number, ry?: number, rz?: number, scale?: number,
|
|
758
|
+
* shadow?: boolean, parent?: any, move?: (t: number) => any, picture?: string, size?: [number, number] }} [so]
|
|
759
|
+
* parent: another slab, or any three object (a lid, a turntable): the slab rides on it, in its scene
|
|
760
|
+
*/
|
|
761
|
+
function slab(el, so = {}) {
|
|
762
|
+
const w = so.size?.[0] ?? el.offsetWidth, h = so.size?.[1] ?? el.offsetHeight;
|
|
763
|
+
const k = so.scale ?? 2;
|
|
764
|
+
const tw = Math.round(w * k), th = Math.round(h * k);
|
|
765
|
+
const glTex = gl.createTexture();
|
|
766
|
+
const tex = new T.ExternalTexture(glTex);
|
|
767
|
+
const mat = new T.MeshBasicMaterial({ map: tex, transparent: true, premultipliedAlpha: true, toneMapped: false, depthWrite: so.shadow !== false });
|
|
768
|
+
mat.onBeforeCompile = (/** @type {any} */ sh) => { sh.fragmentShader = sh.fragmentShader.replace("#include <map_fragment>", SLAB_MAP); };
|
|
769
|
+
mat.customProgramCacheKey = () => "space-slab";
|
|
770
|
+
const mesh = new T.Mesh(new T.PlaneGeometry(w, h), mat);
|
|
771
|
+
const group = new T.Group(); group.add(mesh);
|
|
772
|
+
/** @type {any} */ let shadow = null;
|
|
773
|
+
if (so.shadow !== false) {
|
|
774
|
+
const s = softCard(w, h, 22, "rgba(0,0,0,0.55)", 22);
|
|
775
|
+
shadow = new T.Mesh(new T.PlaneGeometry(s.width, s.height), new T.MeshBasicMaterial({ map: s.texture, transparent: true, depthWrite: false, toneMapped: false }));
|
|
776
|
+
shadow.position.set(0, -26, -24);
|
|
777
|
+
group.add(shadow);
|
|
778
|
+
}
|
|
779
|
+
group.position.set(...(so.pos ?? [0, 0, 0]));
|
|
780
|
+
group.rotation.set((so.rx ?? 0) * DEG, (so.ry ?? 0) * DEG, (so.rz ?? 0) * DEG);
|
|
781
|
+
// a slab riding on another is in its scene; one on a three object, in the scene that
|
|
782
|
+
// object is in (looked up each time: the object may be put in its scene after)
|
|
783
|
+
const host = so.parent ? (so.parent.isObject3D ? so.parent : so.parent.group) : null;
|
|
784
|
+
if (so.parent && !host?.isObject3D) throw new Error("space: a slab's `parent` is another slab or a three object (a Group, a Mesh)");
|
|
785
|
+
const sceneName = so.parent?.slab?.scene ?? so.scene ?? "main";
|
|
786
|
+
(host ?? layer(so.layer ?? "hero", sceneName)).add(group);
|
|
787
|
+
/** @type {Slab} */
|
|
788
|
+
const s = { el, w, h, tw, th, glTex, tex, mesh, group, shadow, home: group.position.clone(), homeRot: group.rotation.clone(),
|
|
789
|
+
move: so.move ?? null, dirty: true, allocated: false, lod: "", picture: so.picture ?? null, scene: sceneName };
|
|
790
|
+
if (host && !so.parent.slab && !so.scene) Object.defineProperty(s, "scene", { get: () => sceneHolding(host) ?? "main" });
|
|
791
|
+
slabs.push(s);
|
|
792
|
+
|
|
793
|
+
/** everything the slab hangs on, as it is at t — before any draw too */
|
|
794
|
+
const settleAt = (/** @type {number} */ t) => {
|
|
795
|
+
const sc = scenes[s.scene];
|
|
796
|
+
if (sc) settle(sc, t, lens.pose(t));
|
|
797
|
+
mesh.updateWorldMatrix(true, false);
|
|
798
|
+
};
|
|
799
|
+
/** a point of the element (its own CSS px, from its top-left) in the space at t
|
|
800
|
+
* @param {number} x @param {number} y @param {number} [t] @returns {V3} */
|
|
801
|
+
function point(x, y, t = 0) {
|
|
802
|
+
settleAt(t);
|
|
803
|
+
const v = new T.Vector3(x - w / 2, h / 2 - y, 0).applyMatrix4(mesh.matrixWorld);
|
|
804
|
+
return [v.x, v.y, v.z];
|
|
805
|
+
}
|
|
806
|
+
/**
|
|
807
|
+
* The lens that frames a part of the slab as lib/moves.js `station` frames
|
|
808
|
+
* a rect for a 2D camera: aimed at its middle, the rect `share` of the
|
|
809
|
+
* frame's width (0.635), square on — or `yaw`/`pitch` degrees round it
|
|
810
|
+
* (yaw + from the slab's right, pitch + from above). A Pose for a shot's
|
|
811
|
+
* `from`/`to` or a station's `to`; with the slab where it is at `t`.
|
|
812
|
+
* @param {{ x: number, y: number, w: number, h: number } | null} [rect] in the element's CSS px (default: all of it)
|
|
813
|
+
* @param {{ share?: number, fov?: number, t?: number, yaw?: number, pitch?: number, dist?: number }} [fo]
|
|
814
|
+
* dist: how far the lens stands off, in place of `share`
|
|
815
|
+
* @returns {{ pos: V3, at: V3, fov: number }}
|
|
816
|
+
*/
|
|
817
|
+
function station(rect, fo = {}) {
|
|
818
|
+
const r = rect ?? { x: 0, y: 0, w, h };
|
|
819
|
+
const { share = 0.635, fov = 30, t = 0, yaw = 0, pitch = 0 } = fo;
|
|
820
|
+
const at = point(r.x + r.w / 2, r.y + r.h / 2, t);
|
|
821
|
+
const m = mesh.matrixWorld;
|
|
822
|
+
const right = new T.Vector3().setFromMatrixColumn(m, 0), up = new T.Vector3().setFromMatrixColumn(m, 1), out = new T.Vector3().setFromMatrixColumn(m, 2);
|
|
823
|
+
const k = right.length();
|
|
824
|
+
right.normalize(); up.normalize(); out.normalize();
|
|
825
|
+
out.applyAxisAngle(right, -pitch * DEG).applyAxisAngle(up, yaw * DEG);
|
|
826
|
+
const d = fo.dist ?? (r.w * k) / (share * 2 * Math.tan((fov * DEG) / 2) * aspect);
|
|
827
|
+
return { pos: [at[0] + out.x * d, at[1] + out.y * d, at[2] + out.z * d], at, fov };
|
|
828
|
+
}
|
|
829
|
+
return {
|
|
830
|
+
group, mesh, el, width: w, height: h, slab: s, point, station,
|
|
831
|
+
/** a point of the element (its own CSS px) in the frame at t, px; null behind the lens
|
|
832
|
+
* @param {number} x @param {number} y @param {number} [t] */
|
|
833
|
+
toFrame: (x, y, t = 0) => toFrame(point(x, y, t), t),
|
|
834
|
+
};
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
/** the name of the scene a three object is in, if it is in one @param {any} obj @returns {string | null} */
|
|
838
|
+
function sceneHolding(obj) {
|
|
839
|
+
let root = obj;
|
|
840
|
+
while (root.parent) root = root.parent;
|
|
841
|
+
for (const sc of Object.values(scenes)) if (sc.three === root) return sc.name;
|
|
842
|
+
return null;
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
/** @param {Slab} s @param {TexImageSource | null} [img] */
|
|
846
|
+
function upload(s, img = null) {
|
|
847
|
+
gl.bindTexture(gl.TEXTURE_2D, s.glTex);
|
|
848
|
+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
|
|
849
|
+
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
|
|
850
|
+
if (!s.allocated) {
|
|
851
|
+
// sRGB bytes, premultiplied: decoded in the slab's shader (see SLAB_MAP)
|
|
852
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, s.tw, s.th, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
|
|
853
|
+
s.allocated = true;
|
|
854
|
+
}
|
|
855
|
+
if (img) gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, img);
|
|
856
|
+
else gl.texElementSubImage2D(gl.TEXTURE_2D, 0, 0, 0, s.el, { width: s.tw, height: s.th });
|
|
857
|
+
gl.generateMipmap(gl.TEXTURE_2D);
|
|
858
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR);
|
|
859
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
|
860
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
861
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
862
|
+
if (aniso) gl.texParameterf(gl.TEXTURE_2D, aniso.TEXTURE_MAX_ANISOTROPY_EXT, 16);
|
|
863
|
+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
|
864
|
+
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
|
|
865
|
+
s.lod = "";
|
|
866
|
+
renderer.resetState();
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
/** where HTML-in-Canvas is missing: the slab's `picture`, or the element through an SVG
|
|
870
|
+
* foreignObject with the page's own style sheets (system fonts only; no outside images)
|
|
871
|
+
* @param {Slab} s @returns {Promise<HTMLCanvasElement>} */
|
|
872
|
+
async function raster(s) {
|
|
873
|
+
const c = document.createElement("canvas");
|
|
874
|
+
c.width = s.tw; c.height = s.th;
|
|
875
|
+
const ctx = /** @type {CanvasRenderingContext2D} */ (c.getContext("2d"));
|
|
876
|
+
const img = new Image();
|
|
877
|
+
if (s.picture) img.src = s.picture;
|
|
878
|
+
else {
|
|
879
|
+
let css = "";
|
|
880
|
+
for (const sh of Array.from(document.styleSheets)) {
|
|
881
|
+
try { for (const r of Array.from(sh.cssRules)) css += r.cssText + "\n"; } catch { /* another origin's sheet */ }
|
|
882
|
+
}
|
|
883
|
+
const xml = new XMLSerializer().serializeToString(s.el);
|
|
884
|
+
img.src = "data:image/svg+xml;charset=utf-8," + encodeURIComponent(
|
|
885
|
+
`<svg xmlns="http://www.w3.org/2000/svg" width="${s.tw}" height="${s.th}" viewBox="0 0 ${s.w} ${s.h}"><foreignObject x="0" y="0" width="${s.w}" height="${s.h}"><style>${css}</style>${xml}</foreignObject></svg>`);
|
|
886
|
+
}
|
|
887
|
+
await img.decode();
|
|
888
|
+
ctx.drawImage(img, 0, 0, c.width, c.height);
|
|
889
|
+
return c;
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
// what changed in a slab's element since its last upload: the observer's
|
|
893
|
+
// own deliveries (a page that awaits between setting its DOM and draw(t))
|
|
894
|
+
// and the records still queued, taken in draw() — either way exactly the
|
|
895
|
+
// slabs it touched are uploaded
|
|
896
|
+
/** @param {MutationRecord[]} recs */
|
|
897
|
+
const markDirty = (recs) => {
|
|
898
|
+
for (const r of recs) for (const s of slabs) if (s.el === r.target || s.el.contains(r.target)) s.dirty = true;
|
|
899
|
+
};
|
|
900
|
+
const watcher = new MutationObserver(markDirty);
|
|
901
|
+
watcher.observe(canvas, { subtree: true, childList: true, attributes: true, characterData: true });
|
|
902
|
+
|
|
903
|
+
/** @type {Promise<void> | null} */
|
|
904
|
+
let fresh = null;
|
|
905
|
+
async function refresh() {
|
|
906
|
+
markDirty(watcher.takeRecords());
|
|
907
|
+
const todo = slabs.filter((s) => s.dirty);
|
|
908
|
+
if (!todo.length) return;
|
|
909
|
+
if (hic) {
|
|
910
|
+
await nextPaint(canvas);
|
|
911
|
+
markDirty(watcher.takeRecords());
|
|
912
|
+
for (const s of slabs.filter((x) => x.dirty)) { upload(s); s.dirty = false; }
|
|
913
|
+
} else {
|
|
914
|
+
for (const s of todo) { upload(s, await raster(s)); s.dirty = false; }
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
/** where a slab is in the frame for the lens as aimed now: its middle and corners (frame
|
|
919
|
+
* px), how many device px its width covers, and how far it is along the lens's axis
|
|
920
|
+
* @param {Slab} s */
|
|
921
|
+
function seen(s) {
|
|
922
|
+
const e = s.mesh.matrixWorld.elements;
|
|
923
|
+
const sx = Math.hypot(e[0], e[1], e[2]);
|
|
924
|
+
const c = new T.Vector3().setFromMatrixPosition(s.mesh.matrixWorld);
|
|
925
|
+
const fwd = new T.Vector3(); cam.getWorldDirection(fwd);
|
|
926
|
+
const depth = Math.max(1, c.clone().sub(cam.position).dot(fwd));
|
|
927
|
+
const pxPerUnit = H / (2 * depth * Math.tan((cam.fov * DEG) / 2) || 1);
|
|
928
|
+
const pts = [[0, 0], [-0.5, -0.5], [0.5, -0.5], [0.5, 0.5], [-0.5, 0.5]].map(([x, y]) =>
|
|
929
|
+
onFrame(new T.Vector3((x ?? 0) * s.w, (y ?? 0) * s.h, 0).applyMatrix4(s.mesh.matrixWorld)));
|
|
930
|
+
return { depth, shownPx: s.w * sx * pxPerUnit, pts };
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
/**
|
|
934
|
+
* Which mip levels a slab's texture is read from this frame. Shown at more
|
|
935
|
+
* than half its texture's pixels and sharp: its full level only (blending
|
|
936
|
+
* in smaller levels softened text most). Blurred by the lens or the shutter
|
|
937
|
+
* further than its samples are apart: never finer than the level blurred by
|
|
938
|
+
* that gap (sampleGap), so its copies merge into one smear.
|
|
939
|
+
* @param {Slab} s @param {number} gap frame px between its copies
|
|
940
|
+
* @param {number} shownPx device px across it */
|
|
941
|
+
function levels(s, gap, shownPx) {
|
|
942
|
+
// blurred by 1.5 × the mean gap: the lens's samples are not evenly apart all over its disk
|
|
943
|
+
const d = gap * (W / FW);
|
|
944
|
+
const min = d >= 1 ? prefilterLevel(1.5 * d, s.tw / Math.max(1, shownPx)) : 0;
|
|
945
|
+
const max = min > 0 ? 1000 : shownPx / s.tw > 0.5 ? 0 : 1000;
|
|
946
|
+
const key = `${min.toFixed(2)}/${max}`;
|
|
947
|
+
if (key === s.lod) return;
|
|
948
|
+
gl.bindTexture(gl.TEXTURE_2D, s.glTex);
|
|
949
|
+
gl.texParameterf(gl.TEXTURE_2D, gl.TEXTURE_MIN_LOD, min);
|
|
950
|
+
gl.texParameterf(gl.TEXTURE_2D, gl.TEXTURE_MAX_LOD, max);
|
|
951
|
+
renderer.resetState();
|
|
952
|
+
s.lod = key;
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
// --- the backdrop and what passes the lens ---
|
|
956
|
+
/** @param {any} texture @param {{ scene?: string, z?: number, width?: number, height?: number }} [bo] */
|
|
957
|
+
function backdrop(texture, bo = {}) {
|
|
958
|
+
const m = new T.Mesh(new T.PlaneGeometry(bo.width ?? 9600, bo.height ?? 5400), new T.MeshBasicMaterial({ map: texture, toneMapped: false }));
|
|
959
|
+
m.position.z = bo.z ?? 0;
|
|
960
|
+
layer("backdrop", bo.scene ?? "main").add(m);
|
|
961
|
+
return m;
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
/** @type {{ mesh: any, start: number, dur: number, from: [number, number], to: [number, number], dist: number, turn: number, scene: string }[]} */
|
|
965
|
+
const passes = [];
|
|
966
|
+
/**
|
|
967
|
+
* Something passing near the lens — a pane of frosted glass, a card — placed
|
|
968
|
+
* from the lens each sample, `dist` in front of it, crossing from `from` to
|
|
969
|
+
* `to` (frame-relative units: −1 left/bottom edge … 1 right/top) over [start, start+dur].
|
|
970
|
+
* Pre-blurred so a large blur does not break into copies.
|
|
971
|
+
* @param {{ start: number, dur: number, from?: [number, number], to?: [number, number], dist?: number,
|
|
972
|
+
* width?: number, height?: number, blur?: number, fill?: string, texture?: any, scene?: string, turn?: number }} po
|
|
973
|
+
*/
|
|
974
|
+
function nearLens(po) {
|
|
975
|
+
const card = po.texture ? null : softCard(po.width ?? 560, po.height ?? 360, po.blur ?? 26, po.fill ?? "rgba(255,255,255,0.5)", 40);
|
|
976
|
+
const tex = po.texture ?? card?.texture;
|
|
977
|
+
const mesh = new T.Mesh(new T.PlaneGeometry(card?.width ?? po.width ?? 560, card?.height ?? po.height ?? 360),
|
|
978
|
+
new T.MeshBasicMaterial({ map: tex, transparent: true, depthWrite: false, toneMapped: false }));
|
|
979
|
+
mesh.visible = false;
|
|
980
|
+
scene(po.scene ?? "main");
|
|
981
|
+
/** @type {Scene} */ (scenes[po.scene ?? "main"]).three.add(mesh);
|
|
982
|
+
passes.push({ mesh, start: po.start, dur: po.dur, from: po.from ?? [-1.6, -0.2], to: po.to ?? [1.6, 0], dist: po.dist ?? 520, turn: po.turn ?? 20, scene: po.scene ?? "main" });
|
|
983
|
+
return mesh;
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
// --- the lens ---
|
|
987
|
+
const rigOpts = { fps: () => fps(), height: FH };
|
|
988
|
+
let lens = rig([], rigOpts);
|
|
989
|
+
/** @param {Shot[]} list */
|
|
990
|
+
function shots(list) { lens = rig(list, rigOpts); return lens; }
|
|
991
|
+
|
|
992
|
+
/** a scene's own things as they are at ts: its slabs from home, then what its objects'
|
|
993
|
+
* ticks and its `update` say — the lens not aimed
|
|
994
|
+
* @param {Scene} sc @param {number} ts @param {LensAt} p */
|
|
995
|
+
function settle(sc, ts, p) {
|
|
996
|
+
for (const s of slabs) {
|
|
997
|
+
if (s.scene !== sc.name) continue;
|
|
998
|
+
// from home every sample: the same t, the same place, whatever was drawn before
|
|
999
|
+
s.group.position.copy(s.home);
|
|
1000
|
+
s.group.rotation.copy(s.homeRot);
|
|
1001
|
+
s.group.scale.setScalar(1);
|
|
1002
|
+
let op = 1;
|
|
1003
|
+
if (s.move) {
|
|
1004
|
+
const m = s.move(ts) ?? {};
|
|
1005
|
+
s.group.position.x += m.x ?? 0; s.group.position.y += m.y ?? 0; s.group.position.z += m.z ?? 0;
|
|
1006
|
+
s.group.rotation.x += (m.rx ?? 0) * DEG; s.group.rotation.y += (m.ry ?? 0) * DEG; s.group.rotation.z += (m.rz ?? 0) * DEG;
|
|
1007
|
+
s.group.scale.setScalar(m.scale ?? 1);
|
|
1008
|
+
op = m.opacity ?? 1;
|
|
1009
|
+
}
|
|
1010
|
+
s.mesh.material.opacity = op;
|
|
1011
|
+
if (s.shadow) s.shadow.material.opacity = op;
|
|
1012
|
+
s.group.visible = op > 0.001;
|
|
1013
|
+
}
|
|
1014
|
+
if (sc.ticks.length) {
|
|
1015
|
+
const at = { clear: clearOf(sc, ts), pose: p };
|
|
1016
|
+
for (const f of sc.ticks) f(ts, at);
|
|
1017
|
+
}
|
|
1018
|
+
sc.update?.(ts, p);
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
/** everything in the scene at sample time ts, the lens unjittered
|
|
1022
|
+
* @param {number} ts @returns {{ p: LensAt, sc: Scene }} */
|
|
1023
|
+
function place(ts) {
|
|
1024
|
+
const p = lens.pose(ts);
|
|
1025
|
+
const sc = /** @type {Scene} */ (scenes[p.scene] ?? scenes.main);
|
|
1026
|
+
settle(sc, ts, p);
|
|
1027
|
+
aim(p);
|
|
1028
|
+
for (const ps of passes) {
|
|
1029
|
+
const u = (ts - ps.start) / ps.dur;
|
|
1030
|
+
ps.mesh.visible = ps.scene === sc.name && u > -0.05 && u < 1.05;
|
|
1031
|
+
if (!ps.mesh.visible) continue;
|
|
1032
|
+
const e = eases.smooth?.(u) ?? u;
|
|
1033
|
+
const hh = ps.dist * Math.tan((p.fov * DEG) / 2), ww = hh * aspect;
|
|
1034
|
+
const fx = ps.from[0] + (ps.to[0] - ps.from[0]) * e, fy = ps.from[1] + (ps.to[1] - ps.from[1]) * u;
|
|
1035
|
+
const fwd = new T.Vector3(); cam.getWorldDirection(fwd);
|
|
1036
|
+
const right = new T.Vector3().setFromMatrixColumn(cam.matrixWorld, 0), up = new T.Vector3().setFromMatrixColumn(cam.matrixWorld, 1);
|
|
1037
|
+
ps.mesh.position.copy(cam.position).addScaledVector(fwd, ps.dist).addScaledVector(right, fx * ww).addScaledVector(up, fy * hh);
|
|
1038
|
+
ps.mesh.quaternion.copy(cam.quaternion); ps.mesh.rotateY(ps.turn * DEG); ps.mesh.rotateZ(-0.08);
|
|
1039
|
+
}
|
|
1040
|
+
sc.three.updateMatrixWorld();
|
|
1041
|
+
return { p, sc };
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
const fps = () => /** @type {any} */ (window).__filmFps || (dpr < 1 ? 30 : 60);
|
|
1045
|
+
const sampleCount = () => {
|
|
1046
|
+
const sm = o.samples;
|
|
1047
|
+
if (typeof sm === "number") return sm;
|
|
1048
|
+
return dpr < 1 ? (sm?.draft ?? 8) : (sm?.master ?? 32);
|
|
1049
|
+
};
|
|
1050
|
+
|
|
1051
|
+
/** each shown slab's gap between its copies across `times` (sampleGap), and its size
|
|
1052
|
+
* in device px at t, for levels()
|
|
1053
|
+
* @param {number} t @param {number[]} times @returns {Map<Slab, [number, number]>} */
|
|
1054
|
+
function gaps(t, times) {
|
|
1055
|
+
const N = times.length;
|
|
1056
|
+
const first = Math.min(...times), last = Math.max(...times);
|
|
1057
|
+
/** @param {number} ts */
|
|
1058
|
+
const at = (ts) => { const { p, sc } = place(ts); return { p, sc, seen: new Map(slabs.filter((s) => s.scene === sc.name && s.group.visible).map((s) => [s, seen(s)])) }; };
|
|
1059
|
+
const a = first < last ? at(first) : null, b = first < last ? at(last) : null;
|
|
1060
|
+
const mid = at(t);
|
|
1061
|
+
/** @type {Map<Slab, [number, number]>} */
|
|
1062
|
+
const out = new Map();
|
|
1063
|
+
for (const [s, v] of mid.seen) {
|
|
1064
|
+
// the lens's disk at the slab's depth, frame px (a thin lens: a point at depth d
|
|
1065
|
+
// moves (1 − F/d) of the lens's offset on the plane in focus)
|
|
1066
|
+
const p = mid.p;
|
|
1067
|
+
const coc = (p.aperture * Math.abs(v.depth - p.focus) / v.depth) * (FH / (2 * p.focus * Math.tan((p.fov * DEG) / 2)));
|
|
1068
|
+
let travel = 0;
|
|
1069
|
+
const va = a?.seen.get(s), vb = b?.seen.get(s);
|
|
1070
|
+
if (va && vb) va.pts.forEach((x, k) => { const y = vb.pts[k]; if (x && y) travel = Math.max(travel, Math.hypot(x[0] - y[0], x[1] - y[1])); });
|
|
1071
|
+
out.set(s, [sampleGap(coc, travel, N), v.shownPx]);
|
|
1072
|
+
}
|
|
1073
|
+
return out;
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
// When `film render` spreads a frame's samples over the shutter itself (the
|
|
1077
|
+
// DOM outside the canvas moves), each draw is one of them and exposes the
|
|
1078
|
+
// share of the shutter the render says it stands for (window.__filmShare),
|
|
1079
|
+
// so the stage's samples and the render's tile the shutter without gaps.
|
|
1080
|
+
const share = () => {
|
|
1081
|
+
const s = /** @type {any} */ (window).__filmShare;
|
|
1082
|
+
return typeof s === "number" && s > 0 && s <= 1 ? s : 1;
|
|
1083
|
+
};
|
|
1084
|
+
|
|
1085
|
+
/** the frame at t @param {number} t */
|
|
1086
|
+
async function draw(t) {
|
|
1087
|
+
ensureSize();
|
|
1088
|
+
if (fresh) await fresh;
|
|
1089
|
+
await refresh();
|
|
1090
|
+
const N = sampleCount();
|
|
1091
|
+
const [lo, hi] = runOf(t, lens.cuts);
|
|
1092
|
+
const times = shutterTimes(t, N, (shutterShare / fps()) * share(), lo, hi);
|
|
1093
|
+
const spin = (t * 7.31) % (Math.PI * 2);
|
|
1094
|
+
const gap = gaps(t, times);
|
|
1095
|
+
renderer.setRenderTarget(accRT); renderer.setClearColor(0x000000, 0); renderer.clear(true, false, false);
|
|
1096
|
+
/** @type {Scene | null} */ let shown = null;
|
|
1097
|
+
for (let i = 0; i < N; i++) {
|
|
1098
|
+
const { p, sc } = place(/** @type {number} */ (times[i]));
|
|
1099
|
+
shown = sc;
|
|
1100
|
+
for (const s of slabs) if (s.scene === sc.name) { const g = gap.get(s); if (g) levels(s, g[0], g[1]); }
|
|
1101
|
+
const r = Math.sqrt((i + 0.5) / N), th = i * 2.399963 + spin; // a Vogel spiral on the lens, turned each frame
|
|
1102
|
+
aim(p, r * Math.cos(th), r * Math.sin(th), halton(i + 1, 2) - 0.5, halton(i + 1, 3) - 0.5);
|
|
1103
|
+
renderer.setRenderTarget(sampleRT); renderer.setClearColor(clearOf(sc, /** @type {number} */ (times[i])), 1); renderer.clear(true, true, false);
|
|
1104
|
+
renderer.render(sc.three, cam);
|
|
1105
|
+
accMat.uniforms.map.value = sampleRT.texture; accMat.uniforms.weight.value = 1 / N;
|
|
1106
|
+
renderer.setRenderTarget(accRT); renderer.render(accScene, ortho);
|
|
1107
|
+
}
|
|
1108
|
+
if (shown?.finish) {
|
|
1109
|
+
shown.finish.size?.(W, H);
|
|
1110
|
+
shown.finish.apply(accRT.texture, t);
|
|
1111
|
+
} else {
|
|
1112
|
+
renderer.setRenderTarget(null);
|
|
1113
|
+
outMat.uniforms.map.value = accRT.texture;
|
|
1114
|
+
renderer.render(outScene, ortho);
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
/** a point of the space at t in the frame, px (top-left origin); null behind the lens
|
|
1119
|
+
* @param {V3} pt @param {number} t @returns {[number, number] | null} */
|
|
1120
|
+
function toFrame(pt, t) {
|
|
1121
|
+
ensureSize();
|
|
1122
|
+
const { p } = place(t);
|
|
1123
|
+
aim(p);
|
|
1124
|
+
const v = new T.Vector3(...pt).project(cam);
|
|
1125
|
+
if (v.z > 1 || v.z < -1) return null;
|
|
1126
|
+
return [((v.x + 1) / 2) * FW, ((1 - v.y) / 2) * FH];
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
/** world points followed at t, each under its own key: each shown slab's corners and
|
|
1130
|
+
* middle, watched objects' boxes, and where the frame's corners meet the backdrop
|
|
1131
|
+
* @param {number} t @returns {{ scene: string, world: Map<string, any>, ground: any[] }} */
|
|
1132
|
+
function follow(t) {
|
|
1133
|
+
const { p, sc } = place(t);
|
|
1134
|
+
aim(p);
|
|
1135
|
+
/** @type {Map<string, any>} */
|
|
1136
|
+
const world = new Map();
|
|
1137
|
+
slabs.forEach((s, i) => {
|
|
1138
|
+
if (s.scene !== sc.name || !s.group.visible) return;
|
|
1139
|
+
[[-0.5, -0.5], [0.5, -0.5], [0.5, 0.5], [-0.5, 0.5], [0, 0]].forEach(([x, y], k) => {
|
|
1140
|
+
world.set(`s${i}.${k}`, new T.Vector3((x ?? 0) * s.w, (y ?? 0) * s.h, 0).applyMatrix4(s.mesh.matrixWorld));
|
|
1141
|
+
});
|
|
1142
|
+
});
|
|
1143
|
+
sc.watch.forEach((obj, i) => {
|
|
1144
|
+
const b = new T.Box3().setFromObject(obj);
|
|
1145
|
+
if (b.isEmpty()) return;
|
|
1146
|
+
for (let k = 0; k < 8; k++) world.set(`w${i}.${k}`, new T.Vector3(k & 1 ? b.max.x : b.min.x, k & 2 ? b.max.y : b.min.y, k & 4 ? b.max.z : b.min.z));
|
|
1147
|
+
});
|
|
1148
|
+
/** @type {any[]} */
|
|
1149
|
+
const ground = [];
|
|
1150
|
+
const bd = sc.layers.backdrop;
|
|
1151
|
+
if (bd?.children.length) {
|
|
1152
|
+
const z = new T.Vector3(); bd.getWorldPosition(z);
|
|
1153
|
+
const d = Math.abs(cam.position.z - z.z);
|
|
1154
|
+
for (const [x, y] of [[-0.8, -0.8], [0.8, -0.8], [0.8, 0.8], [-0.8, 0.8]])
|
|
1155
|
+
ground.push(new T.Vector3(x, y, 1).unproject(cam).sub(cam.position).normalize().multiplyScalar(d).add(cam.position));
|
|
1156
|
+
}
|
|
1157
|
+
return { scene: sc.name, world, ground };
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
/** @param {any} v the lens as it is now @returns {[number, number] | null} */
|
|
1161
|
+
const onFrame = (v) => {
|
|
1162
|
+
const q = v.clone().project(cam);
|
|
1163
|
+
if (q.z > 1 || q.z < -1 || Math.abs(q.x) > 1.5 || Math.abs(q.y) > 1.5) return null;
|
|
1164
|
+
return [((q.x + 1) / 2) * FW, ((1 - q.y) / 2) * FH];
|
|
1165
|
+
};
|
|
1166
|
+
|
|
1167
|
+
/** how far the picture moves across [t−half, t+half], frame px: the 90th
|
|
1168
|
+
* percentile of the followed points' moves (things on their own paths,
|
|
1169
|
+
* the backdrop under the lens's own), each point matched to itself and
|
|
1170
|
+
* counted where it is shown at both ends. No shutter crosses a cut: where
|
|
1171
|
+
* the span touches one, the part inside t's run is measured and scaled to
|
|
1172
|
+
* the whole span (the speed there, over the shutter)
|
|
1173
|
+
* @param {number} t @param {number} half */
|
|
1174
|
+
function travel(t, half) {
|
|
1175
|
+
const [lo, hi] = runOf(t, lens.cuts);
|
|
1176
|
+
const t0 = Math.max(t - half, lo), t1 = Math.min(t + half, hi - 1e-6);
|
|
1177
|
+
if (!(t1 > t0)) return 0;
|
|
1178
|
+
const mid = follow((t0 + t1) / 2).ground;
|
|
1179
|
+
const a = follow(t0);
|
|
1180
|
+
const pa = new Map([...a.world, ...mid.map((g, k) => [`g${k}`, g])].map(([key, v]) => [key, onFrame(v)]));
|
|
1181
|
+
const b = follow(t1);
|
|
1182
|
+
const pb = new Map([...b.world, ...mid.map((g, k) => [`g${k}`, g])].map(([key, v]) => [key, onFrame(v)]));
|
|
1183
|
+
if (a.scene !== b.scene) return 0;
|
|
1184
|
+
/** @type {number[]} */
|
|
1185
|
+
const d = [];
|
|
1186
|
+
for (const [key, x] of pa) { const y = pb.get(key); if (x && y) d.push(Math.hypot(x[0] - y[0], x[1] - y[1])); }
|
|
1187
|
+
if (!d.length) return 0;
|
|
1188
|
+
d.sort((x, y) => x - y);
|
|
1189
|
+
return /** @type {number} */ (d[Math.min(d.length - 1, Math.floor(d.length * 0.9))]) * ((2 * half) / (t1 - t0));
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
/** the lens's cuts, for the events file: a hard cut, a momentum cut, and a jump's cut
|
|
1193
|
+
* hidden in its push @returns {{ t: number, kind: string, label: string }[]} */
|
|
1194
|
+
function events() {
|
|
1195
|
+
return lens.marks().map((m) => ({ t: m.t, kind: m.kind,
|
|
1196
|
+
label: m.kind === "cut" ? "space: a cut between shots" : "space: the jump inside a push" }));
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
/** @param {{ duration: number, ready?: Promise<unknown>, events?: () => any[], width?: number, height?: number, [k: string]: any }} fo */
|
|
1200
|
+
function film(fo) {
|
|
1201
|
+
const { ready: theirs, events: theirEvents, ...rest } = fo;
|
|
1202
|
+
const ready = (async () => {
|
|
1203
|
+
await theirs;
|
|
1204
|
+
await Promise.resolve();
|
|
1205
|
+
ensureSize();
|
|
1206
|
+
fresh = refresh();
|
|
1207
|
+
await fresh;
|
|
1208
|
+
fresh = null;
|
|
1209
|
+
})();
|
|
1210
|
+
return {
|
|
1211
|
+
width: FW, height: FH, ...rest,
|
|
1212
|
+
ready,
|
|
1213
|
+
// The stage blurs itself across its own shutter, so the render need not
|
|
1214
|
+
// for the canvas; the DOM over it the render measures itself (see `share`).
|
|
1215
|
+
motion: (/** @type {number} */ t, /** @type {number} */ half) =>
|
|
1216
|
+
shutterShare > 0 ? 0 : travel(t, half),
|
|
1217
|
+
events: () => [...(theirEvents ? theirEvents() : []), ...events()].sort((x, y) => x.t - y.t),
|
|
1218
|
+
};
|
|
1219
|
+
}
|
|
1220
|
+
|
|
1221
|
+
return {
|
|
1222
|
+
three: T, renderer, camera: cam, canvas, hic,
|
|
1223
|
+
scene, layer, slab, backdrop, nearLens, softCard, shots, draw, toFrame, travel, events, film,
|
|
1224
|
+
/** the lens at t (no jitter) */
|
|
1225
|
+
pose: (/** @type {number} */ t) => lens.pose(t),
|
|
1226
|
+
};
|
|
1227
|
+
}
|