mesh

package
v0.0.0-...-2ef904a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 29, 2016 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package mesh provides functions for managing 3d triangle meshes and material definitions.

Index

Constants

View Source
const MaxLights = 4

Variables

This section is empty.

Functions

func LoadMtl

func LoadMtl(r io.Reader) (names []string, err error)

Create a new material from .mtl data, returns list of material names

func LoadMtlFile

func LoadMtlFile(name string) ([]string, error)

Load a .mtl file to create one or more new materials, returns list of material names

Types

type El

type El struct {
	Vert, Tex, Norm int
}

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 Diffuse

func Diffuse(tex ...glu.Texture) Material

Diffuse colored material with optional texture

func Earth

func Earth() Material

Earth cubemap

func Emissive

func Emissive() Material

Emissive material which looks like it glows

func Glass

func Glass() Material

Glass is reflective and has transparency

func LoadMaterial

func LoadMaterial(name string, bumpMap bool) (mtl Material, err error)

Get material by name

func Marble

func Marble() Material

Marble textured material

func Metallic

func Metallic() Material

Textured metallic material

func Plastic

func Plastic() Material

Shiny plastic like material

func PointMaterial

func PointMaterial() Material

Material used for drawing points

func Reflective

func Reflective(specular mgl32.Vec4, shininess float32, tex ...glu.Texture) Material

Coloured material with specular highlights using Blinn-Phong model. tex paramater is optional list of associated textures for diffuse, specular and normal map.

func Rough

func Rough() Material

Rough randomly textured material

func Skybox

func Skybox() Material

Skybox using a cubemap texture

func Unshaded

func Unshaded(tex ...glu.Texture) Material

Unshaded colored material with optional texture

func Wood

func Wood() Material

3d Textured wood material

type Mesh

type Mesh struct {
	// contains filtered or unexported fields
}

Mesh type stores a mesh of vertices

func Circle

func Circle(segments int) *Mesh

Circle is a flat circlular triangle fan with given number of segments

func Cone

func Cone(segments int) *Mesh

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

func Cylinder(segments int) *Mesh

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 LoadObj

func LoadObj(r io.Reader) (m *Mesh, err error)

Create a new mesh from data

func LoadObjFile

func LoadObjFile(name string) (m *Mesh, err error)

Create a new mesh and associated materials from a .obj file

func New

func New() *Mesh

NewMesh creates a new empty mesh structure

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 Point

func Point(pointSize int) *Mesh

Generate a zero dimensional point

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

func Sphere(recursionLevel int) *Mesh

Create a sphere by recursively dividing the faces on the icosohedron into smaller triangles

func (*Mesh) AddFace

func (m *Mesh) AddFace(el ...El) int

Add a triangular or a quad face

func (*Mesh) AddNormal

func (m *Mesh) AddNormal(nx, ny, nz float32) int

Add a new vertex normal

func (*Mesh) AddTexCoord

func (m *Mesh) AddTexCoord(tx, ty float32) int

Add tex coordinates

func (*Mesh) AddVertex

func (m *Mesh) AddVertex(x, y, z float32) int

Add a new vertex position

func (*Mesh) Build

func (m *Mesh) Build(materialName string)

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) BumpMap

func (m *Mesh) BumpMap(on bool)

Enable or disable normal mapping

func (*Mesh) Clear

func (m *Mesh) Clear() *Mesh

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

func (m *Mesh) Clone() *Mesh

Clone method makes a copy of the mesh with the same vertex data, but a copy of the materials

func (*Mesh) Draw

func (m *Mesh) Draw(setUniforms func(*glu.Program)) error

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

func (m *Mesh) Invert() *Mesh

Invert method reverses the normals and winding order to flip the shape inside out

func (*Mesh) Material

func (m *Mesh) Material() Material

Get the material assocociated with the first mesh group

func (*Mesh) PointSize

func (m *Mesh) PointSize() int

Point method returns point size, or zero for non-point

func (*Mesh) SetMaterial

func (m *Mesh) SetMaterial(mtl Material) *Mesh

Update all the materials associated with this mesh.

func (*Mesh) SetNormalSmoothing

func (m *Mesh) SetNormalSmoothing(on bool)

If flag is false then turn off smoothing of vertex normals, else start a new smoothing group

func (*Mesh) String

func (m *Mesh) String() (s string)

String method for dumping out contents of the mesh

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL