I’m trying to create a website using a Canvas as the background, similar to the Scroll Controls in React Three Fiber, but using just Three.js, HTML, and CSS.
My problem:
My canvas isn’t growing beyond 1080px in height. I noticed this issue when I tried to insert a plane at y: -5
.
I believe I handled the resizing correctly:
import * as THREE from 'three';
import { models } from './models';
import { RoomEnvironment } from 'three/addons/environments/RoomEnvironment.js';
import { Videos } from './videos';
const sizes = {
width: window.innerWidth,
height: window.innerHeight,
};
const aspectRatio = sizes.width / sizes.height;
let renderer, scene, camera, fov, clock, velociraptor, canvas, environment, pmremGenerator, mixer, speed;
clock = new THREE.Clock();
experience();
environmentForModels();
animate();
export function experience() {
scene = new THREE.Scene();
canvas = document.getElementById('app');
renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true
});
renderer.shadowMap.enabled = true;
renderer.setSize(sizes.width, sizes.height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
canvas.appendChild(renderer.domElement);
camSettings();
// Load models and create the mixer
models(scene, (loadedModel, loadedMixer) => {
velociraptor = loadedModel;
mixer = loadedMixer;
});
Videos(scene);
window.addEventListener('resize', updateRendererSizes);
renderer.render(scene, camera);
return scene;
}
function environmentForModels() {
environment = new RoomEnvironment(renderer);
pmremGenerator = new THREE.PMREMGenerator(renderer);
scene.environment = pmremGenerator.fromScene(environment).texture;
}
function camSettings() {
fov = window.innerWidth < 600 ? 10 : 25;
camera = new THREE.PerspectiveCamera(fov, aspectRatio, 0.1, 1000);
camera.position.z = 10;
scene.add(camera);
}
function updateRendererSizes() {
sizes.width = window.innerWidth;
sizes.height = window.innerHeight;
camera.aspect = sizes.width / sizes.height;
camera.updateProjectionMatrix();
renderer.setSize(sizes.width, sizes.height);
}
function animate() {
requestAnimationFrame(animate);
const delta = clock.getDelta();
speed = .7;
// Update the mixer with the adjusted speed
if (mixer) {
mixer.update(delta * speed);
}
renderer.render(scene, camera);
}
My HTML and CSS related to the canvas div:
<div id="app" class="canvas"></div>
.canvas {
position: absolute;
width: 100%;
height: 100%;
z-index: 10;
}
I created it this way because I want to control the text z-axis to insert some content in front of and behind the models. I have seen a lot of content on the forum, but I couldn’t find a solution to this issue.
Can you help me, please?
Thank you for your time!