我正在使用Three.js webgl库创建场景。我在第一个场景中有一个纹理。单击此纹理,我试图导航到下一个场景。我编写了一个函数来处理这个场景以移动到下一个场景。单击此纹理,它将按预期移动到第二个场景,但其中没有任何内容可见。所以,我想知道如何以编程方式显示或隐藏场景。这是第一个场景调用第二个场景的代码 “
<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>'