gltf

package module
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2019 License: BSD-2-Clause Imports: 13 Imported by: 62

README

gltf

Documentation Build Status Go Report Card codecov codeclimate License

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 time and moderate memory consumption.
  • glTF specification v2.0.0
    • ASCII glTF.
    • Binary glTF(GLB).
    • PBR material description.
  • glTF validaton
    • Validate against schemas.
    • Validate coherence.
  • Buffers
    • Parse BASE64 encoded embedded buffer data(DataURI).
    • Load .bin file.
  • 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

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)
Write
doc := &gltf.Document{
  Scene: 0, 
  Asset: gltf.Asset{Generator: "qmuntal/gltf"}, 
  Scenes: []gltf.Scene{{Extras: 8.0, Extensions: gltf.Extensions{"a": "b"}, Name: "s_1"}}
}
 
if err := gltf.Save(doc, "./a.gltf", true); err != nil {
  panic(err)
}
Write complex
doc := &gltf.Document{
  Accessors: []gltf.Accessor{
    {BufferView: 0, ByteOffset: 0, ComponentType: gltf.UnsignedShort, Count: 36, Type: gltf.Scalar},
    {BufferView: 1, ByteOffset: 0, 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: 2, ByteOffset: 0, ComponentType: gltf.Float, Count: 24, Type: gltf.Vec3},
    {BufferView: 3, ByteOffset: 0, ComponentType: gltf.Float, Count: 24, Type: gltf.Vec4},
    {BufferView: 4, ByteOffset: 0, 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: readFile("testdata/BoxVertexColors/glTF-Binary/BoxVertexColors.glb")[1628+20+8:]}},
  Materials: []gltf.Material{{Name: "Default", AlphaMode: gltf.Opaque, AlphaCutoff: 0.5, 
    PBRMetallicRoughness: &gltf.PBRMetallicRoughness{BaseColorFactor: [4]float64{0.8, 0.8, 0.8, 1}, MetallicFactor: 0.1, RoughnessFactor: 0.99}}
  },
  Meshes: []gltf.Mesh{{Name: "Cube", Primitives: []gltf.Primitive{{Indices: 0, Material: 0, Mode: gltf.Triangles, Attributes: map[string]uint32{"POSITION": 1, "COLOR_0": 3, "NORMAL": 2, "TEXCOORD_0": 4}}}}},
  Nodes: []gltf.Node{
    {Name: "RootNode", Mesh: -1, Camera: -1, Skin: -1, Children: []uint32{1, 2, 3}, Matrix: [16]float64{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}, Rotation: [4]float64{0, 0, 0, 1}, Scale: [3]float64{1, 1, 1}},
    {Name: "Mesh", Mesh: -1, Camera: -1, Skin: -1, Matrix: [16]float64{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}, Rotation: [4]float64{0, 0, 0, 1}, Scale: [3]float64{1, 1, 1}},
    {Name: "Cube", Mesh: 0, Camera: -1, Skin: -1, Matrix: [16]float64{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}, Rotation: [4]float64{0, 0, 0, 1}, Scale: [3]float64{1, 1, 1}},
    {Name: "Texture Group", Mesh: -1, Camera: -1, Skin: -1, Matrix: [16]float64{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}, Rotation: [4]float64{0, 0, 0, 1}, Scale: [3]float64{1, 1, 1}},
  },
  Samplers: []gltf.Sampler{{WrapS: gltf.Repeat, WrapT: gltf.Repeat}},
  Scene: 0,
  Scenes: []gltf.Scene{{Name: "Root Scene", Nodes: []uint32{0}}},
}
if err := gltf.Save(doc, "./a.gltf", true); err != nil {
  panic(err)
}

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/.

Index

Examples

Constants

