gobaker

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2020 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Zero    = Vector{0, 0, 0}
	One     = Vector{1, 1, 1}
	Forward = Vector{0, 1, 0}
	Back    = Vector{0, -1, 0}
	Left    = Vector{-1, 0, 0}
	Right   = Vector{1, 0, 0}
	Up      = Vector{0, 0, 1}
	Down    = Vector{0, 0, -1}
)

Unit Vectors

Functions

This section is empty.

Types

type Material

type Material struct {
	Name    string
	Diffuse *Texture
	//Normal  *Texture
	ID *Texture
}

Material of the mesh

type Matrix

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

Matrix represents a 3x3 matrix

func NewMatrix

func NewMatrix(v0, v1, v2 Vector) Matrix

NewMatrix return new Matrix based

func (Matrix) MulDirection

func (a Matrix) MulDirection(b Vector) Vector

MulDirection multiplies Matrix 'a' by a Vector 'b' It returns a normalized Vector

func (Matrix) Transpose

func (a Matrix) Transpose() Matrix

Transpose returns a transposed 3x3 Matrix

type Mesh

type Mesh struct {
	Name      string
	Triangles []Triangle
	Materials []*Material
}

Mesh describes a 3D object

func (*Mesh) ReadOBJ

func (m *Mesh) ReadOBJ(pathToFile string) error

ReadOBJ return Mesh object read from the OBJ file, based on pathToFile It needs a Material slice in order to add material to each triangle in the mesh

func (*Mesh) ReadPLY

func (m *Mesh) ReadPLY(pathToFile string) error

ReadPLY adds to Mesh object vertex color values read from the PLY file, based on pathToFile

func (*Mesh) ReadTexturesToMaterials added in v1.1.0

func (m *Mesh) ReadTexturesToMaterials(readID bool) error

ReadTexturesToMaterials read textures data into each material Texture names are based on material name

func (Mesh) String

func (m Mesh) String() string

String implements Stringer interface. It displays information about each triangle in the mesh

type Ray

type Ray struct {
	Origin, Direction  Vector
	Distance           float64
	MaxFrontalDistance float64
	MaxRearDistance    float64
}

Ray describes a 3-dimensional ray with an origin and a direction Vector It also contains two distance values, used to checks intersection with multiple surfaces

func (Ray) HitPosition

func (r Ray) HitPosition() Vector

HitPosition return 3D coordinates of a ray intersetion

type Scene

type Scene struct {
	Lowpoly      Mesh
	Highpoly     Mesh
	BakedDiffuse *Texture
	//BakedNormal       *Texture
	//BakedObjectNormal *Texture
	BakedID            *Texture
	OutputSize         int
	ReadID             bool
	MaxFrontalDistance float64
	MaxRearDistance    float64
}

Scene represents an object in which baking process is being handled It cointais a lowpoly and highpoly meshes and output textures with their final size

func NewScene

func NewScene(s int, readID bool, MaxFrontalDistance, MaxRearDistance float64) Scene

NewScene return a new Scene with output textures of a given size 's'

func (*Scene) Bake

func (s *Scene) Bake(workers int)

Bake processes each pixel of an output texture it computes each texture in one process\

func (*Scene) ReadTexturesForHighpoly added in v1.1.0

func (s *Scene) ReadTexturesForHighpoly() (err error)

ReadTexturesForHighpoly read textures into highpoly model

type Texture

type Texture struct {
	Image *image.NRGBA
	// contains filtered or unexported fields
}

Texture defines image texture

func LoadTexture

func LoadTexture(pathToFile string) (*Texture, error)

LoadTexture loads texture object from png or jpg file with name 'n'

func NewTexture

func NewTexture(size int) *Texture

NewTexture creates new texture with set size

func (*Texture) SamplePixel

func (t *Texture) SamplePixel(u, v float64) color.NRGBA

SamplePixel return color of a pixel in u and v coordinates on image

func (*Texture) SaveImage

func (t *Texture) SaveImage(dir, f string) error

