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): drag an emitter's radius on the canvas
yhh2e4e4f05c772
diff --git a/desktop/src/engine/ViewportController.ts b/desktop/src/engine/ViewportController.tsindex e6f0b8a35..f7d10c940 100644--- a/desktop/src/engine/ViewportController.ts+++ b/desktop/src/engine/ViewportController.ts@@ -526,7 +526,7 @@ export const ViewportController = {*/getParticleEmitterGizmo(id: EntityId,- ): { cx: number; cy: number; kind: 'point' | 'circle' | 'poly'; r: number; pts: Array<{ x: number; y: number }>; on: boolean } | null {+ ): { cx: number; cy: number; kind: 'point' | 'circle' | 'poly'; r: number; pts: Array<{ x: number; y: number }>; on: boolean; handle: { x: number; y: number } | null } | null {const world = EngineHost.world;if (!world || !world.valid(id) || !world.has(id, ParticleEmitter) || !world.has(id, Transform)) return null;const t = world.get(id, Transform);@@ -550,7 +550,9 @@ export const ViewportController = {case 1: { // Circle — spawn disk of shapeRadiusconst edge = this.worldToClient(t.worldPosition.x + p.shapeRadius, t.worldPosition.y);const r = edge ? Math.hypot(edge.x - center.x, edge.y - center.y) : 0;- return { cx: center.x, cy: center.y, kind: 'circle', r, pts: [], on };+ // Radius handle at the top of the ring (drag to resize shapeRadius).+ const handle = this.worldToClient(t.worldPosition.x, t.worldPosition.y + p.shapeRadius);+ return { cx: center.x, cy: center.y, kind: 'circle', r, pts: [], on, handle: handle ?? null };}case 2: { // Rectangle — oriented spawn box of shapeSizeconst corners = obbCorners({@@ -558,7 +560,7 @@ export const ViewportController = {hw: Math.abs(p.shapeSize.x) * 0.5, hh: Math.abs(p.shapeSize.y) * 0.5, rot,}).map(([wx, wy]) => this.worldToClient(wx, wy));if (corners.some((s) => !s)) return null;- return { cx: center.x, cy: center.y, kind: 'poly', r: 0, pts: corners.map((s) => ({ x: s!.x, y: s!.y })), on };+ return { cx: center.x, cy: center.y, kind: 'poly', r: 0, pts: corners.map((s) => ({ x: s!.x, y: s!.y })), on, handle: null };}case 3: { // Cone — aim wedge: local up (0,1) swept ±shapeAngle/2, out to shapeRadiusconst half = Math.max(0, p.shapeAngle) * 0.5 * (Math.PI / 180);@@ -572,10 +574,13 @@ export const ViewportController = {if (!s) return null;pts.push({ x: s.x, y: s.y });}- return { cx: center.x, cy: center.y, kind: 'poly', r: 0, pts, on };+ // Radius handle at the wedge's forward tip (drag to resize shapeRadius/reach).+ const tip = toWorld(0, rad);+ const handleS = this.worldToClient(tip.x, tip.y);+ return { cx: center.x, cy: center.y, kind: 'poly', r: 0, pts, on, handle: handleS ?? null };}default: // Point (0) — a marker at the emitter (the clickable icon)- return { cx: center.x, cy: center.y, kind: 'point', r: 0, pts: [], on };+ return { cx: center.x, cy: center.y, kind: 'point', r: 0, pts: [], on, handle: null };}},};diff --git a/desktop/src/panels/Viewport.tsx b/desktop/src/panels/Viewport.tsxindex f626aeac5..cf8c39206 100644--- a/desktop/src/panels/Viewport.tsx+++ b/desktop/src/panels/Viewport.tsx@@ -16,6 +16,7 @@ import { ViewportController } from '@/engine/ViewportController';import { ProjectStore } from '@/project/ProjectStore';import { IMAGE_RE } from '@/project/assetMeta';import { SceneModel } from '@/engine/SceneModel';+import { SceneCommands } from '@/engine/SceneCommands';import { SceneStore } from '@/engine/SceneStore';import { StatsStore } from '@/engine/StatsStore';import { PerfMonitor } from '@/engine/PerfMonitor';@@ -34,6 +35,33 @@ const toInput = (e: ReactPointerEvent): PointerInput => ({button: e.button, shift: e.shiftKey, alt: e.altKey,});+// Drag an emitter gizmo's radius handle: convert the cursor to world space and write+// shapeRadius through the SAME setField + begin/endGesture channel the Inspector uses+// (one coalesced undo step, one source of truth). This is the reusable on-canvas-edit+// shape — any gizmo handle can drive a component field the same way (light radius,+// collider size are the natural next adopters).+function startEmitterRadiusDrag(rt: number, e: ReactPointerEvent): void {+ if (e.button !== 0) return;+ const src = SceneModel.sourceFor(rt);+ const center = ViewportController.getEntityWorldXY(rt);+ if (src == null || !center) return;+ e.stopPropagation();+ SceneCommands.beginGesture('Emitter radius');+ const onMove = (ev: PointerEvent) => {+ const w = ViewportController.canvasToWorld(ev.clientX, ev.clientY);+ if (!w) return;+ const r = Math.max(0, Math.hypot(w.x - center.x, w.y - center.y));+ SceneCommands.setField(src, 'ParticleEmitter', 'shapeRadius', 'number', r);+ };+ const onUp = () => {+ SceneCommands.endGesture();+ window.removeEventListener('pointermove', onMove);+ window.removeEventListener('pointerup', onUp);+ };+ window.addEventListener('pointermove', onMove);+ window.addEventListener('pointerup', onUp);+}+// The interactive transform gizmo, drawn from the origin (= the selection pivot, the// wrapper is translated there each frame). Its geometry mirrors the hit zones in// gizmo.ts (GIZMO constants) so the handles a user aims at are the handles the tool@@ -621,6 +649,18 @@ export function Viewport() {if (poly) poly.style.opacity = '0';if (circ) circ.style.opacity = '0';}+ // Radius drag-handle (Circle/Cone): shown only when the emitter is on and+ // exposes one; hidden (display:none) otherwise so it can't grab pointers.+ const hnd = svg ? (svg.querySelector('.pe-handle') as SVGCircleElement | null) : null;+ if (hnd) {+ if (pg && pg.on && pg.handle) {+ hnd.setAttribute('cx', String(pg.handle.x));+ hnd.setAttribute('cy', String(pg.handle.y));+ hnd.style.display = '';+ } else {+ hnd.style.display = 'none';+ }+ }}PerfMonitor.mark('gizmo.update', perfT0);};@@ -944,6 +984,14 @@ export function Viewport() {><polygon className="pe-poly" points="" /><circle className="pe-circle" cx="0" cy="0" r="0" />+ <circle+ className="pe-handle"+ cx="0"+ cy="0"+ r="5"+ style={{ display: 'none' }}+ onPointerDown={(e) => startEmitterRadiusDrag(id, e)}+ /></svg>))}diff --git a/desktop/src/theme/app.css b/desktop/src/theme/app.cssindex 75164f61f..ce9b27ca5 100644--- a/desktop/src/theme/app.css+++ b/desktop/src/theme/app.css@@ -823,6 +823,17 @@ body.thumb-capture .viewport__play-stop {stroke-width: 1.5;opacity: 0;}+/* Draggable radius handle (Circle/Cone) — write shapeRadius on canvas. */+.viewport__particle-shape .pe-handle {+ fill: #ffb454;+ stroke: #1a1a1a;+ stroke-width: 1.5;+ pointer-events: auto;+ cursor: ew-resize;+}+.viewport__particle-shape .pe-handle:hover {+ fill: #ffd08a;+}.viewport__overlay {position: absolute;