Skip to content
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

Added max rects and pivot point support to texture packer plugin #11

Merged
merged 4 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified examples/basic/basic-0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/basic/basic-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed examples/basic/basic-2.png
Binary file not shown.
Binary file removed examples/basic/basic-3.png
Binary file not shown.
454 changes: 214 additions & 240 deletions examples/basic/basic.tpinfo

Large diffs are not rendered by default.

90 changes: 12 additions & 78 deletions examples/basic/basic.tps
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<key>fileFormatVersion</key>
<int>6</int>
<key>texturePackerVersion</key>
<string>7.1.0</string>
<string>7.4.0</string>
<key>autoSDSettings</key>
<array>
<struct type="AutoSDSettings">
Expand Down Expand Up @@ -32,7 +32,7 @@
<key>dpi</key>
<uint>72</uint>
<key>dataFormat</key>
<string>defoldexporter</string>
<string>defold</string>
<key>textureFileName</key>
<filename></filename>
<key>flipPVR</key>
Expand Down Expand Up @@ -64,7 +64,7 @@
</struct>
</struct>
<key>shapePadding</key>
<uint>1</uint>
<uint>0</uint>
<key>jpgQuality</key>
<uint>80</uint>
<key>pngOptimizationLevel</key>
Expand All @@ -76,7 +76,7 @@
<key>textureFormat</key>
<enum type="SettingsBase::TextureFormat">png</enum>
<key>borderPadding</key>
<uint>1</uint>
<uint>0</uint>
<key>maxTextureSize</key>
<QSize>
<key>width</key>
Expand Down Expand Up @@ -161,53 +161,21 @@
<key>trimMargin</key>
<uint>1</uint>
<key>trimMode</key>
<enum type="SpriteSettings::TrimMode">Polygon</enum>
<enum type="SpriteSettings::TrimMode">Trim</enum>
<key>tracerTolerance</key>
<int>200</int>
<key>heuristicMask</key>
<false/>
<key>defaultPivotPoint</key>
<point_f>0,0</point_f>
<key>writePivotPoints</key>
<false/>
<true/>
</struct>
<key>individualSpriteSettings</key>
<map type="IndividualSpriteSettingsMap">
<key type="filename">original/anim/test-0.png</key>
<key type="filename">original/anim/test-1.png</key>
<key type="filename">original/anim/test-2.png</key>
<struct type="IndividualSpriteSettings">
<key>pivotPoint</key>
<point_f>0,0</point_f>
<key>spriteScale</key>
<double>1</double>
<key>scale9Enabled</key>
<false/>
<key>scale9Borders</key>
<rect>16,16,32,32</rect>
<key>scale9Paddings</key>
<rect>16,16,32,32</rect>
<key>scale9FromFile</key>
<false/>
</struct>
<key type="filename">original/box_fill_128.png</key>
<key type="filename">original/circle_fill_128.png</key>
<key type="filename">original/shape_L_128.png</key>
<key type="filename">original/triangle_fill_128.png</key>
<struct type="IndividualSpriteSettings">
<key>pivotPoint</key>
<point_f>0.5,0.5</point_f>
<key>spriteScale</key>
<double>1</double>
<key>scale9Enabled</key>
<false/>
<key>scale9Borders</key>
<rect>32,32,64,64</rect>
<key>scale9Paddings</key>
<rect>32,32,64,64</rect>
<key>scale9FromFile</key>
<false/>
</struct>
<key type="filename">original/box_fill_64.png</key>
<key type="filename">original/circle_fill_64.png</key>
<key type="filename">original/triangle_fill_64.png</key>
Expand All @@ -225,10 +193,14 @@
<key>scale9FromFile</key>
<false/>
</struct>
<key type="filename">original/box_fill_128.png</key>
<key type="filename">original/box_small_128.png</key>
<key type="filename">original/circle_fill_128.png</key>
<key type="filename">original/shape_L_128.png</key>
<key type="filename">original/triangle_fill_128.png</key>
<struct type="IndividualSpriteSettings">
<key>pivotPoint</key>
<point_f>0,0</point_f>
<point_f>0.5,0.5</point_f>
<key>spriteScale</key>
<double>1</double>
<key>scale9Enabled</key>
Expand Down Expand Up @@ -272,44 +244,6 @@
<key>normalMapSheetFileName</key>
<filename></filename>
<key>exporterProperties</key>
<map type="ExporterProperties">
<key>defoldexporter::animations_flip</key>
<struct type="ExporterProperty">
<key>value</key>
<string></string>
</struct>
<key>defoldexporter::animations_fps</key>
<struct type="ExporterProperty">
<key>value</key>
<string>24</string>
</struct>
<key>defoldexporter::animations_playback</key>
<struct type="ExporterProperty">
<key>value</key>
<string>once_forward</string>
</struct>
<key>defoldexporter::animations_trim</key>
<struct type="ExporterProperty">
<key>value</key>
<string>off</string>
</struct>
<key>defoldexporter::assets_path</key>
<struct type="ExporterProperty">
<key>value</key>
<string>assets/{atlas_name}/{animation_name}</string>
</struct>
<key>defoldexporter::extrude_borders</key>
<key>defoldexporter::inner_padding</key>
<key>defoldexporter::margin</key>
<struct type="ExporterProperty">
<key>value</key>
<string>0</string>
</struct>
<key>defoldexporter::sprite-prefix</key>
<struct type="ExporterProperty">
<key>value</key>
<string>img_</string>
</struct>
</map>
<map type="ExporterProperties"/>
</struct>
</data>
4 changes: 0 additions & 4 deletions examples/broken/README.md

