chunk

package
v0.0.0-...-124f97e Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2023 License: GPL-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const NormalUndefined = 0
View Source
const NormalXN = 2
View Source
const NormalXP = 1
View Source
const NormalYN = 4
View Source
const NormalYP = 3
View Source
const NormalZN = 6
View Source
const NormalZP = 5
View Source
const TexcoordBottomLeft = 2
View Source
const TexcoordBottomRight = 3
View Source
const TexcoordTopLeft = 0
View Source
const TexcoordTopRight = 1

Variables

This section is empty.

Functions

func ChunkVertexGenerator

func ChunkVertexGenerator(cm *T) mesh.Generator[voxel.Vertex, uint16]

func Crop

func Crop(chk *T)

func Deserialize

func Deserialize(dec object.Decoder) (object.Component, error)

func ExampleWorldgen

func ExampleWorldgen(seed, size int) *worldgen

func Expand

func Expand(chk *T)

func NewGUI

func NewGUI(e *Editor, target *Mesh) gui.Fragment

func NewMenu

func NewMenu(editor *Editor) gui.Fragment

func Subdivide

func Subdivide(chk *T)

Types

type ChunkState

type ChunkState struct {
	Data       []voxel.T
	Sx, Sy, Sz int
}

type Editor

type Editor struct {
	object.Object
	*editor.Context

	Chunk *T

	PlaceTool   *PlaceTool
	EraseTool   *EraseTool
	SampleTool  *SampleTool
	ReplaceTool *ReplaceTool

	XPlane *plane.Plane
	YPlane *plane.Plane
	ZPlane *plane.Plane

	GUI  gui.Fragment
	Menu gui.Fragment

	BoundingBox *lines.BoxObject

	Rigidbody     *physics.RigidBody
	CollisionMesh *physics.Mesh
	// contains filtered or unexported fields
}

Editor base struct

func NewEditor

func NewEditor(ctx *editor.Context, mesh *Mesh) *Editor

NewEditor creates a new chunk editor

func (*Editor) Actions

func (e *Editor) Actions() []editor.Action

func (*Editor) Bounds

func (e *Editor) Bounds() physics.Shape

func (*Editor) Deselect

func (e *Editor) Deselect(ev mouse.Event) bool

func (*Editor) GetVoxel

func (e *Editor) GetVoxel(x, y, z int) voxel.T

func (*Editor) InBounds

func (e *Editor) InBounds(p vec3.T) bool

func (*Editor) KeyEvent

func (e *Editor) KeyEvent(ev keys.Event)

func (*Editor) Name

func (e *Editor) Name() string

func (*Editor) Recalculate

func (e *Editor) Recalculate()

func (*Editor) Select

func (e *Editor) Select(ev mouse.Event)

func (*Editor) SelectColor

func (e *Editor) SelectColor(c color.T)

func (*Editor) SelectedColor

func (e *Editor) SelectedColor() color.T

func (*Editor) SetVoxel

func (e *Editor) SetVoxel(x, y, z int, v voxel.T)

func (*Editor) Target

func (e *Editor) Target() object.Component

func (*Editor) Update

func (e *Editor) Update(scene object.Component, dt float32)

type EraseTool

type EraseTool struct {
	object.Object
	Box object.Object
}

func NewEraseTool

func NewEraseTool() *EraseTool

func (*EraseTool) CanDeselect

func (pt *EraseTool) CanDeselect() bool

func (*EraseTool) Hover

func (pt *EraseTool) Hover(editor *Editor, position, normal vec3.T)

func (*EraseTool) ToolMouseEvent

func (pt *EraseTool) ToolMouseEvent(ev mouse.Event, hover physics.RaycastHit)

func (*EraseTool) Use

func (pt *EraseTool) Use(editor *Editor, position, normal vec3.T)

type Generator

type Generator interface {
	Voxel(x, y, z int) voxel.T
}

func NewRandomGen

func NewRandomGen() Generator

type LightVolume

type LightVolume struct {
	Falloff    float32
	Sx, Sy, Sz int
	Data       [][][]LightVoxel
}

func NewLightVolume

