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(ui): align affine visuals with picking and mask bounds
yhh07cdd2dae161
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 60ba57dcd..4302032bc 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -18,6 +18,8 @@ published separately; it ships inside the editor.- **Advertising requests preserve a single active break.** Rewarded and interstitial requests reject immediately while another ad is showing, before creating a competing unit. The active break retains its showing flag, clock pause and audio suspension until it closes; errors release the guard so a later request can proceed. Rejected requests are not queued for playback.+- **UI geometry, picking and scissors retain parent-induced shear.** Solid, image, nine-slice, tiled and filled visuals use the complete parent basis for vertices and camera bounds. UI, editor and world-sprite picking test the same local boxes, and scissor bounds project their actual corners. Mirrored radial fills retain their wedges and UVs; axis-aligned positive UI keeps its existing geometry path.+- **Extreme sprite tile counts reach the bounded fallback on native hosts.** Tile budgets are checked in floating point before converting loop counts to integers, preventing overflowing axes from bypassing the existing 16,384-quad cap. Tiny positive steps retain the single stretched quad; non-finite tile steps and sizes emit no geometry, and grids at the cap remain tiled.- **Sprites retain parent-induced shear in every draw mode.** Ordinary, nine-slice and tiled geometry follows the complete parent transform, and camera bounds use the same basis. Mirrored tiled grids retain positive tile steps before applying signed axes, including the capped fallback. Zero-area sprites skip geometry; existing material, UV and batch state is preserved.diff --git a/src/esengine/renderer/frame/RenderFrameMask.cpp b/src/esengine/renderer/frame/RenderFrameMask.cppindex a0c1bcf1d..9118ba81c 100644--- a/src/esengine/renderer/frame/RenderFrameMask.cpp+++ b/src/esengine/renderer/frame/RenderFrameMask.cpp@@ -29,9 +29,9 @@ ScreenRect intersectRects(const ScreenRect& a, const ScreenRect& b) {return {x1, y1, x2 - x1, y2 - y1};}-glm::vec2 worldToScreen(f32 wx, f32 wy, const glm::mat4& vp,+glm::vec2 worldToScreen(const glm::vec3& world, const glm::mat4& vp,i32 vpX, i32 vpY, i32 vpW, i32 vpH) {- glm::vec4 clip = vp * glm::vec4(wx, wy, 0.0f, 1.0f);+ glm::vec4 clip = vp * glm::vec4(world, 1.0f);f32 ndcX = clip.x / clip.w;f32 ndcY = clip.y / clip.w;f32 sx = static_cast<f32>(vpX) + (ndcX * 0.5f + 0.5f) * static_cast<f32>(vpW);@@ -53,36 +53,28 @@ ScreenRect computeMaskScreenRect(// other pass has read this frame would be clipped to where it used to be.transform.ensureDecomposed();- f32 worldW = node.computed_size_.x * transform.worldScale.x;- f32 worldH = node.computed_size_.y * transform.worldScale.y;- if (worldW == 0.0f || worldH == 0.0f) return {0, 0, 0, 0};- f32 cx = transform.worldPosition.x;- f32 cy = transform.worldPosition.y;- f32 px = 0.5f; // UINode box is pivot-centered- f32 py = 0.5f;-- f32 localLeft = -worldW * px;- f32 localRight = worldW * (1.0f - px);- f32 localBottom = -worldH * py;- f32 localTop = worldH * (1.0f - py);-- f32 angle = 2.0f * std::atan2(transform.worldRotation.z, transform.worldRotation.w);- f32 cosA = std::cos(angle);- f32 sinA = std::sin(angle);-- glm::vec2 corners[4] = {- {cx + localLeft * cosA - localBottom * sinA, cy + localLeft * sinA + localBottom * cosA},- {cx + localRight * cosA - localBottom * sinA, cy + localRight * sinA + localBottom * cosA},- {cx + localRight * cosA - localTop * sinA, cy + localRight * sinA + localTop * cosA},- {cx + localLeft * cosA - localTop * sinA, cy + localLeft * sinA + localTop * cosA},- };+ if (transform.worldScale.x == 0.0f || transform.worldScale.y == 0.0f) return {0, 0, 0, 0};+ glm::vec3 axisX, axisY;+ if (registry.has<ecs::Parent>(entity)) {+ axisX = glm::vec3(transform.cachedMatrix_[0]);+ axisY = glm::vec3(transform.cachedMatrix_[1]);+ } else {+ const auto turn = flatTurnZ(transform.worldRotation);+ axisX = glm::vec3(turn.x, turn.y, 0) * transform.worldScale.x;+ axisY = glm::vec3(-turn.y, turn.x, 0) * transform.worldScale.y;+ }+ const glm::vec3 hx = axisX * node.computed_size_.x * .5f;+ const glm::vec3 hy = axisY * node.computed_size_.y * .5f;+ const glm::vec3 center = transform.worldPosition;+ const glm::vec3 corners[] = {center - hx - hy, center + hx - hy,+ center + hx + hy, center - hx + hy};f32 minX = std::numeric_limits<f32>::max();f32 minY = std::numeric_limits<f32>::max();f32 maxX = std::numeric_limits<f32>::lowest();f32 maxY = std::numeric_limits<f32>::lowest();for (const auto& c : corners) {- glm::vec2 s = worldToScreen(c.x, c.y, vp, vpX, vpY, vpW, vpH);+ glm::vec2 s = worldToScreen(c, vp, vpX, vpY, vpW, vpH);minX = std::min(minX, s.x);minY = std::min(minY, s.y);maxX = std::max(maxX, s.x);diff --git a/src/esengine/renderer/plugins/BatchPlugin.cpp b/src/esengine/renderer/plugins/BatchPlugin.cppindex 9aef7d4ea..96e6be99b 100644--- a/src/esengine/renderer/plugins/BatchPlugin.cpp+++ b/src/esengine/renderer/plugins/BatchPlugin.cpp@@ -138,7 +138,9 @@ void BatchPlugin::emitRadialFill() {constexpr f32 TWO_PI = 6.2831853071795864f;sweep = std::clamp(sweep, 0.0f, TWO_PI);- f32 hx = size.x * 0.5f, hy = size.y * 0.5f;+ const glm::vec2 absSize = glm::abs(size);+ const glm::vec2 direction{size.x < 0 ? -1.0f : 1.0f, size.y < 0 ? -1.0f : 1.0f};+ f32 hx = absSize.x * 0.5f, hy = absSize.y * 0.5f;if (sweep <= 0.0001f || hx <= 0.0f || hy <= 0.0f) return;// Sample angles are the two endpoints plus any box corner the sweep crosses,@@ -179,9 +181,9 @@ void BatchPlugin::emitRadialFill(asa > 1e-6f ? hy / asa : 1e30f);glm::vec2 p{ t * ca, t * sa }; // box-local, centeredverts[i + 1] = {- rotatePoint(center, center.x + p.x, center.y + p.y, cosR, sinR),+ rotatePoint(center, center.x + p.x * direction.x, center.y + p.y * direction.y, cosR, sinR),pc,- uvOffset + glm::vec2(p.x / size.x + 0.5f, p.y / size.y + 0.5f) * uvScale,+ uvOffset + glm::vec2(p.x / absSize.x + 0.5f, p.y / absSize.y + 0.5f) * uvScale,};}diff --git a/src/esengine/renderer/plugins/UIElementPlugin.cpp b/src/esengine/renderer/plugins/UIElementPlugin.cppindex b1f725cdf..cc307016b 100644--- a/src/esengine/renderer/plugins/UIElementPlugin.cpp+++ b/src/esengine/renderer/plugins/UIElementPlugin.cpp@@ -6,6 +6,7 @@#include "../frame/RenderFrame.hpp"#include "../rhi/Texture.hpp"#include "../../ecs/components/Transform.hpp"+#include "../../ecs/components/Hierarchy.hpp"#include "../../ecs/components/UIVisual.hpp"#include "../../ecs/components/UINode.hpp"#include "../../ecs/components/UIMask.hpp"@@ -79,6 +80,11 @@ void UIElementPlugin::collect(RenderCollectContext& collect_ctx) {const auto& rotation = transform.worldRotation;const auto& scale = transform.worldScale;if (scale.x == 0.0f || scale.y == 0.0f) continue;+ const bool parented = registry.has<ecs::Parent>(entity);+ const glm::vec3 basisOrigin = position;+ const auto& matrix = transform.cachedMatrix_;+ const bool mapBasis = parented && (matrix[0].y != 0 || matrix[1].x != 0+ || matrix[0].z != 0 || matrix[1].z != 0 || matrix[0].x < 0 || matrix[1].y < 0);// UI bakes the pivot into the world position here, so the quad is emitted centered.f32 dx = (0.5f - pivotX) * w * scale.x;@@ -99,9 +105,14 @@ void UIElementPlugin::collect(RenderCollectContext& collect_ctx) {// `position` above already carries the turned offset, so only the extents do.glm::vec3 halfExtents = flatHalfExtents(flatTurnZ(rotation), glm::vec3(w * scale.x, h * scale.y, 0.0f) * 0.5f);+ if (parented) {+ halfExtents = glm::abs(glm::vec3(transform.cachedMatrix_[0])) * w * .5f+ + glm::abs(glm::vec3(transform.cachedMatrix_[1])) * h * .5f;+ }if (!collect_ctx.visible(position, halfExtents, false)) { ++collect_ctx.culled; continue; }f32 angle = 2.0f * std::atan2(rotation.z, rotation.w);+ if (mapBasis) angle = 0.0f;i32 layer = UI_BASE_LAYER + renderer.uiOrder;u32 textureId = ctx.white_texture_id;@@ -270,6 +281,7 @@ void UIElementPlugin::collect(RenderCollectContext& collect_ctx) {glm::vec4 color = renderer.color;color.a *= node->alpha_in_tree_;+ const u32 vertexStart = buffers.vertexBytesUsed(LayoutId::Batch);if (isRadialFill) {f32 sweep = std::clamp(renderer.fillAmount, 0.0f, 1.0f)* radialMaxSweep(renderer.fillMethod);@@ -287,6 +299,16 @@ void UIElementPlugin::collect(RenderCollectContext& collect_ctx) {position, finalSize, CENTERED_PIVOT,angle, uvOffset, uvScale, color, key);}+ if (mapBasis) {+ const glm::vec3 basisX = glm::vec3(transform.cachedMatrix_[0]) / scale.x;+ const glm::vec3 basisY = glm::vec3(transform.cachedMatrix_[1]) / scale.y;+ const u32 vertexEnd = buffers.vertexBytesUsed(LayoutId::Batch);+ auto* vertices = reinterpret_cast<BatchVertex*>(buffers.vertexData(LayoutId::Batch));+ for (u32 i = vertexStart / sizeof(BatchVertex); i < vertexEnd / sizeof(BatchVertex); ++i) {+ const auto delta = vertices[i].position - basisOrigin;+ vertices[i].position = basisOrigin + basisX * delta.x + basisY * delta.y;+ }+ }}}diff --git a/src/esengine/ui/UIHitTestSystem.hpp b/src/esengine/ui/UIHitTestSystem.hppindex 644191373..f3c0b9dc1 100644--- a/src/esengine/ui/UIHitTestSystem.hpp+++ b/src/esengine/ui/UIHitTestSystem.hpp@@ -118,6 +118,30 @@ inline bool rayHitsOBB(const PickRay& ray,return true;}+inline bool pointInTransformedBox(Registry& registry, Entity entity, Transform& transform,+ f32 px, f32 py, f32 width, f32 height,+ f32 pivotX, f32 pivotY) {+ transform.ensureDecomposed();+ if (!registry.has<Parent>(entity)) {+ return pointInOBB(px, py, transform.worldPosition.x, transform.worldPosition.y,+ width * transform.worldScale.x, height * transform.worldScale.y,+ pivotX, pivotY, transform.worldRotation.z, transform.worldRotation.w);+ }+ if (width == 0.0f || height == 0.0f) return false;+ const auto& matrix = transform.cachedMatrix_;+ const f64 determinant = static_cast<f64>(matrix[0].x) * matrix[1].y+ - static_cast<f64>(matrix[1].x) * matrix[0].y;+ if (determinant == 0.0 || !std::isfinite(determinant)) return false;+ const f64 dx = static_cast<f64>(px) - transform.worldPosition.x;+ const f64 dy = static_cast<f64>(py) - transform.worldPosition.y;+ const f64 localX = (dx * matrix[1].y - dy * matrix[1].x) / determinant;+ const f64 localY = (dy * matrix[0].x - dx * matrix[0].y) / determinant;+ const f32 x0 = -width * pivotX, x1 = width * (1.0f - pivotX);+ const f32 y0 = -height * pivotY, y1 = height * (1.0f - pivotY);+ return localX >= std::min(x0, x1) && localX <= std::max(x0, x1)+ && localY >= std::min(y0, y1) && localY <= std::max(y0, y1);+}+inline bool isClippedByMask(Registry& registry,Entity entity,@@ -136,13 +160,9 @@ inline bool isClippedByMask(if (t && node) {t->ensureDecomposed();// UINode mask box is pivot-centered.- if (!pointInOBB(- worldMouseX, worldMouseY,- t->worldPosition.x, t->worldPosition.y,- node->computed_size_.x * t->worldScale.x,- node->computed_size_.y * t->worldScale.y,- 0.5f, 0.5f,- t->worldRotation.z, t->worldRotation.w+ if (!pointInTransformedBox(+ registry, ancestor, *t, worldMouseX, worldMouseY,+ node->computed_size_.x, node->computed_size_.y, 0.5f, 0.5f)) {return true;}diff --git a/src/esengine/ui/UISystem.cpp b/src/esengine/ui/UISystem.cppindex a1d93da3b..c14d9cb19 100644--- a/src/esengine/ui/UISystem.cpp+++ b/src/esengine/ui/UISystem.cpp@@ -66,15 +66,9 @@ void UISystem::hitTestUpdate(Registry& registry, const PickRay& worldRay, constf32 baseH = node->computed_size_.y;f32 pivotX = 0.5f, pivotY = 0.5f;- f32 worldW = baseW * t.worldScale.x;- f32 worldH = baseH * t.worldScale.y;-- if (pointInOBB(- mouseWorldX, mouseWorldY,- t.worldPosition.x, t.worldPosition.y,- worldW, worldH,- pivotX, pivotY,- t.worldRotation.z, t.worldRotation.w+ if (pointInTransformedBox(+ registry, entity, t, mouseWorldX, mouseWorldY,+ baseW, baseH, pivotX, pivotY)) {if (isClippedByMask(registry, entity, mouseWorldX, mouseWorldY)) {continue;@@ -132,12 +126,9 @@ void UISystem::hitWorldContent(Registry& registry, const PickRay& ray,f32 px = 0.0f, py = 0.0f, hitT = 0.0f;if (!rayHitsPlaneZ(ray, t.worldPosition.z, px, py, hitT)) return;- if (!pointInOBB(- px, py,- t.worldPosition.x, t.worldPosition.y,- sprite.size.x * t.worldScale.x, sprite.size.y * t.worldScale.y,- sprite.pivot.x, sprite.pivot.y,- t.worldRotation.z, t.worldRotation.w+ if (!pointInTransformedBox(+ registry, entity, t, px, py, sprite.size.x, sprite.size.y,+ sprite.pivot.x, sprite.pivot.y)) return;consider(entity, hitT, static_cast<i32>(sprite.layer));@@ -199,13 +190,9 @@ u32 UISystem::pickAll(Registry& registry, f32 worldX, f32 worldY) {auto& t = registry.get<Transform>(entity);t.ensureDecomposed();- if (!pointInOBB(- worldX, worldY,- t.worldPosition.x, t.worldPosition.y,- node->computed_size_.x * t.worldScale.x,- node->computed_size_.y * t.worldScale.y,- 0.5f, 0.5f,- t.worldRotation.z, t.worldRotation.w+ if (!pointInTransformedBox(+ registry, entity, t, worldX, worldY,+ node->computed_size_.x, node->computed_size_.y, 0.5f, 0.5f)) continue;if (isClippedByMask(registry, entity, worldX, worldY)) continue;diff --git a/tests/renderer/MockGfxDevice.hpp b/tests/renderer/MockGfxDevice.hppindex 20b8e7d3c..53271727a 100644--- a/tests/renderer/MockGfxDevice.hpp+++ b/tests/renderer/MockGfxDevice.hpp@@ -8,12 +8,14 @@#include "esengine/renderer/rhi/GfxDevice.hpp"#include <cstring>+#include <array>#include <vector>namespace esengine {struct MockGfxDevice final : GfxDevice {std::vector<i32> stencilReferences;+ std::vector<std::array<i32, 4>> scissorRectangles;// Device-loss entry points a backend calls on itself. Protected on GfxDevice,// so a harness driving the state machine needs them republished here.using GfxDevice::markDeviceLost;@@ -130,7 +132,7 @@ struct MockGfxDevice final : GfxDevice {void clearStencil(i32) override {}void setScissorTest(bool) override {}- void setScissor(i32, i32, i32, i32) override {}+ void setScissor(i32 x, i32 y, i32 w, i32 h) override { scissorRectangles.push_back({x, y, w, h}); }/** Set false to make allocation fail, the way a GPU out of memory does — the* path a caller's "leaves it as it found it" promise is only true along. */diff --git a/tests/renderer/test_batch_builder.cpp b/tests/renderer/test_batch_builder.cppindex b0e4c049d..551bcf139 100644--- a/tests/renderer/test_batch_builder.cpp+++ b/tests/renderer/test_batch_builder.cpp@@ -25,6 +25,8 @@#include "esengine/ecs/components/UINode.hpp"#include "esengine/ecs/components/UIVisual.hpp"#include "esengine/ecs/components/UIMask.hpp"+#include "esengine/ecs/components/Interactable.hpp"+#include "esengine/ui/UISystem.hpp"#include "esengine/ecs/components/Hierarchy.hpp"#include <functional>@@ -51,6 +53,7 @@ struct Harness {struct NineSlicePlugin : UIElementPlugin {using BatchPlugin::emitNineSlice;+ using BatchPlugin::emitRadialFill;};BatchDrawKey quadKey(u32 textureId, i32 layer = 0) {@@ -368,6 +371,168 @@ TEST_CASE("sprites: affine parents preserve every draw mode and mirrored tile gr}}+TEST_CASE("UI visuals: affine parents preserve box-local geometry and fill edges") {+ for (auto type : {ecs::UIVisualType::SolidColor, ecs::UIVisualType::Image,+ ecs::UIVisualType::NineSlice, ecs::UIVisualType::Tiled, ecs::UIVisualType::Filled}) {+ for (bool mirror : {false, true}) for (bool radial : {false, true}) {+ if (radial && type != ecs::UIVisualType::Filled) continue;+ Harness h;+ RenderContext context(h.device);+ resource::ResourceManager resources;+ resources.init(h.device);+ const u8 pixels[16 * 16 * 4] = {};+ const auto texture = resources.createTexture(resource::ResourceContent::Retained,+ 16, 16, pixels, TextureFormat::RGBA8);+ ecs::Registry registry;+ const auto parent = registry.create(), entity = registry.create();+ registry.emplace<ecs::Parent>(entity).entity = parent;+ auto& transform = registry.emplace<ecs::Transform>(entity);+ transform.cachedMatrix_ = glm::scale(glm::mat4(1), glm::vec3(2, 1, 1))+ * glm::translate(glm::mat4(1), glm::vec3(4, -7, 0))+ * glm::mat4_cast(glm::angleAxis(.7f, glm::vec3(0, 0, 1)))+ * glm::scale(glm::mat4(1), glm::vec3(mirror ? -3 : 3, 2, 1));+ transform.decomposed_ = false;+ registry.emplace<ecs::UINode>(entity).computed_size_ = {20, 30};+ auto& visual = registry.emplace<ecs::UIVisual>(entity);+ visual.texture = texture;+ visual.visualType = type;+ visual.sliceBorder = {2, 2, 2, 2};+ visual.fillAmount = .5f;+ visual.fillMethod = radial ? ecs::UIFillMethod::Radial360 : ecs::UIFillMethod::Horizontal;+ visual.fillOrigin = radial ? ecs::UIFillOrigin::Top : ecs::UIFillOrigin::Left;+ Frustum frustum;+ frustum.extractFromMatrix(glm::ortho(-500.0f, 500.0f, -500.0f, 500.0f));+ RenderFrameContext frameContext{context, resources};+ RenderCollectContext collect{registry, frustum, h.clips, h.pool, h.list, frameContext, {}};+ UIElementPlugin plugin;+ plugin.init(frameContext);+ plugin.collect(collect);+ const u32 count = h.pool.vertexBytesUsed(LayoutId::Batch) / sizeof(BatchVertex);+ CHECK(count > 0);+ const auto* vertices = reinterpret_cast<const BatchVertex*>(h.pool.vertexData(LayoutId::Batch));+ const auto inverse = glm::inverse(transform.cachedMatrix_);+ for (u32 i = 0; i < count; ++i) {+ const auto local = glm::vec3(inverse * glm::vec4(vertices[i].position, 1));+ CHECK(local.x >= -10.001f);+ CHECK(local.x <= 10.001f);+ CHECK(local.y >= -15.001f);+ CHECK(local.y <= 15.001f);+ if (type == ecs::UIVisualType::Filled) {+ if (radial) CHECK(local.x >= -.001f);+ else CHECK(local.x <= .001f);+ }+ }+ const auto corner = glm::vec3(transform.cachedMatrix_ * glm::vec4(-10, 15, 0, 1));+ frustum.extractFromMatrix(glm::ortho(corner.x-.1f, corner.x+.1f, corner.y-.1f, corner.y+.1f));+ h.pool.beginFrame();+ h.list.clear();+ plugin.collect(collect);+ CHECK(h.pool.vertexBytesUsed(LayoutId::Batch) > 0);+ resources.shutdown();+ }+ }+}++TEST_CASE("radial fills: signed boxes mirror positions while retaining sampled UVs") {+ for (f32 x : {1.0f, -1.0f}) for (f32 y : {1.0f, -1.0f}) {+ Harness original, reflected;+ NineSlicePlugin plugin;+ const glm::vec3 center{13, 17, 0};+ plugin.emitRadialFill(original.pool, original.list, original.clips,+ center, {20, 30}, 0, 1.5707963f, 3.1415927f,+ {.2f, .3f}, {.4f, .5f}, {1, 1, 1, 1}, quadKey(1));+ plugin.emitRadialFill(reflected.pool, reflected.list, reflected.clips,+ center, {20*x, 30*y}, 0, 1.5707963f, 3.1415927f,+ {.2f, .3f}, {.4f, .5f}, {1, 1, 1, 1}, quadKey(1));+ REQUIRE(original.pool.vertexBytesUsed(LayoutId::Batch) > 0);+ REQUIRE(reflected.pool.vertexBytesUsed(LayoutId::Batch) == original.pool.vertexBytesUsed(LayoutId::Batch));+ const auto* a = reinterpret_cast<const BatchVertex*>(original.pool.vertexData(LayoutId::Batch));+ const auto* b = reinterpret_cast<const BatchVertex*>(reflected.pool.vertexData(LayoutId::Batch));+ for (u32 i = 0; i < original.pool.vertexBytesUsed(LayoutId::Batch) / sizeof(BatchVertex); ++i) {+ CHECK(b[i].position.x == doctest::Approx(center.x + (a[i].position.x-center.x)*x));+ CHECK(b[i].position.y == doctest::Approx(center.y + (a[i].position.y-center.y)*y));+ CHECK(b[i].texCoord == a[i].texCoord);+ }+ }+}++TEST_CASE("UI and sprite picking: parent shear follows authored local bounds") {+ for (bool uiNode : {false, true}) for (bool mirror : {false, true}) {+ ecs::Registry registry;+ const auto parent = registry.create(), entity = registry.create();+ registry.emplace<ecs::Canvas>(parent);+ registry.emplace<ecs::Transform>(parent);+ registry.emplace<ecs::UINode>(parent).computed_size_ = {200, 200};+ registry.emplace<ecs::Children>(parent).entities.push_back(entity);+ registry.emplace<ecs::Parent>(entity).entity = parent;+ auto& transform = registry.emplace<ecs::Transform>(entity);+ transform.cachedMatrix_ = glm::scale(glm::mat4(1), glm::vec3(2, 1, 1))+ * glm::translate(glm::mat4(1), glm::vec3(4, -7, 0))+ * glm::mat4_cast(glm::angleAxis(.7f, glm::vec3(0, 0, 1)))+ * glm::scale(glm::mat4(1), glm::vec3(mirror ? -3 : 3, 2, 1));+ transform.decomposed_ = false;+ registry.emplace<ecs::Interactable>(entity);+ if (uiNode) registry.emplace<ecs::UINode>(entity).computed_size_ = {20, 30};+ else registry.emplace<ecs::Sprite>(entity).size = {20, 30};+ ecs::UISystem ui;+ ui.tree.rebuild(registry);+ for (const glm::vec2 local : {glm::vec2(9, 14), {-9, -14}, {11, 0}, {0, 16}}) {+ const auto point = glm::vec3(transform.cachedMatrix_ * glm::vec4(local, 0, 1));+ const bool inside = std::abs(local.x) < 10 && std::abs(local.y) < 15;+ ui.hitTestUpdate(registry, ecs::PickRay{{point.x, point.y, 100}, {0, 0, -1}}, nullptr);+ CHECK((ui.hitResult.hit_entity == entity) == inside);+ if (uiNode) CHECK((ui.pick(registry, point.x, point.y) == entity.id()) == inside);+ }+ const auto child = registry.create();+ registry.emplace<ecs::Parent>(child).entity = entity;+ if (!uiNode) registry.emplace<ecs::UINode>(entity).computed_size_ = {20, 30};+ registry.emplace<ecs::UIMask>(entity);+ for (const glm::vec2 local : {glm::vec2(9, 14), {-9, -14}, {11, 0}, {0, 16}}) {+ const auto point = glm::vec3(transform.cachedMatrix_ * glm::vec4(local, 0, 1));+ CHECK(ecs::isClippedByMask(registry, child, point.x, point.y)+ == (std::abs(local.x) > 10 || std::abs(local.y) > 15));+ }+ }+}++TEST_CASE("UI scissor: affine corners determine the projected clip rectangle") {+ MockGfxDevice device;+ RenderContext context(device);+ resource::ResourceManager resources;+ ecs::Registry registry;+ RenderFrame frame(device, context, resources);+ frame.init(200, 200);+ const auto parent = registry.create(), mask = registry.create(), child = registry.create();+ registry.emplace<ecs::Parent>(mask).entity = parent;+ registry.emplace<ecs::Children>(mask).entities.push_back(child);+ registry.emplace<ecs::Parent>(child).entity = mask;+ auto& transform = registry.emplace<ecs::Transform>(mask);+ transform.cachedMatrix_ = glm::scale(glm::mat4(1), glm::vec3(2, 1, 1))+ * glm::mat4_cast(glm::angleAxis(.7f, glm::vec3(0, 0, 1)));+ transform.decomposed_ = false;+ registry.emplace<ecs::UINode>(mask).computed_size_ = {20, 30};+ registry.emplace<ecs::UIMask>(mask).mode = ecs::MaskMode::Scissor;+ const auto half = glm::abs(glm::vec3(transform.cachedMatrix_[0])) * 10.0f+ + glm::abs(glm::vec3(transform.cachedMatrix_[1])) * 15.0f;+ const std::array<i32, 4> expected{static_cast<i32>(std::round(100-half.x)),+ static_cast<i32>(std::round(100-half.y)),+ static_cast<i32>(std::round(2*half.x)),+ static_cast<i32>(std::round(2*half.y))};+ const f32 vertices[36] = {};+ const u16 indices[] = {0, 1, 2, 2, 3, 0};+ const glm::mat4 identity(1);+ frame.beginFrame();+ frame.begin(glm::ortho(-100.0f, 100.0f, -100.0f, 100.0f));+ frame.processMasks(registry, 0, 0, 200, 200);+ frame.collectAll(registry);+ frame.submitTextBatch(vertices, 4, indices, 6, 1, &identity[0][0], child, 0, 0, false);+ frame.flush();+ frame.end();+ CHECK(std::find(device.scissorRectangles.begin(), device.scissorRectangles.end(), expected)+ != device.scissorRectangles.end());+ frame.endFrame();+}+TEST_CASE("sprites: tile budget applies before integer conversion") {struct Case { glm::vec2 tile, spacing; u32 quads; };const Case cases[] = {diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex 49ea9ca9e..fdf01b1d6 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -30,6 +30,9 @@ export const NOTES_FLOOR = 'v0.65.0';export const NOTED = {'fix(ads): reject overlapping advertising requests':{ note: 'Advertising requests preserve a single active break.' },++ 'fix(ui): align affine visuals with picking and mask bounds':+ { note: 'UI geometry, picking and scissors retain parent-induced shear.' },'fix(sprite): enforce tile budgets before integer conversion':{ note: 'Extreme sprite tile counts reach the bounded fallback on native hosts.' },'fix(sprite): preserve affine geometry and mirrored tile grids':