0

I have tested PCL triangluation introduced here:

And from the experiment I got a .vtk file. And I tried to render it via web browser whith three.js on windows. It is like below:

See! there are many holes

See! There are many holes. These holes are triangles that have opposite normal vectors.

Normal vectors are not aligned

What I need is flipping those normal vectors that are opposite than others. This way I believe I would get clean mesh image as shown below:

This is expected image I want

How can I do this? Do I work with three.js? Had I better work with pcl library? - the triangluation?

This is the html I tested:

<!DOCTYPE html>
<html lang="en">
  <head>
    <!--title>four.js webgl - loaders - vtk loader</title-->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
    <link type="text/css" rel="stylesheet" href="main.css">
  </head>

  <body>
    <script type="module">

      var console = (window.console = window.console || {});

      import * as THREE from '../build/three.module.js';

      import { TrackballControls } from './jsm/controls/TrackballControls.js';
      import { VTKLoader } from './jsm/loaders/VTKLoader.js';

      import { VertexNormalsHelper } from './jsm/helpers/VertexNormalsHelper.js';

      let container, camera, controls, scene, renderer, vnh;

      init();
      animate();

      function init() {
            camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 0.01, 1e10);
            camera.position.set( -1, 0, 0 );

            scene = new THREE.Scene();

            scene.add( camera );

            // light

            const hemiLight = new THREE.HemisphereLight( 0xffffff, 0x000000, 1 );
            scene.add( hemiLight );

            const dirLight = new THREE.DirectionalLight( 0xffffff, 0.5 );
            dirLight.position.set( 2, 2, 2 );
            scene.add( dirLight );

            const material = new THREE.MeshLambertMaterial( { color: 0xffffff } );

            const loader = new VTKLoader();
            loader.load( "models/vtk/point_cloud_mesh.vtk", function ( geometry )
            //loader.load( "models/vtk/point_cloud_mesh_not_smoothed.vtk", function ( geometry )
            {

                    //geometry.applyMatrix(new THREE.Matrix4().makeScale(-1, -1,-1));
                    //geometry.computeFaceNormals();

                    //var tmp;
                    //console.log(geometry.index.count);
                    //console.log(geometry.userData);

                    geometry.computeVertexNormals();

                    const mesh = new THREE.Mesh( geometry, material );
                    mesh.position.set( - 0.075, 0.005, 0 );
                    mesh.scale.multiplyScalar( 0.2 );

                    scene.add( mesh );

                    //vnh = new VertexNormalsHelper(mesh, 0.001, 0x00ff00, 1);
                    //scene.add( vnh );

            } );

            // renderer

            renderer = new THREE.WebGLRenderer();
            renderer.setPixelRatio( window.devicePixelRatio );
            renderer.setSize( window.innerWidth, window.innerHeight );

            container = document.createElement( 'div' );
            document.body.appendChild( container );
            container.appendChild( renderer.domElement );

            // controls

            controls = new TrackballControls( camera, renderer.domElement );
            controls.minDistance = .1;
            controls.maxDistance = 0.5;
            controls.rotateSpeed = 5.0;

            window.addEventListener( 'resize', onWindowResize );

            }

            function onWindowResize() {
                    camera.aspect = window.innerWidth / window.innerHeight;
                    camera.updateProjectionMatrix();
                    renderer.setSize( window.innerWidth, window.innerHeight );
                    controls.handleResize();
            }

            function animate() {
                    requestAnimationFrame( animate );
                    controls.update();

                    //if (vnh) vnh.update();

                    renderer.render( scene, camera );
            }

    </script>

  </body>
</html>

Thanks to WestLangley , I finally got a expected result as shown below:

This is the expected result!

Thank you WestLangley and Stackoverflow!!

But the question still remains. WestLangley's suggestion helps but it wouldn't be the only one solution. As you see below, some of the normal vectors are facing into the body of my hand. I believe there would be a way to make all the normal vectors face out of the body of my hand. Answers to this question still wanted...

Some normal vectors still face into my hand body

Jumogehn
  • 1,102
  • 3
  • 11
  • 29

0 Answers0