为什么照明在Three.js中不起作用?

Kar*_*ana 11 three.js

我不明白为什么照明在我的代码中不起作用.我下载了一个简单的OBJ.文件以测试OBJLoader,但模型不受影响.在我更多地编辑灯光之前,至少环境照明会起作用.也许是OBJ.模特需要纹理?

            var container, stats;

        var camera, scene, renderer, controls;


        init();
        animate();


        function init() {

            container = document.createElement( 'div' );
            document.body.appendChild( container );

            scene = new THREE.Scene();

            camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 2000 );
            camera.position.z = 2.5;
            scene.add( camera );

            controls = new THREE.TrackballControls( camera );

            controls.rotateSpeed = 2.0;
            controls.zoomSpeed = 1.2;
            controls.panSpeed = 0.0;

            controls.noZoom = false;
            controls.noPan = true;

            controls.staticMoving = true;
            controls.dynamicDampingFactor = 0.3;

            controls.keys = [ 65, 83, 68 ];

            controls.addEventListener( 'change', render );

            var ambient = new THREE.AmbientLight( 0x020202 );
            scene.add( ambient );

            directionalLight = new THREE.DirectionalLight( 0xffffff );
            directionalLight.position.set( 1, 1, 0.5 ).normalize();
            scene.add( directionalLight );

            pointLight = new THREE.PointLight( 0xffaa00 );
            pointLight.position.set( 0, 0, 0 );
            scene.add( pointLight );

            sphere = new THREE.SphereGeometry( 100, 16, 8 );
            lightMesh = new THREE.Mesh( sphere, new THREE.MeshBasicMaterial( { color: 0xffaa00 } ) );
            lightMesh.scale.set( 0.05, 0.05, 0.05 );
            lightMesh.position = pointLight.position;
            scene.add( lightMesh );


            var loader = new THREE.OBJLoader();
            loader.load( "originalMeanModel.obj", function ( object ) {
                scene.add( object );
            } );

            renderer = new THREE.WebGLRenderer();
            renderer.setSize( window.innerWidth, window.innerHeight );
            container.appendChild( renderer.domElement );

        }

        function animate() {

            requestAnimationFrame( animate );
            controls.update();

        }

        function render() {

            camera.lookAt( scene.position );

            renderer.render( scene, camera );

        }
Run Code Online (Sandbox Code Playgroud)

小智 18

THREE.js中的MeshBasicMaterial就像一个香椿着色器(适用于silouhette,阴影绘制或线框),并且不受灯光的影响.

尝试使用MeshLambertMaterial或MeshPhongMaterial


daf*_*mat 1

如果您几天前遇到像我一样的问题,如果您的 obj 中没有法线,这可能会对您有所帮助,这绝对是值得一看的地方

您也可以尝试从 a 开始MeshBasicMaterial,只是为了检查顶点/面是否正常:new THREE.MeshBasicMaterial({ color: 0x999999, wireframe: true, transparent: true, opacity: 0.85 } )

另外,正如 doob 先生所说,请考虑共享您正在加载的 obj。