c3d

package
v0.0.0-...-86c6665 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2024 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddCube

func AddCube(p, d [3]uint8, uvd uint8, f t.Facing, c *t.Cube, m *CubeMesh)

AddCube adds all of the faces of the given cube definition.

func AddFace

func AddFace[T any](p, d [3]uint8, uvd uint8, f t.Facing, c T, m Mesh[T])

AddFace adds the given face with the given position and dimensions to the mesh.

func BuildVoxelMesh

func BuildVoxelMesh[T comparable](v VoxelSource[T], d Mesh[T])

BuildVoxelMesh builds a VoxelMesh object from the passed voxel source and constructs faces in the destination mesh. Note that the destination mesh is not reset before faces are added.

Types

type AABB

type AABB struct {
	Bounds t.AABB
	// contains filtered or unexported fields
}

AABB represents an axis-aligned bounding box with an optional bounds mesh.

type Animation

type Animation struct {
	Frames []*AnimationFrame // List of all frames
	// contains filtered or unexported fields
}

Animation contains the information and functionality to play an animation loop on a model. Animations consist of rotations to joints only.

func (*Animation) Play

func (a *Animation) Play()

Play starts the animation playing.

func (*Animation) Update

func (a *Animation) Update(dt float32)

Update advances toward the next frame, ensuring that when a frame transition occurs the final position is reached by the target joint. The t argument is the number of seconds elapsed since the last call to this function. Frames are transitioned as appropriate.

type AnimationFrame

type AnimationFrame struct {
	Time    float32                // Time T for interpolation to Q
	TTL     float32                // Time left to move
	Joints  map[string]*mgl32.Quat // Map of part ID's to quaternions that describe that part's final rotation
	Targets map[string]mgl32.Quat  // Target rotations for each joint
	Starts  map[string]mgl32.Quat  // Staring rotation of the part in the frame
}

AnimationFrame describes a single frame of the animation.

type App

type App struct {
	CursorVisible     bool // If true, draw the cursor
	CrosshairVisible  bool // If true, draw the crosshair
	DebugTextVisible  bool // If true, draw the debug text
	WireFramesVisible bool // If true, draws wire frames
	// contains filtered or unexported fields
}

App manages a set of drawable objects and the shader programs used to draw them.

func NewApp

func NewApp(faces *FaceAtlas, tiles *FaceAtlas) (*App, error)

NewApp constructs a new App object with the given resources ready to draw.

func (*App) AddChunkDD

func (a *App) AddChunkDD(d *ChunkDrawDescriptor)

AddChunkDD adds the chunk draw descriptor to the list to draw.

func (*App) AddDebugLine

func (a *App) AddDebugLine(c [3]uint8, f string, args ...any)

AddDebugLine sets the debug text drawn in the bottom-left.

func (*App) AddLineDD

func (a *App) AddLineDD(d *LineMeshDrawDescriptor)

AddLineDD adds the line draw descriptor to the list to draw.

func (*App) AddModelDD

func (a *App) AddModelDD(d *ModelDrawDescriptor)

AddModelDD adds the model draw descriptor to the list to draw.

func (*App) AddUIMesh

func (a *App) AddUIMesh(m *UIMesh)

AddUIMesh adds the UI mesh to the list to render.

func (*App) Delete

func (a *App) Delete()

Delete removes all memory and GPU resources managed by the app.

func (*App) Draw

func (a *App) Draw(c *Camera)

Draw draws everything with the given camera for 3D space..

func (*App) NewTextMesh

func (a *App) NewTextMesh() *TextMesh

NewTextMesh returns a new text mesh ready for use.

func (*App) NewUIMesh

func (a *App) NewUIMesh() *UIMesh

NewUIMesh returns a new UI mesh ready for use.

func (*App) RemoveChunkDD

func (a *App) RemoveChunkDD(id uint32)

RemoveChunkDD removes the chunk draw descriptor by ID.

func (*App) RemoveLineDD

func (a *App) RemoveLineDD(id uint32)

RemoveLineDD removes the line draw descriptor by ID.

func (*App) RemoveModelDD

func (a *App) RemoveModelDD(id uint32)

RemoveModelDD removes the model draw descriptor by ID.

func (*App) RemoveUIMesh

func (a *App) RemoveUIMesh(m *UIMesh)

RemoveUIMesh removes the passed UI mesh from the renderer.

func (*App) SetCrosshair

