gltf

package module
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2019 License: BSD-2-Clause Imports: 16 Imported by: 58

README

gltf

Documentation Build Status Go Report Card codecov codeclimate License Mentioned in Awesome Go

A Go package for simple, efficient, and robust serialization/deserialization of glTF 2.0 (GL Transmission Format), a royalty-free specification for the efficient transmission and loading of 3D scenes and models by applications.

Features

  • High parsing speed and moderate memory consumption
  • glTF specification v2.0.0
    • ASCII glTF
    • Binary glTF(GLB)
    • PBR material description
    • Modeler package
  • glTF validaton
    • Validate against schemas
    • Validate coherence
  • Buffers
    • Parse BASE64 encoded embedded buffer data(DataURI)
    • Load .bin file
    • Binary package
  • Read from io.Reader
    • Boilerplate for disk loading
    • Custom callback handlers
    • Automatic ASCII / glTF detection
  • Write to io.Writer
    • Boilerplate for disk saving
    • Custom callback handlers
    • ASCII / Binary
  • Extensions
    • KHR_draco_mesh_compression
    • KHR_lights_punctual
    • KHR_materials_pbrSpecularGlossiness
    • KHR_materials_unlit
    • KHR_techniques_webgl
    • KHR_texture_transform
    • Support custom extensions

Extensions

This module is designed to support dynamic extensions. By default only the core specification is decoded and the data inside the extensions objects are stored as json.RawMessage so they can be decoded outside this package or automatically encoded when saving the document.

To decode one of the supported extensions the only required action is to import the associated package, this way the extension will not be stored as json.RawMessage but as the type defined in the extension package:

import (
  "github.com/qmuntal/gltf"
  "github.com/qmuntal/gltf/ext/lightspuntual"
)

func ExampleExension() {
  doc, _ := gltf.Open("...")
  if v, ok := doc.Extensions[lightspuntual.ExtensionName]; ok {
      for _, l := range v.(lightspuntual.Lights) {
          fmt.Print(l.Type)
      }
  }
}

It is not necessary to call gltf.RegisterExtension for built-in extensions, as these auto-register themselves on init().

Perfomance

All the functionality is benchmarked and tested using the official glTF Samples in the utility package qmuntal/gltf-bench. The results show that the perfomance of this package is equivalent to fx-gltf, a reference perfomance-driven glTF implementation for C++, .

Examples

Read
doc, err := gltf.Open("./a.gltf")
if err != nil {
  panic(err)
}
fmt.Print(doc.Asset)
Create a glb using gltf/modeler
package main

import (
 "github.com/qmuntal/gltf"
 "github.com/qmuntal/gltf/modeler"
)

func main() {
  m := modeler.NewModeler()
  positionAccessor := m.AddPosition(0, [][3]float32{{43, 43, 0}, {83, 43, 0}, {63, 63, 40}, {43, 83, 0}, {83, 83, 0}})
  indicesAccessor := m.AddIndices(0, []uint8{0, 1, 2, 3, 1, 0, 0, 2, 3, 1, 4, 2, 4, 3, 2, 4, 1, 3})
  colorIndices := m.AddColor(0, [][3]uint8{{50, 155, 255}, {0, 100, 200}, {255, 155, 50}, {155, 155, 155}, {25, 25, 25}})
  m.Document.Meshes = []gltf.Mesh{{
    Name: "Pyramid",
    Primitives: []gltf.Primitive{
      {
        Indices: gltf.Index(indicesAccessor),
        Attributes: map[string]uint32{
          "POSITION": positionAccessor,
          "COLOR_0":  colorIndices,
        },
      },
    },
  }}
  m.Nodes = []gltf.Node{{Name: "Root", Mesh: gltf.Index(0)}}
  m.Scenes[0].Nodes = append(m.Scenes[0].Nodes, 0)
  if err := gltf.SaveBinary(m.Document, "./example.glb"); err != nil {
    panic(err)
  }
}
Create a glb using raw data

The following example generates a 3D box with colors per vertex.

screenshot


package main

import (
    "github.com/qmuntal/gltf"
)

func main() {
    doc := &gltf.Document{
        Accessors: []gltf.Accessor{
            {BufferView: gltf.Index(0), ComponentType: gltf.UnsignedShort, Count: 36, Type: gltf.Scalar},
            {BufferView: gltf.Index(1), ComponentType: gltf.Float, Count: 24, Max: []float64{0.5, 0.5, 0.5}, Min: []float64{-0.5, -0.            -0.5}, Type: gltf.Vec3},
            {BufferView: gltf.Index(2), ComponentType: gltf.Float, Count: 24, Type: gltf.Vec3},
            {BufferView: gltf.Index(3), ComponentType: gltf.Float, Count: 24, Type: gltf.Vec4},
            {BufferView: gltf.Index(4), ComponentType: gltf.Float, Count: 24, Type: gltf.Vec2},
        },
        Asset: gltf.Asset{Version: "2.0", Generator: "FBX2glTF"},
        BufferViews: []gltf.BufferView{
            {Buffer: 0, ByteLength: 72, ByteOffset: 0, Target: gltf.ElementArrayBuffer},
            {Buffer: 0, ByteLength: 288, ByteOffset: 72, Target: gltf.ArrayBuffer},
            {Buffer: 0, ByteLength: 288, ByteOffset: 360, Target: gltf.ArrayBuffer},
            {Buffer: 0, ByteLength: 384, ByteOffset: 648, Target: gltf.ArrayBuffer},
            {Buffer: 0, ByteLength: 192, ByteOffset: 1032, Target: gltf.ArrayBuffer},
        },
        Buffers: []gltf.Buffer{{ByteLength: 1224, URI: bufferData}},
        Materials: []gltf.Material{{
            Name: "Default", AlphaMode: gltf.Opaque, AlphaCutoff: gltf.Float64(0.5),
            PBRMetallicRoughness: &gltf.PBRMetallicRoughness{BaseColorFactor: &gltf.RGBA{R: 0.8, G: 0.8, B: 0.8, A: 1}, MetallicFactor: gltf.Float64(0.1), RoughnessFactor: gltf.Float64(0.99)},
        }},
        Meshes: []gltf.Mesh{{Name: "Cube", Primitives: []gltf.Primitive{{Indices: gltf.Index(0), Material: gltf.Index(0), Mode: gltf.Triangles, Attributes: map[string]uint32{"POSITION": 1, "COLOR_0": 3, "NORMAL": 2, "TEXCOORD_0": 4}}}}},
        Nodes: []gltf.Node{
            {Name: "RootNode", Children: []uint32{1, 2, 3}},
            {Name: "Mesh"},
            {Name: "Cube", Mesh: gltf.Index(0)},
            {Name: "Texture Group"},
        },
        Samplers: []gltf.Sampler{{WrapS: gltf.Repeat, WrapT: gltf.Repeat}},
        Scene:    gltf.Index(0),
        Scenes:   []gltf.Scene{{Name: "Root Scene", Nodes: []uint32{0}}},
    }
    if err := gltf.Save(doc, "./cube.gltf"); err != nil {
        panic(err)
    }
}

