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

Add margins to the left and top edges of the atlas. #8657

Merged
merged 2 commits into from Mar 11, 2024
Merged

Add margins to the left and top edges of the atlas. #8657

merged 2 commits into from Mar 11, 2024

Conversation

AGulev
Copy link
Contributor

@AGulev AGulev commented Mar 10, 2024

Fixed an issue where the margin specified for the atlas ignored the top and left edges of the atlas and was added only between images and on the right and the bottom edges of the atlas.

Fix #8584

PR checklist

  • Code
    • Add engine and/or editor unit tests.
    • New and changed code follows the overall code style of existing code
    • Add comments where needed
  • Documentation
    • Make sure that API documentation is updated in code comments
    • Make sure that manuals are updated (in github.com/defold/doc)
  • Prepare pull request and affected issue for automatic release notes generator
    • Pull request - Write a message that explains what this pull request does. What was the problem? How was it solved? What are the changes to APIs or the new APIs introduced? This message will be used in the generated release notes. Make sure it is well written and understandable for a user of Defold.
    • Pull request - Write a pull request title that in a sentence summarises what the pull request does. Do not include "Issue-1234 ..." in the title. This text will be used in the generated release notes.
    • Pull request - Link the pull request to the issue(s) it is closing. Use on of the approved closing keywords.
    • Affected issue - Assign the issue to a project. Do not assign the pull request to a project if there is an issue which the pull request closes.
    • Affected issue - Assign the "breaking change" label to the issue if introducing a breaking change.
    • Affected issue - Assign the "skip release notes" is the issue should not be included in the generated release notes.

Example of a well written PR description:

  1. Start with the user facing changes. This will end up in the release notes.
  2. Add one of the GitHub approved closing keywords
  3. Optionally also add the technical changes made. This is information that might help the reviewer. It will not show up in the release notes. Technical changes are identified by a line starting with one of these:
    1. ### Technical changes
    2. Technical changes:
    3. Technical notes:
There was a anomaly in the carbon chroniton propeller, introduced in version 8.10.2. This fix will make sure to reset the phaser collector on application startup.

Fixes #1234

### Technical changes
* Pay special attention to line 23 of phaser_collector.clj as it contains some interesting optimizations
* The propeller code was not taking into account a negative phase.

@AGulev AGulev added the atlas Issues related to atlas creation label Mar 10, 2024
@AGulev AGulev requested a review from JCash March 10, 2024 08:53
@@ -70,7 +70,8 @@ public List<Layout> createLayout(List<Rect> srcRects) {
ArrayList<Rect> rects = new ArrayList<Rect>(page.outputRects.size());
for(RectNode node : page.outputRects) {
Rect finalRect = new Rect(node.rect.getId(), node.rect.getIndex(), node.rect.getPage(),
node.rect.getX(), node.rect.getY(), node.rect.getWidth() - settings.paddingX, node.rect.getHeight() - settings.paddingY,
node.rect.getX() + settings.paddingX, node.rect.getY() + settings.paddingY,
node.rect.getWidth() - settings.paddingX, node.rect.getHeight() - settings.paddingY,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In line 55-56 we add settings.paddingX() and settings.paddingY to each image rect to take it into account. Here we subtract it from rect size to restore size as it was.
This operation add margin between images + on the right and bottom edge of the atlas (because it affects rect size and 0;0 is in top left corner), but left and top edges of the atlas ignored.

To take it into account I reduce size of the atlas for margin (settings.paddingX and settings.paddingY) and here I move each rect position to add this space from left and top side.

throw new RuntimeException("Image does not fit with max page width " + settings.maxPageWidth + " and paddingX "
+ settings.paddingX + ": " + rect);
}
if (rect.getHeight() > settings.maxPageHeight && (!settings.rotation || rect.getWidth() > settings.maxPageHeight)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Second half of condition doesn't make any sense, because it's already in !settings.rotation) branch

@@ -119,14 +120,14 @@ private Page packPage(ArrayList<RectNode> inputRects) {
BinarySearch sizeSearch = new BinarySearch(minSize, maxSize);
int size = sizeSearch.reset();
while (size != -1) {
Page result = packAtSize(true, size, size, inputRects);
Page result = packAtSize(true, size - settings.paddingX, size - settings.paddingY, inputRects);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reduce all the places where we use size for margin to be able to move all the rects from top left corner for margin count of pixels

@AGulev AGulev merged commit f4db7d9 into dev Mar 11, 2024
22 checks passed
@AGulev AGulev deleted the issue-8584 branch March 11, 2024 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
atlas Issues related to atlas creation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sprite Atlas "Margin" setting is only applied between sprites, not at atlas edges.
2 participants