mesh

package
v0.0.0-...-1050381 Latest Latest
Warning

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

Go to latest
Published: May 7, 2017 License: MIT Imports: 7 Imported by: 16

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Initialize

func Initialize()

Loads models into buffers on the GPU. glfw.Init() must be called before calling this.

func TriangleNormals

func TriangleNormals(triangles [][3]mgl32.Vec3) []mgl32.Vec3

TriangleNormals takes triangles that presumably make up mesh and returns a slice of normals. There will be one normal per vertex, for a total of 3 * len(triangles). All normals for a single triangle are the same. Note that the direction of the normals is based on the right hand rule, so the order by which the vertices are defined can flip the direction of the normal. If you need it in the other direction, just negate each normal:

for i := range normals {
  normals[i] = normals[i].Mul(-1)
}

Types

type Mesh

type Mesh struct {

	// Color is 32-bit non-premultiplied RGBA. It is optional, but leaving it nil is the same as setting it to pure white.
	// Note that the color.Color interface's Color() function returns weird values (between 0 and 0xFFFF for avoiding overflow).
	// I recommend just accessing the RGBA fields directly.
	Color *color.NRGBA

	// BaseRotation is a rotation applied to the mesh.
	// This is intended to be used to orient the mesh so Up toward {0,1,0}, and Forward is towards {1,0,0}, since not all
	// meshes will be created in this orientation. Note that if you don't want to modify the default rotation, this must
	// be set to mgl32.QuatIdent().
	// Encouraging a consistent orientation for all meshes makes dealing with them much easier, but it is not absolutely
	// required.
	BaseRotation mgl32.Quat
	// contains filtered or unexported fields
}
var (

	// Axes are the X,Y,Z axes in a mesh. All axes are of length 1, so they should be scaled before being drawn in most cases.
	// The XYZ axes are colored RGB respectively.
	Axes Mesh
)

func NewCircle

func NewCircle(col *color.NRGBA, texture gl.Texture) Mesh

func NewCircleOutline

func NewCircleOutline(col *color.NRGBA) Mesh

func NewCube

func NewCube(col *color.NRGBA, texture gl.Texture) Mesh

NewCube returns a Mesh of a unit cube (all sides length 1) centered at the origin.

func NewIcosahedron

func NewIcosahedron(col *color.NRGBA, texture gl.Texture) Mesh

NewIcosahedron returns a mesh for a 20 sided figure. TODO: Implement texture coordinates for this figure. For now only color is supported.

func NewLine

func NewLine(p1, p2 mgl32.Vec3, col *color.NRGBA) Mesh

TODO: Line is an odd case. Other meshes can be easily scaled and rotated while still using the same basic built in model, but that doesn't work for lines. The way this is, each line requires creating a buffer on the GPU which is never deleted. Adding a delete method just for line meshes is odd, since none of the other models do it, but it's probably necessary.

func NewMesh

func NewMesh(vertices, vertexIndices, normals gl.Buffer, vboMode gl.Enum, itemCount int, color *color.NRGBA, texture gl.Texture, textureCoords gl.Buffer) Mesh

NewMesh combines the input buffers and rendering information into a Mesh struct. Using this method requires loading OpenGL buffers yourself. It's not recommended for general use. Most standard use of meshes can be done via the standard ones (i.e. NewCube(), NewSphere(), NewRect()) or by loading an model from file via the `asset` package.

func NewMeshFromArrays

func NewMeshFromArrays(vertices, normals []mgl32.Vec3, textureCoords []mgl32.Vec2) (Mesh, error)

NewMeshFromArrays copies the input vertices, normals, and texture coordinates into buffers on the GPU.

func NewRect

func NewRect(col *color.NRGBA, texture gl.Texture) Mesh

func NewRectOutline

func NewRectOutline(col *color.NRGBA) Mesh

func NewSphere

func NewSphere(detail int, col *color.NRGBA, texture gl.Texture) Mesh

NewSphere returns a sphere mesh. The higher the detail, the more triangles that make up the mesh. Making this number too large will very quickly make you run out of memory. Detail 0 is an icosahedron with 20 triangular faces. Each detail level has (detail ^ 4) * 3 * 20 vertices, so by detail 5 it's up to 37500 faces. Recommended value for a decently smooth sphere is 4.

func NewSubdividedIcosahedron

func NewSubdividedIcosahedron(divisions int, col *color.NRGBA, texture gl.Texture) Mesh

NewSubdividedIcosahedron returns a mesh for an n sided figure created by recursively dividing each face of an icosahedron (20 sided figure). Note that this recursive division of each triangular face grows very quickly and may cause unexpected crashes due to running out of memory if the number of divisions is too large.

func (*Mesh) ItemCount

func (m *Mesh) ItemCount() int

func (*Mesh) NormalVBO

func (m *Mesh) NormalVBO() gl.Buffer

func (*Mesh) SetNormalVBO

func (m *Mesh) SetNormalVBO(normals gl.Buffer)

func (*Mesh) SetTexture

func (m *Mesh) SetTexture(texture gl.Texture)

func (*Mesh) SetTextureCoords

func (m *Mesh) SetTextureCoords(coords gl.Buffer)

func (*Mesh) SetVBOMode

func (m *Mesh) SetVBOMode(mode gl.Enum)

SetVBOMode allows changing what mode a mesh is rendered in. It's recommended not to use this on the built in meshes as they are created with the VBO Mode they expect to be rendered with. The VBO modes include gl.TRIANGLES, gl.LINES, gl.LINE_LOOP, etc.

func (*Mesh) Texture

func (m *Mesh) Texture() gl.Texture

func (*Mesh) TextureCoords

func (m *Mesh) TextureCoords() gl.Buffer

func (*Mesh) VBOMode

func (m *Mesh) VBOMode() gl.Enum

func (*Mesh) VertexIndices

func (m *Mesh) VertexIndices() gl.Buffer

func (*Mesh) VertexVBO

func (m *Mesh) VertexVBO() gl.Buffer

Jump to

Keyboard shortcuts

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