-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Texpacker #18
Add Texpacker #18
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still using a single file for output while it should do two (packed PNG + metadata). My original doc referred to "Header" meaning "C header file", not header of the actual texture.
go build -o bin/tevasm ./tevasm | ||
go build -o bin/texpacker ./texpacker |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add the "go get" command on top of both build files, just like tools-extra/build.*
tools/texpacker/format.go
Outdated
|
||
// 8 bytes | ||
type Rect struct { | ||
Start, Size Point |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Size isn't a point, so either rename Point
to be less specialized (Vector2?)
Or change what Size is?
tools/texpacker/main.go
Outdated
noheader := flag.Bool("noheader", false, "Don't write header, output raw PNG") | ||
cwd, err := os.Getwd() | ||
checkErr(err, "Couldn't get working directory") | ||
stripPfx := flag.String("strip", cwd, "Prefix to strip from file paths for hashing") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not call this -prefix
? The current name sounds like its a toggle flag
tools/texpacker/main.go
Outdated
// All positional arguments are input files | ||
inputFiles := flag.Args() | ||
|
||
maxBounds := image.Point{1 << 16, 1 << 16} // TODO |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot a TODO here, flag?
tools/texpacker/format.go
Outdated
func ToFileHash(s string) FileHash { | ||
hash.Reset() | ||
_, err := fmt.Fprintf(hash, s) | ||
if err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why doesnt this use checkErr ?
tools/texpacker/main.go
Outdated
checkErr(err, "Error converting file path %s to absolute", path) | ||
packer.Add(abspath) | ||
} | ||
if err := packer.Save(); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why doesn this use checkErr ?
tools/texpacker/packer.go
Outdated
|
||
// writeImageAt adds all pixels of `src` to `dst`, starting from pixel at (`x`,`y`). | ||
// It returns an error if the whole source image couldn't be added to the target. | ||
func writeImageAt(dst *image.RGBA, src image.Image, x, y int) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could instead use image.SubImage
and the image/draw
functions?
if tryOk { | ||
contextSize = trySize | ||
rects = tryRects | ||
shrunk = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will still cause it to try shrinkY, is that ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's probably a typo in the function I copy-pasted, it should be shrinkY = false
in the shrinkY
branch.
- add go get to build scripts - change Point -> Vector2 - use checkErr where appropriate - change -strip -> -prefix - pass max bounds via flags - use image/draw functions instead of writeImageAt - fix typo in minimizeFit
Ok, I should have fixed all issues. Now the tool outputs 2 files: |
tools/texpacker/main.go
Outdated
outpath := flag.String("o", "-", "Output file (- for STDOUT)") | ||
noheader := flag.Bool("noheader", false, "Don't write header, output raw PNG") | ||
outpath := flag.String("o", "out.png", "Output file") | ||
maxW := flag.Int("maxwidth", 1<<16, "Max width of output texture in pixels") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Up for discussion, do we wanna support non-square atlasses? if not, only needs 1 flag ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No reason to, I think.
tools/texpacker/packer.go
Outdated
} | ||
return out, nil | ||
headerOut, err = os.Create(packer.outfile + ".atlas") | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this returns an error, TexPacker.Save
will not close the imageOut
Latest commit should have fixed both issues. |
(See #12)
Texpacker now works hopefully well. I tried sticking to the rest of the tools' style as much as possible, so it should be pretty familiar to review.
Usage
Basically it takes input textures as positional arguments and spits out a binary file with the format
[header | PNG image]
. It can be told to output just the PNG for debugging purposes.The
-strip
flag is used to make the tool usable from any directory: the hashed paths will be relative to the path given to-strip
.The packing algorithm is currently maxrects and uses
"github.com/adinfinit/texpack/maxrect"
which is MIT-licensed.Header format
The header looks like this:
Forgot anything?