Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import {
Undo2,
X,
} from 'lucide-react';
import { activeBrush } from './core/editor-brush';
import {
liveHost,
liveSession,
Expand Down Expand Up @@ -925,11 +926,7 @@ export default function App() {
return;
}
const state = useEditor.getState();
if (
event.target instanceof HTMLCanvasElement &&
state.tool === 'align' &&
state.operation.mode === 'surface'
) {
if (event.target instanceof HTMLCanvasElement && activeBrush(state)) {
event.preventDefault();
event.stopPropagation();
state.openContextMenu({ x: event.clientX, y: event.clientY, kind: 'brush' });
Expand All @@ -951,12 +948,7 @@ export default function App() {
state.openContextMenu({
x: event.clientX,
y: event.clientY,
kind:
target.closest('.viewport') &&
state.tool === 'align' &&
state.operation.mode === 'surface'
? 'brush'
: undefined,
kind: target.closest('.viewport') && activeBrush(state) ? 'brush' : undefined,
...(partId ? { partId } : {}),
});
}}
Expand Down
190 changes: 190 additions & 0 deletions src/components/BrushSettings.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
import { useShallow } from 'zustand/react/shallow';
import type { ReactNode } from 'react';
import { Eraser, Paintbrush, Undo2 } from 'lucide-react';
import { useEditor, paintingRefine, paintingWarpRegion } from '../core/store';
import { activeBrush, contactBrush, refineBrush, type EditorBrush } from '../core/editor-brush';
import { useSliderEdit } from '../hooks/useSliderEdit';
import { LogRangeInput, NumericInput } from './ui';

function PaintSettings({ full, children }: { full: boolean; children: ReactNode }) {
const erase = useEditor((state) => state.brushErase),
history = useEditor((state) => state.paintHistory),
plane = useEditor((state) => state.brushPlane);
return (
<>
<div
className={full ? 'paint-brush-modes' : 'paint-brush-modes without-undo'}
role="group"
aria-label="Surface brush mode"
>
<button
className={!erase ? 'active' : ''}
aria-pressed={!erase}
onClick={() => useEditor.getState().setBrush({ erase: false })}
>
<Paintbrush size={14} /> Paint
</button>
<button
className={erase ? 'active' : ''}
aria-pressed={erase}
onClick={() => useEditor.getState().setBrush({ erase: true })}
>
<Eraser size={14} /> Erase
</button>
{full ? (
<button
title="Undo last paint stroke"
aria-label="Undo last paint stroke"
disabled={!history.length}
onClick={() => useEditor.getState().undoPaintStroke()}
>
<Undo2 size={14} />
</button>
) : null}
</div>
{children}
{full ? (
<div className="plane-brush-settings">
<div className="appearance-row">
<span>Stay on seed plane</span>
<button
role="switch"
aria-label="Restrict brush to seed plane"
aria-checked={plane.enabled}
className={`toggle ${plane.enabled ? 'on' : ''}`}
onClick={() => useEditor.getState().setBrush({ plane: { enabled: !plane.enabled } })}
>
<span />
</button>
</div>
{plane.enabled ? (
<>
<label className="brush-radius">
<span>Normal tolerance</span>
<NumericInput
label="Brush plane angle tolerance"
value={plane.angle}
min={0}
max={90}
onCommit={(angle) => useEditor.getState().setBrush({ plane: { angle } })}
/>
<small>°</small>
</label>
<label className="brush-radius">
<span>Plane tolerance</span>
<NumericInput
label="Brush plane distance tolerance"
value={plane.distance}
min={0}
max={100}
step={0.1}
onCommit={(distance) => useEditor.getState().setBrush({ plane: { distance } })}
/>
<small>mm</small>
</label>
<p className="field-help">
Measured from this patch’s first hit. Clear a patch to choose a new seed plane.
</p>
</>
) : null}
</div>
) : null}
</>
);
}

function RadiusFields({
brush,
label,
draft,
onSlide,
}: {
brush: EditorBrush;
label: string;
draft?: number | null;
onSlide?: (radius: number) => void;
}) {
const radius = useEditor(brush.radius);
const range = useEditor(useShallow(brush.slider));
const set = (radius: number) => brush.setRadius(useEditor.getState(), radius);
const shown = draft ?? radius;
const slide = onSlide ?? set;
return (
<>
<label className="brush-radius">
<span>{label}</span>
<NumericInput
label={label}
value={shown}
min={brush.limits.min}
max={brush.limits.max}
step={brush.step}
onCommit={set}
/>
<small>mm</small>
</label>
{range.scale === 'linear' ? (
<input
className="brush-radius-slider"
aria-label="Brush radius slider"
type="range"
min={range.min}
max={range.max}
step={0.1}
value={Math.min(shown, range.max)}
onChange={(event) => slide(Number(event.target.value))}
/>
) : (
<LogRangeInput
className="brush-radius-slider"
label="Brush radius slider"
value={shown}
min={range.min}
max={range.max}
onChange={slide}
/>
)}
</>
);
}

function RefineRadius({ partId }: { partId: string }) {
const slider = useSliderEdit({
owned: () => useEditor.getState().refine?.partId === partId,
onSet: (value) => refineBrush.setRadius(useEditor.getState(), value),
});
return (
<div
className="refine-brush-radius"
ref={slider.row}
onPointerDown={slider.onPointerDown}
onKeyDown={slider.onKeyDown}
>
<RadiusFields
brush={refineBrush}
label="Brush radius"
draft={slider.draft}
onSlide={slider.change}
/>
</div>
);
}

/** The inspector and the viewport popup edit the same active brush. */
export function BrushSettings({ label = 'Brush radius' }: { label?: string }) {
const brush = useEditor(activeBrush);
const painting = useEditor((state) => paintingWarpRegion(state) || paintingRefine(state));
const refinePart = useEditor((state) => state.refine?.partId);
if (!brush) return null;
const fields =
brush === refineBrush && refinePart ? (
<RefineRadius key={refinePart} partId={refinePart} />
) : (
<RadiusFields brush={brush} label={label} />
);
return painting || brush === contactBrush ? (
<PaintSettings full={brush !== refineBrush}>{fields}</PaintSettings>
) : (
fields
);
}
12 changes: 3 additions & 9 deletions src/components/CameraNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { OrbitControls } from '@react-three/drei';
import type { OrbitControls as OrbitControlsImpl } from 'three-stdlib';
import { MOUSE, Quaternion, TOUCH, Vector3 } from 'three';
import { ArrowDown, ArrowLeft, ArrowRight, ArrowUp, Crosshair, Hand, Orbit, X } from 'lucide-react';
import { activeBrush } from '../core/editor-brush';
import { sceneBounds } from '../core/geometry';
import { hasAlignmentView, partDisplay } from '../core/alignment-visibility';
import {
Expand All @@ -15,7 +16,7 @@ import {
viewDirections,
} from '../core/navigation';
import type { CameraDirection, CameraStep } from '../core/navigation';
import { brushingRefine, paintingRefine, paintingWarpRegion, useEditor } from '../core/store';
import { useEditor } from '../core/store';
import { usePreferences, useShortcut, withShortcut } from '../core/preferences';
import { clampPendingZoom, wheelZoom, zoomGlideStep } from '../core/zoom';
import { IconButton } from './ui';
Expand All @@ -30,14 +31,7 @@ const drawnSelection = (state: Editor) =>
const initialOrbitTarget: [number, number, number] = [0, 54, 0];
/** Whether a left drag paints with a surface brush rather than moving the camera. */
const brushOwnsLeftDrag = (state: Editor) =>
((state.tool === 'align' && state.operation.mode === 'surface') ||
state.tool === 'sculpt' ||
paintingWarpRegion(state) ||
paintingRefine(state) ||
brushingRefine(state)) &&
!state.navigationMode &&
!state.temporaryOrbit &&
!state.pivotPicking;
!!activeBrush(state) && !state.navigationMode && !state.temporaryOrbit && !state.pivotPicking;

export function CameraRig() {
const freeTransform = useEditor((state) => !!state.freeTransform);
Expand Down
11 changes: 7 additions & 4 deletions src/components/EditorContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ import {
Trash2,
UnlockKeyhole,
} from 'lucide-react';
import { contactBrush, activeBrush } from '../core/editor-brush';
import { editorCommands, executeEditorCommand } from '../core/commands';
import type { CommandContext, CommandId } from '../core/commands';
import { useEditor } from '../core/store';
import type { EditorContextMenu as MenuLocation } from '../core/store';
import { SurfaceBrushControls } from './SurfaceBrushControls';
import { BrushSettings } from './BrushSettings';

const icons = {
copy: Copy,
Expand Down Expand Up @@ -77,6 +78,8 @@ function OpenContextMenu({
}) {
const state = useEditor();
const brush = location.kind === 'brush';
const brushTitle =
activeBrush(state) === contactBrush ? 'Paint brush settings' : 'Brush settings';
const menu = useRef<HTMLDivElement>(null);
const previousFocus = useRef(document.activeElement as HTMLElement | null);
const typeahead = useRef({ query: '', time: 0 });
Expand Down Expand Up @@ -181,7 +184,7 @@ function OpenContextMenu({
ref={menu}
className={`editor-context-menu ${brush ? 'brush-context-menu' : ''}`}
role={brush ? 'dialog' : 'menu'}
aria-label={brush ? 'Paint brush settings' : 'Component actions'}
aria-label={brush ? brushTitle : 'Component actions'}
tabIndex={-1}
style={position}
onContextMenu={(event) => event.preventDefault()}
Expand Down Expand Up @@ -258,10 +261,10 @@ function OpenContextMenu({
{brush ? (
<>
<div className="context-heading">
<span>Paint brush settings</span>
<span>{brushTitle}</span>
<small>Right-click to adjust · Right-drag to pan</small>
</div>
<SurfaceBrushControls />
<BrushSettings />
<button className="button secondary full-width" onClick={() => close(true)}>
Done
</button>
Expand Down
Loading
Loading