【发布时间】:2018-02-16 19:44:23
【问题描述】:
我在 Three.js 中创建了一个 PlaneGeometry,并在其上放置了一个对象。
如果我移动相机以便从下方看到 PlaneGeometry,我仍然可以看到顶部对象的部分。如何定义对象只能从 PlaneGeometry 上方看到?
Image from above
Image from below
// Creating PlaneGeometry
var floorGeometry = new THREE.PlaneGeometry( 100, 100 );
floorGeometry.rotateX( - Math.PI / 2 );
var floorTexture = new THREE.TextureLoader().load( '../img/wood-texture.jpg' );
floorTexture.wrapS = THREE.RepeatWrapping;
floorTexture.wrapT = THREE.RepeatWrapping;
floorTexture.repeat.set(20, 20);
var floorMaterial = new THREE.MeshBasicMaterial({map: floorTexture, side: THREE.DoubleSide});
var floor = new THREE.Mesh( floorGeometry, floorMaterial );
scene.add( floor );
// Creating object on top
var cubeGeometry = new THREE.BoxGeometry(1, 1, 1);
var cubeMaterial = new THREE.MeshBasicMaterial({color: 0x444444,wireframe: true});
var cube = new THREE.Mesh(cubeGeometry, cubeMaterial);
cube.position.set(0, 0.5, 0);
scene.add(cube);
【问题讨论】:
-
作为一个选项,尝试将立方体设置得更高
cube.position.set(0, 0.51, 0); -
这也是我的第一个想法。但如果我放大,我可以看到差距。而且我想它会在以后导致阴影投射问题。
-
在黑暗中拍摄:尝试像这样设置
floorMaterial:var floorMaterial = new THREE.MeshBasicMaterial({map: floorTexture, side: THREE.DoubleSide, polygonOffset: true, polygonOffsetFactor: 1, polygonOffsetUnits: 0.1 });这应该会使地板稍微靠近相机,但它也可能会产生使地板重叠的负面影响从上面看时立方体的底部。 -
@TheJim01 试过了,没有明显效果。
标签: three.js