Documentation
¶
Overview ¶
Package gltf provides functionality to read and write GLTF 2.0 files.
The reading API is designed to be flexible and support various use cases:
Simple file loading: doc, buffers, err := gltf.LoadFile("model.gltf", nil) models, err := gltf.DecodeModels(doc, buffers, "", nil)
Loading from memory/streams: doc, buffers, err := gltf.Load(reader, nil)
Custom resource loading (e.g., from database): opts := &gltf.ReaderOptions{ BufferLoader: myBufferLoader, ImageLoader: myImageLoader, } doc, buffers, err := gltf.Load(reader, opts)
Parsing without loading resources: doc, err := gltf.Parse(reader) // Process doc structure, then load resources as needed
Index ¶
- Constants
- Variables
- func Save(modelPath string, scene PolyformScene, options *WriterOptions) error
- func SaveBinary(gltfPath string, scene PolyformScene, options *WriterOptions) error
- func SaveText(gltfPath string, scene PolyformScene, options *WriterOptions) error
- func WriteBinary(scene PolyformScene, out io.Writer, options *WriterOptions) error
- func WriteText(scene PolyformScene, out io.Writer, options *WriterOptions) error
- type Accessor
- type AccessorComponentType
- type AccessorType
- type Animation
- type AnimationChannel
- type AnimationChannelTarget
- type AnimationChannelTargetPath
- type AnimationSampler
- type AnimationSamplerInterpolation
- type Artifact
- type Asset
- type Buffer
- type BufferEmbeddingStrategy
- type BufferLoader
- type BufferView
- type BufferViewTarget
- type Camera
- type ChildOfRootProperty
- type ExtGpuInstancing
- type Extensions
- type Extra
- type Gltf
- func ExperimentalLoad(gltfPath string, options *ReaderOptions) (*Gltf, [][]byte, error)deprecated
- func Load(r io.Reader, options *ReaderOptions) (*Gltf, [][]byte, error)
- func LoadFile(gltfPath string, options *ReaderOptions) (*Gltf, [][]byte, error)
- func Parse(r io.Reader) (*Gltf, error)
- func ParseFile(gltfPath string) (*Gltf, error)
- type GltfId
- type Image
- type ImageLoader
- type ImageMimeType
- type JsonFormat
- type KHR_LightsPunctual
- type KHR_LightsPunctualType
- type ManifestNode
- type Material
- type MaterialAlphaMode
- type MaterialAnisotropyExtensionNode
- type MaterialClearcoatExtensionNode
- type MaterialExtension
- type MaterialNode
- type MaterialTransmissionExtensionNode
- type MaterialVolumeExtensionNode
- type Mesh
- type ModelNode
- type NoOpImageLoader
- type Node
- type NormalTexture
- type NormalTextureNode
- type OcclusionTexture
- type PbrMetallicRoughness
- type PolyformAnisotropy
- type PolyformClearcoat
- type PolyformDispersion
- type PolyformEmissiveStrength
- type PolyformIndexOfRefraction
- type PolyformIridescence
- type PolyformMaterial
- type PolyformModel
- type PolyformNormal
- type PolyformOcclusion
- type PolyformPbrMetallicRoughness
- type PolyformPbrSpecularGlossiness
- type PolyformScene
- type PolyformSheen
- type PolyformSpecular
- type PolyformTexture
- type PolyformTextureTransform
- type PolyformTransmission
- type PolyformUnlit
- type PolyformVolume
- type Primitive
- type PrimitiveMode
- type Property
- type ReaderOptions
- type Sampler
- type SamplerMagFilter
- type SamplerMagFilterNode
- type SamplerMinFilter
- type SamplerMinFilterNode
- type SamplerNode
- type SamplerWrap
- type SamplerWrapNode
- type Scene
- type Skin
- type StandardLoader
- type Texture
- type TextureExtension
- type TextureInfo
- type TextureNode
- type TextureReferenceNode
- type Writer
- func (w *Writer) AddAnimations(animations []animation.Sequence, skeleton animation.Skeleton, skeletonNode int)
- func (w *Writer) AddLight(light KHR_LightsPunctual)
- func (w *Writer) AddMaterial(mat *PolyformMaterial) (*int, error)
- func (w *Writer) AddModel(model PolyformModel) (_ int, err error)
- func (w *Writer) AddScene(scene PolyformScene) error
- func (w *Writer) AddSkin(skeleton animation.Skeleton) (*int, int)
- func (w *Writer) AddTexture(polyTex *PolyformTexture) *TextureInfo
- func (w *Writer) Align(alignment int)
- func (w Writer) ToGLTF(embeddingStrategy BufferEmbeddingStrategy) Gltf
- func (w Writer) WriteGLB(out io.Writer, opts WriterOptions) error
- func (w *Writer) WriteIndices(indices *iter.ArrayIterator[int], attributeSize int)
- func (w *Writer) WriteVector2(accessorComponentType AccessorComponentType, ...)
- func (w Writer) WriteVector2AsByte(v vector2.Float64)
- func (w Writer) WriteVector2AsFloat32(v vector2.Float64)
- func (w *Writer) WriteVector3(accessorComponentType AccessorComponentType, ...)
- func (w Writer) WriteVector3AsByte(v vector3.Float64)
- func (w Writer) WriteVector3AsFloat32(v vector3.Float64)
- func (w *Writer) WriteVector4(accessorComponentType AccessorComponentType, ...)
- func (w Writer) WriteVector4AsByte(v vector4.Float64)
- func (w Writer) WriteVector4AsFloat32(v vector4.Float64)
- type WriterOptions
Constants ¶
const ( POSITION = "POSITION" NORMAL = "NORMAL" TANGENT = "TANGENT" TEXCOORD_0 = "TEXCOORD_0" COLOR_0 = "COLOR_0" JOINTS_0 = "JOINTS_0" WEIGHTS_0 = "WEIGHTS_0" )
https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.pdf Page 39
Variables ¶
var ErrInvalidInput = errors.New("invalid input")
Functions ¶
func Save ¶ added in v0.14.0
func Save(modelPath string, scene PolyformScene, options *WriterOptions) error
Save writes the mesh to the path in the format dictated by the extension in the path
func SaveBinary ¶ added in v0.9.0
func SaveBinary(gltfPath string, scene PolyformScene, options *WriterOptions) error
SaveBinary writes the mesh to the path specified in GLB format
func SaveText ¶
func SaveText(gltfPath string, scene PolyformScene, options *WriterOptions) error
SaveText writes the mesh to the path specified in GLTF format with the provided options
func WriteBinary ¶ added in v0.9.0
func WriteBinary(scene PolyformScene, out io.Writer, options *WriterOptions) error
func WriteText ¶
func WriteText(scene PolyformScene, out io.Writer, options *WriterOptions) error
Types ¶
type Accessor ¶
type Accessor struct {
ChildOfRootProperty
BufferView *GltfId `json:"bufferView,omitempty"` // The index of the buffer view. When undefined, the accessor **MUST** be initialized with zeros; `sparse` property or extensions **MAY** override zeros with actual values.
ByteOffset int `json:"byteOffset,omitempty"` // The offset relative to the start of the buffer view in bytes. This **MUST** be a multiple of the size of the component datatype. This property **MUST NOT** be defined when `bufferView` is undefined.
ComponentType AccessorComponentType `json:"componentType"` // The datatype of the accessor's components. UNSIGNED_INT type **MUST NOT** be used for any accessor that is not referenced by `mesh.primitive.indices`.
Normalized bool `json:"normalized,omitempty"` // Specifies whether integer data values are normalized (`true`) to [0, 1] (for unsigned types) or to [-1, 1] (for signed types) when they are accessed. This property **MUST NOT** be set to `true` for accessors with `FLOAT` or `UNSIGNED_INT` component type.
Type AccessorType `json:"type"` // Specifies if the accessor's elements are scalars, vectors, or matrices.
Count int `json:"count"` // The number of elements referenced by this accessor, not to be confused with the number of bytes or number of components.
Max []float64 `json:"max,omitempty"` // Maximum value of each component in this accessor. Array elements **MUST** be treated as having the same data type as accessor's `componentType`. Both `min` and `max` arrays have the same length. The length is determined by the value of the `type` property; it can be 1, 2, 3, 4, 9, or 16.\n\n`normalized` property has no effect on array values: they always correspond to the actual values stored in the buffer. When the accessor is sparse, this property **MUST** contain maximum values of accessor data with sparse substitution applied.
Min []float64 `json:"min,omitempty"` // Minimum value of each component in this accessor. Array elements **MUST** be treated as having the same data type as accessor's `componentType`. Both `min` and `max` arrays have the same length. The length is determined by the value of the `type` property; it can be 1, 2, 3, 4, 9, or 16.\n\n`normalized` property has no effect on array values: they always correspond to the actual values stored in the buffer. When the accessor is sparse, this property **MUST** contain minimum values of accessor data with sparse substitution applied.
}
A typed view into a buffer view that contains raw binary data. https://github.com/KhronosGroup/glTF/blob/main/specification/2.0/schema/accessor.schema.json
type AccessorComponentType ¶
type AccessorComponentType int
const ( AccessorComponentType_BYTE AccessorComponentType = 5120 AccessorComponentType_UNSIGNED_BYTE AccessorComponentType = 5121 AccessorComponentType_SHORT AccessorComponentType = 5122 AccessorComponentType_UNSIGNED_SHORT AccessorComponentType = 5123 AccessorComponentType_UNSIGNED_INT AccessorComponentType = 5125 AccessorComponentType_FLOAT AccessorComponentType = 5126 )
func (AccessorComponentType) Size ¶ added in v0.5.0
func (act AccessorComponentType) Size() int
type AccessorType ¶
type AccessorType string
const ( AccessorType_SCALAR AccessorType = "SCALAR" AccessorType_VEC2 AccessorType = "VEC2" AccessorType_VEC3 AccessorType = "VEC3" AccessorType_VEC4 AccessorType = "VEC4" AccessorType_MAT2 AccessorType = "MAT2" AccessorType_MAT3 AccessorType = "MAT3" AccessorType_MAT4 AccessorType = "MAT4" )
type Animation ¶
type Animation struct {
ChildOfRootProperty
Channels []AnimationChannel `json:"channels"` // An array of animation channels. An animation channel combines an animation sampler with a target property being animated. Different channels of the same animation **MUST NOT** have the same targets.
Samplers []AnimationSampler `json:"samplers"` // An array of animation samplers. An animation sampler combines timestamps with a sequence of output values and defines an interpolation algorithm.
}
A keyframe animation. https://github.com/KhronosGroup/glTF/blob/main/specification/2.0/schema/animation.schema.json
type AnimationChannel ¶
type AnimationChannel struct {
Property
Sampler GltfId `json:"sampler"` // The index of a sampler in this animation used to compute the value for the target, e.g., a node's translation, rotation, or scale (TRS).
Target AnimationChannelTarget `json:"target"` // The descriptor of the animated property.
}
An animation channel combines an animation sampler with a target property being animated. https://github.com/KhronosGroup/glTF/blob/main/specification/2.0/schema/animation.channel.schema.json
type AnimationChannelTarget ¶
type AnimationChannelTarget struct {
Property
Node GltfId `json:"node,omitempty"`
Path AnimationChannelTargetPath `json:"path"`
}
The descriptor of the animated property. https://github.com/KhronosGroup/glTF/blob/main/specification/2.0/schema/animation.channel.target.schema.json
type AnimationChannelTargetPath ¶
type AnimationChannelTargetPath string
const ( AnimationChannelTargetPath_TRANSLATION AnimationChannelTargetPath = "translation" AnimationChannelTargetPath_ROTATION AnimationChannelTargetPath = "rotation" AnimationChannelTargetPath_SCALE AnimationChannelTargetPath = "scale" AnimationChannelTargetPath_WEIGHTS AnimationChannelTargetPath = "weights" )
type AnimationSampler ¶
type AnimationSampler struct {
Property
Input GltfId `json:"input"` // The index of an accessor containing keyframe timestamps. The accessor **MUST** be of scalar type with floating-point components. The values represent time in seconds with `time[0] >= 0.0`, and strictly increasing values, i.e., `time[n + 1] > time[n]`.
Output GltfId `json:"output"` // The index of an accessor, containing keyframe output values.
Interpolation AnimationSamplerInterpolation `json:"interpolation,omitempty"` // The index of an accessor, containing keyframe output values.
}
An animation sampler combines timestamps with a sequence of output values and defines an interpolation algorithm. https://github.com/KhronosGroup/glTF/blob/main/specification/2.0/schema/animation.sampler.schema.json
type AnimationSamplerInterpolation ¶
type AnimationSamplerInterpolation string
const ( AnimationSamplerInterpolation_LINEAR AnimationSamplerInterpolation = "LINEAR" // The animated values are linearly interpolated between keyframes. When targeting a rotation, spherical linear interpolation (slerp) **SHOULD** be used to interpolate quaternions. The number of output elements **MUST** equal the number of input elements. AnimationSamplerInterpolation_STEP AnimationSamplerInterpolation = "STEP" // The animated values remain constant to the output of the first keyframe, until the next keyframe. The number of output elements **MUST** equal the number of input elements. AnimationSamplerInterpolation_CUBICSPLINE AnimationSamplerInterpolation = "CUBICSPLINE" // The animation's interpolation is computed using a cubic spline with specified tangents. The number of output elements **MUST** equal three times the number of input elements. For each input element, the output stores three elements, an in-tangent, a spline vertex, and an out-tangent. There **MUST** be at least two keyframes when using this interpolation. )
type Artifact ¶ added in v0.21.0
type Artifact struct {
Scene PolyformScene
}
type Asset ¶
type Asset struct {
Property
Version string `json:"version"` // The glTF version in the form of `<major>.<minor>` that this asset targets.
Generator string `json:"generator,omitempty"` // Tool that generated this glTF model. Useful for debugging.
Copyright string `json:"copyright,omitempty"` // A copyright message suitable for display to credit the content creator.
MinVersion string `json:"minVersion,omitempty"` // The minimum glTF version in the form of `<major>.<minor>` that this asset targets. This property **MUST NOT** be greater than the asset version.
}
Metadata about the glTF asset. https://github.com/KhronosGroup/glTF/blob/main/specification/2.0/schema/asset.schema.json
type Buffer ¶
type Buffer struct {
ChildOfRootProperty
ByteLength int `json:"byteLength"` // The length of the buffer in bytes.
URI string `json:"uri,omitempty"` // The URI (or IRI) of the buffer. Relative paths are relative to the current glTF asset. Instead of referencing an external file, this field **MAY** contain a `data:`-URI.
}
A buffer points to binary geometry, animation, or skins. https://github.com/KhronosGroup/glTF/blob/main/specification/2.0/schema/buffer.schema.json
type BufferEmbeddingStrategy ¶ added in v0.9.0
type BufferEmbeddingStrategy int
const ( BufferEmbeddingStrategy_Base64Encode BufferEmbeddingStrategy = iota BufferEmbeddingStrategy_GLB )
type BufferLoader ¶ added in v0.30.0
type BufferLoader interface {
// LoadBuffer loads binary data for the given URI.
// The URI may be a relative path, absolute path, or custom scheme.
LoadBuffer(uri string) ([]byte, error)
}
BufferLoader allows custom buffer resolution when loading GLTF files. This can be used to load buffers from a database, CDN, or other custom source.
type BufferView ¶
type BufferView struct {
ChildOfRootProperty
Buffer int `json:"buffer"` // The index of the buffer
ByteOffset int `json:"byteOffset,omitempty"` // The offset into the buffer in bytes.
ByteLength int `json:"byteLength"` // The length of the bufferView in bytes.
ByteStride *int `json:"byteStride,omitempty"` // The stride, in bytes, between vertex attributes. When this is not defined, data is tightly packed. When two or more accessors use the same buffer view, this field **MUST** be defined.
Target BufferViewTarget `json:"target,omitempty"` // The hint representing the intended GPU buffer type to use with this buffer view.
}
A view into a buffer generally representing a subset of the buffer. https://github.com/KhronosGroup/glTF/blob/main/specification/2.0/schema/bufferView.schema.json
type BufferViewTarget ¶
type BufferViewTarget int
const ( ARRAY_BUFFER BufferViewTarget = 34962 ELEMENT_ARRAY_BUFFER BufferViewTarget = 34963 )
type ChildOfRootProperty ¶
type ExtGpuInstancing ¶ added in v0.18.0
type Extensions ¶ added in v0.9.0
JSON object with extension-specific objects. https://github.com/KhronosGroup/glTF/blob/main/specification/2.0/schema/extension.schema.json
type Extra ¶
Although `extras` **MAY** have any type, it is common for applications to store and access custom data as key/value pairs. Therefore, `extras` **SHOULD** be a JSON object rather than a primitive value for best portability. https://github.com/KhronosGroup/glTF/blob/main/specification/2.0/schema/extras.schema.json
type Gltf ¶
type Gltf struct {
Property
ExtensionsUsed []string `json:"extensionsUsed,omitempty"` // Names of glTF extensions used in this asset.
ExtensionsRequired []string `json:"extensionsRequired,omitempty"` // Names of glTF extensions required to properly load this asset.
Accessors []Accessor `json:"accessors,omitempty"` // An array of accessors. An accessor is a typed view into a bufferView.
Animations []Animation `json:"animations,omitempty"` // An array of keyframe animations.
Asset Asset `json:"asset"` // Metadata about the glTF asset.
Buffers []Buffer `json:"buffers,omitempty"` // An array of buffers. A buffer points to binary geometry, animation, or skins.
BufferViews []BufferView `json:"bufferViews,omitempty"` // An array of bufferViews. A bufferView is a view into a buffer generally representing a subset of the buffer
Cameras []Camera `json:"cameras,omitempty"` // An array of cameras. A camera defines a projection matrix.
Images []Image `json:"images,omitempty"` // An array of images. An image defines data used to create a texture.
Materials []Material `json:"materials,omitempty"` // An array of materials. A material defines the appearance of a primitive.
Meshes []Mesh `json:"meshes,omitempty"` // An array of meshes. A mesh is a set of primitives to be rendered
Nodes []Node `json:"nodes,omitempty"` // An array of nodes.
Samplers []Sampler `json:"samplers,omitempty"` // An array of samplers. A sampler contains properties for texture filtering and wrapping modes.
Scene *int `json:"scene,omitempty"` // The index of the default scene. This property **MUST NOT** be defined, when `scenes` is undefined.
Scenes []Scene `json:"scenes,omitempty"` // An array of scenes.
Skins []Skin `json:"skins,omitempty"` // An array of skins. A skin is defined by joints and matrices.
Textures []Texture `json:"textures,omitempty"` // An array of textures
}
The root object for a glTF asset. https://github.com/KhronosGroup/glTF/blob/main/specification/2.0/schema/glTF.schema.json
func ExperimentalLoad
deprecated
added in
v0.25.0
func ExperimentalLoad(gltfPath string, options *ReaderOptions) (*Gltf, [][]byte, error)
Deprecated: Use LoadFile instead. ExperimentalLoad reads a GLTF file from disk and loads all referenced buffers.
func Load ¶ added in v0.30.0
Load reads GLTF JSON from an io.Reader and loads all referenced buffers.
Example with embedded buffer:
jsonData := strings.NewReader(gltfJSON) // GLTF with data URI buffers doc, buffers, err := gltf.Load(jsonData, nil)
Example with custom loader:
opts := &gltf.ReaderOptions{
BufferLoader: myCustomLoader,
}
doc, buffers, err := gltf.Load(jsonData, opts)
If a custom BufferLoader is provided in options, it will be used to load buffers. Otherwise, a StandardLoader is used with options.BasePath (or current directory).
func LoadFile ¶ added in v0.30.0
func LoadFile(gltfPath string, options *ReaderOptions) (*Gltf, [][]byte, error)
LoadFile reads a GLTF file from disk and loads all referenced buffers. The directory containing the GLTF file is used as the base path for resolving relative URIs.
Example:
doc, buffers, err := gltf.LoadFile("model.gltf", nil)
if err != nil {
log.Fatal(err)
}
Example with custom image loader:
opts := &gltf.ReaderOptions{
ImageLoader: &gltf.NoOpImageLoader{}, // Skip loading texture files
}
doc, buffers, err := gltf.LoadFile("model.gltf", opts)
func Parse ¶ added in v0.30.0
Parse reads and parses GLTF JSON from an io.Reader. This only parses the JSON structure without loading any external resources like buffers or images. Use Load or LoadFile if you need to load external resources.
Example:
jsonData := strings.NewReader(gltfJSON)
doc, err := gltf.Parse(jsonData)
if err != nil {
log.Fatal(err)
}
func ParseFile ¶ added in v0.30.0
ParseFile reads and parses a GLTF JSON file from disk. This only parses the JSON structure without loading any external resources like buffers or images. Use LoadFile if you need to load external resources.
Example:
doc, err := gltf.ParseFile("model.gltf")
if err != nil {
log.Fatal(err)
}
type Image ¶
type Image struct {
ChildOfRootProperty
MimeType ImageMimeType `json:"mimeType,omitempty"` // The image's media type. This field **MUST** be defined when `bufferView` is defined.
URI string `json:"uri,omitempty"` // The URI (or IRI) of the image. Relative paths are relative to the current glTF asset. Instead of referencing an external file, this field **MAY** contain a `data:`-URI. This field **MUST NOT** be defined when `bufferView` is defined.
BufferView *GltfId `json:"bufferView,omitempty"` // The index of the bufferView that contains the image. This field **MUST NOT** be defined when `uri` is defined.
}
Image data used to create a texture. Image **MAY** be referenced by an URI (or IRI) or a buffer view index. https://github.com/KhronosGroup/glTF/blob/main/specification/2.0/schema/image.schema.json
type ImageLoader ¶ added in v0.30.0
type ImageLoader interface {
// LoadImage loads an image for the given URI.
// The URI may be a relative path, absolute path, or custom scheme.
LoadImage(uri string) (image.Image, string, error)
}
ImageLoader allows custom image resolution when loading GLTF files. This can be used to load images from a database, CDN, or other custom source.
type ImageMimeType ¶
type ImageMimeType string
const ( ImageMimeType_JPEG ImageMimeType = "image/jpeg" ImageMimeType_PNG ImageMimeType = "image/png" )
type JsonFormat ¶ added in v0.30.0
type JsonFormat int
JsonFormat specifies the JSON output format for GLTF export
const ( // DefaultJsonFormat uses the library's default JSON formatting (pretty-printed with indentation) DefaultJsonFormat JsonFormat = iota // MinifyJsonFormat produces compact JSON output without indentation MinifyJsonFormat // PrettyJsonFormat explicitly specifies pretty-printed JSON with indentation (same as default) PrettyJsonFormat )
type KHR_LightsPunctual ¶ added in v0.9.0
type KHR_LightsPunctual struct {
Type KHR_LightsPunctualType
Name *string
Color color.Color
Intensity *float64
Range *float64
Position vector3.Float64
}
func (KHR_LightsPunctual) ToExtension ¶ added in v0.9.0
func (khr_lp KHR_LightsPunctual) ToExtension() map[string]any
type KHR_LightsPunctualType ¶ added in v0.9.0
type KHR_LightsPunctualType string
const ( KHR_LightsPunctualType_Directional KHR_LightsPunctualType = "directional" KHR_LightsPunctualType_Point KHR_LightsPunctualType = "point" KHR_LightsPunctualType_Spot KHR_LightsPunctualType = "spot" )
type ManifestNode ¶ added in v0.25.0
type ManifestNode struct {
Models []nodes.Output[PolyformModel]
}
func (ManifestNode) Out ¶ added in v0.32.0
func (gad ManifestNode) Out(out *nodes.StructOutput[manifest.Manifest])
type Material ¶
type Material struct {
ChildOfRootProperty
// A set of parameter values that are used to define the metallic-roughness material model from Physically Based Rendering (PBR) methodology. When undefined, all the default values of `pbrMetallicRoughness` **MUST** apply.
PbrMetallicRoughness *PbrMetallicRoughness `json:"pbrMetallicRoughness,omitempty"`
// The tangent space normal texture. The texture encodes RGB components with linear transfer function. Each texel represents the XYZ components of a normal vector in tangent space. The normal vectors use the convention +X is right and +Y is up. +Z points toward the viewer. If a fourth component (A) is present, it **MUST** be ignored. When undefined, the material does not have a tangent space normal texture.
NormalTexture *NormalTexture `json:"normalTexture,omitempty"`
// The occlusion texture. The occlusion values are linearly sampled from the R channel. Higher values indicate areas that receive full indirect lighting and lower values indicate no indirect lighting. If other channels are present (GBA), they **MUST** be ignored for occlusion calculations. When undefined, the material does not have an occlusion texture.
OcclusionTexture *OcclusionTexture `json:"occlusionTexture,omitempty"`
// The emissive texture. It controls the color and intensity of the light being emitted by the material. This texture contains RGB components encoded with the sRGB transfer function. If a fourth component (A) is present, it **MUST** be ignored. When undefined, the texture **MUST** be sampled as having `1.0` in RGB components.
EmissiveTexture *TextureInfo `json:"emissiveTexture,omitempty"`
// The factors for the emissive color of the material. This value defines linear multipliers for the sampled texels of the emissive texture.
EmissiveFactor *[3]float64 `json:"emissiveFactor,omitempty"`
// The material's alpha rendering mode enumeration specifying the interpretation of the alpha value of the base color."
AlphaMode *MaterialAlphaMode `json:"alphaMode,omitempty"`
// Specifies the cutoff threshold when in `MASK` alpha mode. If the alpha value is greater than or equal to this value then it is rendered as fully opaque, otherwise, it is rendered as fully transparent. A value greater than `1.0` will render the entire material as fully transparent. This value **MUST** be ignored for other alpha modes. When `alphaMode` is not defined, this value **MUST NOT** be defined.
AlphaCutoff *float64 `json:"alphaCutoff,omitempty"`
// Specifies whether the material is double sided. When this value is false, back-face culling is enabled. When this value is true, back-face culling is disabled and double-sided lighting is enabled. The back-face **MUST** have its normals reversed before the lighting equation is evaluated.
DoubleSided *bool `json:"doubleSided,omitempty"`
}
The material appearance of a primitive. https://github.com/KhronosGroup/glTF/blob/main/specification/2.0/schema/material.schema.json
type MaterialAlphaMode ¶
type MaterialAlphaMode string
The alpha rendering mode of the material https://github.com/KhronosGroup/glTF/blob/0890b76c62cc762ce82d4010df9bfebb1634839b/specification/2.0/schema/material.schema.json#L43
const ( MaterialAlphaMode_OPAQUE MaterialAlphaMode = "OPAQUE" // The alpha value is ignored, and the rendered output is fully opaque. Default behaviour if alphaMode is not explicitly set. MaterialAlphaMode_MASK MaterialAlphaMode = "MASK" // The rendered output is either fully opaque or fully transparent depending on the alpha value and the specified `alphaCutoff` value; the exact appearance of the edges **MAY** be subject to implementation-specific techniques such as \"`Alpha-to-Coverage`\". MaterialAlphaMode_BLEND MaterialAlphaMode = "BLEND" // The alpha value is used to composite the source and destination areas. The rendered output is combined with the background using the normal painting operation (i.e. the Porter and Duff over operator). )
type MaterialAnisotropyExtensionNode ¶ added in v0.21.2
type MaterialAnisotropyExtensionNode struct {
AnisotropyStrength nodes.Output[float64] `` /* 134-byte string literal not displayed */
AnisotropyRotation nodes.Output[float64] `` /* 240-byte string literal not displayed */
}
func (MaterialAnisotropyExtensionNode) Description ¶ added in v0.32.0
func (node MaterialAnisotropyExtensionNode) Description() string
func (MaterialAnisotropyExtensionNode) Out ¶ added in v0.32.0
func (node MaterialAnisotropyExtensionNode) Out(out *nodes.StructOutput[PolyformAnisotropy])
type MaterialClearcoatExtensionNode ¶ added in v0.21.2
type MaterialClearcoatExtensionNode struct {
ClearcoatFactor nodes.Output[float64]
ClearcoatRoughnessFactor nodes.Output[float64]
}
func (MaterialClearcoatExtensionNode) Description ¶ added in v0.32.0
func (node MaterialClearcoatExtensionNode) Description() string
func (MaterialClearcoatExtensionNode) Out ¶ added in v0.32.0
func (node MaterialClearcoatExtensionNode) Out(out *nodes.StructOutput[PolyformClearcoat])
type MaterialExtension ¶ added in v0.9.0
type MaterialNode ¶ added in v0.21.2
type MaterialNode struct {
Color nodes.Output[coloring.WebColor] `` /* 149-byte string literal not displayed */
ColorTexture nodes.Output[PolyformTexture] `` /* 498-byte string literal not displayed */
MetallicFactor nodes.Output[float64] `` /* 166-byte string literal not displayed */
RoughnessFactor nodes.Output[float64] `` /* 166-byte string literal not displayed */
MetallicRoughnessTexture nodes.Output[PolyformTexture] `` /* 392-byte string literal not displayed */
EmissiveFactor nodes.Output[coloring.WebColor] `` /* 151-byte string literal not displayed */
NormalTexture nodes.Output[PolyformNormal] `` /* 421-byte string literal not displayed */
// Extensions
IndexOfRefraction nodes.Output[float64]
Transmission nodes.Output[PolyformTransmission]
Volume nodes.Output[PolyformVolume]
Anisotropy nodes.Output[PolyformAnisotropy]
Clearcoat nodes.Output[PolyformClearcoat]
EmissiveStrength nodes.Output[float64]
}
func (MaterialNode) Description ¶ added in v0.32.0
func (gmnd MaterialNode) Description() string
func (MaterialNode) Out ¶ added in v0.32.0
func (gmnd MaterialNode) Out(out *nodes.StructOutput[PolyformMaterial])
type MaterialTransmissionExtensionNode ¶ added in v0.21.2
type MaterialTransmissionExtensionNode struct {
Factor nodes.Output[float64] `description:"The base percentage of light that is transmitted through the surface"`
Texture nodes.Output[PolyformTexture] `` /* 152-byte string literal not displayed */
}
func (MaterialTransmissionExtensionNode) Description ¶ added in v0.32.0
func (node MaterialTransmissionExtensionNode) Description() string
func (MaterialTransmissionExtensionNode) Out ¶ added in v0.32.0
func (node MaterialTransmissionExtensionNode) Out(out *nodes.StructOutput[PolyformTransmission])
type MaterialVolumeExtensionNode ¶ added in v0.21.2
type MaterialVolumeExtensionNode struct {
ThicknessFactor nodes.Output[float64] `` /* 291-byte string literal not displayed */
AttenuationDistance nodes.Output[float64] `` /* 189-byte string literal not displayed */
AttenuationColor nodes.Output[coloring.WebColor] `description:"The color that white light turns into due to absorption when reaching the attenuation distance."`
}
func (MaterialVolumeExtensionNode) Description ¶ added in v0.32.0
func (node MaterialVolumeExtensionNode) Description() string
func (MaterialVolumeExtensionNode) Out ¶ added in v0.32.0
func (node MaterialVolumeExtensionNode) Out(out *nodes.StructOutput[PolyformVolume])
type Mesh ¶
type Mesh struct {
ChildOfRootProperty
Primitives []Primitive `json:"primitives"` // An array of primitives, each defining geometry to be rendered.
Weights []float64 `json:"weights,omitempty"` // Array of weights to be applied to the morph targets. The number of array elements **MUST** match the number of morph targets.
}
A set of primitives to be rendered. Its global transform is defined by a node that references it. https://github.com/KhronosGroup/glTF/blob/main/specification/2.0/schema/mesh.schema.json
type ModelNode ¶ added in v0.21.2
type ModelNode struct {
Mesh nodes.Output[modeling.Mesh]
Material nodes.Output[PolyformMaterial]
Translation nodes.Output[vector3.Float64]
Rotation nodes.Output[quaternion.Quaternion]
Scale nodes.Output[vector3.Float64]
GpuInstances nodes.Output[[]trs.TRS]
}
func (ModelNode) Out ¶ added in v0.32.0
func (gmnd ModelNode) Out(out *nodes.StructOutput[PolyformModel])
type NoOpImageLoader ¶ added in v0.30.0
type NoOpImageLoader struct{}
NoOpImageLoader implements the ImageLoader interface but does not actually load any images. This can be used to skip texture loading while still processing the rest of the GLTF file.
type Node ¶
type Node struct {
ChildOfRootProperty
Camera *GltfId `json:"camera,omitempty"` // The index of the camera referenced by this node.
Children []GltfId `json:"children,omitempty"` // The indices of this node's children.
Skin *GltfId `json:"skin,omitempty"` // The index of the skin referenced by this node. When a skin is referenced by a node within a scene, all joints used by the skin **MUST** belong to the same scene. When defined, `mesh` **MUST** also be defined.
Matrix *[16]float64 `json:"matrix,omitempty"` // A floating-point 4x4 transformation matrix stored in column-major order.
Mesh *GltfId `json:"mesh,omitempty"` // The index of the mesh in this node.
Rotation *[4]float64 `json:"rotation,omitempty"` // The node's unit quaternion rotation in the order (x, y, z, w), where w is the scalar.
Scale *[3]float64 `json:"scale,omitempty"` // The node's non-uniform scale, given as the scaling factors along the x, y, and z axes.
Translation *[3]float64 `json:"translation,omitempty"` // The node's translation along the x, y, and z axes.
Weights []float64 `json:"weights,omitempty"` // The weights of the instantiated morph target. The number of array elements **MUST** match the number of morph targets of the referenced mesh. When defined, `mesh` **MUST** also be defined.
Name string `json:"name,omitempty"`
}
A node in the node hierarchy. When the node contains `skin`, all `mesh.primitives` **MUST** contain `JOINTS_0` and `WEIGHTS_0` attributes. A node **MAY** 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), `matrix` **MUST NOT** be present. https://github.com/KhronosGroup/glTF/blob/main/specification/2.0/schema/node.schema.json
type NormalTexture ¶
type NormalTexture struct {
TextureInfo
Scale *float64 `json:"scale,omitempty"` // The scalar parameter applied to each normal vector of the texture. This value scales the normal vector in X and Y directions using the formula: `scaledNormal = normalize((<sampled normal texture value> * 2.0 - 1.0) * vec3(<normal scale>, <normal scale>, 1.0))`.
}
type NormalTextureNode ¶ added in v0.26.0
func (NormalTextureNode) Out ¶ added in v0.32.0
func (tnd NormalTextureNode) Out(out *nodes.StructOutput[PolyformNormal])
type OcclusionTexture ¶
type OcclusionTexture struct {
TextureInfo
Strength *float64 `json:"strength,omitempty"` // A scalar parameter controlling the amount of occlusion applied. A value of `0.0` means no occlusion. A value of `1.0` means full occlusion. This value affects the final occlusion value as: `1.0 + strength * (<sampled occlusion texture value> - 1.0)`.
}
type PbrMetallicRoughness ¶
type PbrMetallicRoughness struct {
Property
BaseColorFactor *[4]float64 `json:"baseColorFactor,omitempty"` // The factors for the base color of the material. This value defines linear multipliers for the sampled texels of the base color texture.
BaseColorTexture *TextureInfo `json:"baseColorTexture,omitempty"` // The base color texture. The first three components (RGB) **MUST** be encoded with the sRGB transfer function. They specify the base color of the material. If the fourth component (A) is present, it represents the linear alpha coverage of the material. Otherwise, the alpha coverage is equal to `1.0`. The `material.alphaMode` property specifies how alpha is interpreted. The stored texels **MUST NOT** be premultiplied. When undefined, the texture **MUST** be sampled as having `1.0` in all components.
MetallicFactor *float64 `json:"metallicFactor,omitempty"` // The factor for the metalness of the material. This value defines a linear multiplier for the sampled metalness values of the metallic-roughness texture.
RoughnessFactor *float64 `json:"roughnessFactor,omitempty"` // The factor for the roughness of the material. This value defines a linear multiplier for the sampled roughness values of the metallic-roughness texture.
MetallicRoughnessTexture *TextureInfo `json:"metallicRoughnessTexture,omitempty"` // The metallic-roughness texture. The metalness values are sampled from the B channel. The roughness values are sampled from the G channel. These values **MUST** be encoded with a linear transfer function. If other channels are present (R or A), they **MUST** be ignored for metallic-roughness calculations. When undefined, the texture **MUST** be sampled as having `1.0` in G and B components.
}
A set of parameter values that are used to define the metallic-roughness material model from Physically-Based Rendering (PBR) methodology. https://github.com/KhronosGroup/glTF/blob/main/specification/2.0/schema/material.pbrMetallicRoughness.schema.json
type PolyformAnisotropy ¶ added in v0.17.0
type PolyformAnisotropy struct {
// The anisotropy strength. When the anisotropy texture is present, this
// value is multiplied by the texture's blue channel.
AnisotropyStrength float64
// The rotation of the anisotropy in tangent, bitangent space, measured in
// radians counter-clockwise from the tangent. When the anisotropy texture
// is present, this value provides additional rotation to the vectors in
// the texture.
AnisotropyRotation float64
// The anisotropy texture. Red and green channels represent the anisotropy
// direction in $[-1, 1]$ tangent, bitangent space, to be rotated by the
// anisotropy rotation. The blue channel contains strength as $[0, 1]$ to
// be multiplied by the anisotropy strength.
AnisotropyTexture *PolyformTexture
}
glTF extension that defines anisotropy
func (PolyformAnisotropy) ExtensionID ¶ added in v0.17.0
func (pa PolyformAnisotropy) ExtensionID() string
func (PolyformAnisotropy) ToMaterialExtensionData ¶ added in v0.18.0
func (pa PolyformAnisotropy) ToMaterialExtensionData(w *Writer) map[string]any
type PolyformClearcoat ¶ added in v0.17.0
type PolyformClearcoat struct {
ClearcoatFactor float64
ClearcoatTexture *PolyformTexture
ClearcoatRoughnessFactor float64
ClearcoatRoughnessTexture *PolyformTexture
ClearcoatNormalTexture *PolyformNormal
}
func (PolyformClearcoat) ExtensionID ¶ added in v0.17.0
func (pmc PolyformClearcoat) ExtensionID() string
func (PolyformClearcoat) ToMaterialExtensionData ¶ added in v0.18.0
func (pmc PolyformClearcoat) ToMaterialExtensionData(w *Writer) map[string]any
type PolyformDispersion ¶ added in v0.17.0
type PolyformDispersion struct {
// This parameter defines dispersion in terms of the 20/Abbe number
// formulation.
Dispersion float64
}
glTF extension that defines the strength of dispersion.
func (PolyformDispersion) ExtensionID ¶ added in v0.17.0
func (pd PolyformDispersion) ExtensionID() string
func (PolyformDispersion) ToMaterialExtensionData ¶ added in v0.18.0
func (pd PolyformDispersion) ToMaterialExtensionData(w *Writer) map[string]any
type PolyformEmissiveStrength ¶ added in v0.17.0
type PolyformEmissiveStrength struct {
// The strength adjustment to be multiplied with the material's emissive value.
EmissiveStrength *float64
}
glTF extension that adjusts the strength of emissive material properties.
func (PolyformEmissiveStrength) ExtensionID ¶ added in v0.17.0
func (pmes PolyformEmissiveStrength) ExtensionID() string
func (PolyformEmissiveStrength) ToMaterialExtensionData ¶ added in v0.18.0
func (pmes PolyformEmissiveStrength) ToMaterialExtensionData(w *Writer) map[string]any
type PolyformIndexOfRefraction ¶ added in v0.9.0
type PolyformIndexOfRefraction struct {
// The index of refraction
// Air 1.0
// Water 1.33
// Eyes 1.38
// Window Glass 1.52
// Sapphire 1.76
// Diamond 2.42
IOR *float64
}
https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_ior/README.md
func (PolyformIndexOfRefraction) ExtensionID ¶ added in v0.9.0
func (sg PolyformIndexOfRefraction) ExtensionID() string
func (PolyformIndexOfRefraction) ToMaterialExtensionData ¶ added in v0.18.0
func (sg PolyformIndexOfRefraction) ToMaterialExtensionData(w *Writer) map[string]any
type PolyformIridescence ¶ added in v0.17.0
type PolyformIridescence struct {
// The iridescence intensity factor
IridescenceFactor float64
// The iridescence intensity texture. The values are sampled from the R
// channel. These values are linear. If a texture is not given, a value
// of `1.0` **MUST** be assumed. If other channels are present (GBA), they
// are ignored for iridescence intensity calculations
IridescenceTexture *PolyformTexture
// The index of refraction of the dielectric thin-film layer.
IridescenceIor *float64
// The minimum thickness of the thin-film layer given in nanometers. The
// value **MUST** be less than or equal to the value of
// `iridescenceThicknessMaximum`.
IridescenceThicknessMinimum *float64
// The maximum thickness of the thin-film layer given in nanometers. The
// value **MUST** be greater than or equal to the value of
// `iridescenceThicknessMinimum`.
IridescenceThicknessMaximum *float64
// The thickness texture of the thin-film layer to linearly interpolate
// between the minimum and maximum thickness given by the corresponding
// properties, where a sampled value of `0.0` represents the minimum
// thickness and a sampled value of `1.0` represents the maximum thickness.
// The values are sampled from the G channel. These values are linear. If a
// texture is not given, the maximum thickness **MUST** be assumed. If
// other channels are present (RBA), they are ignored for thickness
// calculations.
IridescenceThicknessTexture *PolyformTexture
}
glTF extension that defines an iridescence effect
func (PolyformIridescence) ExtensionID ¶ added in v0.17.0
func (pmi PolyformIridescence) ExtensionID() string
func (PolyformIridescence) ToMaterialExtensionData ¶ added in v0.18.0
func (pmi PolyformIridescence) ToMaterialExtensionData(w *Writer) map[string]any
type PolyformMaterial ¶ added in v0.9.0
type PolyformMaterial struct {
Name string
Extras map[string]any
AlphaMode *MaterialAlphaMode
AlphaCutoff *float64
PbrMetallicRoughness *PolyformPbrMetallicRoughness
Extensions []MaterialExtension
NormalTexture *PolyformNormal
OcclusionTexture *PolyformOcclusion
EmissiveTexture *PolyformTexture
EmissiveFactor color.Color
}
type PolyformModel ¶ added in v0.9.0
type PolyformModel struct {
Name string
Mesh *modeling.Mesh
Material *PolyformMaterial
// TRS contains the transformation (translation, rotation, scale) for this model
// This is optional and it will be used if the models are deduplicated and collapsed into a list of instances.
TRS *trs.TRS
// Utilizes the EXT_mesh_gpu_instancing extension to duplicate the model
// without increasing the mesh data footprint on the GPU.
// This is a list of transformations where this model should be repeated.
// This can only used if the UseGpuInstancing flag is set on the scene.
// If flag is not set, populating this list will cause the scene writing to fail.
GpuInstances []trs.TRS
// Animation is a list of animations that are applied to this model.
// Models with animations defined will never be deduplicated into a single list.
// However, these models can utilize GpuInstances and in that case the same animation will be applied to all of them.
// Limitations on using GpuInstances still apply.
Skeleton *animation.Skeleton
Animations []animation.Sequence
}
PolyformModel is a utility structure for reading/writing to GLTF format within polyform, and not an actual concept found within the GLTF format.
func DecodeModels ¶ added in v0.30.0
func DecodeModels(doc *Gltf, buffers [][]byte, options *ReaderOptions) ([]PolyformModel, error)
DecodeModels converts a GLTF document into a flat list of Polyform models. The options.BasePath field is used to resolve relative image URIs. If a custom ImageLoader is provided in options, it will be used to load images.
Example:
doc, buffers, _ := gltf.LoadFile("model.gltf", nil)
models, err := gltf.DecodeModels(doc, buffers, "", nil)
if err != nil {
log.Fatal(err)
}
for _, model := range models {
fmt.Printf("Model: %s, Vertices: %d\n", model.Name, model.Mesh.AttributeLength())
}
func ExperimentalDecodeModels
deprecated
added in
v0.25.0
func ExperimentalDecodeModels(doc *Gltf, buffers [][]byte, gltfDir string, options *ReaderOptions) ([]PolyformModel, error)
Deprecated: Use DecodeModels instead. ExperimentalDecodeModels converts a GLTF document into a flat list of Polyform models.
type PolyformNormal ¶ added in v0.10.0
type PolyformNormal struct {
*PolyformTexture
Scale *float64
}
type PolyformOcclusion ¶ added in v0.19.0
type PolyformOcclusion struct {
*PolyformTexture
Strength *float64
}
type PolyformPbrMetallicRoughness ¶ added in v0.9.0
type PolyformPbrMetallicRoughness struct {
BaseColorFactor color.Color
BaseColorTexture *PolyformTexture
MetallicFactor *float64
RoughnessFactor *float64
MetallicRoughnessTexture *PolyformTexture
}
type PolyformPbrSpecularGlossiness ¶ added in v0.9.0
type PolyformPbrSpecularGlossiness struct {
// The RGBA components of the reflected diffuse color of the material.
// Metals have a diffuse value of [0.0, 0.0, 0.0]. The fourth component (A)
// is the opacity of the material. The values are linear.
DiffuseFactor color.Color
// The diffuse texture. This texture contains RGB(A) components of the
// reflected diffuse color of the material in sRGB color space. If the
// fourth component (A) is present, it represents the alpha coverage of the
// material. Otherwise, an alpha of 1.0 is assumed. The alphaMode property
// specifies how alpha is interpreted. The stored texels must not be
// premultiplied.
DiffuseTexture *PolyformTexture
// The specular RGB color of the material. This value is linear.
SpecularFactor color.Color
// The glossiness or smoothness of the material. A value of 1.0 means the
// material has full glossiness or is perfectly smooth. A value of 0.0
// means the material has no glossiness or is perfectly rough. This value
// is linear.
// Default value is 1.0
GlossinessFactor *float64
// The specular-glossiness texture is a RGBA texture, containing the
// specular color (RGB) in sRGB space and the glossiness value (A) in
// linear space.
SpecularGlossinessTexture *PolyformTexture
}
https://kcoley.github.io/glTF/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness/
func (PolyformPbrSpecularGlossiness) ExtensionID ¶ added in v0.9.0
func (ppsg PolyformPbrSpecularGlossiness) ExtensionID() string
func (PolyformPbrSpecularGlossiness) ToMaterialExtensionData ¶ added in v0.18.0
func (sg PolyformPbrSpecularGlossiness) ToMaterialExtensionData(w *Writer) map[string]any
type PolyformScene ¶ added in v0.9.0
type PolyformScene struct {
Models []PolyformModel
Lights []KHR_LightsPunctual
// UseGpuInstancing indicates that the EXT_mesh_gpu_instancing extension should be used
// when appropriate for mesh instances. This must be set if GPU instances are defined on any of the models in the scene.
// If not set while GPU instances are defined - the scene serialisation will fail.
// This is a global setting for the scene and cannot be set on a per-model basis.
//
// The model deduplication applies regardless, and models that have exactly the same mesh pointer reference,
// and material value will be collapsed into a single list.
// If this flag is set, this single list will be converted into GPU instances as well.
UseGpuInstancing bool
}
func DecodeScene ¶ added in v0.30.0
func DecodeScene(doc *Gltf, buffers [][]byte, options *ReaderOptions) (*PolyformScene, error)
DecodeScene reconstructs the complete scene hierarchy with proper parent-child relationships. The options.BasePath field is used to resolve relative image URIs. If a custom ImageLoader is provided in options, it will be used to load images.
Example:
doc, buffers, _ := gltf.LoadFile("scene.gltf", nil)
scene, err := gltf.DecodeScene(doc, buffers, nil)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Scene has %d models and %d lights\n", len(scene.Models), len(scene.Lights))
func ExperimentalDecodeScene
deprecated
added in
v0.30.0
func ExperimentalDecodeScene(doc *Gltf, buffers [][]byte, gltfDir string, options *ReaderOptions) (*PolyformScene, error)
Deprecated: Use DecodeScene instead. ExperimentalDecodeScene reconstructs the complete scene hierarchy with proper parent-child relationships.
type PolyformSheen ¶ added in v0.17.0
type PolyformSheen struct {
// Color of the sheen layer (in linear space).
SheenColorFactor color.Color
// The sheen color (RGB) texture. Stored in channel RGB, the sheen color is
// in sRGB transfer function.
SheenColorTexture *PolyformTexture
// The sheen layer roughness of the material.
SheenRoughnessFactor float64
// The sheen roughness (Alpha) texture. Stored in alpha channel, the
// roughness value is in linear space.
SheenRoughnessTexture *PolyformTexture
}
glTF extension that defines the sheen material model.
func (PolyformSheen) ExtensionID ¶ added in v0.17.0
func (ps PolyformSheen) ExtensionID() string
func (PolyformSheen) ToMaterialExtensionData ¶ added in v0.18.0
func (ps PolyformSheen) ToMaterialExtensionData(w *Writer) map[string]any
type PolyformSpecular ¶ added in v0.9.0
type PolyformSpecular struct {
// The strength of the specular reflection.
// Default: 1.0
Factor *float64
// A texture that defines the strength of the specular reflection, stored
// in the alpha (A) channel. This will be multiplied by specularFactor.
Texture *PolyformTexture
// The F0 color of the specular reflection (linear RGB).
ColorFactor color.Color
// A texture that defines the F0 color of the specular reflection, stored
// in the RGB channels and encoded in sRGB. This texture will be multiplied
// by specularColorFactor.
ColorTexture *PolyformTexture
}
func (PolyformSpecular) ExtensionID ¶ added in v0.9.0
func (ps PolyformSpecular) ExtensionID() string
func (PolyformSpecular) ToMaterialExtensionData ¶ added in v0.18.0
func (ps PolyformSpecular) ToMaterialExtensionData(w *Writer) map[string]any
type PolyformTexture ¶ added in v0.9.0
type PolyformTexture struct {
URI string
Image image.Image
Sampler *Sampler
Extensions []TextureExtension
}
type PolyformTextureTransform ¶ added in v0.18.0
type PolyformTextureTransform struct {
// Whether to make this extension required for the given model.
// If set - extension will be added to `extensionsRequired` list at the GLTF file top level.
Required bool
Offset *vector2.Float64 // The offset of the UV coordinate origin as a factor of the texture dimensions.
Rotation *float64 // Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise.
Scale *vector2.Float64 // The scale factor applied to the components of the UV coordinates.
TexCoord *int // Overrides the textureInfo texCoord value if supplied, and if this extension is supported.
}
PolyformTextureTransform is a glTF extension that defines texture transformations.
func (PolyformTextureTransform) ExtensionID ¶ added in v0.18.0
func (ptt PolyformTextureTransform) ExtensionID() string
func (PolyformTextureTransform) IsInfo ¶ added in v0.18.0
func (ptt PolyformTextureTransform) IsInfo() bool
func (PolyformTextureTransform) IsRequired ¶ added in v0.18.0
func (ptt PolyformTextureTransform) IsRequired() bool
func (PolyformTextureTransform) ToTextureExtensionData ¶ added in v0.18.0
func (ptt PolyformTextureTransform) ToTextureExtensionData(w *Writer) map[string]any
type PolyformTransmission ¶ added in v0.9.0
type PolyformTransmission struct {
// The base percentage of light that is transmitted through the surface.
// Default: 0.0
Factor float64
// A texture that defines the transmission percentage of the surface,
// stored in the R channel. This will be multiplied by transmissionFactor.
Texture *PolyformTexture
}
func (PolyformTransmission) ExtensionID ¶ added in v0.9.0
func (tr PolyformTransmission) ExtensionID() string
func (PolyformTransmission) ToMaterialExtensionData ¶ added in v0.18.0
func (tr PolyformTransmission) ToMaterialExtensionData(w *Writer) map[string]any
type PolyformUnlit ¶ added in v0.17.0
type PolyformUnlit struct {
}
func (PolyformUnlit) ExtensionID ¶ added in v0.17.0
func (ps PolyformUnlit) ExtensionID() string
func (PolyformUnlit) ToMaterialExtensionData ¶ added in v0.18.0
func (ps PolyformUnlit) ToMaterialExtensionData(w *Writer) map[string]any
type PolyformVolume ¶ added in v0.9.0
type PolyformVolume struct {
// The thickness of the volume beneath the surface. The value is given in
// the coordinate space of the mesh. If the value is 0 the material is
// thin-walled. Otherwise the material is a volume boundary. The
// doubleSided property has no effect on volume boundaries. Range is
// [0, +inf).
// Default: 0
ThicknessFactor float64
// A texture that defines the thickness, stored in the G channel. This will
// be multiplied by thicknessFactor. Range is [0, 1].
ThicknessTexture *PolyformTexture
// Density of the medium given as the average distance that light travels
// in the medium before interacting with a particle. The value is given in
// world space. Range is (0, +inf).
// Default: +Infinity
AttenuationDistance *float64
// The color that white light turns into due to absorption when reaching
// the attenuation distance.
AttenuationColor color.Color
}
https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_volume/README.md
func (PolyformVolume) ExtensionID ¶ added in v0.9.0
func (v PolyformVolume) ExtensionID() string
func (PolyformVolume) ToMaterialExtensionData ¶ added in v0.18.0
func (v PolyformVolume) ToMaterialExtensionData(w *Writer) map[string]any
type Primitive ¶
type Primitive struct {
Property
Attributes map[string]GltfId `json:"attributes"` // A plain JSON object, where each key corresponds to a mesh attribute semantic and each value is the index of the accessor containing attribute's data.
Indices *GltfId `json:"indices,omitempty"` // The index of the accessor that contains the vertex indices. When this is undefined, the primitive defines non-indexed geometry. When defined, the accessor **MUST** have `SCALAR` type and an unsigned integer component type.
Material *GltfId `json:"material,omitempty"` // The index of the material to apply to this primitive when rendering.
Targets []GltfId `json:"targets,omitempty"` // A plain JSON object specifying attributes displacements in a morph target, where each key corresponds to one of the three supported attribute semantic (`POSITION`, `NORMAL`, or `TANGENT`) and each value is the index of the accessor containing the attribute displacements' data.
Mode *PrimitiveMode `json:"mode,omitempty"` // The topology type of primitives to render.
}
Geometry to be rendered with the given material. https://github.com/KhronosGroup/glTF/blob/main/specification/2.0/schema/mesh.primitive.schema.json
type PrimitiveMode ¶
type PrimitiveMode int
const ( PrimitiveMode_POINTS PrimitiveMode = 0 PrimitiveMode_LINES PrimitiveMode = 1 PrimitiveMode_LINE_LOOP PrimitiveMode = 2 PrimitiveMode_LINE_STRIP PrimitiveMode = 3 PrimitiveMode_TRIANGLES PrimitiveMode = 4 PrimitiveMode_TRIANGLE_STRIP PrimitiveMode = 5 PrimitiveMode_TRIANGLE_FAN PrimitiveMode = 6 )
type Property ¶
type Property struct {
Extensions Extensions `json:"extensions,omitempty"`
Extras Extra `json:"extras,omitempty"`
}
https://github.com/KhronosGroup/glTF/blob/main/specification/2.0/schema/glTFProperty.schema.json
type ReaderOptions ¶ added in v0.30.0
type ReaderOptions struct {
// BufferLoader provides custom buffer resolution. If nil, uses default file loading.
BufferLoader BufferLoader
// ImageLoader provides custom image resolution. If nil, uses default file loading.
ImageLoader ImageLoader
// BasePath overrides the base path for resolving relative URIs.
// If empty, uses the directory of the GLTF file (for file-based loading) or current directory.
BasePath string
}
ReaderOptions configures GLTF import behavior
type Sampler ¶
type Sampler struct {
ChildOfRootProperty
MagFilter SamplerMagFilter `json:"magFilter,omitempty"` // Magnification filter.
MinFilter SamplerMinFilter `json:"minFilter,omitempty"` // Minification filter
WrapS SamplerWrap `json:"wrapS,omitempty"` // S (U) wrapping mode. All valid values correspond to WebGL enums.
WrapT SamplerWrap `json:"wrapT,omitempty"` // T (V) wrapping mode.
}
Texture sampler properties for filtering and wrapping modes. https://github.com/KhronosGroup/glTF/blob/main/specification/2.0/schema/sampler.schema.json
type SamplerMagFilter ¶
type SamplerMagFilter int
const ( SamplerMagFilter_NEAREST SamplerMagFilter = 9728 SamplerMagFilter_LINEAR SamplerMagFilter = 9729 )
type SamplerMagFilterNode ¶ added in v0.25.0
type SamplerMagFilterNode struct {
}
func (SamplerMagFilterNode) Description ¶ added in v0.25.0
func (SamplerMagFilterNode) Description() string
func (SamplerMagFilterNode) Inputs ¶ added in v0.25.0
func (SamplerMagFilterNode) Inputs() map[string]nodes.InputPort
func (SamplerMagFilterNode) Name ¶ added in v0.25.0
func (SamplerMagFilterNode) Name() string
func (*SamplerMagFilterNode) Outputs ¶ added in v0.25.0
func (p *SamplerMagFilterNode) Outputs() map[string]nodes.OutputPort
type SamplerMinFilter ¶
type SamplerMinFilter int
const ( SamplerMinFilter_NEAREST SamplerMinFilter = 9728 SamplerMinFilter_LINEAR SamplerMinFilter = 9729 SamplerMinFilter_NEAREST_MIPMAP_NEAREST SamplerMinFilter = 9984 SamplerMinFilter_LINEAR_MIPMAP_NEAREST SamplerMinFilter = 9985 SamplerMinFilter_NEAREST_MIPMAP_LINEAR SamplerMinFilter = 9986 SamplerMinFilter_LINEAR_MIPMAP_LINEAR SamplerMinFilter = 9987 )
type SamplerMinFilterNode ¶ added in v0.25.0
type SamplerMinFilterNode struct {
}
func (SamplerMinFilterNode) Description ¶ added in v0.25.0
func (SamplerMinFilterNode) Description() string
func (SamplerMinFilterNode) Inputs ¶ added in v0.25.0
func (SamplerMinFilterNode) Inputs() map[string]nodes.InputPort
func (SamplerMinFilterNode) Name ¶ added in v0.25.0
func (SamplerMinFilterNode) Name() string
func (*SamplerMinFilterNode) Outputs ¶ added in v0.25.0
func (p *SamplerMinFilterNode) Outputs() map[string]nodes.OutputPort
type SamplerNode ¶ added in v0.25.0
type SamplerNode struct {
MagFilter nodes.Output[SamplerMagFilter] `description:"Magnification filter"`
MinFilter nodes.Output[SamplerMinFilter] `description:"Minification filter"`
WrapS nodes.Output[SamplerWrap] `description:"S (U) wrapping mode"`
WrapT nodes.Output[SamplerWrap] `description:"T (V) wrapping mode"`
}
func (SamplerNode) Description ¶ added in v0.32.0
func (SamplerNode) Description() string
func (SamplerNode) Out ¶ added in v0.32.0
func (tnd SamplerNode) Out(out *nodes.StructOutput[Sampler])
type SamplerWrap ¶
type SamplerWrap int
const ( SamplerWrap_CLAMP_TO_EDGE SamplerWrap = 33071 SamplerWrap_MIRRORED_REPEAT SamplerWrap = 33648 SamplerWrap_REPEAT SamplerWrap = 10497 )
type SamplerWrapNode ¶ added in v0.25.0
type SamplerWrapNode struct {
}
func (SamplerWrapNode) Inputs ¶ added in v0.25.0
func (SamplerWrapNode) Inputs() map[string]nodes.InputPort
func (SamplerWrapNode) Name ¶ added in v0.25.0
func (SamplerWrapNode) Name() string
func (*SamplerWrapNode) Outputs ¶ added in v0.25.0
func (p *SamplerWrapNode) Outputs() map[string]nodes.OutputPort
type Scene ¶
type Scene struct {
ChildOfRootProperty
Nodes []GltfId `json:"nodes,omitempty"` // The indices of each root node.
}
The root nodes of a scene. https://github.com/KhronosGroup/glTF/blob/main/specification/2.0/schema/scene.schema.json
type Skin ¶
type Skin struct {
ChildOfRootProperty
InverseBindMatrices GltfId `json:"inverseBindMatrices,omitempty"` // The index of the accessor containing the floating-point 4x4 inverse-bind matrices. Its `accessor.count` property **MUST** be greater than or equal to the number of elements of the `joints` array. When undefined, each matrix is a 4x4 identity matrix.
Skeleton GltfId `json:"skeleton,omitempty"` // The index of the node used as a skeleton root. The node **MUST** be the closest common root of the joints hierarchy or a direct or indirect parent node of the closest common root.
Joints []GltfId `json:"joints"` // Indices of skeleton nodes, used as joints in this skin.
}
Joints and matrices defining a skin. https://github.com/KhronosGroup/glTF/blob/main/specification/2.0/schema/skin.schema.json
type StandardLoader ¶ added in v0.30.0
type StandardLoader struct {
// BasePath is used to resolve relative file paths
BasePath string
}
StandardLoader implements both the BufferLoader and the ImageLoader interface for loading buffers and images from the file system or data URIs.
func (*StandardLoader) LoadBuffer ¶ added in v0.30.0
func (l *StandardLoader) LoadBuffer(uri string) ([]byte, error)
LoadBuffer loads binary data for the given URI. It supports: - Data URIs (data:application/octet-stream;base64,...) - Relative file paths (resolved against BasePath) - Absolute file paths
type Texture ¶
type Texture struct {
ChildOfRootProperty
Sampler *GltfId `json:"sampler,omitempty"`
Source *GltfId `json:"source,omitempty"`
Extensions Extensions `json:"extensions,omitempty"`
}
"A texture and its sampler. https://github.com/KhronosGroup/glTF/blob/main/specification/2.0/schema/texture.schema.json
type TextureExtension ¶ added in v0.18.0
type TextureInfo ¶
type TextureInfo struct {
Property
Index GltfId `json:"index"` // The index of the texture.
TexCoord int `json:"texCoord,omitempty"` // "This integer value is used to construct a string in the format `TEXCOORD_<set index>` which is a reference to a key in `mesh.primitives.attributes` (e.g. a value of `0` corresponds to `TEXCOORD_0`). A mesh primitive **MUST** have the corresponding texture coordinate attributes for the material to be applicable to it.
Extensions Extensions `json:"extensions,omitempty"`
}
Reference to a texture https://github.com/KhronosGroup/glTF/blob/main/specification/2.0/schema/textureInfo.schema.json
type TextureNode ¶ added in v0.21.0
func (TextureNode) Description ¶ added in v0.32.0
func (gmnd TextureNode) Description() string
func (TextureNode) Out ¶ added in v0.32.0
func (tnd TextureNode) Out(out *nodes.StructOutput[PolyformTexture])
type TextureReferenceNode ¶ added in v0.25.0
func (TextureReferenceNode) Description ¶ added in v0.32.0
func (gmnd TextureReferenceNode) Description() string
func (TextureReferenceNode) Out ¶ added in v0.32.0
func (tnd TextureReferenceNode) Out(out *nodes.StructOutput[PolyformTexture])
type Writer ¶ added in v0.9.0
type Writer struct {
// EmbedTextures forces texture images to be embedded as data URIs instead of external file references
EmbedTextures bool
// contains filtered or unexported fields
}
func NewWriterFromScene ¶ added in v0.18.0
func NewWriterFromScene(scene PolyformScene) (*Writer, error)
func (*Writer) AddAnimations ¶ added in v0.9.0
func (*Writer) AddLight ¶ added in v0.9.0
func (w *Writer) AddLight(light KHR_LightsPunctual)
func (*Writer) AddMaterial ¶ added in v0.9.0
func (w *Writer) AddMaterial(mat *PolyformMaterial) (*int, error)
func (*Writer) AddModel ¶ added in v0.23.0
func (w *Writer) AddModel(model PolyformModel) (_ int, err error)
func (*Writer) AddScene ¶ added in v0.18.0
func (w *Writer) AddScene(scene PolyformScene) error
func (*Writer) AddTexture ¶ added in v0.9.0
func (w *Writer) AddTexture(polyTex *PolyformTexture) *TextureInfo
func (*Writer) Align ¶ added in v0.25.0
Align ensures the buffer is aligned to the specified byte boundary
func (Writer) ToGLTF ¶ added in v0.9.0
func (w Writer) ToGLTF(embeddingStrategy BufferEmbeddingStrategy) Gltf
func (Writer) WriteGLB ¶ added in v0.9.0
func (w Writer) WriteGLB(out io.Writer, opts WriterOptions) error
func (*Writer) WriteIndices ¶ added in v0.9.0
func (w *Writer) WriteIndices(indices *iter.ArrayIterator[int], attributeSize int)
func (*Writer) WriteVector2 ¶ added in v0.9.0
func (w *Writer) WriteVector2(accessorComponentType AccessorComponentType, data *iter.ArrayIterator[vector2.Float64])
func (Writer) WriteVector2AsByte ¶ added in v0.9.0
func (Writer) WriteVector2AsFloat32 ¶ added in v0.9.0
func (*Writer) WriteVector3 ¶ added in v0.9.0
func (w *Writer) WriteVector3(accessorComponentType AccessorComponentType, data *iter.ArrayIterator[vector3.Float64])
func (Writer) WriteVector3AsByte ¶ added in v0.9.0
func (Writer) WriteVector3AsFloat32 ¶ added in v0.9.0
func (*Writer) WriteVector4 ¶ added in v0.9.0
func (w *Writer) WriteVector4(accessorComponentType AccessorComponentType, data *iter.ArrayIterator[vector4.Float64])
func (Writer) WriteVector4AsByte ¶ added in v0.9.0
func (Writer) WriteVector4AsFloat32 ¶ added in v0.9.0
type WriterOptions ¶ added in v0.30.0
type WriterOptions struct {
// EmbedTextures forces texture images to be embedded as data URIs instead of external file references
EmbedTextures bool
// JsonFormat specifies the JSON output format (default is pretty-printed with indentation)
JsonFormat JsonFormat
}
WriterOptions configures GLTF export behavior