SaveImage saves Texture's image with a given name 'n'

type Triangle

type Triangle struct {
	V0, V1, V2 Vertex // Each triangle vertex
	Tangent    Vector
	Bitangent  Vector
	Normal     Vector
	Bar        Vector // Baricentric coordinates from intersection with a ray
	Material   *Material
	Distance   float64
	// contains filtered or unexported fields
}

Triangle describes single triangle of a 3D mesh

func (Triangle) Barycentric

func (t Triangle) Barycentric(u, v float64) Vector

Barycentric return barycentric coorditnates based on UV position of a triangle.

func (*Triangle) Intersect

func (t *Triangle) Intersect(r *Ray) bool

Intersect checks if ray intersects with a triangle

func (Triangle) String

func (t Triangle) String() string

String implements Stringer interface. It displays each triangle Vertex, Texture and Normals Vectors

type Vector

type Vector struct {
	X, Y, Z float64
}

Vector defines 3 point or axis with X,Y,Z values

func Barycentric

func Barycentric(a, b, c, l Vector) Vector

Barycentric performs a barycentric interpolation between 3 Vectors 'a', 'b' and 'c' based on values of a Vector 'l'.

func ColorToFloat

func ColorToFloat(r, g, b uint8) Vector

ColorToFloat converts uint8 values into 0.0-1.0 number in Vector format.

func ParseVector

func ParseVector(stringX, stringY, stringZ string) (v Vector, err error)

ParseVector parses 3 string values into a Vector.

func ParseVectorFromString

func ParseVectorFromString(s string) (v Vector, err error)

ParseVectorFromString parses string values seperated with comma into a Vector.

func (Vector) Abs

func (a Vector) Abs() Vector

Abs negates each Vectors component if it's lower then zero.

func (Vector) Add

func (a Vector) Add(b Vector) Vector

Add adds two Vectors together

func (Vector) CompareVectors

func (a Vector) CompareVectors(b Vector, tolerance float64) bool

CompareVectors compares 2 vectors values with given tolerance

func (Vector) Cross

func (a Vector) Cross(b Vector) Vector

Cross returns the cross product of two Vectors.

func (Vector) Div

func (a Vector) Div(b float64) Vector

Div divides Vector by scalar

func (Vector) DivVec

func (a Vector) DivVec(b Vector) Vector

DivVec divides each Vector value by corresponding value from second Vector

func (Vector) Dot

func (a Vector) Dot(b Vector) float64

Dot returns the dot product of two Vector's.

func (Vector) Equals

func (a Vector) Equals(b Vector) bool

Equals compares two Vectors.

func (Vector) FloatToColor

func (a Vector) FloatToColor() color.NRGBA

FloatToColor converts 0.0-1.0 number into color.NRGBA format.

func (Vector) Len

func (a Vector) Len() float64

Len finds the length of the Vector.

func (Vector) Lerp

func (a Vector) Lerp(b Vector, n float64) Vector

Lerp interpolates each Vector's value with another Vector, scaling it by n.

func (Vector) Mul

func (a Vector) Mul(n float64) Vector

Mul multiplies Vector by a scalar

func (Vector) MulVec

func (a Vector) MulVec(b Vector) Vector

MulVec multiplies Vector by a Vector

func (Vector) Negate

func (a Vector) Negate() Vector

Negate returns negated Vector.

func (Vector) Normalize

func (a Vector) Normalize() Vector

Normalize return Normalize current Vector.

func (Vector) Square

func (a Vector) Square() Vector

Square returns new Vector with each values squared.

func (Vector) String

func (a Vector) String() string

String implements Stringer interface. It displays each Vector components value seperated with a comma.

func (Vector) Sub

func (a Vector) Sub(b Vector) Vector

Sub subtracts set Vector from current one

type Vertex

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

Vertex desribes a 3D mesh vertex

func (*Vertex) SetVertexAlpha

func (v *Vertex) SetVertexAlpha(vAlpha float64)

SetVertexAlpha set vertex alpha color

Jump to

Keyboard shortcuts

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