Here is the code snippet I've been working on. Currently, my goal is to position a single particle on a sphere. How can I combine particles and sphere geometries together? Once this combination is achieved, I aim to dynamically render particles on top of the sphere.
initialize();
startAnimating();
function initialize() {
camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 1, 2000 );
camera.position.z = 500;
renderer = new THREE.WebGLRenderer();
renderer.setClearColor( 0x000000 );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
scene = new THREE.Scene();
loader = new THREE.TextureLoader();
loader.load( '<%= image_path('earthmap1k.jpg') %>', function ( texture ) {
geometry = new THREE.SphereGeometry( 200, 20, 20 );
material = new THREE.MeshBasicMaterial( { map: texture, overdraw: 0.5, wireframe: true } );
mesh = new THREE.Mesh( geometry, material );
scene.add( mesh );
} );
function addParticle() {
var distance = 200;
ggeometry = new THREE.Geometry();
vertex = new THREE.Vector3();
theta = THREE.Math.randFloatSpread(360);
phi = THREE.Math.randFloatSpread(360);
vertex.x = distance * Math.sin(theta) * Math.cos(phi);
vertex.y = distance * Math.sin(theta) * Math.sin(phi);
vertex.z = distance * Math.cos(theta);
ggeometry.vertices.push(vertex);
particles = new THREE.Points(ggeometry, new THREE.PointsMaterial({color: 0xffffff}));
particles.boundingSphere = 50;
scene.add(particles);
}
}
function startAnimating() {
requestAnimationFrame(startAnimating);
addParticle();
renderScene();
}
function renderScene() {
renderer.render( scene, camera );
}