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(pick): a shape is selected by its drawn size and layer, so a click inside it lands
yhh159f06e47f0d
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 934caa25d..1934ca3f3 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -38,6 +38,7 @@ published separately; it ships inside the editor.### Fixed+- **A click selects a shape by its drawn size, and a bare Canvas no longer takes the click.** A ShapeRenderer could be selected only on the small icon at its origin, and any scene with a Canvas answered every click in the design screen with the Canvas, so the sprites beneath could not be clicked at all. A shape is picked by its size and its own sorting layer, and a UI node that draws nothing is picked only where nothing else is.- **An unset texture array reads its default on WebGL.** A `textureArray` param a material left unset was given the plain white texture, which an array sampler cannot read, so on WebGL it read black (WebGPU already drew white). An unset array param now binds layers of its declared default: white, black or a flat normal.- **Clearing an asset field from automation clears it.** `set_field` on an asset slot stored whatever it was given as text: 0 became the path "0" and null the path "null". The scene kept it, the editor drew nothing there, and an export failed to find an asset called 0. Nothing, however it is said (null, 0, false, the empty string, or "null" and "0" from a transport that sends values as text), now stores what the inspector's clear button stores: 0 in a handle-valued slot and the empty string in a Spine skeleton or atlas, which are string fields. Both ask one function for it (`emptyAssetValue`). Any other number is refused, since it names nothing a caller could have meant. `model_write`'s text also says what its report holds, to read `triangles` every time, and that `material.texture` may name a recipe.- **A model's picture can be a recipe.** A model source's `material.texture` took a `.png`, `.jpg` or `.webp` and refused an `.esimage`, the recipe `image_write` answers as the picture's `ref`: a tree's branches named the pixels while the foliage material beside them named the layers, and a game shipped whichever was referenced. A recipe is now accepted there. Whether a path names a recipe is asked in one place, `sdk/src/asset/textureRecipePath.ts`, which reads nothing of the runtime: the registry that draws recipes, the packager deciding what ships and the model source's check each spelled the extension themselves.diff --git a/sdk/src/ecs/entityBox.ts b/sdk/src/ecs/entityBox.tsindex 89b0cc692..c9680219a 100644--- a/sdk/src/ecs/entityBox.ts+++ b/sdk/src/ecs/entityBox.ts@@ -11,7 +11,7 @@*/import type { Entity, Quat, Vec3 } from '../types';import type { World } from './world';-import { Transform, Sprite, MeshRenderer } from './component';+import { Transform, Sprite, MeshRenderer, ShapeRenderer } from './component';import { UINode } from '../ui/core/ui-node';import { q } from '../math/quat';import { worldEngineApi } from './bridge/engineApi';@@ -95,6 +95,11 @@ export function entityWorldBox(world: ReadableWorld, entity: Entity, opts?: Entid = 0;px = sp.pivot?.x ?? 0.5;py = sp.pivot?.y ?? 0.5;+ } else if (world.has(entity, ShapeRenderer)) {+ const shape = world.get(entity, ShapeRenderer);+ w = Math.max(shape.size.x * t.worldScale.x, iconHalf * 2);+ h = Math.max(shape.size.y * t.worldScale.y, iconHalf * 2);+ d = 0;} else if (iconHalf === 0) {return null;}diff --git a/sdk/src/ecs/entityPick.ts b/sdk/src/ecs/entityPick.tsindex 9bcc7f75d..9b762663d 100644--- a/sdk/src/ecs/entityPick.ts+++ b/sdk/src/ecs/entityPick.ts@@ -11,7 +11,7 @@import type { Entity, Vec3 } from '../types';import type { World } from './world';import type { WorldRay } from '../ui/util/math';-import { Transform, Sprite, SortingGroup, Parent } from './component';+import { Transform, Sprite, ShapeRenderer, SortingGroup, Parent } from './component';import {layerOrderOf, rankPickCandidates, sortingIdentity, type PickCandidate,} from '../render/layerOrder';@@ -94,13 +94,14 @@ export function pickEntitiesByRay(const box = meshWorldBox(world, entity) ?? entityWorldBox(world, entity, { iconHalf });if (!box || entityBoxRayHit(box, ray.origin, ray.dir) === null) continue;- const sprite = world.has(entity, Sprite) ? world.get(entity, Sprite) : null;+ const sprite = world.has(entity, Sprite) ? world.get(entity, Sprite)+ : world.has(entity, ShapeRenderer) ? world.get(entity, ShapeRenderer) : null;// A group owns the layer as well as the order, so the layer's RULE is asked of// the group's — the same resolution pushBatchDraw does, for the same reason.const identity = sortingIdentity(enclosingGroups(world, entity),sprite ? sprite.layer : unlayered,- sprite?.order ?? 0,+ (sprite as { order?: number } | null)?.order ?? 0,);const t = world.get(entity, Transform);hits.push({diff --git a/sdk/tests/entity-box.test.ts b/sdk/tests/entity-box.test.tsindex c47603001..324035b75 100644--- a/sdk/tests/entity-box.test.ts+++ b/sdk/tests/entity-box.test.ts@@ -9,7 +9,7 @@*/import { describe, expect, it } from 'vitest';import { entityWorldBox, entityBoxCorners, entityBoxRayHit, uiNodeWorldBox, meshWorldBox } from '../src/ecs/entityBox';-import { Transform, Sprite, MeshRenderer } from '../src/ecs/component';+import { Transform, Sprite, MeshRenderer, ShapeRenderer } from '../src/ecs/component';import { UINode } from '../src/ui/core/ui-node';import type { Entity } from '../src/types';@@ -228,3 +228,17 @@ describe('a ray against an entity box', () => {expect(entityBoxRayHit(box, { x: 500, y: 0, z: 0 }, { x: -1, y: 0, z: 0 })).toBeCloseTo(450, 6);});});++describe('a shape\'s box', () => {+ it('is its size, scaled by the world scale and centred on the entity', () => {+ const world = fakeWorld({ 1: { Transform: T(10, 20, 2, 1), ShapeRenderer: { size: { x: 80, y: 40 } } } });+ const box = entityWorldBox(world, ent(1));+ expect(box).toMatchObject({ cx: 10, cy: 20, hw: 80, hh: 20, hd: 0 });+ });++ it('is never smaller than the icon a click would have hit anyway', () => {+ const world = fakeWorld({ 1: { Transform: T(0, 0), ShapeRenderer: { size: { x: 2, y: 2 } } } });+ const box = entityWorldBox(world, ent(1), { iconHalf: 11 });+ expect(box).toMatchObject({ hw: 11, hh: 11 });+ });+});