Skip to content

Commit 84c0e3a

Browse files
committed
fix(textureatlas): Apply internal padding between images
1 parent bd5aa3f commit 84c0e3a

File tree

3 files changed

+51
-35
lines changed

3 files changed

+51
-35
lines changed

CHANGES.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
#### Fixes :wrench:
88

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

1213
#### Additions :tada:
1314

packages/engine/Source/Core/TexturePacker.js

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ TexturePacker.prototype._findNode = function (node, { width, height }) {
122122
return node;
123123
}
124124

125+
const borderPadding = this._borderPadding;
126+
125127
// Vertical split (childNode1 = left half, childNode2 = right half).
126128
if (widthDifference > heightDifference) {
127129
node.childNode1 = new TextureNode({
@@ -130,12 +132,18 @@ TexturePacker.prototype._findNode = function (node, { width, height }) {
130132
width,
131133
height: nodeHeight,
132134
});
133-
node.childNode2 = new TextureNode({
134-
x: rectangle.x + width,
135-
y: rectangle.y,
136-
width: widthDifference,
137-
height: nodeHeight,
138-
});
135+
136+
// Apply padding only along the vertical "cut".
137+
const widthDifferencePadded = widthDifference - borderPadding;
138+
139+
if (widthDifferencePadded > 0) {
140+
node.childNode2 = new TextureNode({
141+
x: rectangle.x + width + borderPadding,
142+
y: rectangle.y,
143+
width: widthDifferencePadded,
144+
height: nodeHeight,
145+
});
146+
}
139147

140148
return this._findNode(node.childNode1, { width, height });
141149
}
@@ -147,12 +155,19 @@ TexturePacker.prototype._findNode = function (node, { width, height }) {
147155
width: nodeWidth,
148156
height,
149157
});
150-
node.childNode2 = new TextureNode({
151-
x: rectangle.x,
152-
y: rectangle.y + height,
153-
width: nodeWidth,
154-
height: heightDifference,
155-
});
158+
159+
// Apply padding only along the horizontal "cut".
160+
const heightDifferencePadded = heightDifference - borderPadding;
161+
162+
if (heightDifferencePadded > 0) {
163+
node.childNode2 = new TextureNode({
164+
x: rectangle.x,
165+
y: rectangle.y + height + borderPadding,
166+
width: nodeWidth,
167+
height: heightDifferencePadded,
168+
});
169+
}
170+
156171
return this._findNode(node.childNode1, { width, height });
157172
}
158173

packages/engine/Specs/Renderer/TextureAtlasSpec.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -832,16 +832,16 @@ describe("Scene/TextureAtlas", function () {
832832
expect(drawAtlas(atlas, [index0, index1, index2, index3])).toBe(
833833
`
834834
••••••••••••••••••••••••••••••••
835-
2222222222222222333333333301•••
836-
22222222222222223333333333•••••
837-
22222222222222223333333333•••••
838-
22222222222222223333333333•••••
839-
22222222222222223333333333•••••
840-
22222222222222223333333333•••••
841-
22222222222222223333333333•••••
842-
22222222222222223333333333•••••
843-
22222222222222223333333333•••••
844-
22222222222222223333333333•••••
835+
2222222222222222•3333333333•0••
836+
2222222222222222•3333333333••••
837+
2222222222222222•3333333333•1••
838+
2222222222222222•3333333333••••
839+
2222222222222222•3333333333••••
840+
2222222222222222•3333333333••••
841+
2222222222222222•3333333333••••
842+
2222222222222222•3333333333••••
843+
2222222222222222•3333333333••••
844+
2222222222222222•3333333333••••
845845
•2222222222222222•••••••••••••••
846846
•2222222222222222•••••••••••••••
847847
•2222222222222222•••••••••••••••
@@ -917,9 +917,9 @@ describe("Scene/TextureAtlas", function () {
917917
expect(drawAtlas(atlas, [index0, index1, index2])).toBe(
918918
`
919919
••••••••••••••
920-
•222222222201•
921-
•2222222222•••
920+
•2222222222•0•
922921
•2222222222•••
922+
•2222222222•1•
923923
•2222222222•••
924924
•2222222222•••
925925
•2222222222•••
@@ -956,16 +956,16 @@ describe("Scene/TextureAtlas", function () {
956956
expect(drawAtlas(atlas, [index0, index1, index2, index3])).toBe(
957957
`
958958
••••••••••••••••••••••••••••••••
959-
3333333333333333222222222201•••
960-
33333333333333332222222222•••••
961-
33333333333333332222222222•••••
962-
33333333333333332222222222•••••
963-
33333333333333332222222222•••••
964-
33333333333333332222222222•••••
965-
33333333333333332222222222•••••
966-
33333333333333332222222222•••••
967-
33333333333333332222222222•••••
968-
33333333333333332222222222•••••
959+
3333333333333333•2222222222•0••
960+
3333333333333333•2222222222••••
961+
3333333333333333•2222222222•1••
962+
3333333333333333•2222222222••••
963+
3333333333333333•2222222222••••
964+
3333333333333333•2222222222••••
965+
3333333333333333•2222222222••••
966+
3333333333333333•2222222222••••
967+
3333333333333333•2222222222••••
968+
3333333333333333•2222222222••••
969969
•3333333333333333•••••••••••••••
970970
•3333333333333333•••••••••••••••
971971
•3333333333333333•••••••••••••••

0 commit comments

Comments
 (0)