A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
fix(renderer): mirror nine-slice cells and texture borders
yhh456339171c3c
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 79e4fbdc1..61e8660e6 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -20,6 +20,8 @@ published separately; it ships inside the editor.### Fixed+- **Nine-slice texture flips preserve asymmetric borders.** Flipped UV spans sample inside their original region and exchange opposing border widths, producing the complete mirrored texture. The shared geometry builder retains all cells for signed destination extents, including small boxes and rotated draws.+- **Small nine-slice visuals keep borders inside their box.** Sprite and UI nine-slice geometry proportionally shrinks opposing borders when their total exceeds the destination size, retaining the texture's original border UVs. Zero-width or zero-height nine-slices emit no geometry; ordinary sizes retain their existing border widths.- **Fully transparent UI visuals skip geometry uploads.** Default-material solid, image, nine-slice, tiled and filled visuals stop generating vertices and indices when their own or inherited alpha is zero, and resume when visible. Stencil mask geometry and custom-material draws remain available for clipping and shader-defined output.diff --git a/src/esengine/renderer/plugins/BatchPlugin.cpp b/src/esengine/renderer/plugins/BatchPlugin.cppindex 5f05180f5..9aef7d4ea 100644--- a/src/esengine/renderer/plugins/BatchPlugin.cpp+++ b/src/esengine/renderer/plugins/BatchPlugin.cpp@@ -69,11 +69,15 @@ void BatchPlugin::emitNineSlice(f32 T = border.z;f32 B = border.w;if (size.x == 0.0f || size.y == 0.0f) return;+ if (uvScale.x < 0.0f) std::swap(L, R);+ if (uvScale.y < 0.0f) std::swap(T, B);// Fit destination borders proportionally when the box is smaller than// their sum. Source UV borders still sample the original texture region.- const f32 sx = size.x >= 0.0f && L + R > 0.0f ? std::min(1.0f, size.x / (L + R)) : 1.0f;- const f32 sy = size.y >= 0.0f && T + B > 0.0f ? std::min(1.0f, size.y / (T + B)) : 1.0f;+ const f32 directionX = std::copysign(1.0f, size.x);+ const f32 directionY = std::copysign(1.0f, size.y);+ const f32 sx = directionX * (L + R > 0.0f ? std::min(1.0f, std::abs(size.x) / (L + R)) : 1.0f);+ const f32 sy = directionY * (T + B > 0.0f ? std::min(1.0f, std::abs(size.y) / (T + B)) : 1.0f);f32 baseX = position.x - size.x * pivotNorm.x;f32 baseY = position.y - size.y * pivotNorm.y;@@ -83,13 +87,15 @@ void BatchPlugin::emitNineSlice(f32 u[4], v[4];if (texSize.x > 0.0f && texSize.y > 0.0f) {+ const f32 uvDirectionX = std::copysign(1.0f, uvScale.x);+ const f32 uvDirectionY = std::copysign(1.0f, uvScale.y);u[0] = uvOffset.x;- u[1] = uvOffset.x + L / texSize.x;- u[2] = uvOffset.x + uvScale.x - R / texSize.x;+ u[1] = uvOffset.x + uvDirectionX * L / texSize.x;+ u[2] = uvOffset.x + uvScale.x - uvDirectionX * R / texSize.x;u[3] = uvOffset.x + uvScale.x;v[0] = uvOffset.y;- v[1] = uvOffset.y + B / texSize.y;- v[2] = uvOffset.y + uvScale.y - T / texSize.y;+ v[1] = uvOffset.y + uvDirectionY * B / texSize.y;+ v[2] = uvOffset.y + uvScale.y - uvDirectionY * T / texSize.y;v[3] = uvOffset.y + uvScale.y;} else {u[0] = uvOffset.x;@@ -110,7 +116,7 @@ void BatchPlugin::emitNineSlice(for (i32 col = 0; col < 3; ++col) {f32 pw = x[col + 1] - x[col];f32 ph = y[row + 1] - y[row];- if (pw <= 0.0f || ph <= 0.0f) continue;+ if (pw * directionX <= 0.0f || ph * directionY <= 0.0f) continue;BatchVertex verts[4];verts[0] = { rotatePoint(position, x[col], y[row], cosA, sinA), pc, {u[col], v[row]} };diff --git a/tests/renderer/test_batch_builder.cpp b/tests/renderer/test_batch_builder.cppindex 0f455839f..470246541 100644--- a/tests/renderer/test_batch_builder.cpp+++ b/tests/renderer/test_batch_builder.cpp@@ -320,6 +320,47 @@ TEST_CASE("nine-slice: small boxes contain their borders and preserve source UVs}}+TEST_CASE("nine-slice: signed transforms and UV flips preserve every cell") {+ NineSlicePlugin plugin;+ const glm::vec3 position{13, 17, 0};+ const glm::vec2 pivot{.25f, .75f}, uvOffset{.2f, .1f}, uvScale{.6f, .8f};+ for (const glm::vec2 size : {glm::vec2{40, 30}, {10, 6}}) {+ Harness reference;+ plugin.emitNineSlice(reference.pool, reference.list, reference.clips, position, size, pivot,+ 0, {100, 100}, {8, 12, 10, 6}, uvOffset, uvScale, {1, 1, 1, 1}, quadKey(1));+ const u32 bytes = reference.pool.vertexBytesUsed(LayoutId::Batch);+ const auto* original = reinterpret_cast<const BatchVertex*>(reference.pool.vertexData(LayoutId::Batch));+ for (f32 signX : {1.0f, -1.0f}) for (f32 signY : {1.0f, -1.0f}) {+ for (f32 flipX : {1.0f, -1.0f}) for (f32 flipY : {1.0f, -1.0f}) {+ for (f32 angle : {0.0f, .4f}) {+ Harness h;+ const glm::vec2 offset = uvOffset + glm::vec2(flipX < 0 ? uvScale.x : 0, flipY < 0 ? uvScale.y : 0);+ plugin.emitNineSlice(h.pool, h.list, h.clips, position, size * glm::vec2(signX, signY), pivot,+ angle, {100, 100}, {8, 12, 10, 6}, offset, uvScale * glm::vec2(flipX, flipY),+ {1, 1, 1, 1}, quadKey(1));+ REQUIRE(h.pool.vertexBytesUsed(LayoutId::Batch) == bytes);+ CHECK(h.pool.indicesUsed(LayoutId::Batch) == reference.pool.indicesUsed(LayoutId::Batch));+ const auto* vertices = reinterpret_cast<const BatchVertex*>(h.pool.vertexData(LayoutId::Batch));+ for (u32 i = 0; i < bytes / sizeof(BatchVertex); ++i) {+ glm::vec2 local = glm::vec2(original[i].position) - glm::vec2(position);+ if (flipX < 0) local.x = size.x * (1 - 2 * pivot.x) - local.x;+ if (flipY < 0) local.y = size.y * (1 - 2 * pivot.y) - local.y;+ local *= glm::vec2(signX, signY);+ const glm::vec2 expected{position.x + local.x * std::cos(angle) - local.y * std::sin(angle),+ position.y + local.x * std::sin(angle) + local.y * std::cos(angle)};+ bool found = false;+ for (u32 j = 0; j < bytes / sizeof(BatchVertex); ++j) {+ found |= glm::length(glm::vec2(vertices[j].position) - expected) < .0001f+ && glm::length(vertices[j].texCoord - original[i].texCoord) < .0001f;+ }+ CHECK(found);+ }+ }+ }+ }+ }+}+TEST_CASE("UI visuals: zero alpha skips geometry and a restored fade draws again") {for (auto mode : {ecs::UIVisualType::SolidColor, ecs::UIVisualType::Image,ecs::UIVisualType::NineSlice, ecs::UIVisualType::Tiled,diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex d01ff6f9d..83159b2f7 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -28,6 +28,8 @@ export const NOTES_FLOOR = 'v0.65.0';* the reader recognises anyway.*/export const NOTED = {+ 'fix(renderer): mirror nine-slice cells and texture borders':+ { note: 'Nine-slice texture flips preserve asymmetric borders.' },'fix(renderer): fit nine-slice borders inside small boxes':{ note: 'Small nine-slice visuals keep borders inside their box.' },'fix(docs): escape playable size limits in MDX':