问题
I am creating scene using Three.js webgl library. I am having a texture in the first scene. Clicking on this texture, i am trying to navigate to the next scene. I have written a function to handle this scenario to move to the next scene. Clicking on this texture, it is moving to the second scene as expected,but nothing is visible in it. So, i would like to know How to programmatically show or hide scenes.Here is the code where the first scene calls the second scene '
<script>
function createsecondScene()
{
function setVisibility (scene1, node)
{
node.visible = scene1.visible;
}
function traverseVisibility (scene1, callback)
{
var child, i, num_children = scene1.children.length;
for (i = num_children - 1; i >= 0; i--)
{
child = scene1.children[i];
callback (scene1, child);
traverseVisibility (child, callback);
}
}
scene1.visible = false; // or true
traverseVisibility (scene1, setVisibility);
var container, scene2, camera, renderer, stats, objects=[],length;
projector = new THREE.Projector();
// custom global variables
var familyRoom;
init();
animate();
// FUNCTIONS
function init()
{
// SCENE
scene2 = 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);
scene2.add(camera);
camera.position.set(0,-100,450);
camera.lookAt(scene2.position);
// RENDERER
if ( Detector.webgl )
renderer = new THREE.WebGLRenderer( {antialias:true} );
else
renderer = new THREE.CanvasRenderer();
renderer.setSize(SCREEN_WIDTH, SCREEN_HEIGHT);
container = document.createElement( 'div' );
document.body.appendChild( container );
container.appendChild( renderer.domElement );
// EVENTS
// LIGHT
var light = new THREE.PointLight(0xffffff);
light.position.set(-100,200,100);
scene2.add(light);
// FLOOR
////////////
// CUSTOM //
////////////
// Note: if imported model appears too dark,
// add an ambient light in this file
// and increase values in model's exported .js file
// to e.g. "colorAmbient" : [0.75, 0.75, 0.75]
var jsonLoader = new THREE.JSONLoader();
jsonLoader.load( "LivingAndOtherRooms/RoomModel.js", addModelToScene );
// addModelToScene function is called back after model has loaded
var ambientLight = new THREE.AmbientLight(0x111111);
scene2.add(ambientLight);
}
function addModelToScene( geometry, materials )
{
var material = new THREE.MeshFaceMaterial( materials );
familyRoom = new THREE.Mesh( geometry, material );
familyRoom.scale.set(35,10,3);
scene2.add( familyRoom );
}
function animate()
{
requestAnimationFrame( animate );
render();
}
function render()
{
renderer.render( scene2, camera );
}
}
</script>'
来源:https://stackoverflow.com/questions/17361463/how-to-hide-or-show-scene-in-three-js