最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Three.js: The Surface is One-Sided - Stack Overflow

programmeradmin0浏览0评论

This code (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>

Render passes, all right, but when I try to look under the surface it disappears. But in an example of which is taken from the code works correctly. The only difference: in the example library r49, but I have a r55

This code (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>

Render passes, all right, but when I try to look under the surface it disappears. But in an example of which is taken from the code works correctly. The only difference: in the example library r49, but I have a r55

Share Improve this question edited Feb 10, 2013 at 16:09 WestLangley 105k11 gold badges287 silver badges283 bronze badges asked Feb 10, 2013 at 15:47 user2059076user2059076 231 silver badge4 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

Instead of

floor.doubleSided = true;

use

floorMaterial.side = THREE.DoubleSide;

If you are learning, only refer to the official three.js examples, which work with r.55.

If you must update from an older version, see the Migration Wiki for help upgrading.

发布评论

评论列表(0)

  1. 暂无评论