odrick / free-tex-packer-core Goto Github PK
View Code? Open in Web Editor NEWFree texture packer core
License: MIT License
Free texture packer core
License: MIT License
Please add an option so that identical images are deleted only from the texture, but not from the resulting json file. Duplicate files must link to the same area of texture. This is necessary for the animation where the character can remain motionless for some time.
Пожалуйста добавьте опцию чтобы идентичные изображения удалялись только из текстуры, но не из результирующего json файла. Дублирующиеся файлы должны ссылать на один и тот же участок текстуры. Это необходимо для анимации где персонаж может некоторое время оставаться неподвижным.
I have come across a issue where the packer does not generate the minimum possible number output spritesheet when exceeding the spritesheet width and height and scale enabled.
when width and height is set to 4096
i should get a single 4096x2048 spritesheet but end up with 2 spritesheet of.
2048x2048
1024x512
it seems like the issue is linked to using the original width and height and not the adjusted width and height using the scale.
@odrick
Egret Engine 2D is an H5 game Engine,but it not support texture pack by CLI
{
"file": "{{config.imageName}}",
"frames": {
{{#rects}}
"{{{name}}}": {
"x": {{frame.x}},
"y": {{frame.y}},
"w": {{frame.w}},
"h": {{frame.h}},
"hw": {{frame.hw}},
"hh": {{frame.hh}}
}{{^last}},{{/last}}
{{/rects}}
}
}
free-tex-packer-core/index.d.ts
Line 85 in 1168d28
Issue goes away when I revert back to "free-tex-packer-core": "0.3.2"
Currently presence of scale
property in configuration - does almost nothing,
The only way how it's using in the code at the moment - it's passing it into exporter template.
In my opinion - it should affect textures scale (resize them) and their positions in the atlas (as it described in readme).
May be I've missed something or it is intended to be so?
Hi, would it be possible to add simple option to force power of two resulting texture size when width/height are not forced?
Thank you!
When multiple output files get generated due to having too many images in your atlas there is no way of knowing how many of them were created.
Maybe a file that tells you how many atlas were created could be useful?
(I would make this an option to always do it (even if only one atlas was created) so from code I can just tell my loader to check one file and load all the things that said file knows: be it one or many atlas.)
anyway, awesome work!
Edit: Maybe a metadata field for that would be simpler and break less stuff?
Edit2: the metafield related_multi_packs
could host an array of strings naming all the other files created by the packer. We could inject it into the options
object here: https://github.com/odrick/free-tex-packer-core/blob/master/FilesProcessor.js#L27 however I am not sure how this would affect the templating system :S
(It seems that the metafield related_multi_packs
is what is used for that in other packers)
I am trying to multipack a set of textures to a nearest low po2 value by adjusting the width and height (currently 1024 and 512 respectively), except this is my output:
My full settings are:
"packer": "OptimalPacker",
"packerMethod": "Automatic",
"width": 1024,
"height": 512,
"fixedSize": false,
"powerOfTwo": true,
"alphaThreshold": 4
"padding": 0,
"extrude": 1,
"allowRotation": true,
"detectIdentical": true,
"allowTrim": true,
"removeFileExtension": true,
"prependFolderName": false,
"textureFormat": "png",
"base64Export": false,
"scale": 1,
"exporter": "JsonHash",
"filter": "none"
My source assets:
Seems like a multipack bug, its creating the second texture on the first
It is not supported?
Hope when use trim mode, and crop the image, the original image size and position can be kept.
It would be great if end user will have an ability to track packing failure:
const packer = require('free-tex-packer-core');
...
packer(items, options, (result, err) => {
if (err) {
logger.error(err);
return;
}
});
Right now I can't track if packing is finished/failed.
Currently this library exports multipack textures into several JSON and image files.
Phaser 3 format supports inserting all exported textures into a single JSON file inside the textures array. As seen in this example:
https://github.com/photonstorm/phaser3-examples/blob/master/public/assets/atlas/tp3-multi-atlas.json
The attached image has a lot of transparent padding causing it to be larger than options.width
& options.height
, and the "Invalid size"
error is thrown by PackProcessor
.
Trimming any transparent pixels should take effect before minWidth
and minHeight
are calculated.
To Reproduce
Using this image...
await packAsync(
[{
path: 'a.png',
contents: await readFile('a.png')
}],
{
exporter: 'JsonHash',
textureFormat: 'png',
textureName: 'a.png',
width: 2048,
height: 2048,
allowTrim: true
}
);
This produces an Invalid size
error.
Note that if you bypass the error by settingoptions.width = 6000
& options.height = 6000
the atlas is packed and the resulting image size is only 112x32 (well within the 2048x2048 limits).
Firstly, thank you for such an awesome product! If possible it would be really nice to have the equivalent of texture packers --trim-threshold
as detailed here https://www.codeandweb.com/texturepacker/documentation/texture-settings. It can really lead to great savings for images with a lot of alpha at the edges, especially if multipacked!
Spine atlas exporter offset is always 0,0
Offset should be calculated from lower-left corner.
I forked your module and wrote some additional codes.
I hope you helped a little.
let tpOffset = {
x: item.spriteSourceSize.x,
// *Caculate lower-left corner based offset for TexturePacker .atlas format
y: item.sourceSize.h - (item.spriteSourceSize.y + item.spriteSourceSize.h)
};
return {
name: name,
frame: frame,
spriteSourceSize: spriteSourceSize,
sourceSize: sourceSize,
index: index,
first: index === 0,
last: index === data.length - 1,
rotated: item.rotated,
trimmed: trimmed,
// *Added tpOffset value to use inside .mst
tpOffset: tpOffset,
};
offset: {{tpOffset.x}},{{tpOffset.y}}
Cocos Creator (AFIK 3.3.0 and 2.4.8) rotates the image by 90deg clockwise with Sharp when generating an atlas:
While `Jimp.rotate(90)` is counter-clockwise.Please consider rotating 90deg clockwise when exporting toCocos2d
with plist
format3.
Here is a proposal of Cocos2d.mst
:
{{=<% %>=}}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>frames</key>
<dict>
<%#rects%>
<key><%&name%></key>
<dict>
<key>aliases</key>
<array/>
<key>spriteOffset</key>
<string>{<% spriteSourceSize.x | offsetLeft : spriteSourceSize.w : sourceSize.w %>,<% spriteSourceSize.y | offsetRight : spriteSourceSize.h : sourceSize.h %>}</string>
<key>spriteSize</key>
<string>{<%spriteSourceSize.w%>,<%spriteSourceSize.h%>}</string>
<key>spriteSourceSize</key>
<string>{<%sourceSize.w%>,<%sourceSize.h%>}</string>
<key>textureRect</key>
<string>{{<%frame.x%>,<%frame.y%>},{<%frame.w%>,<%frame.h%>}}</string>
<key>textureRotated</key>
<<%rotated%>/>
</dict>
<%/rects%>
</dict>
<key>metadata</key>
<dict>
<key>format</key>
<integer>3</integer>
<key>pixelFormat</key>
<string><%config.format%></string>
<key>premultiplyAlpha</key>
<false/>
<key>realTextureFileName</key>
<string><%config.imageFile%></string>
<key>size</key>
<string>{<%config.imageWidth%>,<%config.imageHeight%>}</string>
<key>textureFileName</key>
<string><%config.imageName%></string>
</dict>
</dict>
</plist>
<%={{ }}=%>
summary
rotationDirection
into config rotation cw/ccw like CustomExporterupdate:
Here is a PR also fix the rotation issue:
Format version mismatch
according to https://www.codeandweb.com/blog/2016/01/29/cocos2d-plist-format-explained
The format in this repo is not v3, but it indicates itself v3.
Actually it's v2 format. Not sure what it supposed to be.
textureFileName is always empty
<key>textureFileName</key>
<string><%config.imageFile%></string>
config.imageFile is not set.
This causes the png of the sprite sheet cannot be found, neither Cocostudio (UI tool) nor cocos2d-x 3.17 library.
<key>metadata</key>
<dict>
<key>format</key>
<integer>2</integer>
<key>pixelFormat</key>
<string><%config.format%></string>
<key>premultiplyAlpha</key>
<false/>
<key>realTextureFileName</key>
<string><%config.imageName%></string>
<key>size</key>
<string>{<%config.imageWidth%>,<%config.imageHeight%>}</string>
<key>textureFileName</key>
<string><%config.imageName%></string>
</dict>
Google I/O Adventure
Please add an option to sort the images by names in the array, so that they can be embedded in a animations object before meta object. Like below...
"animations": {
"{{config.imageName}}": [{{#rects}}"{{{name}}}"{{^last}},{{/last}}{{/rects}}]
}
Also maybe in the future you can add animations options created folder wise.
Thank you all for a superb software :)
Hello, all. Is it possible for any one of you contributors who understand javascript to add an exportable variable that can be accessed inside of the 'custom' exporter (using mustache)?
I need a numerical index reference for each '{{rects}}' that is process, preferably starting at 1 and not zero. I was trying to do it myself but I have zero clue on how to even install / run the javascript code. Thanks for any help.
First off, amazing work on this! Its easily the strongest alternative to texture packer i have seen 👍
A feature which I think would be super handy to have on this would be a multi-pack option.
This would mean that multiple textures / jsons would be created if all the images do not fit in the single texture of a defined size.
Cheers!
This PR #6 fixed options not passing through.
However, after allowing rotation, my packing result needs more area. (Can't fit in original constraint size)
I have to manually disable rotation to ensure my result the same as before.
Is this a normal case?
Hi,
It would be great if there was an additional packing option, that would automatically choose the best packer
and packMethod
combinations based on the most optimal expected result. Hence the name 'Best'.
We have found that there is no one combination that works for everything, to find the best combination is a manual process, and since we have 100s of spritesheets being generated the process is tedious. And as source assets changed the same process is repeated.
For our use, the method to determine 'best' would be:
It may take a little longer, but in our case it is part of an automated deployment process so time is less important. If time is a big concern the 'Best' option does not need to be the default
Case
Image's dimension larger than atlas dimension.
Current Behavior:
There will be an error.
Proposed Behavior:
Throw warning and exclude that image from atlas.
Hi there, i have created a spritesheet and am unable to export it.
The spritesheet was generated from a folder with 3 subfolders
I can view the animation cells just fine and play them back as well, just the export is not working.
Tried restarting and re-creating the spritesheet, no luck.
Version 0.6.7
Aside from the export-issue, this tool is really neat!
Best,
David
EDIT: I can export if i select a predefined format. Not sure if it's actually a bug or if I was using incorrect settings, feel free to close if it's the latter or too irrelevant.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.