dusunax / dicom-and-three-js-viewer

🩻 great viewer for dcm & ply file
3 stars 0 forks source link

230625 - Add `dat.GUI` #14

Closed dusunax closed 1 year ago

dusunax commented 1 year ago

230625 - Add dat.GUI

πŸ—‚ Works μž‘μ—…λ‚΄μš©

[feat & ui] Add UI uses dat.GUI on screen that changes rendering properties.

230628_surface (1)


[feat & ui] Add UI uses dat.GUI on screen that changes rendering properties. πŸ“Œ

Import Dat.GUI

import { GUI } from "three/examples/jsm/libs/lil-gui.module.min";

Add configs

GUI init πŸ™†β€β™€οΈ

function guiEditorInit(
  guiConfig: GuiConfig,
  setGuiConfig: Dispatch<SetStateAction<GuiConfig>>
): void {
  if (guiConfig === undefined || document.querySelector(".lil-gui")) return; // early return to avoid duplicate GUI appends.

    const gui = new GUI(); // create GUI
    gui.$title.innerText = "μ„€μ • βš™ model configuration";
    gui
      .add(guiConfig, "wireframe", [true, false]) // array of properties => select & option
      .onFinishChange((value: boolean) =>
        setGuiConfig((prevState) => ({ ...prevState, wireframe: value })) // setState!πŸ™‚
      );
    gui
      .add(guiConfig, "light", 0, 1, 0.1) // number
      .onFinishChange((value: number) =>
        setGuiConfig((prevState) => ({ ...prevState, light: value }))
      );
    gui
      .add(guiConfig, "metalness", 0, 1, 0.1)
      .onFinishChange((value: number) =>
        setGuiConfig((prevState) => ({ ...prevState, metalness: value }))
      );
    gui
      .add(guiConfig, "roughness", 0, 1, 0.1)
      .onFinishChange((value: number) =>
        setGuiConfig((prevState) => ({ ...prevState, roughness: value }))
      );
    gui
      .addColor(guiConfig, "color") // use color picker
      .onFinishChange((value: string) =>
        setGuiConfig((prevState) => ({ ...prevState, color: value }))
      );

    // move the GUI to the top left corner
    const guiElement = gui.domElement;
    guiElement.style.position = "absolute";
    guiElement.style.top = "90px";
    guiElement.style.left = "10px";
}

Use guiCofing values

Add guiConfig to useEffect's dependency array.

when guiConfig changes => setState for change UI

Result

1. wireframe mode

2. metarial color

3. add metarial options


update

there is no change in the result even after applying the tolerance to BufferGeometryUtils's mergeVertices function, since the step_size value was added when dcm to ply converting using trimesh.

geometry = BufferGeometryUtils.mergeVertices(geometry, guiConfig.tolerance); // ν•΄λ‹Ή μ½”λ“œ
dusunax commented 1 year ago

Close issue and move to the next documentation.