const bufferData = "data:application/octet-stream;base64,AAABAAIAAQAAAAMABAAFAAYABwAEAAYACAAJAAoACwAJAAgADAANAA4ADQAMAA8AEAARABIAEAASABMAFAAVABYAFAAWABcAAAAAvwAAAD8AAAC/AAAAPwAAAD8AAAA/AAAAPwAAAD8AAAC/AAAAvwAAAD8AAAA/AAAAvwAAAD8AAAA/AAAAvwAAAD8AAAC/AAAAvwAAAL8AAAC/AAAAvwAAAL8AAAA/AAAAPwAAAD8AAAA/AAAAvwAAAL8AAAA/AAAAPwAAAL8AAAA/AAAAvwAAAD8AAAA/AAAAPwAAAD8AAAC/AAAAPwAAAL8AAAA/AAAAPwAAAL8AAAC/AAAAPwAAAD8AAAA/AAAAPwAAAL8AAAC/AAAAvwAAAL8AAAC/AAAAvwAAAD8AAAC/AAAAPwAAAD8AAAC/AAAAPwAAAL8AAAA/AAAAvwAAAL8AAAA/AAAAvwAAAL8AAAC/AAAAPwAAAL8AAAC/AAAAAAAAgD8AAAAAAAAAAAAAgD8AAAAAAAAAAAAAgD8AAAAAAAAAAAAAgD8AAAAAAACAvwAAAAAAAAAAAACAvwAAAAAAAAAAAACAvwAAAAAAAAAAAACAvwAAAAAAAAAAAAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AACAPwAAAAAAAAAAAACAPwAAAAAAAAAAAACAPwAAAAAAAAAAAACAPwAAAAAAAAAAAAAAAAAAAAAAAIC/AAAAAAAAAAAAAIC/AAAAAAAAAAAAAIC/AAAAAAAAAAAAAIC/AAAAAAAAgL8AAAAAAAAAAAAAgL8AAAAAAAAAAAAAgL8AAAAAAAAAAAAAgL8AAAAAHekGMHp6JTz+/38/UdInMBHtfz9SNZs6rTHKPJsTwTrvy00/XMpNP0HLTT8AAIA/3ssCP4z/fz+gF+43whYUON7LAj+M/38/oBfuN8IWFDgd6QYwenolPP7/fz9R0icw6vR/PwjDNTqNSsY80xtiOu/LTT9cyk0/QctNPwAAgD8R7X8/UjWbOq0xyjybE8E678tNP1zKTT9By00/AACAP6bmIzurlgY+BNh/P0ziSzveywI/jP9/P6AX7jfCFhQ478tNP1zKTT9By00/AACAP6bmIzurlgY+BNh/P0ziSzsSAI885Oh+PxdguT574rE8Ee1/P1I1mzqtMco8mxPBOhIAjzzk6H4/F2C5PnvisTzq9H8/CMM1Oo1KxjzTG2I6HekGMHp6JTz+/38/UdInMO/LTT9cyk0/QctNPwAAgD+m5iM7q5YGPgTYfz9M4ks778tNP1zKTT9By00/AACAP+r0fz8IwzU6jUrGPNMbYjoSAI885Oh+PxdguT574rE8AACAPgAAAAAAAAA/qqqqPgAAAD8AAAAAAACAPqqqqj4AAIA+qqqqPgAAAACqqqo+AAAAAKqqKj8AAIA+qqoqPwAAAD+qqqo+AACAPqqqKj8AAAA/qqoqPwAAgD6qqqo+AABAP6qqqj4AAAA/qqoqPwAAQD+qqio/AAAAP6qqqj4AAEA/qqoqPwAAgD+qqio/AACAP6qqqj4AAEA/qqqqPgAAAD+qqio/AACAPqqqKj8AAIA+AACAPwAAAD8AAIA/"


Documentation

Overview

Package gltf implements a glTF 2.0 file decoder, encoder and validator.

The glTF 2.0 specification is at https://github.com/KhronosGroup/glTF/tree/master/specification/2.0/.

Optional Properties

All optional properties whose default value does not match with the golang type zero value are defines as pointers or as zero arrays.

Guidelines when working with optional values: It is safe to not define them when saving the glTF if the desired value is the default one. It is safe to expect that the optional values are not nil when opening a glTF. When quering values of optional properties that are not indices it is recommended to use the utility functions that returns the property as value if not nil or the default value if nil. When assigning values to optional properties one can use the utility functions that take the reference of basic types. Examples:

gltf.Index(1)
gltf.Float64(0.5)

Index

Examples

Constants

View Source
const (
	// None is used when the buffer should not bound to a target, for example when referenced by an sparce indices.
	None = 0
	// ArrayBuffer corresponds to an array buffer.
	ArrayBuffer Target = 34962
	// ElementArrayBuffer corresponds to an element array buffer.
	ElementArrayBuffer = 34963
)

Variables

View Source
var (
	// DefaultMatrix defines an identity matrix.
	DefaultMatrix = [16]float64{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}
	// DefaultRotation defines a quaternion without rotation.
	DefaultRotation = [4]float64{0, 0, 0, 1}
	// DefaultScale defines a scaling that does not modify the size of the object.
	DefaultScale = [3]float64{1, 1, 1}
	// DefaultTranslation defines a translation that does not move the object.
	DefaultTranslation = [3]float64{0, 0, 0}
)

Functions

func Float64 added in v0.8.0

func Float64(val float64) *float64

Float64 is an utility function that returns a pointer to a float64.

func Index added in v0.8.0

func Index(i uint32) *uint32

Index is an utility function that returns a pointer to a uint32.

func RegisterExtension added in v0.8.0

func RegisterExtension(key string, f func([]byte) (interface{}, error))

RegisterExtension registers a function that returns a new extension of the given byte array. This is intended to be called from the init function in packages that implement extensions.

func Save

func Save(doc *Document, name string) error

Save will save a document as a glTF with the specified by name.

Example
package main

import (
	"github.com/qmuntal/gltf"
)

func main() {
	doc := &gltf.Document{
		Accessors: []gltf.Accessor{
			{BufferView: gltf.Index(0), ComponentType: gltf.UnsignedShort, Count: 36, Type: gltf.Scalar},
			{BufferView: gltf.Index(1), ComponentType: gltf.Float, Count: 24, Max: []float64{0.5, 0.5, 0.5}, Min: []float64{-0.5, -0.5, -0.5}, Type: gltf.Vec3},
			{BufferView: gltf.Index(2), ComponentType: gltf.Float, Count: 24, Type: gltf.Vec3},
			{BufferView: gltf.Index(3), ComponentType: gltf.Float, Count: 24, Type: gltf.Vec4},
			{BufferView: gltf.Index(4), ComponentType: gltf.Float, Count: 24, Type: gltf.Vec2},
		},
		Asset: gltf.Asset{Version: "2.0", Generator: "FBX2glTF"},
		BufferViews: []gltf.BufferView{
			{Buffer: 0, ByteLength: 72, ByteOffset: 0, Target: gltf.ElementArrayBuffer},
			{Buffer: 0, ByteLength: 288, ByteOffset: 72, Target: gltf.ArrayBuffer},
			{Buffer: 0, ByteLength: 288, ByteOffset: 360, Target: gltf.ArrayBuffer},
			{Buffer: 0, ByteLength: 384, ByteOffset: 648, Target: gltf.ArrayBuffer},
			{Buffer: 0, ByteLength: 192, ByteOffset: 1032, Target: gltf.ArrayBuffer},
		},
		Buffers: []gltf.Buffer{{ByteLength: 1224, Data: []uint8{97, 110, 121, 32, 99, 97, 114, 110, 97, 108, 32, 112, 108, 101, 97, 115}}},
		Materials: []gltf.Material{{
			Name: "Default", AlphaMode: gltf.Opaque, AlphaCutoff: gltf.Float64(0.5),
			PBRMetallicRoughness: &gltf.PBRMetallicRoughness{BaseColorFactor: &gltf.RGBA{R: 0.8, G: 0.8, B: 0.8, A: 1}, MetallicFactor: gltf.Float64(0.1), RoughnessFactor: gltf.Float64(0.99)},
		}},
		Meshes: []gltf.Mesh{{Name: "Cube", Primitives: []gltf.Primitive{{Indices: gltf.Index(0), Material: gltf.Index(0), Mode: gltf.Triangles, Attributes: map[string]uint32{"POSITION": 1, "COLOR_0": 3, "NORMAL": 2, "TEXCOORD_0": 4}}}}},
		Nodes: []gltf.Node{
			{Name: "RootNode", Children: []uint32{1, 2, 3}},
			{Name: "Mesh"},
			{Name: "Cube", Mesh: gltf.Index(0)},
			{Name: "Texture Group"},
		},
		Samplers: []gltf.Sampler{{WrapS: gltf.Repeat, WrapT: gltf.Repeat}},
		Scene:    gltf.Index(0),
		Scenes:   []gltf.Scene{{Name: "Root Scene", Nodes: []uint32{0}}},
	}
	if err := gltf.SaveBinary(doc, "./example.glb"); err != nil {
		panic(err)
	}
}
Output:

func SaveBinary added in v0.9.0

func SaveBinary(doc *Document, name string) error

SaveBinary will save a document as a GLB file with the specified by name.

Types

type Accessor

type Accessor struct {
	Extensions    Extensions    `json:"extensions,omitempty"`
	Extras        interface{}   `json:"extras,omitempty"`
	Name          string        `json:"name,omitempty"`
	BufferView    *uint32       `json:"bufferView,omitempty"`
	ByteOffset    uint32        `json:"byteOffset,omitempty"`
	ComponentType ComponentType `json:"componentType" validate:"lte=5"`
	Normalized    bool          `json:"normalized,omitempty"`      // Specifies whether integer data values should be normalized.
	Count         uint32        `json:"count" validate:"required"` // The number of attributes referenced by this accessor.
	Type          AccessorType  `json:"type" validate:"lte=6"`
	Max           []float64     `json:"max,omitempty" validate:"omitempty,lte=16"` // Maximum value of each component in this attribute.
	Min           []float64     `json:"min,omitempty" validate:"omitempty,lte=16"` // Minimum value of each component in this attribute.
	Sparse        *Sparse       `json:"sparse,omitempty"`                          // Sparse storage of attributes that deviate from their initialization value.
}

An Accessor is a typed view into a bufferView. An accessor provides a typed view into a bufferView or a subset of a bufferView similar to how WebGL's vertexAttribPointer() defines an attribute in a buffer.

type AccessorType

type AccessorType uint8

AccessorType specifies if the attribute is a scalar, vector, or matrix.

const (
	// Scalar corresponds to a single dimension value.
	Scalar AccessorType = iota
	// Vec2 corresponds to a two dimensions array.
	Vec2
	// Vec3 corresponds to a three dimensions array.
	Vec3
	// Vec4 corresponds to a four dimensions array.
	Vec4
	// Mat2 corresponds to a 2x2 matrix.
	Mat2
	// Mat3 corresponds to a 3x3 matrix.
	Mat3
	// Mat4 corresponds to a 4x4 matrix.
	Mat4
)

func (*AccessorType) MarshalJSON added in v0.8.0

func (a *AccessorType) MarshalJSON() ([]byte, error)

MarshalJSON marshal the accessor type with the correct default values.

func (*AccessorType) UnmarshalJSON added in v0.8.0

func (a *AccessorType) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshal the accessor type with the correct default values.

type AlphaMode

type AlphaMode uint8

The AlphaMode enumeration specifying the interpretation of the alpha value of the main factor and texture.

const (
	// Opaque corresponds to an Opaque material.
	Opaque AlphaMode = iota
	// Mask corresponds to a masked material.
	Mask
	// Blend corresponds to a Blend material.
	Blend
)

func (*AlphaMode) MarshalJSON added in v0.8.0

func (a *AlphaMode) MarshalJSON() ([]byte, error)

MarshalJSON marshal the alpha mode with the correct default values.

func (*AlphaMode) UnmarshalJSON added in v0.8.0

func (a *AlphaMode) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshal the alpha mode with the correct default values.

