Skip to content
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
3 changes: 2 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
#### Fixes :wrench:

- Billboards using `imageSubRegion` now render as expected. [#12585](https://github.com/CesiumGS/cesium/issues/12585)
- Improved scaling of SVGs in billboards [#TODO](https://github.com/CesiumGS/cesium/issues/TODO)
- Improved scaling of SVGs in billboards [#13020](https://github.com/CesiumGS/cesium/issues/13020)
- Fixed unexpected outline artifacts around billboards [#13038](https://github.com/CesiumGS/cesium/issues/13038)

#### Additions :tada:

Expand Down
39 changes: 27 additions & 12 deletions packages/engine/Source/Core/TexturePacker.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ TexturePacker.prototype._findNode = function (node, { width, height }) {
return node;
}

const borderPadding = this._borderPadding;

// Vertical split (childNode1 = left half, childNode2 = right half).
if (widthDifference > heightDifference) {
node.childNode1 = new TextureNode({
Expand All @@ -130,12 +132,18 @@ TexturePacker.prototype._findNode = function (node, { width, height }) {
width,
height: nodeHeight,
});
node.childNode2 = new TextureNode({
x: rectangle.x + width,
y: rectangle.y,
width: widthDifference,
height: nodeHeight,
});

// Apply padding only along the vertical "cut".
const widthDifferencePadded = widthDifference - borderPadding;

if (widthDifferencePadded > 0) {
node.childNode2 = new TextureNode({
x: rectangle.x + width + borderPadding,
y: rectangle.y,
width: widthDifferencePadded,
height: nodeHeight,
});
}

return this._findNode(node.childNode1, { width, height });
}
Expand All @@ -147,12 +155,19 @@ TexturePacker.prototype._findNode = function (node, { width, height }) {
width: nodeWidth,
height,
});
node.childNode2 = new TextureNode({
x: rectangle.x,
y: rectangle.y + height,
width: nodeWidth,
height: heightDifference,
});

// Apply padding only along the horizontal "cut".
const heightDifferencePadded = heightDifference - borderPadding;

if (heightDifferencePadded > 0) {
node.childNode2 = new TextureNode({
x: rectangle.x,
y: rectangle.y + height + borderPadding,
width: nodeWidth,
height: heightDifferencePadded,
});
}

return this._findNode(node.childNode1, { width, height });
}

Expand Down
146 changes: 124 additions & 22 deletions packages/engine/Specs/Renderer/TextureAtlasSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -852,16 +852,16 @@ describe("Scene/TextureAtlas", function () {
.2222222222222222...............
.2222222222222222...............
.2222222222222222...............
.22222222222222223333333333.....
.22222222222222223333333333.....
.22222222222222223333333333.....
.22222222222222223333333333.....
.22222222222222223333333333.....
.22222222222222223333333333.....
.22222222222222223333333333.....
.22222222222222223333333333.....
.22222222222222223333333333.....
.2222222222222222333333333301...
.2222222222222222.3333333333....
.2222222222222222.3333333333....
.2222222222222222.3333333333....
.2222222222222222.3333333333....
.2222222222222222.3333333333....
.2222222222222222.3333333333....
.2222222222222222.3333333333....
.2222222222222222.3333333333.1..
.2222222222222222.3333333333....
.2222222222222222.3333333333.0..
................................
`.trim(),
);
Expand Down Expand Up @@ -926,9 +926,9 @@ describe("Scene/TextureAtlas", function () {
.2222222222...
.2222222222...
.2222222222...
.2222222222.1.
.2222222222...
.2222222222...
.222222222201.
.2222222222.0.
..............
`.trim(),
);
Expand Down Expand Up @@ -976,16 +976,16 @@ describe("Scene/TextureAtlas", function () {
.3333333333333333...............
.3333333333333333...............
.3333333333333333...............
.33333333333333332222222222.....
.33333333333333332222222222.....
.33333333333333332222222222.....
.33333333333333332222222222.....
.33333333333333332222222222.....
.33333333333333332222222222.....
.33333333333333332222222222.....
.33333333333333332222222222.....
.33333333333333332222222222.....
.3333333333333333222222222201...
.3333333333333333.2222222222....
.3333333333333333.2222222222....
.3333333333333333.2222222222....
.3333333333333333.2222222222....
.3333333333333333.2222222222....
.3333333333333333.2222222222....
.3333333333333333.2222222222....
.3333333333333333.2222222222.1..
.3333333333333333.2222222222....
.3333333333333333.2222222222.0..
................................
`.trim(),
);
Expand Down Expand Up @@ -1337,6 +1337,108 @@ describe("Scene/TextureAtlas", function () {
).contextToRender([0, 255, 0, 255]);
});

it("adds custom padding with borderWidthInPixels", async function () {
atlas = new TextureAtlas({ borderWidthInPixels: 0 });
let indices = await addImages();

expect(drawAtlas(atlas, indices)).toBe(
`
................
................
................
................
................
................
2222222222......
2222222222......
2222222222......
2222222222......
2222222222......
2222222222......
22222222220.....
22222222220.....
22222222220.....
222222222201....
`.trim(),
);

atlas = new TextureAtlas({ borderWidthInPixels: 2 });
indices = await addImages();

expect(drawAtlas(atlas, indices)).toBe(
`
................................
................................
................................
................................
..2222222222....................
..2222222222....................
..2222222222....................
..2222222222..1.................
..2222222222....................
..2222222222....................
..2222222222..0.................
..2222222222..0.................
..2222222222..0.................
..2222222222..0.................
................................
................................
`.trim(),
);

atlas = new TextureAtlas({ borderWidthInPixels: 5 });
indices = await addImages();

expect(drawAtlas(atlas, indices)).toBe(
`
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
.....2222222222.................
.....2222222222.................
.....2222222222.................
.....2222222222.................
.....2222222222.................
.....2222222222.................
.....2222222222.....0...........
.....2222222222.....0...........
.....2222222222.....0...........
.....2222222222.....0.....1.....
................................
................................
................................
................................
................................
`.trim(),
);

async function addImages() {
const promise = Promise.all([
atlas.addImage(tallGreenGuid, tallGreenImage),
atlas.addImage(blueGuid, blueImage),
atlas.addImage(bigBlueGuid, bigBlueImage),
]);

return pollWhilePromise(promise, () => {
atlas.update(scene.frameState.context);
});
}
});

it("GUID changes when atlas texure is modified", async function () {
atlas = new TextureAtlas();

Expand Down