View Source
const (
	// Byte corresponds to a Int8Array.
	Byte ComponentType = 5120
	// UnsignedByte corresponds to a Uint8Array.
	UnsignedByte = 5121
	// Short corresponds to a Int16Array.
	Short = 5122
	// UnsignedShort corresponds to a Uint16Array.
	UnsignedShort = 5123
	// UnsignedInt corresponds to a Uint32Array.
	UnsignedInt = 5125
	// Float corresponds to a Float32Array.
	Float = 5126
)
View Source
const (
	// Scalar corresponds to a single dimension value.
	Scalar AccessorType = "SCALAR"
	// Vec2 corresponds to a two dimensions array.
	Vec2 = "VEC2"
	// Vec3 corresponds to a three dimensions array.
	Vec3 = "VEC3"
	// Vec4 corresponds to a four dimensions array.
	Vec4 = "VEC4"
	// Mat2 corresponds to a 2x2 matrix.
	Mat2 = "MAT2"
	// Mat3 corresponds to a 3x3 matrix.
	Mat3 = "MAT3"
	// Mat4 corresponds to a 4x4 matrix.
	Mat4 = "MAT4"
)
View Source
const (
	// Points corresponds to a Point primitive.
	Points PrimitiveMode = 0
	// Lines corresponds to a Line primitive.
	Lines = 1
	// LineLoop corresponds to a Line Loop primitive.
	LineLoop = 2
	// LineStrip corresponds to a Line Strip primitive.
	LineStrip = 3
	// Triangles corresponds to a Triangle primitive.
	Triangles = 4
	// TriangleStrip corresponds to a Triangle Strip primitive.
	TriangleStrip = 5
	// TriangleFan corresponds to a Triangle Fan primitive.
	TriangleFan = 6
)
View Source
const (
	// Opaque corresponds to an Opaque material.
	Opaque AlphaMode = "OPAQUE"
	// Mask corresponds to a masked material.
	Mask = "MASK"
	// Blend corresponds to a Blend material.
	Blend = "BLEND"
)
View Source
const (
	// MinNearest corresponds to a nearest minification filter.
	MinNearest MinFilter = 9728
	// MinLinear corresponds to a linear minification filter.
	MinLinear = 9729
	// MinNearestMipMapNearest corresponds to a nearest mipmap nearest minification filter.
	MinNearestMipMapNearest = 9984
	// MinLinearMipMapNearest corresponds to a linear mipmap nearest minification filter.
	MinLinearMipMapNearest = 9985
	// MinNearestMipMapLinear corresponds to a nearest mipmap linear minification filter.
	MinNearestMipMapLinear = 9986
	// MinLinearMipMapLinear corresponds to a linear mipmap linear minification filter.
	MinLinearMipMapLinear = 9987
)
View Source
const (
	// ClampToEdge corresponds to a clamp to edge wrapping.
	ClampToEdge WrappingMode = 33071
	// MirroredRepeat corresponds to a mirrored repeat wrapping.
	MirroredRepeat = 33648
	// Repeat corresponds to a repeat wrapping.
	Repeat = 10497
)
View Source
const (
	// Linear corresponds to a linear interpolation.
	Linear Interpolation = "LINEAR"
	// Step corresponds to a step interpolation.
	Step = "STEP"
	// CubicSpline corresponds to a cubic spline interpolation.
	CubicSpline = "CUBICSPLINE"
)
View Source
const (
	// Translation corresponds to a translation transform.
	Translation TRSProperty = "translation"
	// Rotation corresponds to a rotation transform.
	Rotation = "rotation"
	// Scale corresponds to a scale transform.
	Scale = "scale"
	// Weights corresponds to a weights transform.
	Weights = "weights"
)
View Source
const (
	ExtPBRSpecularGlossiness = "KHR_materials_pbrSpecularGlossiness"
)

Variables

This section is empty.

Functions

func Save

func Save(doc *Document, name string, asBinary bool) error

