Hi.
I am trying to set a white planeGeometry to fill the viewport but the result is a plane geometry with a good rotation but it is far to the camera.
This is a small code that I coded to try it.
<html>
<title></title>
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/three@0.170/build/three.module.js",
"three/addons/": "https://unpkg.com/three@0.157/examples/jsm/",
"dat.gui": "https://unpkg.com/dat.gui@0.7.9/build/dat.gui.module.js"
}
}
</script>
</head>
<body>
</body>
<script type="module">
import * as THREE from "three";
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
const scene = new THREE.Scene();
const size = 10;
const divisions = 10;
const gridHelper = new THREE.GridHelper( size, divisions );
scene.add( gridHelper );
gridHelper.position.y = -1;
const cube = new THREE.Mesh(
new THREE.BoxGeometry(1, 1, 1),
new THREE.MeshBasicMaterial({ color: 0x00ff00 })
);
scene.add(cube);
const camera = new THREE.PerspectiveCamera(40, window.innerWidth / window.innerHeight, 1, 20);
camera.position.z = 5;
camera.position.y = 10;
camera.position.x = 10;
const helper = new THREE.CameraHelper( camera ); scene.add( helper );
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
function createFullScreenPlane(camera) {
const aspect = camera.aspect;
const frustumHeight = 2 * Math.tan(THREE.MathUtils.degToRad(camera.fov) / 2) * camera.position.z;
const frustumWidth = frustumHeight * aspect;
const planeGeometry = new THREE.PlaneGeometry(frustumWidth, frustumHeight);
const planeMaterial = new THREE.MeshBasicMaterial({ color: 0xffffff });
const planeMesh = new THREE.Mesh(planeGeometry, planeMaterial);
planeMesh.lookAt(camera.position);
scene.add(planeMesh);
}
createFullScreenPlane(camera);
const debugCamera = new THREE.OrthographicCamera(-20, 20, 20, -20, 1, 100);
debugCamera.position.set(10, 10, 10);
const controls = new OrbitControls(camera, renderer.domElement);
controls.update();
controls.listenToKeyEvents(window);
const animate = () => {
requestAnimationFrame(animate);
renderer.setViewport(0, 0, window.innerWidth, window.innerHeight);
helper.update();
helper.visible = false;
renderer.render(scene, camera);
const debugViewportWidth = window.innerWidth * 0.5;
const debugViewportHeight = window.innerHeight * 0.5;
renderer.setViewport(10, 10, debugViewportWidth, debugViewportHeight);
renderer.setScissor(10, 10, debugViewportWidth, debugViewportHeight);
helper.visible = true;
renderer.setScissorTest(true);
renderer.render(scene, debugCamera);
renderer.setScissorTest(false);
controls.update();
};
animate();
</script>
</html>
And the screenshot with the result: