简体   繁体   English

threejs:在单个webgl渲染器中渲染多个场景

[英]threejs: rendering multiple scenes in a single webgl renderer

I am trying to include multiple scene into a single webgl renderer as per code below: 我试图按照以下代码将多个场景包含到单个webgl渲染器中:

renderer.render( scene1, camera ); renderer.render(scene1,camera);
renderer.render( scene2, camera ); renderer.render(scene2,camera);

I am facing issue where in the last scene object that is passed to the renderer is being painted and the previous one is not. 我面临的问题是,在传递到渲染器的最后一个场景对象中绘制,而上一个场景对象没有绘制。 I confirmed it by swapping the above two lines of code. 通过交换以上两行代码,我确认了这一点。 I am newbie to threejs and would like to know if the above can be achieved? 我是threejs的新手,想知道以上是否可以实现? and also if you can guide me towards supporting examples (if any). 以及您是否可以引导我寻求支持示例(如果有)。

Thanks! 谢谢!

The minimal solution you can find here: https://jsfiddle.net/mmalex/sqg0d8vx/ 您可以在这里找到最小的解决方案: https : //jsfiddle.net/mmalex/sqg0d8vx/

var animate = function() {
    requestAnimationFrame(animate);

    renderer.autoClear = true;

    //render scene1
    renderer.render(scene1, camera);

    //prevent canvas from being erased with next .render call
    renderer.autoClear = false;

    //just render scene2 on top of scene1
    renderer.render(scene2, camera);
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM