0

I'm intrigued by Drei's statement about PerspectiveCameras:

You can use the PerspectiveCamera to film contents into a RenderTarget,...

So I wanted to get it working to try it out.

Using their example as a base, I decided to try and render a PerspectiveCamera to a plane:

<Canvas>                                                        
  // Just a pretty box to look at.
  <mesh>                                                        
      <boxBufferGeometry attach="geometry" args={[1, 1, 1]} />  
      <meshStandardMaterial attach="material" color="hotpink" />
  </mesh>  

  // A non-default camera to look at my box.
  <PerspectiveCamera position={[0, 0, 2]}>     
      {(texture) => (
          // A plane to render my non-default camera's view to.
          // Note: Its position is behind the camera, so I don't think I will run into infinite rendering.              
          <mesh position={[0, 0, 3]}>          
            <planeGeometry args={[2, 2]}/>     
            <meshBasicMaterial map={texture} />
          </mesh>                              
      )}                                       
  </PerspectiveCamera>                         
  
  // Just some necessary and helpful components in my scene                                                     
  <ambientLight intensity={0.3} color="#FFFFFF" />              
  <pointLight intensity={1.0} position={[10, 10, 10]} />                                                  
  <OrbitControls />                                             
                                                                
</Canvas>                                                       

I expected to see a plane in my scene with a rendered texture of the box. However, I see no plane, only the box, and the default scene camera.

I don't fully understand this line in the documentation, so I suspect it may be what's tripping me up.

[the plane mesh] will be set invisible while the FBO renders to avoid issues where the meshes that receive the texture are interfering.

SternK
  • 11,649
  • 22
  • 32
  • 46
zeumer
  • 13
  • 3

0 Answers0