wavefront

package
v0.0.0-...-d35cbbc Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2024 License: CC0-1.0 Imports: 14 Imported by: 0

Documentation

Overview

Package wavefront implements functions to parse Wavefront OBJ files and transform the data. This is not meant to be a fully compliant parser but rather something good enough that allows for easy use of triangle meshes.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnsupportedPolygonType = errors.New("unsupported polygon type")
	ErrInvalidFaceData        = errors.New("invalid face data")
)

Functions

This section is empty.

Types

type Face

type Face struct {
	Vertices []*VertexIndices
}

Face represents a single face.

type Group

type Group struct {
	Name     string
	FaceType ObjFaceType
	Material string
	Faces    []*Face
}

Group represents a single group.

type Material

type Material struct {
	Name      string
	Kd        []float64
	Ka        []float64
	Ks        []float64
	Ns        float64
	Ni        float64
	Sharpness int64
	D         float64
	Illum     int64
}

Material represents a material defined in a .mtl file.

type ObjFaceType

type ObjFaceType int
const (
	OBJ_FACE_TYPE_INVALID ObjFaceType = iota
	OBJ_FACE_TYPE_POLYGON
)

type ParseOption

type ParseOption int
const (
	INVALID_OPTION ParseOption = iota
	IGNORE_NORMALS
	IGNORE_MATERIALS
	IGNORE_TEXTURES
)

type VertexIndices

type VertexIndices struct {
	VIdx  int64
	VtIdx int64
	VnIdx int64
}

VertexIndices represents the indices used by a vertex.

type WavefrontObj

type WavefrontObj struct {
	IgnoreMaterials bool
	IgnoreNormals   bool
	IgnoreTextures  bool
	HasNormals      bool
	HasUV           bool
	Centre          *vec3.Vec3Impl
	ObjectName      string
	Vertices        []*vec3.Vec3Impl
	VertexNormals   []*vec3.Vec3Impl
	VertexUV        []*texture.UV
	MtlLib          map[string]*Material
	Groups          []*Group
}

WavefrontObj represents the data contained in a Wavefront OBJ file.

func NewObjFromReader

func NewObjFromReader(r io.Reader, containerDirectory string, opts ...ParseOption) (*WavefrontObj, error)

NewObjFromReader returns WavefrontObj with the geometry contained in a Wavefront .obj file.

func (*WavefrontObj) GroupToHitablesWithCustomMaterial

func (wo *WavefrontObj) GroupToHitablesWithCustomMaterial(index int, mat material.Material) ([]hitable.Hitable, error)

GroupToHitablesWithCustomMaterial returns a slice of hitables with the supplied material.

func (*WavefrontObj) GroupToHitablesWithCustomMaterialAndDisplacement

func (wo *WavefrontObj) GroupToHitablesWithCustomMaterialAndDisplacement(index int, mat material.Material, displacementMap texture.Texture, min, max float64) ([]hitable.Hitable, error)

GroupToHitablesWithCustomMaterialAndDisplacement returns a slice of displaced hitables with the supplied material.

func (*WavefrontObj) NumGroups

func (wo *WavefrontObj) NumGroups() int

func (*WavefrontObj) Scale

func (wo *WavefrontObj) Scale(scale *vec3.Vec3Impl)

Scale scales all the vertices in this object by the specified amount.

func (*WavefrontObj) Translate

func (wo *WavefrontObj) Translate(translate *vec3.Vec3Impl)

Translate translates all the vertices in this object by the specified amount.

Jump to

Keyboard shortcuts

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