A lightweight Clip Studio Paint alternative with real-time multiplayer collaborative drawing. Built with Tauri and React.
TypeScript animationcartoonclip-studio-paintcollaborativedesktop-appdigital-paintingdrawing-appillustrationmangamultiplayeropen-sourcerusttaurithreejswebglwebtoon
import React, { useState, useEffect } from 'react';
import {
Box,
Upload,
Magnet,
RotateCcw,
Lock,
Unlock,
Layers,
CopyPlus,
Eye,
EyeOff,
Compass,
} from 'lucide-react';
import {
Camera3DPreset,
Gizmo3DMode,
Shading3DMode,
TOOL_3D_BEHAVIOR_RULES,
Tool3DMode,
} from '../utils/tool3DRules';
import { PosePresetName } from '../utils/mannequin3D';
import { PRIMITIVE_3D_ITEMS } from '../utils/primitives3D';
import { LightSourceWidget } from './LightSourceWidget';
import { Primitive3DIcon } from './Primitive3DIcon';
import {
scene3DBridge,
selectHasOpenDocument,
store3DActions,
uiStoreActions,
use3DStore,
useDocumentStore,
useUiStore,
} from '../stores';
import { isImeComposing, useI18n } from '../i18n';
type Inspector3DTab = 'transform' | 'light' | 'scene' | 'pose';
interface NumericAxisRowProps {
label: string;
values: [number, number, number];
step: number;
suffix?: string;
onChangeAxis: (axisIdx: 0 | 1 | 2, value: number) => void;
}
const AXIS_LABELS = ['X', 'Y', 'Z'] as const;
const AXIS_COLORS = ['text-red-400', 'text-emerald-400', 'text-sky-400'] as const;
const NumericAxisRow: React.FC<NumericAxisRowProps> = ({
label,
values,
step,
suffix = '',
onChangeAxis,
}) => (
<div className="space-y-1">
<div className="flex items-center justify-between text-[10px] text-ui-muted">
<span>{label}</span>
{suffix && <span className="font-ui-mono text-[9px] text-ui-muted">{suffix}</span>}
</div>
<div className="grid grid-cols-3 gap-1">
{([0, 1, 2] as const).map((idx) => (
<label
key={AXIS_LABELS[idx]}
className="flex items-center bg-ui-input border border-ui-subtle rounded-ui-xs px-1 py-0.5 gap-0.5 focus-within:border-ui-focus"
>
<span className={`text-[9px] font-ui-mono font-semibold ${AXIS_COLORS[idx]}`}>
{AXIS_LABELS[idx]}
</span>
<input
type="number"
step={step}
value={Number.isFinite(values[idx]) ? values[idx] : 0}
onChange={(e) => {
const parsed = parseFloat(e.target.value);
if (Number.isFinite(parsed)) {
onChangeAxis(idx, parsed);
}
}}
onKeyDown={(e) => {
e.stopPropagation();
if (isImeComposing(e)) return;
}}
className="w-full min-w-0 bg-transparent text-[10px] font-ui-mono tabular-nums text-ui-primary outline-none text-right"
/>
</label>
))}
</div>
</div>
);
export const Tool3DPropertyInspector: React.FC = () => {
const { t, tc, td } = useI18n();
const hasOpenDocument = useDocumentStore(selectHasOpenDocument);
const is3DLayerOpen = useUiStore((s) => s.is3DLayerOpen);
const activeMode = use3DStore((s) => s.activeMode);
const gizmoMode = use3DStore((s) => s.gizmoMode);
const gizmoSpace = use3DStore((s) => s.gizmoSpace);
const snapEnabled = use3DStore((s) => s.snapEnabled);
const isReferenceVisible = use3DStore((s) => s.isReferenceVisible);
const loadedModelName = use3DStore((s) => s.loadedModelName);
const modelKind = use3DStore((s) => s.modelKind);
const activePrimitiveType = use3DStore((s) => s.activePrimitiveType);
const isMannequinActive = use3DStore((s) => s.isMannequinActive);
const activeIKHandle = use3DStore((s) => s.activeIKHandle);
const showIKHandles = use3DStore((s) => s.showIKHandles);
const isBaking = use3DStore((s) => s.isBaking);
const modelTransform = use3DStore((s) => s.modelTransform);
const lighting = use3DStore((s) => s.lighting);
const shadingMode = use3DStore((s) => s.shadingMode);
const materialRoughness = use3DStore((s) => s.materialRoughness);
const toonOutline = use3DStore((s) => s.toonOutline);
const opacity = use3DStore((s) => s.opacity);
const showGrid = use3DStore((s) => s.showGrid);
const perspective = use3DStore((s) => s.perspective);
const fov = use3DStore((s) => s.fov);
const syncCameraPerspective = use3DStore((s) => s.syncCameraPerspective);
const [activeTab, setActiveTab] = useState<Inspector3DTab>('transform');
const [showRules, setShowRules] = useState(false);
// If mannequin becomes inactive while on Pose tab, return cleanly to Edit tab
useEffect(() => {
if (!isMannequinActive && activeTab === 'pose') {
setActiveTab('transform');
}
}, [isMannequinActive, activeTab]);
const hasModel = Boolean(loadedModelName);
if (!hasOpenDocument) {
return (
<div className="p-2.5 space-y-2 overflow-y-auto flex-1">
<div className="text-[11px] font-medium text-ui-primary">{t('3D Studio Tool')}</div>
<p className="text-[10px] text-ui-muted leading-relaxed">
{t('Open or create a canvas document to use the 3D reference stage.')}
</p>
</div>
);
}
if (!is3DLayerOpen) {
return (
<div className="p-2.5 space-y-2.5 overflow-y-auto flex-1">
<div className="text-[11px] font-medium text-ui-primary">{t('3D Studio Tool')}</div>
<p className="text-[10px] text-ui-muted leading-relaxed">
{t('Open the 3D reference stage to create primitives or drop .glb / .gltf / .obj models directly onto the canvas.')}
</p>
<button
type="button"
onClick={() => uiStoreActions.set3DLayerOpen(true)}
className="w-full py-1.5 rounded-ui-sm bg-ui-accent text-ui-accent-contrast text-[11px] font-medium hover:opacity-90 transition-opacity cursor-pointer"
>
{t('Open 3D Stage')}
</button>
</div>
);
}
const updatePosAxis = (idx: 0 | 1 | 2, val: number) => {
const nextPos: [number, number, number] = [...modelTransform.position];
nextPos[idx] = val;
scene3DBridge.applyNumericTransform?.({ ...modelTransform, position: nextPos });
};
const updateRotAxis = (idx: 0 | 1 | 2, val: number) => {
const nextRot: [number, number, number] = [...modelTransform.rotation];
nextRot[idx] = val;
scene3DBridge.applyNumericTransform?.({ ...modelTransform, rotation: nextRot });
};
const updateScaleAxis = (idx: 0 | 1 | 2, pctVal: number) => {
const mult = Math.max(0.05, Math.min(10, pctVal / 100));
const nextScale: [number, number, number] = modelTransform.uniformScale
? [mult, mult, mult]
: ([
idx === 0 ? mult : modelTransform.scale[0],
idx === 1 ? mult : modelTransform.scale[1],
idx === 2 ? mult : modelTransform.scale[2],
] as [number, number, number]);
scene3DBridge.applyNumericTransform?.({ ...modelTransform, scale: nextScale });
};
const uniformScalePct = Math.round(modelTransform.scale[0] * 100);
const tabs: Array<[Inspector3DTab, string]> = [
['transform', t('Edit')],
['light', tc('3d', 'Light')],
['scene', t('View')],
...(isMannequinActive ? ([['pose', t('Pose')]] as Array<[Inspector3DTab, string]>) : []),
];
return (
<div
data-drop-zone="3d-stage"
className="flex flex-col flex-1 min-h-0 overflow-hidden text-ui-primary"
>
{/* Header + Quick Model Source Actions */}
<div className="px-2 pt-2 pb-1.5 border-b border-ui-subtle space-y-1.5 shrink-0">
<div className="flex items-center justify-between gap-1">
<div className="flex items-center gap-1 min-w-0">
<Box className="w-3.5 h-3.5 text-ui-accent shrink-0" />
<span className="text-[11px] font-medium truncate">
{loadedModelName ? td(loadedModelName) : t('3D Studio')}
</span>
</div>
<button
type="button"
onClick={() => store3DActions.toggleReferenceVisible()}
title={isReferenceVisible ? t('Hide 3D Reference') : t('Show 3D Reference')}
className="p-1 rounded-ui-xs text-ui-icon-muted hover:text-ui-primary hover:bg-ui-control-hover transition-colors cursor-pointer shrink-0"
>
{isReferenceVisible ? <Eye className="w-3 h-3" /> : <EyeOff className="w-3 h-3" />}
</button>
</div>
<button
type="button"
onClick={() => scene3DBridge.triggerFilePicker?.()}
title={t('Click to browse or drag & drop .glb, .gltf, or .obj onto canvas')}
className="w-full flex items-center justify-center gap-1.5 py-1 rounded-ui-sm bg-ui-input hover:bg-ui-control-hover border border-ui-subtle text-[10px] text-ui-secondary hover:text-ui-primary transition-colors cursor-pointer"
>
<Upload className="w-3 h-3 text-ui-accent" />
<span>{t('Import 3D Model (.glb / .obj)')}</span>
</button>
{/* Quick 3D Primitives */}
<div className="space-y-1">
<span className="text-[9px] uppercase tracking-wider text-ui-muted">
{t('Primitives')}
</span>
<div className="grid grid-cols-5 gap-0.5">
{PRIMITIVE_3D_ITEMS.map((item) => {
const isSelected = modelKind === 'primitive' && activePrimitiveType === item.type;
return (
<button
key={item.type}
type="button"
onClick={() => scene3DBridge.createPrimitive?.(item.type)}
title={td(item.description)}
data-testid={`inspector-3d-primitive-${item.type}`}
className={`flex flex-col items-center justify-center gap-0.5 py-1 px-0.5 rounded-ui-xs border text-[8.5px] leading-tight transition-colors cursor-pointer ${
isSelected
? 'bg-ui-accent text-ui-accent-contrast border-transparent font-medium'
: 'bg-ui-input hover:bg-ui-control-hover border-ui-subtle text-ui-secondary hover:text-ui-primary'
}`}
>
<Primitive3DIcon type={item.type} className="w-3.5 h-3.5 shrink-0" />
<span className="truncate max-w-full">{td(item.label)}</span>
</button>
);
})}
</div>
</div>
{/* Inspector Section Tabs */}
<div
className={`grid gap-0.5 bg-ui-input border border-ui-subtle p-0.5 rounded-ui-sm ${
tabs.length === 4 ? 'grid-cols-4' : 'grid-cols-3'
}`}
>
{tabs.map(([tabId, label]) => (
<button
key={tabId}
type="button"
onClick={() => setActiveTab(tabId)}
className={`py-1 rounded-ui-xs text-[10px] transition-colors cursor-pointer ${
activeTab === tabId
? 'bg-ui-control-active text-ui-primary font-medium'
: 'text-ui-muted hover:text-ui-primary'
}`}
>
{label}
</button>
))}
</div>
</div>
{/* Scrollable Inspector Body */}
<div className="flex-1 overflow-y-auto p-2 space-y-3">
{activeTab === 'transform' && (
<>
{/* Canvas Drag Sub-Mode */}
<div className="space-y-1">
<span className="text-[10px] uppercase tracking-wider text-ui-muted">
{t('Canvas Tool Mode')}
</span>
<div className="grid grid-cols-2 gap-1">
{(
[
['smart', 'Smart (Auto)'],
['model-rotate', 'Free Rotate'],
['model-rotate-yaw', 'Turn Y-Axis'],
['model-rotate-roll', 'Screen Roll'],
['model-move', 'Move Plane'],
['model-plane-move', 'Slide Floor'],
['model-scale', 'Scale Drag'],
['camera-orbit', 'Cam Orbit'],
] as Array<[Tool3DMode, string]>
).map(([mode, label]) => (
<button
key={mode}
type="button"
onClick={() => store3DActions.setActiveMode(mode)}
className={`py-1 px-1.5 rounded-ui-xs text-[10px] text-left truncate transition-colors cursor-pointer border ${
activeMode === mode
? 'bg-ui-accent text-ui-accent-contrast border-transparent font-medium'
: 'bg-ui-input border-ui-subtle text-ui-secondary hover:text-ui-primary hover:bg-ui-control-hover'
}`}
>
{t(label)}
</button>
))}
</div>
</div>
{/* On-Canvas 3D Manipulator Gizmo */}
<div className="space-y-1.5 pt-1 border-t border-ui-subtle">
<div className="flex items-center justify-between">
<span className="text-[10px] uppercase tracking-wider text-ui-muted">
{t('On-Canvas Gizmo')}
</span>
<button
type="button"
onClick={() =>
store3DActions.setGizmoSpace(gizmoSpace === 'local' ? 'world' : 'local')
}
title={t('Toggle Local vs World Gizmo Axes')}
className="text-[9px] font-ui-mono px-1.5 py-0.5 rounded-ui-xs bg-ui-input hover:bg-ui-control-hover border border-ui-subtle text-ui-secondary hover:text-ui-primary transition-colors cursor-pointer"
>
{gizmoSpace === 'local' ? t('Local') : t('World')}
</button>
</div>
<div className="grid grid-cols-4 gap-0.5 bg-ui-input border border-ui-subtle p-0.5 rounded-ui-sm">
{(
[
['rotate', 'Rot'],
['translate', 'Pos'],
['scale', 'Scl'],
['none', 'Off'],
] as Array<[Gizmo3DMode, string]>
).map(([gm, lbl]) => (
<button
key={gm}
type="button"
onClick={() => store3DActions.setGizmoMode(gm)}
className={`py-1 rounded-ui-xs text-[10px] transition-colors cursor-pointer ${
gizmoMode === gm
? 'bg-ui-control-active text-ui-accent font-medium'
: 'text-ui-muted hover:text-ui-primary'
}`}
>
{tc('3dGizmo', lbl)}
</button>
))}
</div>
<label className="flex items-center justify-between text-[10px] text-ui-muted cursor-pointer">
<span>{t('Snap (15° / 10% · Shift)')}</span>
<input
type="checkbox"
checked={snapEnabled}
onChange={(e) => store3DActions.setSnapEnabled(e.target.checked)}
/>
</label>
</div>
{/* Live Numeric Position / Rotation / Scale */}
<div className="space-y-2.5 pt-1 border-t border-ui-subtle">
<NumericAxisRow
label={t('Position')}
values={modelTransform.position}
step={0.1}
suffix={t('units')}
onChangeAxis={updatePosAxis}
/>
<NumericAxisRow
label={t('Rotation')}
values={modelTransform.rotation}
step={5}
suffix={t('deg')}
onChangeAxis={updateRotAxis}
/>
{/* Scale with Uniform Lock */}
<div className="space-y-1">
<div className="flex items-center justify-between text-[10px]">
<span className="text-ui-muted">{t('Scale')}</span>
<div className="flex items-center gap-1">
<span className="font-ui-mono tabular-nums text-ui-primary">{uniformScalePct}%</span>
<button
type="button"
onClick={() =>
store3DActions.setModelTransform({
uniformScale: !modelTransform.uniformScale,
})
}
title={
modelTransform.uniformScale
? t('Uniform scale locked (click to unlock X/Y/Z)')
: t('Non-uniform X/Y/Z scale (click to lock)')
}
className="p-0.5 rounded-ui-xs bg-ui-input hover:bg-ui-control-hover border border-ui-subtle text-ui-secondary transition-colors cursor-pointer"
>
{modelTransform.uniformScale ? (
<Lock className="w-2.5 h-2.5 text-ui-accent" />
) : (
<Unlock className="w-2.5 h-2.5 text-ui-icon-muted" />
)}
</button>
</div>
</div>
{modelTransform.uniformScale ? (
<input
type="range"
min={15}
max={300}
step={5}
value={Math.max(15, Math.min(300, uniformScalePct))}
onChange={(e) => updateScaleAxis(0, parseFloat(e.target.value))}
className="w-full"
/>
) : (
<NumericAxisRow
label=""
values={[
Math.round(modelTransform.scale[0] * 100),
Math.round(modelTransform.scale[1] * 100),
Math.round(modelTransform.scale[2] * 100),
]}
step={5}
suffix="%"
onChangeAxis={updateScaleAxis}
/>
)}
</div>
</div>
{/* Quick Turn & Utility Buttons */}
<div className="space-y-1.5 pt-1 border-t border-ui-subtle">
<div className="grid grid-cols-3 gap-1">
{([-90, 90, 180] as const).map((deg) => (
<button
key={deg}
type="button"
disabled={!hasModel}
onClick={() => scene3DBridge.rotateModelYaw?.(deg)}
className="py-1 rounded-ui-xs bg-ui-input hover:bg-ui-control-hover border border-ui-subtle text-[10px] font-ui-mono tabular-nums text-ui-primary disabled:opacity-40 transition-colors cursor-pointer"
>
{deg > 0 ? `+${deg}°` : `${deg}°`}
</button>
))}
</div>
<div className="grid grid-cols-2 gap-1">
<button
type="button"
disabled={!hasModel}
onClick={() => scene3DBridge.snapToGround?.()}
className="flex items-center justify-center gap-1 py-1 rounded-ui-xs bg-ui-input hover:bg-ui-control-hover border border-ui-subtle text-[10px] text-ui-primary disabled:opacity-40 transition-colors cursor-pointer"
>
<Magnet className="w-3 h-3 text-ui-accent" />
<span>{t('Snap Floor')}</span>
</button>
<button
type="button"
disabled={!hasModel}
onClick={() => scene3DBridge.resetModelTransform?.()}
className="flex items-center justify-center gap-1 py-1 rounded-ui-xs bg-ui-input hover:bg-ui-control-hover border border-ui-subtle text-[10px] text-ui-muted hover:text-ui-primary disabled:opacity-40 transition-colors cursor-pointer"
>
<RotateCcw className="w-3 h-3" />
<span>{t('Reset')}</span>
</button>
</div>
</div>
</>
)}
{activeTab === 'light' && (
<>
{/* Key Light Toggle + Interactive 3D Sphere */}
<div className="space-y-1.5">
<label className="flex items-center justify-between text-[11px] text-ui-secondary cursor-pointer">
<span>{t('Key Light Enabled')}</span>
<input
type="checkbox"
checked={lighting.keyLight.enabled}
onChange={(e) => store3DActions.updateKeyLight({ enabled: e.target.checked })}
/>
</label>
<LightSourceWidget
embedded
compact
settings={{
azimuth: lighting.keyLight.azimuth,
elevation: lighting.keyLight.elevation,
intensity: lighting.keyLight.intensity,
ambientIntensity: lighting.ambientIntensity,
color: lighting.keyLight.color,
isBacklit: lighting.keyLight.isBacklit,
}}
onChange={(next) => {
store3DActions.updateKeyLight({
azimuth: next.azimuth,
elevation: next.elevation,
intensity: next.intensity,
color: next.color,
isBacklit: next.isBacklit,
});
store3DActions.updateLighting({ ambientIntensity: next.ambientIntensity });
}}
onReset={() => store3DActions.resetLighting()}
/>
</div>
{/* Secondary Light Source (Rim / Fill Light) */}
<div className="space-y-1.5 pt-2 border-t border-ui-subtle">
<div className="flex items-center justify-between">
<label className="flex items-center gap-1.5 text-[11px] text-ui-secondary cursor-pointer">
<input
type="checkbox"
checked={lighting.rimLight.enabled}
onChange={(e) => store3DActions.updateRimLight({ enabled: e.target.checked })}
/>
<span>{t('Light 2 (Rim / Fill)')}</span>
</label>
<input
type="color"
value={lighting.rimLight.color}
onChange={(e) => store3DActions.updateRimLight({ color: e.target.value })}
title={t('Rim Light Color')}
className="w-5 h-4 bg-transparent border-0 cursor-pointer p-0"
/>
</div>
{lighting.rimLight.enabled && (
<div className="space-y-1.5 bg-ui-input p-2 rounded-ui-sm border border-ui-subtle">
<div className="space-y-0.5">
<div className="flex justify-between text-[10px]">
<span className="text-ui-muted">{t('Angle')}</span>
<span className="font-ui-mono tabular-nums text-ui-primary">{lighting.rimLight.azimuth}°</span>
</div>
<input
type="range"
min={0}
max={360}
step={5}
value={lighting.rimLight.azimuth}
onChange={(e) =>
store3DActions.updateRimLight({ azimuth: parseInt(e.target.value, 10) })
}
className="w-full"
/>
</div>
<div className="space-y-0.5">
<div className="flex justify-between text-[10px]">
<span className="text-ui-muted">{t('Height')}</span>
<span className="font-ui-mono tabular-nums text-ui-primary">{lighting.rimLight.elevation}°</span>
</div>
<input
type="range"
min={-60}
max={85}
step={5}
value={lighting.rimLight.elevation}
onChange={(e) =>
store3DActions.updateRimLight({ elevation: parseInt(e.target.value, 10) })
}
className="w-full"
/>
</div>
<div className="space-y-0.5">
<div className="flex justify-between text-[10px]">
<span className="text-ui-muted">{t('Intensity')}</span>
<span className="font-ui-mono tabular-nums text-ui-primary">
{Math.round(lighting.rimLight.intensity * 100)}%
</span>
</div>
<input
type="range"
min={0}
max={2.5}
step={0.05}
value={lighting.rimLight.intensity}
onChange={(e) =>
store3DActions.updateRimLight({ intensity: parseFloat(e.target.value) })
}
className="w-full"
/>
</div>
</div>
)}
</div>
{/* Ambient Tint & Ground Shadow */}
<div className="space-y-1.5 pt-2 border-t border-ui-subtle">
<div className="flex items-center justify-between text-[10px]">
<span className="text-ui-muted">{t('Ambient Color')}</span>
<input
type="color"
value={lighting.ambientColor}
onChange={(e) => store3DActions.updateLighting({ ambientColor: e.target.value })}
className="w-5 h-4 bg-transparent border-0 cursor-pointer p-0"
/>
</div>
<label className="flex items-center justify-between text-[10px] text-ui-secondary cursor-pointer">
<span>{t('Cast Ground Shadow')}</span>
<input
type="checkbox"
checked={lighting.castGroundShadow}
onChange={(e) =>
store3DActions.updateLighting({ castGroundShadow: e.target.checked })
}
/>
</label>
{lighting.castGroundShadow && (
<div className="space-y-0.5">
<div className="flex justify-between text-[10px]">
<span className="text-ui-muted">{t('Shadow Strength')}</span>
<span className="font-ui-mono tabular-nums text-ui-primary">
{Math.round(lighting.shadowOpacity * 100)}%
</span>
</div>
<input
type="range"
min={0.05}
max={0.85}
step={0.05}
value={lighting.shadowOpacity}
onChange={(e) =>
store3DActions.updateLighting({ shadowOpacity: parseFloat(e.target.value) })
}
className="w-full"
/>
</div>
)}
</div>
</>
)}
{activeTab === 'scene' && (
<>
{/* Camera Angle Presets */}
<div className="space-y-1">
<div className="flex items-center justify-between">
<span className="text-[10px] uppercase tracking-wider text-ui-muted">
{t('Camera Angle')}
</span>
<button
type="button"
onClick={() => scene3DBridge.resetCamera?.()}
className="text-[10px] text-ui-muted hover:text-ui-primary cursor-pointer"
>
{t('Reset')}
</button>
</div>
<div className="grid grid-cols-3 gap-1">
{(
[
['front', 'Front'],
['threeQuarter', '3/4'],
['side', 'Side'],
['back', 'Back'],
['top', 'Top'],
['lowAngle', 'Low'],
] as Array<[Camera3DPreset, string]>
).map(([preset, lbl]) => (
<button
key={preset}
type="button"
onClick={() => scene3DBridge.setCameraPreset?.(preset)}
className="py-1 rounded-ui-xs bg-ui-input hover:bg-ui-control-hover border border-ui-subtle text-[10px] text-ui-secondary hover:text-ui-primary transition-colors cursor-pointer"
>
{tc('3dCam', lbl)}
</button>
))}
</div>
</div>
{/* Shading Style */}
<div className="space-y-1 pt-1 border-t border-ui-subtle">
<span className="text-[10px] uppercase tracking-wider text-ui-muted">{t('Shading')}</span>
<div className="grid grid-cols-3 gap-1">
{(
[
['shaded', 'Shaded'],
['smooth', 'Smooth'],
['toon', 'Cel / Toon'],
['wireframe', 'Wire'],
['silhouette', 'Silh'],
] as Array<[Shading3DMode, string]>
).map(([mode, lbl]) => (
<button
key={mode}
type="button"
onClick={() => store3DActions.setShadingMode(mode)}
className={`py-1 rounded-ui-xs text-[10px] border transition-colors cursor-pointer ${
shadingMode === mode
? 'bg-ui-accent text-ui-accent-contrast border-transparent font-medium'
: 'bg-ui-input border-ui-subtle text-ui-secondary hover:text-ui-primary hover:bg-ui-control-hover'
}`}
>
{tc('3dShading', lbl)}
</button>
))}
</div>
{(shadingMode === 'shaded' || shadingMode === 'smooth') && (
<div className="space-y-0.5 pt-1">
<div className="flex justify-between text-[10px]">
<span className="text-ui-muted">{t('Roughness')}</span>
<span className="font-ui-mono tabular-nums text-ui-primary">
{Math.round(materialRoughness * 100)}%
</span>
</div>
<input
type="range"
min={0.1}
max={1}
step={0.05}
value={materialRoughness}
onChange={(e) => store3DActions.setMaterialRoughness(parseFloat(e.target.value))}
className="w-full"
/>
</div>
)}
<label className="flex items-center justify-between text-[10px] text-ui-secondary pt-1 cursor-pointer">
<span>{t('Manga Outline Preview')}</span>
<input
type="checkbox"
checked={toonOutline}
onChange={(e) => store3DActions.setToonOutline(e.target.checked)}
/>
</label>
</div>
{/* Perspective & Reference Opacity */}
<div className="space-y-2 pt-1 border-t border-ui-subtle">
<div>
<div className="flex justify-between text-[10px] mb-0.5">
<span className="text-ui-muted">{t('Perspective (FOV)')}</span>
<span className="font-ui-mono tabular-nums text-ui-primary">
{perspective.toFixed(1)}x · {fov}°
</span>
</div>
<input
type="range"
min={0.3}
max={2.5}
step={0.05}
value={perspective}
onChange={(e) => scene3DBridge.applyPerspectiveDollyZoom?.(parseFloat(e.target.value))}
className="w-full"
/>
</div>
<div>
<div className="flex justify-between text-[10px] mb-0.5">
<span className="text-ui-muted">{t('Stage Opacity')}</span>
<span className="font-ui-mono tabular-nums text-ui-primary">{Math.round(opacity * 100)}%</span>
</div>
<input
type="range"
min={0.1}
max={1}
step={0.05}
value={opacity}
onChange={(e) => store3DActions.setOpacity(parseFloat(e.target.value))}
className="w-full"
/>
</div>
</div>
{/* Guides & Perspective Ruler Sync */}
<div className="space-y-1.5 pt-1 border-t border-ui-subtle">
<label className="flex items-center justify-between text-[10px] text-ui-secondary cursor-pointer">
<span>{t('Floor Grid')}</span>
<input
type="checkbox"
checked={showGrid}
onChange={(e) => store3DActions.setShowGrid(e.target.checked)}
/>
</label>
<label className="flex items-center justify-between text-[10px] text-ui-secondary cursor-pointer">
<span>{t('Live Sync Perspective Ruler')}</span>
<input
type="checkbox"
checked={syncCameraPerspective}
onChange={(e) => store3DActions.setSyncCameraPerspective(e.target.checked)}
/>
</label>
<button
type="button"
onClick={() => scene3DBridge.syncPerspectiveRulerNow?.()}
className="w-full flex items-center justify-center gap-1 py-1 rounded-ui-xs bg-ui-input hover:bg-ui-control-hover border border-ui-subtle text-[10px] text-ui-secondary hover:text-ui-primary transition-colors cursor-pointer"
>
<Compass className="w-3 h-3 text-ui-accent" />
<span>{t('Sync Ruler to Camera Now')}</span>
</button>
</div>
</>
)}
{activeTab === 'pose' && isMannequinActive && (
<>
<div className="space-y-1">
<span className="text-[10px] uppercase tracking-wider text-ui-muted">
{t('Pose Presets')}
</span>
<div className="grid grid-cols-2 gap-1">
{(
[
['standing', 'Standing'],
['action', 'Action'],
['sitting', 'Seated'],
['fists', 'Fists'],
['relaxed_palm', 'Relaxed'],
] as Array<[PosePresetName, string]>
).map(([preset, lbl]) => (
<button
key={preset}
type="button"
onClick={() => scene3DBridge.applyPosePreset?.(preset)}
className="py-1.5 px-2 rounded-ui-xs bg-ui-input hover:bg-ui-control-hover border border-ui-subtle text-[10px] text-ui-primary text-left transition-colors cursor-pointer"
>
{td(lbl)}
</button>
))}
</div>
</div>
<div className="space-y-1.5 pt-1 border-t border-ui-subtle">
<div className="flex items-center justify-between">
<span className="text-[10px] uppercase tracking-wider text-ui-muted">
{t('IK Limb Handles')}
</span>
{activeIKHandle && (
<button
type="button"
onClick={() => scene3DBridge.selectIKTarget?.(null)}
className="text-[10px] text-ui-muted hover:text-ui-primary cursor-pointer"
>
{t('Done')}
</button>
)}
</div>
<p className="text-[10px] text-ui-muted leading-snug">
{t('Click any colored joint sphere on the canvas or pick a limb below to drag it.')}
</p>
<div className="grid grid-cols-3 gap-1">
{(
[
['head', 'Head'],
['leftHand', 'L-Hand'],
['rightHand', 'R-Hand'],
['leftFoot', 'L-Foot'],
['rightFoot', 'R-Foot'],
] as const
).map(([limb, lbl]) => (
<button
key={limb}
type="button"
onClick={() =>
scene3DBridge.selectIKTarget?.(activeIKHandle === limb ? null : limb)
}
className={`py-1 px-1 rounded-ui-xs text-[10px] border transition-colors cursor-pointer ${
activeIKHandle === limb
? 'bg-ui-accent text-ui-accent-contrast border-transparent font-medium'
: 'bg-ui-input border-ui-subtle text-ui-secondary hover:text-ui-primary hover:bg-ui-control-hover'
}`}
>
{t(lbl)}
</button>
))}
</div>
<label className="flex items-center justify-between text-[10px] text-ui-secondary pt-1 cursor-pointer">
<span>{t('Show Joint Spheres')}</span>
<input
type="checkbox"
checked={showIKHandles}
onChange={(e) => store3DActions.setShowIKHandles(e.target.checked)}
/>
</label>
</div>
</>
)}
{/* Collapsible 3D Behavior Rules Reference */}
<div className="pt-1 border-t border-ui-subtle">
<button
type="button"
onClick={() => setShowRules((v) => !v)}
className="w-full flex items-center justify-between text-[10px] text-ui-muted hover:text-ui-primary py-0.5 cursor-pointer"
>
<span>{t('Controls & Rules')}</span>
<span>{showRules ? t('Hide') : t('Show')}</span>
</button>
{showRules && (
<div className="mt-1.5 space-y-1 bg-ui-input rounded-ui-xs p-1.5 border border-ui-subtle">
{TOOL_3D_BEHAVIOR_RULES.map((rule) => (
<div key={rule.gesture} className="text-[9px] leading-tight">
<span className="font-ui-mono text-ui-primary">{td(rule.gesture)}: </span>
<span className="text-ui-muted">{td(rule.action)}</span>
</div>
))}
</div>
)}
</div>
</div>
{/* Footer Bake / Stamp Actions */}
<div className="p-2 border-t border-ui-subtle bg-ui-header grid grid-cols-2 gap-1 shrink-0">
<button
type="button"
disabled={isBaking || !hasModel}
onClick={() => {
void scene3DBridge.bakeTo2D?.(false);
}}
title={t('Bake a 2D raster copy while keeping the 3D stage open')}
className="flex items-center justify-center gap-1 py-1.5 rounded-ui-sm bg-ui-control hover:bg-ui-control-hover border border-ui-subtle text-[10px] text-ui-primary disabled:opacity-40 transition-colors cursor-pointer"
>
<CopyPlus className="w-3 h-3" />
<span>{t('Stamp')}</span>
</button>
<button
type="button"
disabled={isBaking || !hasModel}
onClick={() => {
void scene3DBridge.bakeTo2D?.(true);
}}
title={t('Rasterize 3D model into a 2D Layer and close stage')}
className="flex items-center justify-center gap-1 py-1.5 rounded-ui-sm bg-ui-accent text-ui-accent-contrast hover:opacity-90 text-[10px] font-medium disabled:opacity-40 transition-opacity cursor-pointer"
>
<Layers className="w-3 h-3" />
<span>{isBaking ? t('Baking...') : t('Bake Layer')}</span>
</button>
</div>
</div>
);
};