Save will save a document as a glTF or a GLB file 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    int32         `json:"bufferView" validate:"gte=-1"`
	ByteOffset    uint32        `json:"byteOffset,omitempty"`
	ComponentType ComponentType `json:"componentType" validate:"oneof=5120 5121 5122 5123 5125 5126"`
	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:"oneof=SCALAR VEC2 VEC3 VEC4 MAT2 MAT3 MAT4"`
	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.

func NewAccessor

func NewAccessor() *Accessor

NewAccessor returns a default accessor.

func (*Accessor) MarshalJSON

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

MarshalJSON marshal the accessor with the correct default values.

func (*Accessor) UnmarshalJSON

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

UnmarshalJSON unmarshal the accessor with the correct default values.

type AccessorType

type AccessorType string

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

type AlphaMode

type AlphaMode string

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

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         int32         `json:"input" validate:"gte=-1"` // The index of an accessor containing keyframe input values.
	Interpolation Interpolation `json:"interpolation,omitempty" validate:"omitempty,oneof=LINEAR STEP CUBICSPLINE"`
	Output        int32         `json:"output" validate:"gte=-1"` // 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).

func NewAnimationSampler

func NewAnimationSampler() *AnimationSampler

NewAnimationSampler returns a default AnimationSampler.

func (*AnimationSampler) UnmarshalJSON

func (as *AnimationSampler) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshal the animation sampler with the correct default values.

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.

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     int32       `json:"buffer" validate:"gte=-1"`
	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.

func (*BufferView) MarshalJSON

func (b *BufferView) MarshalJSON() ([]byte, error)

MarshalJSON marshal the buffer view with the correct default values.

func (*BufferView) UnmarshalJSON

func (b *BufferView) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshal the buffer view with the correct default values.

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"`
	Type         CameraType    `json:"type" validate:"oneof=perspective orthographic"`
}

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

type CameraType

type CameraType string

CameraType specifies if the camera uses a perspective or orthographic projection. Based on this, either the camera's perspective or orthographic property will be defined.

const (
	// PerspectiveType corresponds to a perspective camera.
	PerspectiveType CameraType = "perspective"
	// OrthographicType corresponds to an orthographic camera.
	OrthographicType = "orthographic"
)

type Channel

type Channel struct {
	Extensions Extensions    `json:"extensions,omitempty"`
	Extras     interface{}   `json:"extras,omitempty"`
	Sampler    int32         `json:"sampler" validate:"gte=-1"`
	Target     ChannelTarget `json:"target"`
}

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

func NewChannel

func NewChannel(sampler int32) *Channel

NewChannel returns a default Channel.

func (*Channel) MarshalJSON

func (ch *Channel) MarshalJSON() ([]byte, error)

MarshalJSON marshal the channel with the correct default values.

func (*Channel) UnmarshalJSON

func (ch *Channel) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshal the channel with the correct default values.

type ChannelTarget

type ChannelTarget struct {
	Extensions Extensions  `json:"extensions,omitempty"`
	Extras     interface{} `json:"extras,omitempty"`
	Node       int32       `json:"node" validate:"gte=-1"`
	Path       TRSProperty `json:"path" validate:"oneof=translation rotation scale weights"`
}

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.

func NewChannelTarget

func NewChannelTarget(path TRSProperty) *ChannelTarget

NewChannelTarget returns a default ChannelTarget.

func (*ChannelTarget) MarshalJSON

func (ch *ChannelTarget) MarshalJSON() ([]byte, error)

MarshalJSON marshal the channel target with the correct default values.

func (*ChannelTarget) UnmarshalJSON

func (ch *ChannelTarget) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshal the channel target with the correct default values.

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.

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

A Decoder reads and decodes glTF and GLB values from an input stream.

func NewDecoder

func NewDecoder(r io.Reader, cb ReadResourceCallback) *Decoder

NewDecoder returns a new decoder that reads from r.

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) SetQuotas

func (d *Decoder) SetQuotas(quotas ReadQuotas) *Decoder

SetQuotas sets the read memory limits. The return value is the same decoder.

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              int32        `json:"scene" validate:"gte=-1"`
	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
doc, err := Open("fake")
if err != nil {
	panic(err)
}
fmt.Print(doc.Asset)
Output:

func (*Document) MarshalJSON

func (d *Document) MarshalJSON() ([]byte, error)

MarshalJSON marshal the document with the correct default values.

func (*Document) UnmarshalJSON

func (d *Document) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshal the document with the correct default values.

func (*Document) Validate

func (d *Document) Validate() error

Validate ensures that a document follows the glTF 2.0 specs.

type Encoder

type Encoder struct {
	// contains filtered or unexported fields
}

An Encoder writes a GLTF to an output stream.

func NewEncoder

func NewEncoder(w io.Writer, cb WriteResourceCallback, asBinary bool) *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.

