Hello Amazing Stackoverflow community,
I've been attempting to move my object in three.js to a specific point. I believe I need to utilize Tween.js for this task. However, in the tutorial I followed, they imported Tween Js but used 'timelinemax' which confused me a bit.
Below is my code snippet:
var scene = new THREE.Scene();
scene.background = new THREE.Color(0xf0f0f0);
var camera = new THREE.PerspectiveCamera(100, window.innerWidth/window.innerHeight, 0.1, 3000);
camera.position.x = 40;
camera.position.y = 20;
camera.position.z = 1500;
var renderer = new THREE.WebGLRenderer();
var render = function() {
requestAnimationFrame(render);
renderer.render(scene, camera);
}
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
var coord = [{"x":300,"y":10,"z":10},{"x":20,"y":30,"z":30},{"x":30,"y":0,"z":50},
{"x":40,"y":20,"z":70},{"x":50,"y":100,"z":90},
{"x":60,"y":30,"z":110},{"x":70,"y":150,"z":90}];
var sphr;
var geom;
var sphrinfo = [];
function drawsphere() {
for (let i=0; i<coord.length; i++) {
var mat = new THREE.MeshPhongMaterial({flatShading: true});
geom = new THREE.SphereGeometry(60, 50, 50);
sphr = new THREE.Mesh(geom, mat);
sphr.position.set(coord[i].x, coord[i].y, coord[i].z)
sphrinfo.push(sphr)
sphr.tl = new TimelineMax()
sphr.tl.to(sphr.position.set, .5, {x:100, y:204, z:300})
scene.add(sphr);
render();
}
}
drawsphere();
function movesphere() {
for (let i=0; i<coord.length; i++) {
sphrinfo[i].z = 10;
}
}
function animate() {
}
var light = new THREE.AmbientLight(0x404040);
scene.add(light);
var directionalLight = new THREE.DirectionalLight(0xffffff, 0.7);
scene.add(directionalLight);
I included TimelineMax to animate the spheres, but unfortunately, they do not move at all. Can someone assist me in resolving this issue?
My ultimate goal is to generate multiple spheres with specific x, y, z values and then have them drop to the plane where the z coordinate is zero, animating the process.
Thank you in advance.