obj

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: Apache-2.0 Imports: 3 Imported by: 4

Documentation

Overview

Package obj provides APIs through which one can parse Wavefront OBJ resources. The OBJ file format is quite common and is used to store 3D model data.

The parsers provided by this library do not support the full OBJ spec, which is quite lengthy, but rather only the most essential and common features.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewScanner

func NewScanner() common.Scanner

NewScanner creates a new Scanner object that can scan through Wavefront OBJ resources.

Types

type FaceEndEvent

type FaceEndEvent struct {
}

FaceEndEvent indicates that the scanning of the face declaration has completed.

type FaceStartEvent

type FaceStartEvent struct {
}

FaceStartEvent indicates that a face declaration (`f`) is being scanned.

Events that follow will concern that specific face up until the point a FaceEndEvent is thrown.

type MaterialLibraryEvent

type MaterialLibraryEvent struct {

	// FilePath holds the file location of the material library.
	FilePath string
}

MaterialLibraryEvent indicates that a material library (MTL resource) dependency declaration (`mtllib`) has been scanned.

type MaterialReferenceEvent

type MaterialReferenceEvent struct {

	// MaterialName holds the name of the material that should be
	// used for the rendering of entities that follow.
	MaterialName string
}

MaterialReferenceEvent indicates that a material reference declaration (`usemtl`) has been scanned.

type NormalEvent

type NormalEvent struct {

	// X defines the X coordinate of this normal.
	X float64

	// Y defines the Y coordinate of this normal.
	Y float64

	// Z defines the Z coordinate of this normal.
	Z float64
}

NormalEvent indicates that a normal declaration (`vn`) has been scanned.

type NormalReferenceEvent

type NormalReferenceEvent struct {

	// NormalIndex holds the index of the normal that is referenced.
	NormalIndex int64
}

NormalReferenceEvent indicates that a normal reference has been scanned.

type ObjectEvent

type ObjectEvent struct {

	// ObjectName holds the name of the declared object
	ObjectName string
}

ObjectEvent indicates that an object declaration (`o`) has been scanned.

type ReferenceSetEndEvent

type ReferenceSetEndEvent struct {
}

ReferenceSetEndEvent indicates that the scanning of the reference set has completed.

type ReferenceSetStartEvent

type ReferenceSetStartEvent struct {
}

ReferenceSetStartEvent indicates that a reference set (e.g. 1/2/3) is being parsed as part of face scanning.

Events that follow will contain reference data, until a ReferenceSetEndEvent is received.

type TexCoordEvent

type TexCoordEvent struct {

	// U defines the U coordinate of this vertex.
	U float64

	// V defines the V coordinate of this vertex.
	V float64

	// W defines the W coordinate of this vertex.
	W float64
}

TexCoordEvent indicates that a texture coordinate declaration (`vt`) has been scanned.

This event combines 1D, 2D, and 3D coordinate declarations. If the original declaration did not specify one of the dimensions then it will be automatically defaulted to 0.0.

You can make a good guess on what the original dimension was by evaluating the material that is used with the texture coordinates.

Another option is to check all the texture coordinates for a given objet. If they all have their last components defaulted, then its likely the coordinates were of lower dimension. (e.g. all texture coordinates have their W equal to 0.0 which would mean a 2D texture coordinate set)

type TexCoordReferenceEvent

type TexCoordReferenceEvent struct {

	// TexCoordIndex holds the index of the texture coordinate that
	// is referenced.
	TexCoordIndex int64
}

TexCoordReferenceEvent indicates that a texture coordinate reference has been scanned.

type VertexEvent

type VertexEvent struct {

	// X defines the X coordinate of this vertex.
	X float64

	// Y defines the Y coordinate of this vertex.
	Y float64

	// Z defines the Z coordinate of this vertex.
	Z float64

	// W defines the W coordinate of this vertex.
	W float64
}

VertexEvent indicates that a vertex declaration (`v`) has been scanned.

This event combines 1D, 2D, 3D, and 4D vertex declarations. If the original declaration did not specify one of the dimensions then it will be automatically defaulted by the parser (all to 0.0 except for W which will default to 1.0)

In general you should know the dimension of the entity that you are parsing. If not, you can always check whether all the vertices for a given object have the same dimension (e.g. all vertices have Z and W equal to 0.0 and 1.0 respectively which would mean 2D).

type VertexReferenceEvent

type VertexReferenceEvent struct {

	// VertexIndex holds the index of the vertex that is referenced
	VertexIndex int64
}

VertexReferenceEvent indicates that a vertex reference has been scanned.

Jump to

Keyboard shortcuts

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