justgook/webgl-shape/2.0.1

NOTE: the latest version is 3.0.0

WebGL.Shape2d

Render

Dict String Texture
-> { b | width : Float, height : Float }
-> List Shape2d
-> ( List Entity, Set String )

Converts shapes to WebGL entities and Set of missing texture filenames

import WebGL
import WebGL.Shape2d


main =
    WebGL.Shape2d.toEntities Dict.empty 100 100 [ rectangle red 30 30 ]
        |> Tuple.first
        |> Webgl.toHtml [ width 100, height 100 ]

Shape

type Shape2d
= Shape2d
{ x : Float
, y : Float
, z : Float
, a : Float
, sx : Float
, sy : Float
, o : Float
, form : Form
}

Main building block

rectangle : Vec3 -> Float -> Float -> Shape2d
rectangle color width height =
    Shape2d
        { x = 0
        , y = 0
        , a = 0
        , sx = 1
        , sy = 1
        , o = 1
        , form = Form width height (Render.rect color)
        }
type Form
= Form Float Float Render
| Textured String (Texture -> Shape2d)
| Group (List Shape2d)

Types

type alias Render =
Translate -> ScaleRotateSkew -> Z -> Opacity -> Entity

Render is part of Shape2d that converts Shape2d into Entity

rect : Vec3 -> Render
rect color uP uT opacity =
    WebGL.entity
        Shader.vertNone
        Shader.fragFill
        Shader.mesh
        { color = color
        , opacity = opacity
        , uP = uP
        , uT = uT
        }
type alias Opacity =
Float
type alias ScaleRotateSkew =
Vec4

Vec4 representing part of transform matrix

| x y 0 |
| z w 0 |
| 0 0 1 |
type alias Translate =
Vec2

Vec2 representing part of transform matrix

| 1 0 x |
| 0 1 y |
| 0 0 1 |
type alias Z =
Float

Css line z-index that is passed to the Render