meshx

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2024 License: MIT Imports: 11 Imported by: 0

README

MeshX-Go

Documentation

Index

Constants

View Source
const (
	PrefixVertex = "v"
	PrefixFace   = "f"
	PrefixGroup  = "g"
)

Variables

View Source
var (
	ErrInvalidVertex = errors.New("invalid vertex")
	ErrInvalidFace   = errors.New("invalid face")
)
View Source
var (
	ErrNonManifold = errors.New("non-manifold mesh")
)

Functions

This section is empty.

Types

type AABB

type AABB struct {
	Center   Vector
	HalfSize Vector
}

Axis aligned bounding box.

func NewAABB

func NewAABB(center, halfSize Vector) AABB

Construct an AABB from its center and halfsize.

func NewAABBFromBounds

func NewAABBFromBounds(minBound, maxBound Vector) AABB

Construct an AABB from its min/max bounds.

func NewAABBFromVectors

func NewAABBFromVectors(vectors []Vector) AABB

Construct an AABB from a slice of vectors.

func (AABB) Buffer

func (a AABB) Buffer(s float64) AABB

Construct an AABB with a buffer (percentage of the edge length).

func (AABB) GetMaxBound

func (a AABB) GetMaxBound() Vector

Get the maximum bound.

func (AABB) GetMinBound

func (a AABB) GetMinBound() Vector

Get the minimum bound.

func (AABB) IntersectsAABB

func (a AABB) IntersectsAABB(query AABB) bool

Implement the IntersectsAABB interface.

func (AABB) Octant

func (a AABB) Octant(octant int) AABB

Compute the octant AABB.

type IntersectsAABB

type IntersectsAABB interface {
	IntersectsAABB(AABB) bool
}

type IntersectsRay

type IntersectsRay interface {
	IntersectsRay(Ray) bool
}

type IntersectsTriangle

type IntersectsTriangle interface {
	IntersectsTriangle(Triangle) bool
}

type MeshReader

type MeshReader interface {
	Read() error
	GetNumberOfVertices() int
	GetNumberOfFaces() int
	GetNumberOfFaceEdges() int
	GetNumberOfPatches() int
	GetVertex(int) Vector
	GetFace(int) []int
	GetFacePatch(int) int
	GetPatch(int) string
}

Generic mesh reader interface.

type MeshWriter

type MeshWriter interface {
	Write() error
	SetVertices([]Vector)
	SetFaces([][]int)
	SetFacePatches([]int)
	SetPatches([]string)
}

Generic mesh writer interface.

type OBJReader

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

OBJReader manages parsing an OBJ (WaveFront) file. This supports both ASCII and GZIP ASCII files.

func NewOBJReader

func NewOBJReader(reader io.Reader) *OBJReader

Construct an OBJ reader from an io.Reader interface.

func ReadOBJFromPath

func ReadOBJFromPath(path string) (*OBJReader, error)

Read an OBJ file from a file path.

func (*OBJReader) GetFace

func (r *OBJReader) GetFace(index int) []int

Get a face by index.

func (*OBJReader) GetFacePatch

func (r *OBJReader) GetFacePatch(index int) int

Get a face patch by index.

func (*OBJReader) GetNumberOfFaceEdges

func (r *OBJReader) GetNumberOfFaceEdges() int

Get the number of face edges.

func (*OBJReader) GetNumberOfFaces

func (r *OBJReader) GetNumberOfFaces() int

Get the number of faces.

func (*OBJReader) GetNumberOfPatches

func (r *OBJReader) GetNumberOfPatches() int

Get the number of patches.

func (*OBJReader) GetNumberOfVertices

func (r *OBJReader) GetNumberOfVertices() int

Get the number of vertices.

func (*OBJReader) GetPatch

func (r *OBJReader) GetPatch(index int) string

Get a patch by index.

func (*OBJReader) GetVertex

func (r *OBJReader) GetVertex(index int) Vector

Get a vertex by index.

func (*OBJReader) Read

func (r *OBJReader) Read() error

Read the OBJ file.

type OBJWriter

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

OBJReader manages writing an OBJ (WaveFront) file.

func NewOBJWriter

func NewOBJWriter(writer io.Writer) *OBJWriter

