Devesh36/clear-mouse

A transparent, right-handed wireless mouse assembly with a 44×58 mm control PCB, LiPo battery, optical sensor, click buttons, scroll encoder, DPI/middle buttons, USB‑C charging, and 3D‑printed housing/mechanical hardware.

Version
0.1.5
License
unset
Stars
0

Use with the tscircuit CLI

tsci is the tscircuit CLI. Install it with npm install -g tscircuit.

tsci clone Devesh36/clear-mouse  # download the package files into ./clear-mouse
tsci add Devesh36/clear-mouse    # add it to your project as @tsci/Devesh36.clear-mouse

In a cloned or new (tsci init) project: tsci dev starts a local preview, tsci build outputs Circuit JSON, and tsci push publishes to tscircuit.com.

mechanics.tsx

import { jscad } from "tscircuit";
import type { ReactNode } from "react";
import { PixelText } from "./lettering";
export const tilt = Math.PI / 3;
export const controlOrigin = [5, 15, 36] as const;
export const mounts = [
	[-22, 41],
	[22, 41],
	[-22, -26],
	[22, -26],
];
export const controlMounts = [
	[-19, 25],
	[19, 25],
	[-19, -25],
	[19, -25],
];
const clear = {
	color: "#d9edf5",
	transparent: true,
	opacity: 0.34,
	roughness: 0.12,
};
export function ControlsPose({ children }: { children: ReactNode }) {
	return (
		<jscad.translate offset={[...controlOrigin]}>
			<jscad.rotate rotation={[0, tilt, 0]}>{children}</jscad.rotate>
		</jscad.translate>
	);
}
export function controlPoint(
	u: number,
	v: number,
	w: number,
): [number, number, number] {
	return [
		5 + u * Math.cos(tilt) + w * Math.sin(tilt),
		15 + v,
		36 - u * Math.sin(tilt) + w * Math.cos(tilt),
	];
}
export function outline(w: number, h: number, r: number, cy = 0, cx = 0) {
	return [
		[w / 2 - r, h / 2 - r],
		[-w / 2 + r, h / 2 - r],
		[-w / 2 + r, -h / 2 + r],
		[w / 2 - r, -h / 2 + r],
	].flatMap(([x, y], i) =>
		Array.from({ length: 13 }, (_, j) => {
			const a = ((i * 90 + (j * 90) / 12) * Math.PI) / 180;
			return [cx + x + r * Math.cos(a), cy + y + r * Math.sin(a)] as [
				number,
				number,
			];
		}),
	);
}
function Ring({
	z,
	w,
	h,
	r,
	x = 0,
	y = 0,
}: {
	z: number;
	w: number;
	h: number;
	r: number;
	x?: number;
	y?: number;
}) {
	return (
		<jscad.translate offset={[0, 0, z]}>
			<jscad.extrudeLinear height={0.2}>
				<jscad.polygon points={outline(w, h, r, y, x)} />
			</jscad.extrudeLinear>
		</jscad.translate>
	);
}
function Plate({
	w,
	h,
	r,
	z,
	thickness = 1,
	x = 0,
	y = 0,
}: {
	w: number;
	h: number;
	r: number;
	z: number;
	thickness?: number;
	x?: number;
	y?: number;
}) {
	return (
		<jscad.translate offset={[0, 0, z]}>
			<jscad.extrudeLinear height={thickness}>
				<jscad.polygon points={outline(w, h, r, y, x)} />
			</jscad.extrudeLinear>
		</jscad.translate>
	);
}
const bodyStations = [
	[3, 68, 106, 21, -1, -1],
	[14, 60, 99, 23, -2, -2],
	[32, 40, 85, 18, -7, -5],
	[52, 22, 62, 10, -9, -8],
	[62, 12, 38, 5, -9, -12],
	[66, 4, 14, 1.8, -9, -12],
];
function bodySection(i: number) {
	const a = Math.min(4, Math.floor(i / 4));
	const t = i / 4 - a;
	const p0 = bodyStations[Math.max(0, a - 1)],
		p1 = bodyStations[a],
		p2 = bodyStations[a + 1],
		p3 = bodyStations[Math.min(5, a + 2)];
	return p1.map(
		(v, k) =>
			0.5 *
			(2 * v +
				(-p0[k] + p2[k]) * t +
				(2 * p0[k] - 5 * v + 4 * p2[k] - p3[k]) * t * t +
				(-p0[k] + 3 * v - 3 * p2[k] + p3[k]) * t * t * t),
	);
}
function BodyHull({ inner = false }: { inner?: boolean }) {
	const d = inner ? 3.2 : 0;
	return (
		<jscad.hull>
			{Array.from({ length: 21 }, (_, i) => {
				const [z, w, h, r, x, y] = bodySection(i);
				return (
					<Ring
						key={i}
						z={z - (inner ? 1.6 : 0)}
						w={w - d}
						h={h - d}
						r={Math.min((w - d) / 2 - 0.01, Math.max(0.2, r - d / 2))}
						x={x}
						y={y}
					/>
				);
			})}
			<ControlsPose>
				<Plate
					w={51.2 - d}
					h={65.2 - d}
					r={10.6 - d / 2}
					z={inner ? 9.9 : 10.5}
				/>
			</ControlsPose>
		</jscad.hull>
	);
}
function ThumbScoop({
	expanded = false,
	extra = 0,
}: {
	expanded?: boolean;
	extra?: number;
}) {
	const d = (expanded ? 1.6 : 0) + extra;
	return (
		<jscad.hull>
			{Array.from({ length: 17 }, (_, i) => {
				const t = -0.999 + (i * 1.998) / 16;
				const f = Math.sqrt(1 - t * t);
				return (
					<jscad.translate key={i} offset={[-31, 3, 31 + (23 + d) * t]}>
						<jscad.extrudeLinear height={0.12}>
							<jscad.polygon
								points={Array.from({ length: 48 }, (_, k) => {
									const a = (k * Math.PI) / 24;
									return [
										(14 + d) * f * Math.cos(a),
										(39 + d) * f * Math.sin(a),
									] as [number, number];
								})}
							/>
						</jscad.extrudeLinear>
					</jscad.translate>
				);
			})}
		</jscad.hull>
	);
}
export function ClearCover() {
	return (
		<jscad.material {...clear}>
			<jscad.subtract>
				<jscad.union>
					<jscad.subtract>
						<BodyHull />
						<ThumbScoop />
					</jscad.subtract>
					<jscad.subtract>
						<Plate w={74.6} h={108.6} r={20.3} x={-4} z={2.8} thickness={1.2} />
						<Plate w={64} h={102} r={19} x={-1} y={-1} z={2} thickness={3} />
					</jscad.subtract>
				</jscad.union>
				<jscad.subtract>
					<BodyHull inner />
					<ThumbScoop expanded />
				</jscad.subtract>
				<jscad.cuboid size={[150, 160, 40]} center={[0, 0, -17]} />
				<ControlsPose>
					<Plate w={50.4} h={64.4} r={10.2} z={10.4} thickness={40} />
					{/* Clearance pockets for the four bezel spacers. */}
					{controlMounts.map(([u, v], i) => (
						<jscad.cylinder
							key={i}
							radius={3}
							height={12.1}
							center={[u, v, 4.55]}
						/>
					))}
				</ControlsPose>
				<jscad.roundedCuboid
					size={[13, 22, 10]}
					roundRadius={1.2}
					center={[0, 53, 1.4]}
				/>
			</jscad.subtract>
		</jscad.material>
	);
}
export function Base() {
	return (
		<jscad.material color="#35434f" roughness={0.65}>
			<jscad.union>
				<jscad.subtract>
					<jscad.translate offset={[0, 0, -6.1]}>
						<jscad.extrudeLinear height={1.3}>
							<jscad.polygon points={outline(78, 112, 22, 0, -4)} />
						</jscad.extrudeLinear>
					</jscad.translate>
					<jscad.roundedCuboid
						size={[18, 12, 8]}
						roundRadius={1}
						center={[-3.5, 0, -5]}
					/>
					<jscad.cuboid size={[10, 7, 8]} center={[-21, -5, -5]} />
					<jscad.cylinder radius={2.5} height={8} center={[18, -29, -5]} />
					{mounts.map(([x, y], i) => (
						<jscad.cylinder
							key={i}
							radius={1.2}
							height={12}
							center={[x, y, -3]}
						/>
					))}
				</jscad.subtract>
				<jscad.subtract>
					<jscad.translate offset={[0, 0, -4.8]}>
						<jscad.extrudeLinear height={7.8}>
							<jscad.polygon points={outline(78, 112, 22, 0, -4)} />
						</jscad.extrudeLinear>
					</jscad.translate>
					<jscad.translate offset={[0, 0, -5]}>
						<jscad.extrudeLinear height={10}>
							<jscad.polygon points={outline(75, 109, 20.5, 0, -4)} />
						</jscad.extrudeLinear>
					</jscad.translate>
					<jscad.roundedCuboid
						size={[13, 22, 10]}
						roundRadius={1.2}
						center={[0, 53, 1.4]}
					/>
				</jscad.subtract>
				{mounts.map(([x, y], i) => (
					<jscad.subtract key={i}>
						<jscad.cylinder radius={3.2} height={4} center={[x, y, -2.8]} />
						<jscad.cylinder radius={0.85} height={8} center={[x, y, -3]} />
					</jscad.subtract>
				))}
				{/* Broad left thumb shelf, joined to the lower shell. */}
				<jscad.hull>
					<jscad.roundedCuboid
						size={[13, 58, 2.5]}
						roundRadius={1}
						center={[-34, 0, 3]}
					/>
					<jscad.roundedCuboid
						size={[8, 43, 5]}
						roundRadius={2}
						center={[-28, -2, 5]}
					/>
				</jscad.hull>
			</jscad.union>
		</jscad.material>
	);
}
export function ThumbGrip() {
	return (
		<jscad.material color="#28323b" roughness={0.9}>
			<jscad.union>
				{Array.from({ length: 9 }, (_, i) => (
					<jscad.roundedCuboid
						key={i}
						size={[7, 1.1, 0.7]}
						roundRadius={0.3}
						center={[-35, -18 + i * 4.5, 4.6]}
					/>
				))}
			</jscad.union>
		</jscad.material>
	);
}
export function Bezel() {
	return (
		<ControlsPose>
			<jscad.material color="#b9c8d3" roughness={0.5}>
				<jscad.subtract>
					<jscad.union>
						{controlMounts.map(([u, v], i) => (
							<jscad.cylinder
								key={i}
								radius={2.7}
								height={9.8}
								center={[u, v, 5.7]}
							/>
						))}
						<Plate w={50} h={64} r={10} z={10.6} thickness={2.4} />
					</jscad.union>
					{/* Datasheet encoder body clearance under the finger panel. */}
					<jscad.cuboid size={[7, 12, 3.9]} center={[-7.825, 5, 9.95]} />
					{[-15, 15].map((u) => (
						<Plate
							key={u}
							w={17.6}
							h={35.2}
							r={4.6}
							x={u}
							y={5.3}
							z={6}
							thickness={8}
						/>
					))}
					<jscad.roundedCuboid
						size={[8, 25, 12]}
						roundRadius={2}
						center={[0, 5, 13.1]}
					/>
					{[-8.5, -13].map((v) => (
						<jscad.cuboid key={v} size={[6.8, 3.6, 10]} center={[0, v, 12.1]} />
					))}
					{controlMounts.map(([u, v], i) => (
						<jscad.cylinder
							key={`recess-${i}`}
							radius={2.2}
							height={3}
							center={[u, v, 13]}
						/>
					))}
					{controlMounts.map(([u, v], i) => (
						<jscad.cylinder
							key={i}
							radius={1.2}
							height={14}
							center={[u, v, 8]}
						/>
					))}
				</jscad.subtract>
			</jscad.material>
		</ControlsPose>
	);
}
export function ClickCap({ side }: { side: -1 | 1 }) {
	return (
		<ControlsPose>
			<jscad.material color="#f0f4f6" roughness={0.3}>
				<jscad.subtract>
					<jscad.union>
						<jscad.hull>
							<Plate
								w={16.4}
								h={34}
								r={4}
								x={side * 15}
								y={5.3}
								z={11.2}
								thickness={1.2}
							/>
							<Plate
								w={16}
								h={33.6}
								r={4}
								x={side * 15}
								y={5.3}
								z={13.1}
								thickness={0.5}
							/>
						</jscad.hull>
						<jscad.cuboid
							size={[2.5, 3, 3.65]}
							center={[side * 17, 12.7, 10.175]}
						/>
						<jscad.cuboid
							size={[7, 4.5, 0.65]}
							center={[side * 15, -13.5, 11.7]}
						/>
					</jscad.union>
					<jscad.cuboid size={[7, 12, 3.9]} center={[-7.825, 5, 9.95]} />
				</jscad.subtract>
			</jscad.material>
		</ControlsPose>
	);
}
export function Keycap({ v }: { v: number }) {
	return (
		<ControlsPose>
			<jscad.material color="#f0f4f6">
				<jscad.union>
					<jscad.roundedCuboid
						size={[6.2, 3, 1.5]}
						roundRadius={0.4}
						center={[0, v, 12.8]}
					/>
					<jscad.cuboid size={[1.5, 1.5, 9.2]} center={[0, v, 7.45]} />
					<jscad.cuboid size={[8, 3, 0.6]} center={[0, v, 10.2]} />
				</jscad.union>
			</jscad.material>
		</ControlsPose>
	);
}
export function Badge() {
	return (
		<ControlsPose>
			<jscad.colorize color="#237ce4">
				<PixelText text="tscircuit" x={-10.6} y={-23} z={13.03} pitch={0.4} />
			</jscad.colorize>
		</ControlsPose>
	);
}
export function Carrier() {
	return (
		<jscad.material color="#586b79">
			<jscad.subtract>
				<jscad.union>
					{controlMounts.map(([u, v], i) => {
						const b = controlPoint(u, v, -3);
						const a: [number, number, number] = [
							u < 0 ? -22 : 22,
							v > 0 ? 41 : -26,
							4,
						];
						return (
							<jscad.union key={i}>
								<jscad.hull>
									<jscad.cylinder radius={2.5} height={3} center={a} />
									<jscad.translate offset={b}>
										<jscad.rotate rotation={[0, tilt, 0]}>
											<jscad.cylinder radius={2.5} height={3} />
										</jscad.rotate>
									</jscad.translate>
								</jscad.hull>
								<ControlsPose>
									<jscad.subtract>
										<jscad.cylinder radius={3} height={4} center={[u, v, -3]} />
										<jscad.cylinder
											radius={0.85}
											height={8}
											center={[u, v, -3]}
										/>
									</jscad.subtract>
								</ControlsPose>
							</jscad.union>
						);
					})}
					{mounts.map(([x, y], i) => (
						<jscad.subtract key={i}>
							<jscad.cylinder radius={3} height={5.5} center={[x, y, 3.55]} />
							<jscad.cylinder radius={1.1} height={8} center={[x, y, 4]} />
						</jscad.subtract>
					))}
				</jscad.union>
				<ControlsPose>
					{controlMounts.map(([u, v], i) => (
						<jscad.cylinder
							key={i}
							radius={0.85}
							height={12}
							center={[u, v, -4]}
						/>
					))}
				</ControlsPose>
				{mounts.map(([x, y], i) => (
					<jscad.cylinder key={i} radius={1.1} height={12} center={[x, y, 3]} />
				))}
			</jscad.subtract>
		</jscad.material>
	);
}
export function Tray() {
	return (
		<jscad.material color="#627582">
			<jscad.subtract>
				<jscad.union>
					<jscad.roundedCuboid
						size={[16, 36, 1.4]}
						roundRadius={0.6}
						center={[0, -5, 8.5]}
					/>
					{[-7.5, 7.5].map((x) => (
						<jscad.cuboid
							key={x}
							size={[1.3, 36, 3.8]}
							center={[x, -5, 10.5]}
						/>
					))}
					{mounts.map(([x, y], i) => (
						<jscad.hull key={i}>
							<jscad.cuboid size={[4, 4, 1.4]} center={[x, y, 7]} />
							<jscad.cuboid
								size={[3, 4, 1.4]}
								center={[x < 0 ? -7 : 7, y > 0 ? 10 : -22, 8.5]}
							/>
						</jscad.hull>
					))}
					{/* Hold-down bosses act through soft pads on the sensor's top casing. */}
					{[-4, 4].map((x) => (
						<jscad.cuboid key={x} size={[2, 3, 4.6]} center={[x, 0, 5.5]} />
					))}
				</jscad.union>
				{mounts.map(([x, y], i) => (
					<jscad.cylinder key={i} radius={1.2} height={12} center={[x, y, 6]} />
				))}
			</jscad.subtract>
		</jscad.material>
	);
}
export function Fasteners() {
	return (
		<jscad.material color="#b5bec2" metalness={0.7}>
			<jscad.union>
				{mounts.map(([x, y], i) => (
					<jscad.union key={i}>
						<jscad.cylinder radius={1} height={12} center={[x, y, 1.7]} />
						<jscad.cylinder radius={2} height={1.2} center={[x, y, 8.3]} />
					</jscad.union>
				))}
				<ControlsPose>
					{controlMounts.map(([u, v], i) => (
						<jscad.union key={i}>
							<jscad.cylinder radius={1} height={16} center={[u, v, 3.5]} />
							<jscad.cylinder radius={2} height={1.2} center={[u, v, 12.1]} />
						</jscad.union>
					))}
				</ControlsPose>
			</jscad.union>
		</jscad.material>
	);
}
export function Wire({
	points,
	color,
}: {
	points: [number, number, number][];
	color: string;
}) {
	return (
		<jscad.material color={color}>
			<jscad.union>
				{points.slice(1).map((b, i) => (
					<jscad.hull key={i}>
						<jscad.sphere radius={0.4} center={points[i]} segments={8} />
						<jscad.sphere radius={0.4} center={b} segments={8} />
					</jscad.hull>
				))}
			</jscad.union>
		</jscad.material>
	);
}
export function ControlHarness({ index: i }: { index: number }) {
	const colors = [
		"#30383d",
		"#d0524e",
		"#e6ae47",
		"#389a7d",
		"#4684cb",
		"#8e70bb",
		"#ddddc7",
	];
	return (
		<Wire
			color={colors[i]}
			points={[
				[6 - i * 2, 35, 3.8],
				[10 - i * 0.8, 39, 12],
				[13 - i * 0.8, 22, 22],
				[12 - i * 0.7, -7, 28],
				controlPoint(-6 + i * 2, -28, 3.8),
			]}
		/>
	);
}

