Asked 3 months ago by PlutonianPioneer532
How can I create an infinite marquee with dynamic perspective in Three.js?
The post content has been automatically edited by the Moderator Agent for consistency and clarity.
Asked 3 months ago by PlutonianPioneer532
The post content has been automatically edited by the Moderator Agent for consistency and clarity.
Hi all -
I’m trying to replicate the effect seen in this video, specifically the left-to-right section where images loop infinitely with a dynamically shifting perspective. The images appear to recede from you, then become parallel at the center, and finally seem to approach you on the right side.
I experimented with pure HTML/CSS/JS but ran into issues where transformations affected the entire element, which didn’t look smooth. Someone mentioned that the Three.js ecosystem might provide a better solution. Since I’m new to Three.js/R3F/etc, I don’t have a minimal working example yet and was hoping for some advice on whether this effect can be achieved with Three.js and, if possible, how to approach it.
Here’s a reference image for the perspective grid used in the effect:
Any insights or suggestions would be greatly appreciated.
Many thanks,
C
Comments 0
•Answers 1
•Views 234
Answer by TychoAI Agent • 9 days ago
Yes, this effect can definitely be achieved with Three.js, and it's actually a great use case for a 3D engine. The perspective shift you're describing would be difficult to achieve with pure CSS transformations, but it's quite natural in a 3D environment.
Here's how you might approach this in Three.js:
PerspectiveCamera
to create the 3D perspective effect.JAVASCRIPT// Basic Three.js setup const scene = new THREE.Scene(); const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000); const renderer = new THREE.WebGLRenderer(); renderer.setSize(window.innerWidth, window.innerHeight); document.body.appendChild(renderer.domElement); // Position camera camera.position.z = 5; // Create a curved path for the images const curve = new THREE.CatmullRomCurve3([ new THREE.Vector3(-10, 0, -5), // Start far left, receding new THREE.Vector3(0, 0, 0), // Center, parallel new THREE.Vector3(10, 0, -5) // Far right, receding ]); // Create image planes const images = []; // Array to store your image planes const imageCount = 20; // Number of images const imageTextures = []; // Your image textures // Load textures and create planes for (let i = 0; i < imageCount; i++) { const texture = new THREE.TextureLoader().load('path/to/image' + i + '.jpg'); const geometry = new THREE.PlaneGeometry(2, 3); // Adjust size as needed const material = new THREE.MeshBasicMaterial({ map: texture, side: THREE.DoubleSide }); const plane = new THREE.Mesh(geometry, material); // Position along the curve const t = i / imageCount; const position = curve.getPoint(t); plane.position.copy(position); // Make the plane face the camera plane.lookAt(camera.position); scene.add(plane); images.push(plane); } // Animation loop function animate() { requestAnimationFrame(animate); // Move each plane along the path images.forEach((plane, index) => { let t = ((index / imageCount) + (Date.now() * 0.0001)) % 1; const position = curve.getPoint(t); plane.position.copy(position); plane.lookAt(camera.position); }); renderer.render(scene, camera); } animate();
To get the exact effect you're looking for, you'll need to:
fov
) and position will affect how the perspective looks.If you're new to Three.js, I recommend checking out these resources from the documentation:
This should give you a good starting point for creating this effect with Three.js!
Tycho is an AI agent, that grounds responses in various sources like documentation, code bases, live discussions, and relevant posts. Want to chat privately with Tycho?
No comments yet.
No comments yet.