func (a *App) SetCrosshair(f t.FaceIndex, l uint16)

SetCrosshair sets the UI tile to use as the 3D crosshair.

func (*App) SetCursor

func (a *App) SetCursor(f t.FaceIndex, l uint16)

SetCursor sets the UI tile to use as the mouse cursor.

func (*App) SetCursorPosition

func (a *App) SetCursorPosition(p mgl32.Vec2)

SetCursorPosition sets the cursor position.

type Camera

type Camera struct {
	Position mgl32.Vec3 // Position of the camera
	Front    mgl32.Vec3 // Camera facing direction
	Up       mgl32.Vec3 // Camera up vector
	Pitch    float32    // Camera rotation about the X axis
	Yaw      float32    // Camera rotation about the Y axis
}

Camera manages the properties and matrixes of a camera.

func NewCamera

func NewCamera(pos mgl32.Vec3) *Camera

NewCamera creates a new Camera object ready for use.

func (*Camera) TransformMatrix

func (c *Camera) TransformMatrix() mgl32.Mat4

TransformMatrix returns the matrix to transform from world space to camera space.

type ChunkDrawDescriptor

type ChunkDrawDescriptor struct {
	ID       uint32                     // ID
	CubeDD   CubeMeshDrawDescriptor     // The draw descriptor for the cube mesh
	VoxelDDs []*VoxelMeshDrawDescriptor // Draw descriptors for all voxel meshes contained within the chunk
}

ChunkDrawDescriptor describes how and where to render the static portions of a scene.

type ColoredString

type ColoredString struct {
	String string   // The string
	Color  [3]uint8 // The color
}

ColoredString is a string associated with an RGB color.

type CubeMesh

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

CubeMesh is a utility struct that builds cube-based meshes.

func NewCubeMesh

func NewCubeMesh(defs []*t.Cube) *CubeMesh

NewCubeMesh constructs a new CubeMesh object ready for use.

func (*CubeMesh) Reset

func (m *CubeMesh) Reset()

Reset rests the mesh builder state.

type CubeMeshDrawDescriptor

type CubeMeshDrawDescriptor struct {
	ID          uint32        // ID
	Mesh        *CubeMesh     // The mesh to draw
	Position    mgl32.Vec3    // Position of the bottom-north-west corner of the mesh
	Orientation t.Orientation // Describes the origin and rotation of the mesh
}

CubeMeshDrawDescriptor describes how and where to draw a cube mesh.

type FaceAtlas

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

FaceAtlas manages

func NewFaceAtlas

func NewFaceAtlas() *FaceAtlas

NewFaceAtlas creates a new FaceAtlas object ready for use.

func (*FaceAtlas) AddFace

func (a *FaceAtlas) AddFace(img *image.RGBA) t.FaceIndex

AddFace adds a single face graphic to the atlas and returns the FaceIndex.

type LineMesh

type LineMesh struct {
	Orientation t.Orientation // Orientation of the wire frame
	Hidden      bool          // If true, do not draw the line mesh
	// contains filtered or unexported fields
}

LineMesh provides a simple axis indicator made of full-bright lines.

func NewLineMesh

func NewLineMesh() *LineMesh

NewLineMesh creates a new axis indicator.

func (*LineMesh) Line

func (m *LineMesh) Line(a, b mgl32.Vec3, c [4]uint8)

Line adds a single line to the mesh.

func (*LineMesh) Point

func (m *LineMesh) Point(a mgl32.Vec3, c [4]uint8)

Point adds a single point to the mesh.

func (*LineMesh) Reset

func (m *LineMesh) Reset()

Reset resets the mesh to empty.

func (*LineMesh) WireFrame

func (m *LineMesh) WireFrame(v []mgl32.Vec3, c [4]uint8)

WireFrame draws a wire frame from pairs of points in the slice.

type LineMeshDrawDescriptor

type LineMeshDrawDescriptor struct {
	ID          uint32        // ID
	Orientation t.Orientation // Origin of the model
	Mesh        *LineMesh     // Mesh
}

LineMeshDrawDescriptor describes how and where to render a line mesh.

type Mesh

type Mesh[T any] interface {

	// Reset resets the vertex data of the mesh.
	Reset()
	// contains filtered or unexported methods
}

Mesh is implemented by all mesh types in c3d.

type ModelDrawDescriptor

