Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么';t方向灯在three.js中工作?_Javascript_Three.js_Light - Fatal编程技术网

Javascript 为什么';t方向灯在three.js中工作?

Javascript 为什么';t方向灯在three.js中工作?,javascript,three.js,light,Javascript,Three.js,Light,我在three.js里打了个电话。我需要添加摄像头和照明。照相机的工作还可以,但我的灯光有问题。这是我的密码: <script src="three.js"></script> <script src="https://threejs.org/examples/js/controls/OrbitControls.js"></script> <script src="https://threej

我在three.js里打了个电话。我需要添加摄像头和照明。照相机的工作还可以,但我的灯光有问题。这是我的密码:

<script src="three.js"></script>
<script src="https://threejs.org/examples/js/controls/OrbitControls.js"></script>
<script src="https://threejsfundamentals.org/threejs/../3rdparty/dat.gui.module.js"></script>
<script>

        const scene = new THREE.Scene();

        const camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
        const renderer = new THREE.WebGLRenderer();
        renderer.setSize( window.innerWidth, window.innerHeight );

        const color = 0xFFFFFF;
        const intensity = 1;
        const light = new THREE.DirectionalLight(color, intensity);
        light.position.set(10, 10, 10);
        light.target.position.set(-5, 0, 0);
        scene.add(light);
        scene.add(light.target);

        document.body.appendChild( renderer.domElement );

        let controls = new THREE.OrbitControls(camera, renderer.domElement);
        controls.target.set(0, 0, 0);
        controls.rotateSpeed = 0.5;
        controls.update();

        camera.position.z = 5;

        const geometry = new THREE.RingGeometry( 1, 3, 32 );
        const material = new THREE.MeshBasicMaterial( { color: 0xffff00, side: THREE.DoubleSide } );
        const mesh = new THREE.Mesh( geometry, material );
        mesh.receiveShadow = true;
        mesh.castShadow = true
        scene.add( mesh );

        function animate() {
            requestAnimationFrame( animate );
            mesh.rotation.x += 0.01;
            mesh.rotation.y += 0.01;
            renderer.render( scene, camera );
        }
        animate();

</script>

const scene=new THREE.scene();
const-camera=新的三视角摄像机(75,window.innerWidth/window.innerHeight,0.11000);
const renderer=new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth、window.innerHeight);
常量颜色=0xFFFFFF;
常数强度=1;
恒定光=新的三个方向光(颜色、强度);
光。位置。设置(10,10,10);
灯光。目标。位置。设置(-5,0,0);
场景。添加(灯光);
场景。添加(灯光。目标);
document.body.appendChild(renderer.doElement);
let controls=新的三个.OrbitControls(摄影机、渲染器.doElement);
controls.target.set(0,0,0);
controls.rotateSpeed=0.5;
控件更新();
摄像机位置z=5;
常量几何=新的三个环形几何(1,3,32);
const material=new THREE.MeshBasicMaterial({color:0xffff00,side:THREE.DoubleSide});
常量网格=新的三个网格(几何体、材质);
mesh.receiveShadow=true;
mesh.castShadow=true
场景。添加(网格);
函数animate(){
请求动画帧(动画);
网格旋转.x+=0.01;
网格旋转y+=0.01;
渲染器。渲染(场景、摄影机);
}
制作动画();
我曾尝试将方向灯更改为环境灯和聚光灯,但都不起作用。对我来说,什么样的光并不重要,我只需要显示我的3d形状。

不受光的影响。你必须使用不同的材料。使用模型用于灯光计算的:

const material=new THREE.MeshBasicMaterial({color:0xFFFFFF00,side:THREE.DoubleSide})

const material=new THREE.MeshPhongMaterial({color:0xffff00,side:THREE.DoubleSide});

问题解决了吗?