type Animation

type Animation struct {
	Extensions Extensions         `json:"extensions,omitempty"`
	Extras     interface{}        `json:"extras,omitempty"`
	Name       string             `json:"name,omitempty"`
	Channels   []Channel          `json:"channels" validate:"required,gt=0,dive"`
	Samplers   []AnimationSampler `json:"samplers" validate:"required,gt=0,dive"`
}

An Animation keyframe.

type AnimationSampler

type AnimationSampler struct {
	Extensions    Extensions    `json:"extensions,omitempty"`
	Extras        interface{}   `json:"extras,omitempty"`
	Input         *uint32       `json:"input,omitempty"` // The index of an accessor containing keyframe input values.
	Interpolation Interpolation `json:"interpolation,omitempty" validate:"lte=2"`
	Output        *uint32       `json:"output,omitempty"` // The index of an accessor containing keyframe output values.
}

AnimationSampler combines input and output accessors with an interpolation algorithm to define a keyframe graph (but not its target).

type Asset

type Asset struct {
	Extensions Extensions  `json:"extensions,omitempty"`
	Extras     interface{} `json:"extras,omitempty"`
	Copyright  string      `json:"copyright,omitempty"`         // A copyright message suitable for display to credit the content creator.
	Generator  string      `json:"generator,omitempty"`         // Tool that generated this glTF model. Useful for debugging.
	Version    string      `json:"version" validate:"required"` // The glTF version that this asset targets.
	MinVersion string      `json:"minVersion,omitempty"`        // The minimum glTF version that this asset targets.
}

An Asset is metadata about the glTF asset.

type Attribute

type Attribute = map[string]uint32

Attribute is a map that each key corresponds to mesh attribute semantic and each value is the index of the accessor containing attribute's data.

type Buffer

type Buffer struct {
	Extensions Extensions  `json:"extensions,omitempty"`
	Extras     interface{} `json:"extras,omitempty"`
	Name       string      `json:"name,omitempty"`
	URI        string      `json:"uri,omitempty" validate:"omitempty"`
	ByteLength uint32      `json:"byteLength" validate:"required"`
	Data       []uint8     `json:"-"`
}

A Buffer points to binary geometry, animation, or skins. If Data length is 0 and the Buffer is an external resource the Data won't be flushed, which can be useful when there is no need to load data in memory.

func (*Buffer) EmbeddedResource

func (b *Buffer) EmbeddedResource()

EmbeddedResource defines the buffer as an embedded resource and encodes the URI so it points to the the resource.

func (*Buffer) IsEmbeddedResource

func (b *Buffer) IsEmbeddedResource() bool

IsEmbeddedResource returns true if the buffer points to an embedded resource.

type BufferView

type BufferView struct {
	Extensions Extensions  `json:"extensions,omitempty"`
	Extras     interface{} `json:"extras,omitempty"`
	Buffer     uint32      `json:"buffer"`
	ByteOffset uint32      `json:"byteOffset,omitempty"`
	ByteLength uint32      `json:"byteLength" validate:"required"`
	ByteStride uint32      `json:"byteStride,omitempty" validate:"omitempty,gte=4,lte=252"`
	Target     Target      `json:"target,omitempty" validate:"omitempty,oneof=34962 34963"`
}

BufferView is a view into a buffer generally representing a subset of the buffer.

type Camera

type Camera struct {
	Extensions   Extensions    `json:"extensions,omitempty"`
	Extras       interface{}   `json:"extras,omitempty"`
	Name         string        `json:"name,omitempty"`
	Orthographic *Orthographic `json:"orthographic,omitempty"`
	Perspective  *Perspective  `json:"perspective,omitempty"`
}

A Camera projection. A node can reference a camera to apply a transform to place the camera in the scene.

func (*Camera) MarshalJSON added in v0.8.0

func (c *Camera) MarshalJSON() ([]byte, error)

MarshalJSON marshal the camera with the correct default values.

type Channel

type Channel struct {
	Extensions Extensions    `json:"extensions,omitempty"`
	Extras     interface{}   `json:"extras,omitempty"`
	Sampler    *uint32       `json:"sampler,omitempty"`
	Target     ChannelTarget `json:"target"`
}

The Channel targets an animation's sampler at a node's property.

type ChannelTarget

type ChannelTarget struct {
	Extensions Extensions  `json:"extensions,omitempty"`
	Extras     interface{} `json:"extras,omitempty"`
	Node       *uint32     `json:"node,omitempty"`
	Path       TRSProperty `json:"path" validate:"lte=4"`
}

ChannelTarget describes the index of the node and TRS property that an animation channel targets. The Path represents the name of the node's TRS property to modify, or the "weights" of the Morph Targets it instantiates. For the "translation" property, the values that are provided by the sampler are the translation along the x, y, and z axes. For the "rotation" property, the values are a quaternion in the order (x, y, z, w), where w is the scalar. For the "scale" property, the values are the scaling factors along the x, y, and z axes.

type ComponentType

type ComponentType uint16

The ComponentType is the datatype of components in the attribute. All valid values correspond to WebGL enums. 5125 (UNSIGNED_INT) is only allowed when the accessor contains indices.

const (
	// Float corresponds to a Float32Array.
	Float ComponentType = iota
	// Byte corresponds to a Int8Array.
	Byte
	// UnsignedByte corresponds to a Uint8Array.
	UnsignedByte
	// Short corresponds to a Int16Array.
	Short
	// UnsignedShort corresponds to a Uint16Array.
	UnsignedShort
	// UnsignedInt corresponds to a Uint32Array.
	UnsignedInt
)

func (*ComponentType) MarshalJSON added in v0.8.0

func (c *ComponentType) MarshalJSON() ([]byte, error)

MarshalJSON marshal the component type with the correct default values.

func (*ComponentType) UnmarshalJSON added in v0.8.0

func (c *ComponentType) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshal the component type with the correct default values.

type Decoder

type Decoder struct {
	ReadHandler            ReadHandler
	MaxExternalBufferCount int
	MaxMemoryAllocation    int
	// contains filtered or unexported fields
}

A Decoder reads and decodes glTF and GLB values from an input stream. ReadHandler is called to read external resources.

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder returns a new decoder that reads from r with relative external buffers support.

func (*Decoder) Decode

func (d *Decoder) Decode(doc *Document) error

Decode reads the next JSON-encoded value from its input and stores it in the value pointed to by doc.

func (*Decoder) WithReadHandler added in v0.9.0

