gwob: github.com/udhos/gwob Index | Files | Directories

package gwob

import "github.com/udhos/gwob"

Package gwob is a pure Go parser for Wavefront .OBJ 3D geometry file format.

Example:

// Error handling omitted for simplicity.

import "github.com/udhos/gwob"

inputObj, errOpen := os.Open("gopher.obj") // OBJ file

options := &gwob.ObjParserOptions{} // parser options

o, errObj := gwob.NewObjFromReader(fileObj, inputObj, options) // parse

// Scan OBJ groups
for _, g := range o.Groups {
    // snip
}

See also: https://github.com/udhos/gwob

Index

Package Files

obj.go parser.go

Constants

const (
    ErrFatal    = true  // ErrFatal means fatal stream error
    ErrNonFatal = false // ErrNonFatal means non-fatal parsing error
)

Internal parsing error

type Group Uses

type Group struct {
    Name       string
    Smooth     int
    Usemtl     string
    IndexBegin int
    IndexCount int
}

Group holds parser result for a group.

type Material Uses

type Material struct {
    Name  string
    MapKd string
    Kd    [3]float32
}

Material holds information for a material.

type MaterialLib Uses

type MaterialLib struct {
    Lib map[string]*Material
}

MaterialLib stores materials.

func NewMaterialLib Uses

func NewMaterialLib() MaterialLib

NewMaterialLib creates a new material lib.

func ReadMaterialLibFromBuf Uses

func ReadMaterialLibFromBuf(buf []byte, options *ObjParserOptions) (MaterialLib, error)

ReadMaterialLibFromBuf parses material lib from a buffer.

func ReadMaterialLibFromReader Uses

func ReadMaterialLibFromReader(rd io.Reader, options *ObjParserOptions) (MaterialLib, error)

ReadMaterialLibFromReader parses material lib from a reader.

func ReadMaterialLibFromStringReader Uses

func ReadMaterialLibFromStringReader(rd StringReader, options *ObjParserOptions) (MaterialLib, error)

ReadMaterialLibFromStringReader parses material lib from StringReader.

type Obj Uses

type Obj struct {
    Indices []int
    Coord   []float32 // vertex data pos=(x,y,z) tex=(tx,ty) norm=(nx,ny,nz)
    Mtllib  string
    Groups  []*Group

    BigIndexFound  bool // index larger than 65535
    TextCoordFound bool // texture coord
    NormCoordFound bool // normal coord

    StrideSize           int // (px,py,pz),(tu,tv),(nx,ny,nz) = 8 x 4-byte floats = 32 bytes max
    StrideOffsetPosition int // 0
    StrideOffsetTexture  int // 3 x 4-byte floats
    StrideOffsetNormal   int // 5 x 4-byte floats
}

Obj holds parser result for .obj file.

func NewObjFromBuf Uses

func NewObjFromBuf(objName string, buf []byte, options *ObjParserOptions) (*Obj, error)

NewObjFromBuf parses Obj from a buffer.

func NewObjFromReader Uses

func NewObjFromReader(objName string, rd io.Reader, options *ObjParserOptions) (*Obj, error)

NewObjFromReader parses Obj from a reader.

func NewObjFromStringReader Uses

func NewObjFromStringReader(objName string, rd StringReader, options *ObjParserOptions) (*Obj, error)

NewObjFromStringReader parses Obj from a StringReader.

func NewObjFromVertex Uses

func NewObjFromVertex(objName string, coord []float32, indices []int) (*Obj, error)

NewObjFromVertex creates Obj from vertex data.

func (*Obj) Coord64 Uses

func (o *Obj) Coord64(i int) float64

Coord64 gets vertex data as float64.

func (*Obj) NumberOfElements Uses

func (o *Obj) NumberOfElements() int

NumberOfElements gets the number of strides.

func (*Obj) VertexCoordinates Uses

func (o *Obj) VertexCoordinates(stride int) (float32, float32, float32)

VertexCoordinates gets vertex coordinates for a stride index.

type ObjParserOptions Uses

type ObjParserOptions struct {
    LogStats      bool
    Logger        func(string)
    IgnoreNormals bool
}

ObjParserOptions sets options for the parser.

type StringReader Uses

type StringReader interface {
    ReadString(delim byte) (string, error) // Example: bufio.Reader
}

StringReader is input for the parser.

Directories

PathSynopsis
examplePackage main shows how to use the 'gwob' package to parse geometry data from OBJ files.

Package gwob imports 8 packages (graph) and is imported by 1 packages. Updated 2019-04-08. Refresh now. Tools for package owners.