Documentation ¶
Overview ¶
Package common package provides utility APIs that are used by other (more specialized) packages (e.g. mtl and obj) in the go-data-front library.
Index ¶
- Variables
- type CommentEvent
- type Event
- type EventHandler
- type Line
- func (l Line) CommandName() string
- func (l Line) Comment() string
- func (l Line) FloatParam(index int) (float64, error)
- func (l Line) HasCommandName(name string) bool
- func (l Line) IntParam(index int) (int64, error)
- func (l Line) IsBlank() bool
- func (l Line) IsCommand() bool
- func (l Line) IsComment() bool
- func (l Line) ParamCount() int
- func (l Line) ReferenceSetParam(index int) ReferenceSet
- func (l Line) StringParam(index int) string
- type LineScanner
- type ReferenceSet
- type Scanner
Constants ¶
This section is empty.
Variables ¶
var ErrInvalid = errors.New("invalid construct")
ErrInvalid is returned when an invalid file construct is detected.
var ErrLimitsExceeded = errors.New("safety limits exceeded")
ErrLimitsExceeded is returned when the decoder has reached the maximum number of allowed resources to parse.
Functions ¶
This section is empty.
Types ¶
type CommentEvent ¶
type CommentEvent struct { // Comment holds the comment text that has been scanned. Comment string }
CommentEvent indicates that a comment section has been scanned through.
type Event ¶
type Event interface{}
Event represents an event that has occurred during scanning. This is the mechanism through which the Scanner API returns key MTL resource elements to the user.
This interface is subclassed and users should cast this interface to one of them in order to extract meaningful data.
Example event types:
- CommentEvent
- obj.ObjectEvent
- mtl.MaterialEvent
type EventHandler ¶
EventHandler function is passed to the Scanner by the API user in order to receive scanning events.
Implementations of this function should do a type switch on the event in order to determine the exact type and read meaningful data from it.
Implementations can return an error in order to stop any further processing of the Wavefront file.
type Line ¶
type Line struct {
// contains filtered or unexported fields
}
Line represents a single logical line in a Wavefront file. You should get a hold of such a structure through the use of the LineScanner API.
func (Line) CommandName ¶
CommandName returns the name of the command. One should first use the IsCommand method to assure that this logical line is indeed a command.
func (Line) Comment ¶
Comment returns the comment held by this logical line. One should first use IsComment to assure that this logical line is indeed a comment.
func (Line) FloatParam ¶
FloatParam returns the parameter, converted to a float, at the specified index
func (Line) HasCommandName ¶
HasCommandName checks whether the command held by this logical line has the specified name. One should first use IsCommand to assure that this logical line is indeed a command.
func (Line) IntParam ¶
IntParam returns the parameter, converted to an integer, at the specified index
func (Line) IsCommand ¶
IsCommand returns whether the current logical line represents a command (e.g. usemtl, mtllib, vn, etc.)
func (Line) ParamCount ¶
ParamCount returns the number of parameters provided with the current command. Parameters are indexed from `0` up to the number (excluding) returned by this function.
func (Line) ReferenceSetParam ¶
func (l Line) ReferenceSetParam(index int) ReferenceSet
ReferenceSetParam returns the parameter converted into a ReferenceSet
func (Line) StringParam ¶
StringParam returns the parameter, converted to a string, at the specified index
type LineScanner ¶
type LineScanner interface { // Scan scans the next logical line and returns whether that was successful. // A scan is not successful when the end of the file is reached or when an // error has occurred during scanning. Scan() bool // Err is used to get the scanning error, should one have actually occurred. // If `nil` is returned, then scanning was successful and one can proceed // and access the line through the Line method. Err() error // Line returns the last scanned logical line. Line() Line }
LineScanner is an API that allows one to scan Wavefront files one logical line at a time.
func NewLineScanner ¶
func NewLineScanner(reader io.Reader) LineScanner
NewLineScanner creates a new LineScanner instance that uses the specified io.Reader to read a Wavefront resource.
type ReferenceSet ¶
type ReferenceSet struct {
// contains filtered or unexported fields
}
ReferenceSet represents a set of references. This is represented in a Wavefront through a list of values separated by `/` symbols. It is possible to have blank references.
func (ReferenceSet) Count ¶
func (s ReferenceSet) Count() int
Count returns the number of references in this reference set
func (ReferenceSet) FloatReference ¶
func (s ReferenceSet) FloatReference(index int) (float64, error)
FloatReference returns the reference at the specified index location as float if possible to convert, otherwise it returns an error
func (ReferenceSet) IntReference ¶
func (s ReferenceSet) IntReference(index int) (int64, error)
IntReference returns the reference at the specified index location as int if possible to convert, otherwise it returns an error
func (ReferenceSet) IsBlank ¶
func (s ReferenceSet) IsBlank(index int) bool
IsBlank returns whether the reference at the specified index position is blank. (e.g. the reference at index 1 in a//c is blank)
func (ReferenceSet) StringReference ¶
func (s ReferenceSet) StringReference(index int) string
StringReference returns the reference at the specified index location as string
type Scanner ¶
type Scanner interface { // Scan performs a scan through the Wavefront resource that is // provided through the io.Reader. // // The EventHandler parameter is used by the implementation to // pass scanning events back to the user for processing. // // An error is returned should parsing fail for some reason or // if the user returns an error via the EventHandler. Scan(io.Reader, EventHandler) error }
Scanner represents an event-based parser for Wavefront resources.
Implementations of this interface would usually scan through the Wavefront resource and act on each special element that is detected (e.g. when a normal or material declaration is parsed)