@open-take/compositor 0.5.3 → 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
package/kit/world.js
ADDED
|
@@ -0,0 +1,1072 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// A 3D world for a film page — open-take's film kit. The same slabs, poses
|
|
3
|
+
// and moves as kit/stage.js, drawn into one WebGL canvas with three.js: a
|
|
4
|
+
// screen tilted into space, a laptop, a phone or a browser window round a
|
|
5
|
+
// picture of the product, the lens turning about it or travelling past it.
|
|
6
|
+
// A slab here is a picture — a saved screen's picture (`film picture`), a
|
|
7
|
+
// part's picture, a frame of the recording, a <canvas>, a <video> — mapped
|
|
8
|
+
// onto a flat slab in a lit scene.
|
|
9
|
+
//
|
|
10
|
+
// Which one to pick. stage.js keeps a slab live DOM: its text is text, the
|
|
11
|
+
// film's text checks read it, what is on it keeps working. world.js has
|
|
12
|
+
// pixels only — nothing on a slab is an element any more — and gives back:
|
|
13
|
+
// - a cleaner tilt: mipmaps and 16× anisotropic filtering, where Chrome's
|
|
14
|
+
// compositor samples a tilted layer bilinearly (measured on a 40° turn
|
|
15
|
+
// of the same picture: CSS's text stair-stepped, WebGL's held; square on,
|
|
16
|
+
// the two were the same sharpness);
|
|
17
|
+
// - light on the things round a picture, and devices: `device()` builds a
|
|
18
|
+
// laptop, a phone or a browser window round a slab — a plain shape with
|
|
19
|
+
// no logo and no brand;
|
|
20
|
+
// - one lens for everything in it.
|
|
21
|
+
// It costs about a quarter more time a frame (40 ms against 32 ms for the
|
|
22
|
+
// same 4 s turn on an Apple M4). One scene, one of the two: a CSS layer and a
|
|
23
|
+
// canvas do not share a depth, so a slab of one cannot pass behind the other.
|
|
24
|
+
//
|
|
25
|
+
// A device is one block among the others. A laptop with the product on its
|
|
26
|
+
// screen is the most common picture in launch films — fine when the product
|
|
27
|
+
// lives on that device (a desktop app, a phone app), a habit otherwise.
|
|
28
|
+
//
|
|
29
|
+
// Honest by construction: every slab says where its picture came from
|
|
30
|
+
// (`source`: a saved screen and the part, or a file — required), and at(t)
|
|
31
|
+
// says where each lands in the picture (its quad, in the same shape as
|
|
32
|
+
// stage.at(t)), so what reads the film can tell which pixels are the
|
|
33
|
+
// product's and from where; sources() lists them all.
|
|
34
|
+
//
|
|
35
|
+
// Deterministic: no clock, no randomness, drawn in apply(t) and nowhere else,
|
|
36
|
+
// the drawing buffer kept for the frame grab. A video on a slab is copied
|
|
37
|
+
// each frame from the <video> the renderer steps on film time, so the slab
|
|
38
|
+
// shows the frame the film is at.
|
|
39
|
+
//
|
|
40
|
+
// The page imports three itself — `film init` puts it beside the kit — and
|
|
41
|
+
// hands it over, so a film without three never loads it:
|
|
42
|
+
//
|
|
43
|
+
// import * as THREE from "./kit/three.module.min.js";
|
|
44
|
+
// import { world } from "./kit/world.js";
|
|
45
|
+
// const w = world({ el: document.querySelector("#world"), camera: cam, three: THREE });
|
|
46
|
+
// const scr = w.slab("states/home/picture@2x.png", { box: { x: 0, y: 0, w: 1920, h: 1080 },
|
|
47
|
+
// source: { state: "home" }, rest: { scale: 0.55 } });
|
|
48
|
+
// w.device("laptop", scr);
|
|
49
|
+
// scr.set({ ry: 40 }, -Infinity); // turned from the start
|
|
50
|
+
// scr.to({ ry: 0 }, { start: 0.5, dur: 2.5 }); // and round to face the lens
|
|
51
|
+
// window.__film = { duration: 3, ready: w.ready };
|
|
52
|
+
// window.__render = (t) => w.apply(t); // returned: a video's frame is waited for
|
|
53
|
+
|
|
54
|
+
import { matrices as M, stage } from "./stage.js";
|
|
55
|
+
|
|
56
|
+
export { drop, explode, flip, stack, together } from "./stage.js";
|
|
57
|
+
|
|
58
|
+
/** @typedef {import("./stage.js").When} When */
|
|
59
|
+
/** @typedef {import("./stage.js").Pose} Pose */
|
|
60
|
+
/** @typedef {import("./stage.js").BoxLike} BoxLike */
|
|
61
|
+
/** @typedef {import("./stage.js").Box} Box */
|
|
62
|
+
/** @typedef {import("./stage.js").CameraLike} CameraLike */
|
|
63
|
+
/** @typedef {number[]} Mat */
|
|
64
|
+
/**
|
|
65
|
+
* @typedef {{ state: string, selector?: string } | { file: string, selector?: string }} Source
|
|
66
|
+
* where a picture came from: a saved screen (states/<state>/) and the part of it, or a file
|
|
67
|
+
*/
|
|
68
|
+
/** @typedef {string | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement} Src */
|
|
69
|
+
/**
|
|
70
|
+
* @typedef {object} WorldSlabOpts
|
|
71
|
+
* @property {Source} source where its picture came from — required
|
|
72
|
+
* @property {BoxLike} [box] where the slab sits on the stage (px); default its crop's box, else the whole stage
|
|
73
|
+
* @property {BoxLike} [crop] show this region of the picture, laid over the whole stage as stage.js lays it (px); default all of it
|
|
74
|
+
* @property {string} [name] what at(t) and warnings() call it
|
|
75
|
+
* @property {number} [radius] its corners' radius (px, default 0)
|
|
76
|
+
* @property {[number, number]} [origin] the point it turns about, as shares of its box (default its centre)
|
|
77
|
+
* @property {"hidden" | "visible"} [backface] its back when turned away (default hidden)
|
|
78
|
+
* @property {Partial<Pose>} [rest] its pose before any move
|
|
79
|
+
*/
|
|
80
|
+
/**
|
|
81
|
+
* @typedef {object} WorldSlab a slab in the world
|
|
82
|
+
* @property {string} name
|
|
83
|
+
* @property {Box} box
|
|
84
|
+
* @property {[number, number]} origin
|
|
85
|
+
* @property {Source} source
|
|
86
|
+
* @property {(to: Partial<Pose>, when: When) => WorldSlab} to move to a pose — only the fields given
|
|
87
|
+
* @property {(to: Partial<Pose>, at: number) => WorldSlab} set a cut: from `at` on these fields are this
|
|
88
|
+
* @property {(t: number) => Pose} pose its own pose at t
|
|
89
|
+
*/
|
|
90
|
+
/**
|
|
91
|
+
* @typedef {object} WorldSlabState a slab at t
|
|
92
|
+
* @property {string} name
|
|
93
|
+
* @property {Pose} pose its own pose
|
|
94
|
+
* @property {{ x: number, y: number }[]} quad its corners in the picture (px), top-left first, clockwise
|
|
95
|
+
* @property {number} area px² it covers in the picture
|
|
96
|
+
* @property {boolean} flat square on to the lens
|
|
97
|
+
* @property {boolean} facing its front toward the lens
|
|
98
|
+
* @property {boolean} visible drawn at all (faded out, behind the lens or its back turned are not)
|
|
99
|
+
* @property {number} opacity
|
|
100
|
+
* @property {number} depth its centre's z after the turn and the lens (px, + nearer)
|
|
101
|
+
* @property {Source} source where its picture came from
|
|
102
|
+
* @property {string | null} device the device round it, if any
|
|
103
|
+
*/
|
|
104
|
+
/**
|
|
105
|
+
* @typedef {object} Frame what one frame draws, as plain numbers (frame(t)): computed
|
|
106
|
+
* anywhere, drawn by draw() — apply(t) is draw(frame(t))
|
|
107
|
+
* @property {number} t
|
|
108
|
+
* @property {number[]} projection the lens, as three's projection matrix
|
|
109
|
+
* @property {[number, number, number]} eye where the lens is (three's space: y up)
|
|
110
|
+
* @property {{ matrix: number[], opacity: number, visible: boolean, shown: boolean }[]} slabs
|
|
111
|
+
* each slab's matrix (three's space); `visible`: its picture; `shown`: its device
|
|
112
|
+
*/
|
|
113
|
+
/**
|
|
114
|
+
* @typedef {object} DeviceOpts
|
|
115
|
+
* @property {string} [color] its body (default a dark grey, "#2b2d31"; a browser: "#e7e7e4")
|
|
116
|
+
* @property {number} [open] a laptop: degrees between the lid and the keyboard (default 100: the lid tipped back 10° when the keyboard is flat)
|
|
117
|
+
* @property {"light" | "dark"} [tone] a browser window's bar (default light)
|
|
118
|
+
*/
|
|
119
|
+
|
|
120
|
+
const RAD = Math.PI / 180;
|
|
121
|
+
/** @param {BoxLike} b @returns {Box} */
|
|
122
|
+
const boxOf = (b) => ({ x: b.x, y: b.y, w: b.w ?? b.width ?? 0, h: b.h ?? b.height ?? 0 });
|
|
123
|
+
// CSS has y down; three has y up. Its space here is the stage's, y turned over
|
|
124
|
+
const FLIP = [1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
|
125
|
+
/** a stage matrix (CSS, y down) as three's (y up), for geometry made y up
|
|
126
|
+
* @param {Mat} m */
|
|
127
|
+
const up = (m) => M.mul(FLIP, M.mul(m, FLIP));
|
|
128
|
+
const VIDEO = /\.(mp4|webm|mov|m4v|mkv)(\?|#|$)/i;
|
|
129
|
+
|
|
130
|
+
/** the source a slab names, checked */
|
|
131
|
+
/** @param {unknown} s @param {string} name @returns {Source} */
|
|
132
|
+
export function checkSource(s, name) {
|
|
133
|
+
const o = /** @type {Record<string, unknown> | null} */ (s && typeof s === "object" ? s : null);
|
|
134
|
+
const ok =
|
|
135
|
+
o &&
|
|
136
|
+
((typeof o.state === "string" && o.state.length > 0) ||
|
|
137
|
+
(typeof o.file === "string" && o.file.length > 0)) &&
|
|
138
|
+
(o.selector == null || typeof o.selector === "string");
|
|
139
|
+
if (!ok)
|
|
140
|
+
throw new Error(
|
|
141
|
+
`world: ${name} needs a source — where its picture came from: { state, selector } (a saved screen and the part of it) or { file } (a picture, a recording). Every texture points back to what it shows`,
|
|
142
|
+
);
|
|
143
|
+
return /** @type {Source} */ (o);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// --- devices -------------------------------------------------------------------
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* @typedef {object} DeviceShape a device's parts, in the slab's own px (y down, z toward the lens; the screen at z 0)
|
|
150
|
+
* @property {"laptop" | "phone" | "browser"} kind
|
|
151
|
+
* @property {{ x: number, y: number, w: number, h: number, r: number, depth: number }} body the lid, the phone, the window
|
|
152
|
+
* @property {number} screenRadius the screen's corners (px)
|
|
153
|
+
* @property {{ w: number, depth: number, thick: number, hinge: { y: number, z: number }, open: number } | null} deck a laptop's keyboard half
|
|
154
|
+
* @property {number} bar a browser window's bar (px tall, above the slab)
|
|
155
|
+
* @property {{ x: number, y: number, z: number, w: number, h: number, d: number }} bounds everything, as a box
|
|
156
|
+
*/
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* The shape of a device round a screen of w×h px — the numbers only. The
|
|
160
|
+
* proportions are read off the common shapes, not any one maker's: a laptop's
|
|
161
|
+
* bezel 3 % of the screen's width at the sides, 4.5 % above and 6 % below, its
|
|
162
|
+
* lid 1.2 % thick and its keyboard half 70 % as deep as it is wide; a phone's
|
|
163
|
+
* border 4.5 %, outer corners 16 % and its thickness 10 % of the screen's
|
|
164
|
+
* width (a 7.8 mm phone 71.5 mm wide is 11 %); a browser's bar 4.2 % of the
|
|
165
|
+
* window's width (a desktop browser's tabs and address bar are ≈ 80 px at
|
|
166
|
+
* 1920).
|
|
167
|
+
* @param {"laptop" | "phone" | "browser"} kind
|
|
168
|
+
* @param {number} w @param {number} h
|
|
169
|
+
* @param {DeviceOpts} [o]
|
|
170
|
+
* @returns {DeviceShape}
|
|
171
|
+
*/
|
|
172
|
+
export function deviceShape(kind, w, h, o = {}) {
|
|
173
|
+
if (!(w > 0 && h > 0)) throw new Error(`world: a ${kind} needs a screen with a size`);
|
|
174
|
+
if (kind === "laptop") {
|
|
175
|
+
const side = 0.03 * w;
|
|
176
|
+
const top = 0.045 * w;
|
|
177
|
+
const chin = 0.06 * w;
|
|
178
|
+
const depth = 0.012 * w;
|
|
179
|
+
const body = { x: -side, y: -top, w: w + 2 * side, h: h + top + chin, r: 0.03 * w, depth };
|
|
180
|
+
const open = o.open ?? 100;
|
|
181
|
+
if (!(open > 0 && open <= 180))
|
|
182
|
+
throw new Error("world: a laptop's open is degrees between 0 and 180");
|
|
183
|
+
const deck = {
|
|
184
|
+
w: body.w,
|
|
185
|
+
depth: 0.7 * body.w,
|
|
186
|
+
thick: 0.014 * w,
|
|
187
|
+
hinge: { y: body.y + body.h, z: -depth / 2 },
|
|
188
|
+
open,
|
|
189
|
+
};
|
|
190
|
+
// the keyboard half's far edge, out from the hinge at `open` from the lid
|
|
191
|
+
const fy = deck.hinge.y - deck.depth * Math.cos(open * RAD);
|
|
192
|
+
const fz = deck.hinge.z + deck.depth * Math.sin(open * RAD);
|
|
193
|
+
const y0 = body.y;
|
|
194
|
+
const y1 = Math.max(deck.hinge.y, fy) + deck.thick;
|
|
195
|
+
const z0 = Math.min(-depth - 2, fz - deck.thick);
|
|
196
|
+
const z1 = Math.max(0, fz);
|
|
197
|
+
return {
|
|
198
|
+
kind,
|
|
199
|
+
body,
|
|
200
|
+
screenRadius: 0,
|
|
201
|
+
deck,
|
|
202
|
+
bar: 0,
|
|
203
|
+
bounds: { x: body.x, y: y0, z: z0, w: body.w, h: y1 - y0, d: z1 - z0 },
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
if (kind === "phone") {
|
|
207
|
+
const b = 0.045 * w;
|
|
208
|
+
const depth = 0.1 * w;
|
|
209
|
+
const body = { x: -b, y: -b, w: w + 2 * b, h: h + 2 * b, r: 0.16 * w, depth };
|
|
210
|
+
return {
|
|
211
|
+
kind,
|
|
212
|
+
body,
|
|
213
|
+
screenRadius: 0.12 * w,
|
|
214
|
+
deck: null,
|
|
215
|
+
bar: 0,
|
|
216
|
+
bounds: { x: body.x, y: body.y, z: -depth - 2, w: body.w, h: body.h, d: depth + 2 },
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
if (kind === "browser") {
|
|
220
|
+
const bar = 0.042 * w;
|
|
221
|
+
const depth = 0.006 * w;
|
|
222
|
+
const body = { x: 0, y: -bar, w, h: h + bar, r: 0.008 * w, depth };
|
|
223
|
+
return {
|
|
224
|
+
kind,
|
|
225
|
+
body,
|
|
226
|
+
screenRadius: 0,
|
|
227
|
+
deck: null,
|
|
228
|
+
bar,
|
|
229
|
+
bounds: { x: 0, y: -bar, z: -depth - 2, w, h: h + bar, d: depth + 2 },
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
throw new Error(`world: no device "${kind}" (laptop, phone, browser)`);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// --- the world -----------------------------------------------------------------
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* A world of slabs drawn in WebGL — stage()'s shape: the picture's size, a
|
|
239
|
+
* lens, optionally the film's camera framing it. Without `three` it is
|
|
240
|
+
* numbers only (at(t), frame(t)), as a stage without `el` is.
|
|
241
|
+
* @param {object} [opts]
|
|
242
|
+
* @param {any} [opts.three] the three module the page imported (`import * as THREE from "./kit/three.module.min.js"`)
|
|
243
|
+
* @param {HTMLElement} [opts.el] where its canvas goes (at the element's top-left), or a <canvas> to draw in; default a canvas of its own (w.canvas), not on the page
|
|
244
|
+
* @param {number} [opts.width] the picture (px, default the camera's view, else 1920)
|
|
245
|
+
* @param {number} [opts.height] (default the camera's view, else 1080)
|
|
246
|
+
* @param {number} [opts.perspective] how far the lens is from the stage (px, default 2000 — as stage.js)
|
|
247
|
+
* @param {CameraLike} [opts.camera] a kit camera: its view at t frames the world
|
|
248
|
+
* @param {[number, number]} [opts.pivot] what turn() turns about (px, default the middle of the content)
|
|
249
|
+
* @param {string | null} [opts.background] a colour behind everything (default none: the page shows through)
|
|
250
|
+
* @param {number} [opts.pixelRatio] drawing-buffer px per CSS px (default the page's devicePixelRatio)
|
|
251
|
+
*/
|
|
252
|
+
export function world(opts = {}) {
|
|
253
|
+
const T = opts.three ?? null;
|
|
254
|
+
const st = stage({
|
|
255
|
+
...(opts.camera ? { camera: opts.camera } : {}),
|
|
256
|
+
...(opts.width ? { width: opts.width } : {}),
|
|
257
|
+
...(opts.height ? { height: opts.height } : {}),
|
|
258
|
+
...(opts.perspective ? { perspective: opts.perspective } : {}),
|
|
259
|
+
...(opts.pivot ? { pivot: opts.pivot } : {}),
|
|
260
|
+
});
|
|
261
|
+
const W = st.width;
|
|
262
|
+
const H = st.height;
|
|
263
|
+
const d = st.perspective;
|
|
264
|
+
const cam = opts.camera ?? null;
|
|
265
|
+
const content = cam?.content ?? { width: W, height: H };
|
|
266
|
+
const pivot = opts.pivot ?? [content.width / 2, content.height / 2];
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* @typedef {object} Rec a slab's own record
|
|
270
|
+
* @property {WorldSlab} handle
|
|
271
|
+
* @property {ReturnType<typeof st.slab>} inner the stage's slab: its poses
|
|
272
|
+
* @property {Box} box
|
|
273
|
+
* @property {Box | null} crop
|
|
274
|
+
* @property {Src} src
|
|
275
|
+
* @property {Source} source
|
|
276
|
+
* @property {number} radius
|
|
277
|
+
* @property {any} mesh
|
|
278
|
+
* @property {Tex | null} tex
|
|
279
|
+
* @property {{ kind: string, group: any, shape: DeviceShape, mats: any[] } | null} device
|
|
280
|
+
*/
|
|
281
|
+
/** @typedef {{ texture: any, live: (() => void) | null, sync?: () => Promise<unknown> | null, size: () => { w: number, h: number } | null, ready: Promise<unknown>, el: HTMLImageElement | HTMLCanvasElement | HTMLVideoElement }} Tex */
|
|
282
|
+
/** @type {Rec[]} */
|
|
283
|
+
const recs = [];
|
|
284
|
+
|
|
285
|
+
// --- three's side: one renderer, one scene, a lens set every frame ----------
|
|
286
|
+
/** @type {any} */
|
|
287
|
+
let renderer = null;
|
|
288
|
+
/** @type {any} */
|
|
289
|
+
let scene = null;
|
|
290
|
+
/** @type {any} */
|
|
291
|
+
let lens = null;
|
|
292
|
+
/** @type {HTMLCanvasElement | null} */
|
|
293
|
+
let canvas = null;
|
|
294
|
+
let aniso = 1;
|
|
295
|
+
if (T) {
|
|
296
|
+
const host = opts.el ?? null;
|
|
297
|
+
canvas =
|
|
298
|
+
host && host.tagName === "CANVAS"
|
|
299
|
+
? /** @type {HTMLCanvasElement} */ (host)
|
|
300
|
+
: document.createElement("canvas");
|
|
301
|
+
if (host && host !== canvas) {
|
|
302
|
+
Object.assign(canvas.style, { position: "absolute", left: "0px", top: "0px" });
|
|
303
|
+
host.appendChild(canvas);
|
|
304
|
+
}
|
|
305
|
+
renderer = new T.WebGLRenderer({
|
|
306
|
+
canvas,
|
|
307
|
+
antialias: true,
|
|
308
|
+
alpha: true,
|
|
309
|
+
preserveDrawingBuffer: true,
|
|
310
|
+
powerPreference: "high-performance",
|
|
311
|
+
});
|
|
312
|
+
renderer.setPixelRatio(opts.pixelRatio ?? globalThis.devicePixelRatio ?? 1);
|
|
313
|
+
renderer.setSize(W, H, false);
|
|
314
|
+
canvas.style.width = `${W}px`;
|
|
315
|
+
canvas.style.height = `${H}px`;
|
|
316
|
+
// UI colours come out as they went in: sRGB in, sRGB out, no tone curve
|
|
317
|
+
renderer.outputColorSpace = T.SRGBColorSpace;
|
|
318
|
+
renderer.toneMapping = T.NoToneMapping;
|
|
319
|
+
if (opts.background) renderer.setClearColor(new T.Color(opts.background), 1);
|
|
320
|
+
else renderer.setClearColor(0x000000, 0);
|
|
321
|
+
aniso = renderer.capabilities.getMaxAnisotropy();
|
|
322
|
+
scene = new T.Scene();
|
|
323
|
+
lens = new T.Camera();
|
|
324
|
+
// light only for what is round the pictures (screens are unlit): a sky
|
|
325
|
+
// over a darker floor, and a key light from up and to the left of the lens
|
|
326
|
+
scene.add(new T.HemisphereLight(0xffffff, 0x404040, 1.6));
|
|
327
|
+
const key = new T.DirectionalLight(0xffffff, 2.2);
|
|
328
|
+
key.position.set(-0.5, 1, 0.9);
|
|
329
|
+
scene.add(key);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/** @type {Map<unknown, Tex>} */
|
|
333
|
+
const texCache = new Map();
|
|
334
|
+
/** @param {Src} src @param {string} name @returns {Tex} */
|
|
335
|
+
const textureOf = (src, name) => {
|
|
336
|
+
const hit = texCache.get(src);
|
|
337
|
+
if (hit) return hit;
|
|
338
|
+
/** @type {Tex} */
|
|
339
|
+
let tx;
|
|
340
|
+
/** @param {any} tex */
|
|
341
|
+
const crisp = (tex) => {
|
|
342
|
+
tex.colorSpace = T.SRGBColorSpace;
|
|
343
|
+
tex.generateMipmaps = true;
|
|
344
|
+
tex.minFilter = T.LinearMipmapLinearFilter;
|
|
345
|
+
tex.magFilter = T.LinearFilter;
|
|
346
|
+
tex.anisotropy = aniso;
|
|
347
|
+
return tex;
|
|
348
|
+
};
|
|
349
|
+
let el = src;
|
|
350
|
+
if (typeof src === "string") {
|
|
351
|
+
if (VIDEO.test(src)) {
|
|
352
|
+
// a video of its own, on the page so the renderer steps it on film
|
|
353
|
+
// time — playing from film time 0 (give your own <video> to start it
|
|
354
|
+
// elsewhere)
|
|
355
|
+
const v = document.createElement("video");
|
|
356
|
+
v.muted = true;
|
|
357
|
+
v.playsInline = true;
|
|
358
|
+
v.preload = "auto";
|
|
359
|
+
v.autoplay = true;
|
|
360
|
+
v.src = src;
|
|
361
|
+
Object.assign(v.style, {
|
|
362
|
+
position: "absolute",
|
|
363
|
+
left: "0px",
|
|
364
|
+
top: "0px",
|
|
365
|
+
width: "2px",
|
|
366
|
+
height: "2px",
|
|
367
|
+
opacity: "0",
|
|
368
|
+
pointerEvents: "none",
|
|
369
|
+
});
|
|
370
|
+
(opts.el && opts.el.tagName !== "CANVAS" ? opts.el : document.body).appendChild(v);
|
|
371
|
+
el = v;
|
|
372
|
+
} else {
|
|
373
|
+
const im = new Image();
|
|
374
|
+
im.decoding = "sync";
|
|
375
|
+
im.src = src;
|
|
376
|
+
el = im;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
const node = /** @type {HTMLImageElement | HTMLCanvasElement | HTMLVideoElement} */ (el);
|
|
380
|
+
if (node.tagName === "VIDEO") {
|
|
381
|
+
const v = /** @type {HTMLVideoElement} */ (node);
|
|
382
|
+
// the frame the film is at, copied each frame: drawImage of a stepped
|
|
383
|
+
// video hands over the frame the renderer shows for it
|
|
384
|
+
const copy = document.createElement("canvas");
|
|
385
|
+
const g = /** @type {CanvasRenderingContext2D} */ (copy.getContext("2d"));
|
|
386
|
+
const texture = crisp(new T.Texture(copy));
|
|
387
|
+
tx = {
|
|
388
|
+
texture,
|
|
389
|
+
el: v,
|
|
390
|
+
size: () => (v.videoWidth ? { w: v.videoWidth, h: v.videoHeight } : null),
|
|
391
|
+
live: () => {
|
|
392
|
+
if (!v.videoWidth || v.readyState < 2) return;
|
|
393
|
+
if (copy.width !== v.videoWidth || copy.height !== v.videoHeight) {
|
|
394
|
+
copy.width = v.videoWidth;
|
|
395
|
+
copy.height = v.videoHeight;
|
|
396
|
+
texture.dispose();
|
|
397
|
+
}
|
|
398
|
+
g.drawImage(v, 0, 0);
|
|
399
|
+
texture.needsUpdate = true;
|
|
400
|
+
},
|
|
401
|
+
// The renderer shows a video's frame for t only after __render(t) has
|
|
402
|
+
// run, so a copy made in __render would be a frame late (measured on
|
|
403
|
+
// 2 s of a 60 fps recording against the same video shown directly:
|
|
404
|
+
// 34.6 dB). Asked to go where the film has it now, it says so
|
|
405
|
+
// (seeked) once that frame is there — then every frame matched the
|
|
406
|
+
// video shown directly, pixel for pixel.
|
|
407
|
+
sync: () => {
|
|
408
|
+
if (v.readyState < 1) return null;
|
|
409
|
+
const at = v.currentTime;
|
|
410
|
+
return new Promise((ok) => {
|
|
411
|
+
v.addEventListener("seeked", ok, { once: true });
|
|
412
|
+
v.currentTime = at;
|
|
413
|
+
});
|
|
414
|
+
},
|
|
415
|
+
ready:
|
|
416
|
+
v.readyState >= 2
|
|
417
|
+
? Promise.resolve()
|
|
418
|
+
: new Promise((ok, no) => {
|
|
419
|
+
v.addEventListener("loadeddata", ok, { once: true });
|
|
420
|
+
v.addEventListener(
|
|
421
|
+
"error",
|
|
422
|
+
() =>
|
|
423
|
+
no(
|
|
424
|
+
new Error(`world: ${name}: the video ${v.currentSrc || v.src} did not load`),
|
|
425
|
+
),
|
|
426
|
+
{ once: true },
|
|
427
|
+
);
|
|
428
|
+
}),
|
|
429
|
+
};
|
|
430
|
+
} else if (node.tagName === "CANVAS") {
|
|
431
|
+
const c = /** @type {HTMLCanvasElement} */ (node);
|
|
432
|
+
const texture = crisp(new T.Texture(c));
|
|
433
|
+
tx = {
|
|
434
|
+
texture,
|
|
435
|
+
el: c,
|
|
436
|
+
size: () => ({ w: c.width, h: c.height }),
|
|
437
|
+
// the page draws on it: taken again each frame
|
|
438
|
+
live: () => {
|
|
439
|
+
texture.needsUpdate = true;
|
|
440
|
+
},
|
|
441
|
+
ready: Promise.resolve(),
|
|
442
|
+
};
|
|
443
|
+
} else {
|
|
444
|
+
const im = /** @type {HTMLImageElement} */ (node);
|
|
445
|
+
const texture = crisp(new T.Texture(im));
|
|
446
|
+
const ready = (im.complete && im.naturalWidth ? Promise.resolve() : im.decode()).then(
|
|
447
|
+
() => {
|
|
448
|
+
texture.needsUpdate = true;
|
|
449
|
+
},
|
|
450
|
+
() => {
|
|
451
|
+
throw new Error(`world: ${name}: the picture ${im.currentSrc || im.src} did not load`);
|
|
452
|
+
},
|
|
453
|
+
);
|
|
454
|
+
tx = {
|
|
455
|
+
texture,
|
|
456
|
+
el: im,
|
|
457
|
+
size: () => (im.naturalWidth ? { w: im.naturalWidth, h: im.naturalHeight } : null),
|
|
458
|
+
live: null,
|
|
459
|
+
ready,
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
texCache.set(src, tx);
|
|
463
|
+
return tx;
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
/** a rounded rectangle as a three Shape, y up: x from x0, y from y0 down by h
|
|
467
|
+
* @param {number} x0 @param {number} y0 @param {number} w @param {number} h @param {number} r */
|
|
468
|
+
const roundRect = (x0, y0, w, h, r) => {
|
|
469
|
+
const s = new T.Shape();
|
|
470
|
+
const k = Math.max(0, Math.min(r, w / 2, h / 2));
|
|
471
|
+
const top = -y0;
|
|
472
|
+
const bot = -(y0 + h);
|
|
473
|
+
s.moveTo(x0 + k, top);
|
|
474
|
+
s.lineTo(x0 + w - k, top);
|
|
475
|
+
if (k) s.quadraticCurveTo(x0 + w, top, x0 + w, top - k);
|
|
476
|
+
s.lineTo(x0 + w, bot + k);
|
|
477
|
+
if (k) s.quadraticCurveTo(x0 + w, bot, x0 + w - k, bot);
|
|
478
|
+
s.lineTo(x0 + k, bot);
|
|
479
|
+
if (k) s.quadraticCurveTo(x0, bot, x0, bot + k);
|
|
480
|
+
s.lineTo(x0, top - k);
|
|
481
|
+
if (k) s.quadraticCurveTo(x0, top, x0 + k, top);
|
|
482
|
+
return s;
|
|
483
|
+
};
|
|
484
|
+
/** a flat face of a rounded rectangle (y down, as the stage has it), its uv
|
|
485
|
+
* running over [u0, u1] × [v0, v1] across it
|
|
486
|
+
* @param {Box} b @param {number} r @param {[number, number, number, number]} [uv] u0, v0 (its top), u1, v1 (its bottom) */
|
|
487
|
+
const face = (b, r, uv = [0, 1, 1, 0]) => {
|
|
488
|
+
const g = new T.ShapeGeometry(roundRect(b.x, b.y, b.w, b.h, r), 16);
|
|
489
|
+
const pos = g.attributes.position;
|
|
490
|
+
const tex = g.attributes.uv;
|
|
491
|
+
for (let i = 0; i < pos.count; i++) {
|
|
492
|
+
const px = (pos.getX(i) - b.x) / b.w;
|
|
493
|
+
const py = (-pos.getY(i) - b.y) / b.h;
|
|
494
|
+
tex.setXY(i, uv[0] + (uv[2] - uv[0]) * px, uv[1] + (uv[3] - uv[1]) * py);
|
|
495
|
+
}
|
|
496
|
+
tex.needsUpdate = true;
|
|
497
|
+
return g;
|
|
498
|
+
};
|
|
499
|
+
/** a rounded slab of material `depth` thick behind z = back (y down as the stage)
|
|
500
|
+
* @param {Box & { r: number }} b @param {number} depth @param {number} back */
|
|
501
|
+
const block = (b, depth, back) => {
|
|
502
|
+
const g = new T.ExtrudeGeometry(roundRect(b.x, b.y, b.w, b.h, b.r), {
|
|
503
|
+
depth,
|
|
504
|
+
bevelEnabled: false,
|
|
505
|
+
curveSegments: 16,
|
|
506
|
+
});
|
|
507
|
+
g.translate(0, 0, back - depth);
|
|
508
|
+
return g;
|
|
509
|
+
};
|
|
510
|
+
|
|
511
|
+
/** the slab's picture: its geometry with the crop as its uv */
|
|
512
|
+
/** @param {Rec} r */
|
|
513
|
+
const screenGeometry = (r) => {
|
|
514
|
+
const c = r.crop;
|
|
515
|
+
const uv = /** @type {[number, number, number, number]} */ (
|
|
516
|
+
c
|
|
517
|
+
? [
|
|
518
|
+
c.x / content.width,
|
|
519
|
+
1 - c.y / content.height,
|
|
520
|
+
(c.x + c.w) / content.width,
|
|
521
|
+
1 - (c.y + c.h) / content.height,
|
|
522
|
+
]
|
|
523
|
+
: [0, 1, 1, 0]
|
|
524
|
+
);
|
|
525
|
+
return face({ x: 0, y: 0, w: r.box.w, h: r.box.h }, r.radius, uv);
|
|
526
|
+
};
|
|
527
|
+
|
|
528
|
+
/** a material that fades with its slab */
|
|
529
|
+
/** @param {any} m */
|
|
530
|
+
const fades = (m) => {
|
|
531
|
+
m.userData.fades = true;
|
|
532
|
+
return m;
|
|
533
|
+
};
|
|
534
|
+
/** a material at an opacity: blended only while it is faded */
|
|
535
|
+
/** @param {any} m @param {number} op */
|
|
536
|
+
const opacityOf = (m, op) => {
|
|
537
|
+
m.opacity = op;
|
|
538
|
+
const faded = op < 1;
|
|
539
|
+
if (m.transparent !== faded) {
|
|
540
|
+
m.transparent = faded;
|
|
541
|
+
m.depthWrite = !faded;
|
|
542
|
+
m.needsUpdate = true;
|
|
543
|
+
}
|
|
544
|
+
};
|
|
545
|
+
|
|
546
|
+
/** the canvas a laptop's keyboard half wears: keys and a trackpad, drawn
|
|
547
|
+
* the same every time */
|
|
548
|
+
/** @param {number} w @param {number} h @param {string} body */
|
|
549
|
+
const deckPicture = (w, h, body) => {
|
|
550
|
+
const k = Math.min(1, 1024 / w);
|
|
551
|
+
const c = document.createElement("canvas");
|
|
552
|
+
c.width = Math.round(w * k);
|
|
553
|
+
c.height = Math.round(h * k);
|
|
554
|
+
const g = /** @type {CanvasRenderingContext2D} */ (c.getContext("2d"));
|
|
555
|
+
const cw = c.width;
|
|
556
|
+
const ch = c.height;
|
|
557
|
+
g.fillStyle = body;
|
|
558
|
+
g.fillRect(0, 0, cw, ch);
|
|
559
|
+
// the keyboard: 6 rows, 14 keys a row in its well, from 6 % to 50 % of the depth
|
|
560
|
+
const kx = 0.08 * cw;
|
|
561
|
+
const kw = 0.84 * cw;
|
|
562
|
+
const ky = 0.06 * ch;
|
|
563
|
+
const kh = 0.44 * ch;
|
|
564
|
+
g.fillStyle = "rgba(0,0,0,0.35)";
|
|
565
|
+
g.fillRect(kx - 0.006 * cw, ky - 0.006 * cw, kw + 0.012 * cw, kh + 0.012 * cw);
|
|
566
|
+
const gap = 0.0045 * cw;
|
|
567
|
+
const rows = 6;
|
|
568
|
+
const rh = (kh - gap * (rows - 1)) / rows;
|
|
569
|
+
g.fillStyle = "#121214";
|
|
570
|
+
for (let j = 0; j < rows; j++) {
|
|
571
|
+
const y = ky + j * (rh + gap);
|
|
572
|
+
if (j === rows - 1) {
|
|
573
|
+
// the bottom row: a long space bar in the middle
|
|
574
|
+
const unit = (kw - gap * 8) / 13;
|
|
575
|
+
let x = kx;
|
|
576
|
+
for (const n of [1, 1, 1, 1.5, 5, 1.5, 1, 1]) {
|
|
577
|
+
g.fillRect(x, y, unit * n, rh);
|
|
578
|
+
x += unit * n + gap;
|
|
579
|
+
}
|
|
580
|
+
continue;
|
|
581
|
+
}
|
|
582
|
+
const kwid = (kw - gap * 13) / 14;
|
|
583
|
+
for (let i = 0; i < 14; i++) g.fillRect(kx + i * (kwid + gap), y, kwid, rh);
|
|
584
|
+
}
|
|
585
|
+
// the trackpad, centred below
|
|
586
|
+
g.fillStyle = "rgba(255,255,255,0.07)";
|
|
587
|
+
g.fillRect(0.3 * cw, 0.56 * ch, 0.4 * cw, 0.34 * ch);
|
|
588
|
+
g.strokeStyle = "rgba(0,0,0,0.25)";
|
|
589
|
+
g.lineWidth = Math.max(1, 0.002 * cw);
|
|
590
|
+
g.strokeRect(0.3 * cw, 0.56 * ch, 0.4 * cw, 0.34 * ch);
|
|
591
|
+
return c;
|
|
592
|
+
};
|
|
593
|
+
|
|
594
|
+
/** the canvas a browser window's front wears: its bar, three dots, an address field */
|
|
595
|
+
/** @param {number} w @param {number} h @param {number} bar @param {"light" | "dark"} tone @param {string} body */
|
|
596
|
+
const barPicture = (w, h, bar, tone, body) => {
|
|
597
|
+
const k = Math.min(1, 2048 / w);
|
|
598
|
+
const c = document.createElement("canvas");
|
|
599
|
+
c.width = Math.round(w * k);
|
|
600
|
+
c.height = Math.round(h * k);
|
|
601
|
+
const g = /** @type {CanvasRenderingContext2D} */ (c.getContext("2d"));
|
|
602
|
+
const b = bar * k;
|
|
603
|
+
g.fillStyle = body;
|
|
604
|
+
g.fillRect(0, 0, c.width, c.height);
|
|
605
|
+
g.fillStyle = tone === "dark" ? "rgba(0,0,0,0.25)" : "rgba(0,0,0,0.06)";
|
|
606
|
+
g.fillRect(0, b - Math.max(1, b * 0.02), c.width, Math.max(1, b * 0.02));
|
|
607
|
+
const dot = b * 0.13;
|
|
608
|
+
g.fillStyle = tone === "dark" ? "#5a5a5e" : "#c4c4c0";
|
|
609
|
+
for (let i = 0; i < 3; i++) {
|
|
610
|
+
g.beginPath();
|
|
611
|
+
g.arc(b * 0.45 + i * dot * 3.1, b / 2, dot, 0, Math.PI * 2);
|
|
612
|
+
g.fill();
|
|
613
|
+
}
|
|
614
|
+
g.fillStyle = tone === "dark" ? "#3a3a3e" : "#ffffff";
|
|
615
|
+
const fx = c.width * 0.25;
|
|
616
|
+
const fw = c.width * 0.5;
|
|
617
|
+
const fh = b * 0.52;
|
|
618
|
+
const fy = (b - fh) / 2;
|
|
619
|
+
g.beginPath();
|
|
620
|
+
g.roundRect(fx, fy, fw, fh, fh / 2);
|
|
621
|
+
g.fill();
|
|
622
|
+
return c;
|
|
623
|
+
};
|
|
624
|
+
|
|
625
|
+
/** @param {"laptop" | "phone" | "browser"} kind @param {DeviceShape} sh @param {DeviceOpts} o */
|
|
626
|
+
const buildDevice = (kind, sh, o) => {
|
|
627
|
+
const group = new T.Group();
|
|
628
|
+
group.matrixAutoUpdate = false;
|
|
629
|
+
/** @type {any[]} */
|
|
630
|
+
const mats = [];
|
|
631
|
+
/** @param {any} m */
|
|
632
|
+
const mat = (m) => {
|
|
633
|
+
mats.push(fades(m));
|
|
634
|
+
return m;
|
|
635
|
+
};
|
|
636
|
+
const color =
|
|
637
|
+
o.color ?? (kind === "browser" ? (o.tone === "dark" ? "#2a2a2d" : "#e7e7e4") : "#2b2d31");
|
|
638
|
+
const metal = () =>
|
|
639
|
+
mat(
|
|
640
|
+
new T.MeshStandardMaterial({ color: new T.Color(color), roughness: 0.42, metalness: 0.25 }),
|
|
641
|
+
);
|
|
642
|
+
const glass = () =>
|
|
643
|
+
mat(new T.MeshStandardMaterial({ color: 0x0b0b0c, roughness: 0.18, metalness: 0 }));
|
|
644
|
+
const b = sh.body;
|
|
645
|
+
if (kind === "browser") {
|
|
646
|
+
const front = new T.Texture(barPicture(b.w, b.h, sh.bar, o.tone ?? "light", color));
|
|
647
|
+
front.colorSpace = T.SRGBColorSpace;
|
|
648
|
+
front.anisotropy = aniso;
|
|
649
|
+
front.needsUpdate = true;
|
|
650
|
+
group.add(
|
|
651
|
+
new T.Mesh(face(b, b.r), mat(new T.MeshBasicMaterial({ map: front, toneMapped: false }))),
|
|
652
|
+
);
|
|
653
|
+
group.children[0].position.z = -1;
|
|
654
|
+
group.add(new T.Mesh(block(b, b.depth, -2), metal()));
|
|
655
|
+
} else {
|
|
656
|
+
// the front: dark glass round the screen; behind it the body
|
|
657
|
+
const fg = face(b, b.r);
|
|
658
|
+
fg.translate(0, 0, -1);
|
|
659
|
+
group.add(new T.Mesh(fg, glass()));
|
|
660
|
+
group.add(new T.Mesh(block(b, b.depth, -2), metal()));
|
|
661
|
+
}
|
|
662
|
+
if (sh.deck) {
|
|
663
|
+
const dk = sh.deck;
|
|
664
|
+
// the keyboard half: its top in its own x (across) and y (out from the
|
|
665
|
+
// hinge), turned to `open` degrees from the lid about the hinge
|
|
666
|
+
const half = new T.Group();
|
|
667
|
+
const deckBox = { x: b.x, y: 0, w: dk.w, h: dk.depth, r: b.r };
|
|
668
|
+
const slabG = new T.ExtrudeGeometry(roundRect(deckBox.x, 0, dk.w, dk.depth, b.r), {
|
|
669
|
+
depth: dk.thick,
|
|
670
|
+
bevelEnabled: false,
|
|
671
|
+
curveSegments: 16,
|
|
672
|
+
});
|
|
673
|
+
half.add(new T.Mesh(slabG, metal()));
|
|
674
|
+
const topTex = new T.Texture(deckPicture(dk.w, dk.depth, color));
|
|
675
|
+
topTex.colorSpace = T.SRGBColorSpace;
|
|
676
|
+
topTex.anisotropy = aniso;
|
|
677
|
+
topTex.generateMipmaps = true;
|
|
678
|
+
topTex.minFilter = T.LinearMipmapLinearFilter;
|
|
679
|
+
topTex.needsUpdate = true;
|
|
680
|
+
const topG = face(deckBox, b.r);
|
|
681
|
+
topG.translate(0, 0, -0.6);
|
|
682
|
+
half.add(
|
|
683
|
+
new T.Mesh(
|
|
684
|
+
topG,
|
|
685
|
+
mat(
|
|
686
|
+
new T.MeshStandardMaterial({
|
|
687
|
+
map: topTex,
|
|
688
|
+
roughness: 0.5,
|
|
689
|
+
metalness: 0.15,
|
|
690
|
+
side: T.DoubleSide,
|
|
691
|
+
}),
|
|
692
|
+
),
|
|
693
|
+
),
|
|
694
|
+
);
|
|
695
|
+
// its axes in the lid's space (y up): across, out from the hinge, and
|
|
696
|
+
// into the body (the extrusion's +z, away from the keys)
|
|
697
|
+
const th = dk.open * RAD;
|
|
698
|
+
const out = new T.Vector3(0, Math.cos(th), Math.sin(th));
|
|
699
|
+
const across = new T.Vector3(1, 0, 0);
|
|
700
|
+
const into = new T.Vector3().crossVectors(across, out);
|
|
701
|
+
// the shape's y runs down from 0 to -depth (y up): out is its −y
|
|
702
|
+
const basis = new T.Matrix4().makeBasis(across, out.clone().negate(), into);
|
|
703
|
+
basis.setPosition(0, -dk.hinge.y, dk.hinge.z);
|
|
704
|
+
half.matrixAutoUpdate = false;
|
|
705
|
+
half.matrix.copy(basis);
|
|
706
|
+
group.add(half);
|
|
707
|
+
}
|
|
708
|
+
group.traverse((/** @type {any} */ x) => {
|
|
709
|
+
x.frustumCulled = false;
|
|
710
|
+
});
|
|
711
|
+
scene.add(group);
|
|
712
|
+
return { kind, group, shape: sh, mats };
|
|
713
|
+
};
|
|
714
|
+
|
|
715
|
+
/** the slab's matrix in the stage at t: turned and sized about its origin,
|
|
716
|
+
* moved from where it sat, then the world's turn and the lens's travel —
|
|
717
|
+
* stage.js's own sum */
|
|
718
|
+
/** @param {Rec} r @param {number} t */
|
|
719
|
+
const placed = (r, t) => {
|
|
720
|
+
const p = r.inner.pose(t);
|
|
721
|
+
const w = st.world(t);
|
|
722
|
+
const b = r.box;
|
|
723
|
+
const o = r.handle.origin;
|
|
724
|
+
const ox = b.w * o[0];
|
|
725
|
+
const oy = b.h * o[1];
|
|
726
|
+
const own = M.mul(
|
|
727
|
+
M.mul(
|
|
728
|
+
M.translate(b.x + ox + p.x, b.y + oy + p.y, p.z),
|
|
729
|
+
M.mul(M.mul(M.rotateX(p.rx), M.rotateY(p.ry)), M.rotateZ(p.rz)),
|
|
730
|
+
),
|
|
731
|
+
// sized evenly in depth too, so a device round it keeps its shape
|
|
732
|
+
M.mul(
|
|
733
|
+
[p.scale, 0, 0, 0, 0, p.scale, 0, 0, 0, 0, p.scale, 0, 0, 0, 0, 1],
|
|
734
|
+
M.translate(-ox, -oy),
|
|
735
|
+
),
|
|
736
|
+
);
|
|
737
|
+
const turned = M.mul(
|
|
738
|
+
M.mul(
|
|
739
|
+
M.translate(pivot[0], pivot[1], w.z),
|
|
740
|
+
M.mul(M.mul(M.rotateX(w.rx), M.rotateY(w.ry)), M.rotateZ(w.rz)),
|
|
741
|
+
),
|
|
742
|
+
M.translate(-pivot[0], -pivot[1]),
|
|
743
|
+
);
|
|
744
|
+
return M.mul(turned, own);
|
|
745
|
+
};
|
|
746
|
+
|
|
747
|
+
/** the lens at t as three's projection: the stage's camera view and
|
|
748
|
+
* perspective (stage.js's), then the picture's px as clip space; depth
|
|
749
|
+
* from 2 % of the lens's distance in front of it (where a slab is gone)
|
|
750
|
+
* to 100 lens-distances behind */
|
|
751
|
+
/** @param {number} t */
|
|
752
|
+
const lensAt = (t) => {
|
|
753
|
+
let m = M.identity();
|
|
754
|
+
let cx = content.width / 2;
|
|
755
|
+
let cy = content.height / 2;
|
|
756
|
+
if (cam) {
|
|
757
|
+
const v = cam.at(t);
|
|
758
|
+
const s = v.scale ?? W / v.w;
|
|
759
|
+
m = M.mul(M.translate(W / 2 - v.cx * s, H / 2 - v.cy * s), M.scale(s));
|
|
760
|
+
const j = cam.jitter?.(t);
|
|
761
|
+
if (j && (j.x || j.y || j.rot))
|
|
762
|
+
m = M.mul(
|
|
763
|
+
M.mul(M.translate(W / 2 + j.x, H / 2 + j.y), M.rotateZ(j.rot)),
|
|
764
|
+
M.mul(M.translate(-W / 2, -H / 2), m),
|
|
765
|
+
);
|
|
766
|
+
cx = v.cx;
|
|
767
|
+
cy = v.cy;
|
|
768
|
+
}
|
|
769
|
+
const persp = M.mul(M.mul(M.translate(cx, cy), M.perspective(d)), M.translate(-cx, -cy));
|
|
770
|
+
// depth: z / (1 − z/d) runs from far to near; mapped onto −1 (near) … 1 (far)
|
|
771
|
+
/** @param {number} z */
|
|
772
|
+
const u = (z) => (z * d) / (d - z);
|
|
773
|
+
const un = u(0.98 * d);
|
|
774
|
+
const uf = u(-100 * d);
|
|
775
|
+
const a = -2 / (un - uf);
|
|
776
|
+
const bb = -1 - a * un;
|
|
777
|
+
const clip = [2 / W, 0, 0, 0, 0, -2 / H, 0, 0, 0, 0, a, 0, -1, 1, bb, 1];
|
|
778
|
+
const eye = /** @type {[number, number, number]} */ ([cx, -cy, d]);
|
|
779
|
+
const proj = M.mul(
|
|
780
|
+
clip,
|
|
781
|
+
M.mul(m, M.mul(persp, M.mul(FLIP, M.translate(eye[0], eye[1], eye[2])))),
|
|
782
|
+
);
|
|
783
|
+
return { proj, eye };
|
|
784
|
+
};
|
|
785
|
+
|
|
786
|
+
/** @param {number} t @returns {WorldSlabState[]} */
|
|
787
|
+
const at = (t) =>
|
|
788
|
+
st.at(t).map((s, i) => {
|
|
789
|
+
const r = /** @type {Rec} */ (recs[i]);
|
|
790
|
+
return {
|
|
791
|
+
name: s.name,
|
|
792
|
+
pose: s.pose,
|
|
793
|
+
quad: s.quad,
|
|
794
|
+
area: s.area,
|
|
795
|
+
flat: s.flat,
|
|
796
|
+
facing: s.facing,
|
|
797
|
+
visible: s.style.visibility === "visible",
|
|
798
|
+
opacity: Number(s.style.opacity),
|
|
799
|
+
depth: s.depth,
|
|
800
|
+
source: r.source,
|
|
801
|
+
device: r.device?.kind ?? null,
|
|
802
|
+
};
|
|
803
|
+
});
|
|
804
|
+
|
|
805
|
+
/** @param {number} t @returns {Frame} */
|
|
806
|
+
const frame = (t) => {
|
|
807
|
+
const l = lensAt(t);
|
|
808
|
+
const states = st.at(t);
|
|
809
|
+
return {
|
|
810
|
+
t,
|
|
811
|
+
projection: l.proj,
|
|
812
|
+
eye: l.eye,
|
|
813
|
+
slabs: states.map((s, i) => {
|
|
814
|
+
const op = Number(s.style.opacity);
|
|
815
|
+
return {
|
|
816
|
+
matrix: up(placed(/** @type {Rec} */ (recs[i]), t)),
|
|
817
|
+
opacity: op,
|
|
818
|
+
visible: s.style.visibility === "visible",
|
|
819
|
+
shown: op > 0 && Number.isFinite(s.area),
|
|
820
|
+
};
|
|
821
|
+
}),
|
|
822
|
+
};
|
|
823
|
+
};
|
|
824
|
+
|
|
825
|
+
/** @param {Frame} f */
|
|
826
|
+
const draw = (f) => {
|
|
827
|
+
if (!T) throw new Error("world: drawing needs three — world({ three: THREE, … })");
|
|
828
|
+
lens.position.set(f.eye[0], f.eye[1], f.eye[2]);
|
|
829
|
+
lens.updateMatrixWorld(true);
|
|
830
|
+
lens.projectionMatrix.fromArray(f.projection);
|
|
831
|
+
lens.projectionMatrixInverse.copy(lens.projectionMatrix).invert();
|
|
832
|
+
const live = new Set();
|
|
833
|
+
f.slabs.forEach((s, i) => {
|
|
834
|
+
const r = recs[i];
|
|
835
|
+
if (!r) return;
|
|
836
|
+
r.mesh.matrix.fromArray(s.matrix);
|
|
837
|
+
r.mesh.matrixWorldNeedsUpdate = true;
|
|
838
|
+
r.mesh.visible = s.visible;
|
|
839
|
+
opacityOf(r.mesh.material, s.opacity);
|
|
840
|
+
if (r.device) {
|
|
841
|
+
r.device.group.matrix.fromArray(s.matrix);
|
|
842
|
+
r.device.group.matrixWorldNeedsUpdate = true;
|
|
843
|
+
r.device.group.visible = s.shown;
|
|
844
|
+
for (const m of r.device.mats) opacityOf(m, s.opacity);
|
|
845
|
+
}
|
|
846
|
+
if (s.visible && r.tex?.live) live.add(r.tex);
|
|
847
|
+
});
|
|
848
|
+
for (const tx of live) /** @type {Tex} */ (tx).live?.();
|
|
849
|
+
renderer.render(scene, lens);
|
|
850
|
+
};
|
|
851
|
+
|
|
852
|
+
/**
|
|
853
|
+
* A slab: a picture flat in space, with a pose over time (stage.js's).
|
|
854
|
+
* @param {Src} src a picture's URL, a video's URL (it plays from film time 0), or an <img>, <canvas> or <video>
|
|
855
|
+
* @param {WorldSlabOpts} o
|
|
856
|
+
* @returns {WorldSlab}
|
|
857
|
+
*/
|
|
858
|
+
const slab = (src, o) => {
|
|
859
|
+
const name = o?.name ?? `slab ${recs.length + 1}`;
|
|
860
|
+
const source = checkSource(o?.source, name);
|
|
861
|
+
if (src == null || (typeof src !== "string" && !(typeof src === "object" && "tagName" in src)))
|
|
862
|
+
throw new Error(
|
|
863
|
+
`world: ${name}: a picture's or a video's URL, or an <img>, <canvas> or <video>`,
|
|
864
|
+
);
|
|
865
|
+
const crop = o.crop ? boxOf(o.crop) : null;
|
|
866
|
+
const box = o.box
|
|
867
|
+
? boxOf(o.box)
|
|
868
|
+
: (crop ?? { x: 0, y: 0, w: content.width, h: content.height });
|
|
869
|
+
if (!(box.w > 0 && box.h > 0)) throw new Error(`world: ${name} needs a box with a size`);
|
|
870
|
+
const inner = st.slab(null, {
|
|
871
|
+
box,
|
|
872
|
+
name,
|
|
873
|
+
...(o.origin ? { origin: o.origin } : {}),
|
|
874
|
+
...(o.backface ? { backface: o.backface } : {}),
|
|
875
|
+
...(o.rest ? { rest: o.rest } : {}),
|
|
876
|
+
});
|
|
877
|
+
/** @type {WorldSlab} */
|
|
878
|
+
const handle = {
|
|
879
|
+
name,
|
|
880
|
+
box,
|
|
881
|
+
origin: inner.origin,
|
|
882
|
+
source,
|
|
883
|
+
to(to, when) {
|
|
884
|
+
inner.to(to, when);
|
|
885
|
+
return handle;
|
|
886
|
+
},
|
|
887
|
+
set(to, at) {
|
|
888
|
+
inner.set(to, at);
|
|
889
|
+
return handle;
|
|
890
|
+
},
|
|
891
|
+
pose: (t) => inner.pose(t),
|
|
892
|
+
};
|
|
893
|
+
/** @type {Rec} */
|
|
894
|
+
const r = {
|
|
895
|
+
handle,
|
|
896
|
+
inner,
|
|
897
|
+
box,
|
|
898
|
+
crop,
|
|
899
|
+
src,
|
|
900
|
+
source,
|
|
901
|
+
radius: o.radius ?? 0,
|
|
902
|
+
mesh: null,
|
|
903
|
+
tex: null,
|
|
904
|
+
device: null,
|
|
905
|
+
};
|
|
906
|
+
if (T) {
|
|
907
|
+
r.tex = textureOf(src, name);
|
|
908
|
+
const m = new T.MeshBasicMaterial({
|
|
909
|
+
map: r.tex.texture,
|
|
910
|
+
toneMapped: false,
|
|
911
|
+
side: (o.backface ?? "hidden") === "visible" ? T.DoubleSide : T.FrontSide,
|
|
912
|
+
});
|
|
913
|
+
r.mesh = new T.Mesh(screenGeometry(r), m);
|
|
914
|
+
r.mesh.matrixAutoUpdate = false;
|
|
915
|
+
r.mesh.frustumCulled = false;
|
|
916
|
+
scene.add(r.mesh);
|
|
917
|
+
}
|
|
918
|
+
recs.push(r);
|
|
919
|
+
return handle;
|
|
920
|
+
};
|
|
921
|
+
|
|
922
|
+
/**
|
|
923
|
+
* A device round a slab — a laptop, a phone, a browser window: a plain
|
|
924
|
+
* shape, no logo, no brand. It moves with its slab (pose the slab).
|
|
925
|
+
* @param {"laptop" | "phone" | "browser"} kind
|
|
926
|
+
* @param {WorldSlab} sl a slab of this world: its screen
|
|
927
|
+
* @param {DeviceOpts} [o]
|
|
928
|
+
*/
|
|
929
|
+
const device = (kind, sl, o = {}) => {
|
|
930
|
+
const r = recs.find((x) => x.handle === sl);
|
|
931
|
+
if (!r) throw new Error(`world: a ${kind} goes round a slab of this world (w.slab(…))`);
|
|
932
|
+
if (r.device) throw new Error(`world: ${r.handle.name} already has a ${r.device.kind}`);
|
|
933
|
+
const shape = deviceShape(kind, r.box.w, r.box.h, o);
|
|
934
|
+
if (T) {
|
|
935
|
+
if (shape.screenRadius && !r.radius) {
|
|
936
|
+
r.radius = shape.screenRadius;
|
|
937
|
+
r.mesh.geometry.dispose();
|
|
938
|
+
r.mesh.geometry = screenGeometry(r);
|
|
939
|
+
}
|
|
940
|
+
r.device = buildDevice(kind, shape, o);
|
|
941
|
+
} else r.device = { kind, group: null, shape, mats: [] };
|
|
942
|
+
return {
|
|
943
|
+
kind,
|
|
944
|
+
name: r.handle.name,
|
|
945
|
+
slab: sl,
|
|
946
|
+
shape,
|
|
947
|
+
/** what it takes up, in the stage's px where its slab sits (z toward the lens) */
|
|
948
|
+
bounds: {
|
|
949
|
+
x: r.box.x + shape.bounds.x,
|
|
950
|
+
y: r.box.y + shape.bounds.y,
|
|
951
|
+
z: shape.bounds.z,
|
|
952
|
+
w: shape.bounds.w,
|
|
953
|
+
h: shape.bounds.h,
|
|
954
|
+
d: shape.bounds.d,
|
|
955
|
+
},
|
|
956
|
+
/** @param {Partial<Pose>} to @param {When} when */
|
|
957
|
+
to: (to, when) => sl.to(to, when),
|
|
958
|
+
/** @param {Partial<Pose>} to @param {number} at */
|
|
959
|
+
set: (to, at) => sl.set(to, at),
|
|
960
|
+
/** @param {number} t */
|
|
961
|
+
pose: (t) => sl.pose(t),
|
|
962
|
+
};
|
|
963
|
+
};
|
|
964
|
+
|
|
965
|
+
return {
|
|
966
|
+
width: W,
|
|
967
|
+
height: H,
|
|
968
|
+
perspective: d,
|
|
969
|
+
/** the canvas it draws in (null without three) */
|
|
970
|
+
canvas,
|
|
971
|
+
/** three's renderer and scene, for what the kit does not do (null without three) */
|
|
972
|
+
renderer,
|
|
973
|
+
scene,
|
|
974
|
+
slab,
|
|
975
|
+
device,
|
|
976
|
+
/** the whole world turns about its pivot (stage.js's turn)
|
|
977
|
+
* @param {{ rx?: number, ry?: number, rz?: number }} to @param {When} when */
|
|
978
|
+
turn: (to, when) => st.turn(to, when),
|
|
979
|
+
/** the lens travels into the world (stage.js's dolly)
|
|
980
|
+
* @param {number} z @param {When} when */
|
|
981
|
+
dolly: (z, when) => st.dolly(z, when),
|
|
982
|
+
/** the world's own turn and the lens's travel at t */
|
|
983
|
+
/** @param {number} t */
|
|
984
|
+
world: (t) => st.world(t),
|
|
985
|
+
at,
|
|
986
|
+
frame,
|
|
987
|
+
draw,
|
|
988
|
+
/** draw frame t; every slab at t back — a promise of them while a
|
|
989
|
+
* video shows on a slab (`window.__render = (t) => w.apply(t)` waits) */
|
|
990
|
+
/** @param {number} t */
|
|
991
|
+
apply(t) {
|
|
992
|
+
if (!T) return at(t);
|
|
993
|
+
const f = frame(t);
|
|
994
|
+
/** @type {Set<Tex>} */
|
|
995
|
+
const vids = new Set();
|
|
996
|
+
f.slabs.forEach((s, i) => {
|
|
997
|
+
const tx = recs[i]?.tex;
|
|
998
|
+
if (s.visible && tx?.sync) vids.add(tx);
|
|
999
|
+
});
|
|
1000
|
+
const waits = [...vids].map((tx) => tx.sync?.()).filter(Boolean);
|
|
1001
|
+
if (!waits.length) {
|
|
1002
|
+
draw(f);
|
|
1003
|
+
return at(t);
|
|
1004
|
+
}
|
|
1005
|
+
// a video on a slab: drawn once its frame at t is there — return this
|
|
1006
|
+
// from __render, which waits for it
|
|
1007
|
+
return Promise.all(waits).then(() => {
|
|
1008
|
+
draw(f);
|
|
1009
|
+
return at(t);
|
|
1010
|
+
});
|
|
1011
|
+
},
|
|
1012
|
+
/** every picture's source, slab by slab */
|
|
1013
|
+
sources: () =>
|
|
1014
|
+
recs.map((r) => ({
|
|
1015
|
+
name: r.handle.name,
|
|
1016
|
+
source: r.source,
|
|
1017
|
+
src:
|
|
1018
|
+
typeof r.src === "string"
|
|
1019
|
+
? r.src
|
|
1020
|
+
: /** @type {any} */ (r.src).currentSrc ||
|
|
1021
|
+
/** @type {any} */ (r.src).src ||
|
|
1022
|
+
`<${r.src.tagName.toLowerCase()}>`,
|
|
1023
|
+
device: r.device?.kind ?? null,
|
|
1024
|
+
})),
|
|
1025
|
+
/** every picture loaded (window.__film.ready) */
|
|
1026
|
+
ready: () => Promise.all(recs.map((r) => r.tex?.ready)).then(() => undefined),
|
|
1027
|
+
/**
|
|
1028
|
+
* Pictures drawn bigger than their own pixels — a slab whose picture is
|
|
1029
|
+
* stretched past 1.1 drawing-buffer px per picture px — and when, checked
|
|
1030
|
+
* every 1/30 s from `from` to `to` (default 0 to the last move plus a
|
|
1031
|
+
* second). Pictures not loaded yet are not checked.
|
|
1032
|
+
* @param {number} [from] @param {number} [to]
|
|
1033
|
+
*/
|
|
1034
|
+
warnings(from = 0, to) {
|
|
1035
|
+
const end = to ?? from + 1;
|
|
1036
|
+
const dpr = renderer ? renderer.getPixelRatio() : 1;
|
|
1037
|
+
/** @type {Map<string, [number, number, number]>} */
|
|
1038
|
+
const over = new Map();
|
|
1039
|
+
/** @type {string[]} */
|
|
1040
|
+
const out = [];
|
|
1041
|
+
const flush = (/** @type {string} */ n) => {
|
|
1042
|
+
const r = over.get(n);
|
|
1043
|
+
if (!r) return;
|
|
1044
|
+
out.push(
|
|
1045
|
+
`${n}: its picture drawn at ${r[2].toFixed(2)}× its own pixels ${r[0].toFixed(2)}–${r[1].toFixed(2)} s — soft; a sharper picture (film picture --scale 2), or smaller on screen`,
|
|
1046
|
+
);
|
|
1047
|
+
over.delete(n);
|
|
1048
|
+
};
|
|
1049
|
+
for (let t = from; t <= end + 1e-9; t += 1 / 30) {
|
|
1050
|
+
at(t).forEach((s, i) => {
|
|
1051
|
+
const r = /** @type {Rec} */ (recs[i]);
|
|
1052
|
+
const n = r.tex?.size();
|
|
1053
|
+
if (!n || !s.visible) {
|
|
1054
|
+
flush(s.name);
|
|
1055
|
+
return;
|
|
1056
|
+
}
|
|
1057
|
+
const c = r.crop ?? { x: 0, y: 0, w: content.width, h: content.height };
|
|
1058
|
+
const own = r.crop
|
|
1059
|
+
? (c.w * n.w * c.h * n.h) / (content.width * content.height)
|
|
1060
|
+
: n.w * n.h;
|
|
1061
|
+
const k = Math.sqrt((s.area * dpr * dpr) / own);
|
|
1062
|
+
if (k > 1.1) {
|
|
1063
|
+
const p = over.get(s.name);
|
|
1064
|
+
over.set(s.name, p ? [p[0], t, Math.max(p[2], k)] : [t, t, k]);
|
|
1065
|
+
} else flush(s.name);
|
|
1066
|
+
});
|
|
1067
|
+
}
|
|
1068
|
+
for (const n of [...over.keys()]) flush(n);
|
|
1069
|
+
return out;
|
|
1070
|
+
},
|
|
1071
|
+
};
|
|
1072
|
+
}
|