elm-3d-scene icon indicating copy to clipboard operation
elm-3d-scene copied to clipboard

add WebXR support?

Open mathiajusth opened this issue 3 years ago • 11 comments

Do you think it is something that could / should be part of this package?

mathiajusth avatar Jul 27 '20 14:07 mathiajusth

👋 @mathiajusth! Native support for WebXR probably won't be possible for a while, since Elm doesn't provide access to navigator.xr etc., and since it's not "just another HTML element" the way a WebGL scene is it would require a different kind of API. (And I think Elm is unlikely to support WebXR directly until it has much broader browser support.)

I think the most promising approach would be to have an option to render elm-3d-scene to HTML using A-Frame elements instead of using WebGL directly - you'd need to include the A-Frame JS on your HTML page, but then we could exploit A-Frame's existing WebVR etc. support. I think this should be possible, but there may very well be some gotchas and it would probably take a fair bit of work. (A-Frame support would need to be part of elm-3d-scene directly - you'd need access to internal data types that aren't accessible by third-party code.)

ianmackenzie avatar Jul 27 '20 19:07 ianmackenzie

Thank you for the fast reply.

Native support for WebXR probably won't be possible for a while, since Elm doesn't provide access to navigator.xr etc

I am sad to heat that, but you gave me hope with the a-frame approach. I started to look into 3D rendering / VR just a few day ago and a-frame indeed looked like the best candidate to take advatage of if one wants a functional reactive approach. So I'll try to look into that a bit more.

Btw. love you library, the best entry-friendly 3D rendering tool I found! A little off-topic, but do you have any recommendation regarding VR with any functional programming language?

mathiajusth avatar Jul 27 '20 20:07 mathiajusth

Thanks for the kind words! As for VR in functional programming languages, I think the best I can point you to is https://github.com/halfzebra/elm-aframe, which was an early stab at getting Elm and A-Frame to play well together. (I probably should have linked to that in my first reply!) If I recall correctly I think it largely worked (though I never played around with it myself), but for whatever reason development hasn't continued.

ianmackenzie avatar Jul 27 '20 20:07 ianmackenzie

Be aware that A-frame mutates the Dom and doesn't play well with Elm's vdom. Last time I checked. See also https://github.com/halfzebra/elm-aframe/issues/35

harmboschloo avatar Jul 28 '20 07:07 harmboschloo

Thanks for pointing that out @harmboschloo, that's really good to know! From looking through some of the linked issues it seem that the A-Frame maintainers have no interest in compatibility with Elm, so even if it could be somehow made to work now it's likely that more issues would occur in the future.

Any thoughts on what the best path forward would be if someone was interested in doing VR with elm-3d-scene? Maybe something like some custom web components that would use WebXR internally? I don't expect to have much time myself to work on anything like this directly in the near future, but I'd be happy to answer questions/provide feedback etc. if someone else wanted to have a go.

ianmackenzie avatar Jul 28 '20 14:07 ianmackenzie

It could actually be interesting if perhaps elm-3d-scene provided a generic way to render to a DOM tree with custom node names, perhaps with a customizable node name for the top-level node. Then different people could try creating web components that implemented that standard node hierarchy, e.g.:

  • One that used WebXR to render as VR
  • One that used Rust compiled to WebAssembly for perhaps even higher-performance rendering

ianmackenzie avatar Jul 28 '20 14:07 ianmackenzie

A fresh contender to rival A-Frame would be https://github.com/hmans/three-elements

PixelPartner avatar Feb 05 '21 12:02 PixelPartner

Ah very cool @PixelPartner! Will be interesting to see how that library evolves...

ianmackenzie avatar Feb 05 '21 17:02 ianmackenzie

I just started looking into WebXR but it just for everything but the rendering. Since this package uses WebGL, it should be possible to somehow get this rendering into WebXR. WebXR sort of gives you parameters and a place to render your WebGL.

My understanding of all this works is very shallow, so bear with me.

perty avatar Jan 22 '22 11:01 perty

Hi @perty, happy to help explain the internals of elm-3d-scene if you want to investigate how WebXR support might work - probably easiest to ping me on the Elm Slack with any detailed questions

ianmackenzie avatar Jan 24 '22 20:01 ianmackenzie

Ok, got it and thanks @ianmackenzie . I am currently on a fork of a fork of elm-aframe. Had some none-elm experience with Aframe.

perty avatar Jan 26 '22 14:01 perty