serde

package
v0.0.0-...-d35cbbc Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2024 License: CC0-1.0 Imports: 2 Imported by: 0

Documentation

Overview

Package serde implements functions to serialise and deserialise scene data.

Index

Constants

View Source
const (
	ConstantTexture      = "constant"
	ImageTexture         = "image"
	NoiseTexture         = "noise"
	LambertMaterial      = "lambert"
	DiffuseLightMaterial = "diffuse_light"
	IsotropicMaterial    = "isotropic"
	MetalMaterial        = "metal"
	DielectricMaterial   = "dielectric"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Camera

type Camera struct {
	// LookFrom is the location of the camera.
	LookFrom Vec3
	// LookAt is where the camera is pointing at.
	LookAt Vec3
	// VUp defines the "up" vector.
	VUp Vec3
	// VFov define the field of view.
	VFov float64
	// Aspect is the aspect ratio.
	Aspect float64 `yaml:"aspect,omitempty"`
	// Aperture is the lens aperture for this camera.
	Aperture float64
	// FocusDist is the focus distance.
	FocusDist float64
	// Time0 defines the beginning time of the exposure.
	Time0 float64
	// Time1 defines the end time of the exposure.
	Time1 float64
}

Camera represents a camera.

type Constant

type Constant struct {
	// Value is a vector with the constant data.
	Value Vec3
}

Constant represents a constant texture.

type Dielectric

type Dielectric struct {
	// RefIdx is the refraction index.
	RefIdx float64
}

Dielectric represents a dielectric material.

type DiffuseLight

type DiffuseLight struct {
	// Emit is the colour texture.
	Emit Texture
}

DiffuseLight represents a diffuse light material.

type Displacement

type Displacement struct {
	// DisplacementMap is the displacement map that gets applied.
	DisplacementMap Image `yaml:"displacementmap,omitempty"`
	// Min is the lower value of the displacement.
	Min float64
	// Max is the upper value of the displacement.
	Max float64
}

Displacement represents a displacement mapping operator.

type Image

type Image struct {
	// FileName is the name of the file containing the texture data.
	FileName string
}

Image represents an image based texture.

type Isotropic

type Isotropic struct {
	// Albedo is the colour texture.
	Albedo Texture
}

Isotropic represents a dielectric material.

type Lambert

type Lambert struct {
	// Albedo is the colour texture.
	Albedo Texture
}

Lambert represents a Lambertian material.

type Material

type Material struct {
	// Name is the name of the material.
	Name string
	// Type is the type of material: lambert, diffuse_light, isotropic, metal, dielectric.
	Type string
	// Lambert is a lambert material.
	Lambert Lambert `yaml:"lambert,omitempty"`
	// DiffuseLight is a diffuse light.
	DiffuseLight DiffuseLight `yaml:"diffuselight,omitempty"`
	// Isotropic is an isotropic material.
	Isotropic Isotropic `yaml:"isotropic,omitempty"`
	// Metal is a metallic material.
	Metal Metal `yaml:"metal,omitempty"`
	// Dielectric is a dielectric material.
	Dielectric Dielectric `yaml:"dielectric,omitempty"`
}

Material represents a single material.

type Mesh

type Mesh struct {
	// WavefrontData is the name of the file containing the mesh information.
	WavefrontData string
	// Translate is the translation vector that is applied to all the vertices.
	Translate Vec3
	// Scale is a the scale vector that is applied to all the vetices.
	Scale Vec3
	// Displacement is the displacement map associated with this triangle.
	Displacement Displacement `yaml:"displacement,omitempty"`
	// Material is the material associated with this mesh.
	Material Material
}

Mesh represents a Wavefront OBJ instance.

type Metal

type Metal struct {
	// Albedo is the colour texture.
	Albedo Vec3
	// Fuzz defines how shiny a metallic surface is. 0 is a perfect mirror.
	Fuzz float64
}

Metal represents a metallic material.

type Noise

type Noise struct {
	// Scale defines the Perlin noise scale.
	Scale float64
}

Noise represents a Perlin noise texture.

type Objects

type Objects struct {
	// Meshes is a slice of all the meshes in the scene.
	Meshes []Mesh `yaml:"meshes,omitempty"`
	// Triangles is a slice of all the triangles in the scene.
	Triangles []Triangle `yaml:"triangles,omitempty"`
	// Spheres is a slice of all the spheres in the scene.
	Spheres []Sphere `yaml:"spheres,omitempty"`
}

Objects represents the objects in a scene.

type Scene

type Scene struct {
	// Name is the name of the scene.
	Name string
	// Camera is the camera for this scene.
	Camera Camera
	// Objects contains all the objects in the scene.
	Objects Objects
}

Scene represents a scene that can be rendered.

type Serde

type Serde interface {
	// Serialise writes a serialised version of the data to the provided writer.
	Serialise(scene *Scene, w io.Writer) error
	// Deserialise returns a struct representation of the serialised data.
	Deserialise(r io.Reader) (*Scene, error)
}

Serde defines the methods to seralise and deserialise scene data.

type Sphere

type Sphere struct {
	// Center defines the centre of the sphere.
	Center Vec3
	// Radius is the radius of the sphere.
	Radius float64
	// Material is the material of the sphere.
	Material Material
}

Sphere represents a sphere.

type Texture

type Texture struct {
	// Name is the name of the texture.
	Name string
	// Type is the texture type: constant, image or noise.
	Type string
	// Image is an instance of an Image texture.
	Image Image `yaml:"image,omitempty"`
	// Constant is an instance of a Constant texture.
	Constant Constant `yaml:"constant,omitempty"`
	// Noise is an instance of a Perlin noise texture.
	Noise Noise `yaml:"noise,omitempty"`
}

Texture represents a texture instance.

type Triangle

type Triangle struct {
	// Vertex0 is the first vertex of this triangle.
	Vertex0 Vec3
	// Vertex1 is the second vertex of this triangle.
	Vertex1 Vec3
	// Vertex2 is the third vertex of this triangle.
	Vertex2 Vec3
	// U0 is the u coordinate of the first vertex.
	U0 float64 `yaml:"u0,omitempty"`
	// V0 is the v coordinate of the first vertex.
	V0 float64 `yaml:"v0,omitempty"`
	// U1 is the u coordinate of the second vertex.
	U1 float64 `yaml:"u1,omitempty"`
	// V1 is the v coordinate of the second vertex.
	V1 float64 `yaml:"v1,omitempty"`
	// U2 is the u coordinate of the third vertex.
	U2 float64 `yaml:"u2,omitempty"`
	// V2 is the v coordinate of the third vertex.
	V2 float64 `yaml:"v2,omitempty"`
	// Displacement is the displacement map associated with this triangle.
	Displacement Displacement `yaml:"displacement,omitempty"`
	// Material is the material for this triangle.
	Material Material
}

Triangle represents a single triangle. Vertices must be defined counter clockwise.

type Vec3

type Vec3 struct {
	// X is the x coordinate of this vector.
	X float64
	// Y is the y coordinate of this vector.
	Y float64
	// Z is the z coordinate of this vector.
	Z float64
}

Vec3 represents a vector.

type Yaml

type Yaml struct {
}

Yaml represents a struct representation of a scene that is seralised as YAML data.

func (*Yaml) Deserialise

func (yml *Yaml) Deserialise(r io.Reader) (*Scene, error)

func (*Yaml) Serialise

func (yml *Yaml) Serialise(scene *Scene, w io.Writer) error

Jump to

Keyboard shortcuts

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