export function ThumbSaddle() {
	return (
		<jscad.material color="#33434e" roughness={0.95}>
			<jscad.subtract>
				<ThumbScoop />
				<ThumbScoop extra={-0.8} />
				<jscad.cuboid size={[80, 150, 150]} center={[-67, 0, 30]} />
				<jscad.cuboid size={[150, 150, 80]} center={[0, 0, 83]} />
				<jscad.cuboid size={[150, 150, 80]} center={[0, 0, -24]} />
				<jscad.cuboid size={[150, 80, 150]} center={[0, 60, 30]} />
				<jscad.cuboid size={[150, 80, 150]} center={[0, -58, 30]} />
			</jscad.subtract>
		</jscad.material>
	);
}

// Removable port trim, in front of the receptacle mouth at Y=50.60mm.
// The 11.8 x 7mm opening admits a slim USB-C plug; check the chosen cable overmold.
export function UsbSurround() {
	return (
		<jscad.material color="#35434f" roughness={0.6}>
			<jscad.translate offset={[0, 55.7, 1.4]}>
				<jscad.rotate rotation={[Math.PI / 2, 0, 0]}>
					<jscad.subtract>
						<Plate w={13} h={9} r={2} z={0} thickness={4.8} />
						<Plate w={11.8} h={7} r={1.8} z={-0.1} thickness={5} />
					</jscad.subtract>
				</jscad.rotate>
			</jscad.translate>
		</jscad.material>
	);
}