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

Add Scene3d.Cache type for WebGL rendering

Open ianmackenzie opened this issue 5 years ago • 1 comments

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:

  • Can support dynamic levels of detail transparently for analytical shapes like spline curves, extruded/revolved surfaces etc: generate meshes with different levels of accuracy on the fly as needed
  • Similarly, can separate construction of a scene from curves/surfaces from the decision of what accuracy to render at
  • In some cases, meshing can be avoided entirely: for example, if the scene is actually encoded as JSON or in a particular file format to be rendered on a server and sent back as an image/streaming video etc.

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 avatar Apr 26 '19 00:04 ianmackenzie

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

ianmackenzie avatar May 09 '19 03:05 ianmackenzie