Three.js:表面是单面的

时间:2013-02-10 15:47:29

标签: javascript three.js webgl

此代码(three.js):

<script type="text/javascript">
init();
animate();

// FUNCTIONS        
function init() 
{
// SCENE
scene = new THREE.Scene();
// CAMERA
var SCREEN_WIDTH = window.innerWidth, SCREEN_HEIGHT = window.innerHeight;
var VIEW_ANGLE = 45, ASPECT = SCREEN_WIDTH / SCREEN_HEIGHT, NEAR = 0.1, FAR = 20000;
camera = new THREE.PerspectiveCamera( VIEW_ANGLE, ASPECT, NEAR, FAR);
scene.add(camera);
camera.position.set(0,150,400);
camera.lookAt(scene.position);  
// RENDERER
renderer = new THREE.WebGLRenderer( {antialias:true} );
renderer.setSize(SCREEN_WIDTH, SCREEN_HEIGHT);
container = document.createElement( 'div' );
document.body.appendChild( container );
container.appendChild( renderer.domElement );
// EVENTS

// CONTROLS
controls = new THREE.TrackballControls( camera );
// STATS
stats = new Stats();
stats.domElement.style.position = 'absolute';
stats.domElement.style.bottom = '0px';
stats.domElement.style.zIndex = 100;
container.appendChild( stats.domElement );
// LIGHT
var light = new THREE.PointLight(0xffffff);
light.position.set(0,250,0);
scene.add(light);
// FLOOR
var floorTexture = new THREE.ImageUtils.loadTexture( 'https://localhost/geos/images/square.png' );
floorTexture.wrapS = floorTexture.wrapT = THREE.RepeatWrapping; 
floorTexture.repeat.set( 10, 10 );
var floorMaterial = new THREE.MeshBasicMaterial( { map: floorTexture } );
var floorGeometry = new THREE.PlaneGeometry(1000, 1000, 10, 10);
var floor = new THREE.Mesh(floorGeometry, floorMaterial);
floor.position.y = -0.5;
floor.doubleSided = true;
scene.add(floor);
}

function animate() 
{
   requestAnimationFrame( animate );
   render();       
   update();
}

function update()
{


   controls.update();
   stats.update();
}

function render() 
{
  renderer.render( scene, camera );
}

</script>

渲染过程,好吧,但是当我试图在表面下看时,它会消失。但是在一个例子中从代码中获取正确的工作。唯一的区别:在示例库r49中,但我有一个r55

1 个答案:

答案 0 :(得分:5)

而不是

floor.doubleSided = true;

使用

floorMaterial.side = THREE.DoubleSide;

如果您正在学习,请参阅官方的three.js示例,这些示例适用于r.55。

如果您必须从旧版本更新,请参阅Migration Wiki以获取升级帮助。