Place assets by dragging them from the panel into the view

The context menu entry is gone; dragging replaces it entirely. The drop
target is the view under the pointer, not the active tab, so the same
gesture works for scenes and for container templates.

While dragging, an outline shows the footprint the object will have plus
a crosshair on its origin, turning red when the drop would be refused.
Preview and command share one function (placementRejection), so the
outline cannot promise something the drop then rejects.

A left-press used to select the list row immediately. Since the container
tab follows the selection, it switched to the very container being dragged
and every drop would have nested it inside itself. The list now selects on
release without a drag: picking something up is not the same as choosing it.
This commit is contained in:
root committed 2026-09-09 13:09:13 +02:00
1 parent 14562cf157
commit 75d377af39
18 files changed
+545 -77

No files matched your search

+3 -5
View File
@@ -1,8 +1,7 @@
import { newId } from '../ids';
import { isPlaceableType } from '../model/AssetTypes';
import { containerReaches } from '../model/container';
import { isSelfOrAncestor, localPositionFor, removeSubtrees, worldPosition } from '../model/hierarchy';
import { captureObject, isLiveInstance, type ObjectMemo, restoreObject } from '../model/instance';
import { placementRejection } from '../model/placement';
import { type Position, type PropertyValue, toPosition, type Vec2 } from '../model/Properties';
import type { Project } from '../model/Project';
import { createSceneObject, type SceneObject } from '../model/SceneObject';
@@ -37,9 +36,8 @@ export class PlaceAssetCommand implements Command {
execute(project: Project): void {
const holder = requireHolder(project, this.holderId);
const asset = requireAsset(project, this.assetId);
if (!isPlaceableType(asset.type)) throw new CommandError('A scene cannot be placed into a scene');
if (asset.type === 'container' && containerReaches(project, asset, holder.id))
throw new CommandError(`${asset.name} cannot contain ${holder.name}: that nests forever`);
const rejection = placementRejection(project, holder, asset);
if (rejection) throw new CommandError(rejection);
if (this.parentId) {
requireObject(project, this.holderId, this.parentId);
requireStructural(project, holder, this.parentId);
+16
View File
@@ -0,0 +1,16 @@
import type { Asset } from './Asset';
import { isPlaceableType } from './AssetTypes';
import { containerReaches } from './container';
import type { ObjectHolder, Project } from './Project';
/**
* Why `asset` cannot be placed into `holder`, or '' when it can. A drag needs the answer while
* it hovers, `PlaceAssetCommand` needs it at the drop; both ask here so the preview cannot
* promise a placement the command then refuses.
*/
export function placementRejection(project: Project, holder: ObjectHolder, asset: Asset): string {
if (!isPlaceableType(asset.type)) return 'A scene cannot be placed into a scene';
if (asset.type === 'container' && containerReaches(project, asset, holder.id))
return `${asset.name} cannot contain ${holder.name}: that nests forever`;
return '';
}