added functions to return the node/cable clicked on all the way up to the parent

This commit is contained in:
csawatzky 2026-04-23 15:56:59 -06:00
parent 0701be2539
commit f4d1167e4d
5 changed files with 113 additions and 165 deletions

View file

@ -1,4 +1,5 @@
import { Euler, Vector3, BufferGeometry, MaterialParameters, Side } from "three";
import { ThreeEvent } from "@react-three/fiber";
export interface BaseMeshProps {
geometry: BufferGeometry;
@ -13,8 +14,9 @@ export interface BaseMeshProps {
materialType?: "standard" | "basic";
materialProps?: Partial<MaterialParameters>;
materialOverride?: React.ReactNode;
side?: Side
depthWrite?: boolean
side?: Side;
depthWrite?: boolean;
onClick?: (event: ThreeEvent<MouseEvent>) => void;
}
export default function BaseMesh(props: BaseMeshProps) {
@ -32,10 +34,12 @@ export default function BaseMesh(props: BaseMeshProps) {
materialProps,
materialOverride,
side,
depthWrite = true
depthWrite = true,
onClick,
} = props;
const isTransparent = opacity < 1;
const buildMaterial = () => {
if (materialOverride) return materialOverride;
switch (materialType) {
@ -50,7 +54,7 @@ export default function BaseMesh(props: BaseMeshProps) {
{...materialProps}
/>
);
case "standard":
default:
return (
@ -71,7 +75,7 @@ export default function BaseMesh(props: BaseMeshProps) {
return (
<group position={position} rotation={rotation}>
{/* Main surface */}
<mesh geometry={geometry}>
<mesh geometry={geometry} onClick={onClick}>
{buildMaterial()}
</mesh>