Start working on UI
This commit is contained in:
parent
07208177fd
commit
8227b4141a
16 changed files with 701 additions and 581 deletions
84
app/components/Form.tsx
Normal file
84
app/components/Form.tsx
Normal file
|
@ -0,0 +1,84 @@
|
|||
"use client";
|
||||
|
||||
import {
|
||||
Accordion,
|
||||
Button,
|
||||
Checkbox,
|
||||
Label,
|
||||
TextInput,
|
||||
ToggleSwitch,
|
||||
} from "flowbite-react";
|
||||
import { useContext, useState } from "react";
|
||||
|
||||
import {
|
||||
MapSceneContext,
|
||||
MapSceneContextType,
|
||||
} from "../providers/map-scene-provider";
|
||||
import { Mesh, MeshStandardMaterial } from "three";
|
||||
|
||||
export function Form() {
|
||||
const [enabled, setEnabled] = useState<boolean>(true);
|
||||
const { mapScene } = useContext(MapSceneContext) as MapSceneContextType;
|
||||
|
||||
function handleChange() {
|
||||
if (!mapScene) return;
|
||||
|
||||
mapScene.toggleClippingBox();
|
||||
setEnabled(!enabled);
|
||||
}
|
||||
|
||||
function handleCheckboxChange(name: string) {
|
||||
if (!mapScene) return;
|
||||
|
||||
const mesh = mapScene.model.getObjectByName(name);
|
||||
if (mesh) {
|
||||
mesh.visible = !mesh.visible;
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="w-full flex flex-col gap-2 overflow-y-auto">
|
||||
<div className="w-full flex flex-col gap-3 p-4 border border-gray-200 rounded shadow">
|
||||
<ToggleSwitch
|
||||
checked={enabled}
|
||||
label="Toggle Slicing Box"
|
||||
onChange={handleChange}
|
||||
/>
|
||||
<Accordion>
|
||||
<Accordion.Panel>
|
||||
<Accordion.Title>Layers</Accordion.Title>
|
||||
<Accordion.Content>
|
||||
<div className="mt-2">
|
||||
{mapScene?.model.children.map((child) => {
|
||||
const key = `toggle-visibility-${child.name}`;
|
||||
const color = `#${(
|
||||
(child as Mesh).material as MeshStandardMaterial
|
||||
).color.getHexString()}`;
|
||||
return (
|
||||
<div key={key} className="flex items-center ml-2">
|
||||
<span
|
||||
className="inline-block w-4 h-4"
|
||||
style={{
|
||||
backgroundColor: color,
|
||||
}}
|
||||
></span>
|
||||
<Checkbox
|
||||
id={key}
|
||||
defaultChecked
|
||||
onChange={() => handleCheckboxChange(child.name)}
|
||||
className="ml-2"
|
||||
/>
|
||||
<Label htmlFor={key} className="ml-2">
|
||||
{child.name}
|
||||
</Label>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</Accordion.Content>
|
||||
</Accordion.Panel>
|
||||
</Accordion>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
Loading…
Add table
editor.link_modal.header
Reference in a new issue