four.Geometry

.new (def)

-- Module definition

local lib = { type = 'four.Geometry' } lib.__index = lib four.Geometry = lib setmetatable(lib, { __call = function(lib, ...) return lib.new(...) end})

local Buffer = four.Buffer local V2 = four.V2 local V3 = four.V3

-- h2. Primitive constants -- Defines how the vertex stream is interpreted.

lib.POINTS = 1 lib.LINE_STRIP = 2 lib.LINE_LOOP = 3 lib.LINES = 4 lib.LINE_STRIP_ADJACENCY = 5 lib.LINES_ADJACENCY = 6 lib.TRIANGLE_STRIP = 7 lib.TRIANGLE_FAN = 8 lib.TRIANGLES = 9 lib.TRIANGLE_STRIP_ADJACENCY = 10 lib.TRIANGLES_ADJACENCY = 11

-- h2. Constructor

--[[-- @Geometry(def)@ is a new geometry object. @def@ keys:

  • @primitive@, the geometrical primitive (defaults to @Geometry.TRIANGLES@).
  • @data@, table of named @Buffer@s all of the same length defining per vertex data. Table key names are used to bind to the corresponding vertex shader inputs.
  • @index@, @Buffer@ of unsigned ints or bytes (any dim), indexing into @data@ to define the actual sequence of primitives. WARNING indices are zero-based.
  • @pre_transform@, an M4 matrix that the renderer pre-multiplies to the renderable's transform.
  • @name@, a user defined way of naming the geometry (may be used by the renderer to report errors about the object).

Warning Once a geometry object was rendered its structure is immutable: the buffers referenced by @data@ keys and @index@ cannot change. However the actual data of the buffers may change.

:set (def)

TODO MISSING DOCUMENTATION

:computeBoundRadius ()

@computeBoundsRadius()@ computes the radius of the bounding sphere containing all the 3D points of @self.data.vertex@ and stores it in @self.bound_radius@. If @data.vertex@ is @nil@ the radius is zero.

:computeVertexNormals (force)

@computeVertexNormals(force)@ computes per vertex normals for all the 3D points of @self.data.vertex@ and stores them in @self.data.normal@. WARNING works only with @Geometry.TRIANGLE@ primitive. Does nothing if @data.normal@ exists and force is @false@ (default).

.Cuboid (extents, no_dups)

@Cuboid(V3(w, h, d) [, no_dups])@ is a cuboid centered on the origin with the given extents. If [no_dups] is @true@ vertices in the mesh are not duplicated, better for computational geometry but implies that normals do not define facets.

.Cube (s, no_dups)

@Cube(s [, no_dups])@ is @Cuboid(V3(s, s, s) [, no_dups])

.Sphere (r, level)

@Sphere(r[,level])@ is a sphere of radius @r@ centered on the origin. The optional parameter @level@ defines the subdivision level (defaults to @10@. Number of triangles is @4^level * 8@

.Plane (extents, segs)

@Plane(V2(w, h) [, V2(xseg, yseg))@ is an Oxy plane of width @w@ and height @h@ centered on the origin. The plane is divided in @xseg@ segments along the x-axis and @yseg@ along the y-axis (both default to @1@).

TODO

#setTODO MISSING DOCUMENTATION