C
C
chelnokov_a2021-09-05 19:23:20
three.js
chelnokov_a, 2021-09-05 19:23:20

How to light up an object in three.js? Where is the mistake?

It is not possible to illuminate the object that is in the upper block

https://pateder.ru/RODECOR/

function main() {
            // const canvas = document.querySelector('#three');
            // const renderer = new THREE.WebGLRenderer({canvas});

            const scene = new THREE.Scene();
            const camera = new THREE.PerspectiveCamera(45, document.querySelector('.main__decor').clientWidth / document.querySelector('.main__decor').clientHeight, 0.1, 1000)
            const renderer = new THREE.WebGLRenderer({antialias: true, alpha: true});
            
            
            renderer.setSize( document.querySelector('.main__decor').clientWidth, document.querySelector('.main__decor').clientHeight)
            renderer.domElement.setAttribute('id', 'three')
            document.querySelector('#three').append(renderer.domElement);
            renderer.setClearColor( 0xff0000, 0 );
            
            renderer.render(scene, camera)
            
            let objLoader = new THREE.OBJLoader();
            objLoader.load('./obj.obj', obj => {
                console.log(obj)
                
                scene.add(obj);
                obj.rotation.x += 1;
                camera.rotation.x += -0.1
                
            })
            
            var spotLight = new THREE.SpotLight( 0xffffff );
            scene.add(spotLight);
            
            let light = new THREE.AmbientLight(0xffffff)
            scene.add(light);
            
            camera.position.z = 5;
            
            var render = function () {
                requestAnimationFrame( render );
                
              	renderer.render(scene, camera);
            };
            render();
        }
        main();


I've been tinkering all day already. Tell me where to look to solve the problem !!!???

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question