Documentation ¶
Overview ¶
Package gltf
Index ¶
- Constants
- Variables
- type Accessor
- type Animation
- type AnimationSampler
- type Asset
- type Buffer
- type BufferView
- type Camera
- type Channel
- type GLB
- type GLBChunk
- type GLBHeader
- type GLTF
- func (g *GLTF) LoadAnimation(animIdx int) (*animation.Animation, error)
- func (g *GLTF) LoadAnimationByName(animName string) (*animation.Animation, error)
- func (g *GLTF) LoadCamera(camIdx int) (core.INode, error)
- func (g *GLTF) LoadImage(imgIdx int) (*image.RGBA, error)
- func (g *GLTF) LoadMaterial(matIdx int) (material.IMaterial, error)
- func (g *GLTF) LoadMesh(meshIdx int) (core.INode, error)
- func (g *GLTF) LoadNode(nodeIdx int) (core.INode, error)
- func (g *GLTF) LoadScene(sceneIdx int) (core.INode, error)
- func (g *GLTF) LoadSkin(skinIdx int) (*graphic.Skeleton, error)
- func (g *GLTF) LoadTexture(texIdx int) (*texture.Texture2D, error)
- type Image
- type Indices
- type Material
- type Mesh
- type Node
- type NormalTextureInfo
- type OcclusionTextureInfo
- type Orthographic
- type PbrMetallicRoughness
- type Perspective
- type Primitive
- type Sampler
- type Scene
- type Skin
- type Sparse
- type Target
- type Texture
- type TextureInfo
- type Values
Constants ¶
const ( KhrDracoMeshCompression = "KHR_draco_mesh_compression" KhrMaterialsUnlit = "KHR_materials_unlit" KhrMaterialsCommon = "KHR_materials_common" // TODO this is officially part of glTF 1.0 (remove?) KhrMaterialsPbrSpecularGlossiness = "KHR_materials_pbrSpecularGlossiness" )
glTF Extensions.
const ( POINTS = 0 LINES = 1 LINE_LOOP = 2 LINE_STRIP = 3 TRIANGLES = 4 TRIANGLE_STRIP = 5 TRIANGLE_FAN = 6 )
Primitive types.
const ( ARRAY_BUFFER = 34962 // For vertex attributes ELEMENT_ARRAY_BUFFER = 34963 // For indices )
OpenGL array types.
const ( NEAREST = 9728 LINEAR = 9729 NEAREST_MIPMAP_NEAREST = 9984 LINEAR_MIPMAP_NEAREST = 9985 NEAREST_MIPMAP_LINEAR = 9986 LINEAR_MIPMAP_LINEAR = 9987 )
Texture filtering modes.
const ( CLAMP_TO_EDGE = 33071 MIRRORED_REPEAT = 33648 REPEAT = 10497 )
Texture sampling modes.
const ( BYTE = 5120 UNSIGNED_BYTE = 5121 SHORT = 5122 UNSIGNED_SHORT = 5123 UNSIGNED_INT = 5125 FLOAT = 5126 )
Possible componentType values.
const ( SCALAR = "SCALAR" VEC2 = "VEC2" VEC3 = "VEC3" VEC4 = "VEC4" MAT2 = "MAT2" MAT3 = "MAT3" MAT4 = "MAT4" )
Attribute element types.
const ( GLBMagic = 0x46546C67 GLBJson = 0x4E4F534A GLBBin = 0x004E4942 )
Variables ¶
var AttributeName = map[string]gls.AttribType{ "POSITION": gls.VertexPosition, "NORMAL": gls.VertexNormal, "TANGENT": gls.VertexTangent, "TEXCOORD_0": gls.VertexTexcoord, "TEXCOORD_1": gls.VertexTexcoord2, "COLOR_0": gls.VertexColor, "JOINTS_0": gls.SkinIndex, "WEIGHTS_0": gls.SkinWeight, }
AttributeName maps the glTF attribute name to the internal g3n attribute type.
var TypeSizes = map[string]int{ SCALAR: 1, VEC2: 2, VEC3: 3, VEC4: 4, MAT2: 4, MAT3: 9, MAT4: 16, }
TypeSizes maps an attribute element type to the number of components it contains.
Functions ¶
This section is empty.
Types ¶
type Accessor ¶
type Accessor struct { BufferView *int // The index of the buffer view. Not required. ByteOffset *int // The offset relative to the start of the BufferView in bytes. Not required. Default is 0. ComponentType int // The data type of components in the attribute. Required. Normalized bool // Specifies whether integer data values should be normalized. Not required. Default is false. Count int // The number of attributes referenced by this accessor. Required. Type string // Specifies if the attribute is a scalar, vector or matrix. Required. Max []float32 // Maximum value of each component in this attribute. Not required. Min []float32 // Minimum value of each component in this attribute. Not required. Sparse *Sparse // Sparse storage attribute that deviates from their initialization value. Not required. Name string // The user-defined name of this object. Not required. Extensions map[string]interface{} // Dictionary object with extension specific objects. Not required. Extras interface{} // Application-specific data. Not required. // contains filtered or unexported fields }
Accessor is a typed view into a BufferView.
type Animation ¶
type Animation struct { Channels []Channel // An array of channels, each of which targets an animation's sampler at a node's property. Different channels of the same animation can't have equal targets. Required. Samplers []AnimationSampler // An array of samplers that combines input and output accessors with an interpolation algorithm to define a keyframe graph (but not its target). Required. Name string // The user-defined name of this object. Not required. Extensions map[string]interface{} // Dictionary object with extension specific objects. Not required. Extras interface{} // Application-specific data. Not required. // contains filtered or unexported fields }
Animation is a keyframe animation.
type AnimationSampler ¶
type AnimationSampler struct { Input int // The index of an accessor containing keyframe input values, e.g., time. Required. Interpolation string // Interpolation algorithm. Not required. Default is "LINEAR". Output int // The index of an accessor, containing keyframe output values. Required. Extensions map[string]interface{} // Dictionary object with extension-specific objects. Not required. Extras interface{} // Application-specific data. Not required. }
AnimationSample combines input and output accessors with an interpolation algorithm to define a keyframe graph (but not its target).
type Asset ¶
type Asset struct { Copyright string // A copyright message suitable for display to credit the content creator. Not required. Generator string // Tool that generated this glTF model. Useful for debugging. Not required. Version string // The glTF version that this asset targets. Required. MinVersion string // The minimum glTF version that this asset targets. Not required. Extensions map[string]interface{} // Dictionary object with extension-specific objects. Not required. Extras interface{} // Application-specific data. Not required. }
Asset contains metadata about the glTF asset.
type Buffer ¶
type Buffer struct { Uri string // The URI of the buffer. Not required. ByteLength int // The length of the buffer in bytes. Required. Name string // The user-defined name of this object. Not required. Extensions map[string]interface{} // Dictionary object with extension-specific objects. Not required. Extras interface{} // Application-specific data. Not required. // contains filtered or unexported fields }
Buffer points to binary geometry, animation, or skins.
type BufferView ¶
type BufferView struct { Buffer int // The index of the buffer. Required. ByteOffset *int // The offset into the buffer, in bytes. Not required. Default is 0. ByteLength int // The length of the buffer view, in bytes. Required. ByteStride *int // The stride, in bytes. Not required. Target *int // The target that the GPU buffer should be bound to. Not required. Name string // The user-defined name of this object. Not required. Extensions map[string]interface{} // Dictionary object with extension specific objects. Not required. Extras interface{} // Application-specific data. Not required. // contains filtered or unexported fields }
BufferView is a view into a buffer generally representing a subset of the buffer.
type Camera ¶
type Camera struct { Orthographic *Orthographic // An orthographic camera containing properties to create an orthographic projection matrix. Not required. Perspective *Perspective // A perspective camera containing properties to create a perspective projection matrix. Not required. Type string // Specifies if the camera uses a perspective or orthographic projection. Required. Name string // The user-defined name of this object. Not required. Extensions map[string]interface{} // Dictionary object with extension-specific objects. Not required. Extras interface{} // Application-specific data. Not required. // contains filtered or unexported fields }
Camera is a camera's projection. A node can reference a camera to apply a transform to place the camera in the scene.
type Channel ¶
type Channel struct { Sampler int // The index of a sampler in this animation used to compute the value for the target. Required. Target Target // The index of the node and TRS property to target. Required. Extensions map[string]interface{} // Dictionary object with extension-specific objects. Not required. Extras interface{} // Application-specific data. Not required. }
Channel targets an animation's sampler at a node's property.
type GLTF ¶
type GLTF struct { ExtensionsUsed []string // Names of glTF extensions used somewhere in this asset. Not required. ExtensionsRequired []string // Names of glTF extensions required to properly load this asset. Not required. Accessors []Accessor // An array of accessors. Not required. Animations []Animation // An array of keyframe animations. Not required. Asset Asset // Metadata about the glTF asset. Required. Buffers []Buffer // An array of buffers. Not required. BufferViews []BufferView // An array of bufferViews. Not required. Cameras []Camera // An array of cameras. Not required. Images []Image // An array of images. Not required. Materials []Material // An array of materials. Not required. Meshes []Mesh // An array of meshes. Not required. Nodes []Node // An array of nodes. Not required. Samplers []Sampler // An array of samplers. Not required. Scene *int // The index of the default scene. Not required. Scenes []Scene // An array of scenes. Not required. Skins []Skin // An array of skins. Not required. Textures []Texture // An array of textures. Not required. Extensions map[string]interface{} // Dictionary object with extension-specific objects. Not required. Extras interface{} // Application-specific data. Not required. // contains filtered or unexported fields }
GLTF is the root object for a glTF asset.
func ParseBin ¶
ParseBin parses the glTF data from the specified binary file and returns a pointer to the parsed structure.
func ParseBinReader ¶
ParseBinReader parses the glTF data from the specified binary reader and returns a pointer to the parsed structure
func ParseJSON ¶
ParseJSON parses the glTF data from the specified JSON file and returns a pointer to the parsed structure.
func ParseJSONReader ¶
ParseJSONReader parses the glTF JSON data from the specified reader and returns a pointer to the parsed structure
func (*GLTF) LoadAnimation ¶
LoadAnimation creates an Animation for the specified animation index from the GLTF Animations array.
func (*GLTF) LoadAnimationByName ¶
LoadAnimationByName loads the animations with specified name. If there are multiple animations with the same name it loads the first occurrence.
func (*GLTF) LoadCamera ¶
LoadCamera creates and returns a Camera Node from the specified GLTF.Cameras index.
func (*GLTF) LoadImage ¶
LoadImage loads the image specified by the index of GLTF.Images. Image can be loaded from binary chunk file or data URI or external file..
func (*GLTF) LoadMaterial ¶
LoadMaterial creates and returns a new material based on the material data with the specified index.
func (*GLTF) LoadMesh ¶
LoadMesh creates and returns a Graphic Node (graphic.Mesh, graphic.Lines, graphic.Points, etc) from the specified GLTF.Meshes index.
func (*GLTF) LoadNode ¶
LoadNode creates and returns a new Node described by the specified index in the decoded GLTF Nodes array.
func (*GLTF) LoadScene ¶
LoadScene creates a parent Node which contains all nodes contained by the specified scene index from the GLTF Scenes array.
type Image ¶
type Image struct { Uri string // The URI of the image. Not required. MimeType string // The image's MIME type. Not required. BufferView *int // The index of the bufferView that contains the image. Use this instead of the image's uri property. Not required. Name string // The user-defined name of this object. Not required. Extensions map[string]interface{} // Dictionary object with extension-specific objects. Not required. Extras interface{} // Application-specific data. Not required. // contains filtered or unexported fields }
Image data used to create a texture. Image can be referenced by URI or bufferView index. mimeType is required in the latter case.
type Indices ¶
type Indices struct { BufferView int // The index of the bufferView with sparse indices. Referenced bufferView can't have ARRAY_BUFFER or ELEMENT_ARRAY_BUFFER target. Required. ByteOffset int // The offset relative to the start of the bufferView in bytes. Must be aligned. Not required. Default is 0. ComponentType int // The indices data type. Required. Extensions map[string]interface{} // Dictionary object with extension-specific objects. Not required. Extras interface{} // Application-specific data. Not required. }
Indices of those attributes that deviate from their initialization value.
type Material ¶
type Material struct { Name string // The user-defined name of this object. Not required. PbrMetallicRoughness *PbrMetallicRoughness // A set of parameter values that are used to define the metallic-roughness material model from Physically-Based Rendering (PBR) methodology. When not specified, all the default values of pbrMetallicRoughness apply. Not required. NormalTexture *NormalTextureInfo // The normal map texture. Not required. OcclusionTexture *OcclusionTextureInfo // The occlusion map texture. Not required. EmissiveTexture *TextureInfo // The emissive map texture. Not required. EmissiveFactor *[3]float32 // The emissive color of the material. Not required. Default is [0,0,0] AlphaMode string // The alpha rendering mode of the material. Not required. Default is OPAQUE. AlphaCutoff float32 // The alpha cutoff value of the material. Not required. Default is 0.5. DoubleSided bool // Specifies whether the material is double sided. Not required. Default is false. Extensions map[string]interface{} // Dictionary object with extension-specific objects. Not required. Extras interface{} // Application-specific data. Not required. // contains filtered or unexported fields }
Material describes the material appearance of a primitive.
type Mesh ¶
type Mesh struct { Primitives []Primitive // An array of primitives, each defining geometry to be rendered with a material. Required. Weights []float32 // Array of weights to be applied to the Morph Targets. Not required. Name string // The user-defined name of this object. Not required. Extensions map[string]interface{} // Dictionary object with extension-specific objects. Not required. Extras interface{} // Application-specific data. Not required. // contains filtered or unexported fields }
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 Node ¶
type Node struct { Camera *int // Index of the camera referenced by this node. Not required. Children []int // The indices of this node's children. Not required. Skin *int // The index of the skin referenced by this node. Not required. Matrix *[16]float32 // Floating point 4x4 transformation matrix in column-major order. Not required. Default is the identity matrix. Mesh *int // The index of the mesh in this node. Not required. Rotation *[4]float32 // The node's unit quaternion rotation in the order (x, y, z, w), where w is the scalar. Not required. Default is [0,0,0,1]. Scale *[3]float32 // The node's non-uniform scale, given as the scaling factors along the x, y, and z axes. Not required. Default is [1,1,1]. Translation *[3]float32 // The node's translation along the x, y, and z axes. Not required. Default is [0,0,0]. Weights []float32 // The weights of the instantiated Morph Target. Number of elements must match number of Morph Targets of used mesh. Not required. Name string // The user-defined name of this object. Not required. Extensions map[string]interface{} // Dictionary object with extension-specific objects. Not required. Extras interface{} // Application-specific data. Not required. // contains filtered or unexported fields }
Node is a node in the node hierarchy. When the node contains skin, all mesh.primitives must contain JOINTS_0 and WEIGHTS_0 attributes. A node can have either a matrix or any combination of translation/rotation/scale (TRS) properties. TRS properties are converted to matrices and postmultiplied in the T * R * S order to compose the transformation matrix; first the scale is applied to the vertices, then the rotation, and then the translation. If none are provided, the transform is the identity. When a node is targeted for animation (referenced by an animation.channel.target), only TRS properties may be present; matrix will not be present.
type NormalTextureInfo ¶
type NormalTextureInfo struct { Index int // The index of the texture. Required. TexCoord int // The set index of texture's TEXCOORD attribute used for texture coordinate mapping. Not required. Default is 0. Scale float32 // The scalar multiplier applied to each normal vector of the normal texture. Not required. Default is 1. Extensions map[string]interface{} // Dictionary object with extension-specific objects. Not required. Extras interface{} // Application-specific data. Not required. }
NormalTextureInfo is a reference to a texture.
type OcclusionTextureInfo ¶
type OcclusionTextureInfo struct { Index int // The index of the texture. Required. TexCoord int // The set index of texture's TEXCOORD attribute used for texture coordinate mapping. Not required. Default is 0. Strength float32 // The scalar multiplier controlling the amount of occlusion applied. Not required. Default is 1. Extensions map[string]interface{} // Dictionary object with extension-specific objects. Not required. Extras interface{} // Application-specific data. Not required. }
OcclusionTextureInfo is a reference to a texture.
type Orthographic ¶
type Orthographic struct { Xmag float32 // The floating-point horizontal magnification of the view. Required. Ymag float32 // The floating-point vertical magnification of the view. Required. Zfar float32 // The floating-point distance to the far clipping plane. Zfar must be greater than Znear. Required. Znear float32 // The floating-point distance to the near clipping plane. Required. Extensions map[string]interface{} // Dictionary object with extension-specific objects. Not required. Extras interface{} // Application-specific data. Not required. }
Orthographic is an orthographic camera containing properties to create an orthographic projection matrix.
type PbrMetallicRoughness ¶
type PbrMetallicRoughness struct { BaseColorFactor *[4]float32 // The material's base color factor. Not required. Default is [1,1,1,1] BaseColorTexture *TextureInfo // The base color texture. Not required. MetallicFactor *float32 // The metalness of the material. Not required. Default is 1. RoughnessFactor *float32 // The roughness of the material. Not required. Default is 1. MetallicRoughnessTexture *TextureInfo // The metallic-roughness texture. Not required. Extensions map[string]interface{} // Dictionary object with extension-specific objects. Not required. Extras interface{} // Application-specific data. Not required. }
PbrMetallicRoughness is a set of parameter values that are used to define the metallic-roughness material model from Physically-Based Rendering (PBR) methodology.
type Perspective ¶
type Perspective struct { AspectRatio *float32 // The floating-point aspect ratio of the field of view. Not required. Yfov float32 // The floating-point vertical field of view in radians. Required. Zfar *float32 // The floating-point distance to the far clipping plane. Not required. Znear float32 // The floating-point distance to the near clipping plane. Required. Extensions map[string]interface{} // Dictionary object with extension-specific objects. Not required. Extras interface{} // Application-specific data. Not required. }
Perspective is a perspective camera containing properties to create a perspective projection matrix.
type Primitive ¶
type Primitive struct { Attributes map[string]int // A dictionary object, where each key corresponds to mesh attribute semantic and each value is the index of the accessor containing attribute's data. Required. Indices *int // The index of the accessor that contains the indices. Not required. Material *int // The index of the material to apply to this primitive when rendering. Not required. Mode *int // The type of primitives to render. Not required. Default is 4 (TRIANGLES). Targets []map[string]int // An array of Morph Targets. Each Morph Target is a dictionary mapping attributes (only POSITION, NORMAL, and TANGENT supported) to their deviations in the Morph Target. Extensions map[string]interface{} // Dictionary object with extension-specific objects. Not required. Extras interface{} // Application-specific data. Not required. }
Primitive represents geometry to be rendered with the given material.
type Sampler ¶
type Sampler struct { MagFilter *int // Magnification filter. Not required. MinFilter *int // Minification filter. Not required. WrapS *int // s coordinate wrapping mode. Not required. Default is 10497 (REPEAT). WrapT *int // t coordinate wrapping mode. Not required. Default is 10497 (REPEAT). Name string // The user-defined name of this object. Not required. Extensions map[string]interface{} // Dictionary object with extension-specific objects. Not required. Extras interface{} // Application-specific data. Not required. }
Sampler represents a texture sampler with properties for filtering and wrapping modes.
type Scene ¶
type Scene struct { Nodes []int // The indices of the root nodes. Not required. Name string // The user-defined name of this object. Not required. Extensions map[string]interface{} // Dictionary object with extension-specific objects. Not required. Not required. Extras interface{} // Application-specific data. Not required. Not required. }
Scene contains root nodes.
type Skin ¶
type Skin struct { InverseBindMatrices int // The index of the accessor containing the floating-point 4x4 inverse-bind matrices. The default is that each matrix is a 4x4 identity matrix, which implies that inverse-bind matrices were pre-applied. Not required. Skeleton *int // The index of the node used as a skeleton root. When undefined, joints transforms resolve to scene root. Not required. Joints []int // Indices of skeleton nodes, used as joints in this skin. Required. Name string // The user-define named of this object. Not required. Extensions map[string]interface{} // Dictionary object with extension-specific objects. Not required. Extras interface{} // Application-specific data. Not required. // contains filtered or unexported fields }
Joints and matrices defining a skin.
type Sparse ¶
type Sparse struct { Count int // Number of entries stored in the sparse array. Required. Indices []int // Index array of size count that points to those accessor attributes that deviate from their initialization value. Indices must strictly increase. Required. Values []int // Array of size count times number of components, storing the displaced accessor attributes pointed by indices. Substituted values must have the same componentType and number of components as the base accessor. Required. Extensions map[string]interface{} // Dictionary object with extension-specific objects. Not required. Extras interface{} // Application-specific data. Not required. }
Sparse storage of attributes that deviate from their initialization value.
type Target ¶
type Target struct { Node int // The index of the node to target. Not required. Path string // The name of the node's TRS property to modify, or the "weights" of the Morph Targets it instantiates. Required. // 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. Extensions map[string]interface{} // Dictionary object with extension-specific objects. Not required. Extras interface{} // Application-specific data. Not required. }
Target represents the index of the node and TRS property than an animation channel targets.
type Texture ¶
type Texture struct { Sampler *int // The index of the sampler used by this texture. When undefined, a sampler with REPEAT wrapping and AUTO filtering should be used. Not required. Source int // The index of the image used by this texture. Not required. Name string // The user-defined name of this object. Not required. Extensions map[string]interface{} // Dictionary object with extension-specific objects. Not required. Not required. Extras interface{} // Application-specific data. Not required. Not required. }
Texture represents a texture and its sampler.
type TextureInfo ¶
type TextureInfo struct { Index int // The index of the texture. Required. TexCoord int // The set index of texture's TEXCOORD attribute used for texture coordinate mapping. Not required. Default is 0. Extensions map[string]interface{} // Dictionary object with extension-specific objects. Not required. Extras interface{} // Application-specific data. Not required. }
TextureInfo is a reference to a texture.
type Values ¶
type Values struct { BufferView int // The index of the bufferView with sparse values. Referenced bufferView can't have ARRAY_BUFFER or ELEMENT_ARRAY_BUFFER target. Required. ByteOffset int // The offset relative to the start of the bufferView in bytes. Must be aligned. Not required. Default is 0. Extensions map[string]interface{} // Dictionary object with extension-specific objects. Not required. Extras interface{} // Application-specific data. Not required. }
Values is an array of size accessor.sparse.count times number of components storing the displaced accessor attributes pointed by accessor.sparse.indices.