mtl

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: 4 Imported by: 3

Documentation

Overview

Package mtl provides APIs through which one can parse Wavefront MTL resources. The MTL file format is quite common and is used to store material data for OBJ 3D models.

The parsers provided by this library do not support the full MTL 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

This section is empty.

Types

type DecodeLimits

type DecodeLimits struct {

	// MaxMaterialCount specifies the maximum number of
	// material declarations that can be parsed.
	MaxMaterialCount int
}

DecodeLimits specifies restrictions on parsing.

One will generally use this to limit the number of data that is parsed in order to prevent out of memory errors

func DefaultLimits

func DefaultLimits() DecodeLimits

DefaultLimits returns some default DecodeLimits. Users can take the result and modify specific parameters.

type Decoder

type Decoder interface {

	// Decode decodes the MTL Wavefront resource, specified
	// through the io.Reader, into a Library model.
	//
	// If decoding fails for some reason, an error is returned.
	Decode(io.Reader) (*Library, error)
}

Decoder is an API that allows one to decode MTL Wavefront resources into an object model.

func NewDecoder

func NewDecoder(limits DecodeLimits) Decoder

NewDecoder creates a new Decoder instance with the specified DecodeLimits.

type Library

type Library struct {

	// Materials contains a list of all the materials that
	// were defined in the given library.
	Materials []*Material
}

Library represents a material library.

A material library can be though of as a single MTL resource which can contain information on multiple materials.

func (*Library) FindMaterial

func (l *Library) FindMaterial(name string) (*Material, bool)

FindMaterial finds a material in the given Library with the specified name or returns false, otherwise.

type Material

type Material struct {

	// Name holds the name of this material.
	Name string

	// AmbientColor holds the ambient color to be used
	// when rendering objects.
	AmbientColor RGBColor

	// DiffuseColor holds the diffuse color to be used
	// when rendering objects.
	DiffuseColor RGBColor

	// SpecularColor holds the specular color to be used
	// when rendering objects.
	SpecularColor RGBColor

	// EmissiveColor holds the emissive color to be used
	// when rendering objects.
	EmissiveColor RGBColor

	// TransmissionFilter holds the filter to be used on
	// colors when rendering objects.
	TransmissionFilter RGBColor

	// SpecularExponent defines the specular exponent for
	// this material.
	//
	// The specular exponent defines the sharpness of the
	// specular reflection. The value will generally range
	// between 0.0 (sharp) and 1000.0 (soft).
	SpecularExponent float64

	// Dissolve defines the dissolve for this material.
	//
	// Dissolve indicates how much an object should blend.
	// The value should range between 0.0 (fully transparent)
	// and 1.0 (opaque).
	Dissolve float64

	// Illumination defines the illumination model to be used when
	// rendering objects.
	//
	// The value ranges between 0 and 10.
	//
	// 	0. Color on and Ambient off
	// 	1. Color on and Ambient on
	// 	2. Highlight on
	// 	3. Reflection on and Ray trace on
	// 	4. Transparency: Glass on, Reflection: Ray trace on
	// 	5. Reflection: Fresnel on and Ray trace on
	//	6. Transparency: Refraction on, Reflection: Fresnel off and Ray trace on
	//	7. Transparency: Refraction on, Reflection: Fresnel on and Ray trace on
	//	8. Reflection on and Ray trace off
	//	9. Transparency: Glass on, Reflection: Ray trace off
	//	10. Casts shadows onto invisible surfaces
	Illumination int64

	// AmbientTexture defines the location of the ambient
	// texture to be used when rendering objects.
	//
	// If this value is the empty string, then there is no
	// ambient texture provided.
	AmbientTexture string

	// DiffuseTexture defines the location of the diffuse
	// texture to be used when rendering objects.
	//
	// If this value is the empty string, then there is no
	// diffuse texture provided.
	DiffuseTexture string

	// SpecularTexture defines the location of the specular
	// texture to be used when rendering objects.
	//
	// If this value is the empty string, then there is no
	// specular texture provided.
	SpecularTexture string

	// EmissiveTexture defines the location of the emissive
	// texture to be used when rendering objects.
	//
	// If this value is the empty string, then there is no
	// emissive texture provided.
	EmissiveTexture string

	// SpecularExponentTexture defines the location of the specular
	// exponent texture to be used when rendering objects.
	//
	// If this value is the empty string, then there is no
	// specular exponent texture provided.
	SpecularExponentTexture string

	// DissolveTexture defines the location of the dissolve
	// texture to be used when rendering objects.
	//
	// If this value is the empty string, then there is no
	// dissolve texture provided.
	DissolveTexture string

	// BumpTexture defines the location of the bump
	// texture to be used when rendering objects.
	//
	// If this value is the empty string, then there is no
	// Bump texture provided.
	BumpTexture string
}

Material represents a material in a MTL wavefront resource.

Materials define how objects should be rendered.

func DefaultMaterial

func DefaultMaterial() *Material

DefaultMaterial returns a new Material which is initialized with some proper default values

type RGBColor

type RGBColor struct {

	// Specifies the amount of Red in this color. Usually in the
	// range 0.0 to 1.0.
	R float64

	// Specifies the amount of Green in this color. Usually in the
	// range 0.0 to 1.0.
	G float64

	// Specifies the amount of Blue in this color. Usually in the
	// range 0.0 to 1.0.
	B float64
}

RGBColor represents a color represented by the three basic colors - Red, Green, and Blue

Jump to

Keyboard shortcuts

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