Construct an OBJWriter from an io.Writer interface.

func (*OBJWriter) SetEdges

func (w *OBJWriter) SetEdges(edges [][2]int)

Set the edges to write.

func (*OBJWriter) SetFacePatches

func (w *OBJWriter) SetFacePatches(facePatches []int)

Set the face patches to write.

func (*OBJWriter) SetFaces

func (w *OBJWriter) SetFaces(faces [][]int)

Set the faces to write.

func (*OBJWriter) SetPatches

func (w *OBJWriter) SetPatches(patches []string)

Set the patches to write.

func (*OBJWriter) SetVertices

func (w *OBJWriter) SetVertices(vertices []Vector)

Set the vertices to write.

func (*OBJWriter) Write

func (w *OBJWriter) Write() error

Write the data to the io.Writer interface.

type Ray

type Ray struct {
	Origin    Vector
	Direction Vector
}

Ray in three-dimensional Cartesian space.

func NewRay

func NewRay(origin, direction Vector) Ray

Construct a Ray from its origin and direction.

func (Ray) IntersectsAABB

func (r Ray) IntersectsAABB(query AABB) bool

Implement the IntersectsAABB interface.

func (Ray) IntersectsTriangle

func (r Ray) IntersectsTriangle(query Triangle) bool

Implement the IntersectsTriangle interface.

type Triangle

type Triangle struct {
	P Vector
	Q Vector
	R Vector
}

Triangle in three-dimension Cartesian space.

func NewTriangle

func NewTriangle(p, q, r Vector) Triangle

Construct a Triangle from its vertices.

func (Triangle) Area

func (t Triangle) Area() float64

Compute the area.

func (Triangle) IntersectsAABB

func (t Triangle) IntersectsAABB(query AABB) bool

Implement the IntersectsAABB interface.

func (Triangle) IntersectsRay

func (t Triangle) IntersectsRay(query Ray) bool

Implement the IntersectsRay interface.

func (Triangle) Normal

func (t Triangle) Normal() Vector

Compute the normal.

func (Triangle) UnitNormal

func (t Triangle) UnitNormal() Vector

Compute the unit normal.

type Vector

type Vector [3]float64

Cartesian vector in three-dimensional space.

func NewVector

func NewVector(x, y, z float64) Vector

Construct a Vector from its components.

func NewVectorFromArray

func NewVectorFromArray(values [3]float64) Vector

Construct a Vector from an array.

func (Vector) Abs

func (v Vector) Abs() Vector

Compute the absolute vector.

func (Vector) Add

func (v Vector) Add(w Vector) Vector

Add two vectors v + w.

func (Vector) AddScalar

func (v Vector) AddScalar(s float64) Vector

Add a scalar to a vector.

func (Vector) AngleTo

func (v Vector) AngleTo(w Vector) float64

Compute the angle (in radians) from v to w.

func (Vector) Cross

func (v Vector) Cross(w Vector) Vector

Compute the cross product v x w.

func (Vector) Div

func (v Vector) Div(w Vector) Vector

Divide two vectors element-wise v / w.

func (Vector) DivScalar

func (v Vector) DivScalar(s float64) Vector

Divide a vector by a scalar.

func (Vector) Dot

func (v Vector) Dot(w Vector) float64

Compute the dot product v * w.

func (Vector) IntersectsAABB

func (v Vector) IntersectsAABB(query AABB) bool

Implement the IntersectsAABB interface.

func (Vector) Inv

func (v Vector) Inv() Vector

Compute the inverse.

func (Vector) Mag

func (v Vector) Mag() float64

Compute the magnitude (L2-norm).

func (Vector) Mul

func (v Vector) Mul(w Vector) Vector

Multiply two vectors element-wise v * w.

func (Vector) MulScalar

func (v Vector) MulScalar(s float64) Vector

Multiply a scalar by a vector.

func (Vector) Sub

func (v Vector) Sub(w Vector) Vector

Subtract two vectors v - w.

func (Vector) SubScalar

func (v Vector) SubScalar(s float64) Vector

Subtract a scalar from a vector.

func (Vector) Unit

func (v Vector) Unit() Vector

Compute the unit.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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