@@ -15,6 +15,8 @@ const folderControls = gui.addFolder('controls');
1515const folderSongs = gui . addFolder ( 'songs' ) ;
1616const size = { x : 8 , y : 22 } , offset = - 32 , atlasPath = 'src/img/inconsolata_regular_8x22.png' ;
1717
18+ const { uniforms, storages } = points ;
19+
1820points . debug = false ;
1921
2022let audio = null ;
@@ -32,7 +34,7 @@ const options = {
3234const selectedScheme = {
3335 'Color Scheme' : 0 , // Default value
3436} ;
35- points . setUniform ( ' colorScheme' , 0 ) ;
37+ uniforms . colorScheme = 0 ;
3638const colorSchemes = {
3739 Default : 0 ,
3840 Matrix : 1 ,
@@ -42,7 +44,7 @@ const colorSchemes = {
4244 Cycle : 5
4345}
4446folderOptions . add ( selectedScheme , 'Color Scheme' , colorSchemes ) . onChange ( v => {
45- points . setUniform ( ' colorScheme' , v )
47+ uniforms . colorScheme = + v ;
4648 saveOption ( 'scheme' , v ) ;
4749} ) ;
4850
@@ -70,7 +72,7 @@ async function playSong(song) {
7072 const { file } = song ;
7173 currentSong = song ;
7274 saveOption ( 'currentSongId' , currentSong . id ) ;
73- points . setUniform ( ' showMessage' , 0 ) ;
75+ uniforms . showMessage = 0 ;
7476 const name = song ?. name || file . name ;
7577 const title = name ;
7678
@@ -82,9 +84,9 @@ async function playSong(song) {
8284
8385 let artworkLoaded = 0 ;
8486
85- song ?. artworkColors && points . setStorageMap ( ' artworkColors' , song ?. artworkColors . flat ( ) ) ;
87+ song ?. artworkColors && ( points . storages . artworkColors = song ?. artworkColors . flat ( ) ) ;
8688 song ?. artworkColors && ( artworkLoaded = 1 ) ;
87- points . setUniform ( ' artworkLoaded' , artworkLoaded ) ;
89+ uniforms . artworkLoaded = artworkLoaded ;
8890 audio . id = song ?. id ;
8991
9092 assingMediaSession ( song ) ;
@@ -95,8 +97,7 @@ async function playSong(song) {
9597}
9698
9799function onTimeUpdate ( ) {
98- const progress = audio . currentTime / audio . duration ;
99- points . setUniform ( 'progress' , progress ) ;
100+ uniforms . progress = audio . currentTime / audio . duration ;
100101}
101102
102103function loadSong ( ) {
@@ -160,8 +161,8 @@ async function onCompleteTags(result) {
160161 artworkColors = await countImageColors ( artworkImageUrl ) ;
161162 song . artworkImageUrl = artworkImageUrl ;
162163 song . artworkColors = artworkColors ;
163- points . setStorageMap ( ' artworkColors' , artworkColors . flat ( ) ) ;
164- points . setUniform ( ' artworkLoaded' , 1 ) ;
164+ storages . artworkColors = artworkColors . flat ( ) ;
165+ uniforms . artworkLoaded = 1 ;
165166
166167 } else {
167168 console . log ( 'No album art found.' ) ;
@@ -306,7 +307,7 @@ console.log(currentSongId);
306307
307308if ( scheme ) {
308309 selectedScheme [ 'Color Scheme' ] = scheme ;
309- points . setUniform ( ' colorScheme' , scheme )
310+ uniforms . colorScheme = + scheme ;
310311 folderOptions . updateDisplay ( ) ;
311312}
312313
@@ -336,7 +337,7 @@ songsFromDB.forEach(item => {
336337
337338let volumeSlider = null ;
338339Object . keys ( options ) . forEach ( key => {
339- points . setUniform ( key , options [ key ] ) ;
340+ uniforms [ key ] = options [ key ] ;
340341 if ( key == 'volume' ) {
341342 volumeSlider = folderOptions . add ( options , key , 0 , 1 , .0001 ) . name ( key ) ;
342343 } else {
@@ -365,13 +366,14 @@ points.setTexture2d('feedbackTexture', true);
365366
366367audio = points . setAudio ( 'audio' , '' , options . volume , loop , false ) ; // TODO returl null if empty or null is passed
367368
368- points . setUniform ( 'showMessage' , 1 ) ;
369- points . setUniform ( 'rand' , 0 ) ;
370- points . setUniform ( 'progress' , 0 ) ;
371- points . setUniform ( 'artworkLoaded' , 0 ) ;
369+ uniforms . showMessage = 1 ;
370+ uniforms . rand = 0 ;
371+ uniforms . progress = 0 ;
372+ uniforms . artworkLoaded = 0 ;
373+
372374// points.setStorageMap('chars', strToCodes('Gravity Pull'), 'array<f32>')// TODO: setStorageMap doesn't work with u32 wrong sized
373- points . setStorageMap ( 'artworkColors' , Array ( 40 ) . fill ( 1 ) , 'array<vec4f, 10>' ) ;
374- points . setStorage ( 'variables' , ' Variables', false , GPUShaderStage . FRAGMENT ) ;
375+ storages . artworkColors . setType ( 'array<vec4f, 10>' ) . setValue ( Array ( 40 ) . fill ( 1 ) )
376+ storages . variables . setType ( ' Variables') . setShaderStage ( GPUShaderStage . FRAGMENT ) ;
375377
376378
377379await points . setTextureString ( 'messageString' , 'Select a song to Play' , atlasPath , size , offset ) ;
@@ -417,13 +419,13 @@ points.canvas.addEventListener('dblclick', _ => {
417419
418420setInterval ( _ => {
419421 console . log ( '---- 10s' ) ;
420- points . setUniform ( ' rand' , Math . random ( ) ) ;
422+ uniforms . rand = Math . random ( ) ;
421423} , 10000 )
422424
423425
424426// call `points.update()` methods to render a new frame
425427function update ( ) {
426- Object . keys ( options ) . forEach ( key => points . setUniform ( key , options [ key ] ) ) ;
428+ Object . keys ( options ) . forEach ( key => uniforms [ key ] = options [ key ] ) ;
427429 // points.setUniform('somecolor', colors.color2.map(i => i / 255))
428430}
429431
0 commit comments