mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-10 03:51:25 +00:00
PageScene: route shape recreate through the geometry key
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.
This commit is contained in:
1 parent
62094e5a33
commit
3681f4faef
2 files changed
+18
-1
No files matched your search
@@ -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));
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user