Can I use the model's original color in the code instead of setting new color?

Hi,
I am new to this and I was wondering if there is a way to get the original color of the model from Solidworks, I exported the model in STL format but I read that it might not have the color information in it…
Is there any format that I can export that will allow me to use the color with threejs ?
Right now I have this code and I have to set the color or the model doesn’t visualize:

var material = new THREE.MeshPhongMaterial({ 
				color: 0xcccccc,
				specular: 100, 
				shininess: 200 });
var mesh = new THREE.Mesh(geometry, material);
scene.add(mesh);

STL is a pure geometry format. Meaning it does not support any material information.

However, it does support vertex colors. Depending on the STL exporter, the color might be decoded as vertex colors in the geometry. Fortunately, THREE.STLLoader does parse vertex colors and provides a flag for testing. Use this approach in your onLoad() callback:

if ( geometry.hasColors  === true ) {

    material = new THREE.MeshPhongMaterial( { vertexColors: true } );

}
2 Likes