Skip to content

cyj907/simple-mesh-visualizer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple Mesh Visualizer

This is a simple mesh visualizer developed in three.js. The codes are modified from this example.

You can use it for rendering 3d mesh file with diffuse and normal maps.

The files in ./models are generated using High-Fidelity 3D Digital Human Creation from RGB-D Selfies.

Usage

  1. Data preparation.

    Convert .obj file into .glb/.gltf file (You can use blender to do the conversion)

    Below is a simple tutorial in blender 2.83.

    • open blender

      open blender

    • import .obj file

      import obj

    • smooth vertex normal

      before

      shade smooth

      after: notice that the faces are smoothed.

      shade smooth

    • export .glb file

      make sure only the head.obj file is selected.

      export glb

      export glb selected

  2. Data placement.

    Put all files into ./models, including a .glb file, a diffuse map, a normal map and a specular map.

  3. Code editing.

    Open index.html in text/code editor and change the corresponding filenames below.

    function loadMesh() {
    
    	  var loader = new GLTFLoader();
    
    	  loader.load( 'models/head.glb', function ( gltf ) { // 3d mesh
    
    	  	mesh = gltf.scene.children[ 0 ];
    	  	var diffuse = textureLoader.load( 'models/diffuse.png' ); // diffuse map
    	  	diffuse.flipY = false;
    	  	var specular = textureLoader.load( 'models/specular.TGA' ); // specular map
    	  	specular.flipY = false;
    	  	var normal = textureLoader.load( 'models/normal.png' ); // normal map
    	  	normal.flipY = false;
    	  	normal.encoding = THREE.sRGBEncoding;
              var normalScale = new THREE.Vector2( 0.5, 0.5);
    	  	mesh.material = new THREE.MeshPhongMaterial( {
    	  		specular: 0x111111,
    	  		map: diffuse,
    	  		specularMap: specular,
    	  		normalMap: normal,
    	  		shininess: 20,
    	  		normalScale: normalScale,
    	  	} );
    
    	  	scene.add( mesh );
    	  	mesh.scale.set( 3, 3, 3 );
    
    	  } );
    
    }
  4. Serving.

    Load the webpage in apache or any other server software. I recommend using xampp in windows, and mampp in macos, because they are simple to use.

    Below is the tutorial for using xampp in windows 10.

    • Open /path/to/xampp/apache/conf/httpd.conf
    • Search for DocumentRoot and set values to the path to this visualizer
    DocumentRoot "/path/to/this/visualizer"
    <Directory> "/path/to/this/visualizer"
    
    • Press "start" button in the control pannel

      control pannel

    • Open the visualizer in localhost

    • Clear browser cache and refresh if necessary.

Results

result

Contact

If you have any question regarding this repo, please contact jadechancyj907@gmail.com.

About

A simple mesh visualizer in three.js

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages