简体   繁体   English

如何在Three.js中使用相机作为纹理图像

[英]How to use camera as texture image in Three.js

In three.js, I am trying to create a texture whose image is the current scene as viewed from a Camera. 在three.js中,我正在尝试创建一个纹理,其图像是从相机中查看的当前场景。 Using a CubeCamera to create a similar effect is well-documented; 使用CubeCamera创建类似的效果已有详细记录; and with CubeCamera I have created an example of a scene to illustrate my goal at: 并且使用CubeCamera我创建了一个场景示例来说明我的目标:

http://stemkoski.github.com/Three.js/Camera-Texture-Almost.html http://stemkoski.github.com/Three.js/Camera-Texture-Almost.html

However, I would like to use a regular Camera (rather than a CubeCamera) as the texture. 但是,我想使用常规相机(而不是CubeCamera)作为纹理。 How could I do this? 我怎么能这样做?

Ideally this would work. 理想情况下这可行。

Init: 在里面:

renderTarget = new THREE.WebGLRenderTarget( 512, 512, { format: THREE.RGBFormat } );

var planelikeGeometry = new THREE.CubeGeometry( 400, 200, 200 );
var plane = new THREE.Mesh( planelikeGeometry, new THREE.MeshBasicMaterial( { map: renderTarget } ) );
plane.position.set(0,100,-500);
scene.add(plane);

Render: 渲染:

renderer.render( scene, topCamera, renderTarget, true );
renderer.render( scene, topCamera );

And it almost does, but we have some unfinished business with y-flipped textures that ruins the party here. 它几乎可以,但我们有一些未完成的业务与y翻转纹理,在这里破坏了聚会。

So the best solution at the moment is to use the intermediry quad for flipping the texture (also saves a render): 因此,目前最好的解决方案是使用中间四边形来翻转纹理(也可以保存渲染):

http://mrdoob.github.com/three.js/examples/webgl_rtt.html http://mrdoob.github.com/three.js/examples/webgl_rtt.html

Based on mrdoob's example and suggestions, I have created a working example with very detailed comments, available at: 基于mrdoob的示例和建议,我创建了一个包含非常详细注释的工作示例,可从以下位置获得:

http://stemkoski.github.com/Three.js/Camera-Texture.html http://stemkoski.github.com/Three.js/Camera-Texture.html

part of my series of tutorial-style Three.js series of examples at 我系列教程风格的Three.js系列示例的一部分

http://stemkoski.github.com/Three.js/ http://stemkoski.github.com/Three.js/

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

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