elm-3d-scene icon indicating copy to clipboard operation
elm-3d-scene copied to clipboard

Add support for polygons and extrusions

Open pzingg opened this issue 4 years ago • 2 comments

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:

  1. polygon (with or without holes) - more generalized than quad, just a planar triangulated mesh
  2. polygonExtrusion (with or without holes) - like cylinder or block 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.

pzingg avatar Apr 18 '20 17:04 pzingg

Hi Peter, that's very much the next step once elm-3d-scene 1.0 is out! The rough plan is:

  • Add Curve2d, Curve3d and Surface3d types to elm-geometry to represent parametric curves and surfaces
  • Add Region2d (a region bounded by a set of Curve2ds) and Body3d (a body bounded by a set of Surface3d) types to elm-geometry
  • Add extrusion, revolution and similar methods to elm-geometry so you can do things like construct a Body3d by extruding a Region2d along an axis or revolving it around an axis, construct a Surface3d by placing a Region2d on a SketchPlane3d, or construct a Surface3d by extruding/revolving a Curve3d
  • Add Scene3d.curve, Scene3d.surface and Scene3d.body functions to elm-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!

ianmackenzie avatar Apr 18 '20 21:04 ianmackenzie

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.

ianmackenzie avatar Apr 18 '20 21:04 ianmackenzie