From 3681f4faefeb304d38ece2231a3b34c21d11726a Mon Sep 17 00:00:00 2001 From: Tanish Manku Date: Fri, 1 May 2026 03:26:31 -0700 Subject: [PATCH] PageScene: route shape recreate through the geometry key MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Shapes redo'd to broken / invisible objects because the snapshot captured obj.name = "Cube" (the display label addShape sets after creation), but scene.instantiate's geometry switch only matches the geometry key ("Box", "Sphere", "PointLight", ...). Calling instantiate("Cube", pos) fell through with no matching geometry. Fix: addShape stashes the geometry key in userData.shapeKey before overriding obj.name. recreateFromSnapshot picks shapeKey when present (falls back to snap.name for non-shape paths), then restores obj.name = snap.name after the create returns so the display label sticks. Non-shape recreations are unaffected — their userData has no shapeKey, so the fallback to snap.name keeps the existing flow. --- .../app/src/pages/PageScene/actions/addShape.ts | 4 ++++ .../PageScene/engine/editor/actions/snapshots.ts | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/frontend/apps/artcraft/app/src/pages/PageScene/actions/addShape.ts b/frontend/apps/artcraft/app/src/pages/PageScene/actions/addShape.ts index b093e9aba7..07b770d86b 100644 --- a/frontend/apps/artcraft/app/src/pages/PageScene/actions/addShape.ts +++ b/frontend/apps/artcraft/app/src/pages/PageScene/actions/addShape.ts @@ -15,6 +15,10 @@ export async function addShape( position ?? new THREE.Vector3(), ); if (!obj) return undefined; + // Stash the geometry key (Box / Sphere / PointLight / ...) so undo/redo + // can re-route through scene.instantiate's name switch. obj.name gets + // overridden below with the display label ("Cube", "Point Light"). + obj.userData.shapeKey = item.media_id; obj.name = item.name ?? "shape"; editor.history.record(new CreateAction(editor, obj)); diff --git a/frontend/apps/artcraft/app/src/pages/PageScene/engine/editor/actions/snapshots.ts b/frontend/apps/artcraft/app/src/pages/PageScene/engine/editor/actions/snapshots.ts index 4fccc0ca13..f2d83790fa 100644 --- a/frontend/apps/artcraft/app/src/pages/PageScene/engine/editor/actions/snapshots.ts +++ b/frontend/apps/artcraft/app/src/pages/PageScene/engine/editor/actions/snapshots.ts @@ -71,9 +71,22 @@ export const recreateFromSnapshot = async ( snap.transform.position.y, snap.transform.position.z, ); - const obj = await editor.sceneManager?.create(snap.media_id, snap.name, pos); + // Shapes route through scene.instantiate's geometry switch, which + // matches on the geometry key ("Box", "Sphere", "PointLight"), not + // the display name ("Cube", "Point Light"). addShape stashes the + // original key in userData.shapeKey so we can recover it here. + const nameForCreate = + (snap.userData.shapeKey as string | undefined) ?? snap.name; + const obj = await editor.sceneManager?.create( + snap.media_id, + nameForCreate, + pos, + ); if (!obj) return undefined; obj.uuid = snap.uuid; + // Restore the display name (instantiate/loadObject set obj.name to + // nameForCreate; for shapes that's the geometry key, not the label). + obj.name = snap.name; obj.rotation.set( snap.transform.rotation.x, snap.transform.rotation.y,