I have positioned some plane meshes distributed evenly on an ellipse curve line.
On the animation loop, i'm moving them around on the ellipse curve with curve.getPointAt
and time delta, then applying the matrix.
however, im also trying to add a scroll functionality by adding on the wheelY delta to this default orbit the planes already have.
But adding the delta values makes it 'jank' and then moving back fall in line with the original posiition. Which isnt ideal.
Any help on how i can achieve this would be much appreciated!
var renderer = new THREE.WebGLRenderer({ canvas: document.getElementById("canvas"), antialias: true });
renderer.setClearColor(0xffffff);
// use device aspect ratio //
renderer.setPixelRatio(window.devicePixelRatio);
// set size of canvas within window
renderer.setSize(window.innerWidth, window.innerHeight);
// SCENE
var scene = new THREE.Scene();
// CAMERA
var camera = new THREE.PerspectiveCamera(2, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.z = 220;
camera.position.y = 200;
camera.lookAt(0, 0, 0);
// ELLIPTIC CURVE
let curve = new THREE.EllipseCurve(0, 0, 7, 5);
let line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(curve.getSpacedPoints(100)),
new THREE.LineBasicMaterial({
color: "red",
})
);
line.rotation.x = -Math.PI * 0.5;
line.position.x = 0;
scene.add(line);
// MESH
var geometry = new THREE.PlaneGeometry(1.3, 2.8);
var material = new THREE.MeshBasicMaterial({ color: 0xff0000, side: THREE.FrontSide });
const caro_group = new THREE.Group();
scene.add(caro_group);
var image_count = 11;
var image_meshes = [];
for (let i = 0; i < image_count; i++) {
image_meshes[i] = new THREE.Mesh(geometry, material);
caro_group.add(image_meshes[i]);
}
var delta_y = 0;
let target_delta = 0;
let current_delta = 0;
const ease_delta = 0.075;
window.onwheel = function (e) {
// use wheel delta for lerping rotation of meshes
target_delta = e.deltaY * 0.008;
};
let clock = new THREE.Clock();
let v = new THREE.Vector3();
// RENDER + ANIMATE
function animate() {
// rotation to add from mousewheel delta lerp
var rot_toadd = (target_delta - current_delta) * ease_delta;
let t = (clock.getElapsedTime() * 0.01) % 1;
for (let i = 0; i < image_count; i++) {
var point = ((1 / image_count) * i + t + rot_toadd) % 1;
image_meshes[i].position.copy(curve.getPointAt(point, v));
image_meshes[i].position.applyMatrix4(line.matrixWorld);
}
/* render scene and camera */
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
requestAnimationFrame(animate);
// RESIZE EVENTS
window.addEventListener("resize", onResize);
function onResize() {
width = window.innerWidth;
height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
}
html ,body {
overflow:hidden;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<canvas id="canvas"></canvas>