func (d *Decoder) WithReadHandler(h ReadHandler) *Decoder

WithReadHandler sets the ReadHandler.

type Document

type Document struct {
	Extensions         Extensions   `json:"extensions,omitempty"`
	Extras             interface{}  `json:"extras,omitempty"`
	ExtensionsUsed     []string     `json:"extensionsUsed,omitempty"`
	ExtensionsRequired []string     `json:"extensionsRequired,omitempty"`
	Accessors          []Accessor   `json:"accessors,omitempty" validate:"dive"`
	Animations         []Animation  `json:"animations,omitempty" validate:"dive"`
	Asset              Asset        `json:"asset"`
	Buffers            []Buffer     `json:"buffers,omitempty" validate:"dive"`
	BufferViews        []BufferView `json:"bufferViews,omitempty" validate:"dive"`
	Cameras            []Camera     `json:"cameras,omitempty" validate:"dive"`
	Images             []Image      `json:"images,omitempty" validate:"dive"`
	Materials          []Material   `json:"materials,omitempty" validate:"dive"`
	Meshes             []Mesh       `json:"meshes,omitempty" validate:"dive"`
	Nodes              []Node       `json:"nodes,omitempty" validate:"dive"`
	Samplers           []Sampler    `json:"samplers,omitempty" validate:"dive"`
	Scene              *uint32      `json:"scene,omitempty"`
	Scenes             []Scene      `json:"scenes,omitempty" validate:"dive"`
	Skins              []Skin       `json:"skins,omitempty" validate:"dive"`
	Textures           []Texture    `json:"textures,omitempty" validate:"dive"`
}

Document defines the root object for a glTF asset.

func Open

func Open(name string) (*Document, error)

Open will open a glTF or GLB file specified by name and return the Document.

Example
package main

import (
	"fmt"

	"github.com/qmuntal/gltf"
)

func main() {
	doc, err := gltf.Open("fake")
	if err != nil {
		panic(err)
	}
	fmt.Print(doc.Asset)
}
Output:

type Encoder

type Encoder struct {
	AsBinary     bool
	WriteHandler WriteHandler
	// contains filtered or unexported fields
}

An Encoder writes a GLTF to an output stream with relative external buffers support.

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

NewEncoder returns a new encoder that writes to w as a normal glTF file.

func (*Encoder) Encode

func (e *Encoder) Encode(doc *Document) error

Encode writes the encoding of doc to the stream.

func (*Encoder) WithWriteHandler added in v0.9.0

func (e *Encoder) WithWriteHandler(h WriteHandler) *Encoder

WithWriteHandler sets the WriteHandler.

type Extensions

type Extensions map[string]interface{}

Extensions is map where the keys are the extension identifiers and the values are the extensions payloads. If a key matches with one of the supported extensions the value will be marshalled as a pointer to the extension struct. If a key does not match with any of the supported extensions the value will be a json.RawMessage so its decoding can be delayed.

func (*Extensions) UnmarshalJSON

func (ext *Extensions) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshal the extensions with the supported extensions initialized.

type Image

type Image struct {
	Extensions Extensions  `json:"extensions,omitempty"`
	Extras     interface{} `json:"extras,omitempty"`
	Name       string      `json:"name,omitempty"`
	URI        string      `json:"uri,omitempty" validate:"omitempty"`
	MimeType   string      `json:"mimeType,omitempty" validate:"omitempty,oneof=image/jpeg image/png"` // Manadatory if BufferView is defined.
	BufferView *uint32     `json:"bufferView,omitempty"`                                               // Use this instead of the image's uri property.
}

Image data used to create a texture. Image can be referenced by URI or bufferView index. mimeType is required in the latter case.

func (*Image) IsEmbeddedResource

func (im *Image) IsEmbeddedResource() bool

IsEmbeddedResource returns true if the buffer points to an embedded resource.

func (*Image) MarshalData

func (im *Image) MarshalData() ([]uint8, error)

MarshalData decode the image from the URI. If the image is not en embedded resource the returned array will be empty.

type Interpolation

type Interpolation uint8

Interpolation algorithm.

const (
	// Linear corresponds to a linear interpolation.
	Linear Interpolation = iota
	// Step corresponds to a step interpolation.
	Step
	// CubicSpline corresponds to a cubic spline interpolation.
	CubicSpline
)

func (*Interpolation) MarshalJSON added in v0.8.0

func (i *Interpolation) MarshalJSON() ([]byte, error)

MarshalJSON marshal the interpolation with the correct default values.

func (*Interpolation) UnmarshalJSON added in v0.8.0

func (i *Interpolation) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshal the interpolation with the correct default values.

type MagFilter

type MagFilter uint16

MagFilter is the magnification filter.

const (
	// MagLinear corresponds to a linear magnification filter.
	MagLinear MagFilter = iota
	// MagNearest corresponds to a nearest magnification filter.
	MagNearest
)

func (*MagFilter) MarshalJSON added in v0.8.0

func (m *MagFilter) MarshalJSON() ([]byte, error)

MarshalJSON marshal the alpha mode with the correct default values.

func (*MagFilter) UnmarshalJSON added in v0.8.0

func (m *MagFilter) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshal the mag filter with the correct default values.

type Material

type Material struct {
	Extensions           Extensions            `json:"extensions,omitempty"`
	Extras               interface{}           `json:"extras,omitempty"`
	Name                 string                `json:"name,omitempty"`
	PBRMetallicRoughness *PBRMetallicRoughness `json:"pbrMetallicRoughness,omitempty"`
	NormalTexture        *NormalTexture        `json:"normalTexture,omitempty"`
	OcclusionTexture     *OcclusionTexture     `json:"occlusionTexture,omitempty"`
	EmissiveTexture      *TextureInfo          `json:"emissiveTexture,omitempty"`
	EmissiveFactor       [3]float64            `json:"emissiveFactor,omitempty" validate:"dive,gte=0,lte=1"`
	AlphaMode            AlphaMode             `json:"alphaMode,omitempty" validate:"lte=2"`
	AlphaCutoff          *float64              `json:"alphaCutoff,omitempty" validate:"omitempty,gte=0"`
	DoubleSided          bool                  `json:"doubleSided,omitempty"`
}

The Material appearance of a primitive.

func (*Material) AlphaCutoffOrDefault added in v0.8.0

func (m *Material) AlphaCutoffOrDefault() float64

AlphaCutoffOrDefault returns the scale if it is not nil, else return the default one.