This file was deleted.

3 changes: 0 additions & 3 deletions examples/broken/broken.tpatlas

This file was deleted.

61 changes: 0 additions & 61 deletions examples/broken/missing_image.tpinfo

This file was deleted.

4 changes: 2 additions & 2 deletions exporter/defold/exporter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
<supportsPolygonPacking>true</supportsPolygonPacking>

<!-- target framework supports pivot point settings (default=false) -->
<supportsPivotPoint>false</supportsPivotPoint>
<supportsPivotPoint>true</supportsPivotPoint>

<!-- target framework accepts sprite names without file name extension. (default=false) -->
<supportsTrimSpriteNames>false</supportsTrimSpriteNames>
Expand Down Expand Up @@ -133,7 +133,7 @@
<borderPadding>0</borderPadding>
<trimMode>Polygon</trimMode> <!-- None, Trim, Crop, CropKeepPos, Polygon -->
<sizeConstraints>POT</sizeConstraints> <!-- POT, WordAligned, AnySize -->
<writePivotPoints>false</writePivotPoints> <!-- true, false -->
<writePivotPoints>true</writePivotPoints> <!-- true, false -->
<defaultPivotPoint>0.5,0.5</defaultPivotPoint>
</defaults>

Expand Down
33 changes: 26 additions & 7 deletions exporter/defold/grantlee/0.2/defoldscript.qs
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,37 @@ var exportSprite = function(output, indentLevel, sprite)
field("is_solid", sprite.isSolid, indentLevel+1),
)

//exportPoint(output, indentLevel+1, "centerOffset", sprite.centerOffset); // don't think we need this one
exportPoint(output, indentLevel+1, "corner_offset", sprite.cornerOffset);
exportRect(output, indentLevel+1, "source_rect", sprite.sourceRect);
exportPoint(output, indentLevel+1, "pivot", sprite.pivotPoint);
exportRect(output, indentLevel+1, "frame_rect", sprite.frameRect);
exportSize(output, indentLevel+1, "untrimmed_size", sprite.untrimmedSize);

for (let i = 0; i < sprite.vertices.length; ++i) {
let vertex = sprite.vertices[i];
exportPoint(output, indentLevel+1, "vertices", vertex);
}
// The vertices are in sprite image coordinate space (texels)
// Rotation is handled later in the pipeline
if (sprite.vertices.length > 0)
{
for (let i = 0; i < sprite.vertices.length; ++i) {
let vertex = sprite.vertices[i];
exportPoint(output, indentLevel+1, "vertices", vertex);
}

exportIntArray(output, indentLevel+1, "indices", sprite.triangleIndices);
exportIntArray(output, indentLevel+1, "indices", sprite.triangleIndices);
}
else
{
exportIntArray(output, indentLevel+1, "indices", [1, 2, 3, 0, 1, 3]);

let x0 = sprite.sourceRect.x;
let y0 = sprite.sourceRect.y;
let x1 = x0 + sprite.sourceRect.width;
let y1 = y0 + sprite.sourceRect.height;

exportPoint(output, indentLevel+1, "vertices", {x: x1, y: y0}); // TR
exportPoint(output, indentLevel+1, "vertices", {x: x0, y: y0}); // TL
exportPoint(output, indentLevel+1, "vertices", {x: x0, y: y1}); // BL
exportPoint(output, indentLevel+1, "vertices", {x: x1, y: y1}); // BR
Comment on lines +102 to +105
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We export a polygon that happens to be a rectangle.

}