type Extensions

type Extensions map[string]interface{}

Extension 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 string

Interpolation algorithm.

type MagFilter

type MagFilter uint16

MagFilter is the magnification filter.

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

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:"oneof=OPAQUE MASK BLEND"`
	AlphaCutoff          float64               `json:"alphaCutoff" validate:"gte=0"`
	DoubleSided          bool                  `json:"doubleSided,omitempty"`
}

The Material appearance of a primitive.

func NewMaterial

func NewMaterial() *Material

NewMaterial create a default Material.

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.

type Node

type Node struct {
	Extensions  Extensions  `json:"extensions,omitempty"`
	Extras      interface{} `json:"extras,omitempty"`
	Name        string      `json:"name,omitempty"`
	Camera      int32       `json:"camera" validate:"gte=-1"`
	Children    []uint32    `json:"children,omitempty" validate:"omitempty,unique"`
	Skin        int32       `json:"skin" validate:"gte=-1"`
	Matrix      [16]float64 `json:"matrix"` // A 4x4 transformation matrix stored in column-major order.
	Mesh        int32       `json:"mesh" validate:"gte=-1"`
	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 NewNode

func NewNode() *Node

NewNode returns a default Node.

func (*Node) MarshalJSON

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

MarshalJSON marshal the node with the correct default values.

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      int32       `json:"index" validate:"gte=-1"`
	TexCoord   uint32      `json:"texCoord,omitempty"` // The index of texture's TEXCOORD attribute used for texture coordinate mapping.
	Scale      float64     `json:"scale"`
}

A NormalTexture references to a normal texture.

func NewNormalTexture

func NewNormalTexture(index int32) *NormalTexture

NewNormalTexture returns a default NormalTexture.

func (*NormalTexture) MarshalJSON

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

MarshalJSON marshal the texture info with the correct default values.

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      int32       `json:"index" validate:"gte=-1"`
	TexCoord   uint32      `json:"texCoord,omitempty"` // The index of texture's TEXCOORD attribute used for texture coordinate mapping.
	Strength   float64     `json:"strength" validate:"gte=0,lte=1"`
}

An OcclusionTexture references to an occlusion texture

func NewOcclusionTexture

func NewOcclusionTexture(index int32) *OcclusionTexture

NewOcclusionTexture returns a default OcclusionTexture.

func (*OcclusionTexture) MarshalJSON

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

MarshalJSON marshal the texture info with the correct default values.

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          [4]float64   `json:"baseColorFactor" validate:"dive,gte=0,lte=1"`
	BaseColorTexture         *TextureInfo `json:"baseColorTexture,omitempty"`
	MetallicFactor           float64      `json:"metallicFactor" validate:"gte=0,lte=1"`
	RoughnessFactor          float64      `json:"roughnessFactor" validate:"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 NewPBRMetallicRoughness

func NewPBRMetallicRoughness() *PBRMetallicRoughness

NewPBRMetallicRoughness returns a default PBRMetallicRoughness.

func (*PBRMetallicRoughness) MarshalJSON

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

MarshalJSON marshal the pbr with the correct default values.

func (*PBRMetallicRoughness) UnmarshalJSON

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

UnmarshalJSON unmarshal the pbr with the correct default values.

type PBRSpecularGlossiness

type PBRSpecularGlossiness struct {
	DiffuseFactor             [4]float64   `json:"diffuseFactor" validate:"dive,gte=0,lte=1"`
	DiffuseTexture            *TextureInfo `json:"diffuseTexture,omitempty"`
	SpecularFactor            [3]float64   `json:"specularFactor" validate:"dive,gte=0,lte=1"`
	GlossinessFactor          float64      `json:"glossinessFactor" validate:"gte=0,lte=1"`
	SpecularGlossinessTexture *TextureInfo `json:"specularGlossinessTexture,omitempty"`
}

func NewPBRSpecularGlossiness

func NewPBRSpecularGlossiness() *PBRSpecularGlossiness

PBRSpecularGlossiness returns a default PBRSpecularGlossiness.

func (*PBRSpecularGlossiness) MarshalJSON

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

MarshalJSON marshal the pbr with the correct default values.