func (*Material) MarshalJSON

func (m *Material) MarshalJSON() ([]byte, error)

MarshalJSON marshal the material with the correct default values.

func (*Material) UnmarshalJSON

func (m *Material) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshal the material with the correct default values.

type Mesh

type Mesh struct {
	Extensions Extensions  `json:"extensions,omitempty"`
	Extras     interface{} `json:"extras,omitempty"`
	Name       string      `json:"name,omitempty"`
	Primitives []Primitive `json:"primitives" validate:"required,gt=0,dive"`
	Weights    []float64   `json:"weights,omitempty"`
}

A Mesh is a set of primitives to be rendered. A node can contain one mesh. A node's transform places the mesh in the scene.

type MinFilter

type MinFilter uint16

MinFilter is the minification filter.

const (
	// MinLinear corresponds to a linear minification filter.
	MinLinear MinFilter = iota
	// MinNearestMipMapLinear corresponds to a nearest mipmap linear minification filter.
	MinNearestMipMapLinear
	// MinNearest corresponds to a nearest minification filter.
	MinNearest
	// MinNearestMipMapNearest corresponds to a nearest mipmap nearest minification filter.
	MinNearestMipMapNearest
	// MinLinearMipMapNearest corresponds to a linear mipmap nearest minification filter.
	MinLinearMipMapNearest
	// MinLinearMipMapLinear corresponds to a linear mipmap linear minification filter.
	MinLinearMipMapLinear
)

func (*MinFilter) MarshalJSON added in v0.8.0

func (m *MinFilter) MarshalJSON() ([]byte, error)

MarshalJSON marshal the min filter with the correct default values.

func (*MinFilter) UnmarshalJSON added in v0.8.0

func (m *MinFilter) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshal the min filter with the correct default values.

type Node

type Node struct {
	Extensions  Extensions  `json:"extensions,omitempty"`
	Extras      interface{} `json:"extras,omitempty"`
	Name        string      `json:"name,omitempty"`
	Camera      *uint32     `json:"camera,omitempty"`
	Children    []uint32    `json:"children,omitempty" validate:"omitempty,unique"`
	Skin        *uint32     `json:"skin,omitempty"`
	Matrix      [16]float64 `json:"matrix"` // A 4x4 transformation matrix stored in column-major order.
	Mesh        *uint32     `json:"mesh,omitempty"`
	Rotation    [4]float64  `json:"rotation" validate:"omitempty,dive,gte=-1,lte=1"` // The node's unit quaternion rotation in the order (x, y, z, w), where w is the scalar.
	Scale       [3]float64  `json:"scale"`
	Translation [3]float64  `json:"translation"`
	Weights     []float64   `json:"weights,omitempty"` // The weights of the instantiated Morph Target.
}

A Node in the node hierarchy. It can have either a matrix or any combination of translation/rotation/scale (TRS) properties.

func (*Node) MarshalJSON

func (n *Node) MarshalJSON() ([]byte, error)

MarshalJSON marshal the node with the correct default values.

func (*Node) MatrixOrDefault added in v0.8.0

func (n *Node) MatrixOrDefault() [16]float64

MatrixOrDefault returns the node matrix if it represents a valid affine matrix, else return the default one.

func (*Node) RotationOrDefault added in v0.8.0

func (n *Node) RotationOrDefault() [4]float64

RotationOrDefault returns the node rotation if it represents a valid quaternion, else return the default one.

func (*Node) ScaleOrDefault added in v0.8.0

func (n *Node) ScaleOrDefault() [3]float64

ScaleOrDefault returns the node scale if it represents a valid scale factor, else return the default one.

func (*Node) TranslationOrDefault added in v0.8.0

func (n *Node) TranslationOrDefault() [3]float64

TranslationOrDefault returns the node translation.

func (*Node) UnmarshalJSON

func (n *Node) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshal the node with the correct default values.

type NormalTexture

type NormalTexture struct {
	Extensions Extensions  `json:"extensions,omitempty"`
	Extras     interface{} `json:"extras,omitempty"`
	Index      *uint32     `json:"index,omitempty"`
	TexCoord   uint32      `json:"texCoord,omitempty"` // The index of texture's TEXCOORD attribute used for texture coordinate mapping.
	Scale      *float64    `json:"scale,omitempty"`
}

A NormalTexture references to a normal texture.

func (*NormalTexture) MarshalJSON

func (n *NormalTexture) MarshalJSON() ([]byte, error)

MarshalJSON marshal the texture info with the correct default values.

func (*NormalTexture) ScaleOrDefault added in v0.8.0

func (n *NormalTexture) ScaleOrDefault() float64

ScaleOrDefault returns the scale if it is not nil, else return the default one.

func (*NormalTexture) UnmarshalJSON

func (n *NormalTexture) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshal the texture info with the correct default values.

type OcclusionTexture

type OcclusionTexture struct {
	Extensions Extensions  `json:"extensions,omitempty"`
	Extras     interface{} `json:"extras,omitempty"`
	Index      *uint32     `json:"index,omitempty"`
	TexCoord   uint32      `json:"texCoord,omitempty"` // The index of texture's TEXCOORD attribute used for texture coordinate mapping.
	Strength   *float64    `json:"strength,omitempty" validate:"omitempty,gte=0,lte=1"`
}

An OcclusionTexture references to an occlusion texture

func (*OcclusionTexture) MarshalJSON

func (o *OcclusionTexture) MarshalJSON() ([]byte, error)

MarshalJSON marshal the texture info with the correct default values.

func (*OcclusionTexture) StrengthOrDefault added in v0.8.0

func (o *OcclusionTexture) StrengthOrDefault() float64

StrengthOrDefault returns the strength if it is not nil, else return the default one.

func (*OcclusionTexture) UnmarshalJSON

func (o *OcclusionTexture) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshal the texture info with the correct default values.

type Orthographic

type Orthographic struct {
	Extensions Extensions  `json:"extensions,omitempty"`
	Extras     interface{} `json:"extras,omitempty"`
	Xmag       float64     `json:"xmag"`                               // The horizontal magnification of the view.
	Ymag       float64     `json:"ymag"`                               // The vertical magnification of the view.
	Zfar       float64     `json:"zfar" validate:"gt=0,gtfield=Znear"` // The distance to the far clipping plane.
	Znear      float64     `json:"znear" validate:"gte=0"`             // The distance to the near clipping plane.
}

Orthographic camera containing properties to create an orthographic projection matrix.

type PBRMetallicRoughness

