elm-community / webgl

Moved to elm-explorations/webgl
https://package.elm-lang.org/packages/elm-explorations/webgl/latest
BSD 3-Clause "New" or "Revised" License
131 stars 18 forks source link

Add the ability to render HTML Elements to Texture #45

Closed shamansir closed 7 years ago

shamansir commented 7 years ago

...such as canvas, video, svg, even with animation.

Adds

Adds dynamic-texture.elm example, which is just a copy of crate.elm, with few changes:

init : ( Model, Cmd Msg )
init =
    ( { texture = Nothing, theta = 0 }
    , Task.attempt TextureLoaded
        (Texture.fromDynamicElement UseRAF "my-element")
    )

view : Model -> Html Msg
view { texture, theta } =
    div
        [ ]
        [ Element.toHtml
            <| tag "my-element"
            <| collage 128 128
                [ (circle 64) |> filled blue
                , (rect 3 60) |> filled black
                              |> rotate theta
                ]
        , WebGL.toHtmlWith
            [ WebGL.alpha True
            , WebGL.antialias
            , WebGL.depth 1
            , WebGL.stencil 0
            ]
            [ width 400
            , height 400
            , style [ ( "display", "block" ) ]
            ]
            (texture
                |> Maybe.map (scene (perspective theta))
                |> Maybe.withDefault []
            )
        ]

Caveats

Motivation

Usually the source element is hidden, so it’s quite a useful method. For example, I need to show a video in a texture, others also use this method to display text in 3D with almost no hardware tension. Or to add shader-based effects to HTML components, see http://htmlgl.com/.

shamansir commented 7 years ago

This functionality is not reviewed by community, not needed for now and could be too exclusive for my case.

w0rm commented 6 years ago

@shamansir just had an idea, it may be possible to send a blob url through ports to Elm and then load it as a texture. This may partially cover this use case.