synth

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2018 License: BSD-2-Clause, Zlib Imports: 3 Imported by: 0

Documentation

Overview

Package synth is used to procedurally generate textures and models. Synthesized data is unique to a supplied random seed so the generated items can be different or identical based on need. They can also be as detailed or large as desired, mindfull that it is the clients responsibility to manage the memory required for large amounts of generated data.

Package synth is provided as part of the vu (virtual universe) 3D engine.

Index

Constants

View Source
const (
	XPos = iota // Face on right side of cube.
	XNeg        // Face on left side of cube.
	YPos        // Face on top of cube.
	YNeg        // Face on bottom of cube.
	ZPos        // Face on at back of cube.
	ZNeg        // Face on front of cube.
)

Cube face identifiers used when generating the six sides of a 3D cube map. Used in Tile.SetFace.

Variables

View Source
var CircleForm = &Form{M: 0, N1: 1, N2: 1, N3: 1, A: 1, B: 1}

CircleForm is the default state of a super formula whose shape is a 2D circle or 3D sphere with values 0,1,1,1,1,1. Not expected to be changed.

Functions

func ZLabel

func ZLabel(zoom uint, merge uint64) (key string)

ZLabel returns a label for a zorder merge value.

func ZMerge

func ZMerge(a, b uint32) (m uint64)

ZMerge two numbers by interleaving their bits and creating a new z-order encoded number. The b-bits will precede the a-bits which means the b value can be at most a 31 bit value.

func ZSplit

func ZSplit(m uint64) (a, b uint32)

ZSplit a z-order encoded number by de-interleaving the bits into two numbers. The b value represents the higher order bits.

Types

type Form

type Form struct {
	M  float64 // Angle multiplier
	N1 float64 // Overall exponent.
	N2 float64 // Cos exponent.
	N3 float64 // Sin exponent.
	A  float64 // Cos divisor
	B  float64 // Sin divisor
}

Form holds the 6 parameters needed to for the superformula to create supershapes. Form uses the the superformula to generate points in both 2D and 3D. See:

https://en.wikipedia.org/wiki/Superformula
http://paulbourke.net/geometry/supershape/

func NewForm

func NewForm() *Form

NewForm creates a supershape at its default circle/sphere shape.

func (*Form) At2D

func (f *Form) At2D(angle float64) (x, y float64)

At2D returns the 2D point for a given angle in radians.

func (*Form) At3D

func (f *Form) At3D(lat, lon float64) (x, y, z float64)

At3D returns the 3D point for the supplied lat and lon angles in radians.

lat is the angle in radians between Pi/2 and -Pi/2.
lon is the angle in radians between Pi and -Pi.

func (*Form) Radius

func (f *Form) Radius(angle float64) (r float64)

Radius runs the superformula for the given angle in radians.

func (*Form) Set

func (f *Form) Set(fm *Form)

Set the superform to the given Form fm.

func (*Form) SetValues

func (f *Form) SetValues(m, n1, n2, n3, a, b float64)

SetValues sets the superform to the given values.

type Land

type Land interface {
	TileSize() int     // Land tile width, height. Standard is 256
	Size(zoom int) int // Width and height at the given zoom.

	// Allocate and populate the indicated land tile with height data.
	//    tx,ty: topo/tile index at given zoom.
	NewTile(zoom, tx, ty int) Tile
	Fill(tile Tile)   // (Re)populates a tile with 2D height data.
	Fill3D(tile Tile) // (Re)populates a tile with 3D height data.
}

Land provides the ability to procedurally generate terrain height information. The higher the level of detail the larger the terrain. Land is created using NewLand().

func NewLand

func NewLand(tileSize int, seed int64) Land

NewLand initializes the procedural land generator. The seed determines land shape, such that lands created from the same seed will be the same. The zoom determines the overall size of the land (limit to 8 or less pending stress testing). For example if tileSize is 256 then increasing the level of detail results in the following sizes:

zoom  0 :  256*2^0  = 256m
zoom  1 :  256*2^1  = 512
zoom  2 :  256*2^2  = 1024     ~1km2
zoom  3 :  256*2^3  = 2048     ~4km2
zoom  4 :  256*2^4  = 4096
zoom  5 :  256*2^5  = 8192     ~64km2 Medium size city.
zoom  6 :  256*2^6  = 16384
zoom  7 :  256*2^7  = 37768
zoom  8 :  256*2^8  = 65536
zoom  9 :  256*2^9  = 131072
zoom 10 :  256*2^10 = 262144
zoom 11 :  256*2^11 = 524288
zoom 12 :  256*2^12 = 1048576  ~1,000,000km2 Size of Ontario
zoom 13 :  256*2^13 = 2097152
                      3162000  ~10,000,000km2 Size of Canada
zoom 14 :  256*2^14 = 4194304
zoom 15 :  256*2^15 = 8388608
zoom 16 :  256*2^16 = 16777216
                      22583000 ~510,000,000km2 Size of Earth
zoom 17 :  256*2^17 = 33554472

Land heights are generated by creating tiles at a particular zoom level. It is up to the caller to store/cache or regenerate tiles as needed.

type Noise

type Noise interface {
	Gen2D(x, y float64) float64
	Gen3D(x, y, z float64) float64
}

Noise exposes noise generating algorithms.

type RegionData

type RegionData [][]int

RegionData is used to associate a data value at each land location. For example this can be used to associate a land type or land region at each height location.

func Regions

func Regions(size, numRegions int, seed int64) RegionData

Regions divides a given land. This is attempting to do something similar to creating a Voronoi diagram, just using a lot less code (also less efficient). The random seed is injected so that identical results can be re-created.

type SimplexNoise

type SimplexNoise struct {
	F float64 // Higher frequency results in finer features.
	G float64 // Gain limits final value amount.
	L float64 // Using 2.0 gives scales of 1, 1/2, 1/4 for the octaves.
	O int     // More octaves for sharper features.
	N Noise   // Simplex noise algorithm.
}

SimplexNoise exposes the simplex noise generator and its control parameters for easy manipulation.

func NewSimplexNoise

func NewSimplexNoise(seed int64) *SimplexNoise

NewSimplexNoise initializes a simplex noise generator using the given seed. The returned generator can be used to create data blocks of generated values.

func (*SimplexNoise) Gen2D

func (sn *SimplexNoise) Gen2D(x, y float64) float64

Gen2D returns a generated noise value for the given x,y coordinate. Used to generate different 2D images based on the SimplexNoise parameters.

type Tile

type Tile interface {
	Size() (x, y int)          // Tile width and height dimensions.
	Zoom() int                 // Zoom (level of detail) for this tile.
	Topo() [][]float64         // Size x Size height data points.
	Origin() (ox, oy int)      // Tile origin.
	Set(zoom, ox, oy int) Tile // Repurpose this tile. Data needs updating.
	SetFace(face int) Tile     // Needed to fill a 3D cube face image.
}

Tile holds a portion of the overall world map and the parameters that uniquely indicate the map portion.

Jump to

Keyboard shortcuts

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