您可以通过删除当前场景来重绘画布 scene.remove(mesh); 并在场景中添加创建新网格添加
scene.remove(mesh);
的 演示 强> http://jsfiddle.net/sumitridhal/x8t801f5/4/
您可以使用添加自定义控件 dat.GUI 图书馆。
dat.GUI
<script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.6.4/dat.gui.js"></script>
//
var controls = new function() { // we need the first child, since it's a multimaterial this.radius = 10; this.detail = 0; this.type = 'Icosahedron'; this.redraw = function() { // remove the old plane scene.remove(mesh); // create a new one // add it to the scene. scene.add(mesh); } }); var gui = new dat.GUI(); gui.add(controls, 'radius', 0, 40).step(1).onChange(controls.redraw); gui.add(controls, 'detail', 0, 3).step(1).onChange(controls.redraw); gui.add(controls, 'type', ['Icosahedron', 'Tetrahedron', 'Octahedron', 'Custom']).onChange(controls.redraw);
的 演示 强> http://codepen.io/sumitridhal/pen/NjbGpB
如果你只需要切换到新场景,那么为什么不要有两个场景对象和一个主场景。请尝试以下代码
/* Buttons to handle scene switch */ $("#scene2").click(function() { scene = scene2 }) $("#scene1").click(function() { scene = scene1 }) function init() { .... /* I dont think you need to add camera to scene for viewing perpose. By doing this, essentially you are adding camera object to scene, and you won't be able to see it because scene is rendered using this camera and camera eye is at same location */ scene1 = new THREE.Scene(); // Build scene1 // scene1.add(camera); scene2 = new THREE.Scene(); // Build scene2 // Choosing default scene as scene1 scene = scene1; } function render() { // Try some checking to update what is necessary renderer.render(scene, camera); }
更新 的jsfiddle