@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
|
@@ -0,0 +1,1402 @@
|
|
|
1
|
+
// devices.js — a laptop, a phone and a plain box computer for a film page,
|
|
2
|
+
// built from the page's own elements. Each face is one flat element with its
|
|
3
|
+
// own perspective, the way kit/stage.js draws a slab: no perspective on a
|
|
4
|
+
// parent and no layer bigger than the face it shows. The faces are lit from
|
|
5
|
+
// one light up and to the left of the lens. A screen is any element: the
|
|
6
|
+
// film's own rebuilt interface keeps working on it — its text is text, its
|
|
7
|
+
// cursor moves and its rows open — or a picture, a canvas, a video. No logo and no maker's shape; the colours
|
|
8
|
+
// are options.
|
|
9
|
+
//
|
|
10
|
+
// Made once, then drawn from a pose: a plain object you write from film time
|
|
11
|
+
// (anim.js's `keys`), so the same pose draws the same frame, in any order;
|
|
12
|
+
// nothing here keeps time. The lid's angle is in the pose, shut (0) to open
|
|
13
|
+
// and back at any speed; a computer's light too.
|
|
14
|
+
//
|
|
15
|
+
// import { laptop, phone, computer } from "./lib/devices.js";
|
|
16
|
+
// import { keys } from "./lib/anim.js";
|
|
17
|
+
// const lap = laptop(document.querySelector("#scene"), { screen: document.querySelector("#app") });
|
|
18
|
+
// window.__render = (t) => {
|
|
19
|
+
// const at = lap.draw({ x: 960, y: 860, rx: -18, ry: -24, scale: 0.55,
|
|
20
|
+
// open: keys(t, [[0.4, 0], [1.2, 108, "out3"], [3.6, 108], [3.95, 0, "in3"]]) });
|
|
21
|
+
// const [cx, cy] = at.toFrame(700, 420); // a point of the screen (its own px), in the frame
|
|
22
|
+
// };
|
|
23
|
+
//
|
|
24
|
+
// laptop(host, o) a lid on a hinge round the screen, a keyboard half, thickness
|
|
25
|
+
// enough to read as a laptop shut; pose.open: degrees between
|
|
26
|
+
// lid and keyboard (0 shut … 105 open … 180 flat), pose.screen: 0…1 lit
|
|
27
|
+
// phone(host, o) a rounded slab, the screen on its front; pose.screen: 0…1 lit
|
|
28
|
+
// computer(host, o) a rounded box with a status light — a desktop, a server, a cloud
|
|
29
|
+
// machine; pose.on: 0…1, the light and the glow under it
|
|
30
|
+
//
|
|
31
|
+
// `host` is a layer whose top-left is the frame's top-left (a scene the size of
|
|
32
|
+
// the frame) and that has no perspective of its own; null gives numbers only.
|
|
33
|
+
// Every device has
|
|
34
|
+
// draw(pose, cam?) writes its faces and returns at(pose, cam)
|
|
35
|
+
// at(pose, cam?) numbers only: `bounds` (the box it takes in the frame),
|
|
36
|
+
// `quad` and `toFrame(x, y)` (its screen — a computer's front
|
|
37
|
+
// — in the frame), `facing`, `depth`, `soft` (faces with the
|
|
38
|
+
// page's content Chrome would still stretch), `faces`
|
|
39
|
+
// el its layer in the host (null without one)
|
|
40
|
+
// A pose: { x, y, z, rx, ry, rz, scale, opacity, shadow } and the device's own
|
|
41
|
+
// fields. x, y: where its origin lands in the frame (px) — a laptop's and a
|
|
42
|
+
// computer's is the middle of its footprint on the table, a phone's the middle
|
|
43
|
+
// of its screen; z: px toward the lens. Turned as kit/stage.js turns a slab
|
|
44
|
+
// (rz, then ry, then rx, degrees): ry turns a laptop on the table, a negative
|
|
45
|
+
// rx shows it from above (−20: from 20° up). scale 1: its screen at the screen
|
|
46
|
+
// element's own px (a computer: its w, h, d in px). shadow 0…1: the soft
|
|
47
|
+
// shadow on the table under it (default 1; a phone 0).
|
|
48
|
+
// cam: anim.js's 2D camera { x, y, s }, for a host the camera does not move —
|
|
49
|
+
// the lens stays at the middle of the frame. A host inside the camera's layer
|
|
50
|
+
// needs none. The lens is 2800 px from the stage, at the frame's middle
|
|
51
|
+
// (option `lens: { d, cx, cy }`). Nothing here blurs: the master's shutter
|
|
52
|
+
// smears a lid that shuts in 0.3 s, as it does any fast move.
|
|
53
|
+
//
|
|
54
|
+
// Sharp up close. Chrome draws a layer under a perspective with no more
|
|
55
|
+
// pixels than the frame has and stretches it (`skill film render`), so a
|
|
56
|
+
// screen pushed in until it fills the frame went soft. Now:
|
|
57
|
+
// - a screen face is cut to the part of it inside the frame;
|
|
58
|
+
// - as the screen comes to need about as many pixels as the frame has, the
|
|
59
|
+
// device's lens is drawn back toward none (a smooth step from 0.6 of the
|
|
60
|
+
// frame's pixels to all of them), the screen's middle kept as big and where
|
|
61
|
+
// it is; from there every face is a plain 2D transform, which Chrome draws
|
|
62
|
+
// at the scale it shows, at any size. Up close the laptop then looks as a
|
|
63
|
+
// long lens shows it: little foreshortening. `flatten: false` (an option)
|
|
64
|
+
// keeps the lens as it is; pose.flatten (0…1) asks for more by hand.
|
|
65
|
+
// - `soft` names a face that shows the page's content which Chrome would
|
|
66
|
+
// still stretch (with `flatten: false`, a phone or a computer's mark, a
|
|
67
|
+
// screen behind a host the page has scaled up): at() says it, so a draft
|
|
68
|
+
// shows it before a master; the render's report names the layer too.
|
|
69
|
+
// The cut and the flattening read the frame as the host's 1920 × 1080 (or
|
|
70
|
+
// `frame`): a host the page itself moves or scales needs `cam` instead.
|
|
71
|
+
//
|
|
72
|
+
// Hiding a device: opacity 0 in its pose, or the page's own
|
|
73
|
+
// `el.style.visibility = "hidden"` / `display = "none"` — draw leaves those
|
|
74
|
+
// alone (it sets visibility only to hide a device at opacity 0, and gives the
|
|
75
|
+
// page's back after).
|
|
76
|
+
//
|
|
77
|
+
// Several devices in one host: each is its own layer (`el`); set its zIndex
|
|
78
|
+
// for which is in front (`depth` says which is nearer), and make the host a
|
|
79
|
+
// stacking context of its own (`isolation: isolate`) so that a zIndex there
|
|
80
|
+
// does not lift the device over what the page draws above the host.
|
|
81
|
+
|
|
82
|
+
import { matrices as M } from "../kit/stage.js";
|
|
83
|
+
|
|
84
|
+
/** @typedef {{ x: number, y: number, z: number }} V3 */
|
|
85
|
+
/** @typedef {number[]} Mat 4×4, column-major, as CSS matrix3d lists it */
|
|
86
|
+
/** @typedef {{ x: number, y: number, s: number }} Cam anim.js's 2D camera */
|
|
87
|
+
/**
|
|
88
|
+
* @typedef {object} Pose where a device is and how it is
|
|
89
|
+
* @property {number} [x] @property {number} [y] @property {number} [z]
|
|
90
|
+
* @property {number} [rx] @property {number} [ry] @property {number} [rz]
|
|
91
|
+
* @property {number} [scale] @property {number} [opacity] @property {number} [shadow]
|
|
92
|
+
* @property {number} [open] a laptop: degrees between lid and keyboard (default 105)
|
|
93
|
+
* @property {number} [screen] a laptop's or a phone's screen: 1 lit, 0 dark (default 1)
|
|
94
|
+
* @property {number} [on] a computer: its light and glow, 0…1 (default 0)
|
|
95
|
+
* @property {number} [lens] the lens's distance for this frame (px; default the device's, 2800)
|
|
96
|
+
* @property {number} [flatten] 0…1: the lens drawn back toward none at 1 (no perspective), the
|
|
97
|
+
* screen's middle kept as big and where it is — for a screen filling the frame at a tilt (default 0)
|
|
98
|
+
*/
|
|
99
|
+
/**
|
|
100
|
+
* @typedef {object} Face one flat element of a device
|
|
101
|
+
* @property {string} name
|
|
102
|
+
* @property {string} part what it moves with ("base", "lid", "body", "floor")
|
|
103
|
+
* @property {number} layer 0 the body, 1 a mark on it, 2 a screen, 3 the screen's glass
|
|
104
|
+
* @property {string} kind body, bezel, keys, decal, screen, glass, shadow, glow
|
|
105
|
+
* @property {V3} O its top-left in its part's px
|
|
106
|
+
* @property {V3} U its x axis there (unit)
|
|
107
|
+
* @property {V3} V its y axis there (unit)
|
|
108
|
+
* @property {number} w @property {number} h its own px
|
|
109
|
+
* @property {string | null} clip a polygon in its own px, or none: the whole rectangle
|
|
110
|
+
* @property {number} radius its corners (px)
|
|
111
|
+
* @property {string} color a body's colour, before the light
|
|
112
|
+
* @property {[V3, V3] | null} ends a rounded piece: its normal (part px) at its x = 0 and at x = w,
|
|
113
|
+
* lit as a gradient between them so the pieces of a curve read as one curve
|
|
114
|
+
* @property {HTMLElement | null} el
|
|
115
|
+
*/
|
|
116
|
+
/**
|
|
117
|
+
* @typedef {object} DeviceAt a device in the frame
|
|
118
|
+
* @property {{ x: number, y: number, w: number, h: number }} bounds the box its faces take in the frame
|
|
119
|
+
* @property {{ x: number, y: number }[]} quad its screen's (a computer's front's) corners in the frame, top-left first, clockwise
|
|
120
|
+
* @property {(x: number, y: number) => [number, number]} toFrame a point of the screen (its own px) — a computer's front — in the frame
|
|
121
|
+
* @property {boolean} facing the screen (a computer's front) toward the lens
|
|
122
|
+
* @property {number} depth its origin's z after the turn (px, + nearer the lens)
|
|
123
|
+
* @property {string[]} soft faces showing the page's content that Chrome would still draw with fewer pixels than they show (soft)
|
|
124
|
+
* @property {{ name: string, facing: boolean, quad: { x: number, y: number }[], z: number }[]} faces every face: toward the lens, where, its order (higher in front)
|
|
125
|
+
*/
|
|
126
|
+
|
|
127
|
+
const RAD = Math.PI / 180;
|
|
128
|
+
const FRAME = { width: 1920, height: 1080 };
|
|
129
|
+
// a lens 2800 px from the stage: the long end of the 1600–2800 px measured
|
|
130
|
+
// on films that tilted a screen into space (kit/stage.js takes the middle,
|
|
131
|
+
// 2000) — a device seen from three-quarters keeps its shape, as product shots
|
|
132
|
+
// taken with a long lens do
|
|
133
|
+
const LENS = 2800;
|
|
134
|
+
|
|
135
|
+
/** @param {number} x @param {number} y @param {number} z @returns {V3} */
|
|
136
|
+
const v3 = (x, y, z) => ({ x, y, z });
|
|
137
|
+
/** @param {V3} a @param {V3} b */
|
|
138
|
+
const add = (a, b) => v3(a.x + b.x, a.y + b.y, a.z + b.z);
|
|
139
|
+
/** @param {V3} a @param {V3} b */
|
|
140
|
+
const sub = (a, b) => v3(a.x - b.x, a.y - b.y, a.z - b.z);
|
|
141
|
+
/** @param {V3} a @param {number} k */
|
|
142
|
+
const mulv = (a, k) => v3(a.x * k, a.y * k, a.z * k);
|
|
143
|
+
/** @param {V3} a @param {V3} b */
|
|
144
|
+
const dot = (a, b) => a.x * b.x + a.y * b.y + a.z * b.z;
|
|
145
|
+
/** @param {V3} a @param {V3} b */
|
|
146
|
+
const cross = (a, b) => v3(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x);
|
|
147
|
+
/** @param {V3} a */
|
|
148
|
+
function unit(a) {
|
|
149
|
+
const l = Math.hypot(a.x, a.y, a.z) || 1;
|
|
150
|
+
return v3(a.x / l, a.y / l, a.z / l);
|
|
151
|
+
}
|
|
152
|
+
// one light, up and to the left of the lens, as far from the stage as the
|
|
153
|
+
// lens again (px from the lens, y down): near enough that a large face is a
|
|
154
|
+
// little brighter at its end nearer the light
|
|
155
|
+
const LIGHT = { x: -0.5, y: -1.9, z: -0.2 };
|
|
156
|
+
const AMBIENT = 0.56;
|
|
157
|
+
/** @param {number} x @param {number} [a] @param {number} [b] */
|
|
158
|
+
const clamp = (x, a = 0, b = 1) => Math.min(b, Math.max(a, x));
|
|
159
|
+
/** a matrix's entry @param {Mat} m @param {number} i */
|
|
160
|
+
const g = (m, i) => /** @type {number} */ (m[i]);
|
|
161
|
+
/** a number for CSS @param {number} v */
|
|
162
|
+
const f6 = (v) => (Math.abs(v) < 1e-12 ? 0 : +v.toPrecision(10));
|
|
163
|
+
/** a point through a matrix — x, y, z divided by w, and w @param {Mat} m @param {V3} p */
|
|
164
|
+
const through = (m, p) => M.apply(m, p.x, p.y, p.z);
|
|
165
|
+
/** a direction through a matrix, as a unit vector @param {Mat} m @param {V3} v */
|
|
166
|
+
const turned = (m, v) =>
|
|
167
|
+
unit(
|
|
168
|
+
v3(
|
|
169
|
+
g(m, 0) * v.x + g(m, 4) * v.y + g(m, 8) * v.z,
|
|
170
|
+
g(m, 1) * v.x + g(m, 5) * v.y + g(m, 9) * v.z,
|
|
171
|
+
g(m, 2) * v.x + g(m, 6) * v.y + g(m, 10) * v.z,
|
|
172
|
+
),
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
/** "#rrggbb" or "#rgb" → [r, g, b] @param {string} hex @returns {[number, number, number]} */
|
|
176
|
+
function rgbOf(hex) {
|
|
177
|
+
const h = hex.trim().replace(/^#/, "");
|
|
178
|
+
const full = h.length === 3 ? [...h].map((c) => c + c).join("") : h;
|
|
179
|
+
if (!/^[0-9a-f]{6}$/i.test(full))
|
|
180
|
+
throw new Error(`devices: a colour is "#rrggbb" or "#rgb" (got ${JSON.stringify(hex)})`);
|
|
181
|
+
const n = (/** @type {number} */ i) => parseInt(full.slice(i, i + 2), 16);
|
|
182
|
+
return [n(0), n(2), n(4)];
|
|
183
|
+
}
|
|
184
|
+
/** a colour lit: k times as bright, then `spec` of the way to white @param {[number, number, number]} c @param {number} k @param {number} spec */
|
|
185
|
+
function lit(c, k, spec) {
|
|
186
|
+
const ch = (/** @type {number} */ v) => Math.round(clamp(v * k + (255 - v * k) * spec, 0, 255));
|
|
187
|
+
return `rgb(${ch(c[0])}, ${ch(c[1])}, ${ch(c[2])})`;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// --- faces ------------------------------------------------------------------------
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* A rectangle face: its top-left O and its axes U, V (unit) in its part's px.
|
|
194
|
+
* Its front is U × V.
|
|
195
|
+
* @param {Partial<Face> & { name: string, part: string, O: V3, U: V3, V: V3, w: number, h: number }} o
|
|
196
|
+
* @returns {Face}
|
|
197
|
+
*/
|
|
198
|
+
function rect(o) {
|
|
199
|
+
return {
|
|
200
|
+
layer: 0,
|
|
201
|
+
kind: "body",
|
|
202
|
+
clip: null,
|
|
203
|
+
radius: 0,
|
|
204
|
+
color: "#888888",
|
|
205
|
+
ends: null,
|
|
206
|
+
el: null,
|
|
207
|
+
...o,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* A flat polygon (its points in one plane) as a face: the rectangle round it,
|
|
213
|
+
* the polygon its clip. `out` says which way its front is; `along`, if given,
|
|
214
|
+
* its x axis (else its longest edge).
|
|
215
|
+
* @param {string} part @param {string} name @param {V3[]} pts @param {V3} out
|
|
216
|
+
* @param {Partial<Face>} [o] @param {V3} [along]
|
|
217
|
+
* @returns {Face}
|
|
218
|
+
*/
|
|
219
|
+
function poly(part, name, pts, out, o = {}, along) {
|
|
220
|
+
// the plane's normal (Newell's), turned to face `out`
|
|
221
|
+
let n = v3(0, 0, 0);
|
|
222
|
+
for (let i = 0; i < pts.length; i++) {
|
|
223
|
+
const a = /** @type {V3} */ (pts[i]);
|
|
224
|
+
const b = /** @type {V3} */ (pts[(i + 1) % pts.length]);
|
|
225
|
+
n = add(n, v3((a.y - b.y) * (a.z + b.z), (a.z - b.z) * (a.x + b.x), (a.x - b.x) * (a.y + b.y)));
|
|
226
|
+
}
|
|
227
|
+
n = unit(n);
|
|
228
|
+
if (dot(n, out) < 0) n = mulv(n, -1);
|
|
229
|
+
// its x along its longest edge, or as asked (in its plane)
|
|
230
|
+
let U = v3(1, 0, 0);
|
|
231
|
+
let longest = along ? Number.POSITIVE_INFINITY : -1;
|
|
232
|
+
if (along) U = unit(sub(along, mulv(n, dot(along, n))));
|
|
233
|
+
for (let i = 0; i < pts.length; i++) {
|
|
234
|
+
const e = sub(/** @type {V3} */ (pts[(i + 1) % pts.length]), /** @type {V3} */ (pts[i]));
|
|
235
|
+
const l = Math.hypot(e.x, e.y, e.z);
|
|
236
|
+
if (l > longest) {
|
|
237
|
+
longest = l;
|
|
238
|
+
U = unit(e);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
const V = cross(n, U);
|
|
242
|
+
const p0 = /** @type {V3} */ (pts[0]);
|
|
243
|
+
const uv = pts.map((p) => [dot(sub(p, p0), U), dot(sub(p, p0), V)]);
|
|
244
|
+
const us = uv.map((q) => /** @type {number} */ (q[0]));
|
|
245
|
+
const vs = uv.map((q) => /** @type {number} */ (q[1]));
|
|
246
|
+
const u0 = Math.min(...us);
|
|
247
|
+
const v0 = Math.min(...vs);
|
|
248
|
+
const w = Math.max(...us) - u0;
|
|
249
|
+
const h = Math.max(...vs) - v0;
|
|
250
|
+
const local = uv.map((q) => [
|
|
251
|
+
/** @type {number} */ (q[0]) - u0,
|
|
252
|
+
/** @type {number} */ (q[1]) - v0,
|
|
253
|
+
]);
|
|
254
|
+
const whole =
|
|
255
|
+
local.length === 4 &&
|
|
256
|
+
local.every(
|
|
257
|
+
([a, b]) =>
|
|
258
|
+
(Math.abs(/** @type {number} */ (a)) < 1e-6 ||
|
|
259
|
+
Math.abs(/** @type {number} */ (a) - w) < 1e-6) &&
|
|
260
|
+
(Math.abs(/** @type {number} */ (b)) < 1e-6 ||
|
|
261
|
+
Math.abs(/** @type {number} */ (b) - h) < 1e-6),
|
|
262
|
+
);
|
|
263
|
+
return rect({
|
|
264
|
+
...o,
|
|
265
|
+
part,
|
|
266
|
+
name,
|
|
267
|
+
O: add(p0, add(mulv(U, u0), mulv(V, v0))),
|
|
268
|
+
U,
|
|
269
|
+
V,
|
|
270
|
+
w,
|
|
271
|
+
h,
|
|
272
|
+
clip: whole
|
|
273
|
+
? null
|
|
274
|
+
: `polygon(${local.map(([a, b]) => `${f6(/** @type {number} */ (a))}px ${f6(/** @type {number} */ (b))}px`).join(", ")})`,
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* A slab lying flat — a box whose upright edges are rounded (r, in `seg`
|
|
280
|
+
* pieces a corner) and whose top edge may be bevelled (`bevel` px at 45°):
|
|
281
|
+
* x from x0 to x1, z from z0 (back) to z1 (front), y from y0 (its top, y is
|
|
282
|
+
* down) to y1. The top's x runs along x and its y from back to front; the
|
|
283
|
+
* bottom's from front to back (so a lid's underside reads upright once the
|
|
284
|
+
* lid is raised).
|
|
285
|
+
* @param {string} part
|
|
286
|
+
* @param {{ x0: number, x1: number, z0: number, z1: number, y0: number, y1: number, r: number, seg: number, bevel?: number, color: string, top?: Partial<Face>, bottom?: Partial<Face>, side?: Partial<Face> }} o
|
|
287
|
+
* @returns {{ faces: Face[], top: Face, bottom: Face }}
|
|
288
|
+
*/
|
|
289
|
+
function slab(part, o) {
|
|
290
|
+
const { x0, x1, z0, z1, y0, y1, seg } = o;
|
|
291
|
+
const r = Math.max(0, Math.min(o.r, (x1 - x0) / 2, (z1 - z0) / 2));
|
|
292
|
+
const b = Math.max(0, Math.min(o.bevel ?? 0, r || Number.POSITIVE_INFINITY, (y1 - y0) / 2));
|
|
293
|
+
const body = { part, color: o.color };
|
|
294
|
+
/** @type {Face[]} */
|
|
295
|
+
const faces = [];
|
|
296
|
+
const top = rect({
|
|
297
|
+
...body,
|
|
298
|
+
name: `${part} top`,
|
|
299
|
+
O: v3(x0 + b, y0, z0 + b),
|
|
300
|
+
U: v3(1, 0, 0),
|
|
301
|
+
V: v3(0, 0, 1),
|
|
302
|
+
w: x1 - x0 - 2 * b,
|
|
303
|
+
h: z1 - z0 - 2 * b,
|
|
304
|
+
radius: Math.max(0, r - b),
|
|
305
|
+
...o.top,
|
|
306
|
+
});
|
|
307
|
+
const bottom = rect({
|
|
308
|
+
...body,
|
|
309
|
+
name: `${part} bottom`,
|
|
310
|
+
O: v3(x0, y1, z1),
|
|
311
|
+
U: v3(1, 0, 0),
|
|
312
|
+
V: v3(0, 0, -1),
|
|
313
|
+
w: x1 - x0,
|
|
314
|
+
h: z1 - z0,
|
|
315
|
+
radius: r,
|
|
316
|
+
...o.bottom,
|
|
317
|
+
});
|
|
318
|
+
faces.push(top, bottom);
|
|
319
|
+
const ys = y0 + b;
|
|
320
|
+
const hs = y1 - ys;
|
|
321
|
+
const side = { ...body, ...o.side };
|
|
322
|
+
if (x1 - x0 - 2 * r > 1e-6) {
|
|
323
|
+
faces.push(
|
|
324
|
+
rect({
|
|
325
|
+
...side,
|
|
326
|
+
name: `${part} front`,
|
|
327
|
+
O: v3(x0 + r, ys, z1),
|
|
328
|
+
U: v3(1, 0, 0),
|
|
329
|
+
V: v3(0, 1, 0),
|
|
330
|
+
w: x1 - x0 - 2 * r,
|
|
331
|
+
h: hs,
|
|
332
|
+
}),
|
|
333
|
+
rect({
|
|
334
|
+
...side,
|
|
335
|
+
name: `${part} back`,
|
|
336
|
+
O: v3(x1 - r, ys, z0),
|
|
337
|
+
U: v3(-1, 0, 0),
|
|
338
|
+
V: v3(0, 1, 0),
|
|
339
|
+
w: x1 - x0 - 2 * r,
|
|
340
|
+
h: hs,
|
|
341
|
+
}),
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
if (z1 - z0 - 2 * r > 1e-6) {
|
|
345
|
+
faces.push(
|
|
346
|
+
rect({
|
|
347
|
+
...side,
|
|
348
|
+
name: `${part} right`,
|
|
349
|
+
O: v3(x1, ys, z1 - r),
|
|
350
|
+
U: v3(0, 0, -1),
|
|
351
|
+
V: v3(0, 1, 0),
|
|
352
|
+
w: z1 - z0 - 2 * r,
|
|
353
|
+
h: hs,
|
|
354
|
+
}),
|
|
355
|
+
rect({
|
|
356
|
+
...side,
|
|
357
|
+
name: `${part} left`,
|
|
358
|
+
O: v3(x0, ys, z0 + r),
|
|
359
|
+
U: v3(0, 0, 1),
|
|
360
|
+
V: v3(0, 1, 0),
|
|
361
|
+
w: z1 - z0 - 2 * r,
|
|
362
|
+
h: hs,
|
|
363
|
+
}),
|
|
364
|
+
);
|
|
365
|
+
}
|
|
366
|
+
// the bevel's straight pieces
|
|
367
|
+
if (b > 0) {
|
|
368
|
+
const yb = y0 + b;
|
|
369
|
+
/** @type {[V3[], V3][]} */
|
|
370
|
+
const bands = [
|
|
371
|
+
[
|
|
372
|
+
[v3(x0 + r, y0, z1 - b), v3(x1 - r, y0, z1 - b), v3(x1 - r, yb, z1), v3(x0 + r, yb, z1)],
|
|
373
|
+
v3(0, -1, 1),
|
|
374
|
+
],
|
|
375
|
+
[
|
|
376
|
+
[v3(x1 - r, y0, z0 + b), v3(x0 + r, y0, z0 + b), v3(x0 + r, yb, z0), v3(x1 - r, yb, z0)],
|
|
377
|
+
v3(0, -1, -1),
|
|
378
|
+
],
|
|
379
|
+
[
|
|
380
|
+
[v3(x1 - b, y0, z1 - r), v3(x1 - b, y0, z0 + r), v3(x1, yb, z0 + r), v3(x1, yb, z1 - r)],
|
|
381
|
+
v3(1, -1, 0),
|
|
382
|
+
],
|
|
383
|
+
[
|
|
384
|
+
[v3(x0 + b, y0, z0 + r), v3(x0 + b, y0, z1 - r), v3(x0, yb, z1 - r), v3(x0, yb, z0 + r)],
|
|
385
|
+
v3(-1, -1, 0),
|
|
386
|
+
],
|
|
387
|
+
];
|
|
388
|
+
bands.forEach(([pts, out], i) => {
|
|
389
|
+
const a = /** @type {V3} */ (pts[0]);
|
|
390
|
+
const c = /** @type {V3} */ (pts[1]);
|
|
391
|
+
if (Math.hypot(c.x - a.x, c.z - a.z) > 1e-6)
|
|
392
|
+
faces.push(poly(part, `${part} bevel ${i}`, pts, out, side));
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
// the rounded corners: upright strips, and the bevel round them
|
|
396
|
+
if (r > 0) {
|
|
397
|
+
const corners = [
|
|
398
|
+
[x1 - r, z1 - r, 0],
|
|
399
|
+
[x0 + r, z1 - r, 90],
|
|
400
|
+
[x0 + r, z0 + r, 180],
|
|
401
|
+
[x1 - r, z0 + r, 270],
|
|
402
|
+
];
|
|
403
|
+
for (const [cx, cz, a0] of /** @type {[number, number, number][]} */ (corners)) {
|
|
404
|
+
for (let k = 0; k < seg; k++) {
|
|
405
|
+
const a = (a0 + (90 * k) / seg) * RAD;
|
|
406
|
+
const c = (a0 + (90 * (k + 1)) / seg) * RAD;
|
|
407
|
+
const m = (a + c) / 2;
|
|
408
|
+
const at = (
|
|
409
|
+
/** @type {number} */ ang,
|
|
410
|
+
/** @type {number} */ rad,
|
|
411
|
+
/** @type {number} */ y,
|
|
412
|
+
) => v3(cx + rad * Math.cos(ang), y, cz + rad * Math.sin(ang));
|
|
413
|
+
const out = v3(Math.cos(m), 0, Math.sin(m));
|
|
414
|
+
const nA = v3(Math.cos(a), 0, Math.sin(a));
|
|
415
|
+
const nC = v3(Math.cos(c), 0, Math.sin(c));
|
|
416
|
+
// its x from the end at angle c to the one at a: so its front is outward
|
|
417
|
+
const chord = sub(at(a, r, 0), at(c, r, 0));
|
|
418
|
+
faces.push(
|
|
419
|
+
poly(
|
|
420
|
+
part,
|
|
421
|
+
`${part} corner ${a0}.${k}`,
|
|
422
|
+
[at(c, r, ys), at(a, r, ys), at(a, r, y1), at(c, r, y1)],
|
|
423
|
+
out,
|
|
424
|
+
{ ...side, ends: [nC, nA] },
|
|
425
|
+
chord,
|
|
426
|
+
),
|
|
427
|
+
);
|
|
428
|
+
if (b > 0) {
|
|
429
|
+
const ri = r - b;
|
|
430
|
+
const pts =
|
|
431
|
+
ri > 1e-6
|
|
432
|
+
? [at(a, ri, y0), at(c, ri, y0), at(c, r, ys), at(a, r, ys)]
|
|
433
|
+
: [at(a, 0, y0), at(c, r, ys), at(a, r, ys)];
|
|
434
|
+
const bevelN = (/** @type {V3} */ q) => unit(v3(q.x, -1, q.z));
|
|
435
|
+
faces.push(
|
|
436
|
+
poly(
|
|
437
|
+
part,
|
|
438
|
+
`${part} bevel ${a0}.${k}`,
|
|
439
|
+
pts,
|
|
440
|
+
v3(out.x, -1, out.z),
|
|
441
|
+
{ ...side, ends: [bevelN(nC), bevelN(nA)] },
|
|
442
|
+
chord,
|
|
443
|
+
),
|
|
444
|
+
);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
return { faces, top, bottom };
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/** a face that shows something of the page's (a screen, the keys, a mark on a face)
|
|
453
|
+
* @param {Face} f */
|
|
454
|
+
const holds = (f) => f.kind === "screen" || f.kind === "keys" || (f.kind === "decal" && !!f.el);
|
|
455
|
+
|
|
456
|
+
/** the 3×3 that takes a face's px (u, v) to the frame's, from its 4×4 (z 0, divide by w) @param {Mat} m */
|
|
457
|
+
const homography = (m) => [
|
|
458
|
+
g(m, 0),
|
|
459
|
+
g(m, 4),
|
|
460
|
+
g(m, 12),
|
|
461
|
+
g(m, 1),
|
|
462
|
+
g(m, 5),
|
|
463
|
+
g(m, 13),
|
|
464
|
+
g(m, 3),
|
|
465
|
+
g(m, 7),
|
|
466
|
+
g(m, 15),
|
|
467
|
+
];
|
|
468
|
+
|
|
469
|
+
/** a 3×3's inverse (rows) @param {number[]} a @returns {number[] | null} */
|
|
470
|
+
function inverse3(a) {
|
|
471
|
+
const [A = 0, B = 0, C = 0, D = 0, E = 0, F = 0, G = 0, H = 0, I = 0] = a;
|
|
472
|
+
const c0 = E * I - F * H;
|
|
473
|
+
const c1 = -(D * I - F * G);
|
|
474
|
+
const c2 = D * H - E * G;
|
|
475
|
+
const det = A * c0 + B * c1 + C * c2;
|
|
476
|
+
if (!(Math.abs(det) > 1e-12)) return null;
|
|
477
|
+
const k = 1 / det;
|
|
478
|
+
return [
|
|
479
|
+
c0 * k,
|
|
480
|
+
-(B * I - C * H) * k,
|
|
481
|
+
(B * F - C * E) * k,
|
|
482
|
+
c1 * k,
|
|
483
|
+
(A * I - C * G) * k,
|
|
484
|
+
-(A * F - C * D) * k,
|
|
485
|
+
c2 * k,
|
|
486
|
+
-(A * H - B * G) * k,
|
|
487
|
+
(A * E - B * D) * k,
|
|
488
|
+
];
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
/**
|
|
492
|
+
* The part of a face (its own px, whole px) that lands inside the frame, with
|
|
493
|
+
* a margin round it — or null when all of it is needed or it cannot be told
|
|
494
|
+
* (a corner of the frame looks past the face's plane).
|
|
495
|
+
* @param {Mat} m the face's px to the frame's @param {number} w @param {number} h
|
|
496
|
+
* @param {{ width: number, height: number }} frame
|
|
497
|
+
*/
|
|
498
|
+
function cropOf(m, w, h, frame) {
|
|
499
|
+
const inv = inverse3(homography(m));
|
|
500
|
+
if (!inv) return null;
|
|
501
|
+
const at = (/** @type {number} */ x, /** @type {number} */ y) => {
|
|
502
|
+
const q = (/** @type {number} */ i) => /** @type {number} */ (inv[i]);
|
|
503
|
+
const u = q(0) * x + q(1) * y + q(2);
|
|
504
|
+
const v = q(3) * x + q(4) * y + q(5);
|
|
505
|
+
const s = q(6) * x + q(7) * y + q(8);
|
|
506
|
+
return { u: u / s, v: v / s, s };
|
|
507
|
+
};
|
|
508
|
+
// the face's middle, to know which sign of w is in front
|
|
509
|
+
const mid = M.apply(m, w / 2, h / 2, 0);
|
|
510
|
+
const ref = at(mid.x, mid.y).s;
|
|
511
|
+
const corners = [
|
|
512
|
+
at(0, 0),
|
|
513
|
+
at(frame.width, 0),
|
|
514
|
+
at(frame.width, frame.height),
|
|
515
|
+
at(0, frame.height),
|
|
516
|
+
];
|
|
517
|
+
if (corners.some((c) => !(c.s * ref > 0) || !Number.isFinite(c.u) || !Number.isFinite(c.v)))
|
|
518
|
+
return null;
|
|
519
|
+
const pad = 24 + 0.02 * Math.max(w, h);
|
|
520
|
+
const x0 = Math.max(0, Math.floor(Math.min(...corners.map((c) => c.u)) - pad));
|
|
521
|
+
const y0 = Math.max(0, Math.floor(Math.min(...corners.map((c) => c.v)) - pad));
|
|
522
|
+
const x1 = Math.min(w, Math.ceil(Math.max(...corners.map((c) => c.u)) + pad));
|
|
523
|
+
const y1 = Math.min(h, Math.ceil(Math.max(...corners.map((c) => c.v)) + pad));
|
|
524
|
+
if (!(x1 > x0 && y1 > y0)) return null;
|
|
525
|
+
if (x0 === 0 && y0 === 0 && x1 >= w && y1 >= h) return null;
|
|
526
|
+
return { x: x0, y: y0, w: x1 - x0, h: y1 - y0 };
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* A plain 2D transform for a rect of a face (CSS matrix(a, b, c, d, e, f) in
|
|
531
|
+
* the rect's own px) when it lands within half a frame pixel of the true,
|
|
532
|
+
* perspective one everywhere on the rect — the true one's first-order fit
|
|
533
|
+
* about the rect's middle, checked at its corners and edge middles — else null.
|
|
534
|
+
* @param {Mat} m @param {{ x: number, y: number, w: number, h: number }} r
|
|
535
|
+
* @returns {number[] | null}
|
|
536
|
+
*/
|
|
537
|
+
function affineOf(m, r) {
|
|
538
|
+
const P = (/** @type {number} */ u, /** @type {number} */ v) => M.apply(m, u, v, 0);
|
|
539
|
+
const u0 = r.x + r.w / 2;
|
|
540
|
+
const v0 = r.y + r.h / 2;
|
|
541
|
+
const o = P(u0, v0);
|
|
542
|
+
if (!(o.w > 0)) return null;
|
|
543
|
+
const e = 0.5;
|
|
544
|
+
const du = P(u0 + e, v0);
|
|
545
|
+
const dv = P(u0, v0 + e);
|
|
546
|
+
const a = (du.x - o.x) / e;
|
|
547
|
+
const b = (du.y - o.y) / e;
|
|
548
|
+
const c = (dv.x - o.x) / e;
|
|
549
|
+
const d = (dv.y - o.y) / e;
|
|
550
|
+
let worst = 0;
|
|
551
|
+
for (const [u = 0, v = 0] of [
|
|
552
|
+
[r.x, r.y],
|
|
553
|
+
[r.x + r.w, r.y],
|
|
554
|
+
[r.x + r.w, r.y + r.h],
|
|
555
|
+
[r.x, r.y + r.h],
|
|
556
|
+
[u0, r.y],
|
|
557
|
+
[r.x + r.w, v0],
|
|
558
|
+
[u0, r.y + r.h],
|
|
559
|
+
[r.x, v0],
|
|
560
|
+
]) {
|
|
561
|
+
const t = P(u, v);
|
|
562
|
+
if (!(t.w > 0)) return null;
|
|
563
|
+
const x = o.x + a * (u - u0) + c * (v - v0);
|
|
564
|
+
const y = o.y + b * (u - u0) + d * (v - v0);
|
|
565
|
+
worst = Math.max(worst, Math.hypot(t.x - x, t.y - y));
|
|
566
|
+
}
|
|
567
|
+
if (worst > 0.5) return null;
|
|
568
|
+
// in the rect's own px (its top-left at 0, 0)
|
|
569
|
+
return [a, b, c, d, o.x - a * (u0 - r.x) - c * (v0 - r.y), o.y - b * (u0 - r.x) - d * (v0 - r.y)];
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
/** the most a px of the face is enlarged in the frame, over a rect of it (its corners and middle)
|
|
573
|
+
* @param {Mat} m @param {{ x: number, y: number, w: number, h: number }} c */
|
|
574
|
+
function maxScale(m, c) {
|
|
575
|
+
let most = 0;
|
|
576
|
+
for (const [u, v] of [
|
|
577
|
+
[c.x, c.y],
|
|
578
|
+
[c.x + c.w, c.y],
|
|
579
|
+
[c.x + c.w, c.y + c.h],
|
|
580
|
+
[c.x, c.y + c.h],
|
|
581
|
+
[c.x + c.w / 2, c.y + c.h / 2],
|
|
582
|
+
]) {
|
|
583
|
+
const a = M.apply(m, /** @type {number} */ (u), /** @type {number} */ (v), 0);
|
|
584
|
+
const bu = M.apply(m, /** @type {number} */ (u) + 1, /** @type {number} */ (v), 0);
|
|
585
|
+
const bv = M.apply(m, /** @type {number} */ (u), /** @type {number} */ (v) + 1, 0);
|
|
586
|
+
if (!(a.w > 0)) continue;
|
|
587
|
+
most = Math.max(most, Math.hypot(bu.x - a.x, bu.y - a.y), Math.hypot(bv.x - a.x, bv.y - a.y));
|
|
588
|
+
}
|
|
589
|
+
return most;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
/** a face's own matrix: its px (u, v, 0) to its part's px @param {Face} f @returns {Mat} */
|
|
593
|
+
function faceMatrix(f) {
|
|
594
|
+
const N = cross(f.U, f.V);
|
|
595
|
+
return [f.U.x, f.U.y, f.U.z, 0, f.V.x, f.V.y, f.V.z, 0, N.x, N.y, N.z, 0, f.O.x, f.O.y, f.O.z, 1];
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
/** a face on the table under a device: a soft shadow or a glow, y the table's height
|
|
599
|
+
* @param {string} name @param {string} kind @param {number} cx @param {number} cz @param {number} w @param {number} d @param {number} y */
|
|
600
|
+
const floor = (name, kind, cx, cz, w, d, y) =>
|
|
601
|
+
rect({
|
|
602
|
+
name,
|
|
603
|
+
part: "floor",
|
|
604
|
+
kind,
|
|
605
|
+
O: v3(cx - w / 2, y, cz - d / 2),
|
|
606
|
+
U: v3(1, 0, 0),
|
|
607
|
+
V: v3(0, 0, 1),
|
|
608
|
+
w,
|
|
609
|
+
h: d,
|
|
610
|
+
});
|
|
611
|
+
|
|
612
|
+
// --- the device ------------------------------------------------------------------------
|
|
613
|
+
|
|
614
|
+
/**
|
|
615
|
+
* @typedef {object} Build what a device is made of
|
|
616
|
+
* @property {Face[]} faces
|
|
617
|
+
* @property {(pose: Required<Pose>) => Record<string, Mat>} parts each part's matrix in the device's px
|
|
618
|
+
* @property {(pose: Required<Pose>, eye: (p: V3, n: V3) => boolean) => string[]} order the parts back to front; `eye(p, n)`: is the lens on n's side of the plane through p (device px)
|
|
619
|
+
* @property {Face} main its screen (a computer: its front)
|
|
620
|
+
* @property {(pose: Required<Pose>, f: Face) => Record<string, string> | null} [style] a face's own look at this pose, beyond the light
|
|
621
|
+
* @property {(f: Face) => Record<string, string> | null} [look] a face's look that never changes, written once
|
|
622
|
+
*/
|
|
623
|
+
|
|
624
|
+
/**
|
|
625
|
+
* @param {HTMLElement | null} host
|
|
626
|
+
* @param {Build} build
|
|
627
|
+
* @param {{ lens?: { d?: number, cx?: number, cy?: number }, frame?: { width: number, height: number }, crop?: boolean, flatten?: boolean }} o
|
|
628
|
+
* @param {Partial<Pose>} defaults
|
|
629
|
+
*/
|
|
630
|
+
function device(host, build, o, defaults) {
|
|
631
|
+
const frame = o.frame ?? FRAME;
|
|
632
|
+
const d = o.lens?.d ?? LENS;
|
|
633
|
+
if (!(d > 0)) throw new Error("devices: the lens's distance (lens.d) is px above 0");
|
|
634
|
+
const lensC = { x: o.lens?.cx ?? frame.width / 2, y: o.lens?.cy ?? frame.height / 2 };
|
|
635
|
+
const base = {
|
|
636
|
+
x: 0,
|
|
637
|
+
y: 0,
|
|
638
|
+
z: 0,
|
|
639
|
+
rx: 0,
|
|
640
|
+
ry: 0,
|
|
641
|
+
rz: 0,
|
|
642
|
+
scale: 1,
|
|
643
|
+
opacity: 1,
|
|
644
|
+
shadow: 1,
|
|
645
|
+
open: 105,
|
|
646
|
+
screen: 1,
|
|
647
|
+
on: 0,
|
|
648
|
+
lens: d,
|
|
649
|
+
flatten: 0,
|
|
650
|
+
...defaults,
|
|
651
|
+
};
|
|
652
|
+
/** @type {HTMLElement | null} */
|
|
653
|
+
let el = null;
|
|
654
|
+
if (host) {
|
|
655
|
+
el = document.createElement("div");
|
|
656
|
+
el.dataset.otDevice = "";
|
|
657
|
+
// its own stacking context: its faces are ordered among themselves, and
|
|
658
|
+
// the device as one among other things on the page
|
|
659
|
+
Object.assign(el.style, {
|
|
660
|
+
position: "absolute",
|
|
661
|
+
left: "0px",
|
|
662
|
+
top: "0px",
|
|
663
|
+
width: "0px",
|
|
664
|
+
height: "0px",
|
|
665
|
+
isolation: "isolate",
|
|
666
|
+
});
|
|
667
|
+
for (const f of build.faces) {
|
|
668
|
+
const e = f.el ?? document.createElement("div");
|
|
669
|
+
f.el = e;
|
|
670
|
+
e.dataset.otFace = f.name;
|
|
671
|
+
Object.assign(e.style, {
|
|
672
|
+
position: "absolute",
|
|
673
|
+
left: "0px",
|
|
674
|
+
top: "0px",
|
|
675
|
+
width: `${f6(f.w)}px`,
|
|
676
|
+
height: `${f6(f.h)}px`,
|
|
677
|
+
transformOrigin: "0 0",
|
|
678
|
+
backfaceVisibility: "hidden",
|
|
679
|
+
boxSizing: "border-box",
|
|
680
|
+
...(f.radius > 0 ? { borderRadius: `${f6(f.radius)}px` } : {}),
|
|
681
|
+
...(f.clip ? { clipPath: f.clip } : {}),
|
|
682
|
+
...(f.kind === "screen" ? { overflow: "hidden", background: "#000" } : {}),
|
|
683
|
+
// the screen's glass and the light on the table are not in the way of
|
|
684
|
+
// what is under them (a hit test finds the screen's own elements)
|
|
685
|
+
...(f.kind === "glass" || f.kind === "shadow" || f.kind === "glow"
|
|
686
|
+
? { pointerEvents: "none" }
|
|
687
|
+
: {}),
|
|
688
|
+
...build.look?.(f),
|
|
689
|
+
});
|
|
690
|
+
el.appendChild(e);
|
|
691
|
+
}
|
|
692
|
+
host.appendChild(el);
|
|
693
|
+
}
|
|
694
|
+
const colours = new Map(build.faces.map((f) => [f, rgbOf(f.color)]));
|
|
695
|
+
const cropOn = o.crop !== false;
|
|
696
|
+
const autoOn = o.flatten !== false;
|
|
697
|
+
/**
|
|
698
|
+
* How far to flatten by itself: none while the screen (cut to the frame)
|
|
699
|
+
* needs well under the pixels the frame has (0.6 of them), all of it once
|
|
700
|
+
* it would need as many — a smooth step between — so a screen pushed in
|
|
701
|
+
* until it fills the frame is drawn with no perspective, at the scale it
|
|
702
|
+
* shows, and one that would not fill it keeps the device's lens.
|
|
703
|
+
* @param {Mat} view @param {{ x: number, y: number }} c @param {number} d0
|
|
704
|
+
* @param {(name: string) => Mat} partM
|
|
705
|
+
*/
|
|
706
|
+
const autoFlatten = (view, c, d0, partM) => {
|
|
707
|
+
const mf = build.main;
|
|
708
|
+
if (mf.kind !== "screen") return 0;
|
|
709
|
+
const lens0 = M.mul(M.mul(M.translate(c.x, c.y), M.perspective(d0)), M.translate(-c.x, -c.y));
|
|
710
|
+
const seen0 = M.mul(view, M.mul(lens0, M.mul(partM(mf.part), faceMatrix(mf))));
|
|
711
|
+
const corners = [v3(0, 0, 0), v3(mf.w, 0, 0), v3(mf.w, mf.h, 0), v3(0, mf.h, 0)].map((q) =>
|
|
712
|
+
through(seen0, q),
|
|
713
|
+
);
|
|
714
|
+
if (corners.some((q) => !(q.w > 1e-6))) return 0;
|
|
715
|
+
const whole = { x: 0, y: 0, w: mf.w, h: mf.h };
|
|
716
|
+
const part = (cropOn ? cropOf(seen0, mf.w, mf.h, frame) : null) ?? whole;
|
|
717
|
+
const r = (part.w * part.h * maxScale(seen0, part) ** 2) / (frame.width * frame.height);
|
|
718
|
+
const u = clamp((r - 0.6) / 0.4);
|
|
719
|
+
return u * u * (3 - 2 * u);
|
|
720
|
+
};
|
|
721
|
+
// the layer's visibility is the page's: draw sets it only to hide a device
|
|
722
|
+
// at opacity 0, and gives it back after
|
|
723
|
+
let hiddenByPose = false;
|
|
724
|
+
let pageVisibility = "";
|
|
725
|
+
|
|
726
|
+
/** @param {Partial<Pose>} [pose] @param {Cam} [cam] @param {boolean} [write] @returns {DeviceAt} */
|
|
727
|
+
const run = (pose = {}, cam, write = false) => {
|
|
728
|
+
/** @type {Required<Pose>} */
|
|
729
|
+
const p = /** @type {any} */ ({ ...base });
|
|
730
|
+
for (const [k, v] of Object.entries(pose)) {
|
|
731
|
+
if (v == null) continue;
|
|
732
|
+
if (!Number.isFinite(v)) throw new Error(`devices: pose.${k} must be a number (got ${v})`);
|
|
733
|
+
/** @type {any} */ (p)[k] = v;
|
|
734
|
+
}
|
|
735
|
+
// the view: anim.js's 2D camera, the lens at the middle of what it shows
|
|
736
|
+
const c = cam ? { x: cam.x, y: cam.y } : lensC;
|
|
737
|
+
const s = cam ? cam.s : 1;
|
|
738
|
+
const view = cam
|
|
739
|
+
? M.mul(M.translate(frame.width / 2 - cam.x * s, frame.height / 2 - cam.y * s), M.scale(s))
|
|
740
|
+
: M.identity();
|
|
741
|
+
if (!(p.lens > 0))
|
|
742
|
+
throw new Error(`devices: pose.lens is a distance in px above 0 (got ${p.lens})`);
|
|
743
|
+
const placed = M.mul(
|
|
744
|
+
M.mul(
|
|
745
|
+
M.translate(p.x, p.y, p.z),
|
|
746
|
+
M.mul(M.mul(M.rotateX(p.rx), M.rotateY(p.ry)), M.rotateZ(p.rz)),
|
|
747
|
+
),
|
|
748
|
+
[p.scale, 0, 0, 0, 0, p.scale, 0, 0, 0, 0, p.scale, 0, 0, 0, 0, 1],
|
|
749
|
+
);
|
|
750
|
+
const parts = build.parts(p);
|
|
751
|
+
const partM = (/** @type {string} */ name) => M.mul(placed, parts[name] ?? M.identity());
|
|
752
|
+
// flatten: the lens drawn back toward no perspective at all (1), the whole
|
|
753
|
+
// picture scaled about the lens's middle so the screen's middle stays as
|
|
754
|
+
// big and where it is under the device's own lens
|
|
755
|
+
const flatten = Math.max(clamp(p.flatten), autoOn ? autoFlatten(view, c, p.lens, partM) : 0);
|
|
756
|
+
const L = flatten > 0 ? p.lens / Math.max(1e-7, (1 - flatten) ** 2) : p.lens;
|
|
757
|
+
let k = 1;
|
|
758
|
+
if (L !== p.lens) {
|
|
759
|
+
const mf = build.main;
|
|
760
|
+
const zs = through(M.mul(partM(mf.part), faceMatrix(mf)), v3(mf.w / 2, mf.h / 2, 0)).z;
|
|
761
|
+
k = p.lens / (p.lens - zs) / (L / (L - zs));
|
|
762
|
+
}
|
|
763
|
+
const lens = M.mul(
|
|
764
|
+
M.mul(M.mul(M.translate(c.x, c.y), M.scale(k)), M.perspective(L)),
|
|
765
|
+
M.translate(-c.x, -c.y),
|
|
766
|
+
);
|
|
767
|
+
const eyeAt = v3(c.x, c.y, L);
|
|
768
|
+
// the light stays where the device's own lens puts it
|
|
769
|
+
const lightAt = add(
|
|
770
|
+
v3(c.x, c.y, p.lens),
|
|
771
|
+
v3(LIGHT.x * frame.width, LIGHT.y * frame.height, LIGHT.z * p.lens),
|
|
772
|
+
);
|
|
773
|
+
// which side of a plane of the device the lens is on
|
|
774
|
+
const eye = (/** @type {V3} */ q, /** @type {V3} */ n) => {
|
|
775
|
+
const a = through(placed, q);
|
|
776
|
+
const b = through(placed, add(q, n));
|
|
777
|
+
const nn = v3(b.x - a.x, b.y - a.y, b.z - a.z);
|
|
778
|
+
return dot(sub(eyeAt, v3(a.x, a.y, a.z)), nn) > 0;
|
|
779
|
+
};
|
|
780
|
+
const order = build.order(p, eye);
|
|
781
|
+
const ink = s * p.scale;
|
|
782
|
+
// a face grown by about half a frame pixel each side, so two faces meet
|
|
783
|
+
// without the background showing along their edge
|
|
784
|
+
const grow = 0.55 / Math.max(1e-6, ink);
|
|
785
|
+
/** @type {string[]} */
|
|
786
|
+
const soft = [];
|
|
787
|
+
/** @type {DeviceAt["faces"]} */
|
|
788
|
+
const faces = [];
|
|
789
|
+
let x0 = Number.POSITIVE_INFINITY;
|
|
790
|
+
let y0 = Number.POSITIVE_INFINITY;
|
|
791
|
+
let x1 = Number.NEGATIVE_INFINITY;
|
|
792
|
+
let y1 = Number.NEGATIVE_INFINITY;
|
|
793
|
+
/** @type {DeviceAt["quad"]} */
|
|
794
|
+
let quad = [];
|
|
795
|
+
let mainFacing = false;
|
|
796
|
+
/** @type {Mat} */
|
|
797
|
+
let mainFull = M.identity();
|
|
798
|
+
for (const f of build.faces) {
|
|
799
|
+
const fp = M.mul(partM(f.part), faceMatrix(f));
|
|
800
|
+
const body = f.kind === "body" || f.kind === "bezel";
|
|
801
|
+
const seen = M.mul(view, M.mul(lens, fp));
|
|
802
|
+
// a body face drawn grown by `grow` each side: its corner moved out,
|
|
803
|
+
// its size scaled to w + 2·grow
|
|
804
|
+
const full = body
|
|
805
|
+
? M.mul(
|
|
806
|
+
seen,
|
|
807
|
+
M.mul(
|
|
808
|
+
M.translate(-grow, -grow),
|
|
809
|
+
M.scale((f.w + 2 * grow) / f.w, (f.h + 2 * grow) / f.h),
|
|
810
|
+
),
|
|
811
|
+
)
|
|
812
|
+
: seen;
|
|
813
|
+
const n = unit(v3(g(fp, 8), g(fp, 9), g(fp, 10)));
|
|
814
|
+
const centre = through(fp, v3(f.w / 2, f.h / 2, 0));
|
|
815
|
+
const toEye = unit(sub(eyeAt, v3(centre.x, centre.y, centre.z)));
|
|
816
|
+
const facing = dot(toEye, n) > 0;
|
|
817
|
+
const corners = [v3(0, 0, 0), v3(f.w, 0, 0), v3(f.w, f.h, 0), v3(0, f.h, 0)].map((q) =>
|
|
818
|
+
through(seen, q),
|
|
819
|
+
);
|
|
820
|
+
const behind = corners.some((q) => !(q.w > 1e-6));
|
|
821
|
+
const q4 = corners.map((q) => ({ x: q.x, y: q.y }));
|
|
822
|
+
let area = 0;
|
|
823
|
+
for (let i = 0; i < 4; i++) {
|
|
824
|
+
const a = /** @type {{x:number,y:number}} */ (q4[i]);
|
|
825
|
+
const b = /** @type {{x:number,y:number}} */ (q4[(i + 1) % 4]);
|
|
826
|
+
area += a.x * b.y - b.x * a.y;
|
|
827
|
+
}
|
|
828
|
+
area = behind ? Number.POSITIVE_INFINITY : Math.abs(area) / 2;
|
|
829
|
+
// square on to the lens: the lens only scales it — a 2D transform,
|
|
830
|
+
// drawn by Chrome at its final scale
|
|
831
|
+
const flat = Math.abs(Math.abs(n.z) - 1) < 1e-7;
|
|
832
|
+
let transform;
|
|
833
|
+
if (flat && !behind) {
|
|
834
|
+
// (through() has divided by w already)
|
|
835
|
+
const o2 = through(full, v3(0, 0, 0));
|
|
836
|
+
const ex = through(full, v3(1, 0, 0));
|
|
837
|
+
const ey = through(full, v3(0, 1, 0));
|
|
838
|
+
const e1 = { x: ex.x - o2.x, y: ex.y - o2.y };
|
|
839
|
+
const e2 = { x: ey.x - o2.x, y: ey.y - o2.y };
|
|
840
|
+
transform = `matrix(${[e1.x, e1.y, e2.x, e2.y, o2.x, o2.y].map(f6).join(", ")})`;
|
|
841
|
+
} else transform = `matrix3d(${full.map(f6).join(", ")})`;
|
|
842
|
+
// Chrome draws a layer under a perspective with no more pixels than
|
|
843
|
+
// the frame has, and stretches it: a screen that would need more —
|
|
844
|
+
// large, or magnified at its near edge — goes soft. So a face that
|
|
845
|
+
// shows the page's content is
|
|
846
|
+
// - cut to the part of it inside the frame (and a little round it):
|
|
847
|
+
// the layer no bigger than what shows;
|
|
848
|
+
// - drawn with no perspective at all where, over that part, a plain
|
|
849
|
+
// 2D transform lands within half a frame pixel of the true one
|
|
850
|
+
// (square on, or nearly, as a push into a screen ends): Chrome then
|
|
851
|
+
// draws it at the scale it shows, at any size.
|
|
852
|
+
// What is left — a large screen still turned well away from the lens —
|
|
853
|
+
// is named in `soft`.
|
|
854
|
+
const content = f.kind === "screen" || f.kind === "glass" || holds(f);
|
|
855
|
+
const frameArea = frame.width * frame.height;
|
|
856
|
+
const whole = { x: 0, y: 0, w: f.w, h: f.h };
|
|
857
|
+
const needOf = (/** @type {{ x: number, y: number, w: number, h: number }} */ r) =>
|
|
858
|
+
r.w * r.h * maxScale(seen, r) ** 2;
|
|
859
|
+
const cut =
|
|
860
|
+
content && !flat && !behind && cropOn && needOf(whole) > frameArea
|
|
861
|
+
? cropOf(seen, f.w, f.h, frame)
|
|
862
|
+
: null;
|
|
863
|
+
const part = cut ?? whole;
|
|
864
|
+
// (any face: a body face that fits is drawn plainly too, one layer
|
|
865
|
+
// fewer under a perspective)
|
|
866
|
+
const affine = !flat && !behind ? affineOf(full, part) : null;
|
|
867
|
+
if (affine) {
|
|
868
|
+
transform = `matrix(${affine.map(f6).join(", ")})`;
|
|
869
|
+
} else if (cut) {
|
|
870
|
+
transform = `matrix3d(${M.mul(full, M.translate(cut.x, cut.y)).map(f6).join(", ")})`;
|
|
871
|
+
}
|
|
872
|
+
if (holds(f) && !flat && !affine && facing && !behind && needOf(part) > 1.05 * frameArea)
|
|
873
|
+
soft.push(f.name);
|
|
874
|
+
const rank = order.indexOf(f.part);
|
|
875
|
+
const z = (rank < 0 ? 0 : rank) * 10 + f.layer;
|
|
876
|
+
faces.push({ name: f.name, facing, quad: q4, z });
|
|
877
|
+
if (facing && !behind && (body || f.kind === "screen")) {
|
|
878
|
+
for (const q of q4) {
|
|
879
|
+
x0 = Math.min(x0, q.x);
|
|
880
|
+
y0 = Math.min(y0, q.y);
|
|
881
|
+
x1 = Math.max(x1, q.x);
|
|
882
|
+
y1 = Math.max(y1, q.y);
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
if (f === build.main) {
|
|
886
|
+
quad = q4;
|
|
887
|
+
mainFacing = facing;
|
|
888
|
+
mainFull = seen;
|
|
889
|
+
}
|
|
890
|
+
if (!write || !f.el) continue;
|
|
891
|
+
const st = f.el.style;
|
|
892
|
+
st.transform = transform;
|
|
893
|
+
if (f.kind === "screen" || f.kind === "glass") {
|
|
894
|
+
const c = cut ?? { x: 0, y: 0, w: f.w, h: f.h };
|
|
895
|
+
st.width = `${c.w}px`;
|
|
896
|
+
st.height = `${c.h}px`;
|
|
897
|
+
const pane = /** @type {HTMLElement | null} */ (
|
|
898
|
+
f.kind === "screen" ? f.el.firstElementChild : null
|
|
899
|
+
);
|
|
900
|
+
if (pane) {
|
|
901
|
+
pane.style.left = `${-c.x}px`;
|
|
902
|
+
pane.style.top = `${-c.y}px`;
|
|
903
|
+
}
|
|
904
|
+
if (f.radius > 0) {
|
|
905
|
+
// round only the corners that are the screen's own
|
|
906
|
+
const r = `${f6(f.radius)}px`;
|
|
907
|
+
const L = c.x === 0;
|
|
908
|
+
const T = c.y === 0;
|
|
909
|
+
const R = c.x + c.w >= f.w;
|
|
910
|
+
const B = c.y + c.h >= f.h;
|
|
911
|
+
st.borderRadius = `${T && L ? r : "0px"} ${T && R ? r : "0px"} ${B && R ? r : "0px"} ${B && L ? r : "0px"}`;
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
st.zIndex = String(z + 1);
|
|
915
|
+
// a face turned from the lens is hidden outright: backface-visibility
|
|
916
|
+
// hides only one drawn with a matrix3d, and a face written as a plain
|
|
917
|
+
// 2D matrix (square on, or the `affine` one above) has no back — a
|
|
918
|
+
// computer's far wall was drawn over its top
|
|
919
|
+
st.visibility = behind || !facing ? "hidden" : "inherit";
|
|
920
|
+
// the light on it, at the two ends of its x (half way down its y): how
|
|
921
|
+
// much it turns to the light, and a glint where it mirrors the light into
|
|
922
|
+
// the lens. A piece of a curve takes its normal at each end, so the
|
|
923
|
+
// pieces of one curve and the flat faces beside them meet in one tone.
|
|
924
|
+
const col = /** @type {[number, number, number]} */ (colours.get(f));
|
|
925
|
+
/** the light at a point of the face (its own px) with this normal @param {number} u @param {V3} nn */
|
|
926
|
+
const light = (u, nn) => {
|
|
927
|
+
const q = through(fp, v3(u, f.h / 2, 0));
|
|
928
|
+
const P = v3(q.x, q.y, q.z);
|
|
929
|
+
const L = unit(sub(lightAt, P));
|
|
930
|
+
const half = unit(add(L, unit(sub(eyeAt, P))));
|
|
931
|
+
return lit(
|
|
932
|
+
col,
|
|
933
|
+
AMBIENT + (1 - AMBIENT) * Math.max(0, dot(nn, L)),
|
|
934
|
+
0.28 * Math.max(0, dot(nn, half)) ** 36,
|
|
935
|
+
);
|
|
936
|
+
};
|
|
937
|
+
if (body) {
|
|
938
|
+
const pm = partM(f.part);
|
|
939
|
+
const n0 = f.ends ? turned(pm, f.ends[0]) : n;
|
|
940
|
+
const n1 = f.ends ? turned(pm, f.ends[1]) : n;
|
|
941
|
+
st.background = `linear-gradient(90deg, ${light(0, n0)}, ${light(f.w, n1)})`;
|
|
942
|
+
}
|
|
943
|
+
if (f.kind === "glass") {
|
|
944
|
+
const half = unit(add(unit(sub(lightAt, v3(centre.x, centre.y, centre.z))), toEye));
|
|
945
|
+
const glint = 0.05 + 0.22 * Math.max(0, dot(n, half)) ** 10;
|
|
946
|
+
const dark = clamp(1 - p.screen);
|
|
947
|
+
st.background = `linear-gradient(115deg, rgba(255,255,255,${f6(glint)}) 0%, rgba(255,255,255,0) 42%), rgba(6,6,8,${f6(dark)})`;
|
|
948
|
+
}
|
|
949
|
+
const extra = build.style?.(p, f);
|
|
950
|
+
if (extra) Object.assign(st, extra);
|
|
951
|
+
// (a device's own style may hide a face, never show one turned away)
|
|
952
|
+
if (behind || !facing) st.visibility = "hidden";
|
|
953
|
+
}
|
|
954
|
+
if (write && el) {
|
|
955
|
+
el.style.opacity = p.opacity >= 1 ? "" : String(f6(clamp(p.opacity)));
|
|
956
|
+
if (p.opacity <= 0 && !hiddenByPose) {
|
|
957
|
+
pageVisibility = el.style.visibility;
|
|
958
|
+
el.style.visibility = "hidden";
|
|
959
|
+
hiddenByPose = true;
|
|
960
|
+
} else if (p.opacity > 0 && hiddenByPose) {
|
|
961
|
+
el.style.visibility = pageVisibility;
|
|
962
|
+
hiddenByPose = false;
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
const origin = through(placed, v3(0, 0, 0));
|
|
966
|
+
return {
|
|
967
|
+
bounds: Number.isFinite(x0)
|
|
968
|
+
? { x: x0, y: y0, w: x1 - x0, h: y1 - y0 }
|
|
969
|
+
: { x: 0, y: 0, w: 0, h: 0 },
|
|
970
|
+
quad,
|
|
971
|
+
toFrame: (x, y) => {
|
|
972
|
+
const q = through(mainFull, v3(x, y, 0));
|
|
973
|
+
return [q.x, q.y];
|
|
974
|
+
},
|
|
975
|
+
facing: mainFacing,
|
|
976
|
+
depth: origin.z,
|
|
977
|
+
soft,
|
|
978
|
+
faces,
|
|
979
|
+
};
|
|
980
|
+
};
|
|
981
|
+
return {
|
|
982
|
+
el,
|
|
983
|
+
/** numbers only: where it is at this pose @param {Partial<Pose>} [pose] @param {Cam} [cam] */
|
|
984
|
+
at: (pose, cam) => run(pose, cam, false),
|
|
985
|
+
/** write its faces at this pose, and say where it is @param {Partial<Pose>} [pose] @param {Cam} [cam] */
|
|
986
|
+
draw: (pose, cam) => run(pose, cam, true),
|
|
987
|
+
};
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
/** a screen: the element given (moved onto the device), or a picture's or a
|
|
991
|
+
* video's URL as an <img> or a muted <video> at its size
|
|
992
|
+
* @param {HTMLElement | string | null | undefined} s @param {number | undefined} w @param {number | undefined} h @param {string} who */
|
|
993
|
+
function screenOf(s, w, h, who) {
|
|
994
|
+
if (s == null) {
|
|
995
|
+
if (!(w && h))
|
|
996
|
+
throw new Error(
|
|
997
|
+
`devices: a ${who} needs a screen (an element, or a picture's URL) or its w and h`,
|
|
998
|
+
);
|
|
999
|
+
return { el: null, w, h };
|
|
1000
|
+
}
|
|
1001
|
+
if (typeof s === "string") {
|
|
1002
|
+
if (!(w && h)) throw new Error(`devices: a ${who}'s screen from a URL needs its w and h (px)`);
|
|
1003
|
+
if (typeof document === "undefined") return { el: null, w, h };
|
|
1004
|
+
const video = /\.(mp4|webm|mov|m4v)(\?|#|$)/i.test(s);
|
|
1005
|
+
const e = /** @type {HTMLImageElement | HTMLVideoElement} */ (
|
|
1006
|
+
document.createElement(video ? "video" : "img")
|
|
1007
|
+
);
|
|
1008
|
+
e.src = s;
|
|
1009
|
+
if (e instanceof HTMLVideoElement) e.muted = true;
|
|
1010
|
+
Object.assign(e.style, {
|
|
1011
|
+
width: `${w}px`,
|
|
1012
|
+
height: `${h}px`,
|
|
1013
|
+
display: "block",
|
|
1014
|
+
objectFit: "cover",
|
|
1015
|
+
});
|
|
1016
|
+
return { el: /** @type {HTMLElement} */ (e), w, h };
|
|
1017
|
+
}
|
|
1018
|
+
const W = w ?? s.offsetWidth;
|
|
1019
|
+
const H = h ?? s.offsetHeight;
|
|
1020
|
+
if (!(W > 0 && H > 0))
|
|
1021
|
+
throw new Error(
|
|
1022
|
+
`devices: the ${who}'s screen element has no size where it is — give its w and h (px)`,
|
|
1023
|
+
);
|
|
1024
|
+
return { el: s, w: W, h: H };
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
/** the element a screen face holds, placed at its top-left
|
|
1028
|
+
* @param {HTMLElement | null} el @param {number} w @param {number} h */
|
|
1029
|
+
function screenFace(el, w, h) {
|
|
1030
|
+
if (!el || typeof document === "undefined") return null;
|
|
1031
|
+
const face = document.createElement("div");
|
|
1032
|
+
// a pane between them: when only part of the screen is in the frame, the
|
|
1033
|
+
// face is cut to that part and the pane moved so the part shows (draw)
|
|
1034
|
+
const pane = document.createElement("div");
|
|
1035
|
+
Object.assign(pane.style, {
|
|
1036
|
+
position: "absolute",
|
|
1037
|
+
left: "0px",
|
|
1038
|
+
top: "0px",
|
|
1039
|
+
width: `${w}px`,
|
|
1040
|
+
height: `${h}px`,
|
|
1041
|
+
});
|
|
1042
|
+
Object.assign(el.style, {
|
|
1043
|
+
position: "absolute",
|
|
1044
|
+
left: "0px",
|
|
1045
|
+
top: "0px",
|
|
1046
|
+
margin: "0px",
|
|
1047
|
+
width: `${w}px`,
|
|
1048
|
+
height: `${h}px`,
|
|
1049
|
+
});
|
|
1050
|
+
pane.appendChild(el);
|
|
1051
|
+
face.appendChild(pane);
|
|
1052
|
+
return face;
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
/** a keyboard and a touchpad drawn flat, keys a little darker than what is
|
|
1056
|
+
* under them, as an SVG picture of w × d px (the back edge at the top)
|
|
1057
|
+
* @param {number} w @param {number} d @param {string} keys */
|
|
1058
|
+
function keyboard(w, d, keys) {
|
|
1059
|
+
const kw = 0.86 * w;
|
|
1060
|
+
const u = kw / 15;
|
|
1061
|
+
const gap = 0.11 * u;
|
|
1062
|
+
const x0 = (w - kw) / 2;
|
|
1063
|
+
let y = 0.07 * d;
|
|
1064
|
+
const rows = [
|
|
1065
|
+
{ h: 0.55, keys: Array(14).fill(15 / 14) },
|
|
1066
|
+
{ h: 1, keys: [...Array(13).fill(1), 2] },
|
|
1067
|
+
{ h: 1, keys: [1.5, ...Array(12).fill(1), 1.5] },
|
|
1068
|
+
{ h: 1, keys: [1.75, ...Array(11).fill(1), 2.25] },
|
|
1069
|
+
{ h: 1, keys: [2.25, ...Array(10).fill(1), 2.75] },
|
|
1070
|
+
{ h: 1, keys: [1, 1, 1, 1.25, 5.5, 1.25, 1, 1, 1, 1] },
|
|
1071
|
+
];
|
|
1072
|
+
/** @type {string[]} */
|
|
1073
|
+
const out = [];
|
|
1074
|
+
for (const row of rows) {
|
|
1075
|
+
let x = x0;
|
|
1076
|
+
const hh = row.h * u;
|
|
1077
|
+
for (const k of row.keys) {
|
|
1078
|
+
const kwid = k * u;
|
|
1079
|
+
out.push(
|
|
1080
|
+
`<rect x="${f6(x + gap / 2)}" y="${f6(y + gap / 2)}" width="${f6(kwid - gap)}" height="${f6(hh - gap)}" rx="${f6(0.14 * u)}"/>`,
|
|
1081
|
+
);
|
|
1082
|
+
x += kwid;
|
|
1083
|
+
}
|
|
1084
|
+
y += hh;
|
|
1085
|
+
}
|
|
1086
|
+
const pw = 0.42 * w;
|
|
1087
|
+
const ph = Math.min(0.34 * d, d - y - 0.08 * d - 0.06 * d);
|
|
1088
|
+
const py = y + 0.07 * d;
|
|
1089
|
+
return `url("data:image/svg+xml,${encodeURIComponent(
|
|
1090
|
+
`<svg xmlns="http://www.w3.org/2000/svg" width="${f6(w)}" height="${f6(d)}" viewBox="0 0 ${f6(w)} ${f6(d)}">` +
|
|
1091
|
+
`<rect x="0" y="0" width="${f6(w)}" height="${f6(0.028 * d)}" fill="rgba(0,0,0,0.22)"/>` +
|
|
1092
|
+
`<g fill="${keys}">${out.join("")}</g>` +
|
|
1093
|
+
`<rect x="${f6((w - pw) / 2)}" y="${f6(py)}" width="${f6(pw)}" height="${f6(ph)}" rx="${f6(0.03 * w)}" fill="rgba(0,0,0,0.05)" stroke="rgba(0,0,0,0.12)" stroke-width="${f6(0.0015 * w)}"/>` +
|
|
1094
|
+
"</svg>",
|
|
1095
|
+
)}") 0 0 / 100% 100% no-repeat`;
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
// --- the three -------------------------------------------------------------------------
|
|
1099
|
+
|
|
1100
|
+
/**
|
|
1101
|
+
* A laptop round a screen: the lid on a hinge at the back of the keyboard
|
|
1102
|
+
* half, the screen inside the lid, the keyboard and a touchpad drawn on the
|
|
1103
|
+
* keyboard half, enough thickness that shut it reads as a laptop. Its px are
|
|
1104
|
+
* the screen's: a bezel 2.8 % of the screen's width at the sides, 4 % above,
|
|
1105
|
+
* 5.5 % below; the keyboard half 70 % as deep as it is wide and 2.1 % of its
|
|
1106
|
+
* width thick, the lid 1.1 % (a 13-inch laptop is about 304 × 215 mm, 11 mm
|
|
1107
|
+
* shut). Its origin is the middle of its footprint, on the table.
|
|
1108
|
+
* Pose: open (degrees between lid and keyboard: 0 shut, 105 default, 180
|
|
1109
|
+
* flat), screen (1 lit … 0 dark), shadow.
|
|
1110
|
+
* @param {HTMLElement | null} host
|
|
1111
|
+
* @param {{ screen?: HTMLElement | string, w?: number, h?: number, color?: string, bezel?: string, keys?: string, thick?: number, lens?: { d?: number, cx?: number, cy?: number }, frame?: { width: number, height: number } }} [o]
|
|
1112
|
+
* screen: the element shown on it (moved onto the lid), or a picture's or a video's URL;
|
|
1113
|
+
* w, h: the screen's px (default the element's own size); color: its body (default "#c6c8cd");
|
|
1114
|
+
* bezel: the glass round the screen (default "#0d0d10"); keys: the keys (default "rgba(18,18,22,0.78)");
|
|
1115
|
+
* thick: the keyboard half's thickness as a share of its width (default 0.021)
|
|
1116
|
+
*/
|
|
1117
|
+
export function laptop(host, o = {}) {
|
|
1118
|
+
const scr = screenOf(o.screen, o.w, o.h, "laptop");
|
|
1119
|
+
const sw = scr.w;
|
|
1120
|
+
const sh = scr.h;
|
|
1121
|
+
const color = o.color ?? "#c6c8cd";
|
|
1122
|
+
const side = 0.028 * sw;
|
|
1123
|
+
const top = 0.04 * sw;
|
|
1124
|
+
const chin = 0.055 * sw;
|
|
1125
|
+
const W = sw + 2 * side;
|
|
1126
|
+
const L = sh + top + chin; // the lid, hinge to far edge
|
|
1127
|
+
const D = Math.max(0.7 * W, L + 0.02 * W);
|
|
1128
|
+
const T = (o.thick ?? 0.021) * W;
|
|
1129
|
+
const TL = 0.011 * W;
|
|
1130
|
+
const gap = 0.003 * W;
|
|
1131
|
+
const r = 0.03 * W;
|
|
1132
|
+
const hinge = v3(0, -T, -D / 2);
|
|
1133
|
+
const baseS = slab("base", {
|
|
1134
|
+
x0: -W / 2,
|
|
1135
|
+
x1: W / 2,
|
|
1136
|
+
z0: -D / 2,
|
|
1137
|
+
z1: D / 2,
|
|
1138
|
+
y0: -T,
|
|
1139
|
+
y1: 0,
|
|
1140
|
+
r,
|
|
1141
|
+
seg: 4,
|
|
1142
|
+
color,
|
|
1143
|
+
});
|
|
1144
|
+
const keysFace = rect({ ...baseS.top, name: "keys", kind: "decal", layer: 1 });
|
|
1145
|
+
const lidS = slab("lid", {
|
|
1146
|
+
x0: -W / 2,
|
|
1147
|
+
x1: W / 2,
|
|
1148
|
+
z0: -D / 2,
|
|
1149
|
+
z1: -D / 2 + L,
|
|
1150
|
+
y0: -T - gap - TL,
|
|
1151
|
+
y1: -T - gap,
|
|
1152
|
+
r,
|
|
1153
|
+
seg: 4,
|
|
1154
|
+
color,
|
|
1155
|
+
bottom: { kind: "bezel", color: o.bezel ?? "#0d0d10" },
|
|
1156
|
+
});
|
|
1157
|
+
// the screen on the lid's underside: its x along the lid, its y from the
|
|
1158
|
+
// far edge toward the hinge — upright once the lid is raised
|
|
1159
|
+
const B = lidS.bottom;
|
|
1160
|
+
const at0 = add(B.O, add(mulv(B.U, side), mulv(B.V, top)));
|
|
1161
|
+
const screen = rect({
|
|
1162
|
+
name: "screen",
|
|
1163
|
+
part: "lid",
|
|
1164
|
+
kind: "screen",
|
|
1165
|
+
layer: 2,
|
|
1166
|
+
O: at0,
|
|
1167
|
+
U: B.U,
|
|
1168
|
+
V: B.V,
|
|
1169
|
+
w: sw,
|
|
1170
|
+
h: sh,
|
|
1171
|
+
});
|
|
1172
|
+
const glass = rect({
|
|
1173
|
+
name: "glass",
|
|
1174
|
+
part: "lid",
|
|
1175
|
+
kind: "glass",
|
|
1176
|
+
layer: 3,
|
|
1177
|
+
O: at0,
|
|
1178
|
+
U: B.U,
|
|
1179
|
+
V: B.V,
|
|
1180
|
+
w: sw,
|
|
1181
|
+
h: sh,
|
|
1182
|
+
});
|
|
1183
|
+
const shadow = floor("shadow", "shadow", 0, 0, 1.22 * W, 1.32 * D, 0);
|
|
1184
|
+
screen.el = screenFace(scr.el, sw, sh);
|
|
1185
|
+
const faces = [shadow, ...baseS.faces, keysFace, ...lidS.faces, screen, glass];
|
|
1186
|
+
const keyPic = keyboard(baseS.top.w, baseS.top.h, o.keys ?? "rgba(18,18,22,0.78)");
|
|
1187
|
+
return device(
|
|
1188
|
+
host,
|
|
1189
|
+
{
|
|
1190
|
+
faces,
|
|
1191
|
+
main: screen,
|
|
1192
|
+
parts: (p) => ({
|
|
1193
|
+
lid: M.mul(
|
|
1194
|
+
M.mul(M.translate(hinge.x, hinge.y, hinge.z), M.rotateX(clamp(p.open, 0, 180))),
|
|
1195
|
+
M.translate(-hinge.x, -hinge.y, -hinge.z),
|
|
1196
|
+
),
|
|
1197
|
+
}),
|
|
1198
|
+
// the keyboard half's top divides them: the lid is always on its upper side
|
|
1199
|
+
order: (_p, eye) =>
|
|
1200
|
+
eye(v3(0, -T, 0), v3(0, -1, 0)) ? ["floor", "base", "lid"] : ["floor", "lid", "base"],
|
|
1201
|
+
look: (f) => (f === keysFace ? { background: keyPic } : null),
|
|
1202
|
+
style: (p, f) =>
|
|
1203
|
+
f === shadow
|
|
1204
|
+
? {
|
|
1205
|
+
background: `radial-gradient(closest-side, rgba(0,0,0,${f6(0.26 * clamp(p.shadow))}), rgba(0,0,0,${f6(0.1 * clamp(p.shadow))}) 62%, rgba(0,0,0,0))`,
|
|
1206
|
+
}
|
|
1207
|
+
: null,
|
|
1208
|
+
},
|
|
1209
|
+
o,
|
|
1210
|
+
{ open: 105 },
|
|
1211
|
+
);
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1214
|
+
/**
|
|
1215
|
+
* A phone: a rounded slab, the screen on its front with rounded corners, the
|
|
1216
|
+
* front edge bevelled. Its px are the screen's: a border 4.5 % of the screen's
|
|
1217
|
+
* width, outer corners 16 %, 8.5 % thick (a 7.8 mm phone 71.5 mm wide is
|
|
1218
|
+
* 11 %). Its origin is the middle of its screen, the screen toward the lens.
|
|
1219
|
+
* Pose: screen (1 lit … 0 dark).
|
|
1220
|
+
* @param {HTMLElement | null} host
|
|
1221
|
+
* @param {{ screen?: HTMLElement | string, w?: number, h?: number, color?: string, bezel?: string, lens?: { d?: number, cx?: number, cy?: number }, frame?: { width: number, height: number } }} [o]
|
|
1222
|
+
* color: its body (default "#1d1e22"); bezel: the glass round the screen (default "#050507")
|
|
1223
|
+
*/
|
|
1224
|
+
export function phone(host, o = {}) {
|
|
1225
|
+
const scr = screenOf(o.screen, o.w, o.h, "phone");
|
|
1226
|
+
const sw = scr.w;
|
|
1227
|
+
const sh = scr.h;
|
|
1228
|
+
const color = o.color ?? "#1d1e22";
|
|
1229
|
+
const border = 0.045 * sw;
|
|
1230
|
+
const W = sw + 2 * border;
|
|
1231
|
+
const H = sh + 2 * border;
|
|
1232
|
+
const T = 0.085 * sw;
|
|
1233
|
+
const R = 0.16 * sw;
|
|
1234
|
+
const bevel = 0.3 * T;
|
|
1235
|
+
// lying flat, screen up; stood up by its part's matrix (the top toward the lens)
|
|
1236
|
+
const body = slab("body", {
|
|
1237
|
+
x0: -W / 2,
|
|
1238
|
+
x1: W / 2,
|
|
1239
|
+
z0: -H / 2,
|
|
1240
|
+
z1: H / 2,
|
|
1241
|
+
y0: 0,
|
|
1242
|
+
y1: T,
|
|
1243
|
+
r: R,
|
|
1244
|
+
seg: 6,
|
|
1245
|
+
bevel,
|
|
1246
|
+
color,
|
|
1247
|
+
top: { kind: "bezel", color: o.bezel ?? "#050507" },
|
|
1248
|
+
});
|
|
1249
|
+
const sr = Math.max(0, R - border);
|
|
1250
|
+
const screen = rect({
|
|
1251
|
+
name: "screen",
|
|
1252
|
+
part: "body",
|
|
1253
|
+
kind: "screen",
|
|
1254
|
+
layer: 2,
|
|
1255
|
+
O: v3(-sw / 2, 0, -sh / 2),
|
|
1256
|
+
U: v3(1, 0, 0),
|
|
1257
|
+
V: v3(0, 0, 1),
|
|
1258
|
+
w: sw,
|
|
1259
|
+
h: sh,
|
|
1260
|
+
radius: sr,
|
|
1261
|
+
});
|
|
1262
|
+
const glass = rect({ ...screen, name: "glass", kind: "glass", layer: 3 });
|
|
1263
|
+
const shadow = floor("shadow", "shadow", 0, 0, 1.25 * W, 1.12 * H, T);
|
|
1264
|
+
screen.el = screenFace(scr.el, sw, sh);
|
|
1265
|
+
return device(
|
|
1266
|
+
host,
|
|
1267
|
+
{
|
|
1268
|
+
faces: [shadow, ...body.faces, screen, glass],
|
|
1269
|
+
main: screen,
|
|
1270
|
+
parts: () => ({ body: M.rotateX(-90), floor: M.rotateX(-90) }),
|
|
1271
|
+
order: () => ["floor", "body"],
|
|
1272
|
+
style: (p, f) =>
|
|
1273
|
+
f === shadow
|
|
1274
|
+
? {
|
|
1275
|
+
background: `radial-gradient(closest-side, rgba(0,0,0,${f6(0.3 * clamp(p.shadow))}), rgba(0,0,0,0))`,
|
|
1276
|
+
}
|
|
1277
|
+
: null,
|
|
1278
|
+
},
|
|
1279
|
+
o,
|
|
1280
|
+
{ shadow: 0 },
|
|
1281
|
+
);
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1284
|
+
/**
|
|
1285
|
+
* A plain box computer — a desktop, a small server, a machine in the cloud:
|
|
1286
|
+
* a rounded box with a bevelled top and a status light on its front. pose.on
|
|
1287
|
+
* (0…1) lights it: the light in its colour and a glow on the table round it.
|
|
1288
|
+
* Its px are its own (w × h × d, default 300 × 110 × 300); its origin is the
|
|
1289
|
+
* middle of its footprint, on the table; its front faces the lens.
|
|
1290
|
+
* @param {HTMLElement | null} host
|
|
1291
|
+
* @param {{ w?: number, h?: number, d?: number, r?: number, bevel?: number, color?: string, light?: string, front?: HTMLElement, top?: HTMLElement, lens?: { d?: number, cx?: number, cy?: number }, frame?: { width: number, height: number } }} [o]
|
|
1292
|
+
* color: its body (default "#ecebe7"); light: the status light's and the glow's colour
|
|
1293
|
+
* (default "#38c172"); front, top: an element of the page shown on that face
|
|
1294
|
+
* (front: (w − 2r) × (h − bevel) px; top: the top's flat part)
|
|
1295
|
+
*/
|
|
1296
|
+
export function computer(host, o = {}) {
|
|
1297
|
+
const w = o.w ?? 300;
|
|
1298
|
+
const h = o.h ?? 110;
|
|
1299
|
+
const dd = o.d ?? 300;
|
|
1300
|
+
const r = o.r ?? 0.16 * Math.min(w, dd);
|
|
1301
|
+
const bevel = Math.min(r, o.bevel ?? 0.16 * h);
|
|
1302
|
+
const color = o.color ?? "#ecebe7";
|
|
1303
|
+
const light = o.light ?? "#38c172";
|
|
1304
|
+
const lc = rgbOf(light);
|
|
1305
|
+
const body = slab("body", {
|
|
1306
|
+
x0: -w / 2,
|
|
1307
|
+
x1: w / 2,
|
|
1308
|
+
z0: -dd / 2,
|
|
1309
|
+
z1: dd / 2,
|
|
1310
|
+
y0: -h,
|
|
1311
|
+
y1: 0,
|
|
1312
|
+
r,
|
|
1313
|
+
seg: 6,
|
|
1314
|
+
bevel,
|
|
1315
|
+
color,
|
|
1316
|
+
});
|
|
1317
|
+
const fw = w - 2 * r;
|
|
1318
|
+
const fh = h - bevel;
|
|
1319
|
+
const front = rect({
|
|
1320
|
+
name: "front",
|
|
1321
|
+
part: "body",
|
|
1322
|
+
kind: "decal",
|
|
1323
|
+
layer: 1,
|
|
1324
|
+
O: v3(-w / 2 + r, -h + bevel, dd / 2),
|
|
1325
|
+
U: v3(1, 0, 0),
|
|
1326
|
+
V: v3(0, 1, 0),
|
|
1327
|
+
w: fw,
|
|
1328
|
+
h: fh,
|
|
1329
|
+
});
|
|
1330
|
+
const topFace = rect({ ...body.top, name: "top mark", kind: "decal", layer: 1 });
|
|
1331
|
+
const glow = floor("glow", "glow", 0, 0, 2.6 * w, 2.6 * dd, 0);
|
|
1332
|
+
const shadow = floor("shadow", "shadow", 0, 0, 1.3 * w, 1.3 * dd, 0);
|
|
1333
|
+
/** @type {HTMLElement | null} */
|
|
1334
|
+
let led = null;
|
|
1335
|
+
if (typeof document !== "undefined") {
|
|
1336
|
+
const fe = document.createElement("div");
|
|
1337
|
+
led = document.createElement("div");
|
|
1338
|
+
const size = Math.max(4, 0.045 * Math.min(w, h * 2));
|
|
1339
|
+
Object.assign(led.style, {
|
|
1340
|
+
position: "absolute",
|
|
1341
|
+
left: `${f6(0.06 * fw)}px`,
|
|
1342
|
+
top: `${f6(fh / 2 - size / 2)}px`,
|
|
1343
|
+
width: `${f6(size)}px`,
|
|
1344
|
+
height: `${f6(size)}px`,
|
|
1345
|
+
borderRadius: "50%",
|
|
1346
|
+
});
|
|
1347
|
+
fe.appendChild(led);
|
|
1348
|
+
if (o.front) {
|
|
1349
|
+
Object.assign(o.front.style, {
|
|
1350
|
+
position: "absolute",
|
|
1351
|
+
left: "0px",
|
|
1352
|
+
top: "0px",
|
|
1353
|
+
margin: "0px",
|
|
1354
|
+
});
|
|
1355
|
+
fe.appendChild(o.front);
|
|
1356
|
+
}
|
|
1357
|
+
front.el = fe;
|
|
1358
|
+
if (o.top) {
|
|
1359
|
+
const te = document.createElement("div");
|
|
1360
|
+
Object.assign(o.top.style, { position: "absolute", left: "0px", top: "0px", margin: "0px" });
|
|
1361
|
+
te.appendChild(o.top);
|
|
1362
|
+
topFace.el = te;
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1365
|
+
const faces = [glow, shadow, ...body.faces, front, ...(o.top ? [topFace] : [])];
|
|
1366
|
+
return device(
|
|
1367
|
+
host,
|
|
1368
|
+
{
|
|
1369
|
+
faces,
|
|
1370
|
+
main: front,
|
|
1371
|
+
parts: () => ({}),
|
|
1372
|
+
order: () => ["floor", "body"],
|
|
1373
|
+
/** @returns {Record<string, string> | null} */
|
|
1374
|
+
style: (p, f) => {
|
|
1375
|
+
const on = clamp(p.on);
|
|
1376
|
+
if (f === glow)
|
|
1377
|
+
return {
|
|
1378
|
+
background: `radial-gradient(closest-side, rgba(${lc.join(",")},${f6(0.42 * on)}), rgba(${lc.join(",")},${f6(0.14 * on)}) 55%, rgba(${lc.join(",")},0))`,
|
|
1379
|
+
visibility: on > 0 ? "inherit" : "hidden",
|
|
1380
|
+
};
|
|
1381
|
+
if (f === shadow)
|
|
1382
|
+
return {
|
|
1383
|
+
background: `radial-gradient(closest-side, rgba(0,0,0,${f6(0.24 * clamp(p.shadow))}), rgba(0,0,0,0))`,
|
|
1384
|
+
};
|
|
1385
|
+
if (f === front && led) {
|
|
1386
|
+
const dim = [150, 150, 150];
|
|
1387
|
+
const mix = dim.map((v, i) => Math.round(v + ((lc[i] ?? v) - v) * on));
|
|
1388
|
+
Object.assign(led.style, {
|
|
1389
|
+
background: `rgb(${mix.join(",")})`,
|
|
1390
|
+
boxShadow:
|
|
1391
|
+
on > 0
|
|
1392
|
+
? `0 0 ${f6(4 + 10 * on)}px ${f6(1 + 3 * on)}px rgba(${lc.join(",")},${f6(0.85 * on)})`
|
|
1393
|
+
: "none",
|
|
1394
|
+
});
|
|
1395
|
+
}
|
|
1396
|
+
return null;
|
|
1397
|
+
},
|
|
1398
|
+
},
|
|
1399
|
+
o,
|
|
1400
|
+
{ on: 0 },
|
|
1401
|
+
);
|
|
1402
|
+
}
|