Module OgamlGraphics.Model

Creation, loading and manipulation of 3D models


Face Represents a face of a model
Vertex Represents a particular vertex of a model

This module provides helpers to manipulate and load immutable 3D models in the RAM.
Moreover, the operations provided in this module are generally costly and should not be used in performance-sensitive code.
Models stored in that form are not RAM-friendly, and should not be stored in large numbers. Use vertex arrays instead.

exception Error of string
Raised if an OBJ file is ill-formed or if a model has a wrong type
type t
Type of a model

Model creation

val empty : t
Empty model
val from_obj : string -> t
Returns the model associated to an OBJ file
val cube : OgamlMath.Vector3f.t -> OgamlMath.Vector3f.t -> t
Creates a cube from two endpoints


val transform : t -> OgamlMath.Matrix3D.t -> t
Applies a transformation to a 3D model
val scale : t -> OgamlMath.Vector3f.t -> t
Scales a 3D model
val translate : t -> OgamlMath.Vector3f.t -> t
Translates a 3D model
val rotate : t -> OgamlMath.Quaternion.t -> t
Rotates a 3D model

Model modification

val add_face : t -> Face.t -> t
Adds a face to a model
val paint : t -> Color.t -> t
Paints the whole model with a given color
val merge : t -> t -> t
Merges two models
val compute_normals : ?smooth:bool -> t -> t
(Re-)computes the normals of a model. If smooth is true , then the normals are computed per-vertex instead of per-face
val simplify : t -> t
Simpifies a model (removes all redundant faces)
val source : t -> ?index_source:IndexArray.Source.t -> vertex_source:VertexArray.SimpleVertex.T.s VertexArray.VertexSource.t -> unit -> unit
Appends a model to a vertex source. Uses indexing if an index source is provided. Use Triangles as DrawMode with this source.
See : OgamlGraphics.IndexArray.Source
See : OgamlGraphics.VertexArray.Source


val iter : t -> (Face.t -> unit) -> unit
Iterates through all faces of a model
val fold : t -> ('a -> Face.t -> 'a) -> 'a -> 'a
Folds through all faces of a model
val map : t -> (Face.t -> Face.t) -> t
Maps a model face by face