samplegltf

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package samplegltf generates and validates the deterministic glTF 2.0 sample models of the placeholder asset pack (package placeholder's models folder), which the 3D Blender pipeline documentation describes.

Index

Constants

View Source
const (
	GLBMagic      uint32 = 0x46546C67 // "glTF"
	GLBVersion    uint32 = 2
	ChunkTypeJSON uint32 = 0x4E4F534A // "JSON"
	ChunkTypeBIN  uint32 = 0x004E4942 // "BIN\0"

	ComponentUnsignedByte  = 5121
	ComponentUnsignedShort = 5123
	ComponentFloat         = 5126

	TargetArrayBuffer        = 34962
	TargetElementArrayBuffer = 34963

	ModeTriangles = 4
)

GLB container and glTF 2.0 constants.

Variables

This section is empty.

Functions

func GenerateCrateGLB

func GenerateCrateGLB() ([]byte, error)

GenerateCrateGLB builds a deterministic binary glTF 2.0 (GLB) 1 m cube crate: right-handed +X right, +Y up, -Z forward, pivot at bottom center (Y in [0, 1]), CCW front faces, outward normals, UVs, and a PBR metallicRoughness material.

func GenerateGemGLB

func GenerateGemGLB() ([]byte, error)

GenerateGemGLB builds a deterministic binary glTF 2.0 (GLB) pickup gem: a flat-shaded hexagonal bipyramid 0.8 m across and 1 m tall, pivot at its bottom point (Y in [0, 1]), with CCW outward faces, one normal per face and a glossy emerald PBR material. It uses only exactly rounded arithmetic (square roots, and products rounded before they are summed), so it writes the same bytes on every architecture.

func GenerateRobotArmGLTF

func GenerateRobotArmGLTF() ([]byte, error)

GenerateRobotArmGLTF builds a deterministic embedded-buffer glTF 2.0 JSON file containing a 2-bone skinned and animated robot arm (UpperArm -> Forearm) with inverseBindMatrices, JOINTS_0, WEIGHTS_0, a Wave rotation animation, and extras.events clip markers.

func PackGLB

func PackGLB(doc *Document, bin []byte) ([]byte, error)

PackGLB encodes doc and bin into a 4-byte-aligned GLB 2.0 container.

func ValidateDocument

func ValidateDocument(doc *Document, bin []byte) error

ValidateDocument verifies glTF 2.0 schema bounds, geometry winding, normals, skinning joints/weights/IBMs, and animation samplers/events.

func WriteSamples

func WriteSamples(dir string) error

WriteSamples writes crate.glb, robot_arm.gltf and gem.glb into dir.

Types

type Accessor

type Accessor struct {
	BufferView    *int      `json:"bufferView,omitempty"`
	ByteOffset    int       `json:"byteOffset,omitempty"`
	ComponentType int       `json:"componentType"`
	Count         int       `json:"count"`
	Type          string    `json:"type"`
	Min           []float64 `json:"min,omitempty"`
	Max           []float64 `json:"max,omitempty"`
}

Accessor describes a typed view into a BufferView.

type Animation

type Animation struct {
	Name     string             `json:"name,omitempty"`
	Channels []AnimationChannel `json:"channels"`
	Samplers []AnimationSampler `json:"samplers"`
	Extras   *AnimationExtras   `json:"extras,omitempty"`
}

Animation stores keyframe channels, samplers, and NSGo clip events.

type AnimationChannel

type AnimationChannel struct {
	Sampler int             `json:"sampler"`
	Target  AnimationTarget `json:"target"`
}

AnimationChannel binds a sampler to a node property path.

type AnimationExtras

type AnimationExtras struct {
	Events []ClipEvent `json:"events,omitempty"`
}

AnimationExtras holds custom metadata on an animation clip.

type AnimationSampler

type AnimationSampler struct {
	Input         int    `json:"input"`
	Interpolation string `json:"interpolation,omitempty"`
	Output        int    `json:"output"`
}

AnimationSampler maps keyframe input timestamps to output values.

type AnimationTarget

type AnimationTarget struct {
	Node *int   `json:"node,omitempty"`
	Path string `json:"path"`
}

AnimationTarget identifies the animated node and TRS/weights path.

type Asset

type Asset struct {
	Version   string `json:"version"`
	Generator string `json:"generator,omitempty"`
}

Asset identifies the glTF version and generator.

type Buffer

type Buffer struct {
	URI        string `json:"uri,omitempty"`
	ByteLength int    `json:"byteLength"`
}

Buffer holds binary geometry, skinning, or animation data.

type BufferView

type BufferView struct {
	Buffer     int `json:"buffer"`
	ByteOffset int `json:"byteOffset"`
	ByteLength int `json:"byteLength"`
	Target     int `json:"target,omitempty"`
}

BufferView slices a byte range out of a Buffer.

type ClipEvent

type ClipEvent struct {
	Time float64 `json:"time"`
	Name string  `json:"name"`
}

ClipEvent marks a named gameplay event at a timestamp in seconds.

type Document

type Document struct {
	Asset       Asset        `json:"asset"`
	Scene       *int         `json:"scene,omitempty"`
	Scenes      []Scene      `json:"scenes,omitempty"`
	Nodes       []Node       `json:"nodes,omitempty"`
	Meshes      []Mesh       `json:"meshes,omitempty"`
	Materials   []Material   `json:"materials,omitempty"`
	Skins       []Skin       `json:"skins,omitempty"`
	Animations  []Animation  `json:"animations,omitempty"`
	Accessors   []Accessor   `json:"accessors,omitempty"`
	BufferViews []BufferView `json:"bufferViews,omitempty"`
	Buffers     []Buffer     `json:"buffers,omitempty"`
}

Document is the subset of the glTF 2.0 JSON schema used by the sample models.

func ParseEmbeddedGLTF

func ParseEmbeddedGLTF(data []byte) (*Document, []byte, error)

ParseEmbeddedGLTF parses a glTF 2.0 JSON file whose single buffer uses a base64 data URI.

func UnpackGLB

func UnpackGLB(data []byte) (*Document, []byte, error)

UnpackGLB parses and validates a binary glTF 2.0 container (header, chunks, padding, and JSON/BIN payloads).

type Material

type Material struct {
	Name                 string                `json:"name,omitempty"`
	PBRMetallicRoughness *PBRMetallicRoughness `json:"pbrMetallicRoughness,omitempty"`
	DoubleSided          bool                  `json:"doubleSided"`
}

Material defines PBR surface properties.

type Mesh

type Mesh struct {
	Name       string      `json:"name,omitempty"`
	Primitives []Primitive `json:"primitives"`
}

Mesh groups one or more renderable primitives.

type Node

type Node struct {
	Name        string      `json:"name,omitempty"`
	Children    []int       `json:"children,omitempty"`
	Mesh        *int        `json:"mesh,omitempty"`
	Skin        *int        `json:"skin,omitempty"`
	Translation *[3]float64 `json:"translation,omitempty"`
	Rotation    *[4]float64 `json:"rotation,omitempty"`
	Scale       *[3]float64 `json:"scale,omitempty"`
}

Node represents an object or joint in the scene hierarchy.

type PBRMetallicRoughness

type PBRMetallicRoughness struct {
	BaseColorFactor [4]float64 `json:"baseColorFactor"`
	MetallicFactor  float64    `json:"metallicFactor"`
	RoughnessFactor float64    `json:"roughnessFactor"`
}

PBRMetallicRoughness defines the glTF 2.0 metallic-roughness material model.

type Primitive

type Primitive struct {
	Attributes map[string]int `json:"attributes"`
	Indices    *int           `json:"indices,omitempty"`
	Material   *int           `json:"material,omitempty"`
	Mode       *int           `json:"mode,omitempty"`
}

Primitive references vertex attributes, optional indices, and a material.

type Scene

type Scene struct {
	Name  string `json:"name,omitempty"`
	Nodes []int  `json:"nodes,omitempty"`
}

Scene lists root nodes of a glTF scene.

type Skin

type Skin struct {
	Name                string `json:"name,omitempty"`
	InverseBindMatrices *int   `json:"inverseBindMatrices,omitempty"`
	Skeleton            *int   `json:"skeleton,omitempty"`
	Joints              []int  `json:"joints"`
}

Skin binds a mesh to a skeleton joint hierarchy.

Jump to

Keyboard shortcuts

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