output.push(indent(indentLevel) + "}");
}
Expand Down Expand Up @@ -116,7 +135,7 @@ var exportAtlas = function(root)
""
);

output.push("version: \"1.1\""); // our file format version
output.push("version: \"2.0\""); // our file format version
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to know we can tell the files apart, if anything goes wrong.

output.push("description: \"Exported using TexturePacker\""); // The tool used

let textures = root.allResults[root.variantIndex].textures;
Expand Down
21 changes: 18 additions & 3 deletions texturepacker/editor/src/texturepacker.clj
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,12 @@
(def ^:private TSize
(s/pair s/Num "width" s/Num "height"))

(def ^:private TPoint
(s/pair s/Num "x" s/Num "y"))

(def ^:private TImageInfo
{:index-count s/Int
:pivot TPoint
:size TSize
:untrimmed-size TSize
:vertex-count s/Int})
Expand Down Expand Up @@ -490,12 +494,18 @@
(into {}
(mapcat
(fn [page]
(map (fn [{:keys [frame-rect indices untrimmed-size vertices] :as sprite}]
(map (fn [{:keys [frame-rect indices untrimmed-size vertices pivot] :as sprite}]
(let [original-name (:name sprite)
size [(:width frame-rect) (:height frame-rect)]
untrimmed-size [(:width untrimmed-size) (:height untrimmed-size)]]
width (:width untrimmed-size)
height (:height untrimmed-size)
untrimmed-size [width height]
pivot (if pivot
[(:x pivot) (:y pivot)]
[(/ width 2.0) (/ height 2.0)])]
(pair original-name
{:size size
{:pivot pivot
:size size
:untrimmed-size untrimmed-size
:vertex-count (count vertices)
:index-count (count indices)})))
Expand Down Expand Up @@ -608,6 +618,11 @@
(dynamic error (g/fnk [_node-id original-name tpinfo-image-infos-by-original-name]
(validate-original-name _node-id original-name tpinfo-image-infos-by-original-name))))

(property pivot types/Vec2
(value (g/fnk [tpinfo-image-info] (:pivot tpinfo-image-info)))
(dynamic edit-type (g/constantly {:type types/Vec2 :labels ["X" "Y"]}))
(dynamic read-only? (g/constantly true)))

(property size types/Vec2
(value (g/fnk [tpinfo-image-info] (:size tpinfo-image-info)))
(dynamic edit-type (g/constantly {:type types/Vec2 :labels ["W" "H"]}))
Expand Down
Binary file modified texturepacker/plugins/share/pluginTexturePackerExt.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,18 @@ static private TextureSetLayout.SourceImage createSprite(Info.Sprite srcSprite)
float width;
float height;

TextureSetLayout.Point pivot;
if (srcSprite.hasPivot()) // backwards compatibility
pivot = AtlasBuilder.createPoint(srcSprite.getPivot());
else
{
pivot = new TextureSetLayout.Point(originalSize.getWidth() * 0.5f, originalSize.getHeight() * 0.5f);
}

// Transform it like a regular vertex
pivot.y = originalSize.getHeight() - pivot.y;
out.setPivot(pivot);

// For legacy reasons, the other bob code wants it already rotated
if (rotated)
{
Expand Down
2 changes: 0 additions & 2 deletions utils/build_plugins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ set -e

PROJECT=texturepacker
DEFAULT_SERVER=https://build-stage.defold.com
#DEFAULT_SERVER=http://localhost:9000

# 1.9.3 alpha
DEFOLDSDK=b5ed137e64ee409ce64bcf468947385e8091f41b
Expand All @@ -26,7 +25,6 @@ echo "Using DEFOLDSDK=${DEFOLDSDK}"
if [ "" == "${SERVER}" ]; then
SERVER=${DEFAULT_SERVER}
fi
#SERVER=http://localhost:9000

echo "Using SERVER=${SERVER}"

Expand Down
Loading