elm-geometry
elm-geometry copied to clipboard
Export to WebGL Meshes
Or may be you know some easy trick to do it and I've missed it?
Agreed! I definitely want to have a good WebGL story but I haven't figured out a good way to do it yet since it's possible (and often very useful) to attach additional data (color, normal direction, texture coordinate etc.) to individual vertices. So it would be easy enough to (for instance) create something like
module OpenSolid.WebGL
import OpenSolid.Geometry.Types exposing (..)
import WebGL
import Math.Vector3 exposing (Vec3)
triangles : List Triangle3d -> WebGL.Mesh { position: Vec3 }
triangles list =
-- Implementation: convert triangle vertices to Vec3 values, use WebGL.triangles function
but this would restrict you to only being able to have access to vertex position in your shader (and you'd have to call it position
).
In the short term it would be easy to at least publish a tiny OpenSolid.WebGL
module that would provide helper functions to at convert back and forth between (e.g.) an OpenSolid Point3d
and a Math.Vector3.Vec3
(the type supported by WebGL
) but the functions would be pretty trivial:
toVec3 : Point3d -> Math.Vector3.Vec3
toVec3 =
Point3d.coordinates >> Math.Vector3.fromTuple
Long-term I'm sketching out a higher-level OpenSolid.Scene3d
module that will build on top of this package and the WebGL package but hide the attributes/shader details.
Thoughts? Can you sketch out the type signatures of a couple OpenSolid-to-WebGL functions that you would find useful?
@ianmackenzie Thank you a lot for the explanation! I'll try to use it in my code and report (actually for the moment I need 3D Spheres and other 3D volumes), I think, though, both the suggested converter and Point3d.coordinates >> Math.Vector3.fromTuple
could do the trick I need.