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 Scene3d.Cache type for WebGL rendering #20

Open ianmackenzie opened 5 years ago

ianmackenzie commented 5 years ago

This would contain generated WebGL meshes at varying levels of detail, and would be updated in an app's update function based on a 3D scene, a camera position, a desired rendering accuracy (in pixels), and possibly a caching strategy (to determine when generated meshes should be discarded). The cache would then be used in view to actually render as WebGL.

This system would have many benefits:

Having a cache system would likely mean that individual drawables should have a pre-computed hash of their content, to be used as an ID for looking up corresponding meshes in the cache.

ianmackenzie commented 5 years ago

Could probably just call the cache type Scene3d, with an API like

-- Create an empty scene
Scene3d.init : Scene3d

-- Update a scene to include the given scene graph (drawable), reusing
-- cached meshes or generating new meshes as needed
Scene3d.update : List Light -> Camera -> Drawable -> Scene3d -> Scene3d

-- Render the cached meshes using WebGL
Scene3d.view : Scene3d -> Html msg

-- Could then also have export-to-file functions like
Scene3d.toCollada : Scene3d -> String