N
N
node_js2021-05-21 01:58:55
JavaScript
node_js, 2021-05-21 01:58:55

How to set MeshNormalMaterial color?

Everything almost suits, I need a gray color and clarity, tell me what I'm doing wrong, I don't understand (
my screen
60a6e95cb768a294515079.png
Here is my code, tell me how to change the color of MeshNormalMaterial ?

import * as THREE from "https://threejs.org/build/three.module.js";
import {OrbitControls} from "https://threejs.org/examples/jsm/controls/OrbitControls.js";
import {STLLoader} from "https://threejs.org/examples/jsm/loaders/STLLoader.js";
const scene = new THREE.Scene();
const loader = new THREE.TextureLoader();
scene.background = new THREE.Color( 0xafdafc );
const camera = new THREE.PerspectiveCamera();
const renderer = new THREE.WebGLRenderer({canvas: viewer});
const controls = new OrbitControls(camera, renderer.domElement);
function render() {
requestAnimationFrame(render);
controls.update();
renderer.render(scene, camera);
}

var input = document.getElementById( 'input' );
input.addEventListener( 'change', function( event ) {
var file = this.files[ 0 ];
var reader = new FileReader();
reader.addEventListener( 'load', function ( event ) {
var contents = event.target.result;


var material = new THREE.MeshNormalMaterial({});

var geometry = new STLLoader().parse( contents );
var mesh = new THREE.Mesh( geometry,material);

camera.position.set(0, 480, 0);
scene.add( mesh );
scene.add(new THREE.AmbientLight(0x404040));
}, false );
if ( reader.readAsBinaryString !== undefined ) {
reader.readAsBinaryString( file );
} else {
reader.readAsArrayBuffer( file );
}
});
render();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
McBernar, 2021-05-21
@node_js

Are you aware, right, that MeshNormalMaterial simply represents the normals of the geometry in certain colors? Roughly speaking, in which direction the surface looks - this will be the color.
If you need a specific color - use any of the appropriate materials - Lambert, Physicist.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question