import type { CSSProperties, MouseEvent as ReactMouseEvent } from "react"; import { ViewportCanvas } from "./ViewportCanvas"; import { getViewportDisplayModeLabel, getViewportLayoutModeLabel, getViewportPanelLabel, VIEWPORT_LAYOUT_MODES, type ViewportPanelCameraState, type ViewportDisplayMode, type ViewportLayoutMode, type ViewportPanelId, type ViewportPanelState } from "./viewport-layout"; import { VIEWPORT_VIEW_MODES, getViewportViewModeLabel, type ViewportViewMode } from "./viewport-view-modes"; import type { CreationViewportToolPreview, ViewportToolPreview } from "./viewport-transient-state"; import type { LoadedModelAsset } from "../assets/gltf-model-import"; import type { LoadedImageAsset } from "../assets/image-assets"; import type { ProjectAssetRecord } from "../assets/project-assets"; import type { EditorSelection } from "../core/selection"; import { getWhiteboxSelectionModeLabel, WHITEBOX_SELECTION_MODES, type WhiteboxSelectionMode } from "../core/whitebox-selection-mode"; import type { ActiveTransformSession, TransformOperation, TransformSessionState } from "../core/transform-session"; import type { ToolMode } from "../core/tool-mode"; import type { SceneDocument } from "../document/scene-document"; import type { WorldSettings } from "../document/world-settings"; import type { RuntimeClockState } from "../runtime-three/runtime-project-time"; import type { RuntimeSceneDefinition } from "../runtime-three/runtime-scene-build"; interface ViewportPanelProps { panelId: ViewportPanelId; panelState: ViewportPanelState; layoutMode: ViewportLayoutMode; isActive: boolean; className?: string; style?: CSSProperties; world: WorldSettings; sceneDocument: SceneDocument; editorSimulationScene: RuntimeSceneDefinition | null; editorSimulationClock: RuntimeClockState | null; projectAssets: Record; loadedModelAssets: Record; loadedImageAssets: Record; whiteboxSelectionMode: WhiteboxSelectionMode; whiteboxSnapEnabled: boolean; whiteboxSnapStepDraft: string; whiteboxSnapStep: number; viewportGridVisible: boolean; selection: EditorSelection; activeSelectionId: string | null; toolMode: ToolMode; toolPreview: ViewportToolPreview; transformSession: TransformSessionState; canTranslateSelectedTarget: boolean; canRotateSelectedTarget: boolean; canScaleSelectedTarget: boolean; canSurfaceSnapTransformTarget: boolean; cameraState: ViewportPanelCameraState; focusRequestId: number; focusSelection: EditorSelection; isAddMenuOpen: boolean; onActivatePanel(panelId: ViewportPanelId): void; onOpenAddMenu(event: ReactMouseEvent): void; onSetViewportLayoutMode(layoutMode: ViewportLayoutMode): void; onSetPanelViewMode( panelId: ViewportPanelId, viewMode: ViewportViewMode ): void; onSetPanelDisplayMode( panelId: ViewportPanelId, displayMode: ViewportDisplayMode ): void; onCommitCreation(toolPreview: CreationViewportToolPreview): boolean; onCameraStateChange(cameraState: ViewportPanelCameraState): void; onToolPreviewChange(toolPreview: ViewportToolPreview): void; onBeginTransformOperation(operation: TransformOperation): void; onToggleTransformSurfaceSnap(): void; onWhiteboxSelectionModeChange(mode: WhiteboxSelectionMode): void; onViewportGridToggle(): void; onWhiteboxSnapToggle(): void; onWhiteboxSnapStepDraftChange(value: string): void; onWhiteboxSnapStepBlur(): void; onTransformSessionChange(transformSession: TransformSessionState): void; onTransformCommit(transformSession: ActiveTransformSession): void; onTransformCancel(): void; onSelectionChange(selection: EditorSelection): void; } const VIEWPORT_DISPLAY_MODES = ["normal", "authoring", "wireframe"] as const; function getPanelScopedTestId(panelId: ViewportPanelId, name: string): string { return `viewport-panel-${panelId}-${name}`; } function getSharedControlTestId( panelId: ViewportPanelId, isActive: boolean, sharedId: string, fallbackId = sharedId ): string { return isActive ? sharedId : getPanelScopedTestId(panelId, fallbackId); } export function ViewportPanel({ panelId, panelState, layoutMode, isActive, className, style, world, sceneDocument, editorSimulationScene, editorSimulationClock, projectAssets, loadedModelAssets, loadedImageAssets, whiteboxSelectionMode, whiteboxSnapEnabled, whiteboxSnapStepDraft, whiteboxSnapStep, viewportGridVisible, selection, activeSelectionId, toolMode, toolPreview, transformSession, canTranslateSelectedTarget, canRotateSelectedTarget, canScaleSelectedTarget, canSurfaceSnapTransformTarget, cameraState, focusRequestId, focusSelection, isAddMenuOpen, onActivatePanel, onOpenAddMenu, onSetViewportLayoutMode, onSetPanelViewMode, onSetPanelDisplayMode, onCommitCreation, onCameraStateChange, onToolPreviewChange, onBeginTransformOperation, onToggleTransformSurfaceSnap, onWhiteboxSelectionModeChange, onViewportGridToggle, onWhiteboxSnapToggle, onWhiteboxSnapStepDraftChange, onWhiteboxSnapStepBlur, onTransformSessionChange, onTransformCommit, onTransformCancel, onSelectionChange }: ViewportPanelProps) { const shouldShow = layoutMode === "quad" || isActive; const panelStyle = shouldShow ? style : { ...(style ?? {}), display: "none" }; const transformButtonsDisabled = toolMode !== "select"; return (
onActivatePanel(panelId)} onFocusCapture={() => onActivatePanel(panelId)} >
{VIEWPORT_LAYOUT_MODES.map((mode) => ( ))}
{VIEWPORT_VIEW_MODES.map((viewMode) => ( ))}
{VIEWPORT_DISPLAY_MODES.map((displayMode) => ( ))}
{transformSession.kind === "active" && transformSession.operation === "translate" ? ( ) : null}
{WHITEBOX_SELECTION_MODES.map((mode) => ( ))}
); }