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
8 changes: 7 additions & 1 deletion docs/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,13 @@ top of the viewport, with Studio as the default. Smaller screens use collapsible
- Offer a Refine tool (E) that rebuilds softened edges on a scanned part from
line, arc and spline guides, treats painted regions (smooth, flatten or snap
to a shape) while keeping detail, offers crease, flatten and smooth brushes,
and proposes guides and regions for review. Apply bakes the result as one
proposes guides and regions for review, and cleans the whole part or a
painted area at once: bilateral normal filtering removes noise, an unsharp
mask on the normals narrows softened edges, edge flips line triangles up with
the edges it sharpens, an unsharp mask along the normal deepens relief up
to a set size, and Square rebuilds roundings between faces at about 90
degrees, outside and inside, as sharp corners cut into the mesh. Apply bakes
the result as one
undo step without modifying pins, anchors, joints, or any other part. Cancel
discards it.
- Paint only edge-connected mesh patches; optional fixed seed-plane angle and
Expand Down
2 changes: 2 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,8 @@ function refineHints(mode: RefineMode | 'building', smaller: string, larger: str
return `Drag across the surface.${smaller && larger ? ` ${smaller} and ${larger} change the brush size.` : ''}`;
case 'detect':
return 'Find edges and surfaces, then accept the proposals you want.';
case 'clean':
return 'Clean the whole part, or paint the area to clean. Undo steps back.';
}
}

