ianmackenzie / elm-3d-scene

A high-level 3D rendering engine for Elm, with support for lighting, shadows, and realistic materials.
https://package.elm-lang.org/packages/ianmackenzie/elm-3d-scene/latest/
Mozilla Public License 2.0
205 stars 27 forks source link

add WebXR support? #88

Open mathiajusth opened 4 years ago

mathiajusth commented 4 years ago

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

ianmackenzie commented 4 years ago

👋 @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.)

mathiajusth commented 4 years ago

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?

ianmackenzie commented 4 years ago

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.

harmboschloo commented 4 years ago

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

ianmackenzie commented 4 years ago

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 commented 4 years ago

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.:

PixelPartner commented 3 years ago

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

ianmackenzie commented 3 years ago

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

perty commented 2 years ago

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.

ianmackenzie commented 2 years ago

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

perty commented 2 years ago

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.