减去的几何形状导致奇怪的光照

时间:2015-05-19 14:08:19

标签: javascript three.js csg threecsg

在three.js中,我试图删除'使用我在这里找到的c​​sg(contructive solid geometry)扩展来自框几何(墙)的窗口:https://github.com/chandlerprall/ThreeCSG

我成功地切割了窗户,但结果的表面非常奇怪地反射光,见下图(第一次正常,然后是带窗户的墙)

normal wall wall with window

var leftWallGeometry = new THREE.BoxGeometry( $scope.wall.width, $scope.room.height, $scope.room.depth);
var leftWallMesh = new THREE.Mesh( leftWallGeometry );

var leftWallBSP = new ThreeBSP( leftWallMesh );

var leftWindowGeometry = new THREE.BoxGeometry($scope.wall.width +10, 100, 100 );
var leftWindowMesh = new THREE.Mesh( leftWindowGeometry)

var leftWindowBSP = new ThreeBSP( leftWindowMesh );

var windowWallBSP = leftWallBSP.subtract( leftWindowBSP );
var result = windowWallBSP.toMesh( wallMaterial );
result.geometry.computeVertexNormals();

result.position.x = $scope.room.width / -2
result.position.y = $scope.room.height / 2
$scope.scene.add( result ); 

墙面材质是MeshPhongMaterial,具有重复的纹理和凹凸贴图。

var wallTexture = new THREE.ImageUtils.loadTexture('img/wall_diffuse_0.jpg')
// wall bump texture
var wallBumpTexture = new THREE.ImageUtils.loadTexture('img/bump_1.jpg')


// repeate wall texture and wall bump texture
wallTexture.wrapS = wallTexture.wrapT = THREE.RepeatWrapping; 
wallTexture.repeat.set( 10, 10 );

wallBumpTexture.wrapS = wallBumpTexture.wrapT = THREE.RepeatWrapping; 
wallBumpTexture.repeat.set( 10, 10 );

var wallMaterial = new THREE.MeshPhongMaterial( { map: wallTexture, bumpMap: wallBumpTexture, bumpScale: 0.2} );

对于如何解决这个奇怪的光/反射问题的任何建议,我将不胜感激。或者如何从three.js中的墙/盒切割窗户。

1 个答案:

答案 0 :(得分:1)

尝试将墙材质的阴影设置为平面阴影:

wallMaterial.shading = THREE.FlatShading;

正确阴影墙的示例图片:

example image