Expand Down
130 changes: 123 additions & 7 deletions src/components/RefineControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { isTaskActive, useActivity } from '../core/activity';
import type { EdgeInput, EdgePosition, EdgeSolve } from '../core/refine-edge';
import type { RegionInput, RegionSolve, RegionShape, Treatment } from '../core/refine-region';
import {
cleanTitle,
refineDraftLimit,
refineFailure,
refinePickingPrompt,
Expand All @@ -17,6 +18,8 @@ import {
} from '../core/store';
import {
autoRule,
cleanDepthMax,
cleanSizeRange,
draftSkippedHint,
endLabels,
endOption,
Expand Down Expand Up @@ -58,6 +61,7 @@ const panelView = (refine: RefineSession | null) =>
region: refine.region,
brush: refine.brush,
detect: refine.detect,
clean: refine.clean,
folds: refine.folds.length,
skipped: refine.skipped.length,
edited: refineEdited(refine),
Expand All @@ -74,15 +78,16 @@ function currentTarget() {
const ownedBy = (target: string) => () => currentTarget() === target;

/**
* A slider with a number field. A percent setting holds 0 to 1 and shows 0 to 100; a setting with
* `range` is in mm on a logarithmic slider. Unless `live`, a drag sets its value once on release;
* A slider with a number field. A percent setting holds 0 to `most` (1 unless set) and shows it as
* a percentage; a setting with `range` is in mm on a logarithmic slider. Unless `live`, a drag sets its value once on release;
* a live one gives `begin` to put the value back on Escape.
*/
function SliderSetting({
label,
value,
mixed = false,
range,
most = 1,
live = false,
begin,
owned,
Expand All @@ -92,6 +97,7 @@ function SliderSetting({
value: number;
mixed?: boolean;
range?: { min: number; max: number };
most?: number;
live?: boolean;
begin?: () => () => void;
owned: () => boolean;
Expand Down Expand Up @@ -131,7 +137,7 @@ function SliderSetting({
aria-label={`${label} slider`}
aria-valuetext={hidden ? 'Mixed' : undefined}
min={0}
max={100}
max={Math.round(most * 100)}
step={1}
value={hidden ? 0 : Math.round(shown * 100)}
onChange={(event) => slider.change(Number(event.target.value) / 100)}
Expand All @@ -142,7 +148,7 @@ function SliderSetting({
value={range ? shown : Math.round(shown * 100)}
mixed={hidden}
min={range ? range.min : 0}
max={range ? range.max : 100}
max={range ? range.max : Math.round(most * 100)}
step={range ? 0.01 : 1}
onCommit={(next) => owned() && onSet(range ? next : next / 100)}
/>
Expand Down Expand Up @@ -984,14 +990,121 @@ function DetectControls({ view, targets, owned }: ModeProps) {
);
}

function CleanControls({ view, owned }: ModeProps) {
const { clean } = view;
const model = view.model!;
const painted = useEditor((s) => (s.refine?.triangles.length ?? 0) > 0);
const task = useActivity((s) =>
s.tasks.find((task) => task.title === cleanTitle && isTaskActive(task)),
);
const set = (options: Partial<Omit<RefineSession['clean'], 'running'>>) =>
editor().setRefineClean(options);
const idle = !clean.smooth && !clean.sharpen && !clean.depth && !clean.square;
return (
<>
<p className="anchor-help">
Removes scan noise, crisps edges and deepens detail, as sharpening does for a photo. Square
rebuilds rounded edges between faces at about 90° as sharp corners.
</p>
<Choice
label="Area"
value={clean.where}
options={[
{ id: 'part', label: 'Whole part' },
{ id: 'painted', label: 'Painted area' },
]}
onChange={(where) => set({ where })}
/>
{clean.where === 'painted' ? <PaintControls /> : null}
<SliderSetting
label="Smooth"
value={clean.smooth}
owned={owned}
onSet={(smooth) => set({ smooth })}
/>
<SliderSetting
label="Sharpen"
value={clean.sharpen}
owned={owned}
onSet={(sharpen) => set({ sharpen })}
/>
<SliderSetting
label="Depth"
value={clean.depth}
most={cleanDepthMax}
owned={owned}
onSet={(depth) => set({ depth })}
/>
<SliderSetting
label="Square"
value={clean.square}
owned={owned}
onSet={(square) => set({ square })}
/>
<AutoSetting
label="Size"
values={[clean.size]}
seed={() => {
const start = manualStart(autoRule('size', model), cleanSizeRange);
set({ size: start.value });
return start.adjusted;
}}
onSet={(size) => set({ size })}
>
{(size, mixed, setSize) => (
<SliderSetting
label="Size"
value={size}
mixed={mixed}
range={cleanSizeRange}
owned={owned}
onSet={setSize}
/>
)}
</AutoSetting>
{clean.running ? (
<>
<div className="job-inline-progress" role="status">
<p>
{cleanTitle}
{task?.progress != null ? ` · ${Math.round(task.progress * 100)}%` : ''}
</p>
<progress aria-label="Clean progress" max={1} value={task?.progress ?? undefined} />
</div>
<button
className="button secondary full-width refine-spaced"
onClick={() => editor().cancelRefineClean()}
>
Cancel
</button>
</>
) : (
<button
className="button primary full-width refine-spaced"
disabled={idle || (clean.where === 'painted' && !painted)}
onClick={() => void editor().cleanRefine()}
>
Clean surface
</button>
)}
</>
);
}

/** Ends the session without a notice and leaves the tool. */
function cancel() {
const state = editor();
state.cancelRefine();
state.setTool('select');
}

const modeTitles = { edge: 'Edge', region: 'Region', brush: 'Brush', detect: 'Detect' } as const;
const modeTitles = {
edge: 'Edge',
region: 'Region',
brush: 'Brush',
detect: 'Detect',
clean: 'Clean',
} as const;

export function RefineControls() {
const view = useEditor(useShallow((s) => panelView(s.refine)));
Expand Down Expand Up @@ -1045,6 +1158,7 @@ export function RefineControls() {
{ id: 'region', label: 'Region' },
{ id: 'brush', label: 'Brush' },
{ id: 'detect', label: 'Detect' },
{ id: 'clean', label: 'Clean' },
]}
onChange={(mode) => editor().setRefineMode(mode)}
/>
Expand All @@ -1059,8 +1173,10 @@ export function RefineControls() {
<RegionControls key={target} {...props} />
) : view.mode === 'brush' ? (
<BrushControls key={target} {...props} />
) : (
) : view.mode === 'detect' ? (
<DetectControls key={target} {...props} />
) : (
<CleanControls key={target} {...props} />
)}
</Section>
)}
Expand Down Expand Up @@ -1100,7 +1216,7 @@ export function RefineControls() {
? `Unlock ${part.name} to apply the refinement.`
: view.edited
? undefined
: 'Accept a feature or make a stroke first.'
: 'Accept a feature, make a stroke or clean the surface first.'
}
onClick={() => editor().applyRefine()}
>
Expand Down
4 changes: 3 additions & 1 deletion src/components/RefinePointer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1233,7 +1233,9 @@ export function RefinePointerController({ pressed }: { pressed: () => boolean })
after.redo !== before.redo ||
after.selected.length !== before.selected.length ||
after.selected.some((id, i) => id !== before.selected[i]) ||
(d.kind === 'paint' && after.detect.where !== before.detect.where)
(d.kind === 'paint' &&
(after.detect.where !== before.detect.where ||
after.clean.where !== before.clean.where))
)
return discard();
}
Expand Down
8 changes: 7 additions & 1 deletion src/components/refine-panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ export const endOption = (chosen: EdgeEnd | undefined) =>
* where a setting taken off Auto starts when no solve says what it used.
*/
export function autoRule(
setting: 'width' | 'scale' | 'detail' | 'blend',
setting: 'width' | 'scale' | 'detail' | 'blend' | 'size',
model: Pick<RefineModel, 'noise' | 'step'>,
) {
switch (setting) {
case 'size':
return 8 * model.step;
case 'width':
return Math.min(1, 6 * model.step);
case 'scale':
Expand All @@ -50,6 +52,10 @@ export function autoRule(
}
}

/** Clean's largest Depth, and the range of its Size in mm, as refine-clean holds them. */
export const cleanDepthMax = 3;
export const cleanSizeRange = { min: 0.05, max: 5 };

/** A setting's first manual value: `start` held to the control's range, and whether that moved it. */
export function manualStart(start: number, range: { min: number; max: number }) {
const value = Math.min(range.max, Math.max(range.min, start));
Expand Down
Loading
Loading