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): unify on-canvas radius editing - lights + colliders adopt the drag handle
yhh446b33beb758
diff --git a/desktop/src/engine/ViewportController.ts b/desktop/src/engine/ViewportController.tsindex f7d10c940..83dce2b31 100644--- a/desktop/src/engine/ViewportController.ts+++ b/desktop/src/engine/ViewportController.ts@@ -400,7 +400,7 @@ export const ViewportController = {*/getLightGizmo(id: EntityId,- ): { cx: number; cy: number; kind: number; color: string; radiusPx: number; sdx: number; sdy: number; coneHalf: number; on: boolean } | null {+ ): { cx: number; cy: number; kind: number; color: string; radiusPx: number; sdx: number; sdy: number; coneHalf: number; on: boolean; handle: { x: number; y: number } | null } | null {const world = EngineHost.world;if (!world || !world.valid(id) || !world.has(id, Light2D) || !world.has(id, Transform)) return null;const t = world.get(id, Transform);@@ -434,7 +434,11 @@ export const ViewportController = {const hex = (v: number) => Math.max(0, Math.min(255, Math.round(v * 255))).toString(16).padStart(2, '0');const color = `#${hex(l.color.r)}${hex(l.color.g)}${hex(l.color.b)}`;const on = l.enabled !== false && l.intensity > 0;- return { cx: center.x, cy: center.y, kind: l.type, color, radiusPx, sdx, sdy, coneHalf, on };+ // Radius handle at the top of the reach circle (Point/Spot only — drag = radius).+ const handle = (l.type === 0 || l.type === 3)+ ? this.worldToClient(t.worldPosition.x, t.worldPosition.y + l.radius)+ : null;+ 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. */@@ -470,7 +474,7 @@ export const ViewportController = {*/getColliderGizmo(id: EntityId,- ): { kind: 'box'; pts: Array<{ x: number; y: number }> } | { kind: 'circle'; cx: number; cy: number; r: number } | null {+ ): { kind: 'box'; pts: Array<{ x: number; y: number }>; handle: { x: number; y: number } | null } | { kind: 'circle'; cx: number; cy: number; r: number; handle: { x: number; y: number } | null } | null {const world = EngineHost.world;if (!world || !world.valid(id) || !world.has(id, Transform)) return null;const t = world.get(id, Transform);@@ -492,7 +496,8 @@ export const ViewportController = {this.worldToClient(wx, wy),);if (screen.some((p) => !p)) return null;- return { kind: 'box', pts: screen.map((p) => ({ x: p!.x, y: p!.y })) };+ // Box halfExtents is a vec2 (corner handle) — a follow-up; no radius handle here.+ return { kind: 'box', pts: screen.map((p) => ({ x: p!.x, y: p!.y })), handle: null };}const cc = world.get(id, CircleCollider) as { radius: number; offset: { x: number; y: number } };@@ -500,7 +505,9 @@ export const ViewportController = {const center = this.worldToClient(c.x, c.y);const edge = this.worldToClient(c.x + cc.radius * ppu, c.y);if (!center || !edge) return null;- return { kind: 'circle', cx: center.x, cy: center.y, r: Math.hypot(edge.x - center.x, edge.y - center.y) };+ // 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), handle: handle ?? null };},/** Ids of entities carrying a ParticleEmitter — the emitter-gizmo set. */diff --git a/desktop/src/panels/Viewport.tsx b/desktop/src/panels/Viewport.tsxindex cf8c39206..32223e2c0 100644--- a/desktop/src/panels/Viewport.tsx+++ b/desktop/src/panels/Viewport.tsx@@ -35,23 +35,27 @@ 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 {+// Drag a gizmo's radius handle: convert the cursor to world space and write a scalar+// radius field through the SAME setField + begin/endGesture channel the Inspector uses+// (one coalesced undo step, one source of truth). The reusable on-canvas-edit shape —+// emitter shapeRadius, light radius, and circle-collider radius all drive their field+// this way. `ppu` maps world distance to the field's units: 1 for world-space radii+// (emitter/light), the collider's pixelsPerUnit for physics-meter radii. Measures from+// the entity's world origin (exact when the shape has no local offset).+function startRadiusHandleDrag(+ rt: number, component: string, field: string, ppu: 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');+ SceneCommands.beginGesture(`${component} 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 r = Math.max(0, Math.hypot(w.x - center.x, w.y - center.y) / (ppu || 1));+ SceneCommands.setField(src, component, field, 'number', r);};const onUp = () => {SceneCommands.endGesture();@@ -565,6 +569,17 @@ export function Viewport() {if (poly) poly.style.opacity = '0';if (circ) circ.style.opacity = '0';}+ // Circle-collider radius handle (box halfExtents is a vec2 — a follow-up).+ 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';+ }+ }}// Light2D gizmos — icon at the light, dashed reach circle (Point/Spot), direction@@ -610,6 +625,18 @@ export function Viewport() {line.style.opacity = '0';}}+ // Radius drag-handle (Point/Spot). The wrapper is translated to the light,+ // so place the handle at the reach edge in wrapper-local px.+ const lhnd = wrap.querySelector('.lg-handle') as SVGCircleElement | null;+ if (lhnd) {+ if (lg.on && lg.handle) {+ lhnd.setAttribute('cx', String(lg.handle.x - lg.cx));+ lhnd.setAttribute('cy', String(lg.handle.y - lg.cy));+ lhnd.style.display = '';+ } else {+ lhnd.style.display = 'none';+ }+ }} else {wrap.style.opacity = '0';wrap.style.visibility = 'hidden'; // an invisible bulb must not swallow clicks@@ -921,6 +948,14 @@ export function Viewport() {<line className="lg-dir" x1="0" y1="0" x2="0" y2="0" /><line className="lg-cone1" x1="0" y1="0" x2="0" y2="0" /><line className="lg-cone2" x1="0" y1="0" x2="0" y2="0" />+ <circle+ className="lg-handle"+ cx="0"+ cy="0"+ r="5"+ style={{ display: 'none' }}+ onPointerDown={(e) => startRadiusHandleDrag(id, 'Light2D', 'radius', 1, e)}+ /></svg></div>);@@ -940,6 +975,14 @@ export function Viewport() {><polygon className="cl-box" points="" /><circle className="cl-circle" cx="0" cy="0" r="0" />+ <circle+ className="cl-handle"+ cx="0"+ cy="0"+ r="5"+ style={{ display: 'none' }}+ onPointerDown={(e) => startRadiusHandleDrag(id, 'CircleCollider', 'radius', ViewportController.colliderPixelsPerUnit(), e)}+ /></svg>))}@@ -990,7 +1033,7 @@ export function Viewport() {cy="0"r="5"style={{ display: 'none' }}- onPointerDown={(e) => startEmitterRadiusDrag(id, e)}+ onPointerDown={(e) => startRadiusHandleDrag(id, 'ParticleEmitter', 'shapeRadius', 1, e)}/></svg>))}diff --git a/desktop/src/theme/app.css b/desktop/src/theme/app.cssindex ce9b27ca5..5435f42ca 100644--- a/desktop/src/theme/app.css+++ b/desktop/src/theme/app.css@@ -754,6 +754,14 @@ body.thumb-capture .viewport__play-stop {stroke-dasharray: 4 3;stroke-linecap: round;}+/* Draggable radius handle (Point/Spot) — write the light's radius on canvas. */+.viewport__light-svg .lg-handle {+ fill: currentColor;+ stroke: #1a1a1a;+ stroke-width: 1.5;+ pointer-events: auto;+ cursor: ew-resize;+}/* Physics collider outline (box polygon / circle). The SVG spans the viewport;the rAF writes absolute canvas-relative px into the shape. */@@ -773,6 +781,14 @@ body.thumb-capture .viewport__play-stop {stroke-width: 1.5;opacity: 0;}+/* Draggable radius handle (circle collider) — write the radius (meters) on canvas. */+.viewport__collider-gizmo .cl-handle {+ fill: #00dc82;+ stroke: #1a1a1a;+ stroke-width: 1.5;+ pointer-events: auto;+ cursor: ew-resize;+}/* Particle-emitter gizmo: a clickable icon at the emitter + its spawn-shape overlay.The icon wrapper is translate()'d to the emitter; the shape SVG spans the viewport