func (*PBRSpecularGlossiness) UnmarshalJSON

func (p *PBRSpecularGlossiness) 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    int32         `json:"indices" validate:"gte=-1"` // The index of the accessor that contains the indices.
	Material   int32         `json:"material" validate:"gte=-1"`
	Mode       PrimitiveMode `json:"mode" 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.

func NewPrimitive

func NewPrimitive() *Primitive

NewPrimitive create a default Primitive.

func (*Primitive) MarshalJSON

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

MarshalJSON marshal the primitive with the correct default values.

func (*Primitive) UnmarshalJSON

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

UnmarshalJSON unmarshal the primitive with the correct default values.

type PrimitiveMode

type PrimitiveMode uint8

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

type ReadQuotas

type ReadQuotas struct {
	MaxBufferCount      int
	MaxMemoryAllocation int
}

ReadQuotas defines maximum allocation sizes to prevent DOS's from malicious files.

type ReadResourceCallback

type ReadResourceCallback = func(string) (io.ReadCloser, error)

ReadResourceCallback defines a callback that will be called when an external resource should be loaded. The string parameter is the URI of the resource.

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:"omitempty,oneof=9728 9729"`
	MinFilter  MinFilter    `json:"minFilter,omitempty" validate:"omitempty,oneof=9728 9729 9984 9985 9986 9987"`
	WrapS      WrappingMode `json:"wrapS,omitempty" validate:"omitempty,oneof=33071 33648 10497"`
	WrapT      WrappingMode `json:"wrapT,omitempty" validate:"omitempty,oneof=33071 33648 10497"`
}

Sampler of a texture for filtering and wrapping modes.

func NewSampler

func NewSampler() *Sampler

NewSampler returns a default Sampler.

func (*Sampler) UnmarshalJSON

func (s *Sampler) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshal the sampler with the correct default values.

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 int32       `json:"inverseBindMatrices" validate:"gte=-1"` // The index of the accessor containing the floating-point 4x4 inverse-bind matrices.
	Skeleton            int32       `json:"skeleton" validate:"gte=-1"`            // 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.

func NewSkin

func NewSkin() *Skin

NewSkin create a default Skin.

func (*Skin) MarshalJSON

func (s *Skin) MarshalJSON() ([]byte, error)

MarshalJSON marshal the skin with the correct default values.

func (*Skin) UnmarshalJSON

func (s *Skin) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshal the skin with the correct default values.

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=5121 5123 5125"`
}

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 string

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

type Target

type Target uint16

The Target that the GPU buffer should be bound to.

const (
	// ArrayBuffer corresponds to an array buffer.
	ArrayBuffer Target = 34962
	// ElementArrayBuffer corresponds to an element array buffer.
	ElementArrayBuffer = 34963
)

type Texture

type Texture struct {
	Extensions Extensions  `json:"extensions,omitempty"`
	Extras     interface{} `json:"extras,omitempty"`
	Name       string      `json:"name,omitempty"`
	Sampler    int32       `json:"sampler" validate:"gte=-1"`
	Source     int32       `json:"source" validate:"gte=-1"`
}

A Texture and its sampler.

func NewTexture

func NewTexture() *Texture

NewTexture returns a default Texture.

func (*Texture) MarshalJSON

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

MarshalJSON marshal the texture with the correct default values.

func (*Texture) UnmarshalJSON

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

UnmarshalJSON unmarshal the texture with the correct default values.

type TextureInfo

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

TextureInfo references to a texture.

func NewTextureInfo

func NewTextureInfo(index int32) *TextureInfo

NewTextureInfo returns a default TextureInfo.

func (*TextureInfo) MarshalJSON

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

MarshalJSON marshal the texture info with the correct default values.

func (*TextureInfo) UnmarshalJSON

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

UnmarshalJSON unmarshal the texture info with the correct default values.

type WrappingMode

type WrappingMode uint16

WrappingMode is the wrapping mode of a texture.

type WriteResourceCallback

type WriteResourceCallback = func(string, int) (io.WriteCloser, error)

WriteResourceCallback defines a callback that will be called when an external resource should be writed. The string parameter is the URI of the resource.

Jump to

Keyboard shortcuts

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