ianmackenzie / elm-3d-scene

A high-level 3D rendering engine for Elm, with support for lighting, shadows, and realistic materials.
https://package.elm-lang.org/packages/ianmackenzie/elm-3d-scene/latest/
Mozilla Public License 2.0
207 stars 27 forks source link

Add support for polygons and extrusions #73

Open pzingg opened 4 years ago

pzingg commented 4 years ago

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.

ianmackenzie commented 4 years ago

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

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 commented 4 years ago

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.