EAGL.Model (eagl v0.1.0)

View Source

Helper module for loading 3D model resources and creating OpenGL vertex array objects.

Summary

Functions

Deletes a vertex array object and its associated buffers.

Lists all available models in the priv/models directory.

Loads a model from the priv/models directory. Returns the processed model data ready for OpenGL.

Loads a model and creates a VAO with the model data. Returns {:ok, %{vao: vao, vertex_count: count}} or {:error, reason}

Functions

delete_vao(vao)

@spec delete_vao(integer()) :: :ok

Deletes a vertex array object and its associated buffers.

list_models()

@spec list_models() :: [String.t()]

Lists all available models in the priv/models directory.

load_model(filename, opts \\ [])

@spec load_model(
  String.t(),
  keyword()
) :: {:ok, map()} | {:error, String.t()}

Loads a model from the priv/models directory. Returns the processed model data ready for OpenGL.

Options:

  • :flip_normal_direction - boolean, set to true to flip normal direction for all models (default: false)
                         This works for both models with existing normals and models that need generated normals.
  • :smooth_normals - boolean, set to true to generate smooth normals by averaging across adjacent faces (default: false)
                  This gives a smoother appearance by eliminating the faceted look.

load_model_to_vao(filename, opts \\ [])

@spec load_model_to_vao(
  String.t(),
  keyword()
) :: {:ok, %{vao: integer(), vertex_count: integer()}} | {:error, String.t()}

Loads a model and creates a VAO with the model data. Returns {:ok, %{vao: vao, vertex_count: count}} or {:error, reason}

The VAO will have the following attributes:

  • Location 0: Vertex positions (vec3)
  • Location 1: Texture coordinates (vec2)
  • Location 2: Normals (vec3)

Options:

  • :flip_normal_direction - boolean, set to true to flip normal direction for all models (default: false)
                         This works for both models with existing normals and models that need generated normals.
                         Useful when model normals are pointing in the wrong direction for your lighting setup.
  • :smooth_normals - boolean, set to true to generate smooth normals by averaging across adjacent faces (default: false)
                  This gives a smoother appearance by eliminating the faceted look.
                  When true, existing normals are ignored and smooth normals are generated.