gltf

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
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

This section is empty.

Functions

func SaveBinary added in v0.9.0

func SaveBinary(gltfPath string, scene PolyformScene) error

Save writes the mesh to the path specified in GLB format

func SaveText

func SaveText(gltfPath string, scene PolyformScene) error

Save writes the mesh to the path specified in GLTF format

func WriteBinary added in v0.9.0

func WriteBinary(scene PolyformScene, out io.Writer) error

func WriteText

func WriteText(scene PolyformScene, out io.Writer) 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 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 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 Camera

type Camera struct{}

type ChildOfRootProperty

type ChildOfRootProperty struct {
	Property
	// The user-defined name of this object.  This is not necessarily unique, e.g.,
	// an accessor and a buffer could have the same name, or two accessors could
	// even have the same name.
	Name string `json:"name,omitempty"`
}

https://github.com/KhronosGroup/glTF/blob/main/specification/2.0/schema/glTFChildOfRootProperty.schema.json

type Extensions added in v0.9.0

type Extensions = map[string]any

JSON object with extension-specific objects. https://github.com/KhronosGroup/glTF/blob/main/specification/2.0/schema/extension.schema.json

type Extra

type Extra = map[string]any

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

type GltfId

type GltfId = int

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 ImageMimeType

type ImageMimeType string
const (
	ImageMimeType_JPEG ImageMimeType = "image/jpeg"
	ImageMimeType_PNG  ImageMimeType = "image/png"
)

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 Material

