Documentation ¶
Overview ¶
Package mesh provides functions for managing 3d triangle meshes and material definitions.
Index ¶
- Constants
- func LoadMtl(r io.Reader) (names []string, err error)
- func LoadMtlFile(name string) ([]string, error)
- type El
- type Material
- func Diffuse(tex ...glu.Texture) Material
- func Earth() Material
- func Emissive() Material
- func Glass() Material
- func LoadMaterial(name string, bumpMap bool) (mtl Material, err error)
- func Marble() Material
- func Metallic() Material
- func Plastic() Material
- func PointMaterial() Material
- func Reflective(specular mgl32.Vec4, shininess float32, tex ...glu.Texture) Material
- func Rough() Material
- func Skybox() Material
- func Unshaded(tex ...glu.Texture) Material
- func Wood() Material
- type Mesh
- func Circle(segments int) *Mesh
- func Cone(segments int) *Mesh
- func Cube() *Mesh
- func Cylinder(segments int) *Mesh
- func Icosohedron() *Mesh
- func LoadObj(r io.Reader) (m *Mesh, err error)
- func LoadObjFile(name string) (m *Mesh, err error)
- func New() *Mesh
- func Plane() *Mesh
- func Point(pointSize int) *Mesh
- func Prism() *Mesh
- func Sphere(recursionLevel int) *Mesh
- func (m *Mesh) AddFace(el ...El) int
- func (m *Mesh) AddNormal(nx, ny, nz float32) int
- func (m *Mesh) AddTexCoord(tx, ty float32) int
- func (m *Mesh) AddVertex(x, y, z float32) int
- func (m *Mesh) Build(materialName string)
- func (m *Mesh) BumpMap(on bool)
- func (m *Mesh) Clear() *Mesh
- func (m *Mesh) Clone() *Mesh
- func (m *Mesh) Draw(setUniforms func(*glu.Program)) error
- func (m *Mesh) Invert() *Mesh
- func (m *Mesh) Material() Material
- func (m *Mesh) PointSize() int
- func (m *Mesh) SetMaterial(mtl Material) *Mesh
- func (m *Mesh) SetNormalSmoothing(on bool)
- func (m *Mesh) String() (s string)
Constants ¶
const MaxLights = 4
Variables ¶
This section is empty.
Functions ¶
func LoadMtlFile ¶
Load a .mtl file to create one or more new materials, returns list of material names
Types ¶
type Material ¶
type Material interface { Enable() *glu.Program Disable() Color() mgl32.Vec4 SetColor(c mgl32.Vec4) Material Ambient() float32 SetAmbient(s float32) Material Clone() Material }
Interface type for a material which can be used to render a mesh
func LoadMaterial ¶
Get material by name
func Reflective ¶
Coloured material with specular highlights using Blinn-Phong model. tex paramater is optional list of associated textures for diffuse, specular and normal map.
type Mesh ¶
type Mesh struct {
// contains filtered or unexported fields
}
Mesh type stores a mesh of vertices
func Cone ¶
Cone object has a circular base with unit diameter and unit height aligned with the y axis if 8 sides or less then map 2d texture to each side, else wrap it around
func Cube ¶
func Cube() *Mesh
Cube object is a cube centered at the origin with sides of unit length aligned with the axes
func Cylinder ¶
Cylinder object has a circle with unit diameter aligned with the y axis and is of unit height
func Icosohedron ¶
func Icosohedron() *Mesh
Create an icosohedron on a sphere of unit diameter centered on the origin
func LoadObjFile ¶
Create a new mesh and associated materials from a .obj file
func Plane ¶
func Plane() *Mesh
Plane object is a flat two sided unit square in the xz plane centered at the origin facing in +ve z direction
func Prism ¶
func Prism() *Mesh
Prism object centered on the origin base is in xz plane and is square of unit lenght, height is sqrt(3)/2
func Sphere ¶
Create a sphere by recursively dividing the faces on the icosohedron into smaller triangles
func (*Mesh) Build ¶
Build method processes the data which has been added so far and appends it to the vertex and element buffers. It can be called multiple times to add multiple groups of data.
func (*Mesh) Clear ¶
Clear method wipes the stored vertex data. It does not erase groups which are already built, call this after Build if you need to add a new set of vertices separate to the previous ones.
func (*Mesh) Clone ¶
Clone method makes a copy of the mesh with the same vertex data, but a copy of the materials
func (*Mesh) Draw ¶
Draw method draws the mesh by calling GL DrawElements, setUniforms callback can be used to set uniforms after binding the vertex arrays and enabling the shaders, but prior to drawing.
func (*Mesh) Invert ¶
Invert method reverses the normals and winding order to flip the shape inside out
func (*Mesh) SetMaterial ¶
Update all the materials associated with this mesh.
func (*Mesh) SetNormalSmoothing ¶
If flag is false then turn off smoothing of vertex normals, else start a new smoothing group