elm-3d-scene
elm-3d-scene copied to clipboard
Add support for polygons and extrusions
I notice that in ianmackenzie/elm-geometry you have Polygon2d.triangulate
. Was wondering how hard it would be to add two more primitives to Scene3d:
- polygon (with or without holes) - more generalized than
quad
, just a planar triangulated mesh - polygonExtrusion (with or without holes) - like
cylinder
orblock
with planar triangulated meshes on top and bottom, and a strip mesh around the extruded sides.
I would like to be able to add extrusions other than blocks and cylinders (I really enjoyed rebuilding my hand crafted WebGL scene using this library, BTW).
Suggestion: rather than the way quad
is defined by four unconstrained 3d points, it would probably be better to define these two new mesh primitives using Polygon2d
points projected onto a sketch plane, to enforce planarity. The polygonExtrusion would also add a length
property.
Hi Peter, that's very much the next step once elm-3d-scene
1.0 is out! The rough plan is:
- Add
Curve2d
,Curve3d
andSurface3d
types toelm-geometry
to represent parametric curves and surfaces - Add
Region2d
(a region bounded by a set ofCurve2d
s) andBody3d
(a body bounded by a set ofSurface3d
) types toelm-geometry
- Add extrusion, revolution and similar methods to
elm-geometry
so you can do things like construct aBody3d
by extruding aRegion2d
along an axis or revolving it around an axis, construct aSurface3d
by placing aRegion2d
on aSketchPlane3d
, or construct aSurface3d
by extruding/revolving aCurve3d
- Add
Scene3d.curve
,Scene3d.surface
andScene3d.body
functions toelm-3d-scene
to render the corresponding types to within a given accuracy (or eventually a set of accuracies, with dynamic level of detail handled automatically)
My ultimate goal for elm-geometry
, elm-3d-scene
etc. is indeed to have a really nice ecosystem for building up 3D shapes with Elm code (roughly "CAD with code instead of a mouse"), which sounds pretty in line with what you're suggesting.
Polygons and polygon extrusions would then be a special case of regions and bodies - for example you might have a function like Region2d.polygon : Polygon2d -> Region2d
which you could then extrude as you describe. But I also really want to support defining regions and bodies with curved boundaries, where conversion to triangles only happens implicitly when rendering.
Hope that makes sense - definitely happy to talk through these ideas as this is the area I'm really excited about using Elm for!
By the way, the entire reason I added Polygon2d.triangulate
was in fact to be able to (eventually) render Body3d
values - since ultimately rendering a body will involve converting various Region2d
values to polygons (with some desired accuracy) and then triangulating the resulting polygons so they can be rendered with WebGL.