type PBRMetallicRoughness struct {
	Extensions               Extensions   `json:"extensions,omitempty"`
	Extras                   interface{}  `json:"extras,omitempty"`
	BaseColorFactor          *RGBA        `json:"baseColorFactor,omitempty"`
	BaseColorTexture         *TextureInfo `json:"baseColorTexture,omitempty"`
	MetallicFactor           *float64     `json:"metallicFactor,omitempty" validate:"omitempty,gte=0,lte=1"`
	RoughnessFactor          *float64     `json:"roughnessFactor,omitempty" validate:"omitempty,gte=0,lte=1"`
	MetallicRoughnessTexture *TextureInfo `json:"metallicRoughnessTexture,omitempty"`
}

PBRMetallicRoughness defines a set of parameter values that are used to define the metallic-roughness material model from Physically-Based Rendering (PBR) methodology.

func (*PBRMetallicRoughness) BaseColorFactorOrDefault added in v0.8.0

func (p *PBRMetallicRoughness) BaseColorFactorOrDefault() RGBA

BaseColorFactorOrDefault returns the base color factor if it is not nil, else return the default one.

func (*PBRMetallicRoughness) MarshalJSON

func (p *PBRMetallicRoughness) MarshalJSON() ([]byte, error)

MarshalJSON marshal the pbr with the correct default values.

func (*PBRMetallicRoughness) MetallicFactorOrDefault added in v0.8.0

func (p *PBRMetallicRoughness) MetallicFactorOrDefault() float64

MetallicFactorOrDefault returns the metallic factor if it is not nil, else return the default one.

func (*PBRMetallicRoughness) RoughnessFactorOrDefault added in v0.8.0

func (p *PBRMetallicRoughness) RoughnessFactorOrDefault() float64

RoughnessFactorOrDefault returns the roughness factor if it is not nil, else return the default one.

func (*PBRMetallicRoughness) UnmarshalJSON

func (p *PBRMetallicRoughness) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshal the pbr with the correct default values.

type Perspective

type Perspective struct {
	Extensions  Extensions  `json:"extensions,omitempty"`
	Extras      interface{} `json:"extras,omitempty"`
	AspectRatio *float64    `json:"aspectRatio,omitempty"`
	Yfov        float64     `json:"yfov"`           // The vertical field of view in radians.
	Zfar        *float64    `json:"zfar,omitempty"` // The distance to the far clipping plane.
	Znear       float64     `json:"znear"`          // The distance to the near clipping plane.
}

Perspective camera containing properties to create a perspective projection matrix.

type Primitive

type Primitive struct {
	Extensions Extensions    `json:"extensions,omitempty"`
	Extras     interface{}   `json:"extras,omitempty"`
	Attributes Attribute     `json:"attributes"`
	Indices    *uint32       `json:"indices,omitempty"` // The index of the accessor that contains the indices.
	Material   *uint32       `json:"material,omitempty"`
	Mode       PrimitiveMode `json:"mode,omitempty" validate:"lte=6"`
	Targets    []Attribute   `json:"targets,omitempty" validate:"omitempty,dive,dive,keys,oneof=POSITION NORMAL TANGENT,endkeys"` // Only POSITION, NORMAL, and TANGENT supported.
}

Primitive defines the geometry to be rendered with the given material.

type PrimitiveMode

type PrimitiveMode uint8

PrimitiveMode defines the type of primitives to render. All valid values correspond to WebGL enums.

const (
	// Triangles corresponds to a Triangle primitive.
	Triangles PrimitiveMode = iota
	// Points corresponds to a Point primitive.
	Points
	// Lines corresponds to a Line primitive.
	Lines
	// LineLoop corresponds to a Line Loop primitive.
	LineLoop
	// LineStrip corresponds to a Line Strip primitive.
	LineStrip
	// TriangleStrip corresponds to a Triangle Strip primitive.
	TriangleStrip
	// TriangleFan corresponds to a Triangle Fan primitive.
	TriangleFan
)

func (*PrimitiveMode) MarshalJSON added in v0.8.0

func (p *PrimitiveMode) MarshalJSON() ([]byte, error)

MarshalJSON marshal the primitive mode with the correct default values.

func (*PrimitiveMode) UnmarshalJSON added in v0.8.0

func (p *PrimitiveMode) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshal the primitive mode with the correct default values.

type RGB added in v0.8.0

type RGB struct {
	R, G, B float64 `validate:"gte=0,lte=1"`
}

The RGB components of a color. Each element must be greater than or equal to 0 and less than or equal to 1.

func NewRGB added in v0.8.0

func NewRGB() *RGB

NewRGB returns a default RGB color.

func NewRGBColor added in v0.12.1

func NewRGBColor(c color.RGBA) *RGB

NewRGBColor transform a RGB uint8 color (from 0 to 255) to its float represtation (from 0 to 1).

func (*RGB) MarshalJSON added in v0.8.0

func (c *RGB) MarshalJSON() ([]byte, error)

MarshalJSON marshal the color with the correct default values.

func (*RGB) UnmarshalJSON added in v0.8.0

func (c *RGB) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshal the color with the correct default values.

type RGBA added in v0.8.0

type RGBA struct {
	R, G, B, A float64 `validate:"gte=0,lte=1"`
}

The RGBA components of a color. Each element must be greater than or equal to 0 and less than or equal to 1.

func NewRGBA added in v0.8.0

func NewRGBA() *RGBA

NewRGBA returns a default RGBA color.

func NewRGBAColor added in v0.12.1

func NewRGBAColor(c color.RGBA) *RGBA

NewRGBAColor transform a RGB uint8 color (from 0 to 255) to its float represtation (from 0 to 1).

func (*RGBA) MarshalJSON added in v0.8.0

func (c *RGBA) MarshalJSON() ([]byte, error)

MarshalJSON marshal the color with the correct default values.

func (*RGBA) UnmarshalJSON added in v0.8.0

func (c *RGBA) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshal the color with the correct default values.

type ReadHandler added in v0.9.0

type ReadHandler interface {
	ReadFullResource(uri string, data []byte) error
}

ReadHandler is the interface that wraps the ReadFullResource method.

ReadFullResource should behaves as io.ReadFull in terms of reading the external resource. The data already has the correct size so it can be used directly to store the read output.

type RelativeFileHandler added in v0.9.0

type RelativeFileHandler struct {
	Dir string
}

RelativeFileHandler implements a secure ReadHandler supporting relative paths. If Dir is empty the os.Getws will be used. It comes with directory traversal protection.

