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
205 stars 27 forks source link

Allow efficient dynamic coloring #12

Closed ianmackenzie closed 5 years ago

ianmackenzie commented 7 years ago

Currently Drawables must be constructed with a specific color/material, but it is possible to vary color dynamically without reloading the mesh data. This might be done by adding functions like

Drawable.trianglesWithDynamicColor : List Triangle3d -> Vec3 -> Drawable

which are designed to be partially applied, resulting in a Vec3 -> Drawable function where every call with a different color ends up reusing the same underlying mesh.

This could also be done by changing the argument order of existing functions to always pass color/material last, but that could interfere with some optimizations - for example, if a simple flat color is passed as the material for some mesh, the implementation can choose to store positions only and discard normal vectors. If the implementation had to always assume that materials will be changed dynamically (potentially to one where normals are required), then such optimizations would become harder or impossible.

ianmackenzie commented 5 years ago

Has been implemented by separating out Mesh into its own type.