func NewLightVolume(sx, sy, sz int) *LightVolume

func (*LightVolume) Block

func (lv *LightVolume) Block(x, y, z int, blocked bool)

func (*LightVolume) Brightness

func (lv *LightVolume) Brightness(x, y, z int) float32

func (*LightVolume) Calculate

func (lv *LightVolume) Calculate()

func (*LightVolume) Clear

func (lv *LightVolume) Clear()

func (*LightVolume) Get

func (lv *LightVolume) Get(x, y, z int) *LightVoxel

func (*LightVolume) Resample

func (lv *LightVolume) Resample(x, y, z int) float32

type LightVoxel

type LightVoxel struct {
	Blocked bool
	V       float32
}

type Mesh

type Mesh struct {
	*mesh.Dynamic[voxel.Vertex, uint16]
	Chunk *T
}

func NewMesh

func NewMesh(chunk *T) *Mesh

func (*Mesh) Serialize

func (m *Mesh) Serialize(enc object.Encoder) error

type PlaceTool

type PlaceTool struct {
	object.Object
	Box object.Object
}

func NewPlaceTool

func NewPlaceTool() *PlaceTool

func (*PlaceTool) CanDeselect

func (pt *PlaceTool) CanDeselect() bool

func (*PlaceTool) Hover

func (pt *PlaceTool) Hover(editor *Editor, position, normal vec3.T)

func (*PlaceTool) ToolMouseEvent

func (pt *PlaceTool) ToolMouseEvent(ev mouse.Event, hover physics.RaycastHit)

func (*PlaceTool) Use

func (pt *PlaceTool) Use(editor *Editor, position, normal vec3.T)

type ReplaceTool

type ReplaceTool struct {
	object.Object
	Box object.Object
}

func NewReplaceTool

func NewReplaceTool() *ReplaceTool

func (*ReplaceTool) CanDeselect

func (pt *ReplaceTool) CanDeselect() bool

func (*ReplaceTool) Hover

func (pt *ReplaceTool) Hover(editor *Editor, position, normal vec3.T)

func (*ReplaceTool) ToolMouseEvent

func (pt *ReplaceTool) ToolMouseEvent(ev mouse.Event, hover physics.RaycastHit)

func (*ReplaceTool) Use

func (pt *ReplaceTool) Use(editor *Editor, position, normal vec3.T)

type SampleTool

type SampleTool struct {
	object.Object
	Box object.Object

	Reselect func()
}

func NewSampleTool

func NewSampleTool() *SampleTool

func (*SampleTool) CanDeselect

func (pt *SampleTool) CanDeselect() bool

func (*SampleTool) Hover

func (pt *SampleTool) Hover(editor *Editor, position, normal vec3.T)

func (*SampleTool) ToolMouseEvent

func (pt *SampleTool) ToolMouseEvent(ev mouse.Event, hover physics.RaycastHit)

func (*SampleTool) Use

func (pt *SampleTool) Use(editor *Editor, position, normal vec3.T)

type T

type T struct {
	Key        string
	Sx, Sy, Sz int
	Data       voxel.Array
	Light      *LightVolume
}

Chunk is the smallest individually renderable unit of voxel geometry

func Generate

func Generate(wg Generator, size, cx, cz int) *T

func New

func New(key string, sx, sy, sz int) *T

New creates a new voxel data chunk

func (*T) At

func (c *T) At(x, y, z int) voxel.T

Returns a pointer to the voxel defintion at the given position. If the space is empty, the Empty voxel is returned

func (*T) Clear

func (c *T) Clear()

Clear all voxel data in this chunk

func (*T) Free

func (c *T) Free(x, y, z int) bool

Free returns true if the given position is open

func (*T) Set

func (c *T) Set(x, y, z int, vox voxel.T)

Set a voxel. If it's out of bounds, nothing happens

type World

type World struct {
	object.Object
	// contains filtered or unexported fields
}

func NewWorld

func NewWorld(size int, generator Generator, distance float32) *World

Builds a world of chunks around the active camera as it moves around

func (*World) Update

func (c *World) Update(scene object.Component, dt float32)

Jump to

Keyboard shortcuts

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