@open-take/compositor 0.5.2 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cdp-CzT5BKNY.js +3 -0
- package/dist/cdp-QXbQfXna.js +373 -0
- package/dist/cdp-QXbQfXna.js.map +1 -0
- package/dist/index.d.ts +4327 -195
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +26282 -160
- package/dist/index.js.map +1 -1
- package/dist/server-841PMF2H.js +163 -0
- package/dist/server-841PMF2H.js.map +1 -0
- package/dist/server-C2aVv4-t.js +3 -0
- package/kit/audio.mjs +2366 -0
- package/kit/camera.js +587 -0
- package/kit/cursor.js +264 -0
- package/kit/cut.js +427 -0
- package/kit/draw.js +346 -0
- package/kit/look.js +589 -0
- package/kit/map.js +170 -0
- package/kit/media.js +3568 -0
- package/kit/motion.js +1115 -0
- package/kit/seams.js +1006 -0
- package/kit/stage.js +923 -0
- package/kit/time.js +812 -0
- package/kit/world.js +1072 -0
- package/package.json +7 -3
- package/src/ffmpeg.ts +63 -0
- package/src/film/beats.ts +1285 -0
- package/src/film/carry.ts +221 -0
- package/src/film/changes.ts +330 -0
- package/src/film/check.ts +996 -0
- package/src/film/clock.ts +2530 -0
- package/src/film/components-probe.ts +809 -0
- package/src/film/components.ts +1566 -0
- package/src/film/frames.ts +389 -0
- package/src/film/gallery.ts +3276 -0
- package/src/film/kit.ts +515 -0
- package/src/film/layout.ts +701 -0
- package/src/film/listen.ts +1979 -0
- package/src/film/look.ts +3829 -0
- package/src/film/materials.ts +976 -0
- package/src/film/moving.ts +248 -0
- package/src/film/part-files.ts +729 -0
- package/src/film/picture.ts +74 -0
- package/src/film/probe-text.ts +843 -0
- package/src/film/probe.ts +3456 -0
- package/src/film/provenance.ts +596 -0
- package/src/film/render.ts +2447 -0
- package/src/film/report.ts +1631 -0
- package/src/film/sheet.ts +156 -0
- package/src/film/study-declared.ts +123 -0
- package/src/film/study-picture.ts +791 -0
- package/src/film/study-sound.ts +416 -0
- package/src/film/study.ts +864 -0
- package/src/film/tuning.ts +155 -0
- package/src/film/viewer.ts +174 -0
- package/src/html/cdp.ts +575 -0
- package/src/html/server.ts +208 -0
- package/src/index.ts +202 -0
- package/src/launch-render.ts +3 -2
- package/src/math.ts +3 -3
- package/src/mjpeg-matroska.ts +228 -0
- package/src/render.ts +6 -4
- package/src/state-diff.ts +215 -0
- package/src/state-index.ts +99 -0
- package/src/types.ts +59 -1
- package/starter/PLAN.md +84 -0
- package/starter/START.md +460 -0
- package/starter/lib/anim.js +760 -0
- package/starter/lib/devices.js +1402 -0
- package/starter/lib/handoff.js +421 -0
- package/starter/lib/hud.js +1879 -0
- package/starter/lib/measure.mjs +154 -0
- package/starter/lib/moves.js +1095 -0
- package/starter/lib/palette.mjs +803 -0
- package/starter/lib/physics-seeds.mjs +198 -0
- package/starter/lib/physics.js +738 -0
- package/starter/lib/sampler.mjs +242 -0
- package/starter/lib/solid.js +727 -0
- package/starter/lib/space.js +1227 -0
- package/starter/lib/swarm.js +1398 -0
- package/starter/reference/motion.md +276 -0
- package/starter/reference/structure.md +466 -0
- package/starter/reference/travel/motion.md +433 -0
- package/starter/reference/travel/sound.md +241 -0
- package/starter/reference/travel/structure.md +518 -0
- package/starter/samples/NOTICE.txt +55 -0
- package/starter/samples/celli/celli_24_1.opus +0 -0
- package/starter/samples/celli/celli_24_3.opus +0 -0
- package/starter/samples/celli/celli_28_1.opus +0 -0
- package/starter/samples/celli/celli_28_3.opus +0 -0
- package/starter/samples/celli/celli_31_1.opus +0 -0
- package/starter/samples/celli/celli_31_3.opus +0 -0
- package/starter/samples/celli/celli_35_1.opus +0 -0
- package/starter/samples/celli/celli_35_3.opus +0 -0
- package/starter/samples/celli/celli_38_1.opus +0 -0
- package/starter/samples/celli/celli_38_3.opus +0 -0
- package/starter/samples/celli/celli_41_1.opus +0 -0
- package/starter/samples/celli/celli_41_3.opus +0 -0
- package/starter/samples/celli/celli_45_1.opus +0 -0
- package/starter/samples/celli/celli_45_3.opus +0 -0
- package/starter/samples/celli/celli_48_1.opus +0 -0
- package/starter/samples/celli/celli_48_3.opus +0 -0
- package/starter/samples/celli/celli_52_1.opus +0 -0
- package/starter/samples/celli/celli_52_3.opus +0 -0
- package/starter/samples/celli/celli_55_1.opus +0 -0
- package/starter/samples/celli/celli_55_3.opus +0 -0
- package/starter/samples/celli/celli_59_1.opus +0 -0
- package/starter/samples/celli/celli_59_3.opus +0 -0
- package/starter/samples/celli/celli_62_1.opus +0 -0
- package/starter/samples/celli/celli_62_3.opus +0 -0
- package/starter/samples/celli/celli_65_1.opus +0 -0
- package/starter/samples/celli/celli_65_3.opus +0 -0
- package/starter/samples/crash/crash_f_1.flac +0 -0
- package/starter/samples/crash/crash_fff_1.flac +0 -0
- package/starter/samples/ebass/ebass_0_x.flac +0 -0
- package/starter/samples/ebass/ebass_10_x.flac +0 -0
- package/starter/samples/ebass/ebass_11_x.flac +0 -0
- package/starter/samples/ebass/ebass_1_x.flac +0 -0
- package/starter/samples/ebass/ebass_2_x.flac +0 -0
- package/starter/samples/ebass/ebass_3_x.flac +0 -0
- package/starter/samples/ebass/ebass_4_x.flac +0 -0
- package/starter/samples/ebass/ebass_5_x.flac +0 -0
- package/starter/samples/ebass/ebass_6_x.flac +0 -0
- package/starter/samples/ebass/ebass_7_x.flac +0 -0
- package/starter/samples/ebass/ebass_8_x.flac +0 -0
- package/starter/samples/ebass/ebass_9_x.flac +0 -0
- package/starter/samples/ek_clap/ek_clap_1_1.flac +0 -0
- package/starter/samples/ek_hat/ek_hat_1_1.flac +0 -0
- package/starter/samples/ek_hat/ek_hat_1_2.flac +0 -0
- package/starter/samples/ek_kick/ek_kick_1_1.flac +0 -0
- package/starter/samples/ek_kick/ek_kick_1_2.flac +0 -0
- package/starter/samples/glock/glock_67_x.flac +0 -0
- package/starter/samples/glock/glock_72_x.flac +0 -0
- package/starter/samples/glock/glock_79_x.flac +0 -0
- package/starter/samples/glock/glock_84_x.flac +0 -0
- package/starter/samples/glock/glock_91_x.flac +0 -0
- package/starter/samples/glock/glock_96_x.flac +0 -0
- package/starter/samples/harp/harp_101_f.opus +0 -0
- package/starter/samples/harp/harp_28_f.opus +0 -0
- package/starter/samples/harp/harp_31_mp.opus +0 -0
- package/starter/samples/harp/harp_35_mf.opus +0 -0
- package/starter/samples/harp/harp_38_mf.opus +0 -0
- package/starter/samples/harp/harp_41_mf.opus +0 -0
- package/starter/samples/harp/harp_45_mf.opus +0 -0
- package/starter/samples/harp/harp_48_mf.opus +0 -0
- package/starter/samples/harp/harp_52_mf.opus +0 -0
- package/starter/samples/harp/harp_55_mf.opus +0 -0
- package/starter/samples/harp/harp_59_mf.opus +0 -0
- package/starter/samples/harp/harp_62_mf.opus +0 -0
- package/starter/samples/harp/harp_65_mf.opus +0 -0
- package/starter/samples/harp/harp_69_mf.opus +0 -0
- package/starter/samples/harp/harp_72_mf.opus +0 -0
- package/starter/samples/harp/harp_76_mf.opus +0 -0
- package/starter/samples/harp/harp_79_mf.opus +0 -0
- package/starter/samples/harp/harp_83_mf.opus +0 -0
- package/starter/samples/harp/harp_86_mf.opus +0 -0
- package/starter/samples/harp/harp_89_mf.opus +0 -0
- package/starter/samples/harp/harp_93_mf.opus +0 -0
- package/starter/samples/harp/harp_95_mf.opus +0 -0
- package/starter/samples/harp/harp_98_f.opus +0 -0
- package/starter/samples/manifest.json +2951 -0
- package/starter/samples/marimba/marimba_29_x.flac +0 -0
- package/starter/samples/marimba/marimba_36_x.flac +0 -0
- package/starter/samples/marimba/marimba_43_x.flac +0 -0
- package/starter/samples/marimba/marimba_47_x.flac +0 -0
- package/starter/samples/marimba/marimba_53_x.flac +0 -0
- package/starter/samples/marimba/marimba_60_x.flac +0 -0
- package/starter/samples/marimba/marimba_67_x.flac +0 -0
- package/starter/samples/marimba/marimba_71_x.flac +0 -0
- package/starter/samples/marimba/marimba_77_x.flac +0 -0
- package/starter/samples/marimba/marimba_84_x.flac +0 -0
- package/starter/samples/piano/piano_102_12.opus +0 -0
- package/starter/samples/piano/piano_102_16.opus +0 -0
- package/starter/samples/piano/piano_102_4.opus +0 -0
- package/starter/samples/piano/piano_102_8.opus +0 -0
- package/starter/samples/piano/piano_105_12.opus +0 -0
- package/starter/samples/piano/piano_105_16.opus +0 -0
- package/starter/samples/piano/piano_105_4.opus +0 -0
- package/starter/samples/piano/piano_105_8.opus +0 -0
- package/starter/samples/piano/piano_108_12.opus +0 -0
- package/starter/samples/piano/piano_108_16.opus +0 -0
- package/starter/samples/piano/piano_108_4.opus +0 -0
- package/starter/samples/piano/piano_108_8.opus +0 -0
- package/starter/samples/piano/piano_21_12.opus +0 -0
- package/starter/samples/piano/piano_21_16.opus +0 -0
- package/starter/samples/piano/piano_21_4.opus +0 -0
- package/starter/samples/piano/piano_21_8.opus +0 -0
- package/starter/samples/piano/piano_24_12.opus +0 -0
- package/starter/samples/piano/piano_24_16.opus +0 -0
- package/starter/samples/piano/piano_24_4.opus +0 -0
- package/starter/samples/piano/piano_24_8.opus +0 -0
- package/starter/samples/piano/piano_27_12.opus +0 -0
- package/starter/samples/piano/piano_27_16.opus +0 -0
- package/starter/samples/piano/piano_27_4.opus +0 -0
- package/starter/samples/piano/piano_27_8.opus +0 -0
- package/starter/samples/piano/piano_30_12.opus +0 -0
- package/starter/samples/piano/piano_30_16.opus +0 -0
- package/starter/samples/piano/piano_30_4.opus +0 -0
- package/starter/samples/piano/piano_30_8.opus +0 -0
- package/starter/samples/piano/piano_33_12.opus +0 -0
- package/starter/samples/piano/piano_33_16.opus +0 -0
- package/starter/samples/piano/piano_33_4.opus +0 -0
- package/starter/samples/piano/piano_33_8.opus +0 -0
- package/starter/samples/piano/piano_36_12.opus +0 -0
- package/starter/samples/piano/piano_36_16.opus +0 -0
- package/starter/samples/piano/piano_36_4.opus +0 -0
- package/starter/samples/piano/piano_36_8.opus +0 -0
- package/starter/samples/piano/piano_39_12.opus +0 -0
- package/starter/samples/piano/piano_39_16.opus +0 -0
- package/starter/samples/piano/piano_39_4.opus +0 -0
- package/starter/samples/piano/piano_39_8.opus +0 -0
- package/starter/samples/piano/piano_42_12.opus +0 -0
- package/starter/samples/piano/piano_42_16.opus +0 -0
- package/starter/samples/piano/piano_42_4.opus +0 -0
- package/starter/samples/piano/piano_42_8.opus +0 -0
- package/starter/samples/piano/piano_45_12.opus +0 -0
- package/starter/samples/piano/piano_45_16.opus +0 -0
- package/starter/samples/piano/piano_45_4.opus +0 -0
- package/starter/samples/piano/piano_45_8.opus +0 -0
- package/starter/samples/piano/piano_48_12.opus +0 -0
- package/starter/samples/piano/piano_48_16.opus +0 -0
- package/starter/samples/piano/piano_48_4.opus +0 -0
- package/starter/samples/piano/piano_48_8.opus +0 -0
- package/starter/samples/piano/piano_51_12.opus +0 -0
- package/starter/samples/piano/piano_51_16.opus +0 -0
- package/starter/samples/piano/piano_51_4.opus +0 -0
- package/starter/samples/piano/piano_51_8.opus +0 -0
- package/starter/samples/piano/piano_54_12.opus +0 -0
- package/starter/samples/piano/piano_54_16.opus +0 -0
- package/starter/samples/piano/piano_54_4.opus +0 -0
- package/starter/samples/piano/piano_54_8.opus +0 -0
- package/starter/samples/piano/piano_57_12.opus +0 -0
- package/starter/samples/piano/piano_57_16.opus +0 -0
- package/starter/samples/piano/piano_57_4.opus +0 -0
- package/starter/samples/piano/piano_57_8.opus +0 -0
- package/starter/samples/piano/piano_60_12.opus +0 -0
- package/starter/samples/piano/piano_60_16.opus +0 -0
- package/starter/samples/piano/piano_60_4.opus +0 -0
- package/starter/samples/piano/piano_60_8.opus +0 -0
- package/starter/samples/piano/piano_63_12.opus +0 -0
- package/starter/samples/piano/piano_63_16.opus +0 -0
- package/starter/samples/piano/piano_63_4.opus +0 -0
- package/starter/samples/piano/piano_63_8.opus +0 -0
- package/starter/samples/piano/piano_66_12.opus +0 -0
- package/starter/samples/piano/piano_66_16.opus +0 -0
- package/starter/samples/piano/piano_66_4.opus +0 -0
- package/starter/samples/piano/piano_66_8.opus +0 -0
- package/starter/samples/piano/piano_69_12.opus +0 -0
- package/starter/samples/piano/piano_69_16.opus +0 -0
- package/starter/samples/piano/piano_69_4.opus +0 -0
- package/starter/samples/piano/piano_69_8.opus +0 -0
- package/starter/samples/piano/piano_72_12.opus +0 -0
- package/starter/samples/piano/piano_72_16.opus +0 -0
- package/starter/samples/piano/piano_72_4.opus +0 -0
- package/starter/samples/piano/piano_72_8.opus +0 -0
- package/starter/samples/piano/piano_75_12.opus +0 -0
- package/starter/samples/piano/piano_75_16.opus +0 -0
- package/starter/samples/piano/piano_75_4.opus +0 -0
- package/starter/samples/piano/piano_75_8.opus +0 -0
- package/starter/samples/piano/piano_78_12.opus +0 -0
- package/starter/samples/piano/piano_78_16.opus +0 -0
- package/starter/samples/piano/piano_78_4.opus +0 -0
- package/starter/samples/piano/piano_78_8.opus +0 -0
- package/starter/samples/piano/piano_81_12.opus +0 -0
- package/starter/samples/piano/piano_81_16.opus +0 -0
- package/starter/samples/piano/piano_81_4.opus +0 -0
- package/starter/samples/piano/piano_81_8.opus +0 -0
- package/starter/samples/piano/piano_84_12.opus +0 -0
- package/starter/samples/piano/piano_84_16.opus +0 -0
- package/starter/samples/piano/piano_84_4.opus +0 -0
- package/starter/samples/piano/piano_84_8.opus +0 -0
- package/starter/samples/piano/piano_87_12.opus +0 -0
- package/starter/samples/piano/piano_87_16.opus +0 -0
- package/starter/samples/piano/piano_87_4.opus +0 -0
- package/starter/samples/piano/piano_87_8.opus +0 -0
- package/starter/samples/piano/piano_90_12.opus +0 -0
- package/starter/samples/piano/piano_90_16.opus +0 -0
- package/starter/samples/piano/piano_90_4.opus +0 -0
- package/starter/samples/piano/piano_90_8.opus +0 -0
- package/starter/samples/piano/piano_93_12.opus +0 -0
- package/starter/samples/piano/piano_93_16.opus +0 -0
- package/starter/samples/piano/piano_93_4.opus +0 -0
- package/starter/samples/piano/piano_93_8.opus +0 -0
- package/starter/samples/piano/piano_96_12.opus +0 -0
- package/starter/samples/piano/piano_96_16.opus +0 -0
- package/starter/samples/piano/piano_96_4.opus +0 -0
- package/starter/samples/piano/piano_96_8.opus +0 -0
- package/starter/samples/piano/piano_99_12.opus +0 -0
- package/starter/samples/piano/piano_99_16.opus +0 -0
- package/starter/samples/piano/piano_99_4.opus +0 -0
- package/starter/samples/piano/piano_99_8.opus +0 -0
- package/starter/samples/piano/piano_rel_102_x.opus +0 -0
- package/starter/samples/piano/piano_rel_105_x.opus +0 -0
- package/starter/samples/piano/piano_rel_108_x.opus +0 -0
- package/starter/samples/piano/piano_rel_21_x.opus +0 -0
- package/starter/samples/piano/piano_rel_24_x.opus +0 -0
- package/starter/samples/piano/piano_rel_27_x.opus +0 -0
- package/starter/samples/piano/piano_rel_30_x.opus +0 -0
- package/starter/samples/piano/piano_rel_33_x.opus +0 -0
- package/starter/samples/piano/piano_rel_36_x.opus +0 -0
- package/starter/samples/piano/piano_rel_39_x.opus +0 -0
- package/starter/samples/piano/piano_rel_42_x.opus +0 -0
- package/starter/samples/piano/piano_rel_45_x.opus +0 -0
- package/starter/samples/piano/piano_rel_48_x.opus +0 -0
- package/starter/samples/piano/piano_rel_51_x.opus +0 -0
- package/starter/samples/piano/piano_rel_54_x.opus +0 -0
- package/starter/samples/piano/piano_rel_57_x.opus +0 -0
- package/starter/samples/piano/piano_rel_60_x.opus +0 -0
- package/starter/samples/piano/piano_rel_63_x.opus +0 -0
- package/starter/samples/piano/piano_rel_66_x.opus +0 -0
- package/starter/samples/piano/piano_rel_69_x.opus +0 -0
- package/starter/samples/piano/piano_rel_72_x.opus +0 -0
- package/starter/samples/piano/piano_rel_75_x.opus +0 -0
- package/starter/samples/piano/piano_rel_78_x.opus +0 -0
- package/starter/samples/piano/piano_rel_81_x.opus +0 -0
- package/starter/samples/piano/piano_rel_84_x.opus +0 -0
- package/starter/samples/piano/piano_rel_87_x.opus +0 -0
- package/starter/samples/piano/piano_rel_90_x.opus +0 -0
- package/starter/samples/piano/piano_rel_93_x.opus +0 -0
- package/starter/samples/piano/piano_rel_96_x.opus +0 -0
- package/starter/samples/piano/piano_rel_99_x.opus +0 -0
- package/starter/samples/pizz/pizz_24_2.flac +0 -0
- package/starter/samples/pizz/pizz_28_2.flac +0 -0
- package/starter/samples/pizz/pizz_31_2.flac +0 -0
- package/starter/samples/pizz/pizz_35_2.flac +0 -0
- package/starter/samples/pizz/pizz_38_2.flac +0 -0
- package/starter/samples/pizz/pizz_41_2.flac +0 -0
- package/starter/samples/pizz/pizz_45_2.flac +0 -0
- package/starter/samples/pizz/pizz_48_2.flac +0 -0
- package/starter/samples/pizz/pizz_52_2.flac +0 -0
- package/starter/samples/pizz/pizz_57_2.flac +0 -0
- package/starter/samples/pizz/pizz_60_2.flac +0 -0
- package/starter/samples/pizz/pizz_64_2.flac +0 -0
- package/starter/samples/pizz/pizz_67_2.flac +0 -0
- package/starter/samples/pizz/pizz_71_2.flac +0 -0
- package/starter/samples/pizz/pizz_74_2.flac +0 -0
- package/starter/samples/pk_hat/pk_hat_2_1.flac +0 -0
- package/starter/samples/pk_hat/pk_hat_2_2.flac +0 -0
- package/starter/samples/pk_hat/pk_hat_6_1.flac +0 -0
- package/starter/samples/pk_hat/pk_hat_6_2.flac +0 -0
- package/starter/samples/pk_kick/pk_kick_3_1.flac +0 -0
- package/starter/samples/pk_kick/pk_kick_3_2.flac +0 -0
- package/starter/samples/pk_kick/pk_kick_7_1.flac +0 -0
- package/starter/samples/pk_kick/pk_kick_7_2.flac +0 -0
- package/starter/samples/pk_ohat/pk_ohat_3_1.flac +0 -0
- package/starter/samples/pk_ohat/pk_ohat_3_2.flac +0 -0
- package/starter/samples/pk_ohat/pk_ohat_6_1.flac +0 -0
- package/starter/samples/pk_ohat/pk_ohat_6_2.flac +0 -0
- package/starter/samples/pk_rim/pk_rim_2_1.flac +0 -0
- package/starter/samples/pk_rim/pk_rim_2_2.flac +0 -0
- package/starter/samples/pk_rim/pk_rim_5_1.flac +0 -0
- package/starter/samples/pk_rim/pk_rim_5_2.flac +0 -0
- package/starter/samples/pk_snare/pk_snare_3_1.flac +0 -0
- package/starter/samples/pk_snare/pk_snare_3_2.flac +0 -0
- package/starter/samples/pk_snare/pk_snare_7_1.flac +0 -0
- package/starter/samples/pk_snare/pk_snare_7_2.flac +0 -0
- package/starter/samples/shaker/shaker_1_1.flac +0 -0
- package/starter/samples/shaker/shaker_2_1.flac +0 -0
- package/starter/samples/snap/snap_r_1.flac +0 -0
- package/starter/samples/snap/snap_r_2.flac +0 -0
- package/starter/samples/snap/snap_r_3.flac +0 -0
- package/starter/samples/snap/snap_r_4.flac +0 -0
- package/starter/samples/snap/snap_r_5.flac +0 -0
- package/starter/samples/snap/snap_r_6.flac +0 -0
- package/starter/samples/tom/tom_3_1.flac +0 -0
- package/starter/samples/tom/tom_3_2.flac +0 -0
- package/starter/samples/tom/tom_4_1.flac +0 -0
- package/starter/samples/tom/tom_4_2.flac +0 -0
- package/starter/samples/vibes/vibes_41_1.opus +0 -0
- package/starter/samples/vibes/vibes_41_2.opus +0 -0
- package/starter/samples/vibes/vibes_45_1.opus +0 -0
- package/starter/samples/vibes/vibes_45_2.opus +0 -0
- package/starter/samples/vibes/vibes_48_1.opus +0 -0
- package/starter/samples/vibes/vibes_48_2.opus +0 -0
- package/starter/samples/vibes/vibes_52_1.opus +0 -0
- package/starter/samples/vibes/vibes_52_2.opus +0 -0
- package/starter/samples/vibes/vibes_55_1.opus +0 -0
- package/starter/samples/vibes/vibes_55_2.opus +0 -0
- package/starter/samples/vibes/vibes_59_1.opus +0 -0
- package/starter/samples/vibes/vibes_59_2.opus +0 -0
- package/starter/samples/vibes/vibes_62_1.opus +0 -0
- package/starter/samples/vibes/vibes_62_2.opus +0 -0
- package/starter/samples/vibes/vibes_65_1.opus +0 -0
- package/starter/samples/vibes/vibes_65_2.opus +0 -0
- package/starter/samples/vibes/vibes_69_1.opus +0 -0
- package/starter/samples/vibes/vibes_69_2.opus +0 -0
- package/starter/samples/vibes/vibes_72_1.opus +0 -0
- package/starter/samples/vibes/vibes_72_2.opus +0 -0
- package/starter/samples/vibes/vibes_76_1.opus +0 -0
- package/starter/samples/vibes/vibes_76_2.opus +0 -0
- package/starter/samples/violas/violas_36_1.opus +0 -0
- package/starter/samples/violas/violas_36_2.opus +0 -0
- package/starter/samples/violas/violas_38_1.opus +0 -0
- package/starter/samples/violas/violas_38_2.opus +0 -0
- package/starter/samples/violas/violas_40_1.opus +0 -0
- package/starter/samples/violas/violas_40_2.opus +0 -0
- package/starter/samples/violas/violas_43_1.opus +0 -0
- package/starter/samples/violas/violas_43_2.opus +0 -0
- package/starter/samples/violas/violas_47_1.opus +0 -0
- package/starter/samples/violas/violas_47_2.opus +0 -0
- package/starter/samples/violas/violas_50_1.opus +0 -0
- package/starter/samples/violas/violas_50_2.opus +0 -0
- package/starter/samples/violas/violas_53_1.opus +0 -0
- package/starter/samples/violas/violas_53_2.opus +0 -0
- package/starter/samples/violas/violas_57_1.opus +0 -0
- package/starter/samples/violas/violas_57_2.opus +0 -0
- package/starter/samples/violas/violas_60_1.opus +0 -0
- package/starter/samples/violas/violas_60_2.opus +0 -0
- package/starter/samples/violas/violas_64_1.opus +0 -0
- package/starter/samples/violas/violas_64_2.opus +0 -0
- package/starter/samples/violas/violas_67_1.opus +0 -0
- package/starter/samples/violas/violas_67_2.opus +0 -0
- package/starter/samples/violas/violas_71_1.opus +0 -0
- package/starter/samples/violas/violas_71_2.opus +0 -0
- package/starter/samples/violas/violas_74_1.opus +0 -0
- package/starter/samples/violas/violas_74_2.opus +0 -0
- package/starter/samples/violins/violins_43_1.opus +0 -0
- package/starter/samples/violins/violins_43_2.opus +0 -0
- package/starter/samples/violins/violins_45_1.opus +0 -0
- package/starter/samples/violins/violins_45_2.opus +0 -0
- package/starter/samples/violins/violins_47_1.opus +0 -0
- package/starter/samples/violins/violins_47_2.opus +0 -0
- package/starter/samples/violins/violins_50_1.opus +0 -0
- package/starter/samples/violins/violins_50_2.opus +0 -0
- package/starter/samples/violins/violins_54_1.opus +0 -0
- package/starter/samples/violins/violins_54_2.opus +0 -0
- package/starter/samples/violins/violins_57_1.opus +0 -0
- package/starter/samples/violins/violins_57_2.opus +0 -0
- package/starter/samples/violins/violins_60_1.opus +0 -0
- package/starter/samples/violins/violins_60_2.opus +0 -0
- package/starter/samples/violins/violins_64_1.opus +0 -0
- package/starter/samples/violins/violins_64_2.opus +0 -0
- package/starter/samples/violins/violins_67_1.opus +0 -0
- package/starter/samples/violins/violins_67_2.opus +0 -0
- package/starter/samples/violins/violins_71_1.opus +0 -0
- package/starter/samples/violins/violins_71_2.opus +0 -0
- package/starter/samples/violins/violins_74_1.opus +0 -0
- package/starter/samples/violins/violins_74_2.opus +0 -0
- package/starter/samples/woodblock/woodblock_f_1.flac +0 -0
- package/starter/samples/woodblock/woodblock_f_2.flac +0 -0
|
@@ -0,0 +1,727 @@
|
|
|
1
|
+
// solid.js — objects made by code for a film page's 3D shots: a product's
|
|
2
|
+
// shell from a distance function, a turned part from a profile, surfaces
|
|
3
|
+
// painted by code (brushed, spun, a circuit board), a backdrop, a room's
|
|
4
|
+
// light to reflect, and a finish (bloom and a grade) for a lit object on a
|
|
5
|
+
// dark ground. No model files and no downloads: what a launch film shows as
|
|
6
|
+
// "the thing itself" when the product has no 3D model of its own.
|
|
7
|
+
//
|
|
8
|
+
// The modelling is abyssal-garden's (MIT, (c) 2026 Maksymilian Dendura,
|
|
9
|
+
// github.com/Noniv/abyssal-garden, source/src/math.js and world.js): write a
|
|
10
|
+
// signed distance function, sample it on a grid and turn it into a mesh by
|
|
11
|
+
// surface nets — smooth unions, cut pockets and repeated grooves come free.
|
|
12
|
+
// Measured in Node 22 at product size: a slab with a pocket at 6 mm voxels
|
|
13
|
+
// 152 ms (372k triangles); a shroud with a fan well and fins at 8 mm 303 ms
|
|
14
|
+
// (284k) — 4 mm took 2.7 s. Make it once, at load.
|
|
15
|
+
//
|
|
16
|
+
// import * as THREE from "./kit/three.module.min.js";
|
|
17
|
+
// import { solid, sd } from "./lib/solid.js";
|
|
18
|
+
// const S = solid(THREE);
|
|
19
|
+
// const shell = S.sdf((x, y, z) => sd.smax(sd.roundBox(x, y, z, 300, 20, 120, 12),
|
|
20
|
+
// -sd.cylY(x - 80, y - 20, z, 90, 8), 4), [-310, -30, -130, 310, 30, 130], 3);
|
|
21
|
+
// const disc = S.lathe([[0, 0], [88, 0], [92, 4, 1], [92, 8, 1], [0, 8]], { seg: 256, ribs: 120 });
|
|
22
|
+
// scene.environment = S.room(renderer); // studio light to reflect, no file
|
|
23
|
+
// scene.environmentIntensity = 0.55; // start here: at 1 a metal face turned up
|
|
24
|
+
// // mirrors the ceiling's light box as a white disk
|
|
25
|
+
// const spun = S.texture(S.spun(1024)); // a map for bumpMap / roughnessMap
|
|
26
|
+
//
|
|
27
|
+
// pure (no three): sd.* — roundBox, box, sphere, cylY, capsule, torus, smin, smax, repeat;
|
|
28
|
+
// sdfMesh(sdf, box, voxel) → { position, normal, index }; latheMesh(profile, o);
|
|
29
|
+
// surfaceNets(D, nx, ny, nz); rng(seed) (anim.js's); vnoise; fbm;
|
|
30
|
+
// brushed / spun / pcb / backdropPaint — pixels drawn on a canvas
|
|
31
|
+
// with three, solid(THREE): sdf(), lathe() → BufferGeometry; texture(canvas, srgb);
|
|
32
|
+
// planarUV(geometry, axes); room(renderer) → a prefiltered environment;
|
|
33
|
+
// backdrop() → a CanvasTexture; finish(renderer, o) → bloom + grade for space.js
|
|
34
|
+
// ready objects, each { group, … } to put in a scene — space.js's scene.add(it) also runs
|
|
35
|
+
// its `tick` at every sample's time and takes its fog:
|
|
36
|
+
// laptop(o) — a keyboard half and a lid on a hinge; `screen` is the group a live slab
|
|
37
|
+
// rides on (st.slab(el, { parent: lap.screen, shadow: false })), `open` the lid's
|
|
38
|
+
// angle, a number or a function of film time
|
|
39
|
+
// desk(o) — a table to stand things on that fades into the scene's ground colour,
|
|
40
|
+
// with a sky light and a sun; `look` (a function of film time) changes them
|
|
41
|
+
// contact(w, d, o) — the soft shadow under a thing standing on the table
|
|
42
|
+
//
|
|
43
|
+
// const main = st.scene("main", { clear: (t) => (t < 6 ? 0x2a211b : 0xe9dfcf) });
|
|
44
|
+
// main.add(S.desk({ color: 0x77604c }));
|
|
45
|
+
// const lap = main.add(S.laptop({ screen: [1440, 900], open: (t) => keys(t, [[0, 105], [3, 105], [3.3, 0, "in2"]]) }));
|
|
46
|
+
// const app = st.slab(document.querySelector("#app"), { parent: lap.screen, shadow: false, scale: 2.5 });
|
|
47
|
+
//
|
|
48
|
+
// The finish: abyssal-garden's chain (Karis-weighted first downsample, a
|
|
49
|
+
// six-level bloom, exposure, vignette, the ACES fit, a luminance S-curve,
|
|
50
|
+
// highlight desaturation) with its two traps fixed — the bloom's alpha held
|
|
51
|
+
// at 1 so additive blending does not multiply it, and no lift of the blacks
|
|
52
|
+
// unless asked (`lift`: its warm lift turns a black ground brown). It ends in
|
|
53
|
+
// the sRGB curve, where abyssal-garden's grade ends in a plain gamma 2.2:
|
|
54
|
+
// a little darker in the deepest shadows. Keep it off an interface: bloom
|
|
55
|
+
// lifts white UI into a glare.
|
|
56
|
+
|
|
57
|
+
import { rng } from "./anim.js";
|
|
58
|
+
|
|
59
|
+
// --- pure: noise and randomness ---------------------------------------------
|
|
60
|
+
|
|
61
|
+
/** a seeded random stream, 0..1 (mulberry32), lib/anim.js's: `const r = rng(3); r()` */
|
|
62
|
+
export { rng };
|
|
63
|
+
|
|
64
|
+
/** @param {number} x @param {number} y @param {number} z */
|
|
65
|
+
const ihash = (x, y, z) => {
|
|
66
|
+
let h = (Math.imul(x, 374761393) + Math.imul(y, 668265263) + Math.imul(z, 1274126177)) | 0;
|
|
67
|
+
h = Math.imul(h ^ (h >>> 13), 1274126177);
|
|
68
|
+
return ((h ^ (h >>> 16)) >>> 0) / 4294967296;
|
|
69
|
+
};
|
|
70
|
+
/** @param {number} a @param {number} b @param {number} t */
|
|
71
|
+
const mix = (a, b, t) => a + (b - a) * t;
|
|
72
|
+
/** @param {number} x @param {number} a @param {number} b */
|
|
73
|
+
const clamp = (x, a, b) => (x < a ? a : x > b ? b : x);
|
|
74
|
+
|
|
75
|
+
/** value noise in 3D, 0..1 @param {number} x @param {number} y @param {number} z */
|
|
76
|
+
export function vnoise(x, y, z) {
|
|
77
|
+
const ix = Math.floor(x), iy = Math.floor(y), iz = Math.floor(z);
|
|
78
|
+
let fx = x - ix, fy = y - iy, fz = z - iz;
|
|
79
|
+
fx = fx * fx * (3 - 2 * fx); fy = fy * fy * (3 - 2 * fy); fz = fz * fz * (3 - 2 * fz);
|
|
80
|
+
const a = mix(mix(ihash(ix, iy, iz), ihash(ix + 1, iy, iz), fx), mix(ihash(ix, iy + 1, iz), ihash(ix + 1, iy + 1, iz), fx), fy);
|
|
81
|
+
const b = mix(mix(ihash(ix, iy, iz + 1), ihash(ix + 1, iy, iz + 1), fx), mix(ihash(ix, iy + 1, iz + 1), ihash(ix + 1, iy + 1, iz + 1), fx), fy);
|
|
82
|
+
return mix(a, b, fz);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** fractal value noise, about 0..1 @param {number} x @param {number} y @param {number} z @param {number} [octaves] */
|
|
86
|
+
export function fbm(x, y, z, octaves = 4) {
|
|
87
|
+
let a = 0.5, s = 0;
|
|
88
|
+
for (let i = 0; i < octaves; i++) {
|
|
89
|
+
s += a * vnoise(x, y, z);
|
|
90
|
+
x = x * 2.03 + 17.1; y = y * 2.03 + 31.7; z = z * 2.03 + 5.3; a *= 0.5;
|
|
91
|
+
}
|
|
92
|
+
return s / (1 - 2 * a);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// --- pure: distance functions -----------------------------------------------
|
|
96
|
+
|
|
97
|
+
/** Signed distances (negative inside), the usual Inigo Quilez forms, scalar
|
|
98
|
+
* arguments so a field of millions of samples allocates nothing. Sizes are
|
|
99
|
+
* half-extents. */
|
|
100
|
+
export const sd = {
|
|
101
|
+
/** @param {number} x @param {number} y @param {number} z @param {number} bx @param {number} by @param {number} bz @param {number} r */
|
|
102
|
+
roundBox: (x, y, z, bx, by, bz, r) => {
|
|
103
|
+
const qx = Math.abs(x) - bx + r, qy = Math.abs(y) - by + r, qz = Math.abs(z) - bz + r;
|
|
104
|
+
return Math.hypot(Math.max(qx, 0), Math.max(qy, 0), Math.max(qz, 0)) + Math.min(Math.max(qx, Math.max(qy, qz)), 0) - r;
|
|
105
|
+
},
|
|
106
|
+
/** @param {number} x @param {number} y @param {number} z @param {number} bx @param {number} by @param {number} bz */
|
|
107
|
+
box: (x, y, z, bx, by, bz) => sd.roundBox(x, y, z, bx, by, bz, 0),
|
|
108
|
+
/** @param {number} x @param {number} y @param {number} z @param {number} r */
|
|
109
|
+
sphere: (x, y, z, r) => Math.hypot(x, y, z) - r,
|
|
110
|
+
/** a cylinder round y, radius r, half-height h @param {number} x @param {number} y @param {number} z @param {number} r @param {number} h */
|
|
111
|
+
cylY: (x, y, z, r, h) => {
|
|
112
|
+
const dx = Math.hypot(x, z) - r, dy = Math.abs(y) - h;
|
|
113
|
+
return Math.min(Math.max(dx, dy), 0) + Math.hypot(Math.max(dx, 0), Math.max(dy, 0));
|
|
114
|
+
},
|
|
115
|
+
/** @param {number} x @param {number} y @param {number} z @param {number} ax @param {number} ay @param {number} az @param {number} bx @param {number} by @param {number} bz @param {number} r */
|
|
116
|
+
capsule: (x, y, z, ax, ay, az, bx, by, bz, r) => {
|
|
117
|
+
const pax = x - ax, pay = y - ay, paz = z - az, bax = bx - ax, bay = by - ay, baz = bz - az;
|
|
118
|
+
const h = clamp((pax * bax + pay * bay + paz * baz) / Math.max(1e-12, bax * bax + bay * bay + baz * baz), 0, 1); // a == b: a sphere
|
|
119
|
+
return Math.hypot(pax - bax * h, pay - bay * h, paz - baz * h) - r;
|
|
120
|
+
},
|
|
121
|
+
/** a ring round y: R to the tube's middle, r the tube @param {number} x @param {number} y @param {number} z @param {number} R @param {number} r */
|
|
122
|
+
torus: (x, y, z, R, r) => Math.hypot(Math.hypot(x, z) - R, y) - r,
|
|
123
|
+
/** a smooth union, k the width of the blend (abyssal's polynomial smooth-min; k 0: the plain min) @param {number} a @param {number} b @param {number} k */
|
|
124
|
+
smin: (a, b, k) => { if (!(k > 0)) return Math.min(a, b); const h = Math.max(k - Math.abs(a - b), 0) / k; return Math.min(a, b) - h * h * k * 0.25; },
|
|
125
|
+
/** a smooth intersection; smax(d, -cut, k) cuts a pocket with a rounded edge (k 0: the plain max) @param {number} a @param {number} b @param {number} k */
|
|
126
|
+
smax: (a, b, k) => { if (!(k > 0)) return Math.max(a, b); const h = Math.max(k - Math.abs(a - b), 0) / k; return Math.max(a, b) + h * h * k * 0.25; },
|
|
127
|
+
/** a coordinate folded so one shape repeats every `step` (fins, grooves, keys) @param {number} x @param {number} step */
|
|
128
|
+
repeat: (x, step) => x - step * Math.round(x / step),
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// --- pure: meshes -----------------------------------------------------------
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Naive surface nets (abyssal-garden math.js): one vertex in each cell the
|
|
135
|
+
* surface crosses, at the mean of the edge crossings; a quad across each
|
|
136
|
+
* crossed edge. D > 0 inside. Positions in grid units. Two surfaces less than
|
|
137
|
+
* a cell apart share a cell's one vertex: the mesh pinches there, its edges
|
|
138
|
+
* shared by more than two triangles — keep separate parts a voxel or two apart.
|
|
139
|
+
* @param {Float32Array} D @param {number} nx @param {number} ny @param {number} nz
|
|
140
|
+
* @returns {{ pos: Float32Array, idx: Uint32Array, nv: number, ni: number }}
|
|
141
|
+
*/
|
|
142
|
+
export function surfaceNets(D, nx, ny, nz) {
|
|
143
|
+
let pos = new Float32Array(1 << 16), nv = 0;
|
|
144
|
+
let idx = new Uint32Array(1 << 17), ni = 0;
|
|
145
|
+
const sl = nx * ny;
|
|
146
|
+
let cur = new Int32Array(sl), prev = new Int32Array(sl);
|
|
147
|
+
/** @param {number} i */
|
|
148
|
+
const at = (i) => /** @type {number} */ (D[i]);
|
|
149
|
+
/** @param {Int32Array} a @param {number} i */
|
|
150
|
+
const g = (a, i) => /** @type {number} */ (a[i]);
|
|
151
|
+
for (let z = 0; z < nz - 1; z++) {
|
|
152
|
+
for (let y = 0; y < ny - 1; y++) {
|
|
153
|
+
let i0 = nx * (y + ny * z);
|
|
154
|
+
for (let x = 0; x < nx - 1; x++, i0++) {
|
|
155
|
+
const d0 = at(i0), d1 = at(i0 + 1), d2 = at(i0 + nx), d3 = at(i0 + nx + 1);
|
|
156
|
+
const d4 = at(i0 + sl), d5 = at(i0 + sl + 1), d6 = at(i0 + sl + nx), d7 = at(i0 + sl + nx + 1);
|
|
157
|
+
const m = (+(d0 > 0)) | (+(d1 > 0) << 1) | (+(d2 > 0) << 2) | (+(d3 > 0) << 3) | (+(d4 > 0) << 4) | (+(d5 > 0) << 5) | (+(d6 > 0) << 6) | (+(d7 > 0) << 7);
|
|
158
|
+
if (m === 0 || m === 255) continue;
|
|
159
|
+
let sx = 0, sy = 0, sz = 0, n = 0, t;
|
|
160
|
+
if ((d0 > 0) !== (d1 > 0)) { t = d0 / (d0 - d1); sx += t; n++; }
|
|
161
|
+
if ((d2 > 0) !== (d3 > 0)) { t = d2 / (d2 - d3); sx += t; sy += 1; n++; }
|
|
162
|
+
if ((d4 > 0) !== (d5 > 0)) { t = d4 / (d4 - d5); sx += t; sz += 1; n++; }
|
|
163
|
+
if ((d6 > 0) !== (d7 > 0)) { t = d6 / (d6 - d7); sx += t; sy += 1; sz += 1; n++; }
|
|
164
|
+
if ((d0 > 0) !== (d2 > 0)) { t = d0 / (d0 - d2); sy += t; n++; }
|
|
165
|
+
if ((d1 > 0) !== (d3 > 0)) { t = d1 / (d1 - d3); sy += t; sx += 1; n++; }
|
|
166
|
+
if ((d4 > 0) !== (d6 > 0)) { t = d4 / (d4 - d6); sy += t; sz += 1; n++; }
|
|
167
|
+
if ((d5 > 0) !== (d7 > 0)) { t = d5 / (d5 - d7); sy += t; sx += 1; sz += 1; n++; }
|
|
168
|
+
if ((d0 > 0) !== (d4 > 0)) { t = d0 / (d0 - d4); sz += t; n++; }
|
|
169
|
+
if ((d1 > 0) !== (d5 > 0)) { t = d1 / (d1 - d5); sz += t; sx += 1; n++; }
|
|
170
|
+
if ((d2 > 0) !== (d6 > 0)) { t = d2 / (d2 - d6); sz += t; sy += 1; n++; }
|
|
171
|
+
if ((d3 > 0) !== (d7 > 0)) { t = d3 / (d3 - d7); sz += t; sx += 1; sy += 1; n++; }
|
|
172
|
+
if (nv * 3 + 3 > pos.length) { const p2 = new Float32Array(pos.length * 2); p2.set(pos); pos = p2; }
|
|
173
|
+
const vi = nv++;
|
|
174
|
+
pos[vi * 3] = x + sx / n; pos[vi * 3 + 1] = y + sy / n; pos[vi * 3 + 2] = z + sz / n;
|
|
175
|
+
const ci = x + nx * y;
|
|
176
|
+
cur[ci] = vi;
|
|
177
|
+
if (ni + 18 > idx.length) { const i2 = new Uint32Array(idx.length * 2); i2.set(idx); idx = i2; }
|
|
178
|
+
const s0 = d0 > 0;
|
|
179
|
+
/** @param {number} a @param {number} b @param {number} c @param {number} d */
|
|
180
|
+
const quad = (a, b, c, d) => {
|
|
181
|
+
if (s0) { idx[ni++] = a; idx[ni++] = b; idx[ni++] = c; idx[ni++] = a; idx[ni++] = c; idx[ni++] = d; }
|
|
182
|
+
else { idx[ni++] = a; idx[ni++] = c; idx[ni++] = b; idx[ni++] = a; idx[ni++] = d; idx[ni++] = c; }
|
|
183
|
+
};
|
|
184
|
+
if ((d1 > 0) !== s0 && y > 0 && z > 0) quad(vi, g(cur, ci - nx), g(prev, ci - nx), g(prev, ci));
|
|
185
|
+
if ((d2 > 0) !== s0 && x > 0 && z > 0) quad(vi, g(prev, ci), g(prev, ci - 1), g(cur, ci - 1));
|
|
186
|
+
if ((d4 > 0) !== s0 && x > 0 && y > 0) quad(vi, g(cur, ci - 1), g(cur, ci - 1 - nx), g(cur, ci - nx));
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
const tmp = cur; cur = prev; prev = tmp;
|
|
190
|
+
}
|
|
191
|
+
return { pos: pos.subarray(0, nv * 3), idx: idx.subarray(0, ni), nv, ni };
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Any distance function → a mesh: sampled every `voxel` over `box`
|
|
196
|
+
* ([x0, y0, z0, x1, y1, z1], scene units), surface nets, normals from the
|
|
197
|
+
* field's gradient (smooth across the grid's facets). Detail below about two
|
|
198
|
+
* voxels is lost: a fin 0.8 mm thick wants voxels under 8 mm; type and screws
|
|
199
|
+
* belong in a texture.
|
|
200
|
+
* @param {(x: number, y: number, z: number) => number} f negative inside
|
|
201
|
+
* @param {number[]} box @param {number} voxel
|
|
202
|
+
* @returns {{ position: Float32Array, normal: Float32Array, index: Uint32Array, voxels: number, triangles: number }}
|
|
203
|
+
*/
|
|
204
|
+
export function sdfMesh(f, box, voxel) {
|
|
205
|
+
const [x0 = 0, y0 = 0, z0 = 0, x1 = 1, y1 = 1, z1 = 1] = box;
|
|
206
|
+
const vs = voxel;
|
|
207
|
+
const nx = Math.ceil((x1 - x0) / vs) + 3, ny = Math.ceil((y1 - y0) / vs) + 3, nz = Math.ceil((z1 - z0) / vs) + 3;
|
|
208
|
+
const ox = x0 - vs, oy = y0 - vs, oz = z0 - vs;
|
|
209
|
+
const D = new Float32Array(nx * ny * nz);
|
|
210
|
+
for (let z = 0; z < nz; z++) for (let y = 0; y < ny; y++) for (let x = 0; x < nx; x++) D[x + nx * (y + ny * z)] = -f(ox + x * vs, oy + y * vs, oz + z * vs);
|
|
211
|
+
const sn = surfaceNets(D, nx, ny, nz);
|
|
212
|
+
/** trilinear sample of the grid @param {number} x @param {number} y @param {number} z */
|
|
213
|
+
const smp = (x, y, z) => {
|
|
214
|
+
x = clamp(x, 0, nx - 1.001); y = clamp(y, 0, ny - 1.001); z = clamp(z, 0, nz - 1.001);
|
|
215
|
+
const ix = x | 0, iy = y | 0, iz = z | 0, fx = x - ix, fy = y - iy, fz = z - iz;
|
|
216
|
+
const i = ix + nx * (iy + ny * iz), sl = nx * ny;
|
|
217
|
+
const d = (/** @type {number} */ k) => /** @type {number} */ (D[k]);
|
|
218
|
+
const a = mix(mix(d(i), d(i + 1), fx), mix(d(i + nx), d(i + nx + 1), fx), fy);
|
|
219
|
+
const b = mix(mix(d(i + sl), d(i + sl + 1), fx), mix(d(i + sl + nx), d(i + sl + nx + 1), fx), fy);
|
|
220
|
+
return mix(a, b, fz);
|
|
221
|
+
};
|
|
222
|
+
const P = new Float32Array(sn.nv * 3), N = new Float32Array(sn.nv * 3), e = 0.7;
|
|
223
|
+
for (let k = 0; k < sn.nv; k++) {
|
|
224
|
+
const x = /** @type {number} */ (sn.pos[k * 3]), y = /** @type {number} */ (sn.pos[k * 3 + 1]), z = /** @type {number} */ (sn.pos[k * 3 + 2]);
|
|
225
|
+
const ax = smp(x - e, y, z) - smp(x + e, y, z), ay = smp(x, y - e, z) - smp(x, y + e, z), az = smp(x, y, z - e) - smp(x, y, z + e);
|
|
226
|
+
const l = Math.hypot(ax, ay, az) || 1;
|
|
227
|
+
P[k * 3] = ox + x * vs; P[k * 3 + 1] = oy + y * vs; P[k * 3 + 2] = oz + z * vs;
|
|
228
|
+
N[k * 3] = ax / l; N[k * 3 + 1] = ay / l; N[k * 3 + 2] = az / l;
|
|
229
|
+
}
|
|
230
|
+
return { position: P, normal: N, index: new Uint32Array(sn.idx), voxels: nx * ny * nz, triangles: sn.ni / 3 };
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* A turned part: a profile [[r, y, ribs?], …] (bottom to top) swept round y.
|
|
235
|
+
* `ribs` grooves round it, `ribAmp` their depth as a share of r; the third
|
|
236
|
+
* value of a ring says how much of the ribs it takes (0 none … 1 all), so a
|
|
237
|
+
* coin's reeding sits on its edge only. `lump` roughens the radius by noise.
|
|
238
|
+
* @param {number[][]} profile
|
|
239
|
+
* @param {{ seg?: number, ribs?: number, ribAmp?: number, lump?: number }} [o]
|
|
240
|
+
* @returns {{ position: Float32Array, uv: Float32Array, index: Uint32Array }}
|
|
241
|
+
*/
|
|
242
|
+
export function latheMesh(profile, { seg = 128, ribs = 0, ribAmp = 0.02, lump = 0 } = {}) {
|
|
243
|
+
const rings = profile.length, cols = seg + 1;
|
|
244
|
+
const P = new Float32Array(rings * cols * 3), UV = new Float32Array(rings * cols * 2);
|
|
245
|
+
profile.forEach(([r = 0, y = 0, rw = ribs ? 1 : 0], k) => {
|
|
246
|
+
for (let s = 0; s <= seg; s++) {
|
|
247
|
+
const a = (s / seg) * Math.PI * 2;
|
|
248
|
+
const rl = r * (1 + lump * (fbm(Math.cos(a) * 1.5 + y * 2, y * 3, Math.sin(a) * 1.5, 2) - 0.5) + (ribs ? ribAmp * rw * Math.cos(ribs * a) : 0));
|
|
249
|
+
const o = (k * cols + s) * 3;
|
|
250
|
+
P[o] = Math.cos(a) * rl; P[o + 1] = y; P[o + 2] = Math.sin(a) * rl;
|
|
251
|
+
UV[(k * cols + s) * 2] = s / seg; UV[(k * cols + s) * 2 + 1] = rings > 1 ? k / (rings - 1) : 0;
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
const I = new Uint32Array((rings - 1) * seg * 6);
|
|
255
|
+
let n = 0;
|
|
256
|
+
for (let k = 0; k < rings - 1; k++) for (let s = 0; s < seg; s++) {
|
|
257
|
+
const a = k * cols + s, b = (k + 1) * cols + s;
|
|
258
|
+
I[n++] = a; I[n++] = b; I[n++] = a + 1; I[n++] = a + 1; I[n++] = b; I[n++] = b + 1;
|
|
259
|
+
}
|
|
260
|
+
return { position: P, uv: UV, index: I };
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// --- surfaces painted by code (a canvas; three not needed) -----------------
|
|
264
|
+
|
|
265
|
+
/** @param {number} w @param {number} h */
|
|
266
|
+
function canvasOf(w, h) {
|
|
267
|
+
const c = document.createElement("canvas");
|
|
268
|
+
c.width = w; c.height = h;
|
|
269
|
+
return { c, g: /** @type {CanvasRenderingContext2D} */ (c.getContext("2d")) };
|
|
270
|
+
}
|
|
271
|
+
/** a grey picture from f(x, y) → 0..1 @param {number} w @param {number} h @param {(x: number, y: number) => number} f */
|
|
272
|
+
export function paint(w, h, f) {
|
|
273
|
+
const { c, g } = canvasOf(w, h);
|
|
274
|
+
const im = g.createImageData(w, h);
|
|
275
|
+
for (let y = 0; y < h; y++) for (let x = 0; x < w; x++) {
|
|
276
|
+
const v = clamp(f(x, y), 0, 1) * 255, o = (x + w * y) * 4;
|
|
277
|
+
im.data[o] = im.data[o + 1] = im.data[o + 2] = v; im.data[o + 3] = 255;
|
|
278
|
+
}
|
|
279
|
+
g.putImageData(im, 0, 0);
|
|
280
|
+
return c;
|
|
281
|
+
}
|
|
282
|
+
/** brushed metal: long streaks along x — a bumpMap or roughnessMap @param {number} [w] @param {number} [h] */
|
|
283
|
+
export const brushed = (w = 1024, h = 512) =>
|
|
284
|
+
paint(w, h, (x, y) => 0.5 + 0.32 * (vnoise(x * 0.004, y * 0.9, 1) - 0.5) + 0.18 * (vnoise(x * 0.02, y * 3.1, 7) - 0.5));
|
|
285
|
+
/** spun metal: fine rings round the middle (a fan hub, a lid, a knob) @param {number} [size] */
|
|
286
|
+
export const spun = (size = 1024) =>
|
|
287
|
+
paint(size, size, (x, y) => { const r = Math.hypot(x - size / 2, y - size / 2); return 0.5 + 0.35 * (vnoise(r * 0.9, 0, 3) - 0.5) + 0.25 * (vnoise(r * 0.15, 5, 1) - 0.5); });
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* A circuit board's face: traces leaving a package's edge, bending 45°,
|
|
291
|
+
* ending on vias; gold edge fingers; silkscreen boxes. A colour map.
|
|
292
|
+
* @param {{ width?: number, height?: number, seed?: number, traces?: number, board?: string, copper?: string }} [o]
|
|
293
|
+
*/
|
|
294
|
+
export function pcb({ width = 2048, height = 1024, seed = 31, traces = 420, board = "#15191d", copper = "196,150,62" } = {}) {
|
|
295
|
+
const { c, g } = canvasOf(width, height), r = rng(seed), rr = (/** @type {number} */ a, /** @type {number} */ b) => a + (b - a) * r();
|
|
296
|
+
g.fillStyle = board; g.fillRect(0, 0, width, height);
|
|
297
|
+
for (let i = 0; i < 2600; i++) { g.fillStyle = `rgba(40,70,60,${rr(0.05, 0.2)})`; g.fillRect(rr(0, width), rr(0, height), rr(2, 30), rr(2, 30)); }
|
|
298
|
+
const cx = width * 0.5, cy = height * 0.47, hw = width * 0.146, hh = height * 0.234;
|
|
299
|
+
g.lineCap = "round"; g.lineJoin = "round";
|
|
300
|
+
for (let i = 0; i < traces; i++) {
|
|
301
|
+
const side = i % 4, s = rr(-1, 1), out = rr(40, 600);
|
|
302
|
+
let x = side < 2 ? cx + (side ? 1 : -1) * hw : cx + s * hw, y = side < 2 ? cy + s * hh : cy + (side === 2 ? 1 : -1) * hh;
|
|
303
|
+
const dx = side === 0 ? -1 : side === 1 ? 1 : 0, dy = side === 2 ? 1 : side === 3 ? -1 : 0, bend = r() < 0.5 ? -1 : 1;
|
|
304
|
+
g.strokeStyle = r() < 0.8 ? `rgba(${copper},${rr(0.55, 0.95)})` : "rgba(150,160,170,.6)"; g.lineWidth = rr(1.5, 4.5);
|
|
305
|
+
g.beginPath(); g.moveTo(x, y); x += dx * out; y += dy * out; g.lineTo(x, y);
|
|
306
|
+
const l2 = rr(20, 300); x += (dx || bend) * l2 * 0.7; y += (dy || bend) * l2 * 0.7; g.lineTo(x, y);
|
|
307
|
+
x += dx * rr(20, 400); y += dy * rr(20, 400); g.lineTo(x, y); g.stroke();
|
|
308
|
+
g.fillStyle = "#d8b060"; g.beginPath(); g.arc(x, y, rr(3, 7), 0, 6.283); g.fill();
|
|
309
|
+
}
|
|
310
|
+
g.fillStyle = "#d4a94e"; for (let i = 0; i < 60; i++) g.fillRect(140 + i * 29, height - 70, 18, 62);
|
|
311
|
+
g.strokeStyle = "rgba(230,230,230,.5)"; g.lineWidth = 2;
|
|
312
|
+
for (let i = 0; i < 70; i++) g.strokeRect(rr(60, width - 120), rr(60, height - 160), rr(20, 70), rr(14, 40));
|
|
313
|
+
return c;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* A backdrop painted once at load: domain-warped fractal noise with ridged
|
|
318
|
+
* veins, three colours from deep to bright, a little grain — soft enough to
|
|
319
|
+
* sit behind windows out of focus. `colors` [deep, mid, vein] as [r, g, b].
|
|
320
|
+
* @param {{ width?: number, height?: number, seed?: number, colors?: number[][], scale?: number }} [o]
|
|
321
|
+
*/
|
|
322
|
+
export function backdropPaint({ width = 1280, height = 720, seed = 7, colors = [[18, 30, 52], [44, 84, 112], [120, 178, 205]], scale = 1 } = {}) {
|
|
323
|
+
const { c, g } = canvasOf(width, height), r = rng(seed);
|
|
324
|
+
const im = g.createImageData(width, height), d = im.data;
|
|
325
|
+
const [c0 = [0, 0, 0], c1 = [0, 0, 0], c2 = [0, 0, 0]] = colors;
|
|
326
|
+
const ox = seed * 13.7;
|
|
327
|
+
for (let y = 0; y < height; y++) for (let x = 0; x < width; x++) {
|
|
328
|
+
const u = (x / width) * 7 * scale + ox, v = (y / height) * 4 * scale;
|
|
329
|
+
const wx = u + 1.6 * fbm(u * 0.6 + 3, v * 0.6, 0.5, 3), wy = v + 1.6 * fbm(u * 0.6, v * 0.6 + 9, 0.5, 3);
|
|
330
|
+
const f = fbm(wx, wy, 1.5, 5);
|
|
331
|
+
const ridge = 1 - Math.abs(2 * fbm(wx * 1.3 + 4, wy * 1.3 + 2, 2.5, 4) - 1);
|
|
332
|
+
const vein = ridge ** 10 * 0.85;
|
|
333
|
+
const grain = (r() - 0.5) * 10;
|
|
334
|
+
const k = (y * width + x) * 4;
|
|
335
|
+
for (let ch = 0; ch < 3; ch++) {
|
|
336
|
+
const a = /** @type {number} */ (c0[ch]), b = /** @type {number} */ (c1[ch]), e = /** @type {number} */ (c2[ch]);
|
|
337
|
+
d[k + ch] = clamp(a + (b - a) * f * 1.4 + (e - a) * vein + grain, 0, 255);
|
|
338
|
+
}
|
|
339
|
+
d[k + 3] = 255;
|
|
340
|
+
}
|
|
341
|
+
g.putImageData(im, 0, 0);
|
|
342
|
+
return c;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// --- with three -------------------------------------------------------------
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* The parts that need three: geometry, textures, light, the finish.
|
|
349
|
+
* @param {any} T the three module the page imported
|
|
350
|
+
*/
|
|
351
|
+
export function solid(T) {
|
|
352
|
+
if (!T) throw new Error("solid: needs three — solid(THREE)");
|
|
353
|
+
|
|
354
|
+
/** @param {{ position: Float32Array, normal?: Float32Array, uv?: Float32Array, index: Uint32Array }} m */
|
|
355
|
+
function geometry(m) {
|
|
356
|
+
const g = new T.BufferGeometry();
|
|
357
|
+
g.setAttribute("position", new T.BufferAttribute(m.position, 3));
|
|
358
|
+
if (m.normal) g.setAttribute("normal", new T.BufferAttribute(m.normal, 3));
|
|
359
|
+
if (m.uv) g.setAttribute("uv", new T.BufferAttribute(m.uv, 2));
|
|
360
|
+
g.setIndex(new T.BufferAttribute(m.index, 1));
|
|
361
|
+
if (!m.normal) g.computeVertexNormals();
|
|
362
|
+
return g;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/** uv from two axes' extents, for a map on a face made by sdf()
|
|
366
|
+
* @param {any} g @param {[number, number, number, number]} ext [a0, b0, a1, b1] @param {"xz" | "xy" | "zy"} [axes] */
|
|
367
|
+
function planarUV(g, ext, axes = "xz") {
|
|
368
|
+
const p = g.attributes.position, uv = new Float32Array(p.count * 2);
|
|
369
|
+
const [a0, b0, a1, b1] = ext;
|
|
370
|
+
for (let i = 0; i < p.count; i++) {
|
|
371
|
+
const a = axes === "zy" ? p.getZ(i) : p.getX(i), b = axes === "xy" || axes === "zy" ? p.getY(i) : p.getZ(i);
|
|
372
|
+
uv[i * 2] = (a - a0) / (a1 - a0); uv[i * 2 + 1] = (b - b0) / (b1 - b0);
|
|
373
|
+
}
|
|
374
|
+
g.setAttribute("uv", new T.BufferAttribute(uv, 2));
|
|
375
|
+
return g;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// --- ready objects ---
|
|
379
|
+
|
|
380
|
+
/** a rounded rectangle lying flat as a plate: x and z about its middle, y from 0 up to h
|
|
381
|
+
* @param {number} w @param {number} d @param {number} h @param {number} r */
|
|
382
|
+
function plate(w, d, h, r) {
|
|
383
|
+
const sh = new T.Shape(), x = -w / 2, y = -d / 2, rr = Math.min(r, w / 2, d / 2);
|
|
384
|
+
sh.moveTo(x + rr, y); sh.lineTo(x + w - rr, y); sh.quadraticCurveTo(x + w, y, x + w, y + rr);
|
|
385
|
+
sh.lineTo(x + w, y + d - rr); sh.quadraticCurveTo(x + w, y + d, x + w - rr, y + d);
|
|
386
|
+
sh.lineTo(x + rr, y + d); sh.quadraticCurveTo(x, y + d, x, y + d - rr);
|
|
387
|
+
sh.lineTo(x, y + rr); sh.quadraticCurveTo(x, y, x + rr, y);
|
|
388
|
+
// a small bevel, so the edge catches the light as one line
|
|
389
|
+
const b = Math.min(1.2, h / 4);
|
|
390
|
+
const g = new T.ExtrudeGeometry(sh, { depth: h - 2 * b, bevelEnabled: true, bevelThickness: b, bevelSize: b, bevelOffset: -b, bevelSegments: 2, curveSegments: 10 });
|
|
391
|
+
g.translate(0, 0, b);
|
|
392
|
+
g.rotateX(-Math.PI / 2);
|
|
393
|
+
return { geometry: g, shape: sh };
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* The soft shadow under a thing standing on a table: a blurred dark card
|
|
398
|
+
* lying flat at y 0, a little bigger than the w × d footprint it is for.
|
|
399
|
+
* Not cast by any light — it is there whatever the lights do, as the
|
|
400
|
+
* darkest part of a contact shadow is.
|
|
401
|
+
* @param {number} w @param {number} d
|
|
402
|
+
* @param {{ blur?: number, opacity?: number, radius?: number, color?: string }} [o] blur: px of the footprint (60)
|
|
403
|
+
*/
|
|
404
|
+
function contact(w, d, { blur = 60, opacity = 0.6, radius = 60, color = "0,0,0" } = {}) {
|
|
405
|
+
// drawn at a quarter size: it is a blur, and four times the pixels show nothing more
|
|
406
|
+
const k = 0.25, pad = blur * 3;
|
|
407
|
+
const { c, g } = canvasOf(Math.ceil((w + pad * 2) * k), Math.ceil((d + pad * 2) * k));
|
|
408
|
+
g.filter = `blur(${blur * k}px)`;
|
|
409
|
+
g.fillStyle = `rgba(${color},${opacity})`;
|
|
410
|
+
g.beginPath(); g.roundRect(pad * k, pad * k, w * k, d * k, radius * k); g.fill();
|
|
411
|
+
const tex = new T.CanvasTexture(c); tex.colorSpace = T.SRGBColorSpace;
|
|
412
|
+
const m = new T.Mesh(new T.PlaneGeometry(w + pad * 2, d + pad * 2), new T.MeshBasicMaterial({ map: tex, transparent: true, depthWrite: false, toneMapped: false }));
|
|
413
|
+
m.rotation.x = -Math.PI / 2;
|
|
414
|
+
return m;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/** keys and a touchpad for a keyboard half w × d, drawn once: a colour map with a clear ground
|
|
418
|
+
* @param {number} w @param {number} d */
|
|
419
|
+
function keysPaint(w, d) {
|
|
420
|
+
const { c, g } = canvasOf(Math.round(w), Math.round(d));
|
|
421
|
+
const u = w * 0.06, x0 = (w - 14 * u) / 2, y0 = d * 0.07;
|
|
422
|
+
const rows = [Array(14).fill(1), [1.5, ...Array(11).fill(1), 1.5], [1.8, ...Array(10).fill(1), 2.2], [2.3, ...Array(9).fill(1), 2.7], [1, 1, 1, 1.3, 5.4, 1.3, 1, 1, 1]];
|
|
423
|
+
g.fillStyle = "rgba(20,20,24,0.9)";
|
|
424
|
+
rows.forEach((row, j) => {
|
|
425
|
+
let x = x0;
|
|
426
|
+
const hh = j === 0 ? u * 0.62 : u, y = y0 + (j === 0 ? 0 : u * 0.62 + (j - 1) * u);
|
|
427
|
+
for (const k of row) { g.beginPath(); g.roundRect(x + u * 0.055, y + u * 0.055, k * u - u * 0.11, hh - u * 0.11, u * 0.11); g.fill(); x += k * u; }
|
|
428
|
+
});
|
|
429
|
+
const top = y0 + 4.62 * u + d * 0.03, ph = Math.max(10, d - top - d * 0.05), pw = Math.min(w * 0.37, ph * 1.6);
|
|
430
|
+
g.fillStyle = "rgba(0,0,0,0.06)"; g.strokeStyle = "rgba(0,0,0,0.16)"; g.lineWidth = 2;
|
|
431
|
+
g.beginPath(); g.roundRect((w - pw) / 2, top, pw, ph, u * 0.24); g.fill(); g.stroke();
|
|
432
|
+
return c;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* A laptop standing on y 0, its footprint's middle at the origin, its
|
|
437
|
+
* hinge along the back (−z): a keyboard half with keys drawn on it, a lid
|
|
438
|
+
* that turns on the hinge, a dark bezel inside the lid. `screen` is a group
|
|
439
|
+
* on the lid's inner face, the size of the screen: a live slab given it as
|
|
440
|
+
* parent lies on the lid and turns with it, and its own point(x, y, t)
|
|
441
|
+
* says where a part of the interface is in the space, lid and all. The lid
|
|
442
|
+
* shut hides the screen; a light in the lid throws the screen's glow on
|
|
443
|
+
* the keys, more the wider it is open. No logo and no maker's shape.
|
|
444
|
+
* Sizes are the scene's units (CSS px of the screen): for a 1440 × 900
|
|
445
|
+
* screen the laptop is 1530 wide and 990 deep.
|
|
446
|
+
* @param {{ screen?: [number, number], bezel?: number, base?: number, lid?: number, radius?: number,
|
|
447
|
+
* color?: number | string, roughness?: number, metalness?: number, keys?: boolean, shadow?: boolean,
|
|
448
|
+
* glow?: number, glowColor?: number | string, open?: number | ((t: number) => number) }} [o]
|
|
449
|
+
* screen: its size (1440 × 900); bezel: the lid's margin round it (45); base, lid: thicknesses
|
|
450
|
+
* (26, 13); open: degrees between lid and keyboard (0 shut … 105), or that from film time;
|
|
451
|
+
* glow: the screen's light on the keys with the lid upright (0.5; 0: none) — one point of
|
|
452
|
+
* light in front of the screen: at 1.6 it showed on the palm rest as a white spot
|
|
453
|
+
*/
|
|
454
|
+
function laptop(o = {}) {
|
|
455
|
+
const [sw, sh] = o.screen ?? [1440, 900];
|
|
456
|
+
const bezel = o.bezel ?? 45, TB = o.base ?? 26, TL = o.lid ?? 13, radius = o.radius ?? 44, GAP = 3, FOOT = 1;
|
|
457
|
+
const LW = sw + 2 * bezel, LD = sh + 2 * bezel;
|
|
458
|
+
const metal = new T.MeshStandardMaterial({ color: o.color ?? 0xc4c6cc, roughness: o.roughness ?? 0.42, metalness: o.metalness ?? 0.25 });
|
|
459
|
+
const group = new T.Group();
|
|
460
|
+
const base = new T.Mesh(plate(LW, LD, TB, radius).geometry, metal);
|
|
461
|
+
base.position.y = FOOT;
|
|
462
|
+
group.add(base);
|
|
463
|
+
if (o.keys !== false) {
|
|
464
|
+
const kt = new T.CanvasTexture(keysPaint(LW, LD)); kt.colorSpace = T.SRGBColorSpace; kt.anisotropy = 8;
|
|
465
|
+
const keysMesh = new T.Mesh(new T.PlaneGeometry(LW, LD), new T.MeshStandardMaterial({ map: kt, transparent: true, roughness: 0.6 }));
|
|
466
|
+
keysMesh.rotation.x = -Math.PI / 2; keysMesh.position.y = FOOT + TB + 0.6;
|
|
467
|
+
group.add(keysMesh);
|
|
468
|
+
}
|
|
469
|
+
// the lid, hinged along the back edge; shut it lies over the keys, its inner face down
|
|
470
|
+
const lid = new T.Group();
|
|
471
|
+
lid.position.set(0, FOOT + TB + GAP, -LD / 2);
|
|
472
|
+
group.add(lid);
|
|
473
|
+
const shell = plate(LW, LD, TL, radius);
|
|
474
|
+
shell.geometry.translate(0, 0, LD / 2);
|
|
475
|
+
lid.add(new T.Mesh(shell.geometry, metal));
|
|
476
|
+
const inner = new T.Mesh(new T.ShapeGeometry(shell.shape, 10), new T.MeshBasicMaterial({ color: 0x0c0c0f }));
|
|
477
|
+
inner.scale.set((LW - 8) / LW, (LD - 8) / LD, 1);
|
|
478
|
+
inner.rotation.x = Math.PI / 2; inner.position.set(0, -0.6, LD / 2);
|
|
479
|
+
lid.add(inner);
|
|
480
|
+
const screen = new T.Group();
|
|
481
|
+
screen.position.set(0, -1.6, LD / 2);
|
|
482
|
+
screen.rotation.x = Math.PI / 2;
|
|
483
|
+
lid.add(screen);
|
|
484
|
+
const glowK = o.glow ?? 0.5;
|
|
485
|
+
const glow = new T.PointLight(o.glowColor ?? 0xfff1e0, 0, 0, 0);
|
|
486
|
+
glow.position.set(0, -LD / 2, LD / 2);
|
|
487
|
+
lid.add(glow);
|
|
488
|
+
if (o.shadow !== false) {
|
|
489
|
+
const sm = contact(LW, LD);
|
|
490
|
+
sm.position.set(20, 0.5, 30);
|
|
491
|
+
group.add(sm);
|
|
492
|
+
}
|
|
493
|
+
let angle = 105, lit = 1;
|
|
494
|
+
/** the lid at `deg` between it and the keyboard (0 shut), the screen `screenLit` 0…1 bright
|
|
495
|
+
* @param {number} deg @param {number} [screenLit] */
|
|
496
|
+
function set(deg, screenLit = lit) {
|
|
497
|
+
angle = Math.max(0, Math.min(180, deg)); lit = screenLit;
|
|
498
|
+
lid.rotation.x = (-angle * Math.PI) / 180;
|
|
499
|
+
glow.intensity = glowK * lit * Math.max(0, Math.sin((angle * Math.PI) / 180));
|
|
500
|
+
// shut, the screen lies in the keys' plane: not drawn
|
|
501
|
+
screen.visible = angle > 0.5;
|
|
502
|
+
}
|
|
503
|
+
const open = o.open ?? 105;
|
|
504
|
+
set(typeof open === "function" ? open(0) : open);
|
|
505
|
+
return {
|
|
506
|
+
group, base, lid, screen, glow, material: metal, width: LW, depth: LD, set,
|
|
507
|
+
/** the lid's angle now */
|
|
508
|
+
get open() { return angle; },
|
|
509
|
+
/** space.js runs this at every sample's time: the lid where `open` puts it then @param {number} t */
|
|
510
|
+
tick: (t) => { if (typeof open === "function") set(open(t)); },
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* A table to stand things on, with its light: a matte ground at y 0 that
|
|
516
|
+
* reaches past the fog, a sky light (a hemisphere: white above, the
|
|
517
|
+
* table's own colour from below) and a sun from the upper left behind the
|
|
518
|
+
* lens — one key and a fill, the least that shows a lid's edge and a
|
|
519
|
+
* body's top apart. `fog` fades the table into the scene's ground colour,
|
|
520
|
+
* so it has no far edge: space.js's scene.add(desk) sets it on the scene
|
|
521
|
+
* and keeps its colour the ground's at every sample (alone: `scene.fog =
|
|
522
|
+
* desk.fog`). `look` changes it over the film — an evening into a morning:
|
|
523
|
+
* look: (t) => (t < 15 ? { color: 0x77604c, sky: 0.75, sun: 1.5, sunColor: 0xffc591 }
|
|
524
|
+
* : { color: 0xd9ccb6, sky: 1.5, sun: 2.3, sunColor: 0xfff3e0 })
|
|
525
|
+
* The intensities are chosen by eye against a mid-grey body.
|
|
526
|
+
* @param {{ color?: number | string, size?: number, roughness?: number, sky?: number, sun?: number,
|
|
527
|
+
* sunColor?: number | string, sunAt?: [number, number, number], fog?: [number, number] | false,
|
|
528
|
+
* look?: (t: number) => { color?: number | string, sky?: number, sun?: number, sunColor?: number | string } }} [o]
|
|
529
|
+
* fog: where it starts and where it has taken everything, from the lens ([4200, 11000])
|
|
530
|
+
*/
|
|
531
|
+
function desk(o = {}) {
|
|
532
|
+
const group = new T.Group();
|
|
533
|
+
const mat = new T.MeshStandardMaterial({ color: o.color ?? 0x6a5848, roughness: o.roughness ?? 0.95 });
|
|
534
|
+
const ground = new T.Mesh(new T.PlaneGeometry(o.size ?? 40000, o.size ?? 40000), mat);
|
|
535
|
+
ground.rotation.x = -Math.PI / 2;
|
|
536
|
+
const sky = new T.HemisphereLight(0xffffff, o.color ?? 0x6a5848, o.sky ?? 1);
|
|
537
|
+
const sun = new T.DirectionalLight(o.sunColor ?? 0xffffff, o.sun ?? 1.5);
|
|
538
|
+
sun.position.set(...(o.sunAt ?? [-900, 1800, 1400]));
|
|
539
|
+
group.add(ground, sky, sun);
|
|
540
|
+
const fog = o.fog === false ? null : new T.Fog(0x000000, o.fog?.[0] ?? 4200, o.fog?.[1] ?? 11000);
|
|
541
|
+
/** @param {{ color?: number | string, sky?: number, sun?: number, sunColor?: number | string }} v */
|
|
542
|
+
function set(v) {
|
|
543
|
+
if (v.color !== undefined) { mat.color.set(v.color); sky.groundColor.set(v.color); }
|
|
544
|
+
if (v.sky !== undefined) sky.intensity = v.sky;
|
|
545
|
+
if (v.sun !== undefined) sun.intensity = v.sun;
|
|
546
|
+
if (v.sunColor !== undefined) sun.color.set(v.sunColor);
|
|
547
|
+
}
|
|
548
|
+
return {
|
|
549
|
+
group, ground, sky, sun, fog, set,
|
|
550
|
+
/** space.js runs this at every sample's time @param {number} t @param {{ clear?: any }} [at] the scene's ground colour then */
|
|
551
|
+
tick: (t, at) => {
|
|
552
|
+
if (o.look) set(o.look(t));
|
|
553
|
+
if (fog && at?.clear) fog.color.copy(at.clear);
|
|
554
|
+
},
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
return {
|
|
559
|
+
geometry, planarUV, laptop, desk, contact,
|
|
560
|
+
/** a distance function as a lit mesh (see sdfMesh); userData: voxels, triangles
|
|
561
|
+
* @param {(x: number, y: number, z: number) => number} f @param {number[]} box @param {number} voxel */
|
|
562
|
+
sdf(f, box, voxel) {
|
|
563
|
+
const m = sdfMesh(f, box, voxel);
|
|
564
|
+
const g = geometry(m);
|
|
565
|
+
g.userData = { voxels: m.voxels, triangles: m.triangles };
|
|
566
|
+
return g;
|
|
567
|
+
},
|
|
568
|
+
/** a turned part (see latheMesh) @param {number[][]} profile @param {Parameters<typeof latheMesh>[1]} [o] */
|
|
569
|
+
lathe: (profile, o) => geometry(latheMesh(profile, o)),
|
|
570
|
+
/** a canvas as a texture: srgb for colour maps, linear for bump and roughness
|
|
571
|
+
* @param {HTMLCanvasElement} c @param {boolean} [srgb] @param {number} [repeat] */
|
|
572
|
+
texture(c, srgb = false, repeat = 1) {
|
|
573
|
+
const t = new T.CanvasTexture(c);
|
|
574
|
+
t.colorSpace = srgb ? T.SRGBColorSpace : T.NoColorSpace;
|
|
575
|
+
t.anisotropy = 8;
|
|
576
|
+
if (repeat !== 1) { t.wrapS = t.wrapT = T.RepeatWrapping; t.repeat.set(repeat, repeat); }
|
|
577
|
+
return t;
|
|
578
|
+
},
|
|
579
|
+
/** backdropPaint as a colour texture @param {Parameters<typeof backdropPaint>[0]} [o] */
|
|
580
|
+
backdrop(o) {
|
|
581
|
+
const t = new T.CanvasTexture(backdropPaint(o));
|
|
582
|
+
t.colorSpace = T.SRGBColorSpace; t.anisotropy = 8;
|
|
583
|
+
return t;
|
|
584
|
+
},
|
|
585
|
+
/**
|
|
586
|
+
* A studio to reflect, prefiltered for PBR materials: a grey room with
|
|
587
|
+
* a few soft boxes in it, after three's RoomEnvironment, built here so a
|
|
588
|
+
* film needs no addon file. `warm` tints the key box, `cool` the rim.
|
|
589
|
+
* Its boxes are bright (up to 50× white): set the scene's
|
|
590
|
+
* environmentIntensity near 0.55 to start, lower for polished metal
|
|
591
|
+
* facing up at the ceiling's box.
|
|
592
|
+
* @param {any} renderer @param {{ key?: number, warm?: number, cool?: number }} [o]
|
|
593
|
+
*/
|
|
594
|
+
room(renderer, { key = 1, warm = 0xfff0dd, cool = 0xcfe0ff } = {}) {
|
|
595
|
+
const sc = new T.Scene();
|
|
596
|
+
const box = new T.BoxGeometry();
|
|
597
|
+
const wall = new T.MeshStandardMaterial({ side: T.BackSide, color: 0x7f7f7f, roughness: 1 });
|
|
598
|
+
const room = new T.Mesh(box, wall); room.position.set(-0.757, 13.219, 0.717); room.scale.set(31.713, 28.305, 28.591); sc.add(room);
|
|
599
|
+
sc.add(new T.PointLight(0xffffff, 900, 28, 2).translateY(5));
|
|
600
|
+
const clutter = new T.MeshStandardMaterial({ color: 0x8a8a8a, roughness: 0.9 });
|
|
601
|
+
for (const [x, y, z, sx, sy, sz] of [[-10.9, 2.1, -2, 2.7, 4.3, 1.6], [-0.3, 1.6, -9, 7.3, 3.2, 1.9], [6.3, 2.3, -3.3, 2.1, 4.6, 3.6], [-6, 1.1, 3.4, 2.9, 2.2, 1.4], [5.2, 1, 7.2, 3.4, 2, 3.2]]) {
|
|
602
|
+
const m = new T.Mesh(box, clutter); m.position.set(x, y, z); m.scale.set(sx, sy, sz); sc.add(m);
|
|
603
|
+
}
|
|
604
|
+
/** @param {number} color @param {number} k @param {number[]} p @param {number[]} s */
|
|
605
|
+
const light = (color, k, p, s) => {
|
|
606
|
+
const m = new T.Mesh(box, new T.MeshBasicMaterial({ color: new T.Color(color).multiplyScalar(k) }));
|
|
607
|
+
m.position.set(p[0], p[1], p[2]); m.scale.set(s[0], s[1], s[2]); sc.add(m);
|
|
608
|
+
};
|
|
609
|
+
light(warm, 50 * key, [-16.1, 2.5, 6.8], [0.1, 2.5, 2.5]); // key, left
|
|
610
|
+
light(cool, 43, [14.6, 11.4, -6.6], [0.1, 2.5, 3.4]); // rim, right and behind
|
|
611
|
+
light(0xffffff, 17, [-0.2, 15.6, 2.3], [5.9, 0.1, 6.9]); // the ceiling
|
|
612
|
+
light(0xffffff, 43, [-1.6, 17.8, 9.2], [1.6, 0.1, 1.5]);
|
|
613
|
+
const pm = new T.PMREMGenerator(renderer);
|
|
614
|
+
const env = pm.fromScene(sc, 0.04).texture;
|
|
615
|
+
pm.dispose();
|
|
616
|
+
return env;
|
|
617
|
+
},
|
|
618
|
+
/**
|
|
619
|
+
* Bloom and a grade from a linear HDR texture to the screen — space.js's
|
|
620
|
+
* scene `finish`, or alone: finish.render(scene, camera) draws a scene
|
|
621
|
+
* into its own target first. P: expo, bloomMix, bloomAdd, vig, lift,
|
|
622
|
+
* grain (8-bit steps of dither). Bloom uses 6 levels of half size each.
|
|
623
|
+
* @param {any} renderer
|
|
624
|
+
* @param {{ width?: number, height?: number, expo?: number, bloomMix?: number, bloomAdd?: number, vig?: number, lift?: number, grain?: number }} [o]
|
|
625
|
+
*/
|
|
626
|
+
finish(renderer, o = {}) {
|
|
627
|
+
const P = { expo: 1, bloomMix: 0.04, bloomAdd: 0.025, vig: 0.7, lift: 0, grain: 1, ...o };
|
|
628
|
+
const VS = "varying vec2 vUv; void main(){ vUv = uv; gl_Position = vec4(position.xy, 0., 1.); }";
|
|
629
|
+
const qScene = new T.Scene(), qCam = new T.OrthographicCamera(-1, 1, 1, -1, 0, 1);
|
|
630
|
+
const q = new T.Mesh(new T.PlaneGeometry(2, 2)); q.frustumCulled = false; qScene.add(q);
|
|
631
|
+
// each pass clears only when asked: the bloom's way up adds onto the level below,
|
|
632
|
+
// which a renderer left to clear itself (autoClear, three's default) would wipe
|
|
633
|
+
/** @param {any} mat @param {any} target @param {boolean} [clear] */
|
|
634
|
+
const pass = (mat, target, clear = true) => {
|
|
635
|
+
q.material = mat; renderer.setRenderTarget(target);
|
|
636
|
+
const auto = renderer.autoClear;
|
|
637
|
+
renderer.autoClear = false;
|
|
638
|
+
if (clear) renderer.clear();
|
|
639
|
+
renderer.render(qScene, qCam);
|
|
640
|
+
renderer.autoClear = auto;
|
|
641
|
+
};
|
|
642
|
+
/** @param {string} fs @param {boolean} [add] */
|
|
643
|
+
const blit = (fs, add = false) => new T.ShaderMaterial({ vertexShader: VS, fragmentShader: fs, depthTest: false, depthWrite: false,
|
|
644
|
+
uniforms: { t: { value: null }, texel: { value: new T.Vector2() } }, blending: add ? T.AdditiveBlending : T.NoBlending, transparent: add });
|
|
645
|
+
const mD0 = blit(`uniform sampler2D t; uniform vec2 texel; varying vec2 vUv;
|
|
646
|
+
vec4 kar(vec3 c){ float w = 1. / (1. + max(c.r, max(c.g, c.b))); return vec4(c * w, w); }
|
|
647
|
+
void main(){ vec4 m = kar(min(texture2D(t, vUv + texel * vec2(-1., -1.)).rgb, vec3(24.))) + kar(min(texture2D(t, vUv + texel * vec2(1., -1.)).rgb, vec3(24.)))
|
|
648
|
+
+ kar(min(texture2D(t, vUv + texel * vec2(-1., 1.)).rgb, vec3(24.))) + kar(min(texture2D(t, vUv + texel * vec2(1., 1.)).rgb, vec3(24.)));
|
|
649
|
+
gl_FragColor = vec4(m.rgb / m.a, 1.); }`);
|
|
650
|
+
const mD = blit(`uniform sampler2D t; uniform vec2 texel; varying vec2 vUv;
|
|
651
|
+
void main(){ gl_FragColor = (texture2D(t, vUv + texel * vec2(-1., -1.)) + texture2D(t, vUv + texel * vec2(1., -1.))
|
|
652
|
+
+ texture2D(t, vUv + texel * vec2(-1., 1.)) + texture2D(t, vUv + texel * vec2(1., 1.))) * .25; }`);
|
|
653
|
+
// alpha 1: three's additive blend multiplies the colour by it
|
|
654
|
+
const mU = blit(`uniform sampler2D t; uniform vec2 texel; varying vec2 vUv;
|
|
655
|
+
void main(){ vec2 e = .75 * texel; gl_FragColor = vec4((texture2D(t, vUv + e * vec2(-1., -1.)).rgb + texture2D(t, vUv + e * vec2(1., -1.)).rgb
|
|
656
|
+
+ texture2D(t, vUv + e * vec2(-1., 1.)).rgb + texture2D(t, vUv + e * vec2(1., 1.)).rgb) * .25, 1.); }`, true);
|
|
657
|
+
const mC = new T.ShaderMaterial({ vertexShader: VS, depthTest: false, depthWrite: false,
|
|
658
|
+
uniforms: { tS: { value: null }, tB: { value: null }, expo: { value: 1 }, bloomMix: { value: 0 }, bloomAdd: { value: 0 }, vig: { value: 0 }, lift: { value: 0 }, grain: { value: 1 }, seed: { value: 0 } },
|
|
659
|
+
fragmentShader: `uniform sampler2D tS; uniform sampler2D tB; uniform float expo, bloomMix, bloomAdd, vig, lift, grain, seed; varying vec2 vUv;
|
|
660
|
+
float ss(float a, float b, float x){ float t = clamp((x - a) / (b - a), 0., 1.); return t * t * (3. - 2. * t); }
|
|
661
|
+
float ign(vec2 p){ return fract(52.9829189 * fract(dot(p, vec2(.06711056, .00583715)))); }
|
|
662
|
+
vec3 aces(vec3 x){ return clamp((x * (2.51 * x + .03)) / (x * (2.43 * x + .59) + .14), 0., 1.); }
|
|
663
|
+
vec3 srgb(vec3 c){ return mix(c*12.92, 1.055*pow(c, vec3(1.0/2.4))-0.055, step(0.0031308, c)); }
|
|
664
|
+
void main(){
|
|
665
|
+
vec3 c = texture2D(tS, vUv).rgb, bl = texture2D(tB, vUv).rgb;
|
|
666
|
+
c = mix(c, bl, bloomMix) + bl * bloomAdd;
|
|
667
|
+
c *= expo;
|
|
668
|
+
vec2 q = vUv - .5; c *= 1. - dot(q, q) * vig;
|
|
669
|
+
c = aces(c);
|
|
670
|
+
float l0 = dot(c, vec3(.2126, .7152, .0722));
|
|
671
|
+
float l = mix(l0, l0 * l0 * (3. - 2. * l0), .55);
|
|
672
|
+
c *= l / max(l0, 1e-4);
|
|
673
|
+
c = mix(c, vec3(l), ss(.55, 1., l) * .1);
|
|
674
|
+
c = mix(vec3(l), c, .93) + vec3(.008, .002, 0.) * lift;
|
|
675
|
+
c = srgb(max(c, vec3(0.)));
|
|
676
|
+
float n = ign(gl_FragCoord.xy + seed) + ign(gl_FragCoord.xy + 37. + seed) - 1.;
|
|
677
|
+
gl_FragColor = vec4(c + grain * n / 255., 1.); }` });
|
|
678
|
+
/** @type {any[]} */ let bl = [];
|
|
679
|
+
/** @type {any} */ let own = null;
|
|
680
|
+
let W = 0, H = 0;
|
|
681
|
+
/** @param {number} w @param {number} h */
|
|
682
|
+
function size(w, h) {
|
|
683
|
+
if (w === W && h === H) return;
|
|
684
|
+
W = w; H = h;
|
|
685
|
+
for (const b of bl) b.dispose();
|
|
686
|
+
bl = [];
|
|
687
|
+
for (let i = 0; i < 6; i++) bl.push(new T.WebGLRenderTarget(Math.max(1, W >> (i + 1)), Math.max(1, H >> (i + 1)), { type: T.HalfFloatType, depthBuffer: false }));
|
|
688
|
+
own?.dispose(); own = null;
|
|
689
|
+
}
|
|
690
|
+
if (o.width && o.height) size(o.width, o.height);
|
|
691
|
+
/** @param {any} tex a linear HDR texture @param {number} [t] film time, to move the dither */
|
|
692
|
+
function apply(tex, t = 0) {
|
|
693
|
+
// not sized yet: the texture's own size, else the canvas's
|
|
694
|
+
if (!bl.length) {
|
|
695
|
+
const im = tex?.image, s = renderer.getDrawingBufferSize(new T.Vector2());
|
|
696
|
+
size(im?.width || s.x, im?.height || s.y);
|
|
697
|
+
}
|
|
698
|
+
for (let i = 0; i < bl.length; i++) {
|
|
699
|
+
const src = i ? bl[i - 1] : null, m = i ? mD : mD0;
|
|
700
|
+
m.uniforms.t.value = src ? src.texture : tex;
|
|
701
|
+
m.uniforms.texel.value.set(1 / (src ? src.width : W), 1 / (src ? src.height : H));
|
|
702
|
+
pass(m, bl[i]);
|
|
703
|
+
}
|
|
704
|
+
for (let i = bl.length - 1; i > 0; i--) {
|
|
705
|
+
mU.uniforms.t.value = bl[i].texture; mU.uniforms.texel.value.set(1 / bl[i].width, 1 / bl[i].height);
|
|
706
|
+
pass(mU, bl[i - 1], false);
|
|
707
|
+
}
|
|
708
|
+
const u = mC.uniforms;
|
|
709
|
+
u.tS.value = tex; u.tB.value = bl[0]?.texture ?? tex;
|
|
710
|
+
for (const k of /** @type {const} */ (["expo", "bloomMix", "bloomAdd", "vig", "lift", "grain"])) u[k].value = P[k];
|
|
711
|
+
u.seed.value = Math.round(t * 60) % 97;
|
|
712
|
+
pass(mC, null);
|
|
713
|
+
}
|
|
714
|
+
return {
|
|
715
|
+
P, size, apply,
|
|
716
|
+
/** draw a scene through it, without space.js @param {any} scene @param {any} camera @param {number} [t] */
|
|
717
|
+
render(scene, camera, t = 0) {
|
|
718
|
+
const s = renderer.getDrawingBufferSize(new T.Vector2());
|
|
719
|
+
size(s.x, s.y);
|
|
720
|
+
if (!own) own = new T.WebGLRenderTarget(W, H, { type: T.HalfFloatType, samples: 4 });
|
|
721
|
+
renderer.setRenderTarget(own); renderer.clear(); renderer.render(scene, camera);
|
|
722
|
+
apply(own.texture, t);
|
|
723
|
+
},
|
|
724
|
+
};
|
|
725
|
+
},
|
|
726
|
+
};
|
|
727
|
+
}
|