我试图仅使light1照射在object1上(都在第0层),而light2照射在object2上(都在第1层)。我正在尝试使用图层。但是,当我在两层(第0层和第1层)上都放置相机时。灯光显然会影响两层的对象。
我使用了Three.js - How to prevent a light from shining on an object
中的解决方法但是仍然感觉应该有一个很好的分层解决方案...这就是他们的权利吗?
谢谢!
var ambientLight = getAmbientLight(2);
var pointLight = getPointLight(0.5);
function getAmbientLight(intensity) {
var light = new THREE.AmbientLight(0xffffff, intensity);
return light;
}
function getPointLight(intensity) {
var light = new THREE.PointLight(0xffffff, intensity);
//light.castShadow = true;
light.layers.set(1);
return light;
}
var loader = new THREE.GLTFLoader();
loader.load( 'models/scene.gltf', function ( gltf ) {
console.log(gltf.scene);
gltf.scene.traverse( function ( child ) {
if ( child.isMesh ) {
child.layers.set(0);
console.log(child);
}
} );
scene.add( gltf.scene );
}, undefined, function ( e ) {
console.error( e );
} );
var sphere = getSphere (0.4, 10, 10);
function getSphere(r) {
var geometry = new THREE.SphereGeometry(r, 24, 24);
var material = new THREE.MeshLambertMaterial( {
color: 'rgb(100,100,100)'
//side: THREE.DoubleSide
} );
var mesh = new THREE.Mesh(
geometry,
material );
mesh.layers.set(1);
return mesh;
}
答案 0 :(得分:0)
如文档(https://threejs.org/docs/#api/en/core/Layers)中所述,图层用于控制对象的可见性。因此,仅当对象与给定相机共享一个公共层时才渲染该对象。目前无法使用图层来确定哪些对象应该受到哪些光源的影响(也称为选择性照明)。请为此使用上述解决方法。此外,请阅读以下github问题,以获取有关该主题的更多信息:
https://github.com/mrdoob/three.js/issues/5180
three.js R96