VR temp texture targ

by matra774

JavaScript

//import * as THREE from 'three';
//import { VRButton } from 'three/addons/webxr/VRButton.js';

import * as THREE from 'https://cdn.jsdelivr.net/npm/three@0.163.0/build/three.module.js';
import { VRButton } from 'https://cdn.jsdelivr.net/npm/three@0.163.0/examples/jsm/webxr/VRButton.js';


class RenderTexture { // texture that can be rendered to. Result can be used on 3d mesh

    constructor(targetWidth, targetHeight){
            
      this.targetTexture = new THREE.WebGLRenderTarget(targetWidth, targetHeight, {
       minFilter: THREE.NearestFilter,
       magFilter: THREE.NearestFilter,
       format: THREE.RGBAFormat,
      });      
      
      // Set up temporary  scene, camera, and renderer 
      this.scene = new THREE.Scene();
      
      // Orthographic camera to encompass the entire triangle
      const cameraFOV = 1
      const aspectRatio = 1
      this.camera = new THREE.OrthographicCamera(-cameraFOV * aspectRatio, cameraFOV * aspectRatio, cameraFOV, -cameraFOV, 0.1, 10);
      this.camera.position.z = 1;
  
  
      const geometry = new THREE.BoxGeometry( 1, 1, 1 );
      const cube = new THREE.Mesh( geometry, new THREE.MeshBasicMaterial( { color: 0x00ff00 } ));
      cube.rotateX(80)
      cube.rotateZ(10)
      this.cube = cube
      this.geometry = geometry
      this.scene.add(cube)
      
    }
  
    
    renderIntoTexture(xSrc, renderer)
    {        
        
      this.cube.rotation.y = xSrc

      const oldAutoClear = renderer.autoClear;
      const oldTarget = renderer.getRenderTarget()

      // If you uncomment this, the latest texture is carried over to VR scene, but then is no longer updated
      //renderer.autoClear = false
    
      renderer.setRenderTarget(this.targetTexture);            

      renderer.render(this.scene, this.camera); 

      renderer.autoClear = oldAutoClear
      renderer.setRenderTarget(oldTarget); // Reset to screen rendering (not needed)
    
    }
  }



const renderTexture = new RenderTexture(256,...