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
feat(editor): unified collider gizmo — all six shapes, editable vertices
yhh2bd0cd3d0450
diff --git a/desktop/src/engine/SceneCommands.ts b/desktop/src/engine/SceneCommands.tsindex f15010a12..e6b053196 100644--- a/desktop/src/engine/SceneCommands.ts+++ b/desktop/src/engine/SceneCommands.ts@@ -77,7 +77,9 @@ export function toModelValue(cur: Record<string, unknown>,type: InspectorFieldType,key: string,- value: InspectorFieldValue,+ // `vec2list` carries a Vec2[] — outside the Inspector's scalar vocabulary, so the write+ // channel accepts it here without widening the Inspector's InspectorFieldValue.+ value: InspectorFieldValue | Array<{ x: number; y: number }>,): unknown {switch (type) {case 'number':@@ -96,6 +98,10 @@ export function toModelValue(const [x, y, z] = value as [number, number, number];return { ...(cur[key] as object), x, y, z };}+ case 'vec2list':+ // A whole Vec2[] replacement (polygon vertices / chain points) — normalized to+ // plain {x,y} so a dragged vertex writes clean data; coalesced to one undo step.+ return (value as Array<{ x: number; y: number }>).map((p) => ({ x: p.x, y: p.y }));case 'angle':return angleZToQuat(Number(value));case 'color':@@ -292,13 +298,22 @@ export class SceneCommandsImpl {if (bakeAbsolute) applySeed(); // coalesced into the caller's gesture}+ /**+ * Write a whole Vec2[] field (polygon vertices / chain points) — the viewport vertex-+ * drag door. Same model + undo/gesture bookkeeping as {@link setField}, but the value+ * is a Vec2[] (outside the Inspector's scalar-field vocabulary, so it has its own door).+ */+ setVertexArray(sourceId: EntityId, compName: string, key: string, verts: Array<{ x: number; y: number }>): void {+ this.writeField_(sourceId, compName, key, 'vec2list', verts);+ }+/** The unconditional single-field write (model + undo/gesture bookkeeping). */private writeField_(sourceId: EntityId,compName: string,key: string,type: InspectorFieldType,- value: InspectorFieldValue,+ value: InspectorFieldValue | Array<{ x: number; y: number }>,): void {const e = this.model.entityBySource(sourceId);if (!e) return;diff --git a/desktop/src/engine/ViewportController.ts b/desktop/src/engine/ViewportController.tsindex 4913f7d38..0ab2c161c 100644--- a/desktop/src/engine/ViewportController.ts+++ b/desktop/src/engine/ViewportController.ts@@ -2,10 +2,12 @@// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Teamimport {Camera, CameraView, EditorView, Light2D, Sprite, Transform, Canvas, BoxCollider, CircleCollider,+ CapsuleCollider, SegmentCollider, PolygonCollider, ChainCollider,ParticleEmitter, OneWayPlatform,RevoluteJoint, DistanceJoint, PrismaticJoint, WeldJoint, WheelJoint, MotorJoint,UINode, UICameraInfo, screenToUiWorld, uiWorldToScreen, uiPickAllWorld, type UICameraData,TilemapLayer, TilemapAPI, decodeTilemapChunks, tileCollisionOutlines,+ readColliderShapes, colliderShapeOutline, shapeCenter,type TilesetModel, type TileCollisionPiece,} from 'esengine';import type { EntityId } from '@/types';@@ -101,6 +103,31 @@ export interface EditorScreenInfo {backgroundColor: { r: number; g: number; b: number; a: number };}+/** A draggable collider point handle (CSS px) + the field it writes. `index` null = a+ * Vec2 field (box/circle/capsule offset, segment endpoint); ≥ 0 = one element of a+ * Vec2[] (polygon vertex, chain point). One drag channel edits every collider point. */+export interface ColliderPointHandle {+ x: number;+ y: number;+ comp: string;+ key: string;+ index: number | null;+}++/** Screen-space gizmo for EVERY collider on an entity: the merged outline as SVG path+ * data (solid + dashed-sensor, CSS px), the one-way arrow, the box-size / circle-radius+ * scalar handles, and every draggable point (vertices / endpoints / offsets). All six+ * shapes project through the shared `colliderShapeOutline` seam — the same geometry+ * PhysicsDebugDraw and the tile-collision overlay use. */+export interface ColliderGizmo {+ outline: string;+ outlineSensor: string;+ oneWay: { cx: number; cy: number; dx: number; dy: number } | null;+ sizeHandle: { x: number; y: number } | null;+ radiusHandle: { x: number; y: number } | null;+ points: ColliderPointHandle[];+}+// Picking and screen<->world conversions for the viewport, all routed through// the engine's own camera matrices (no projection assumptions).export const ViewportController = {@@ -512,13 +539,18 @@ export const ViewportController = {return { cx: center.x, cy: center.y, kind: l.type, color, radiusPx, sdx, sdy, coneHalf, on, handle: handle ?? null };},- /** Ids of entities carrying a box/circle collider — the collider-gizmo set. */+ /** Ids of entities carrying ANY collider (box/circle/capsule/segment/polygon/chain) —+ * the collider-gizmo set. All six render through the shared shape-outline projection. */colliderIds(): EntityId[] {const world = EngineHost.world;if (!world) return [];const out: EntityId[] = [];for (const e of world.getAllEntities()) {- if (world.has(e, Transform) && (world.has(e, BoxCollider) || world.has(e, CircleCollider))) out.push(e);+ if (!world.has(e, Transform)) continue;+ if (world.has(e, BoxCollider) || world.has(e, CircleCollider) || world.has(e, CapsuleCollider)+ || world.has(e, SegmentCollider) || world.has(e, PolygonCollider) || world.has(e, ChainCollider)) {+ out.push(e);+ }}return out;},@@ -636,62 +668,123 @@ export const ViewportController = {},/**- * Screen-space collider outline for the gizmo: a 4-corner polygon (box) or a- * center + radius (circle), in CSS px. The collider lives at the entity's world- * transform + its (meter) offset, scaled to pixels by pixelsPerUnit. `cx/cy` is- * the shape's screen center for both kinds. `oneWay` is the OneWayPlatform solid-- * side normal as a screen unit vector (world-space — contact normals don't rotate- * with the entity), or null when the entity has none / it's disabled.+ * Screen-space gizmo for EVERY collider on `id`, projected through the shared+ * `readColliderShapes` + `colliderShapeOutline` seam so all six shapes (box / circle /+ * capsule / segment / polygon / chain) render one way — identical geometry to+ * PhysicsDebugDraw and the tile-collision overlay. Merged outline path data (solid ++ * dashed-sensor), the one-way arrow, box-size / circle-radius scalar handles, and the+ * draggable point handles (vertices / endpoints / offsets). `ppuHint` avoids re-scanning+ * for the Canvas once per collider. Null when the entity has no collider / no transform.*/- getColliderGizmo(- id: EntityId,- ppuHint?: number,- ): { kind: 'box'; cx: number; cy: number; r: number; pts: Array<{ x: number; y: number }>; handle: { x: number; y: number } | null; sizeHandle: { x: number; y: number } | null; oneWay: { dx: number; dy: number } | null } | { kind: 'circle'; cx: number; cy: number; r: number; pts: Array<{ x: number; y: number }>; handle: { x: number; y: number } | null; sizeHandle: { x: number; y: number } | null; oneWay: { dx: number; dy: number } | null } | null {+ getColliderGizmo(id: EntityId, ppuHint?: number): ColliderGizmo | null {const world = EngineHost.world;if (!world || !world.valid(id) || !world.has(id, Transform)) return null;const t = world.get(id, Transform);- // pixelsPerUnit is a scene-wide constant; callers looping many colliders pass- // it in to avoid re-scanning all entities for the Canvas once per collider.const ppu = ppuHint ?? this.colliderPixelsPerUnit();const rot = quatAngleZ(t.worldRotation as { w: number; x: number; y: number; z: number });const cos = Math.cos(rot);const sin = Math.sin(rot);- const placeOffset = (off: { x: number; y: number }) => ({- x: t.worldPosition.x + (off.x * ppu) * cos - (off.y * ppu) * sin,- y: t.worldPosition.y + (off.x * ppu) * sin + (off.y * ppu) * cos,- });- // One-way platforms cancel contacts approaching from behind `normal` — show the- // solid side. The normal is world-space (screen y flips), independent of rotation.- let oneWay: { dx: number; dy: number } | null = null;- if (world.has(id, OneWayPlatform)) {- const ow = world.get(id, OneWayPlatform) as { normal: { x: number; y: number }; enabled: boolean };- const len = Math.hypot(ow.normal.x, ow.normal.y);- if (ow.enabled !== false && len > 1e-4) oneWay = { dx: ow.normal.x / len, dy: -ow.normal.y / len };- }+ const wp = { x: t.worldPosition.x, y: t.worldPosition.y };- if (world.has(id, BoxCollider)) {- const b = world.get(id, BoxCollider) as { halfExtents: { x: number; y: number }; offset: { x: number; y: number } };- const c = placeOffset(b.offset);- const hw = b.halfExtents.x * ppu;- const hh = b.halfExtents.y * ppu;- const centerS = this.worldToClient(c.x, c.y);- const screen = obbCorners({ cx: c.x, cy: c.y, hw: Math.abs(hw), hh: Math.abs(hh), rot }).map(([wx, wy]) =>- this.worldToClient(wx, wy),- );- if (!centerS || screen.some((p) => !p)) return null;- const bs = screen.map((p) => ({ x: p!.x, y: p!.y }));- // Size handle at the +hw,+hh corner (obbCorners index 2) — drag = halfExtents.- return { kind: 'box', cx: centerS.x, cy: centerS.y, r: 0, pts: bs, handle: null, sizeHandle: bs[2], oneWay };+ // readColliderShapes only reads (has/get); the editor world is the readonly view.+ const instances = readColliderShapes(world as unknown as Parameters<typeof readColliderShapes>[0], id);+ if (instances.length === 0) return null;++ // A world-px outline → SVG path data in CSS px (polylines as move/line runs, a circle+ // as two half-arcs). A run drops out if any of its points is off-camera.+ const outlinePath = (o: { polylines: Array<Array<{ x: number; y: number }>>; circles: Array<{ c: { x: number; y: number }; r: number }> }): string => {+ let d = '';+ for (const line of o.polylines) {+ let seg = '';+ for (let i = 0; i < line.length; i++) {+ const s = this.worldToClient(line[i].x, line[i].y);+ if (!s) { seg = ''; break; }+ seg += `${i ? 'L' : 'M'}${s.x},${s.y}`;+ }+ if (seg) d += `${seg} `;+ }+ for (const c of o.circles) {+ const ctr = this.worldToClient(c.c.x, c.c.y);+ const edge = this.worldToClient(c.c.x + c.r, c.c.y);+ if (!ctr || !edge) continue;+ const r = Math.hypot(edge.x - ctr.x, edge.y - ctr.y);+ d += `M${ctr.x - r},${ctr.y}a${r},${r} 0 1,0 ${2 * r},0a${r},${r} 0 1,0 ${-2 * r},0 `;+ }+ return d;+ };+ // Entity-local (metre) point → CSS px, rotated by the entity angle about its origin.+ const localToClient = (lx: number, ly: number) =>+ this.worldToClient(wp.x + lx * ppu * cos - ly * ppu * sin, wp.y + lx * ppu * sin + ly * ppu * cos);++ let solid = '';+ let sensor = '';+ let sizeHandle: { x: number; y: number } | null = null;+ let radiusHandle: { x: number; y: number } | null = null;+ let oneWayCenter: { x: number; y: number } | null = null;+ const points: ColliderPointHandle[] = [];+ const pushPoint = (lx: number, ly: number, comp: string, key: string, index: number | null) => {+ const s = localToClient(lx, ly);+ if (s) points.push({ x: s.x, y: s.y, comp, key, index });+ };++ for (const inst of instances) {+ const shape = inst.shape;+ const center = shapeCenter(shape, wp, rot, ppu); // world px (offset applied)+ const outline = colliderShapeOutline(shape, center, rot, ppu);+ const d = outlinePath(outline);+ if (inst.isSensor) sensor += d; else solid += d;+ if (!oneWayCenter) oneWayCenter = this.worldToClient(center.x, center.y);++ switch (shape.kind) {+ case 'box': {+ // Size handle at the +hx,+hy corner (drag = halfExtents), rotated with the entity.+ const hx = shape.halfExtents.x * ppu;+ const hy = shape.halfExtents.y * ppu;+ const hs = this.worldToClient(center.x + hx * cos - hy * sin, center.y + hx * sin + hy * cos);+ if (hs) sizeHandle = hs;+ const os = this.worldToClient(center.x, center.y); // offset handle at the shape center+ if (os) points.push({ x: os.x, y: os.y, comp: 'BoxCollider', key: 'offset', index: null });+ break;+ }+ case 'circle': {+ // Radius handle at the shape's local top (drag = radius, in physics metres).+ const r = shape.radius * ppu;+ const rs = this.worldToClient(center.x - r * sin, center.y + r * cos);+ if (rs) radiusHandle = rs;+ const os = this.worldToClient(center.x, center.y);+ if (os) points.push({ x: os.x, y: os.y, comp: 'CircleCollider', key: 'offset', index: null });+ break;+ }+ case 'capsule': {+ // radius / halfHeight stay Inspector-edited (rare shape); the offset is draggable.+ const os = this.worldToClient(center.x, center.y);+ if (os) points.push({ x: os.x, y: os.y, comp: 'CapsuleCollider', key: 'offset', index: null });+ break;+ }+ case 'segment':+ pushPoint(shape.point1.x, shape.point1.y, 'SegmentCollider', 'point1', null);+ pushPoint(shape.point2.x, shape.point2.y, 'SegmentCollider', 'point2', null);+ break;+ case 'polygon':+ shape.vertices.forEach((v, i) => pushPoint(v.x, v.y, 'PolygonCollider', 'vertices', i));+ break;+ case 'chain':+ shape.points.forEach((v, i) => pushPoint(v.x, v.y, 'ChainCollider', 'points', i));+ break;+ }}- const cc = world.get(id, CircleCollider) as { radius: number; offset: { x: number; y: number } };- const c = placeOffset(cc.offset);- const center = this.worldToClient(c.x, c.y);- const edge = this.worldToClient(c.x + cc.radius * ppu, c.y);- if (!center || !edge) return null;- // Radius handle at the top of the circle (drag = radius, in physics meters).- const handle = this.worldToClient(c.x, c.y + cc.radius * ppu);- return { kind: 'circle', cx: center.x, cy: center.y, r: Math.hypot(edge.x - center.x, edge.y - center.y), pts: [], handle: handle ?? null, sizeHandle: null, oneWay };+ // One-way solid-side arrow: the world-space normal (screen y flips), out of the first+ // collider's center — the side a body can land on; it passes through from behind.+ let oneWay: ColliderGizmo['oneWay'] = null;+ if (oneWayCenter && world.has(id, OneWayPlatform)) {+ const ow = world.get(id, OneWayPlatform) as { normal: { x: number; y: number }; enabled: boolean };+ const len = Math.hypot(ow.normal.x, ow.normal.y);+ if (ow.enabled !== false && len > 1e-4) {+ oneWay = { cx: oneWayCenter.x, cy: oneWayCenter.y, dx: ow.normal.x / len, dy: -ow.normal.y / len };+ }+ }+ return { outline: solid, outlineSensor: sensor, oneWay, sizeHandle, radiusHandle, points };},/**diff --git a/desktop/src/panels/Viewport.tsx b/desktop/src/panels/Viewport.tsxindex 8ade52fdb..84f8faf1b 100644--- a/desktop/src/panels/Viewport.tsx+++ b/desktop/src/panels/Viewport.tsx@@ -20,7 +20,7 @@ import { commands } from '@/commands';import { MOD_LABEL } from '@/commands/keybinding';import { EngineHost } from '@/engine/EngineHost';import { PlayRealm } from '@/engine/PlayRealm';-import { ViewportController, type JointGizmoType } from '@/engine/ViewportController';+import { ViewportController, type JointGizmoType, type ColliderPointHandle } from '@/engine/ViewportController';import { ProjectStore } from '@/project/ProjectStore';import { createFromSource, sourceById, SOURCE_DND_MIME } from '@/engine/entitySources';import { resizeUINodeAxis, type ResizeSide, type AxisResizeWrites } from '@/engine/uiResize';@@ -121,6 +121,95 @@ function startSizeHandleDrag(win.addEventListener('pointerup', onUp);}+// Drag a collider point handle → a Vec2 field (box/circle/capsule offset, segment+// endpoint) or ONE element of a Vec2[] (polygon vertex, chain point). The cursor is+// un-rotated into the entity's local frame and scaled to physics metres (÷ppu), then+// written through the same setField + begin/endGesture channel as every other handle+// (one coalesced undo step). Array targets rewrite the whole Vec2[] with only index i+// changed — snapshotted at grab so a drag can't compound. One channel for all six shapes.+function startColliderPointDrag(+ rt: number,+ target: { comp: string; key: string; index: number | null },+ ppu: number,+ e: { button: number; clientX: number; clientY: number; currentTarget: EventTarget | null; stopPropagation(): void },+): void {+ if (e.button !== 0) return;+ const src = SceneModel.sourceFor(rt);+ const origin = ViewportController.getEntityWorldXY(rt);+ if (src == null || !origin) return;+ e.stopPropagation();+ const rot = ViewportController.getEntityWorldAngleRad(rt);+ const cos = Math.cos(rot), sin = Math.sin(rot);+ const base = target.index == null+ ? null+ : (((SceneModel.entityBySource(src)?.components.find((c) => c.type === target.comp)?.data as Record<string, unknown> | undefined)?.[target.key]) as Array<{ x: number; y: number }> | undefined) ?? null;+ const win = eventWindow(e);+ SceneCommands.beginGesture('Edit Collider');+ const onMove = (ev: PointerEvent) => {+ const w = ViewportController.canvasToWorld(ev.clientX, ev.clientY);+ if (!w) return;+ const dx = w.x - origin.x, dy = w.y - origin.y;+ const lx = (dx * cos + dy * sin) / (ppu || 1); // un-rotate into local → metres+ const ly = (-dx * sin + dy * cos) / (ppu || 1);+ if (target.index == null) {+ SceneCommands.setField(src, target.comp, target.key, 'vec2', [lx, ly]);+ } else if (base) {+ SceneCommands.setVertexArray(src, target.comp, target.key,+ base.map((p, i) => (i === target.index ? { x: lx, y: ly } : { x: p.x, y: p.y })));+ }+ };+ const onUp = () => {+ SceneCommands.endGesture();+ win.removeEventListener('pointermove', onMove);+ win.removeEventListener('pointerup', onUp);+ };+ win.addEventListener('pointermove', onMove);+ win.addEventListener('pointerup', onUp);+}++// Native pointerdown on a pooled collider point handle → the drag above. The target field+// is read off the circle's data-*; the entity off the owning gizmo SVG's data-src. Native+// (not React) so the imperatively-pooled circles work in a popped-out viewport window too.+function onColliderPointDown(e: PointerEvent): void {+ const el = e.currentTarget as SVGCircleElement;+ const comp = el.getAttribute('data-comp');+ const key = el.getAttribute('data-key');+ const srcAttr = el.closest('.viewport__collider-gizmo')?.getAttribute('data-src');+ if (!comp || !key || srcAttr == null) return;+ const rt = SceneModel.runtimeFor(Number(srcAttr));+ if (rt == null) return;+ const idx = el.getAttribute('data-index');+ startColliderPointDrag(rt, { comp, key, index: idx ? Number(idx) : null }, ViewportController.colliderPixelsPerUnit(), e);+}++// Pool the point-handle circles inside a gizmo's <g> — one per handle, reused across+// frames, created (and bound) lazily, extras hidden. Uses the SVG's OWN document so a+// popped-out viewport gets its handles in the right window.+function syncColliderPoints(g: SVGGElement, points: ColliderPointHandle[]): void {+ const doc = g.ownerDocument;+ let child = g.firstElementChild as SVGCircleElement | null;+ for (const p of points) {+ if (!child) {+ child = doc.createElementNS('http://www.w3.org/2000/svg', 'circle');+ child.setAttribute('r', '4');+ child.addEventListener('pointerdown', onColliderPointDown);+ g.appendChild(child);+ }+ child.setAttribute('cx', String(p.x));+ child.setAttribute('cy', String(p.y));+ child.setAttribute('data-comp', p.comp);+ child.setAttribute('data-key', p.key);+ child.setAttribute('data-index', p.index == null ? '' : String(p.index));+ child.setAttribute('class', p.key === 'offset' ? 'cl-vert cl-offset' : 'cl-vert');+ child.style.display = '';+ child = child.nextElementSibling as SVGCircleElement | null;+ }+ while (child) {+ child.style.display = 'none';+ child = child.nextElementSibling as SVGCircleElement | null;+ }+}+// Project a world-space, axis-aligned rect (center + half extents) to a CSS-px// screen rect. The editor camera is 2D ortho (no rotation), so projecting two// opposite corners and taking their AABB is exact. Null if off-camera / no view.@@ -1129,62 +1218,45 @@ export function Viewport() {}}- // Collider gizmos — box polygon / circle outline at the collider's shape.- // Resolve the scene-wide pixelsPerUnit once, not once per collider.+ // Collider gizmos — the merged outline of EVERY collider shape (box/circle/capsule/+ // segment/polygon/chain), one <svg> per entity, all via the shared shape-outline+ // projection. Resolve the scene-wide pixelsPerUnit once, not once per collider.const colliderPpu = camsOn ? ViewportController.colliderPixelsPerUnit() : 0;for (const [cid, svg] of colliderRefs.current) {if (!svg) continue;const cg = camsOn ? ViewportController.getColliderGizmo(cid, colliderPpu) : null;- const poly = svg.querySelector('.cl-box') as SVGPolygonElement | null;- const circ = svg.querySelector('.cl-circle') as SVGCircleElement | null;- if (cg && cg.kind === 'box' && poly) {- poly.setAttribute('points', cg.pts.map((p) => `${p.x},${p.y}`).join(' '));- poly.style.opacity = '1';- if (circ) circ.style.opacity = '0';- } else if (cg && cg.kind === 'circle' && circ) {- circ.setAttribute('cx', String(cg.cx));- circ.setAttribute('cy', String(cg.cy));- circ.setAttribute('r', String(cg.r));- circ.style.opacity = '1';- if (poly) poly.style.opacity = '0';- } else {- if (poly) poly.style.opacity = '0';- if (circ) circ.style.opacity = '0';+ const outline = svg.querySelector('.cl-outline') as SVGPathElement | null;+ const outlineS = svg.querySelector('.cl-outline-sensor') as SVGPathElement | null;+ if (outline) outline.setAttribute('d', cg?.outline ?? '');+ if (outlineS) outlineS.setAttribute('d', cg?.outlineSensor ?? '');+ // Scalar handles: box corner size (cl-size-handle) / circle radius (cl-handle).+ const csz = svg.querySelector('.cl-size-handle') as SVGCircleElement | null;+ if (csz) {+ if (cg?.sizeHandle) { csz.setAttribute('cx', String(cg.sizeHandle.x)); csz.setAttribute('cy', String(cg.sizeHandle.y)); csz.style.display = ''; }+ else csz.style.display = 'none';}- // Collider drag handles: circle radius (cl-handle) / box corner size (cl-size-handle).const chnd = svg.querySelector('.cl-handle') as SVGCircleElement | null;if (chnd) {- if (cg && cg.kind === 'circle' && cg.handle) {- chnd.setAttribute('cx', String(cg.handle.x));- chnd.setAttribute('cy', String(cg.handle.y));- chnd.style.display = '';- } else {- chnd.style.display = 'none';- }- }- const csz = svg.querySelector('.cl-size-handle') as SVGCircleElement | null;- if (csz) {- if (cg && cg.kind === 'box' && cg.sizeHandle) {- csz.setAttribute('cx', String(cg.sizeHandle.x));- csz.setAttribute('cy', String(cg.sizeHandle.y));- csz.style.display = '';- } else {- csz.style.display = 'none';- }+ if (cg?.radiusHandle) { chnd.setAttribute('cx', String(cg.radiusHandle.x)); chnd.setAttribute('cy', String(cg.radiusHandle.y)); chnd.style.display = ''; }+ else chnd.style.display = 'none';}+ // Point handles: polygon vertices / chain points / segment endpoints / offsets,+ // pooled in the <g> (their count varies with the shape).+ const g = svg.querySelector('.cl-points') as SVGGElement | null;+ if (g) syncColliderPoints(g, cg?.points ?? []);// One-way platform: an arrow out of the collider center along the solid-side- // normal (screen-fixed length, like the light direction line, so it reads at- // any zoom) — the side a body can land on; it passes through from the other.+ // normal (screen-fixed length, so it reads at any zoom) — the side a body can+ // land on; it passes through from the other.const owLine = svg.querySelector('.cl-oneway') as SVGLineElement | null;const owHead = svg.querySelector('.cl-oneway-head') as SVGPolygonElement | null;- if (cg && cg.oneWay) {+ if (cg?.oneWay) {const L = 30;- const { dx, dy } = cg.oneWay;- const bx = cg.cx + dx * L;- const by = cg.cy + dy * L;+ const { cx, cy, dx, dy } = cg.oneWay;+ const bx = cx + dx * L;+ const by = cy + dy * L;if (owLine) {- owLine.setAttribute('x1', String(cg.cx));- owLine.setAttribute('y1', String(cg.cy));+ owLine.setAttribute('x1', String(cx));+ owLine.setAttribute('y1', String(cy));owLine.setAttribute('x2', String(bx));owLine.setAttribute('y2', String(by));owLine.style.opacity = '1';@@ -1839,8 +1911,9 @@ export function Viewport() {data-src={SceneModel.sourceFor(id)}aria-hidden="true">- <polygon className="cl-box" points="" />- <circle className="cl-circle" cx="0" cy="0" r="0" />+ {/* Merged outline of every collider shape on the entity (solid + dashed sensor). */}+ <path className="cl-outline" d="" />+ <path className="cl-outline-sensor" d="" /><line className="cl-oneway" x1="0" y1="0" x2="0" y2="0" /><polygon className="cl-oneway-head" points="" /><circle@@ -1859,6 +1932,10 @@ export function Viewport() {style={{ display: 'none' }}onPointerDown={(e) => startSizeHandleDrag(id, 'BoxCollider', 'halfExtents', ViewportController.colliderPixelsPerUnit(), false, e, ViewportController.colliderWorldCenter(id))}/>+ {/* Point handles (vertices / endpoints / offsets) — pooled imperatively by the+ rAF since their count varies with the shape; each binds its own native+ pointerdown (see syncColliderPoints). */}+ <g className="cl-points" /></svg>))}diff --git a/desktop/src/theme/app.css b/desktop/src/theme/app.cssindex ebe68597e..57a8f986e 100644--- a/desktop/src/theme/app.css+++ b/desktop/src/theme/app.css@@ -394,12 +394,21 @@ body.thumb-capture .viewport > :not(.viewport__stage):not(.viewport__play) {pointer-events: none;overflow: visible;}-.viewport__collider-gizmo .cl-box,-.viewport__collider-gizmo .cl-circle {+/* Merged outline of every collider shape (box/circle/capsule/segment/polygon/chain) as+ one path — empty `d` when off / no collider, so no opacity toggle is needed. */+.viewport__collider-gizmo .cl-outline {fill: color-mix(in srgb, var(--gizmo-collider) 6%, transparent);stroke: var(--gizmo-collider);stroke-width: 1.5;- opacity: 0;+ stroke-linejoin: round;+}+/* Sensor colliders: dashed, unfilled — a trigger reads distinct from a solid body. */+.viewport__collider-gizmo .cl-outline-sensor {+ fill: none;+ stroke: var(--gizmo-collider);+ stroke-width: 1.5;+ stroke-dasharray: 4 3;+ opacity: 0.85;}/* Draggable handles — circle radius / box corner size (meters), written on canvas. */.viewport__collider-gizmo .cl-handle,@@ -413,6 +422,22 @@ body.thumb-capture .viewport > :not(.viewport__stage):not(.viewport__play) {.viewport__collider-gizmo .cl-size-handle {cursor: nwse-resize;}+/* Point handles: polygon vertices / chain points / segment endpoints (filled), and+ box/circle/capsule offsets (hollow — "move the shape", not "a vertex"). */+.viewport__collider-gizmo .cl-vert {+ fill: var(--gizmo-collider);+ stroke: var(--srf-2);+ stroke-width: 1.25;+ pointer-events: auto;+ cursor: move;+}+.viewport__collider-gizmo .cl-vert:hover {+ fill: color-mix(in srgb, var(--gizmo-collider) 70%, white);+}+.viewport__collider-gizmo .cl-offset {+ fill: var(--srf-2);+ stroke: var(--gizmo-collider);+}/* One-way platform solid-side arrow (world-space normal out of the collider center). */.viewport__collider-gizmo .cl-oneway {stroke: var(--gizmo-collider);diff --git a/desktop/src/types.ts b/desktop/src/types.tsindex 00d6bd5d1..71b6cc5b5 100644--- a/desktop/src/types.ts+++ b/desktop/src/types.ts@@ -33,6 +33,7 @@ export type InspectorFieldType =| 'string'| 'vec2'| 'vec3'+ | 'vec2list' // a whole Vec2[] written at once (polygon vertices / chain points) — viewport vertex drag| 'angle' // 2D rotation: a quaternion shown/edited as Z degrees| 'color'| 'enum' // an int field with named options, shown as a dropdowndiff --git a/desktop/tests/engine-commands.test.ts b/desktop/tests/engine-commands.test.tsindex 38d890d18..079b4bae3 100644--- a/desktop/tests/engine-commands.test.ts+++ b/desktop/tests/engine-commands.test.ts@@ -14,7 +14,7 @@* ids; the World is asserted via session.model.runtimeFor.*/import { describe, it, expect, beforeAll, beforeEach, afterEach, vi } from 'vitest';-import { App, Transform, Parent, Children, Sprite, Interactable, BUILTIN_UI_PREFABS } from 'esengine';+import { App, Transform, Parent, Children, Sprite, Interactable, PolygonCollider, BUILTIN_UI_PREFABS } from 'esengine';import type { ESEngineModule } from 'esengine';import { loadWasmModule, HAS_WASM } from './helpers/loadWasm';@@ -100,6 +100,26 @@ describe.skipIf(!HAS_WASM)('SceneCommands / SceneQuery (headless World)', () =>expect(host.world.get(e, Transform).position.x).toBe(0);});+ it('setVertexArray writes a whole Vec2[] collider field to the World; a gesture coalesces the drag; undo reverts', () => {+ const id = S.commands.addEntity()!;+ const e = rt(id);+ S.commands.addComponent(id, 'PolygonCollider');+ const defLen = (host.world.get(e, PolygonCollider).vertices as ArrayLike<unknown>).length;+ // Simulate a viewport vertex drag: successive whole-array writes, only index 0+ // moving, coalesced into one undo step.+ S.commands.beginGesture('Drag vertex');+ S.commands.setVertexArray(id, 'PolygonCollider', 'vertices', [{ x: 1, y: 0 }, { x: 0, y: 1 }, { x: 0, y: 0 }]);+ S.commands.setVertexArray(id, 'PolygonCollider', 'vertices', [{ x: 2, y: 0 }, { x: 0, y: 1 }, { x: 0, y: 0 }]);+ S.commands.endGesture();+ const v = host.world.get(e, PolygonCollider).vertices as ArrayLike<{ x: number; y: number }>;+ expect(v.length).toBe(3);+ expect(v[0]).toMatchObject({ x: 2, y: 0 }); // the dragged vertex+ expect(v[1]).toMatchObject({ x: 0, y: 1 }); // the others intact++ S.history.undo(); // one step undoes the whole drag+ expect((host.world.get(e, PolygonCollider).vertices as ArrayLike<unknown>).length).toBe(defLen);+ });+it('deleteEntity removes the entity; undo re-creates it', () => {const id = S.commands.addEntity()!;expect(host.world.getAllEntities().length).toBe(1);