type Material struct {
	ChildOfRootProperty
	PbrMetallicRoughness *PbrMetallicRoughness `json:"pbrMetallicRoughness,omitempty"` // 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.
	NormalTexture        *NormalTexture        `json:"normalTexture,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.
	OcclusionTexture     *OcclusionTexture     `json:"occlusionTexture,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.
	EmissiveTexture      *TextureInfo          `json:"emissiveTexture,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.
	EmissiveFactor       *[3]float64           `json:"emissiveFactor,omitempty"`       // The factors for the emissive color of the material. This value defines linear multipliers for the sampled texels of the emissive texture.
	AlphaMode            *MaterialAlphaMode    `json:"alphaMode,omitempty"`            // The material's alpha rendering mode enumeration specifying the interpretation of the alpha value of the base color."
	AlphaCutoff          *float64              `json:"alphaCutoff,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.
	DoubleSided          *bool                 `json:"doubleSided,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.
}

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
const (
	MaterialAlphaMode_OPAQUE MaterialAlphaMode = "OPAQUE" // The alpha value is ignored, and the rendered output is fully opaque.
	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 MaterialExtension added in v0.9.0

type MaterialExtension interface {
	ExtensionID() string
	ToExtensionData(w *Writer) map[string]any
}

type Mesh

type Mesh struct {
	ChildOfRootProperty
	Primitives []Primitive `json:"primitives"`
	Weights    []float64   `json:"weights,omitempty"`
}

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

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 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 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) ToExtensionData added in v0.9.0

func (sg PolyformIndexOfRefraction) ToExtensionData(w *Writer) map[string]any

type PolyformMaterial added in v0.9.0

type PolyformMaterial struct {
	Name                 string
	Extras               map[string]any
	PbrMetallicRoughness *PolyformPbrMetallicRoughness
	Extensions           []MaterialExtension
	NormalTexture        *PolyformNormal
}

type PolyformMaterialsUnlit added in v0.9.0

type PolyformMaterialsUnlit struct {
}

func (PolyformMaterialsUnlit) ExtensionID added in v0.9.0

func (ps PolyformMaterialsUnlit) ExtensionID() string

func (PolyformMaterialsUnlit) ToExtensionData added in v0.9.0

func (ps PolyformMaterialsUnlit) ToExtensionData(w *Writer) map[string]any

type PolyformModel added in v0.9.0

type PolyformModel struct {
	Name     string
	Mesh     modeling.Mesh
	Material *PolyformMaterial

	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.

type PolyformNormal added in v0.10.0

type PolyformNormal struct {
	PolyformTexture
	Scale *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) ToExtensionData added in v0.9.0

func (sg PolyformPbrSpecularGlossiness) ToExtensionData(w *Writer) map[string]any

type PolyformScene added in v0.9.0

type PolyformScene struct {
	Models []PolyformModel
	Lights []KHR_LightsPunctual
}

type PolyformSpecular added in v0.9.0

type PolyformSpecular struct {
	// The strength of the specular reflection.
	// Default: 1.0
	SpecularFactor float64

	// A texture that defines the strength of the specular reflection, stored
	// in the alpha (A) channel. This will be multiplied by specularFactor.
	SpecularTexture *PolyformTexture

	// The F0 color of the specular reflection (linear RGB).
	SpecularColorFactor 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.
	SpecularColorTexture *PolyformTexture
}

https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_specular/README.md

func (PolyformSpecular) ExtensionID added in v0.9.0

func (ps PolyformSpecular) ExtensionID() string

func (PolyformSpecular) ToExtensionData added in v0.9.0

func (ps PolyformSpecular) ToExtensionData(w *Writer) map[string]any

type PolyformTexture added in v0.9.0

type PolyformTexture struct {
	URI     string
	Sampler *Sampler
}

type PolyformTransmission added in v0.9.0

type PolyformTransmission struct {

	// The base percentage of light that is transmitted through the surface.
	// Default: 0.0
	TransmissionFactor float64

	// A texture that defines the transmission percentage of the surface,
	// stored in the R channel. This will be multiplied by transmissionFactor.
	TransmissionTexture *PolyformTexture
}

https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_transmission/README.md

func (PolyformTransmission) ExtensionID added in v0.9.0

func (tr PolyformTransmission) ExtensionID() string

func (PolyformTransmission) ToExtensionData added in v0.9.0

func (tr PolyformTransmission) ToExtensionData(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) ToExtensionData added in v0.9.0

func (v PolyformVolume) ToExtensionData(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 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 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 SamplerWrap

type SamplerWrap int
const (
	SamplerWrap_CLAMP_TO_EDGE   SamplerWrap = 33071
	SamplerWrap_MIRRORED_REPEAT SamplerWrap = 33648
	SamplerWrap_REPEAT          SamplerWrap = 10497
)

type Scene

type Scene struct {
	ChildOfRootProperty
	Nodes []GltfId `json:"nodes"` // 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 Texture

type Texture struct {
	ChildOfRootProperty
	Sampler *GltfId `json:"sampler,omitempty"`
	Source  *GltfId `json:"source,omitempty"`
}

"A texture and its sampler. https://github.com/KhronosGroup/glTF/blob/main/specification/2.0/schema/texture.schema.json

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

Reference to a texture https://github.com/KhronosGroup/glTF/blob/main/specification/2.0/schema/textureInfo.schema.json

type Writer added in v0.9.0

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

func NewWriter added in v0.9.0

func NewWriter() *Writer

func (*Writer) AddAnimations added in v0.9.0

func (w *Writer) AddAnimations(animations []animation.Sequence, skeleton animation.Skeleton, skeletonNode int)

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

func (*Writer) AddMesh added in v0.9.0

func (w *Writer) AddMesh(model PolyformModel)

func (*Writer) AddSkin added in v0.9.0

func (w *Writer) AddSkin(skeleton animation.Skeleton) (*int, int)

func (*Writer) AddTexture added in v0.9.0

func (w *Writer) AddTexture(mat PolyformTexture) *TextureInfo

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) 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 (w Writer) WriteVector2AsByte(v vector2.Float64)

func (Writer) WriteVector2AsFloat32 added in v0.9.0

func (w Writer) WriteVector2AsFloat32(v vector2.Float64)

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 (w Writer) WriteVector3AsByte(v vector3.Float64)

func (Writer) WriteVector3AsFloat32 added in v0.9.0

func (w Writer) WriteVector3AsFloat32(v vector3.Float64)

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 (w Writer) WriteVector4AsByte(v vector4.Float64)

func (Writer) WriteVector4AsFloat32 added in v0.9.0

func (w Writer) WriteVector4AsFloat32(v vector4.Float64)

Jump to

Keyboard shortcuts

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