obj

package
v1.3.25 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2023 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Overview

Package obj is used to parse the Wavefront OBJ file format (*.obj), including associated materials (*.mtl). Not all features of the OBJ format are supported. Basic format info: https://en.wikipedia.org/wiki/Wavefront_.obj_file

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Decoder

type Decoder struct {
	Objfile   string               // .obj filename (without path)
	Objdir    string               // path to .obj file
	Objects   []Object             // decoded objects
	Matlib    string               // name of the material lib
	Materials map[string]*Material // maps material name to object
	Vertices  mat32.ArrayF32       // vertices positions array
	Normals   mat32.ArrayF32       // vertices normals
	Uvs       mat32.ArrayF32       // vertices texture coordinates
	Warnings  []string             // warning messages
	// contains filtered or unexported fields
}

Decoder contains all decoded data from the obj and mtl files. It also implements the gi3d.Decoder interface and an instance is registered to handle .obj files.

func (*Decoder) Decode

func (dec *Decoder) Decode(rs []io.Reader) error

Decode reads the given data and decodes into Decoder tmp vars. if 2 args are passed, first is .obj and second is .mtl

func (*Decoder) Desc

func (dec *Decoder) Desc() string

func (*Decoder) Destroy added in v1.0.11

func (dec *Decoder) Destroy()

Destroy deletes data created during loading

func (*Decoder) HasScene

func (dec *Decoder) HasScene() bool

func (*Decoder) New

func (dec *Decoder) New() gi3d.Decoder

func (*Decoder) SetFile

func (dec *Decoder) SetFile(fname string) []string

func (*Decoder) SetGroup

func (dec *Decoder) SetGroup(sc *gi3d.Scene, gp *gi3d.Group)

SetGroup sets group with with all the decoded objects. calls Destroy after to free memory

func (*Decoder) SetMat

func (dec *Decoder) SetMat(sc *gi3d.Scene, sld *gi3d.Solid, matnm string)

SetMat sets the material for object

func (*Decoder) SetObject

func (dec *Decoder) SetObject(sc *gi3d.Scene, objgp *gi3d.Group, ob *Object)

SetObject sets the object as a group with each gi3d.Solid as a mesh with unique material

func (*Decoder) SetScene

func (dec *Decoder) SetScene(sc *gi3d.Scene)

SetScene sets group with with all the decoded objects.

type Face

type Face struct {
	Vertices []int  // Indices to the face vertices
	Uvs      []int  // Indices to the face UV coordinates
	Normals  []int  // Indices to the face normals
	Material string // Material name
	Smooth   bool   // Smooth face
}

Face contains all information about an object face

func (*Face) Destroy added in v1.0.11

func (fc *Face) Destroy()

type Material

type Material struct {
	Name       string      // Material name
	Illum      int         // Illumination model
	Opacity    float32     // Opacity factor
	Refraction float32     // Refraction factor
	Shininess  float32     // Shininess (specular exponent)
	Ambient    gist.Color  // Ambient color reflectivity
	Diffuse    gist.Color  // Diffuse color reflectivity
	Specular   gist.Color  // Specular color reflectivity
	Emissive   gist.Color  // Emissive color
	MapKd      string      // Texture file linked to diffuse color
	Tiling     gi3d.Tiling // Tiling parameters: repeat and offset
}

Material contains all information about an object material

type Object

type Object struct {
	Name  string // Object name
	Faces []Face // Faces
	// contains filtered or unexported fields
}

Object contains all information about one decoded object

func (*Object) Destroy added in v1.0.11

func (ob *Object) Destroy()

Jump to

Keyboard shortcuts

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