gomesh

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2021 License: MIT Imports: 7 Imported by: 0

README

gomesh

pkg.go.dev Go Report Card

A small library for handling 3D mesh data in Go.

OBJ Support

The library is able to create and parse a subset of the Wavefront OBJ format. Its Parser implementation is very limited, recognizing only basic vertices and faces.

Documentation

Overview

Package gomesh provides functions for basic handling of 3D mesh data in Go.

Index

Constants

View Source
const (
	X = iota
	Y
	Z
)

Axis definitions

Variables

View Source
var ErrInvalidMesh = errors.New("invalid Mesh data")

ErrInvalidMesh is returned when a decoding function can not make a valid mesh from the data

View Source
var ErrUnsupportedOBJ = errors.New("unsupported OBJ Format")

ErrUnsupportedOBJ is returned when DecodeOBJ can not parse the data

View Source
var ErrVertexNotFound = errors.New("vertex not found")

ErrVertexNotFound is returned when the FindVertex() function does not find the vertex

Functions

This section is empty.

Types

type Face

type Face struct {
	Vertices []int
}

Face contains a list of points (as a slice of mesh vertex ids) which describe the face's 3D structure

type Mesh

type Mesh struct {
	Vertices []Point
	Faces    []Face
}

Mesh is composed of one or multiple faces

func DecodeOBJ

func DecodeOBJ(reader io.Reader) (*Mesh, error)

DecodeOBJ reads a Mesh from the given Reader of a Wavefront OBJ file

func (*Mesh) AddCube

func (mesh *Mesh) AddCube(sx, sy, sz float64)

AddCube generates a cube with the size of {sx, sy, sz}

func (*Mesh) AddPlane

func (mesh *Mesh) AddPlane(w, h, offset float64, axis int)

AddPlane generates a plane with the size of {w,h} with offset z. The function panics if the axis parameter is invalid.

func (*Mesh) AddVertex

func (mesh *Mesh) AddVertex(x, y, z float64) int

AddVertex creates a vertex at the given position if there is not already a vertex. Returns the vertex id

func (Mesh) EncodeOBJ

func (mesh Mesh) EncodeOBJ(writer io.Writer) error

EncodeOBJ writes the mesh to the writer in Wavefront OBJ format

func (Mesh) FindVertex

func (mesh Mesh) FindVertex(x, y, z float64) (int, error)

FindVertex searches for a vertex at the given position

func (Mesh) Validate

func (mesh Mesh) Validate() bool

Validate validates the Mesh data

type Point

type Point struct {
	X float64
	Y float64
	Z float64
}

Point is a location definition in 3D space

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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