Hi ! I am just starting out on using Three.js , i have been working on importing a 3D .OBJ model and rendering it using the Chrome browser. I have managed to successfully import the 3D model and render it but i have having issues with its appearance. I am trying to render the model exactly how i found it on Free3D.com but my model appears grey whereas the original model is white. In addition, parts of the model appear white whereas in the original model on the website appears black(not sure if there is an an issue with the downloaded model) or some parts are hazy and appear true to form when i zoom in. My understanding is that i am messing up with the Lighting Controls, i would like to understand how do i manipulate the lights for each model ? How does one decide which light is appropriate and its position?
Please find below , the code i have been working with
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(5, window.innerWidth/window.innerHeight, 0.1, 1000
);
camera.position.y = 300;
camera.position.z = -2;
var renderer = new THREE.WebGLRenderer({antialias:true});
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setClearColor('white');
document.body.appendChild( renderer.domElement );
window.addEventListener('resize', ()=>{
renderer.setSize( window.innerWidth, window.innerHeight );
camera.aspect = window.innerWidth/window.innerHeight;
camera.updateProjectMatrix();
})
var controls = new THREE.OrbitControls(camera, renderer.domElement);
controls.enableDamping = true;
controls.dampingFactor = 0.25;
controls.enableZoom = true;
var ambient = new THREE.AmbientLight(0x404040, 2.0);
scene.add(ambient);
var keyLight = new THREE.DirectionalLight('0x404040', 1.0);
keyLight.position.set(-100, 0, 100);
keyLight.castShadow= true;
var fillLight = new THREE.DirectionalLight('0x404040', 1.0);
fillLight.position.set(100, 0, 100);
var backLight = new THREE.DirectionalLight(0x404040, 1.0);
backLight.position.set(100, 0, -100).normalize();
scene.add(keyLight);
scene.add(fillLight);
scene.add(backLight);
var mtlLoader = new THREE.MTLLoader();
mtlLoader.setTexturePath('/examples/3d-obj-loader/assets/');
mtlLoader.setPath('/examples/3d-obj-loader/assets/');
mtlLoader.load('Controller.mtl', function (materials) {
materials.preload();
var objLoader = new THREE.OBJLoader();
objLoader.setMaterials(materials);
objLoader.setPath('/examples/3d-obj-loader/assets/');
objLoader.load('Controller.obj', function (object) {
scene.add(object);
object.position.y -= 1;
});
});
var animate = function () {
requestAnimationFrame( animate );
controls.update();
renderer.render(scene, camera);
} ;
animate();
The model i am tried exporting is https://free3d.com/3d-model/xbox-one-controller-295065.html
Would i get better results if i used .glTF models ?