meshful

package module
v0.0.0-...-13b082e Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2020 License: MIT Imports: 1 Imported by: 0

README

meshful

Library for processing 3d triangle meshes

Features

Read/Write STL and OBJ files and get mesh dimensions

Demo snippet:

load in an STL file, get the dimensions and export as an OBJ.

package main

import (
	"fmt"
	"github.com/rknizzle/meshful"
	"github.com/rknizzle/meshful/io/obj"
	"github.com/rknizzle/meshful/io/stl"
)

func main() {
	var m *meshful.Mesh
	m, err := stl.ReadFile("tetrahedron.stl")
	if err != nil {
		panic(err)
	}

	fmt.Println("Dimensions of mesh:")
	fmt.Println("bbox:", m.BoundingBox())
	fmt.Println("volume:", m.Volume())
	fmt.Println("area:", m.SurfaceArea())

	err = obj.WriteFile("new.obj", m)
	if err != nil {
		panic(err)
	}
}

WIP: This repo is a work in progress

TODO:
  • transform mesh(scale, rotate, move)
  • Support more complex OBJs
  • Mesh health analysis and repair

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Color

type Color struct {
	// values should be between 0 and 1
	Red   float32
	Green float32
	Blue  float32
}

type Mesh

type Mesh struct {
	Triangles []Triangle
}

A mesh represents a collection of triangles

func (*Mesh) BoundingBox

func (mesh *Mesh) BoundingBox() [3]float32

func (*Mesh) SurfaceArea

func (mesh *Mesh) SurfaceArea() float32

func (*Mesh) Volume

func (mesh *Mesh) Volume() float32

type Triangle

type Triangle struct {
	// the 3 vertices that make up a facet
	Vertices [3]Vec3

	// triangle normal vector
	Normal Vec3

	// color of the triangle
	Color *Color
}

A triangle is made up of 3 vertices and has a surface normal

func (*Triangle) Area

func (t *Triangle) Area() float32

func (*Triangle) SignedVolume

func (t *Triangle) SignedVolume() float32

type Vec3

type Vec3 struct {
	X, Y, Z float32
}

A Vec3 represents a 3 dimensional vector for storing triangle vertices and normals

func (Vec3) Cross

func (vec Vec3) Cross(other Vec3) Vec3

get the cross product of two vectors

func (Vec3) Diff

func (vec Vec3) Diff(other Vec3) Vec3

diff returns the difference between two vectors

func (Vec3) Dot

func (vec Vec3) Dot(other Vec3) float64

get the dot product of two vectors

Directories

Path Synopsis
io
obj
stl

Jump to

Keyboard shortcuts

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