packer

package module
v0.0.0-...-1f2c1b1 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2023 License: MIT Imports: 4 Imported by: 3

README

Packer

This is a work in progress texture packing standalone. Right now the packing algorithm isn't very optimized in terms of speed, but probably finds a fairly well packed set of images.

Install
go install github.com/unitoftime/packer/cmd/packer@latest

Note: the binary is held in cmd/packer/ so the suffix /... is required to install the packer binary to your go path.

Usage

Basic

packer --input sprites --output ./path/to/file
Flags
--input <Directory> - The directory of the input folder
--output <Filename> - The filename of the output json and png files
--extrude <Value> - The amount to extrude each sprite
--stats - If true, display statistics
--size <Value> - The width and height of the packed atlas
Serialized Json

The JSON file created by the packer binary is of form SerializedSpritesheet. (See packer.go for reference):

type SerializedRect struct {
	X,Y,W,H float64
}
type SerializedPos struct {
	X,Y float64
}
type SerializedDim struct {
	W,H float64
}

type SerializedFrame struct {
	Frame SerializedRect
	Rotated bool
	Trimmed bool
	SpriteSourceSize SerializedRect
	SourceSize SerializedDim
	Pivot SerializedPos
}
type SerializedSpritesheet struct {
	ImageName string
	Frames map[string]SerializedFrame
	Meta map[string]interface{}
}
Example Output

You can go to the packer/cmd/images/ and use the generate.sh script to generate some random images. Then you can rerun the test.

packed

Remaining Work
  • Create package to let developers dynamically pack images (ie not through command line)
  • Dynamically resize atlas image (rather than using a size flag)
  • Optimize

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtrudeImage

func ExtrudeImage(img image.Image, extrude int) image.Image

TODO - this is inefficient, but might not matter that much. I think most people will only extrude once

func ExtrudeImageOnce

func ExtrudeImageOnce(img image.Image) image.Image

TODO - needs cleanup

func PrepareImageList

func PrepareImageList(images []ImageData, extrude int)

Types

type ImageData

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

func BasicScanlinePacker

func BasicScanlinePacker(images []ImageData, width, height int) []ImageData

func NewImageData

func NewImageData(img image.Image, filename string) ImageData

func RowWisePacker

func RowWisePacker(images []ImageData, width, height int) []ImageData

func (*ImageData) Area

func (i *ImageData) Area() int

type MountData

type MountData struct {
	Filename    string
	MountPoints map[uint32]image.Point
}

type MountFrames

type MountFrames struct {
	Frames map[string]MountData
}

func CalculateMountPoints

func CalculateMountPoints(images []ImageData) MountFrames

type SerializedDim

type SerializedDim struct {
	W, H float64
}

type SerializedFrame

type SerializedFrame struct {
	Frame            SerializedRect
	Rotated          bool
	Trimmed          bool
	SpriteSourceSize SerializedRect
	SourceSize       SerializedDim
	Pivot            SerializedPos
}

type SerializedPos

type SerializedPos struct {
	X, Y float64
}

type SerializedRect

type SerializedRect struct {
	X, Y, W, H float64
}

type SerializedSpritesheet

type SerializedSpritesheet struct {
	ImageName string
	Frames    map[string]SerializedFrame
	Meta      map[string]interface{}
}

func Pack

func Pack(imageName string, images []ImageData, width, height int) (image.Image, SerializedSpritesheet)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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