feat(web): Outliner eyedropper picks objects for modifier fields

Desktop's UI_OT_eyedropper_id borrows the ID under the cursor through
ED_outliner_give_base_under_cursor. The workbench splits Properties and
the Outliner into separate DOM trees, so an armed pick is shared through
a small external store: object-valued modifier fields grow a 取物 (pick)
button, the Outliner enters a crosshair pick mode, and clicking an
object row commits that object's id. Escape cancels, mirroring the
modal operator.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
mes123456
2026-11-30 17:45:32 +08:00
parent 716ae05c02
commit b0458e12de
8 changed files with 145 additions and 4 deletions

View File

@@ -1,4 +1,5 @@
import { ModifierParameterField } from "./ModifierParameterField";
import { acceptOutlinerPick, cancelOutlinerPick, useOutlinerPickActive } from "./outliner-pick";
import { Fragment } from 'react';
import { NLA_OBJECT_ID_TYPE } from '../../../protocol/nla';
import { EDITOR_RESOURCE_MAX_BYTES, isEditorResourcePath, modelResourcePath } from '../../../protocol/editor-resource-path';
@@ -2611,6 +2612,18 @@ function Outliner({ snapshot, areaId, onSelect, onToggleVisibility, onRefresh, o
const nativeArea = workspace?.areas.find(item => item.editor === 'OUTLINER' &&
(!areaId || item.id === areaId) && item.regions.some(region => region.kind === 'MAIN' && region.visible));
const tree = nativeArea?.space?.outliner;
/* Desktop ui_eyedropper_id arms a pick that ED_outliner_give_base_under_cursor
* resolves against the row under the cursor; here the pick rides a store so
* the Properties field and this tree share it. */
const outlinerPickActive = useOutlinerPickActive();
useEffect(() => {
if (!outlinerPickActive) return;
const onKey = (event: KeyboardEvent) => {
if (event.key === 'Escape') { event.preventDefault(); cancelOutlinerPick(); }
};
window.addEventListener('keydown', onKey, true);
return () => window.removeEventListener('keydown', onKey, true);
}, [outlinerPickActive]);
/* Desktop SO_MODE_COLUMN (outliner_draw.cc): Scenes and View Layer draw a
* mode dot on object rows sharing the active object's type while the active
* object is in an interaction mode. */
@@ -2862,7 +2875,7 @@ function Outliner({ snapshot, areaId, onSelect, onToggleVisibility, onRefresh, o
* parent (default view requires Shift); Alt clears completely instead of
* keeping the world transform. Drops on a row are handled there and never
* reach this container. */}
<div ref={treeRoot} tabIndex={-1} className="outliner-tree"
<div ref={treeRoot} tabIndex={-1} className={`outliner-tree${outlinerPickActive ? ' outliner-picking' : ''}`}
onPointerDownCapture={event => {
/* Only empty space or a B-armed press starts a box; presses on a row
* stay with the row (selection, rename, drag-drop). */
@@ -3012,6 +3025,13 @@ function Outliner({ snapshot, areaId, onSelect, onToggleVisibility, onRefresh, o
if (onTreeSelect && nativeArea) onTreeSelect(row.id, row.selected, false, nativeArea.id, false);
}}
onClick={event => {
/* An armed datablock pick takes the base under the cursor instead
* of selecting the row (desktop eyedropper over the Outliner). */
if (outlinerPickActive && row.objectId) {
event.preventDefault(); event.stopPropagation();
acceptOutlinerPick(row.objectId);
return;
}
const activatesData = event.target instanceof Element &&
!!event.target.closest('.tree-node-name');
// Name activation follows the same native intent as the

View File

@@ -65,3 +65,25 @@
flex: 1 1 100px;
min-width: 0;
}
.modifier-stack-authoring .parameter-eyedropper {
min-width: 0;
padding: 0 4px;
color: #d8d8d8;
background: #2e2e2e;
border: 1px solid #4a4a4a;
border-radius: 2px;
font-size: 11px;
line-height: 18px;
cursor: pointer;
}
.modifier-stack-authoring .parameter-eyedropper:hover {
color: #fff;
background: #4a4a4a;
}
.modifier-stack-authoring .parameter-eyedropper:disabled {
color: #6a6a6a;
cursor: default;
}

View File

@@ -2,6 +2,7 @@ import { useEffect, useId, useRef, useState } from "react";
import type { CSSProperties, PointerEvent as ReactPointerEvent, ReactNode } from "react";
import type { ModifierParameterMetadata } from "../../../protocol/modifier";
import { ModifierCurveProfileField } from "./ModifierCurveProfileField";
import { requestOutlinerPick } from "./outliner-pick";
import { finishModifierInput } from './modifier-input-keyboard';
import './modifier-curve-tools.css';
import zoomInIcon from './curve-icons/zoom_in.svg';
@@ -954,13 +955,19 @@ export function ModifierParameterField({ field, onCommit, onCurveGesture, onInte
const numericRange = typeof value === 'number' && field.minimum !== undefined && field.maximum !== undefined &&
Number.isFinite(field.minimum) && Number.isFinite(field.maximum) && field.minimum < field.maximum;
return <label key={`${index}:${String(value)}`} title={field.description}>{label}{field.kind === "enum" || field.kind === "object" || field.kind === "collection" || field.kind === "texture" || field.kind === "cachefile" || (field.kind === "string" && field.suggestionsOnly === false)
? <select aria-label={label} disabled={disabled} value={String(value ?? "")} onChange={(event) => commit((field.kind === "object" || field.kind === "collection" || field.kind === "texture" || field.kind === "cachefile") && event.target.value === "" ? null : event.target.value)}>
? <><select aria-label={label} disabled={disabled} value={String(value ?? "")} onChange={(event) => commit((field.kind === "object" || field.kind === "collection" || field.kind === "texture" || field.kind === "cachefile") && event.target.value === "" ? null : event.target.value)}>
{(field.kind === "object" || field.kind === "collection" || field.kind === "texture" || field.kind === "cachefile") && <option value="" disabled={field.nullable === false}>None</option>}
{field.kind === "string" && <option value="">None</option>}
{value !== null && value !== "" && !choices.some(item => item.id === value) &&
<option value={String(value)} disabled>{String(value)} (unavailable)</option>}
{choices.map((option) => <option key={option.id} value={option.id}>{option.label}</option>)}
</select>
{field.kind === "object" && !field.length
? <button type="button" className="parameter-eyedropper" disabled={disabled}
aria-label={`取物器 ${label}`} title="取物器:在 Outliner 中点选对象(桌面 UI_OT_eyedropper_id)"
onClick={event => { event.preventDefault(); event.stopPropagation(); requestOutlinerPick(objectId => { void commit(objectId); }); }}>取物</button>
: null}
</>
: field.kind === "string"
? <><input aria-label={label} disabled={disabled} type="text" defaultValue={String(value)}
maxLength={field.maxLength} list={suggestionsId}

View File

@@ -164,7 +164,7 @@ button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-
.tree-node-name { min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap; }
.properties-content { position: relative; display: flex; flex-direction: column; min-height: 100%; padding: 4px 7px 12px 40px; color: #d0d0d0; background: #303030; }
.outliner-tools { display: flex; gap: 3px; margin: 0 2px 4px; }.outliner-tools input { min-width: 0; height: 23px; flex: 1; padding: 3px 7px; color: #e4e4e4; background: #181818; border: 1px solid #454545; border-radius: 3px; outline: none; }.outliner-tools button { width: 27px; background: #383838; border-radius: 2px; }
.tree-row { display: flex; align-items: center; gap: 5px; min-height: 20px; padding: 0 4px; border-radius: 0; }.tree-row:hover { background: #353535; }.tree-row.selected { color: #fff; background: #4775a3; }.tree-icon { height:20px;min-width:16px;padding:0;border:0;background:transparent;color: #d59b44; }.tree-icon.mesh { color: #6999c8; }.tree-action { width: 20px; min-width: 20px; height: 20px; margin-left: auto; padding: 0 2px; color: #a6a6a6; background: transparent; border: 0; border-radius: 2px; }.tree-action:hover { color: #fff; background: #4a4a4a; }
.tree-row { display: flex; align-items: center; gap: 5px; min-height: 20px; padding: 0 4px; border-radius: 0; }.tree-row:hover { background: #353535; } .outliner-tree.outliner-picking .tree-row[data-node-id]:not([data-node-id=""]) { cursor: crosshair; }.tree-row.selected { color: #fff; background: #4775a3; }.tree-icon { height:20px;min-width:16px;padding:0;border:0;background:transparent;color: #d59b44; }.tree-icon.mesh { color: #6999c8; }.tree-action { width: 20px; min-width: 20px; height: 20px; margin-left: auto; padding: 0 2px; color: #a6a6a6; background: transparent; border: 0; border-radius: 2px; }.tree-action:hover { color: #fff; background: #4a4a4a; }
.tree-restrict { display: inline-flex; align-items: center; flex: 0 0 auto; margin-left: auto; }
.tree-restrict-button { width: 20px; min-width: 20px; height: 20px; padding: 0; color: #8d8d8d; background: transparent; border: 0; border-radius: 2px; font-size: 11px; line-height: 20px; }
.tree-restrict-button:hover:not(:disabled) { color: #fff; background: #4a4a4a; }

View File

@@ -0,0 +1,51 @@
import { useSyncExternalStore } from "react";
/* Desktop's datablock eyedropper (UI_OT_eyedropper_id) borrows an ID from the
* Outliner under the cursor through ED_outliner_give_base_under_cursor. The
* workbench splits Properties (DOM) and the Outliner (DOM) into separate
* component trees, so an armed pick is shared through this store instead of
* drilling a callback through the whole area layout. */
type ObjectPickRequest = { accept: (objectId: string) => void };
let pending: ObjectPickRequest | null = null;
const listeners = new Set<() => void>();
function emit(): void {
for (const listener of listeners) listener();
}
/** Arm the picker: the next Outliner object row supplies the ID. */
export function requestOutlinerPick(accept: (objectId: string) => void): void {
pending = { accept };
emit();
}
export function cancelOutlinerPick(): void {
if (!pending) return;
pending = null;
emit();
}
export function acceptOutlinerPick(objectId: string): void {
const request = pending;
if (!request) return;
pending = null;
emit();
request.accept(objectId);
}
function isActive(): boolean {
return pending !== null;
}
function subscribe(listener: () => void): () => void {
listeners.add(listener);
return () => {
listeners.delete(listener);
};
}
export function useOutlinerPickActive(): boolean {
return useSyncExternalStore(subscribe, isActive, () => false);
}