func (*RelativeFileHandler) ReadFullResource added in v0.9.0

func (h *RelativeFileHandler) ReadFullResource(uri string, data []byte) error

ReadFullResource reads all the resource data using io.ReadFull.

func (*RelativeFileHandler) WriteResource added in v0.9.0

func (h *RelativeFileHandler) WriteResource(uri string, data []byte) error

WriteResource writes the resource using io.WriteFile.

type Sampler

type Sampler struct {
	Extensions Extensions   `json:"extensions,omitempty"`
	Extras     interface{}  `json:"extras,omitempty"`
	Name       string       `json:"name,omitempty"`
	MagFilter  MagFilter    `json:"magFilter,omitempty" validate:"lte=1"`
	MinFilter  MinFilter    `json:"minFilter,omitempty" validate:"lte=5"`
	WrapS      WrappingMode `json:"wrapS,omitempty" validate:"lte=2"`
	WrapT      WrappingMode `json:"wrapT,omitempty" validate:"lte=2"`
}

Sampler of a texture for filtering and wrapping modes.

type Scene

type Scene struct {
	Extensions Extensions  `json:"extensions,omitempty"`
	Extras     interface{} `json:"extras,omitempty"`
	Name       string      `json:"name,omitempty"`
	Nodes      []uint32    `json:"nodes,omitempty" validate:"omitempty,unique"`
}

The Scene contains a list of root nodes.

type Skin

type Skin struct {
	Extensions          Extensions  `json:"extensions,omitempty"`
	Extras              interface{} `json:"extras,omitempty"`
	Name                string      `json:"name,omitempty"`
	InverseBindMatrices *uint32     `json:"inverseBindMatrices,omitempty"`      // The index of the accessor containing the floating-point 4x4 inverse-bind matrices.
	Skeleton            *uint32     `json:"skeleton,omitempty"`                 // The index of the node used as a skeleton root. When undefined, joints transforms resolve to scene root.
	Joints              []uint32    `json:"joints" validate:"omitempty,unique"` // Indices of skeleton nodes, used as joints in this skin.
}

Skin defines joints and matrices.

type Sparse

type Sparse struct {
	Extensions Extensions    `json:"extensions,omitempty"`
	Extras     interface{}   `json:"extras,omitempty"`
	Count      uint32        `json:"count" validate:"gte=1"` // Number of entries stored in the sparse array.
	Indices    SparseIndices `json:"indices"`                // Index array of size count that points to those accessor attributes that deviate from their initialization value.
	Values     SparseValues  `json:"values"`                 // Array of size count times number of components, storing the displaced accessor attributes pointed by indices.
}

Sparse storage of attributes that deviate from their initialization value.

type SparseIndices

type SparseIndices struct {
	Extensions    Extensions    `json:"extensions,omitempty"`
	Extras        interface{}   `json:"extras,omitempty"`
	BufferView    uint32        `json:"bufferView"`
	ByteOffset    uint32        `json:"byteOffset,omitempty"`
	ComponentType ComponentType `json:"componentType" validate:"oneof=2 4 5"`
}

SparseIndices defines the indices of those attributes that deviate from their initialization value.

type SparseValues

type SparseValues struct {
	Extensions Extensions  `json:"extensions,omitempty"`
	Extras     interface{} `json:"extras,omitempty"`
	BufferView uint32      `json:"bufferView"`
	ByteOffset uint32      `json:"byteOffset,omitempty"`
}

SparseValues stores the displaced accessor attributes pointed by accessor.sparse.indices.

type TRSProperty

type TRSProperty uint8

TRSProperty defines a local space transformation. TRSproperties are converted to matrices and postmultiplied in the T * R * S order to compose the transformation matrix.

const (
	// Translation corresponds to a translation transform.
	Translation TRSProperty = iota
	// Rotation corresponds to a rotation transform.
	Rotation
	// Scale corresponds to a scale transform.
	Scale
	// Weights corresponds to a weights transform.
	Weights
)

func (*TRSProperty) MarshalJSON added in v0.8.0

func (t *TRSProperty) MarshalJSON() ([]byte, error)

MarshalJSON marshal the TRSProperty with the correct default values.

func (*TRSProperty) UnmarshalJSON added in v0.8.0

func (t *TRSProperty) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshal the TRSProperty with the correct default values.

type Target

type Target uint16

The Target that the GPU buffer should be bound to.

type Texture

type Texture struct {
	Extensions Extensions  `json:"extensions,omitempty"`
	Extras     interface{} `json:"extras,omitempty"`
	Name       string      `json:"name,omitempty"`
	Sampler    *uint32     `json:"sampler,omitempty"`
	Source     *uint32     `json:"source,omitempty"`
}

A Texture and its sampler.

type TextureInfo

type TextureInfo struct {
	Extensions Extensions  `json:"extensions,omitempty"`
	Extras     interface{} `json:"extras,omitempty"`
	Index      uint32      `json:"index"`
	TexCoord   uint32      `json:"texCoord,omitempty"` // The index of texture's TEXCOORD attribute used for texture coordinate mapping.
}

TextureInfo references to a texture.

type WrappingMode

type WrappingMode uint16

WrappingMode is the wrapping mode of a texture.

const (
	// Repeat corresponds to a repeat wrapping.
	Repeat WrappingMode = iota
	// ClampToEdge corresponds to a clamp to edge wrapping.
	ClampToEdge
	// MirroredRepeat corresponds to a mirrored repeat wrapping.
	MirroredRepeat
)

func (*WrappingMode) MarshalJSON added in v0.8.0

func (w *WrappingMode) MarshalJSON() ([]byte, error)

MarshalJSON marshal the wrapping mode with the correct default values.

func (*WrappingMode) UnmarshalJSON added in v0.8.0

func (w *WrappingMode) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshal the wrapping mode with the correct default values.

type WriteHandler added in v0.9.0

type WriteHandler interface {
	WriteResource(uri string, data []byte) error
}

WriteHandler is the interface that wraps the Write method.

WriteResource should behaves as io.Write in terms of reading the writing resource.

Directories

Path Synopsis
Package binary implements simple translation between numbers and byte sequences.
Package binary implements simple translation between numbers and byte sequences.
ext
lightspuntual
Package lightspuntual defines three "punctual" light types: directional, point and spot.
Package lightspuntual defines three "punctual" light types: directional, point and spot.

Jump to

Keyboard shortcuts

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