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:



This section is empty.


This section is empty.


This section is empty.


type Decoder

type Decoder struct {
	Objects   []Object             // decoded objects
	Matlib    string               // name of the material lib
	Materials map[string]*Material // maps material name to object
	Vertices  math32.ArrayF32      // vertices positions array
	Normals   math32.ArrayF32      // vertices normals
	Uvs       math32.ArrayF32      // vertices texture coordinates
	Warnings  []string             // warning messages
	// contains filtered or unexported fields

Decoder contains all decoded data from the obj and mtl files

func Decode

func Decode(objpath string, mtlpath string) (*Decoder, error)

Decode decodes the specified obj and mtl files returning a decoder object and an error. Passing an empty string (or otherwise invalid path) to mtlpath will cause the decoder to check the 'mtllib' file in the OBJ if present, and fall back to a default material as a last resort.

func DecodeReader

func DecodeReader(objreader, mtlreader io.Reader) (*Decoder, error)

DecodeReader decodes the specified obj and mtl readers returning a decoder object and an error if a problem was encoutered while parsing the OBJ.

Pass a valid io.Reader to override the materials defined in the OBJ file, or `nil` to use the materials listed in the OBJ's "mtllib" line (if present), a ".mtl" file with the same name as the OBJ file if presemt, or a default material as a last resort. No error will be returned for problems with materials--a gray default material will be used if nothing else works.

func (*Decoder) NewGeometry

func (dec *Decoder) NewGeometry(obj *Object) (*geometry.Geometry, error)

NewGeometry generates and returns a geometry from the specified object

func (*Decoder) NewGroup

func (dec *Decoder) NewGroup() (*core.Node, error)

NewGroup creates and returns a group containing as children meshes with all the decoded objects. A group is returned even if there is only one object decoded.

func (*Decoder) NewMesh

func (dec *Decoder) NewMesh(obj *Object) (*graphic.Mesh, error)

NewMesh creates and returns a mesh from an specified decoded object.

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

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    math32.Color // Ambient color reflectivity
	Diffuse    math32.Color // Diffuse color reflectivity
	Specular   math32.Color // Specular color reflectivity
	Emissive   math32.Color // Emissive color
	MapKd      string       // Texture file linked to diffuse color

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

Source Files