【问题标题】:Three.js point light not working with large meshesThree.js 点光源不适用于大型网格
【发布时间】:2014-04-07 21:29:14
【问题描述】:

我有以下问题。当我像这样使用 Three.js 点光源时:

 var color = 0xffffff;   
 var intensity = 0.5;
 var distance = 200;
 position_x = 0;
 position_y = 0;
 position_z = 0;

 light = new THREE.PointLight(color, intensity, distance); 
 light.position.set(position_x, position_y, position_z);
 scene.add(light);

当有一个“小”物体(网格)靠近场景中的灯光时,它会按预期工作。但是,当有一个大物体时(比如说地板):

 var floorTexture = new THREE.ImageUtils.loadTexture( 'floor.jpg' );
 floorTexture.wrapS = floorTexture.wrapT = THREE.RepeatWrapping; 
 floorTexture.repeat.set( 1, 1);
 var floorMaterial = new THREE.MeshBasicMaterial( { map: floorTexture, side: THREE.DoubleSide } );
 var floorGeometry = new THREE.PlaneGeometry(1000, 1000, 10, 10);

 var floor = new THREE.Mesh(floorGeometry, floorMaterial);
 floor.position.y = -0.5;
 floor.rotation.x = Math.PI / 2;
 scene.add(floor);

那么灯就不会显示在上面了。起初我认为这是由于地板中心距离点光源较远,因此点光源无法在距离设置为 200 的情况下到达它(即使地板的一部分比上述距离更近)。因此我试图增加这个距离 - 没有运气。

有一种解决方法可以用小部件创建地板。然后点光源再次按预期工作,但这种方法存在一个问题 - 即由于要渲染大量“地板对象”,它会大大降低 FPS。

我的猜测是我错过了一些东西。我知道还有其他类型的光可以覆盖整个场景,但我正在尝试创建一盏灯,所以我认为我需要使用点光源。但我可能错了。任何帮助或提示如何完成这项工作将不胜感激。

【问题讨论】:

  • 你在使用MeshLambertMaterial吗?
  • 对不起,我的代码格式有问题,现在我已经添加了代码。不,我正在使用 MeshBasicMaterial。
  • MeshBasicMaterial 不支持灯光。试试MeshPhongMaterial
  • 我知道我错过了一些东西。它适用于 MeshPhongMatherial。非常感谢。

标签: javascript 3d three.js


【解决方案1】:

MeshBasicMaterial 不支持灯光。使用MeshPhongMaterial

MeshLambertMaterial 也支持灯光,但在您的情况下不建议这样做,原因如下:Three.js: What Is The Exact Difference Between Lambert and Phong?

three.js r.66

【讨论】:

    猜你喜欢
    • 2014-01-19
    • 2011-12-23
    • 2014-03-12
    • 2017-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-19
    • 2013-05-23
    相关资源
    最近更新 更多