Module Litu.Prim

module Prim: sig .. end
Higher level primitives.

All these primitives define at least a Lit.Attr.vertex attribute. Buffers are created with Lit.Buf.create's default arguments.



Primitives

Note. All these primitives are `Triangles primitives.

val rect : ?tr:Gg.m4 ->
?name:string ->
?tex:string -> ?segs:Gg.Size2.t -> ?d2:bool -> Gg.box2 -> Lit.prim
rect tr name tex d2 segs box is an axis-aligned Oxy 2D plane bounded by b.

The plane is divided in Size2.w segs segments along the x-axis and Size2.h segs along the y-axis (segs defaults to Size2.unit, its number are rounded to integers). Each segment is made of two triangles.

If d2 is true (defaults to false), the primitive's vertex attribute has dimension 2.

If tex is specified, 2D texture coordinates are added to the primitive under that attribute name. The bottom left corner of the plane is (0,0) and top right (1,1).

tr and name are given to Lit.Prim.create.

val cuboid : ?tr:Gg.m4 -> ?name:string -> ?dups:bool -> Gg.box3 -> Lit.prim
cuboid tr dups box is an axis-aligned cuboid bounded by box. If dups is true (default) vertices in the mesh are triplicated so that per vertex normal computation defines planar facets.

tr and name are given to Lit.Prim.create.

val cube : ?tr:Gg.m4 -> ?name:string -> ?dups:bool -> float -> Lit.prim
cube tr name dups s is cube tr name dups (Box3.v_mid P3.o (Size3.v s s s)).
val sphere : ?tr:Gg.m4 -> ?name:string -> ?level:int -> float -> Lit.prim
sphere tr name level r is a sphere of radius r centered on the origin obtained by subdividing an octahedron (level = 0). level defaults to 4. The number of vertices is 4level + 1 + 2 and the number of triangles is 8 * 4level. If the number of vertices is greater than 231 all sorts of bad things may happen...

tr and name are given to Lit.Prim.create.


Functions


val with_normals : ?scalar_type:[ `Float32 | `Float64 ] -> ?name:string -> Lit.prim -> Lit.prim
with_normals prim is prim with a Lit.Attr.normal attribute added or replaced. The attribute has a normal per Lit.Attr.vertex attribute computed from the primitive's triangles. In case a vertex belongs to multiple triangles the contribution of each triangle is summed up and the result normalized.

Warning. Vertex data is looked up by taking vertices from their buffer taking into account Lit.Attr.first and Lit.Attr.stride until the end of the buffer.
Raises Invalid_argument if one of these conditions holds: