dusunax / dicom-and-three-js-viewer

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

230611 - Handle three.js with tasks #8

Closed dusunax closed 1 year ago

dusunax commented 1 year ago

230611 - Handle three.js with tasks

learn how to use three.js features with 2 rendering tasks.
- tri mesh rendering
- raycasting with arcball
Task Description Status
B. tri mesh rendering (1st phase) render model with only tri mesh Completed (230611)
(2nd phase) display the mesh by simplifying the faces pending
C. raycasting with arcball change camera position on screen Completed (230611)

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

B. Tri mesh rendering


B. Tri mesh rendering πŸ“Œ

// material as wireframe const wireframeMaterial = new THREE.MeshBasicMaterial({ color: 0x0000ff, wireframe: true, transparent: true, opacity: 0.3, // add for solving issue (comment below) });

const mesh = new THREE.Mesh(geometry, material); const wireframe = new THREE.Mesh(geometry, wireframeMaterial); ... mesh.add(wireframe);


## Refactor `PLYModel.tsx` πŸ“Œ

### refactor list
1. handler to return mesh
```tsx
const { mesh } = handleGeometry({ geometry });
const { mesh } = handleTriMesh({ geometry });
  1. add render() function
    • handle camera, light, control, render method in three.js
  2. use light holder
    
    // setting light
    var lightHolder = new THREE.Group();

var directionalLight = new THREE.DirectionalLight(0xffffff, 1); directionalLight.position.set(1, 1, 0).normalize(); lightHolder.add(directionalLight);

const light = new THREE.AmbientLight("#FFF", 0.3); lightHolder.add(light);

scene.add(lightHolder);

4. add types for `loader`, `render mode state`
```tsx
export type RenderMode = "standard" | "wireframe";

export interface loadModelProps {
  renderer: THREE.WebGLRenderer;
  container: any;
  scene: THREE.Scene;
  renderType: RenderMode;
}

export interface loadModelByFile extends loadModelProps {
  plyFile: File;
}

export interface loadModelBySrc extends loadModelProps {
  plyPath: string;
}
  1. add render mode state

    /** plyPath: 경둜의 ply model을 loadν•©λ‹ˆλ‹€. */
    function loadPLYModelBySrc({
    renderer,
    container,
    scene,
    plyPath,
    renderType,
    }: loadModelBySrc) {
    console.log("경둜 λ‘œλ”");
    
    const loader = new PLYLoader();
    loader.load(plyPath, async (geometry) => {
    const { mesh } =
      renderType === "standard"
        ? handleGeometry({ geometry })
        : handleTriMesh({ geometry });
    render({ renderer, container, scene, geometry, mesh });
    });
    }

C. Raycasting with arcball πŸ“Œ

  • Constructor: OrbitControls( object : Camera, domElement : HTMLDOMElement )
  • object: (required) The camera to be controlled. The camera must not be a child of another object, unless that object is the scene itself.
  • domElement: The HTML element used for event listeners.
const controls = new OrbitControls(camera, container);
controls.enableZoom = true;
dusunax commented 1 year ago

β›” can't see wireframe β›”

// material as wireframe const wireframeMaterial = new THREE.MeshBasicMaterial({ color: 0x0000ff, wireframe: true, transparent: true, });

const mesh = new THREE.Mesh(geometry, material); const wireframe = new THREE.Mesh(geometry, wireframeMaterial); ... mesh.add(wireframe);


<img src="https://github.com/dusunax/dicom-viewer/assets/94776135/43c5552a-0f0c-4ed2-a652-542c055cc133" width="700px">
<img src="https://github.com/dusunax/dicom-viewer/assets/94776135/7f406bf8-0bf9-4b0e-8d94-af7ed0e77b5d" width="300px">

- appeared that when changing the color, the entire mesh's color was affected

## Zoom in πŸ”
- while observing the screen with OrbitControls, discovered the cause of the issue when zooming in. 
- The triangles' faces were too small, causing the lines to overlap and appear as faces.

<img src="https://github.com/dusunax/dicom-viewer/assets/94776135/19edd38d-489b-4eb8-9596-07a8ea410dcf" width="700px">

## add opacity
- added opacity to make the overlapping lines appear lighter. 

<img src="https://github.com/dusunax/dicom-viewer/assets/94776135/a1edcd9c-0d36-4e82-bae3-219b6ffeb0d9" width="500px">
<img src="https://github.com/dusunax/dicom-viewer/assets/94776135/5404381c-637b-42e1-b9ea-b03106aaf348" width="500px">

<img src="https://github.com/dusunax/dicom-viewer/assets/94776135/64bb1a57-9c37-429d-b4cb-390b171590c0" width="700px">

## to be continue...
- however, setting opacity did not completely resolve the issue. 
  also looking into the way to display the mesh by simplifying the faces.
dusunax commented 1 year ago

Close issue and move to the next documentation.