type ModelDrawDescriptor struct {
	ID          uint32        // ID
	Bounds      AABB          // Bounds of the model
	Origin      mgl32.Vec3    // Origin of the model in model space
	Orientation t.Orientation // Origin of the model
	Root        *Part         // Root part that everything else is attached to
}

ModelDrawDescriptor describes how and where to render a dynamic model.

type NinePatch

type NinePatch [9]t.FaceIndex

NinePatch describes the resources used to generate an arbitrarily sized rectangle skinned with nine tiles stretched over the area.

type Part

type Part struct {
	ID          string        // Unique ID of the part for animation references
	Mesh        *VoxelMesh    // Voxel mesh for the part
	Origin      mgl32.Vec3    // Center point of the part
	Orientation t.Orientation // Current part orientation relative to the parent
	Children    []*Part       // Child parts, if any
}

Part manages a voxel volume that represents one body part of a model.

type TextMesh

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

TextMesh is a drawable layer of text. TextMesh may be printed into the layer at any point, and may overlap.

func (*TextMesh) Print

func (text *TextMesh) Print(x, y int, c [3]uint8, s string, args ...any)

Print prints a string at the given screen position in virtual screen units.

func (*TextMesh) Reset

func (t *TextMesh) Reset()

Reset resets the text object to blank. Internal memory buffers are retained to reduce allocations.

type Thing

type Thing struct {
}

Thing is a collection of RGB voxel meshes that are animated.

type UIMesh

type UIMesh struct {
	Cubes    []*CubeMeshDrawDescriptor // List of all cube meshes to draw
	Position mgl32.Vec2                // Position of the element in virtual screen units
	Layer    uint16                    // Layer index, the higher the value the higher priority
	Hidden   bool                      // If true, do not render the mesh or any of its children
	// contains filtered or unexported fields
}

UIMesh is a drawable 2D orthographic mode object that can include ui tiles and text.

func (*UIMesh) AddCube

func (e *UIMesh) AddCube(m *CubeMeshDrawDescriptor)

AddCube adds a cube to the list of cube meshes.

func (*UIMesh) CubeMeshIcon

func (e *UIMesh) CubeMeshIcon(x, y, w, h, d int, c *t.Cube, f t.Facing,
	defs []*t.Cube) *CubeMeshDrawDescriptor

CubeMeshIcon adds an icon rendering of a cube mesh.

func (*UIMesh) NinePatch

func (e *UIMesh) NinePatch(x, y, w, h int, n NinePatch)

NinePatch draws the specified area with the passed nine patch.

func (*UIMesh) Print

func (e *UIMesh) Print(x, y int, c [3]uint8, s string, args ...any)

Print as in c3d.TextMesh.Print.

func (*UIMesh) Reset

func (e *UIMesh) Reset(ui, text bool)

Reset resets the text object to blank. Internal memory buffers are retained to reduce allocations.

func (*UIMesh) Scaled

func (e *UIMesh) Scaled(x, y, w, h int, i t.FaceIndex)

Scaled draws the given UI tile at the position given in virtual screen units with the given width and height in virtual screen units.

func (*UIMesh) Tile

func (e *UIMesh) Tile(x, y int, i t.FaceIndex)

Tile draws the given UI tile at the position given in virtual screen units.

type VoxelMesh

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

VoxelMesh is a utility struct that builds voxel-based meshes.

func NewVoxelMesh

func NewVoxelMesh() *VoxelMesh

NewVoxelMesh constructs a new CubeMesh object ready for use.

func (*VoxelMesh) Reset

func (m *VoxelMesh) Reset()

Reset rests the mesh builder state.

type VoxelMeshDrawDescriptor

type VoxelMeshDrawDescriptor struct {
	ID       uint32     // ID
	Mesh     *VoxelMesh // The mesh to draw
	Position mgl32.Vec3 // Position of the center point of the voxel mesh
	Facing   t.Facing   // Facing of the mesh
}

VoxelMeshDrawDescriptor describes how and where to draw a cube mesh.

type VoxelSource

type VoxelSource[T any] interface {
	// Get returns the value at the given position within the voxel volume.
	Get(x, y, z int) T
	// Dimensions returns the dimensions of the voxel volume.
	Dimensions() (w, h, d int)
	// IsEmpty returns true if the value is considered empty.
	IsEmpty(v T) bool
}

VoxelSource is the interface that must be implemented by voxel data providers to the BuildVoxelMesh function.

Jump to

Keyboard shortcuts

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