charlieroberts / marching

A JavaScript library that compiles GLSL ray marchers.
MIT License
208 stars 13 forks source link

add OSC input support #11

Closed s-ol closed 2 years ago

s-ol commented 2 years ago

This (very naively) maps OSC messages like

  /rpt/distance/x f 0.5
  /rpt/mat/specular fff 1 0.3 0.5
  /sph/rotate f[fff] 90 1 0 0

to JS calls like

window.rpt.distance.x = 0.5
window.rpt.mat.specular = Vec4(1, 0.3, 0.5)
window.sph.rotate(90, Vec4(1, 0, 0))

(yes, all arrays are done as Vec4 right now).

It can be activated using OSC.start("ws://localhost:9000") (or wherever your WebSocket-OSC server is).

s-ol commented 2 years ago

This needs docs of course. Another annoyance is that the osc package depends on serialport, which adds a bunch of useless dependencies. I'm not sure if there's a way to blacklist that dependency-subtree? The other osc packages on npm didn't support all types.

It could also use better Error handling/precise checks, but it seems like the rest of the project does too :stuck_out_tongue:

s-ol commented 2 years ago

demo:

https://user-images.githubusercontent.com/1731279/152680864-9817a952-687c-4af2-95e1-c921ef2ed9db.mp4

OSC.start("ws://localhost:9996")
mat1 = Material( 'phong', Vec3(.05), Vec3(.5), Vec3(1), 8, Vec3(1,4,1) )
march(
  Repeat(
    sph = Sphere( .25 ).material( mat1 ),
    Vec3( .75)
  )
)
.light( 
  Light( Vec3(2,2,3), Vec3(0, 0, 1) ),
  Light( Vec3(-2,2,3), Vec3(1,0,0) ),
)
.background( Vec3(0) )
.render(8, true)

and the OSSIA Score file for sending OSC: osc-demo.zip

s-ol commented 2 years ago

I noticed that scene.camera() is missing, which is pretty important. It would also be nice to make things like obj/transform/translation/x work.

charlieroberts commented 2 years ago

This is awesome! The build you're using doesn't pull in the Serial stuff as far as I can tell, although I didn't look at it to closely. Anyways, it's a pretty small file regardless, happy to pull this in. Thank yoU!