"use client"; import { ChangeEvent, ReactNode, forwardRef, useContext, useImperativeHandle, useRef, useState, } from "react"; import { SceneViewContext, SceneViewContextType, } from "../providers/scene-view-provider"; import { Mesh } from "three"; import { CustomEvent } from "../three/SceneView"; import { RangeSlider } from "./RangeSlider"; import { MeshStandardNodeMaterial } from "three/webgpu"; function Toggle({ title, onChange, defaultChecked, disabled = false, }: { title: string; onChange: (e: ChangeEvent) => void; defaultChecked?: boolean; disabled?: boolean; }) { return ( ); } enum Position { Start, Center, End, } interface AccordionRef { open: (b: boolean) => void; } interface AccordionProps { title: string; position: Position; open: boolean; children: ReactNode; } const Accordion = forwardRef( ({ children, title, position, open }, ref) => { const [expanded, setExpanded] = useState(open); const accordionBodyRef = useRef(null); useImperativeHandle(ref, () => ({ open: (b: boolean) => setExpanded(b), })); function handleClick() { if (!accordionBodyRef.current) return; setExpanded(!expanded); } const className = position === Position.Center ? "flex items-center justify-between w-full p-5 font-medium rtl:text-right text-gray-500 border border-b border-gray-200 dark:border-gray-400 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-800 gap-3 hover:cursor-pointer" : "flex items-center justify-between w-full p-5 font-medium rtl:text-right text-gray-500 border border-b border-gray-200 rounded-t dark:border-gray-400 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-800 gap-3 hover:cursor-pointer"; return (

{children}
); } ); Accordion.displayName = "Accordion"; export function Form() { const svgContainerRef = useRef(null); const accordionRef1 = useRef(null); const accordionRef0 = useRef(null); const [emptyProfile, setEmptyProfile] = useState(false); const { sceneView } = useContext(SceneViewContext) as SceneViewContextType; function handleChangeSlicingBox(e: ChangeEvent) { if (!sceneView) return; if (e.target.checked) { sceneView.toggleClippingBox(true); } else { sceneView.toggleClippingBox(false); } } function handleChangeCG() { if (!sceneView) return; sceneView.toggleCoordinateGrid(); } function handleChangeWireframe() { if (!sceneView) return; sceneView.toggleWireFrame(); } function handleCheckboxChange(name: string) { if (!sceneView) return; sceneView.toggleLayerVisibility(name); } function handleChangeTopography() { if (!sceneView) return; sceneView.toggleLayerVisibility("Topography"); } function handleDrilling(e: ChangeEvent) { if (!sceneView) return; if ((e.target as HTMLInputElement).checked) { // Enable raycaster with callback to handle svg element sceneView.enableRaycaster(handleSVGCreated); } else { sceneView.disableRaycaster(); } } function handleSVGCreated(e: CustomEvent) { if ( !svgContainerRef.current || !accordionRef0.current || !accordionRef1.current ) return; while (svgContainerRef.current.children.length > 0) { const c = svgContainerRef.current.children[0]; svgContainerRef.current.removeChild(c); } if (e.detail && e.detail.element) { setEmptyProfile(false); svgContainerRef.current.appendChild(e.detail.element); accordionRef0.current.open(false); accordionRef1.current.open(true); } else { setEmptyProfile(true); accordionRef0.current.open(false); accordionRef1.current.open(true); } } function handleExport() { if (!sceneView) return; sceneView.exportOBJ(); } function handleExplode(e: ChangeEvent) { if (!sceneView) return; if (e.target.checked) { sceneView.explode(true); } else { sceneView.explode(false); } } return (
{
{sceneView?.model.children .filter((c) => c.name !== "Topography") .map((child) => { const key = `toggle-visibility-${child.name}`; let color = "transparent"; if ( (child as Mesh).material instanceof MeshStandardNodeMaterial ) { color = `#${( (child as Mesh).material as MeshStandardNodeMaterial ).color.getHexString()}`; } const visible = (child as Mesh).visible; return (
handleCheckboxChange(child.name)} className="hover:cursor-pointer" defaultChecked={visible ? true : false} />
); })}
}
{emptyProfile ? (
Virtual profile does not intersect the model.
) : null}
Please enable the Virtual Profile toggle and select a profile position!
); }